blob: 87fe7f5cf87c4b6e8a0ff72533eec8ce5980a114 [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;
1467 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001468 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001469 struct peer *rsclient = rn->table->owner;
1470
Paul Jakmafb982c22007-05-04 20:15:47 +00001471 memset (&attr, 0, sizeof (struct attr));
paulfee0f4c2004-09-13 05:12:46 +00001472 /* Best path selection. */
1473 bgp_best_selection (bgp, rn, &old_and_new);
1474 new_select = old_and_new.new;
1475 old_select = old_and_new.old;
1476
paul200df112005-06-01 11:17:05 +00001477 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1478 {
1479 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1480 {
1481 /* Nothing to do. */
1482 if (old_select && old_select == new_select)
1483 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1484 continue;
paulfee0f4c2004-09-13 05:12:46 +00001485
paul200df112005-06-01 11:17:05 +00001486 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001487 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001488 if (new_select)
1489 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001490 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1491 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001492 }
paulfee0f4c2004-09-13 05:12:46 +00001493
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001495 }
1496 }
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
Paul Jakmafb982c22007-05-04 20:15:47 +00001512 bgp_attr_extra_free (&attr);
1513
paul200df112005-06-01 11:17:05 +00001514 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1515 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001516}
1517
paul200df112005-06-01 11:17:05 +00001518static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001519bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001520{
paul0fb58d52005-11-14 14:31:49 +00001521 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001522 struct bgp *bgp = pq->bgp;
1523 struct bgp_node *rn = pq->rn;
1524 afi_t afi = pq->afi;
1525 safi_t safi = pq->safi;
1526 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001527 struct bgp_info *new_select;
1528 struct bgp_info *old_select;
1529 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001530 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001531 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001532
paulfee0f4c2004-09-13 05:12:46 +00001533 /* Best path selection. */
1534 bgp_best_selection (bgp, rn, &old_and_new);
1535 old_select = old_and_new.old;
1536 new_select = old_and_new.new;
1537
1538 /* Nothing to do. */
1539 if (old_select && old_select == new_select)
1540 {
1541 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001542 {
1543 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1544 bgp_zebra_announce (p, old_select, bgp);
1545
1546 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1547 return WQ_SUCCESS;
1548 }
paulfee0f4c2004-09-13 05:12:46 +00001549 }
paul718e3742002-12-13 20:15:29 +00001550
hasso338b3422005-02-23 14:27:24 +00001551 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001553 if (new_select)
1554 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001557 }
1558
1559
paul718e3742002-12-13 20:15:29 +00001560 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001561 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001562 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001563 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001564 }
1565
1566 /* FIB update. */
1567 if (safi == SAFI_UNICAST && ! bgp->name &&
1568 ! bgp_option_check (BGP_OPT_NO_FIB))
1569 {
1570 if (new_select
1571 && new_select->type == ZEBRA_ROUTE_BGP
1572 && new_select->sub_type == BGP_ROUTE_NORMAL)
1573 bgp_zebra_announce (p, new_select, bgp);
1574 else
1575 {
1576 /* Withdraw the route from the kernel. */
1577 if (old_select
1578 && old_select->type == ZEBRA_ROUTE_BGP
1579 && old_select->sub_type == BGP_ROUTE_NORMAL)
1580 bgp_zebra_withdraw (p, old_select);
1581 }
1582 }
paulb40d9392005-08-22 22:34:41 +00001583
1584 /* Reap old select bgp_info, it it has been removed */
1585 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1586 bgp_info_reap (rn, old_select);
1587
paul200df112005-06-01 11:17:05 +00001588 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1589 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001590}
1591
paul200df112005-06-01 11:17:05 +00001592static void
paul0fb58d52005-11-14 14:31:49 +00001593bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001594{
paul0fb58d52005-11-14 14:31:49 +00001595 struct bgp_process_queue *pq = data;
1596
Stephen Hemminger0088b5d2009-05-21 08:51:03 -07001597 bgp_unlock(pq->bgp);
paul200df112005-06-01 11:17:05 +00001598 bgp_unlock_node (pq->rn);
1599 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;
1644
1645 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1646 pqnode->bgp = bgp;
Stephen Hemminger0088b5d2009-05-21 08:51:03 -07001647 bgp_lock(bgp);
paul200df112005-06-01 11:17:05 +00001648 pqnode->afi = afi;
1649 pqnode->safi = safi;
1650
paulfee0f4c2004-09-13 05:12:46 +00001651 switch (rn->table->type)
1652 {
paul200df112005-06-01 11:17:05 +00001653 case BGP_TABLE_MAIN:
1654 work_queue_add (bm->process_main_queue, pqnode);
1655 break;
1656 case BGP_TABLE_RSCLIENT:
1657 work_queue_add (bm->process_rsclient_queue, pqnode);
1658 break;
paulfee0f4c2004-09-13 05:12:46 +00001659 }
paul200df112005-06-01 11:17:05 +00001660
1661 return;
paulfee0f4c2004-09-13 05:12:46 +00001662}
hasso0a486e52005-02-01 20:57:17 +00001663
paul94f2b392005-06-28 12:44:16 +00001664static int
hasso0a486e52005-02-01 20:57:17 +00001665bgp_maximum_prefix_restart_timer (struct thread *thread)
1666{
1667 struct peer *peer;
1668
1669 peer = THREAD_ARG (thread);
1670 peer->t_pmax_restart = NULL;
1671
1672 if (BGP_DEBUG (events, EVENTS))
1673 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1674 peer->host);
1675
1676 peer_clear (peer);
1677
1678 return 0;
1679}
1680
paulfee0f4c2004-09-13 05:12:46 +00001681int
paul5228ad22004-06-04 17:58:18 +00001682bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1683 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001684{
hassoe0701b72004-05-20 09:19:34 +00001685 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1686 return 0;
1687
1688 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001689 {
hassoe0701b72004-05-20 09:19:34 +00001690 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1691 && ! always)
1692 return 0;
paul718e3742002-12-13 20:15:29 +00001693
hassoe0701b72004-05-20 09:19:34 +00001694 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001695 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1696 "limit %ld", afi_safi_print (afi, safi), peer->host,
1697 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001698 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001699
hassoe0701b72004-05-20 09:19:34 +00001700 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1701 return 0;
paul718e3742002-12-13 20:15:29 +00001702
hassoe0701b72004-05-20 09:19:34 +00001703 {
paul5228ad22004-06-04 17:58:18 +00001704 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001705
1706 if (safi == SAFI_MPLS_VPN)
1707 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001708
1709 ndata[0] = (afi >> 8);
1710 ndata[1] = afi;
1711 ndata[2] = safi;
1712 ndata[3] = (peer->pmax[afi][safi] >> 24);
1713 ndata[4] = (peer->pmax[afi][safi] >> 16);
1714 ndata[5] = (peer->pmax[afi][safi] >> 8);
1715 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001716
1717 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1718 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1719 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1720 }
hasso0a486e52005-02-01 20:57:17 +00001721
1722 /* restart timer start */
1723 if (peer->pmax_restart[afi][safi])
1724 {
1725 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1726
1727 if (BGP_DEBUG (events, EVENTS))
1728 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1729 peer->host, peer->v_pmax_restart);
1730
1731 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1732 peer->v_pmax_restart);
1733 }
1734
hassoe0701b72004-05-20 09:19:34 +00001735 return 1;
paul718e3742002-12-13 20:15:29 +00001736 }
hassoe0701b72004-05-20 09:19:34 +00001737 else
1738 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1739
1740 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1741 {
1742 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1743 && ! always)
1744 return 0;
1745
1746 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001747 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1748 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1749 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001750 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1751 }
1752 else
1753 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001754 return 0;
1755}
1756
paulb40d9392005-08-22 22:34:41 +00001757/* Unconditionally remove the route from the RIB, without taking
1758 * damping into consideration (eg, because the session went down)
1759 */
paul94f2b392005-06-28 12:44:16 +00001760static void
paul718e3742002-12-13 20:15:29 +00001761bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1762 afi_t afi, safi_t safi)
1763{
paul902212c2006-02-05 17:51:19 +00001764 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1765
1766 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1767 bgp_info_delete (rn, ri); /* keep historical info */
1768
paulb40d9392005-08-22 22:34:41 +00001769 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001770}
1771
paul94f2b392005-06-28 12:44:16 +00001772static void
paul718e3742002-12-13 20:15:29 +00001773bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001774 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001775{
paul718e3742002-12-13 20:15:29 +00001776 int status = BGP_DAMP_NONE;
1777
paulb40d9392005-08-22 22:34:41 +00001778 /* apply dampening, if result is suppressed, we'll be retaining
1779 * the bgp_info in the RIB for historical reference.
1780 */
1781 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1782 && peer_sort (peer) == BGP_PEER_EBGP)
1783 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1784 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001785 {
paul902212c2006-02-05 17:51:19 +00001786 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1787 return;
1788 }
1789
1790 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001791}
1792
paul94f2b392005-06-28 12:44:16 +00001793static void
paulfee0f4c2004-09-13 05:12:46 +00001794bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1795 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1796 int sub_type, struct prefix_rd *prd, u_char *tag)
1797{
1798 struct bgp_node *rn;
1799 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001800 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001801 struct attr *attr_new;
1802 struct attr *attr_new2;
1803 struct bgp_info *ri;
1804 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001805 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001806 char buf[SU_ADDRSTRLEN];
1807
Paul Jakmafb982c22007-05-04 20:15:47 +00001808 //memset (new_attr, 0, sizeof (struct attr));
1809
paulfee0f4c2004-09-13 05:12:46 +00001810 /* 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
1897 bgp_unlock_node (rn);
1898 bgp_attr_unintern (attr_new);
1899
1900 return;
1901 }
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)
1995 {
1996 struct bgp_node *rn;
1997 struct bgp_info *ri;
1998 char buf[SU_ADDRSTRLEN];
1999
2000 if (rsclient == peer)
2001 return;
2002
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. */
2020 bgp_unlock_node (rn);
2021 }
2022
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;
2435 struct attr attr;
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;
2524 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002525
2526 memset (&attr, 0, sizeof (struct attr));
2527
paul718e3742002-12-13 20:15:29 +00002528 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002529 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002530
2531 if (safi != SAFI_MPLS_VPN
2532 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2533 bgp_default_originate (peer, afi, safi, 0);
2534
2535 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2536 for (ri = rn->info; ri; ri = ri->next)
2537 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2538 {
paulfee0f4c2004-09-13 05:12:46 +00002539 if ( (rsclient) ?
2540 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2541 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002542 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2543 else
2544 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002545
2546 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002547 }
2548}
2549
2550void
2551bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2552{
2553 struct bgp_node *rn;
2554 struct bgp_table *table;
2555
2556 if (peer->status != Established)
2557 return;
2558
2559 if (! peer->afc_nego[afi][safi])
2560 return;
2561
2562 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2563 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2564 return;
2565
2566 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002567 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002568 else
2569 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2570 rn = bgp_route_next(rn))
2571 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002572 bgp_announce_table (peer, afi, safi, table, 0);
2573
2574 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2575 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002576}
2577
2578void
2579bgp_announce_route_all (struct peer *peer)
2580{
2581 afi_t afi;
2582 safi_t safi;
2583
2584 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2585 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2586 bgp_announce_route (peer, afi, safi);
2587}
2588
2589static void
paulfee0f4c2004-09-13 05:12:46 +00002590bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2591 safi_t safi, struct bgp_table *table)
2592{
2593 struct bgp_node *rn;
2594 struct bgp_adj_in *ain;
2595
2596 if (! table)
2597 table = rsclient->bgp->rib[afi][safi];
2598
2599 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2600 for (ain = rn->adj_in; ain; ain = ain->next)
2601 {
2602 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2603 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2604 }
2605}
2606
2607void
2608bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2609{
2610 struct bgp_table *table;
2611 struct bgp_node *rn;
2612
2613 if (safi != SAFI_MPLS_VPN)
2614 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2615
2616 else
2617 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2618 rn = bgp_route_next (rn))
2619 if ((table = rn->info) != NULL)
2620 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2621}
2622
2623static void
paul718e3742002-12-13 20:15:29 +00002624bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2625 struct bgp_table *table)
2626{
2627 int ret;
2628 struct bgp_node *rn;
2629 struct bgp_adj_in *ain;
2630
2631 if (! table)
2632 table = peer->bgp->rib[afi][safi];
2633
2634 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2635 for (ain = rn->adj_in; ain; ain = ain->next)
2636 {
2637 if (ain->peer == peer)
2638 {
2639 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2640 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2641 NULL, NULL, 1);
2642 if (ret < 0)
2643 {
2644 bgp_unlock_node (rn);
2645 return;
2646 }
2647 continue;
2648 }
2649 }
2650}
2651
2652void
2653bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2654{
2655 struct bgp_node *rn;
2656 struct bgp_table *table;
2657
2658 if (peer->status != Established)
2659 return;
2660
2661 if (safi != SAFI_MPLS_VPN)
2662 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2663 else
2664 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2665 rn = bgp_route_next (rn))
2666 if ((table = rn->info) != NULL)
2667 bgp_soft_reconfig_table (peer, afi, safi, table);
2668}
2669
paul200df112005-06-01 11:17:05 +00002670static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002671bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002672{
Paul Jakma64e580a2006-02-21 01:09:01 +00002673 struct bgp_node *rn = data;
2674 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002675 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002676 afi_t afi = rn->table->afi;
2677 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002678
Paul Jakma64e580a2006-02-21 01:09:01 +00002679 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002680
Paul Jakma64e580a2006-02-21 01:09:01 +00002681 for (ri = rn->info; ri; ri = ri->next)
2682 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002683 {
2684 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002685 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2686 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002687 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002688 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2689 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002690 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002691 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002692 break;
2693 }
paul200df112005-06-01 11:17:05 +00002694 return WQ_SUCCESS;
2695}
2696
2697static void
paul0fb58d52005-11-14 14:31:49 +00002698bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002699{
Paul Jakma64e580a2006-02-21 01:09:01 +00002700 struct bgp_node *rn = data;
2701
2702 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002703}
2704
2705static void
paul94f2b392005-06-28 12:44:16 +00002706bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002707{
Paul Jakma64e580a2006-02-21 01:09:01 +00002708 struct peer *peer = wq->spec.data;
2709
Paul Jakma64e580a2006-02-21 01:09:01 +00002710 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002711
2712 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002713 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002714}
2715
2716static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002717bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002718{
Paul Jakma64e580a2006-02-21 01:09:01 +00002719#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2720 char wname[CLEAR_QUEUE_NAME_LEN];
2721
2722 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2723#undef CLEAR_QUEUE_NAME_LEN
2724
2725 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002726 {
2727 zlog_err ("%s: Failed to allocate work queue", __func__);
2728 exit (1);
2729 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002730 peer->clear_node_queue->spec.hold = 10;
2731 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2732 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2733 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2734 peer->clear_node_queue->spec.max_retries = 0;
2735
2736 /* we only 'lock' this peer reference when the queue is actually active */
2737 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002738}
2739
paul718e3742002-12-13 20:15:29 +00002740static void
2741bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002742 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002743{
2744 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002745
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002746
paul718e3742002-12-13 20:15:29 +00002747 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002748 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002749
hasso6cf159b2005-03-21 10:28:14 +00002750 /* If still no table => afi/safi isn't configured at all or smth. */
2751 if (! table)
2752 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002753
2754 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2755 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002756 struct bgp_info *ri;
2757 struct bgp_adj_in *ain;
2758 struct bgp_adj_out *aout;
2759
Paul Jakma65ca75e2006-05-04 08:08:15 +00002760 if (rn->info == NULL)
2761 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002762
2763 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2764 * queued for every clearing peer, regardless of whether it is
2765 * relevant to the peer at hand.
2766 *
2767 * Overview: There are 3 different indices which need to be
2768 * scrubbed, potentially, when a peer is removed:
2769 *
2770 * 1 peer's routes visible via the RIB (ie accepted routes)
2771 * 2 peer's routes visible by the (optional) peer's adj-in index
2772 * 3 other routes visible by the peer's adj-out index
2773 *
2774 * 3 there is no hurry in scrubbing, once the struct peer is
2775 * removed from bgp->peer, we could just GC such deleted peer's
2776 * adj-outs at our leisure.
2777 *
2778 * 1 and 2 must be 'scrubbed' in some way, at least made
2779 * invisible via RIB index before peer session is allowed to be
2780 * brought back up. So one needs to know when such a 'search' is
2781 * complete.
2782 *
2783 * Ideally:
2784 *
2785 * - there'd be a single global queue or a single RIB walker
2786 * - rather than tracking which route_nodes still need to be
2787 * examined on a peer basis, we'd track which peers still
2788 * aren't cleared
2789 *
2790 * Given that our per-peer prefix-counts now should be reliable,
2791 * this may actually be achievable. It doesn't seem to be a huge
2792 * problem at this time,
2793 */
2794 for (ri = rn->info; ri; ri = ri->next)
2795 if (ri->peer == peer)
2796 {
2797 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2798 work_queue_add (peer->clear_node_queue, rn);
2799 }
2800
2801 for (ain = rn->adj_in; ain; ain = ain->next)
2802 if (ain->peer == peer)
2803 {
2804 bgp_adj_in_remove (rn, ain);
2805 bgp_unlock_node (rn);
2806 break;
2807 }
2808 for (aout = rn->adj_out; aout; aout = aout->next)
2809 if (aout->peer == peer)
2810 {
2811 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2812 bgp_unlock_node (rn);
2813 break;
2814 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002815 }
2816 return;
2817}
2818
2819void
2820bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2821{
2822 struct bgp_node *rn;
2823 struct bgp_table *table;
2824 struct peer *rsclient;
2825 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002826
Paul Jakma64e580a2006-02-21 01:09:01 +00002827 if (peer->clear_node_queue == NULL)
2828 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002829
Paul Jakmaca058a32006-09-14 02:58:49 +00002830 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2831 * Idle until it receives a Clearing_Completed event. This protects
2832 * against peers which flap faster than we can we clear, which could
2833 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002834 *
2835 * a) race with routes from the new session being installed before
2836 * clear_route_node visits the node (to delete the route of that
2837 * peer)
2838 * b) resource exhaustion, clear_route_node likely leads to an entry
2839 * on the process_main queue. Fast-flapping could cause that queue
2840 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002841 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002842 if (!peer->clear_node_queue->thread)
2843 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002844
paul718e3742002-12-13 20:15:29 +00002845 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002846 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002847 else
2848 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2849 rn = bgp_route_next (rn))
2850 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002851 bgp_clear_route_table (peer, afi, safi, table, NULL);
2852
paul1eb8ef22005-04-07 07:30:20 +00002853 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002854 {
2855 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2856 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2857 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002858
Paul Jakmaca058a32006-09-14 02:58:49 +00002859 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002860 * completion function won't be run by workqueue code - call it here.
2861 * XXX: Actually, this assumption doesn't hold, see
2862 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002863 *
2864 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002865 * really needed if peer state is Established - peers in
2866 * pre-Established states shouldn't have any route-update state
2867 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002868 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002869 * We still can get here in pre-Established though, through
2870 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2871 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002872 *
2873 * At some future point, this check could be move to the top of the
2874 * function, and do a quick early-return when state is
2875 * pre-Established, avoiding above list and table scans. Once we're
2876 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002877 */
2878 if (!peer->clear_node_queue->thread)
2879 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002880}
2881
2882void
2883bgp_clear_route_all (struct peer *peer)
2884{
2885 afi_t afi;
2886 safi_t safi;
2887
2888 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2889 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2890 bgp_clear_route (peer, afi, safi);
2891}
2892
2893void
2894bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2895{
2896 struct bgp_table *table;
2897 struct bgp_node *rn;
2898 struct bgp_adj_in *ain;
2899
2900 table = peer->bgp->rib[afi][safi];
2901
2902 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2903 for (ain = rn->adj_in; ain ; ain = ain->next)
2904 if (ain->peer == peer)
2905 {
2906 bgp_adj_in_remove (rn, ain);
2907 bgp_unlock_node (rn);
2908 break;
2909 }
2910}
hasso93406d82005-02-02 14:40:33 +00002911
2912void
2913bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2914{
2915 struct bgp_node *rn;
2916 struct bgp_info *ri;
2917 struct bgp_table *table;
2918
2919 table = peer->bgp->rib[afi][safi];
2920
2921 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2922 {
2923 for (ri = rn->info; ri; ri = ri->next)
2924 if (ri->peer == peer)
2925 {
2926 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2927 bgp_rib_remove (rn, ri, peer, afi, safi);
2928 break;
2929 }
2930 }
2931}
paul718e3742002-12-13 20:15:29 +00002932
2933/* Delete all kernel routes. */
2934void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002935bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002936{
2937 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002938 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002939 struct bgp_node *rn;
2940 struct bgp_table *table;
2941 struct bgp_info *ri;
2942
paul1eb8ef22005-04-07 07:30:20 +00002943 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002944 {
2945 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2946
2947 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2948 for (ri = rn->info; ri; ri = ri->next)
2949 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2950 && ri->type == ZEBRA_ROUTE_BGP
2951 && ri->sub_type == BGP_ROUTE_NORMAL)
2952 bgp_zebra_withdraw (&rn->p, ri);
2953
2954 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2955
2956 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2957 for (ri = rn->info; ri; ri = ri->next)
2958 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2959 && ri->type == ZEBRA_ROUTE_BGP
2960 && ri->sub_type == BGP_ROUTE_NORMAL)
2961 bgp_zebra_withdraw (&rn->p, ri);
2962 }
2963}
2964
2965void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002966bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002967{
2968 vty_reset ();
2969 bgp_zclient_reset ();
2970 access_list_reset ();
2971 prefix_list_reset ();
2972}
2973
2974/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2975 value. */
2976int
2977bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2978{
2979 u_char *pnt;
2980 u_char *lim;
2981 struct prefix p;
2982 int psize;
2983 int ret;
2984
2985 /* Check peer status. */
2986 if (peer->status != Established)
2987 return 0;
2988
2989 pnt = packet->nlri;
2990 lim = pnt + packet->length;
2991
2992 for (; pnt < lim; pnt += psize)
2993 {
2994 /* Clear prefix structure. */
2995 memset (&p, 0, sizeof (struct prefix));
2996
2997 /* Fetch prefix length. */
2998 p.prefixlen = *pnt++;
2999 p.family = afi2family (packet->afi);
3000
3001 /* Already checked in nlri_sanity_check(). We do double check
3002 here. */
3003 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3004 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3005 return -1;
3006
3007 /* Packet size overflow check. */
3008 psize = PSIZE (p.prefixlen);
3009
3010 /* When packet overflow occur return immediately. */
3011 if (pnt + psize > lim)
3012 return -1;
3013
3014 /* Fetch prefix from NLRI packet. */
3015 memcpy (&p.u.prefix, pnt, psize);
3016
3017 /* Check address. */
3018 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3019 {
3020 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3021 {
paulf5ba3872004-07-09 12:11:31 +00003022 /*
3023 * From draft-ietf-idr-bgp4-22, Section 6.3:
3024 * If a BGP router receives an UPDATE message with a
3025 * semantically incorrect NLRI field, in which a prefix is
3026 * semantically incorrect (eg. an unexpected multicast IP
3027 * address), it should ignore the prefix.
3028 */
paul718e3742002-12-13 20:15:29 +00003029 zlog (peer->log, LOG_ERR,
3030 "IPv4 unicast NLRI is multicast address %s",
3031 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003032
paul718e3742002-12-13 20:15:29 +00003033 return -1;
3034 }
3035 }
3036
3037#ifdef HAVE_IPV6
3038 /* Check address. */
3039 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3040 {
3041 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3042 {
3043 char buf[BUFSIZ];
3044
3045 zlog (peer->log, LOG_WARNING,
3046 "IPv6 link-local NLRI received %s ignore this NLRI",
3047 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3048
3049 continue;
3050 }
3051 }
3052#endif /* HAVE_IPV6 */
3053
3054 /* Normal process. */
3055 if (attr)
3056 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3057 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3058 else
3059 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3060 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3061
3062 /* Address family configuration mismatch or maximum-prefix count
3063 overflow. */
3064 if (ret < 0)
3065 return -1;
3066 }
3067
3068 /* Packet length consistency check. */
3069 if (pnt != lim)
3070 return -1;
3071
3072 return 0;
3073}
3074
3075/* NLRI encode syntax check routine. */
3076int
3077bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3078 bgp_size_t length)
3079{
3080 u_char *end;
3081 u_char prefixlen;
3082 int psize;
3083
3084 end = pnt + length;
3085
3086 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3087 syntactic validity. If the field is syntactically incorrect,
3088 then the Error Subcode is set to Invalid Network Field. */
3089
3090 while (pnt < end)
3091 {
3092 prefixlen = *pnt++;
3093
3094 /* Prefix length check. */
3095 if ((afi == AFI_IP && prefixlen > 32)
3096 || (afi == AFI_IP6 && prefixlen > 128))
3097 {
3098 plog_err (peer->log,
3099 "%s [Error] Update packet error (wrong prefix length %d)",
3100 peer->host, prefixlen);
3101 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3102 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3103 return -1;
3104 }
3105
3106 /* Packet size overflow check. */
3107 psize = PSIZE (prefixlen);
3108
3109 if (pnt + psize > end)
3110 {
3111 plog_err (peer->log,
3112 "%s [Error] Update packet error"
3113 " (prefix data overflow prefix size is %d)",
3114 peer->host, psize);
3115 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3116 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3117 return -1;
3118 }
3119
3120 pnt += psize;
3121 }
3122
3123 /* Packet length consistency check. */
3124 if (pnt != end)
3125 {
3126 plog_err (peer->log,
3127 "%s [Error] Update packet error"
3128 " (prefix length mismatch with total length)",
3129 peer->host);
3130 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3131 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3132 return -1;
3133 }
3134 return 0;
3135}
3136
paul94f2b392005-06-28 12:44:16 +00003137static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003138bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003139{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003140 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003141}
3142
paul94f2b392005-06-28 12:44:16 +00003143static void
paul718e3742002-12-13 20:15:29 +00003144bgp_static_free (struct bgp_static *bgp_static)
3145{
3146 if (bgp_static->rmap.name)
3147 free (bgp_static->rmap.name);
3148 XFREE (MTYPE_BGP_STATIC, bgp_static);
3149}
3150
paul94f2b392005-06-28 12:44:16 +00003151static void
paulfee0f4c2004-09-13 05:12:46 +00003152bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3153 struct prefix *p, afi_t afi, safi_t safi)
3154{
3155 struct bgp_node *rn;
3156 struct bgp_info *ri;
3157
3158 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3159
3160 /* Check selected route and self inserted route. */
3161 for (ri = rn->info; ri; ri = ri->next)
3162 if (ri->peer == bgp->peer_self
3163 && ri->type == ZEBRA_ROUTE_BGP
3164 && ri->sub_type == BGP_ROUTE_STATIC)
3165 break;
3166
3167 /* Withdraw static BGP route from routing table. */
3168 if (ri)
3169 {
paulfee0f4c2004-09-13 05:12:46 +00003170 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003171 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003172 }
3173
3174 /* Unlock bgp_node_lookup. */
3175 bgp_unlock_node (rn);
3176}
3177
paul94f2b392005-06-28 12:44:16 +00003178static void
paulfee0f4c2004-09-13 05:12:46 +00003179bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003180 struct bgp_static *bgp_static,
3181 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003182{
3183 struct bgp_node *rn;
3184 struct bgp_info *ri;
3185 struct bgp_info *new;
3186 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003187 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003188 struct attr attr = {0 };
3189 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003190 struct bgp *bgp;
3191 int ret;
3192 char buf[SU_ADDRSTRLEN];
3193
3194 bgp = rsclient->bgp;
3195
Paul Jakma06e110f2006-05-12 23:29:22 +00003196 assert (bgp_static);
3197 if (!bgp_static)
3198 return;
3199
paulfee0f4c2004-09-13 05:12:46 +00003200 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3201
3202 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003203
3204 attr.nexthop = bgp_static->igpnexthop;
3205 attr.med = bgp_static->igpmetric;
3206 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003207
3208 if (bgp_static->ttl)
3209 {
3210 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3211 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3212 attr.pathlimit.as = 0;
3213 attr.pathlimit.ttl = bgp_static->ttl;
3214 }
3215
3216 if (bgp_static->atomic)
3217 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3218
paulfee0f4c2004-09-13 05:12:46 +00003219 /* Apply network route-map for export to this rsclient. */
3220 if (bgp_static->rmap.name)
3221 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003222 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003223 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003224 info.attr = &attr_tmp;
3225
paulfee0f4c2004-09-13 05:12:46 +00003226 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3227 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3228
3229 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3230
3231 rsclient->rmap_type = 0;
3232
3233 if (ret == RMAP_DENYMATCH)
3234 {
3235 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003236 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003237
3238 /* Unintern original. */
3239 aspath_unintern (attr.aspath);
3240 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003241 bgp_attr_extra_free (&attr);
3242
paulfee0f4c2004-09-13 05:12:46 +00003243 return;
3244 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003245 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003246 }
3247 else
3248 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003249
paulfee0f4c2004-09-13 05:12:46 +00003250 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003251
paulfee0f4c2004-09-13 05:12:46 +00003252 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3253
Paul Jakmafb982c22007-05-04 20:15:47 +00003254 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3255 == RMAP_DENY)
3256 {
paulfee0f4c2004-09-13 05:12:46 +00003257 /* This BGP update is filtered. Log the reason then update BGP entry. */
3258 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003259 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003260 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3261 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3262 p->prefixlen, rsclient->host);
3263
3264 bgp->peer_self->rmap_type = 0;
3265
3266 bgp_attr_unintern (attr_new);
3267 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003268 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003269
3270 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3271
3272 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 }
paulfee0f4c2004-09-13 05:12:46 +00003274
3275 bgp->peer_self->rmap_type = 0;
3276
3277 bgp_attr_unintern (attr_new);
3278 attr_new = bgp_attr_intern (&new_attr);
3279
3280 for (ri = rn->info; ri; ri = ri->next)
3281 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3282 && ri->sub_type == BGP_ROUTE_STATIC)
3283 break;
3284
3285 if (ri)
3286 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003287 if (attrhash_cmp (ri->attr, attr_new) &&
3288 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003289 {
3290 bgp_unlock_node (rn);
3291 bgp_attr_unintern (attr_new);
3292 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003293 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003294 return;
3295 }
3296 else
3297 {
3298 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003299 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003300
3301 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003302 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3303 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003304 bgp_attr_unintern (ri->attr);
3305 ri->attr = attr_new;
3306 ri->uptime = time (NULL);
3307
3308 /* Process change. */
3309 bgp_process (bgp, rn, afi, safi);
3310 bgp_unlock_node (rn);
3311 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003312 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003313 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003314 }
paulfee0f4c2004-09-13 05:12:46 +00003315 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003316
paulfee0f4c2004-09-13 05:12:46 +00003317 /* Make new BGP info. */
3318 new = bgp_info_new ();
3319 new->type = ZEBRA_ROUTE_BGP;
3320 new->sub_type = BGP_ROUTE_STATIC;
3321 new->peer = bgp->peer_self;
3322 SET_FLAG (new->flags, BGP_INFO_VALID);
3323 new->attr = attr_new;
3324 new->uptime = time (NULL);
3325
3326 /* Register new BGP information. */
3327 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003328
3329 /* route_node_get lock */
3330 bgp_unlock_node (rn);
3331
paulfee0f4c2004-09-13 05:12:46 +00003332 /* Process change. */
3333 bgp_process (bgp, rn, afi, safi);
3334
3335 /* Unintern original. */
3336 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003337 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003338}
3339
paul94f2b392005-06-28 12:44:16 +00003340static void
paulfee0f4c2004-09-13 05:12:46 +00003341bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003342 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3343{
3344 struct bgp_node *rn;
3345 struct bgp_info *ri;
3346 struct bgp_info *new;
3347 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003349 struct attr *attr_new;
3350 int ret;
3351
Paul Jakmadd8103a2006-05-12 23:27:30 +00003352 assert (bgp_static);
3353 if (!bgp_static)
3354 return;
3355
paulfee0f4c2004-09-13 05:12:46 +00003356 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003357
3358 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003359
3360 attr.nexthop = bgp_static->igpnexthop;
3361 attr.med = bgp_static->igpmetric;
3362 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003363
Paul Jakma41367172007-08-06 15:24:51 +00003364 if (bgp_static->ttl)
3365 {
3366 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3367 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3368 attr.pathlimit.as = 0;
3369 attr.pathlimit.ttl = bgp_static->ttl;
3370 }
3371
3372 if (bgp_static->atomic)
3373 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3374
paul718e3742002-12-13 20:15:29 +00003375 /* Apply route-map. */
3376 if (bgp_static->rmap.name)
3377 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003379 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003380 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003381
paulfee0f4c2004-09-13 05:12:46 +00003382 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3383
paul718e3742002-12-13 20:15:29 +00003384 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003385
paulfee0f4c2004-09-13 05:12:46 +00003386 bgp->peer_self->rmap_type = 0;
3387
paul718e3742002-12-13 20:15:29 +00003388 if (ret == RMAP_DENYMATCH)
3389 {
3390 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003391 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003392
3393 /* Unintern original. */
3394 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003395 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003396 bgp_static_withdraw (bgp, p, afi, safi);
3397 return;
3398 }
paul286e1e72003-08-08 00:24:31 +00003399 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003400 }
paul286e1e72003-08-08 00:24:31 +00003401 else
3402 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003403
3404 for (ri = rn->info; ri; ri = ri->next)
3405 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3406 && ri->sub_type == BGP_ROUTE_STATIC)
3407 break;
3408
3409 if (ri)
3410 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003411 if (attrhash_cmp (ri->attr, attr_new) &&
3412 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003413 {
3414 bgp_unlock_node (rn);
3415 bgp_attr_unintern (attr_new);
3416 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003417 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003418 return;
3419 }
3420 else
3421 {
3422 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003423 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003424
3425 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003426 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3427 bgp_info_restore(rn, ri);
3428 else
3429 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003430 bgp_attr_unintern (ri->attr);
3431 ri->attr = attr_new;
3432 ri->uptime = time (NULL);
3433
3434 /* Process change. */
3435 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3436 bgp_process (bgp, rn, afi, safi);
3437 bgp_unlock_node (rn);
3438 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003439 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003440 return;
3441 }
3442 }
3443
3444 /* Make new BGP info. */
3445 new = bgp_info_new ();
3446 new->type = ZEBRA_ROUTE_BGP;
3447 new->sub_type = BGP_ROUTE_STATIC;
3448 new->peer = bgp->peer_self;
3449 SET_FLAG (new->flags, BGP_INFO_VALID);
3450 new->attr = attr_new;
3451 new->uptime = time (NULL);
3452
3453 /* Aggregate address increment. */
3454 bgp_aggregate_increment (bgp, p, new, afi, safi);
3455
3456 /* Register new BGP information. */
3457 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003458
3459 /* route_node_get lock */
3460 bgp_unlock_node (rn);
3461
paul718e3742002-12-13 20:15:29 +00003462 /* Process change. */
3463 bgp_process (bgp, rn, afi, safi);
3464
3465 /* Unintern original. */
3466 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003467 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003468}
3469
3470void
paulfee0f4c2004-09-13 05:12:46 +00003471bgp_static_update (struct bgp *bgp, struct prefix *p,
3472 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3473{
3474 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003475 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003476
3477 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3478
paul1eb8ef22005-04-07 07:30:20 +00003479 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003480 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003481 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3482 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003483 }
3484}
3485
paul94f2b392005-06-28 12:44:16 +00003486static void
paul718e3742002-12-13 20:15:29 +00003487bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3488 u_char safi, struct prefix_rd *prd, u_char *tag)
3489{
3490 struct bgp_node *rn;
3491 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003492
paulfee0f4c2004-09-13 05:12:46 +00003493 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003494
3495 /* Make new BGP info. */
3496 new = bgp_info_new ();
3497 new->type = ZEBRA_ROUTE_BGP;
3498 new->sub_type = BGP_ROUTE_STATIC;
3499 new->peer = bgp->peer_self;
3500 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3501 SET_FLAG (new->flags, BGP_INFO_VALID);
3502 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 new->extra = bgp_info_extra_new();
3504 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003505
3506 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003507 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003508
3509 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003510 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003511
paul200df112005-06-01 11:17:05 +00003512 /* route_node_get lock */
3513 bgp_unlock_node (rn);
3514
paul718e3742002-12-13 20:15:29 +00003515 /* Process change. */
3516 bgp_process (bgp, rn, afi, safi);
3517}
3518
3519void
3520bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3521 safi_t safi)
3522{
3523 struct bgp_node *rn;
3524 struct bgp_info *ri;
3525
paulfee0f4c2004-09-13 05:12:46 +00003526 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003527
3528 /* Check selected route and self inserted route. */
3529 for (ri = rn->info; ri; ri = ri->next)
3530 if (ri->peer == bgp->peer_self
3531 && ri->type == ZEBRA_ROUTE_BGP
3532 && ri->sub_type == BGP_ROUTE_STATIC)
3533 break;
3534
3535 /* Withdraw static BGP route from routing table. */
3536 if (ri)
3537 {
3538 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003539 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003540 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003541 }
3542
3543 /* Unlock bgp_node_lookup. */
3544 bgp_unlock_node (rn);
3545}
3546
3547void
paulfee0f4c2004-09-13 05:12:46 +00003548bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3549{
3550 struct bgp_static *bgp_static;
3551 struct bgp *bgp;
3552 struct bgp_node *rn;
3553 struct prefix *p;
3554
3555 bgp = rsclient->bgp;
3556
3557 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3558 if ((bgp_static = rn->info) != NULL)
3559 {
3560 p = &rn->p;
3561
3562 bgp_static_update_rsclient (rsclient, p, bgp_static,
3563 afi, safi);
3564 }
3565}
3566
paul94f2b392005-06-28 12:44:16 +00003567static void
paul718e3742002-12-13 20:15:29 +00003568bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3569 u_char safi, struct prefix_rd *prd, u_char *tag)
3570{
3571 struct bgp_node *rn;
3572 struct bgp_info *ri;
3573
paulfee0f4c2004-09-13 05:12:46 +00003574 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003575
3576 /* Check selected route and self inserted route. */
3577 for (ri = rn->info; ri; ri = ri->next)
3578 if (ri->peer == bgp->peer_self
3579 && ri->type == ZEBRA_ROUTE_BGP
3580 && ri->sub_type == BGP_ROUTE_STATIC)
3581 break;
3582
3583 /* Withdraw static BGP route from routing table. */
3584 if (ri)
3585 {
3586 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003587 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003588 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003589 }
3590
3591 /* Unlock bgp_node_lookup. */
3592 bgp_unlock_node (rn);
3593}
3594
Paul Jakma41367172007-08-06 15:24:51 +00003595static void
3596bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3597 int ttl_edge)
3598{
3599 struct bgp_node *parent = rn;
3600 struct bgp_static *sp;
3601
3602 /* Existing static changed TTL, search parents and adjust their atomic */
3603 while ((parent = parent->parent))
3604 if ((sp = parent->info))
3605 {
3606 int sp_level = (sp->atomic ? 1 : 0);
3607 ttl_edge ? sp->atomic++ : sp->atomic--;
3608
3609 /* did we change state of parent whether atomic is set or not? */
3610 if (sp_level != (sp->atomic ? 1 : 0))
3611 {
3612 bgp_static_update (bgp, &parent->p, sp,
3613 rn->table->afi, rn->table->safi);
3614 }
3615 }
3616}
3617
paul718e3742002-12-13 20:15:29 +00003618/* Configure static BGP network. When user don't run zebra, static
3619 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003620static int
paulfd79ac92004-10-13 05:06:08 +00003621bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003622 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3623 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003624{
3625 int ret;
3626 struct prefix p;
3627 struct bgp_static *bgp_static;
3628 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003629 u_char need_update = 0;
3630 u_char ttl_change = 0;
3631 u_char ttl_edge = (ttl ? 1 : 0);
3632 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003633
3634 /* Convert IP prefix string to struct prefix. */
3635 ret = str2prefix (ip_str, &p);
3636 if (! ret)
3637 {
3638 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3639 return CMD_WARNING;
3640 }
3641#ifdef HAVE_IPV6
3642 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3643 {
3644 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3645 VTY_NEWLINE);
3646 return CMD_WARNING;
3647 }
3648#endif /* HAVE_IPV6 */
3649
3650 apply_mask (&p);
3651
3652 /* Set BGP static route configuration. */
3653 rn = bgp_node_get (bgp->route[afi][safi], &p);
3654
3655 if (rn->info)
3656 {
3657 /* Configuration change. */
3658 bgp_static = rn->info;
3659
3660 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003661 if (bgp_static->valid)
3662 {
3663 if (bgp_static->backdoor != backdoor
3664 || bgp_static->ttl != ttl)
3665 need_update = 1;
3666 }
3667
3668 /* need to catch TTL set/unset transitions for handling of
3669 * ATOMIC_AGGREGATE
3670 */
3671 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3672 ttl_change = 1;
3673
paul718e3742002-12-13 20:15:29 +00003674 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003675 bgp_static->ttl = ttl;
3676
paul718e3742002-12-13 20:15:29 +00003677 if (rmap)
3678 {
3679 if (bgp_static->rmap.name)
3680 free (bgp_static->rmap.name);
3681 bgp_static->rmap.name = strdup (rmap);
3682 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3683 }
3684 else
3685 {
3686 if (bgp_static->rmap.name)
3687 free (bgp_static->rmap.name);
3688 bgp_static->rmap.name = NULL;
3689 bgp_static->rmap.map = NULL;
3690 bgp_static->valid = 0;
3691 }
3692 bgp_unlock_node (rn);
3693 }
3694 else
3695 {
3696 /* New configuration. */
3697 bgp_static = bgp_static_new ();
3698 bgp_static->backdoor = backdoor;
3699 bgp_static->valid = 0;
3700 bgp_static->igpmetric = 0;
3701 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003702 bgp_static->ttl = ttl;
3703 ttl_change = ttl_edge;
3704 new = 1;
3705
paul718e3742002-12-13 20:15:29 +00003706 if (rmap)
3707 {
3708 if (bgp_static->rmap.name)
3709 free (bgp_static->rmap.name);
3710 bgp_static->rmap.name = strdup (rmap);
3711 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3712 }
3713 rn->info = bgp_static;
3714 }
3715
Paul Jakma41367172007-08-06 15:24:51 +00003716 /* ".. sites that choose to advertise the
3717 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3718 * all less specific covering prefixes as well as the more specific
3719 * prefixes."
3720 *
3721 * So:
3722 * Prefix that has just had pathlimit set/unset:
3723 * - Must bump ATOMIC refcount on all parents.
3724 *
3725 * To catch less specific prefixes:
3726 * - Must search children for ones with TTL, bump atomic refcount
3727 * (we dont care if we're deleting a less specific prefix..)
3728 */
3729 if (ttl_change)
3730 {
3731 /* Existing static changed TTL, search parents and adjust their atomic */
3732 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3733 }
3734
3735 if (new)
3736 {
3737 struct bgp_node *child;
3738 struct bgp_static *sc;
3739
3740 /* New static, search children and bump this statics atomic.. */
3741 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3742 while ((child = bgp_route_next_until (child, rn)))
3743 {
3744 if ((sc = child->info) && sc->ttl)
3745 bgp_static->atomic++;
3746 }
3747 }
3748
paul718e3742002-12-13 20:15:29 +00003749 /* If BGP scan is not enabled, we should install this route here. */
3750 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3751 {
3752 bgp_static->valid = 1;
3753
3754 if (need_update)
3755 bgp_static_withdraw (bgp, &p, afi, safi);
3756
3757 if (! bgp_static->backdoor)
3758 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3759 }
3760
3761 return CMD_SUCCESS;
3762}
3763
3764/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003765static int
paulfd79ac92004-10-13 05:06:08 +00003766bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003767 u_int16_t afi, u_char safi)
3768{
3769 int ret;
3770 struct prefix p;
3771 struct bgp_static *bgp_static;
3772 struct bgp_node *rn;
3773
3774 /* Convert IP prefix string to struct prefix. */
3775 ret = str2prefix (ip_str, &p);
3776 if (! ret)
3777 {
3778 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3779 return CMD_WARNING;
3780 }
3781#ifdef HAVE_IPV6
3782 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3783 {
3784 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3785 VTY_NEWLINE);
3786 return CMD_WARNING;
3787 }
3788#endif /* HAVE_IPV6 */
3789
3790 apply_mask (&p);
3791
3792 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3793 if (! rn)
3794 {
3795 vty_out (vty, "%% Can't find specified static route configuration.%s",
3796 VTY_NEWLINE);
3797 return CMD_WARNING;
3798 }
3799
3800 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003801
3802 /* decrement atomic in parents, see bgp_static_set */
3803 bgp_pathlimit_update_parents (bgp, rn, 0);
3804
paul718e3742002-12-13 20:15:29 +00003805 /* Update BGP RIB. */
3806 if (! bgp_static->backdoor)
3807 bgp_static_withdraw (bgp, &p, afi, safi);
3808
3809 /* Clear configuration. */
3810 bgp_static_free (bgp_static);
3811 rn->info = NULL;
3812 bgp_unlock_node (rn);
3813 bgp_unlock_node (rn);
3814
3815 return CMD_SUCCESS;
3816}
3817
3818/* Called from bgp_delete(). Delete all static routes from the BGP
3819 instance. */
3820void
3821bgp_static_delete (struct bgp *bgp)
3822{
3823 afi_t afi;
3824 safi_t safi;
3825 struct bgp_node *rn;
3826 struct bgp_node *rm;
3827 struct bgp_table *table;
3828 struct bgp_static *bgp_static;
3829
3830 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3831 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3832 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3833 if (rn->info != NULL)
3834 {
3835 if (safi == SAFI_MPLS_VPN)
3836 {
3837 table = rn->info;
3838
3839 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3840 {
3841 bgp_static = rn->info;
3842 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3843 AFI_IP, SAFI_MPLS_VPN,
3844 (struct prefix_rd *)&rn->p,
3845 bgp_static->tag);
3846 bgp_static_free (bgp_static);
3847 rn->info = NULL;
3848 bgp_unlock_node (rn);
3849 }
3850 }
3851 else
3852 {
3853 bgp_static = rn->info;
3854 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3855 bgp_static_free (bgp_static);
3856 rn->info = NULL;
3857 bgp_unlock_node (rn);
3858 }
3859 }
3860}
3861
3862int
paulfd79ac92004-10-13 05:06:08 +00003863bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3864 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003865{
3866 int ret;
3867 struct prefix p;
3868 struct prefix_rd prd;
3869 struct bgp *bgp;
3870 struct bgp_node *prn;
3871 struct bgp_node *rn;
3872 struct bgp_table *table;
3873 struct bgp_static *bgp_static;
3874 u_char tag[3];
3875
3876 bgp = vty->index;
3877
3878 ret = str2prefix (ip_str, &p);
3879 if (! ret)
3880 {
3881 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3882 return CMD_WARNING;
3883 }
3884 apply_mask (&p);
3885
3886 ret = str2prefix_rd (rd_str, &prd);
3887 if (! ret)
3888 {
3889 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3890 return CMD_WARNING;
3891 }
3892
3893 ret = str2tag (tag_str, tag);
3894 if (! ret)
3895 {
3896 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3897 return CMD_WARNING;
3898 }
3899
3900 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3901 (struct prefix *)&prd);
3902 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003903 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003904 else
3905 bgp_unlock_node (prn);
3906 table = prn->info;
3907
3908 rn = bgp_node_get (table, &p);
3909
3910 if (rn->info)
3911 {
3912 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3913 bgp_unlock_node (rn);
3914 }
3915 else
3916 {
3917 /* New configuration. */
3918 bgp_static = bgp_static_new ();
3919 bgp_static->valid = 1;
3920 memcpy (bgp_static->tag, tag, 3);
3921 rn->info = bgp_static;
3922
3923 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3924 }
3925
3926 return CMD_SUCCESS;
3927}
3928
3929/* Configure static BGP network. */
3930int
paulfd79ac92004-10-13 05:06:08 +00003931bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3932 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003933{
3934 int ret;
3935 struct bgp *bgp;
3936 struct prefix p;
3937 struct prefix_rd prd;
3938 struct bgp_node *prn;
3939 struct bgp_node *rn;
3940 struct bgp_table *table;
3941 struct bgp_static *bgp_static;
3942 u_char tag[3];
3943
3944 bgp = vty->index;
3945
3946 /* Convert IP prefix string to struct prefix. */
3947 ret = str2prefix (ip_str, &p);
3948 if (! ret)
3949 {
3950 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3951 return CMD_WARNING;
3952 }
3953 apply_mask (&p);
3954
3955 ret = str2prefix_rd (rd_str, &prd);
3956 if (! ret)
3957 {
3958 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3959 return CMD_WARNING;
3960 }
3961
3962 ret = str2tag (tag_str, tag);
3963 if (! ret)
3964 {
3965 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3966 return CMD_WARNING;
3967 }
3968
3969 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3970 (struct prefix *)&prd);
3971 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003972 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003973 else
3974 bgp_unlock_node (prn);
3975 table = prn->info;
3976
3977 rn = bgp_node_lookup (table, &p);
3978
3979 if (rn)
3980 {
3981 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3982
3983 bgp_static = rn->info;
3984 bgp_static_free (bgp_static);
3985 rn->info = NULL;
3986 bgp_unlock_node (rn);
3987 bgp_unlock_node (rn);
3988 }
3989 else
3990 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3991
3992 return CMD_SUCCESS;
3993}
3994
3995DEFUN (bgp_network,
3996 bgp_network_cmd,
3997 "network A.B.C.D/M",
3998 "Specify a network to announce via BGP\n"
3999 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4000{
Paul Jakma41367172007-08-06 15:24:51 +00004001 u_char ttl = 0;
4002
4003 if (argc == 2)
4004 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4005
paul718e3742002-12-13 20:15:29 +00004006 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004007 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004008}
4009
Paul Jakma41367172007-08-06 15:24:51 +00004010ALIAS (bgp_network,
4011 bgp_network_ttl_cmd,
4012 "network A.B.C.D/M pathlimit <0-255>",
4013 "Specify a network to announce via BGP\n"
4014 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4015 "AS-Path hopcount limit attribute\n"
4016 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4017
paul718e3742002-12-13 20:15:29 +00004018DEFUN (bgp_network_route_map,
4019 bgp_network_route_map_cmd,
4020 "network A.B.C.D/M route-map WORD",
4021 "Specify a network to announce via BGP\n"
4022 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4023 "Route-map to modify the attributes\n"
4024 "Name of the route map\n")
4025{
4026 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004027 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004028}
4029
4030DEFUN (bgp_network_backdoor,
4031 bgp_network_backdoor_cmd,
4032 "network A.B.C.D/M backdoor",
4033 "Specify a network to announce via BGP\n"
4034 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4035 "Specify a BGP backdoor route\n")
4036{
Paul Jakma41367172007-08-06 15:24:51 +00004037 u_char ttl = 0;
4038
4039 if (argc == 2)
4040 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4041
4042 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4043 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004044}
4045
Paul Jakma41367172007-08-06 15:24:51 +00004046ALIAS (bgp_network_backdoor,
4047 bgp_network_backdoor_ttl_cmd,
4048 "network A.B.C.D/M backdoor pathlimit <0-255>",
4049 "Specify a network to announce via BGP\n"
4050 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4051 "Specify a BGP backdoor route\n"
4052 "AS-Path hopcount limit attribute\n"
4053 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4054
paul718e3742002-12-13 20:15:29 +00004055DEFUN (bgp_network_mask,
4056 bgp_network_mask_cmd,
4057 "network A.B.C.D mask A.B.C.D",
4058 "Specify a network to announce via BGP\n"
4059 "Network number\n"
4060 "Network mask\n"
4061 "Network mask\n")
4062{
4063 int ret;
4064 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004065 u_char ttl = 0;
4066
4067 if (argc == 3)
4068 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4069
paul718e3742002-12-13 20:15:29 +00004070 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4071 if (! ret)
4072 {
4073 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4074 return CMD_WARNING;
4075 }
4076
4077 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004078 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004079}
4080
Paul Jakma41367172007-08-06 15:24:51 +00004081ALIAS (bgp_network_mask,
4082 bgp_network_mask_ttl_cmd,
4083 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4084 "Specify a network to announce via BGP\n"
4085 "Network number\n"
4086 "Network mask\n"
4087 "Network mask\n"
4088 "AS-Path hopcount limit attribute\n"
4089 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4090
paul718e3742002-12-13 20:15:29 +00004091DEFUN (bgp_network_mask_route_map,
4092 bgp_network_mask_route_map_cmd,
4093 "network A.B.C.D mask A.B.C.D route-map WORD",
4094 "Specify a network to announce via BGP\n"
4095 "Network number\n"
4096 "Network mask\n"
4097 "Network mask\n"
4098 "Route-map to modify the attributes\n"
4099 "Name of the route map\n")
4100{
4101 int ret;
4102 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004103
paul718e3742002-12-13 20:15:29 +00004104 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4105 if (! ret)
4106 {
4107 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4108 return CMD_WARNING;
4109 }
4110
4111 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004112 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004113}
4114
4115DEFUN (bgp_network_mask_backdoor,
4116 bgp_network_mask_backdoor_cmd,
4117 "network A.B.C.D mask A.B.C.D backdoor",
4118 "Specify a network to announce via BGP\n"
4119 "Network number\n"
4120 "Network mask\n"
4121 "Network mask\n"
4122 "Specify a BGP backdoor route\n")
4123{
4124 int ret;
4125 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004126 u_char ttl = 0;
4127
4128 if (argc == 3)
4129 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004130
4131 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4132 if (! ret)
4133 {
4134 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4135 return CMD_WARNING;
4136 }
4137
Paul Jakma41367172007-08-06 15:24:51 +00004138 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4139 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004140}
4141
Paul Jakma41367172007-08-06 15:24:51 +00004142ALIAS (bgp_network_mask_backdoor,
4143 bgp_network_mask_backdoor_ttl_cmd,
4144 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4145 "Specify a network to announce via BGP\n"
4146 "Network number\n"
4147 "Network mask\n"
4148 "Network mask\n"
4149 "Specify a BGP backdoor route\n"
4150 "AS-Path hopcount limit attribute\n"
4151 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4152
paul718e3742002-12-13 20:15:29 +00004153DEFUN (bgp_network_mask_natural,
4154 bgp_network_mask_natural_cmd,
4155 "network A.B.C.D",
4156 "Specify a network to announce via BGP\n"
4157 "Network number\n")
4158{
4159 int ret;
4160 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004161 u_char ttl = 0;
4162
4163 if (argc == 2)
4164 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004165
4166 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4167 if (! ret)
4168 {
4169 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4170 return CMD_WARNING;
4171 }
4172
4173 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004174 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004175}
4176
Paul Jakma41367172007-08-06 15:24:51 +00004177ALIAS (bgp_network_mask_natural,
4178 bgp_network_mask_natural_ttl_cmd,
4179 "network A.B.C.D pathlimit <0-255>",
4180 "Specify a network to announce via BGP\n"
4181 "Network number\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_route_map,
4186 bgp_network_mask_natural_route_map_cmd,
4187 "network A.B.C.D route-map WORD",
4188 "Specify a network to announce via BGP\n"
4189 "Network number\n"
4190 "Route-map to modify the attributes\n"
4191 "Name of the route map\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
4195
4196 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202
4203 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004204 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004205}
4206
4207DEFUN (bgp_network_mask_natural_backdoor,
4208 bgp_network_mask_natural_backdoor_cmd,
4209 "network A.B.C.D backdoor",
4210 "Specify a network to announce via BGP\n"
4211 "Network number\n"
4212 "Specify a BGP backdoor route\n")
4213{
4214 int ret;
4215 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004216 u_char ttl = 0;
4217
4218 if (argc == 2)
4219 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004220
4221 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4222 if (! ret)
4223 {
4224 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4225 return CMD_WARNING;
4226 }
4227
Paul Jakma41367172007-08-06 15:24:51 +00004228 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4229 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004230}
4231
Paul Jakma41367172007-08-06 15:24:51 +00004232ALIAS (bgp_network_mask_natural_backdoor,
4233 bgp_network_mask_natural_backdoor_ttl_cmd,
4234 "network A.B.C.D backdoor pathlimit (1-255>",
4235 "Specify a network to announce via BGP\n"
4236 "Network number\n"
4237 "Specify a BGP backdoor route\n"
4238 "AS-Path hopcount limit attribute\n"
4239 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4240
paul718e3742002-12-13 20:15:29 +00004241DEFUN (no_bgp_network,
4242 no_bgp_network_cmd,
4243 "no network A.B.C.D/M",
4244 NO_STR
4245 "Specify a network to announce via BGP\n"
4246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4247{
4248 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4249 bgp_node_safi (vty));
4250}
4251
4252ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004253 no_bgp_network_ttl_cmd,
4254 "no network A.B.C.D/M pathlimit <0-255>",
4255 NO_STR
4256 "Specify a network to announce via BGP\n"
4257 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4258 "AS-Path hopcount limit attribute\n"
4259 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4260
4261ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004262 no_bgp_network_route_map_cmd,
4263 "no network A.B.C.D/M route-map WORD",
4264 NO_STR
4265 "Specify a network to announce via BGP\n"
4266 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4267 "Route-map to modify the attributes\n"
4268 "Name of the route map\n")
4269
4270ALIAS (no_bgp_network,
4271 no_bgp_network_backdoor_cmd,
4272 "no network A.B.C.D/M backdoor",
4273 NO_STR
4274 "Specify a network to announce via BGP\n"
4275 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4276 "Specify a BGP backdoor route\n")
4277
Paul Jakma41367172007-08-06 15:24:51 +00004278ALIAS (no_bgp_network,
4279 no_bgp_network_backdoor_ttl_cmd,
4280 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4281 NO_STR
4282 "Specify a network to announce via BGP\n"
4283 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4284 "Specify a BGP backdoor route\n"
4285 "AS-Path hopcount limit attribute\n"
4286 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4287
paul718e3742002-12-13 20:15:29 +00004288DEFUN (no_bgp_network_mask,
4289 no_bgp_network_mask_cmd,
4290 "no network A.B.C.D mask A.B.C.D",
4291 NO_STR
4292 "Specify a network to announce via BGP\n"
4293 "Network number\n"
4294 "Network mask\n"
4295 "Network mask\n")
4296{
4297 int ret;
4298 char prefix_str[BUFSIZ];
4299
4300 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4301 if (! ret)
4302 {
4303 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4304 return CMD_WARNING;
4305 }
4306
4307 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4308 bgp_node_safi (vty));
4309}
4310
Paul Jakma41367172007-08-06 15:24:51 +00004311ALIAS (no_bgp_network,
4312 no_bgp_network_mask_ttl_cmd,
4313 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Network mask\n"
4318 "Network mask\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321
paul718e3742002-12-13 20:15:29 +00004322ALIAS (no_bgp_network_mask,
4323 no_bgp_network_mask_route_map_cmd,
4324 "no network A.B.C.D mask A.B.C.D route-map WORD",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Route-map to modify the attributes\n"
4331 "Name of the route map\n")
4332
4333ALIAS (no_bgp_network_mask,
4334 no_bgp_network_mask_backdoor_cmd,
4335 "no network A.B.C.D mask A.B.C.D backdoor",
4336 NO_STR
4337 "Specify a network to announce via BGP\n"
4338 "Network number\n"
4339 "Network mask\n"
4340 "Network mask\n"
4341 "Specify a BGP backdoor route\n")
4342
Paul Jakma41367172007-08-06 15:24:51 +00004343ALIAS (no_bgp_network_mask,
4344 no_bgp_network_mask_backdoor_ttl_cmd,
4345 "no network A.B.C.D mask A.B.C.D backdoor 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 "Specify a BGP backdoor route\n"
4352 "AS-Path hopcount limit attribute\n"
4353 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4354
paul718e3742002-12-13 20:15:29 +00004355DEFUN (no_bgp_network_mask_natural,
4356 no_bgp_network_mask_natural_cmd,
4357 "no network A.B.C.D",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "Network number\n")
4361{
4362 int ret;
4363 char prefix_str[BUFSIZ];
4364
4365 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4366 if (! ret)
4367 {
4368 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4369 return CMD_WARNING;
4370 }
4371
4372 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4373 bgp_node_safi (vty));
4374}
4375
4376ALIAS (no_bgp_network_mask_natural,
4377 no_bgp_network_mask_natural_route_map_cmd,
4378 "no network A.B.C.D route-map WORD",
4379 NO_STR
4380 "Specify a network to announce via BGP\n"
4381 "Network number\n"
4382 "Route-map to modify the attributes\n"
4383 "Name of the route map\n")
4384
4385ALIAS (no_bgp_network_mask_natural,
4386 no_bgp_network_mask_natural_backdoor_cmd,
4387 "no network A.B.C.D backdoor",
4388 NO_STR
4389 "Specify a network to announce via BGP\n"
4390 "Network number\n"
4391 "Specify a BGP backdoor route\n")
4392
Paul Jakma41367172007-08-06 15:24:51 +00004393ALIAS (no_bgp_network_mask_natural,
4394 no_bgp_network_mask_natural_ttl_cmd,
4395 "no network A.B.C.D pathlimit <0-255>",
4396 NO_STR
4397 "Specify a network to announce via BGP\n"
4398 "Network number\n"
4399 "AS-Path hopcount limit attribute\n"
4400 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4401
4402ALIAS (no_bgp_network_mask_natural,
4403 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4404 "no network A.B.C.D backdoor pathlimit <0-255>",
4405 NO_STR
4406 "Specify a network to announce via BGP\n"
4407 "Network number\n"
4408 "Specify a BGP backdoor route\n"
4409 "AS-Path hopcount limit attribute\n"
4410 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4411
paul718e3742002-12-13 20:15:29 +00004412#ifdef HAVE_IPV6
4413DEFUN (ipv6_bgp_network,
4414 ipv6_bgp_network_cmd,
4415 "network X:X::X:X/M",
4416 "Specify a network to announce via BGP\n"
4417 "IPv6 prefix <network>/<length>\n")
4418{
Paul Jakma41367172007-08-06 15:24:51 +00004419 u_char ttl = 0;
4420
4421 if (argc == 2)
4422 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4423
4424 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4425 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004426}
4427
Paul Jakma41367172007-08-06 15:24:51 +00004428ALIAS (ipv6_bgp_network,
4429 ipv6_bgp_network_ttl_cmd,
4430 "network X:X::X:X/M pathlimit <0-255>",
4431 "Specify a network to announce via BGP\n"
4432 "IPv6 prefix <network>/<length>\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435
paul718e3742002-12-13 20:15:29 +00004436DEFUN (ipv6_bgp_network_route_map,
4437 ipv6_bgp_network_route_map_cmd,
4438 "network X:X::X:X/M route-map WORD",
4439 "Specify a network to announce via BGP\n"
4440 "IPv6 prefix <network>/<length>\n"
4441 "Route-map to modify the attributes\n"
4442 "Name of the route map\n")
4443{
4444 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004445 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004446}
4447
4448DEFUN (no_ipv6_bgp_network,
4449 no_ipv6_bgp_network_cmd,
4450 "no network X:X::X:X/M",
4451 NO_STR
4452 "Specify a network to announce via BGP\n"
4453 "IPv6 prefix <network>/<length>\n")
4454{
4455 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4456}
4457
4458ALIAS (no_ipv6_bgp_network,
4459 no_ipv6_bgp_network_route_map_cmd,
4460 "no network X:X::X:X/M route-map WORD",
4461 NO_STR
4462 "Specify a network to announce via BGP\n"
4463 "IPv6 prefix <network>/<length>\n"
4464 "Route-map to modify the attributes\n"
4465 "Name of the route map\n")
4466
Paul Jakma41367172007-08-06 15:24:51 +00004467ALIAS (no_ipv6_bgp_network,
4468 no_ipv6_bgp_network_ttl_cmd,
4469 "no network X:X::X:X/M pathlimit <0-255>",
4470 NO_STR
4471 "Specify a network to announce via BGP\n"
4472 "IPv6 prefix <network>/<length>\n"
4473 "AS-Path hopcount limit attribute\n"
4474 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4475
paul718e3742002-12-13 20:15:29 +00004476ALIAS (ipv6_bgp_network,
4477 old_ipv6_bgp_network_cmd,
4478 "ipv6 bgp network X:X::X:X/M",
4479 IPV6_STR
4480 BGP_STR
4481 "Specify a network to announce via BGP\n"
4482 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4483
4484ALIAS (no_ipv6_bgp_network,
4485 old_no_ipv6_bgp_network_cmd,
4486 "no ipv6 bgp network X:X::X:X/M",
4487 NO_STR
4488 IPV6_STR
4489 BGP_STR
4490 "Specify a network to announce via BGP\n"
4491 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4492#endif /* HAVE_IPV6 */
4493
4494/* Aggreagete address:
4495
4496 advertise-map Set condition to advertise attribute
4497 as-set Generate AS set path information
4498 attribute-map Set attributes of aggregate
4499 route-map Set parameters of aggregate
4500 summary-only Filter more specific routes from updates
4501 suppress-map Conditionally filter more specific routes from updates
4502 <cr>
4503 */
4504struct bgp_aggregate
4505{
4506 /* Summary-only flag. */
4507 u_char summary_only;
4508
4509 /* AS set generation. */
4510 u_char as_set;
4511
4512 /* Route-map for aggregated route. */
4513 struct route_map *map;
4514
4515 /* Suppress-count. */
4516 unsigned long count;
4517
4518 /* SAFI configuration. */
4519 safi_t safi;
4520};
4521
paul94f2b392005-06-28 12:44:16 +00004522static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004523bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004524{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004525 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004526}
4527
paul94f2b392005-06-28 12:44:16 +00004528static void
paul718e3742002-12-13 20:15:29 +00004529bgp_aggregate_free (struct bgp_aggregate *aggregate)
4530{
4531 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4532}
4533
paul94f2b392005-06-28 12:44:16 +00004534static void
paul718e3742002-12-13 20:15:29 +00004535bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4536 afi_t afi, safi_t safi, struct bgp_info *del,
4537 struct bgp_aggregate *aggregate)
4538{
4539 struct bgp_table *table;
4540 struct bgp_node *top;
4541 struct bgp_node *rn;
4542 u_char origin;
4543 struct aspath *aspath = NULL;
4544 struct aspath *asmerge = NULL;
4545 struct community *community = NULL;
4546 struct community *commerge = NULL;
4547 struct in_addr nexthop;
4548 u_int32_t med = 0;
4549 struct bgp_info *ri;
4550 struct bgp_info *new;
4551 int first = 1;
4552 unsigned long match = 0;
4553
4554 /* Record adding route's nexthop and med. */
4555 if (rinew)
4556 {
4557 nexthop = rinew->attr->nexthop;
4558 med = rinew->attr->med;
4559 }
4560
4561 /* ORIGIN attribute: If at least one route among routes that are
4562 aggregated has ORIGIN with the value INCOMPLETE, then the
4563 aggregated route must have the ORIGIN attribute with the value
4564 INCOMPLETE. Otherwise, if at least one route among routes that
4565 are aggregated has ORIGIN with the value EGP, then the aggregated
4566 route must have the origin attribute with the value EGP. In all
4567 other case the value of the ORIGIN attribute of the aggregated
4568 route is INTERNAL. */
4569 origin = BGP_ORIGIN_IGP;
4570
4571 table = bgp->rib[afi][safi];
4572
4573 top = bgp_node_get (table, p);
4574 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4575 if (rn->p.prefixlen > p->prefixlen)
4576 {
4577 match = 0;
4578
4579 for (ri = rn->info; ri; ri = ri->next)
4580 {
4581 if (BGP_INFO_HOLDDOWN (ri))
4582 continue;
4583
4584 if (del && ri == del)
4585 continue;
4586
4587 if (! rinew && first)
4588 {
4589 nexthop = ri->attr->nexthop;
4590 med = ri->attr->med;
4591 first = 0;
4592 }
4593
4594#ifdef AGGREGATE_NEXTHOP_CHECK
4595 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4596 || ri->attr->med != med)
4597 {
4598 if (aspath)
4599 aspath_free (aspath);
4600 if (community)
4601 community_free (community);
4602 bgp_unlock_node (rn);
4603 bgp_unlock_node (top);
4604 return;
4605 }
4606#endif /* AGGREGATE_NEXTHOP_CHECK */
4607
4608 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4609 {
4610 if (aggregate->summary_only)
4611 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004612 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004613 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004614 match++;
4615 }
4616
4617 aggregate->count++;
4618
4619 if (aggregate->as_set)
4620 {
4621 if (origin < ri->attr->origin)
4622 origin = ri->attr->origin;
4623
4624 if (aspath)
4625 {
4626 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4627 aspath_free (aspath);
4628 aspath = asmerge;
4629 }
4630 else
4631 aspath = aspath_dup (ri->attr->aspath);
4632
4633 if (ri->attr->community)
4634 {
4635 if (community)
4636 {
4637 commerge = community_merge (community,
4638 ri->attr->community);
4639 community = community_uniq_sort (commerge);
4640 community_free (commerge);
4641 }
4642 else
4643 community = community_dup (ri->attr->community);
4644 }
4645 }
4646 }
4647 }
4648 if (match)
4649 bgp_process (bgp, rn, afi, safi);
4650 }
4651 bgp_unlock_node (top);
4652
4653 if (rinew)
4654 {
4655 aggregate->count++;
4656
4657 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004658 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004659
4660 if (aggregate->as_set)
4661 {
4662 if (origin < rinew->attr->origin)
4663 origin = rinew->attr->origin;
4664
4665 if (aspath)
4666 {
4667 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4668 aspath_free (aspath);
4669 aspath = asmerge;
4670 }
4671 else
4672 aspath = aspath_dup (rinew->attr->aspath);
4673
4674 if (rinew->attr->community)
4675 {
4676 if (community)
4677 {
4678 commerge = community_merge (community,
4679 rinew->attr->community);
4680 community = community_uniq_sort (commerge);
4681 community_free (commerge);
4682 }
4683 else
4684 community = community_dup (rinew->attr->community);
4685 }
4686 }
4687 }
4688
4689 if (aggregate->count > 0)
4690 {
4691 rn = bgp_node_get (table, p);
4692 new = bgp_info_new ();
4693 new->type = ZEBRA_ROUTE_BGP;
4694 new->sub_type = BGP_ROUTE_AGGREGATE;
4695 new->peer = bgp->peer_self;
4696 SET_FLAG (new->flags, BGP_INFO_VALID);
4697 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4698 new->uptime = time (NULL);
4699
4700 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004701 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004702 bgp_process (bgp, rn, afi, safi);
4703 }
4704 else
4705 {
4706 if (aspath)
4707 aspath_free (aspath);
4708 if (community)
4709 community_free (community);
4710 }
4711}
4712
4713void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4714 struct bgp_aggregate *);
4715
4716void
4717bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4718 struct bgp_info *ri, afi_t afi, safi_t safi)
4719{
4720 struct bgp_node *child;
4721 struct bgp_node *rn;
4722 struct bgp_aggregate *aggregate;
4723
4724 /* MPLS-VPN aggregation is not yet supported. */
4725 if (safi == SAFI_MPLS_VPN)
4726 return;
4727
4728 if (p->prefixlen == 0)
4729 return;
4730
4731 if (BGP_INFO_HOLDDOWN (ri))
4732 return;
4733
4734 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4735
4736 /* Aggregate address configuration check. */
4737 for (rn = child; rn; rn = rn->parent)
4738 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4739 {
4740 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004741 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004742 }
4743 bgp_unlock_node (child);
4744}
4745
4746void
4747bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4748 struct bgp_info *del, afi_t afi, safi_t safi)
4749{
4750 struct bgp_node *child;
4751 struct bgp_node *rn;
4752 struct bgp_aggregate *aggregate;
4753
4754 /* MPLS-VPN aggregation is not yet supported. */
4755 if (safi == SAFI_MPLS_VPN)
4756 return;
4757
4758 if (p->prefixlen == 0)
4759 return;
4760
4761 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4762
4763 /* Aggregate address configuration check. */
4764 for (rn = child; rn; rn = rn->parent)
4765 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4766 {
4767 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004768 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004769 }
4770 bgp_unlock_node (child);
4771}
4772
paul94f2b392005-06-28 12:44:16 +00004773static void
paul718e3742002-12-13 20:15:29 +00004774bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4775 struct bgp_aggregate *aggregate)
4776{
4777 struct bgp_table *table;
4778 struct bgp_node *top;
4779 struct bgp_node *rn;
4780 struct bgp_info *new;
4781 struct bgp_info *ri;
4782 unsigned long match;
4783 u_char origin = BGP_ORIGIN_IGP;
4784 struct aspath *aspath = NULL;
4785 struct aspath *asmerge = NULL;
4786 struct community *community = NULL;
4787 struct community *commerge = NULL;
4788
4789 table = bgp->rib[afi][safi];
4790
4791 /* Sanity check. */
4792 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4793 return;
4794 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4795 return;
4796
4797 /* If routes exists below this node, generate aggregate routes. */
4798 top = bgp_node_get (table, p);
4799 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4800 if (rn->p.prefixlen > p->prefixlen)
4801 {
4802 match = 0;
4803
4804 for (ri = rn->info; ri; ri = ri->next)
4805 {
4806 if (BGP_INFO_HOLDDOWN (ri))
4807 continue;
4808
4809 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4810 {
4811 /* summary-only aggregate route suppress aggregated
4812 route announcement. */
4813 if (aggregate->summary_only)
4814 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004815 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004816 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004817 match++;
4818 }
4819 /* as-set aggregate route generate origin, as path,
4820 community aggregation. */
4821 if (aggregate->as_set)
4822 {
4823 if (origin < ri->attr->origin)
4824 origin = ri->attr->origin;
4825
4826 if (aspath)
4827 {
4828 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4829 aspath_free (aspath);
4830 aspath = asmerge;
4831 }
4832 else
4833 aspath = aspath_dup (ri->attr->aspath);
4834
4835 if (ri->attr->community)
4836 {
4837 if (community)
4838 {
4839 commerge = community_merge (community,
4840 ri->attr->community);
4841 community = community_uniq_sort (commerge);
4842 community_free (commerge);
4843 }
4844 else
4845 community = community_dup (ri->attr->community);
4846 }
4847 }
4848 aggregate->count++;
4849 }
4850 }
4851
4852 /* If this node is suppressed, process the change. */
4853 if (match)
4854 bgp_process (bgp, rn, afi, safi);
4855 }
4856 bgp_unlock_node (top);
4857
4858 /* Add aggregate route to BGP table. */
4859 if (aggregate->count)
4860 {
4861 rn = bgp_node_get (table, p);
4862
4863 new = bgp_info_new ();
4864 new->type = ZEBRA_ROUTE_BGP;
4865 new->sub_type = BGP_ROUTE_AGGREGATE;
4866 new->peer = bgp->peer_self;
4867 SET_FLAG (new->flags, BGP_INFO_VALID);
4868 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4869 new->uptime = time (NULL);
4870
4871 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004872 bgp_unlock_node (rn);
4873
paul718e3742002-12-13 20:15:29 +00004874 /* Process change. */
4875 bgp_process (bgp, rn, afi, safi);
4876 }
4877}
4878
4879void
4880bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4881 safi_t safi, struct bgp_aggregate *aggregate)
4882{
4883 struct bgp_table *table;
4884 struct bgp_node *top;
4885 struct bgp_node *rn;
4886 struct bgp_info *ri;
4887 unsigned long match;
4888
4889 table = bgp->rib[afi][safi];
4890
4891 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4892 return;
4893 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4894 return;
4895
4896 /* If routes exists below this node, generate aggregate routes. */
4897 top = bgp_node_get (table, p);
4898 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4899 if (rn->p.prefixlen > p->prefixlen)
4900 {
4901 match = 0;
4902
4903 for (ri = rn->info; ri; ri = ri->next)
4904 {
4905 if (BGP_INFO_HOLDDOWN (ri))
4906 continue;
4907
4908 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4909 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004910 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004911 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004912 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004913
Paul Jakmafb982c22007-05-04 20:15:47 +00004914 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004915 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004916 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004917 match++;
4918 }
4919 }
4920 aggregate->count--;
4921 }
4922 }
4923
Paul Jakmafb982c22007-05-04 20:15:47 +00004924 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004925 if (match)
4926 bgp_process (bgp, rn, afi, safi);
4927 }
4928 bgp_unlock_node (top);
4929
4930 /* Delete aggregate route from BGP table. */
4931 rn = bgp_node_get (table, p);
4932
4933 for (ri = rn->info; ri; ri = ri->next)
4934 if (ri->peer == bgp->peer_self
4935 && ri->type == ZEBRA_ROUTE_BGP
4936 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4937 break;
4938
4939 /* Withdraw static BGP route from routing table. */
4940 if (ri)
4941 {
paul718e3742002-12-13 20:15:29 +00004942 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004943 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004944 }
4945
4946 /* Unlock bgp_node_lookup. */
4947 bgp_unlock_node (rn);
4948}
4949
4950/* Aggregate route attribute. */
4951#define AGGREGATE_SUMMARY_ONLY 1
4952#define AGGREGATE_AS_SET 1
4953
paul94f2b392005-06-28 12:44:16 +00004954static int
paulfd79ac92004-10-13 05:06:08 +00004955bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4956 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004957 u_char summary_only, u_char as_set)
4958{
4959 int ret;
4960 struct prefix p;
4961 struct bgp_node *rn;
4962 struct bgp *bgp;
4963 struct bgp_aggregate *aggregate;
4964
4965 /* Convert string to prefix structure. */
4966 ret = str2prefix (prefix_str, &p);
4967 if (!ret)
4968 {
4969 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4970 return CMD_WARNING;
4971 }
4972 apply_mask (&p);
4973
4974 /* Get BGP structure. */
4975 bgp = vty->index;
4976
4977 /* Old configuration check. */
4978 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4979
4980 if (rn->info)
4981 {
4982 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4983 bgp_unlock_node (rn);
4984 return CMD_WARNING;
4985 }
4986
4987 /* Make aggregate address structure. */
4988 aggregate = bgp_aggregate_new ();
4989 aggregate->summary_only = summary_only;
4990 aggregate->as_set = as_set;
4991 aggregate->safi = safi;
4992 rn->info = aggregate;
4993
4994 /* Aggregate address insert into BGP routing table. */
4995 if (safi & SAFI_UNICAST)
4996 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4997 if (safi & SAFI_MULTICAST)
4998 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4999
5000 return CMD_SUCCESS;
5001}
5002
paul94f2b392005-06-28 12:44:16 +00005003static int
paulfd79ac92004-10-13 05:06:08 +00005004bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5005 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00005006{
5007 int ret;
5008 struct prefix p;
5009 struct bgp_node *rn;
5010 struct bgp *bgp;
5011 struct bgp_aggregate *aggregate;
5012
5013 /* Convert string to prefix structure. */
5014 ret = str2prefix (prefix_str, &p);
5015 if (!ret)
5016 {
5017 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5018 return CMD_WARNING;
5019 }
5020 apply_mask (&p);
5021
5022 /* Get BGP structure. */
5023 bgp = vty->index;
5024
5025 /* Old configuration check. */
5026 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5027 if (! rn)
5028 {
5029 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5030 VTY_NEWLINE);
5031 return CMD_WARNING;
5032 }
5033
5034 aggregate = rn->info;
5035 if (aggregate->safi & SAFI_UNICAST)
5036 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5037 if (aggregate->safi & SAFI_MULTICAST)
5038 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5039
5040 /* Unlock aggregate address configuration. */
5041 rn->info = NULL;
5042 bgp_aggregate_free (aggregate);
5043 bgp_unlock_node (rn);
5044 bgp_unlock_node (rn);
5045
5046 return CMD_SUCCESS;
5047}
5048
5049DEFUN (aggregate_address,
5050 aggregate_address_cmd,
5051 "aggregate-address A.B.C.D/M",
5052 "Configure BGP aggregate entries\n"
5053 "Aggregate prefix\n")
5054{
5055 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5056}
5057
5058DEFUN (aggregate_address_mask,
5059 aggregate_address_mask_cmd,
5060 "aggregate-address A.B.C.D A.B.C.D",
5061 "Configure BGP aggregate entries\n"
5062 "Aggregate address\n"
5063 "Aggregate mask\n")
5064{
5065 int ret;
5066 char prefix_str[BUFSIZ];
5067
5068 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5069
5070 if (! ret)
5071 {
5072 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5073 return CMD_WARNING;
5074 }
5075
5076 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5077 0, 0);
5078}
5079
5080DEFUN (aggregate_address_summary_only,
5081 aggregate_address_summary_only_cmd,
5082 "aggregate-address A.B.C.D/M summary-only",
5083 "Configure BGP aggregate entries\n"
5084 "Aggregate prefix\n"
5085 "Filter more specific routes from updates\n")
5086{
5087 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5088 AGGREGATE_SUMMARY_ONLY, 0);
5089}
5090
5091DEFUN (aggregate_address_mask_summary_only,
5092 aggregate_address_mask_summary_only_cmd,
5093 "aggregate-address A.B.C.D A.B.C.D summary-only",
5094 "Configure BGP aggregate entries\n"
5095 "Aggregate address\n"
5096 "Aggregate mask\n"
5097 "Filter more specific routes from updates\n")
5098{
5099 int ret;
5100 char prefix_str[BUFSIZ];
5101
5102 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5103
5104 if (! ret)
5105 {
5106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5107 return CMD_WARNING;
5108 }
5109
5110 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5111 AGGREGATE_SUMMARY_ONLY, 0);
5112}
5113
5114DEFUN (aggregate_address_as_set,
5115 aggregate_address_as_set_cmd,
5116 "aggregate-address A.B.C.D/M as-set",
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate prefix\n"
5119 "Generate AS set path information\n")
5120{
5121 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5122 0, AGGREGATE_AS_SET);
5123}
5124
5125DEFUN (aggregate_address_mask_as_set,
5126 aggregate_address_mask_as_set_cmd,
5127 "aggregate-address A.B.C.D A.B.C.D as-set",
5128 "Configure BGP aggregate entries\n"
5129 "Aggregate address\n"
5130 "Aggregate mask\n"
5131 "Generate AS set path information\n")
5132{
5133 int ret;
5134 char prefix_str[BUFSIZ];
5135
5136 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5137
5138 if (! ret)
5139 {
5140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5141 return CMD_WARNING;
5142 }
5143
5144 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5145 0, AGGREGATE_AS_SET);
5146}
5147
5148
5149DEFUN (aggregate_address_as_set_summary,
5150 aggregate_address_as_set_summary_cmd,
5151 "aggregate-address A.B.C.D/M as-set summary-only",
5152 "Configure BGP aggregate entries\n"
5153 "Aggregate prefix\n"
5154 "Generate AS set path information\n"
5155 "Filter more specific routes from updates\n")
5156{
5157 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5158 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5159}
5160
5161ALIAS (aggregate_address_as_set_summary,
5162 aggregate_address_summary_as_set_cmd,
5163 "aggregate-address A.B.C.D/M summary-only as-set",
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate prefix\n"
5166 "Filter more specific routes from updates\n"
5167 "Generate AS set path information\n")
5168
5169DEFUN (aggregate_address_mask_as_set_summary,
5170 aggregate_address_mask_as_set_summary_cmd,
5171 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5172 "Configure BGP aggregate entries\n"
5173 "Aggregate address\n"
5174 "Aggregate mask\n"
5175 "Generate AS set path information\n"
5176 "Filter more specific routes from updates\n")
5177{
5178 int ret;
5179 char prefix_str[BUFSIZ];
5180
5181 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5182
5183 if (! ret)
5184 {
5185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5186 return CMD_WARNING;
5187 }
5188
5189 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5190 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5191}
5192
5193ALIAS (aggregate_address_mask_as_set_summary,
5194 aggregate_address_mask_summary_as_set_cmd,
5195 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5196 "Configure BGP aggregate entries\n"
5197 "Aggregate address\n"
5198 "Aggregate mask\n"
5199 "Filter more specific routes from updates\n"
5200 "Generate AS set path information\n")
5201
5202DEFUN (no_aggregate_address,
5203 no_aggregate_address_cmd,
5204 "no aggregate-address A.B.C.D/M",
5205 NO_STR
5206 "Configure BGP aggregate entries\n"
5207 "Aggregate prefix\n")
5208{
5209 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5210}
5211
5212ALIAS (no_aggregate_address,
5213 no_aggregate_address_summary_only_cmd,
5214 "no aggregate-address A.B.C.D/M summary-only",
5215 NO_STR
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate prefix\n"
5218 "Filter more specific routes from updates\n")
5219
5220ALIAS (no_aggregate_address,
5221 no_aggregate_address_as_set_cmd,
5222 "no aggregate-address A.B.C.D/M as-set",
5223 NO_STR
5224 "Configure BGP aggregate entries\n"
5225 "Aggregate prefix\n"
5226 "Generate AS set path information\n")
5227
5228ALIAS (no_aggregate_address,
5229 no_aggregate_address_as_set_summary_cmd,
5230 "no aggregate-address A.B.C.D/M as-set summary-only",
5231 NO_STR
5232 "Configure BGP aggregate entries\n"
5233 "Aggregate prefix\n"
5234 "Generate AS set path information\n"
5235 "Filter more specific routes from updates\n")
5236
5237ALIAS (no_aggregate_address,
5238 no_aggregate_address_summary_as_set_cmd,
5239 "no aggregate-address A.B.C.D/M summary-only as-set",
5240 NO_STR
5241 "Configure BGP aggregate entries\n"
5242 "Aggregate prefix\n"
5243 "Filter more specific routes from updates\n"
5244 "Generate AS set path information\n")
5245
5246DEFUN (no_aggregate_address_mask,
5247 no_aggregate_address_mask_cmd,
5248 "no aggregate-address A.B.C.D A.B.C.D",
5249 NO_STR
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate address\n"
5252 "Aggregate mask\n")
5253{
5254 int ret;
5255 char prefix_str[BUFSIZ];
5256
5257 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5258
5259 if (! ret)
5260 {
5261 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5262 return CMD_WARNING;
5263 }
5264
5265 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5266}
5267
5268ALIAS (no_aggregate_address_mask,
5269 no_aggregate_address_mask_summary_only_cmd,
5270 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5271 NO_STR
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate address\n"
5274 "Aggregate mask\n"
5275 "Filter more specific routes from updates\n")
5276
5277ALIAS (no_aggregate_address_mask,
5278 no_aggregate_address_mask_as_set_cmd,
5279 "no aggregate-address A.B.C.D A.B.C.D as-set",
5280 NO_STR
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate address\n"
5283 "Aggregate mask\n"
5284 "Generate AS set path information\n")
5285
5286ALIAS (no_aggregate_address_mask,
5287 no_aggregate_address_mask_as_set_summary_cmd,
5288 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5289 NO_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate address\n"
5292 "Aggregate mask\n"
5293 "Generate AS set path information\n"
5294 "Filter more specific routes from updates\n")
5295
5296ALIAS (no_aggregate_address_mask,
5297 no_aggregate_address_mask_summary_as_set_cmd,
5298 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5299 NO_STR
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate address\n"
5302 "Aggregate mask\n"
5303 "Filter more specific routes from updates\n"
5304 "Generate AS set path information\n")
5305
5306#ifdef HAVE_IPV6
5307DEFUN (ipv6_aggregate_address,
5308 ipv6_aggregate_address_cmd,
5309 "aggregate-address X:X::X:X/M",
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate prefix\n")
5312{
5313 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5314}
5315
5316DEFUN (ipv6_aggregate_address_summary_only,
5317 ipv6_aggregate_address_summary_only_cmd,
5318 "aggregate-address X:X::X:X/M summary-only",
5319 "Configure BGP aggregate entries\n"
5320 "Aggregate prefix\n"
5321 "Filter more specific routes from updates\n")
5322{
5323 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5324 AGGREGATE_SUMMARY_ONLY, 0);
5325}
5326
5327DEFUN (no_ipv6_aggregate_address,
5328 no_ipv6_aggregate_address_cmd,
5329 "no aggregate-address X:X::X:X/M",
5330 NO_STR
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate prefix\n")
5333{
5334 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5335}
5336
5337DEFUN (no_ipv6_aggregate_address_summary_only,
5338 no_ipv6_aggregate_address_summary_only_cmd,
5339 "no aggregate-address X:X::X:X/M summary-only",
5340 NO_STR
5341 "Configure BGP aggregate entries\n"
5342 "Aggregate prefix\n"
5343 "Filter more specific routes from updates\n")
5344{
5345 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5346}
5347
5348ALIAS (ipv6_aggregate_address,
5349 old_ipv6_aggregate_address_cmd,
5350 "ipv6 bgp aggregate-address X:X::X:X/M",
5351 IPV6_STR
5352 BGP_STR
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n")
5355
5356ALIAS (ipv6_aggregate_address_summary_only,
5357 old_ipv6_aggregate_address_summary_only_cmd,
5358 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5359 IPV6_STR
5360 BGP_STR
5361 "Configure BGP aggregate entries\n"
5362 "Aggregate prefix\n"
5363 "Filter more specific routes from updates\n")
5364
5365ALIAS (no_ipv6_aggregate_address,
5366 old_no_ipv6_aggregate_address_cmd,
5367 "no ipv6 bgp aggregate-address X:X::X:X/M",
5368 NO_STR
5369 IPV6_STR
5370 BGP_STR
5371 "Configure BGP aggregate entries\n"
5372 "Aggregate prefix\n")
5373
5374ALIAS (no_ipv6_aggregate_address_summary_only,
5375 old_no_ipv6_aggregate_address_summary_only_cmd,
5376 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5377 NO_STR
5378 IPV6_STR
5379 BGP_STR
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n"
5382 "Filter more specific routes from updates\n")
5383#endif /* HAVE_IPV6 */
5384
5385/* Redistribute route treatment. */
5386void
5387bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5388 u_int32_t metric, u_char type)
5389{
5390 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005391 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005392 struct bgp_info *new;
5393 struct bgp_info *bi;
5394 struct bgp_info info;
5395 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005396 struct attr attr = { 0 };
5397 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005398 struct attr *new_attr;
5399 afi_t afi;
5400 int ret;
5401
5402 /* Make default attribute. */
5403 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5404 if (nexthop)
5405 attr.nexthop = *nexthop;
5406
5407 attr.med = metric;
5408 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5409
paul1eb8ef22005-04-07 07:30:20 +00005410 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005411 {
5412 afi = family2afi (p->family);
5413
5414 if (bgp->redist[afi][type])
5415 {
5416 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005418
5419 if (bgp->redist_metric_flag[afi][type])
5420 attr_new.med = bgp->redist_metric[afi][type];
5421
5422 /* Apply route-map. */
5423 if (bgp->rmap[afi][type].map)
5424 {
5425 info.peer = bgp->peer_self;
5426 info.attr = &attr_new;
5427
paulfee0f4c2004-09-13 05:12:46 +00005428 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5429
paul718e3742002-12-13 20:15:29 +00005430 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5431 &info);
paulfee0f4c2004-09-13 05:12:46 +00005432
5433 bgp->peer_self->rmap_type = 0;
5434
paul718e3742002-12-13 20:15:29 +00005435 if (ret == RMAP_DENYMATCH)
5436 {
5437 /* Free uninterned attribute. */
5438 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005439 bgp_attr_extra_free (&attr_new);
5440
paul718e3742002-12-13 20:15:29 +00005441 /* Unintern original. */
5442 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005443 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005444 bgp_redistribute_delete (p, type);
5445 return;
5446 }
5447 }
5448
Paul Jakmafb982c22007-05-04 20:15:47 +00005449 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5450 afi, SAFI_UNICAST, p, NULL);
5451
paul718e3742002-12-13 20:15:29 +00005452 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005453 bgp_attr_extra_free (&attr_new);
5454
paul718e3742002-12-13 20:15:29 +00005455 for (bi = bn->info; bi; bi = bi->next)
5456 if (bi->peer == bgp->peer_self
5457 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5458 break;
5459
5460 if (bi)
5461 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005462 if (attrhash_cmp (bi->attr, new_attr) &&
5463 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005464 {
5465 bgp_attr_unintern (new_attr);
5466 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005467 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005468 bgp_unlock_node (bn);
5469 return;
5470 }
5471 else
5472 {
5473 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005474 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005475
5476 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005477 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5478 bgp_info_restore(bn, bi);
5479 else
5480 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005481 bgp_attr_unintern (bi->attr);
5482 bi->attr = new_attr;
5483 bi->uptime = time (NULL);
5484
5485 /* Process change. */
5486 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5487 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5488 bgp_unlock_node (bn);
5489 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005490 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005491 return;
5492 }
5493 }
5494
5495 new = bgp_info_new ();
5496 new->type = type;
5497 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5498 new->peer = bgp->peer_self;
5499 SET_FLAG (new->flags, BGP_INFO_VALID);
5500 new->attr = new_attr;
5501 new->uptime = time (NULL);
5502
5503 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5504 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005505 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005506 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5507 }
5508 }
5509
5510 /* Unintern original. */
5511 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005512 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005513}
5514
5515void
5516bgp_redistribute_delete (struct prefix *p, u_char type)
5517{
5518 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005519 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005520 afi_t afi;
5521 struct bgp_node *rn;
5522 struct bgp_info *ri;
5523
paul1eb8ef22005-04-07 07:30:20 +00005524 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005525 {
5526 afi = family2afi (p->family);
5527
5528 if (bgp->redist[afi][type])
5529 {
paulfee0f4c2004-09-13 05:12:46 +00005530 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005531
5532 for (ri = rn->info; ri; ri = ri->next)
5533 if (ri->peer == bgp->peer_self
5534 && ri->type == type)
5535 break;
5536
5537 if (ri)
5538 {
5539 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005540 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005541 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005542 }
5543 bgp_unlock_node (rn);
5544 }
5545 }
5546}
5547
5548/* Withdraw specified route type's route. */
5549void
5550bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5551{
5552 struct bgp_node *rn;
5553 struct bgp_info *ri;
5554 struct bgp_table *table;
5555
5556 table = bgp->rib[afi][SAFI_UNICAST];
5557
5558 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5559 {
5560 for (ri = rn->info; ri; ri = ri->next)
5561 if (ri->peer == bgp->peer_self
5562 && ri->type == type)
5563 break;
5564
5565 if (ri)
5566 {
5567 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005568 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005569 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005570 }
5571 }
5572}
5573
5574/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005575static void
paul718e3742002-12-13 20:15:29 +00005576route_vty_out_route (struct prefix *p, struct vty *vty)
5577{
5578 int len;
5579 u_int32_t destination;
5580 char buf[BUFSIZ];
5581
5582 if (p->family == AF_INET)
5583 {
5584 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5585 destination = ntohl (p->u.prefix4.s_addr);
5586
5587 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5588 || (IN_CLASSB (destination) && p->prefixlen == 16)
5589 || (IN_CLASSA (destination) && p->prefixlen == 8)
5590 || p->u.prefix4.s_addr == 0)
5591 {
5592 /* When mask is natural, mask is not displayed. */
5593 }
5594 else
5595 len += vty_out (vty, "/%d", p->prefixlen);
5596 }
5597 else
5598 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5599 p->prefixlen);
5600
5601 len = 17 - len;
5602 if (len < 1)
5603 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5604 else
5605 vty_out (vty, "%*s", len, " ");
5606}
5607
paul718e3742002-12-13 20:15:29 +00005608enum bgp_display_type
5609{
5610 normal_list,
5611};
5612
paulb40d9392005-08-22 22:34:41 +00005613/* Print the short form route status for a bgp_info */
5614static void
5615route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005616{
paulb40d9392005-08-22 22:34:41 +00005617 /* Route status display. */
5618 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5619 vty_out (vty, "R");
5620 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005621 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005622 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005623 vty_out (vty, "s");
5624 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5625 vty_out (vty, "*");
5626 else
5627 vty_out (vty, " ");
5628
5629 /* Selected */
5630 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5631 vty_out (vty, "h");
5632 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5633 vty_out (vty, "d");
5634 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5635 vty_out (vty, ">");
5636 else
5637 vty_out (vty, " ");
5638
5639 /* Internal route. */
5640 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5641 vty_out (vty, "i");
5642 else
paulb40d9392005-08-22 22:34:41 +00005643 vty_out (vty, " ");
5644}
5645
5646/* called from terminal list command */
5647void
5648route_vty_out (struct vty *vty, struct prefix *p,
5649 struct bgp_info *binfo, int display, safi_t safi)
5650{
5651 struct attr *attr;
5652
5653 /* short status lead text */
5654 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005655
5656 /* print prefix and mask */
5657 if (! display)
5658 route_vty_out_route (p, vty);
5659 else
5660 vty_out (vty, "%*s", 17, " ");
5661
5662 /* Print attribute */
5663 attr = binfo->attr;
5664 if (attr)
5665 {
5666 if (p->family == AF_INET)
5667 {
5668 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005669 vty_out (vty, "%-16s",
5670 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005671 else
5672 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5673 }
5674#ifdef HAVE_IPV6
5675 else if (p->family == AF_INET6)
5676 {
5677 int len;
5678 char buf[BUFSIZ];
5679
5680 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005681 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5682 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005683 len = 16 - len;
5684 if (len < 1)
5685 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5686 else
5687 vty_out (vty, "%*s", len, " ");
5688 }
5689#endif /* HAVE_IPV6 */
5690
5691 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5692 vty_out (vty, "%10d", attr->med);
5693 else
5694 vty_out (vty, " ");
5695
5696 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5697 vty_out (vty, "%7d", attr->local_pref);
5698 else
5699 vty_out (vty, " ");
5700
Paul Jakmafb982c22007-05-04 20:15:47 +00005701 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005702
Paul Jakmab2518c12006-05-12 23:48:40 +00005703 /* Print aspath */
5704 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005705 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005706
Paul Jakmab2518c12006-05-12 23:48:40 +00005707 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005708 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005709 }
paul718e3742002-12-13 20:15:29 +00005710 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005711}
5712
5713/* called from terminal list command */
5714void
5715route_vty_out_tmp (struct vty *vty, struct prefix *p,
5716 struct attr *attr, safi_t safi)
5717{
5718 /* Route status display. */
5719 vty_out (vty, "*");
5720 vty_out (vty, ">");
5721 vty_out (vty, " ");
5722
5723 /* print prefix and mask */
5724 route_vty_out_route (p, vty);
5725
5726 /* Print attribute */
5727 if (attr)
5728 {
5729 if (p->family == AF_INET)
5730 {
5731 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005732 vty_out (vty, "%-16s",
5733 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005734 else
5735 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5736 }
5737#ifdef HAVE_IPV6
5738 else if (p->family == AF_INET6)
5739 {
5740 int len;
5741 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005742
5743 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005744
5745 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005746 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5747 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005748 len = 16 - len;
5749 if (len < 1)
5750 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5751 else
5752 vty_out (vty, "%*s", len, " ");
5753 }
5754#endif /* HAVE_IPV6 */
5755
5756 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5757 vty_out (vty, "%10d", attr->med);
5758 else
5759 vty_out (vty, " ");
5760
5761 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5762 vty_out (vty, "%7d", attr->local_pref);
5763 else
5764 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005765
5766 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5767
Paul Jakmab2518c12006-05-12 23:48:40 +00005768 /* Print aspath */
5769 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005770 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005771
Paul Jakmab2518c12006-05-12 23:48:40 +00005772 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005773 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005774 }
paul718e3742002-12-13 20:15:29 +00005775
5776 vty_out (vty, "%s", VTY_NEWLINE);
5777}
5778
ajs5a646652004-11-05 01:25:55 +00005779void
paul718e3742002-12-13 20:15:29 +00005780route_vty_out_tag (struct vty *vty, struct prefix *p,
5781 struct bgp_info *binfo, int display, safi_t safi)
5782{
5783 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005784 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005785
5786 if (!binfo->extra)
5787 return;
5788
paulb40d9392005-08-22 22:34:41 +00005789 /* short status lead text */
5790 route_vty_short_status_out (vty, binfo);
5791
paul718e3742002-12-13 20:15:29 +00005792 /* print prefix and mask */
5793 if (! display)
5794 route_vty_out_route (p, vty);
5795 else
5796 vty_out (vty, "%*s", 17, " ");
5797
5798 /* Print attribute */
5799 attr = binfo->attr;
5800 if (attr)
5801 {
5802 if (p->family == AF_INET)
5803 {
5804 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005805 vty_out (vty, "%-16s",
5806 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005807 else
5808 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5809 }
5810#ifdef HAVE_IPV6
5811 else if (p->family == AF_INET6)
5812 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005813 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005814 char buf[BUFSIZ];
5815 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005816 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005817 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005818 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5819 buf, BUFSIZ));
5820 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005821 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005822 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5823 buf, BUFSIZ),
5824 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5825 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005826
5827 }
5828#endif /* HAVE_IPV6 */
5829 }
5830
Paul Jakmafb982c22007-05-04 20:15:47 +00005831 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005832
5833 vty_out (vty, "notag/%d", label);
5834
5835 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005836}
5837
5838/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005839static void
paul718e3742002-12-13 20:15:29 +00005840damp_route_vty_out (struct vty *vty, struct prefix *p,
5841 struct bgp_info *binfo, int display, safi_t safi)
5842{
5843 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005844 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005845 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005846
paulb40d9392005-08-22 22:34:41 +00005847 /* short status lead text */
5848 route_vty_short_status_out (vty, binfo);
5849
paul718e3742002-12-13 20:15:29 +00005850 /* print prefix and mask */
5851 if (! display)
5852 route_vty_out_route (p, vty);
5853 else
5854 vty_out (vty, "%*s", 17, " ");
5855
5856 len = vty_out (vty, "%s", binfo->peer->host);
5857 len = 17 - len;
5858 if (len < 1)
5859 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5860 else
5861 vty_out (vty, "%*s", len, " ");
5862
Chris Caputo50aef6f2009-06-23 06:06:49 +00005863 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005864
5865 /* Print attribute */
5866 attr = binfo->attr;
5867 if (attr)
5868 {
5869 /* Print aspath */
5870 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005871 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005872
5873 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005874 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005875 }
5876 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005877}
5878
paul718e3742002-12-13 20:15:29 +00005879/* flap route */
ajs5a646652004-11-05 01:25:55 +00005880static void
paul718e3742002-12-13 20:15:29 +00005881flap_route_vty_out (struct vty *vty, struct prefix *p,
5882 struct bgp_info *binfo, int display, safi_t safi)
5883{
5884 struct attr *attr;
5885 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005886 char timebuf[BGP_UPTIME_LEN];
5887 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005888
5889 if (!binfo->extra)
5890 return;
5891
5892 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005893
paulb40d9392005-08-22 22:34:41 +00005894 /* short status lead text */
5895 route_vty_short_status_out (vty, binfo);
5896
paul718e3742002-12-13 20:15:29 +00005897 /* print prefix and mask */
5898 if (! display)
5899 route_vty_out_route (p, vty);
5900 else
5901 vty_out (vty, "%*s", 17, " ");
5902
5903 len = vty_out (vty, "%s", binfo->peer->host);
5904 len = 16 - len;
5905 if (len < 1)
5906 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5907 else
5908 vty_out (vty, "%*s", len, " ");
5909
5910 len = vty_out (vty, "%d", bdi->flap);
5911 len = 5 - len;
5912 if (len < 1)
5913 vty_out (vty, " ");
5914 else
5915 vty_out (vty, "%*s ", len, " ");
5916
5917 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5918 timebuf, BGP_UPTIME_LEN));
5919
5920 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5921 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005922 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005923 else
5924 vty_out (vty, "%*s ", 8, " ");
5925
5926 /* Print attribute */
5927 attr = binfo->attr;
5928 if (attr)
5929 {
5930 /* Print aspath */
5931 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005932 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005933
5934 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005935 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005936 }
5937 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005938}
5939
paul94f2b392005-06-28 12:44:16 +00005940static void
paul718e3742002-12-13 20:15:29 +00005941route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5942 struct bgp_info *binfo, afi_t afi, safi_t safi)
5943{
5944 char buf[INET6_ADDRSTRLEN];
5945 char buf1[BUFSIZ];
5946 struct attr *attr;
5947 int sockunion_vty_out (struct vty *, union sockunion *);
5948
5949 attr = binfo->attr;
5950
5951 if (attr)
5952 {
5953 /* Line1 display AS-path, Aggregator */
5954 if (attr->aspath)
5955 {
5956 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005957 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005958 vty_out (vty, "Local");
5959 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005960 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005961 }
5962
paulb40d9392005-08-22 22:34:41 +00005963 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5964 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005965 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5966 vty_out (vty, ", (stale)");
5967 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005968 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005969 attr->extra->aggregator_as,
5970 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005971 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5972 vty_out (vty, ", (Received from a RR-client)");
5973 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5974 vty_out (vty, ", (Received from a RS-client)");
5975 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5976 vty_out (vty, ", (history entry)");
5977 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5978 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005979 vty_out (vty, "%s", VTY_NEWLINE);
5980
5981 /* Line2 display Next-hop, Neighbor, Router-id */
5982 if (p->family == AF_INET)
5983 {
5984 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005985 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005986 inet_ntoa (attr->nexthop));
5987 }
5988#ifdef HAVE_IPV6
5989 else
5990 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005991 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005992 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005993 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005994 buf, INET6_ADDRSTRLEN));
5995 }
5996#endif /* HAVE_IPV6 */
5997
5998 if (binfo->peer == bgp->peer_self)
5999 {
6000 vty_out (vty, " from %s ",
6001 p->family == AF_INET ? "0.0.0.0" : "::");
6002 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6003 }
6004 else
6005 {
6006 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6007 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 else if (binfo->extra && binfo->extra->igpmetric)
6009 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006010 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006011 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006013 else
6014 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6015 }
6016 vty_out (vty, "%s", VTY_NEWLINE);
6017
6018#ifdef HAVE_IPV6
6019 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006021 {
6022 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006023 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006024 buf, INET6_ADDRSTRLEN),
6025 VTY_NEWLINE);
6026 }
6027#endif /* HAVE_IPV6 */
6028
6029 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6030 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6031
6032 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6033 vty_out (vty, ", metric %d", attr->med);
6034
6035 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6036 vty_out (vty, ", localpref %d", attr->local_pref);
6037 else
6038 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6039
Paul Jakmafb982c22007-05-04 20:15:47 +00006040 if (attr->extra && attr->extra->weight != 0)
6041 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006042
6043 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6044 vty_out (vty, ", valid");
6045
6046 if (binfo->peer != bgp->peer_self)
6047 {
6048 if (binfo->peer->as == binfo->peer->local_as)
6049 vty_out (vty, ", internal");
6050 else
6051 vty_out (vty, ", %s",
6052 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6053 }
6054 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6055 vty_out (vty, ", aggregated, local");
6056 else if (binfo->type != ZEBRA_ROUTE_BGP)
6057 vty_out (vty, ", sourced");
6058 else
6059 vty_out (vty, ", sourced, local");
6060
6061 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6062 vty_out (vty, ", atomic-aggregate");
6063
6064 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6065 vty_out (vty, ", best");
6066
6067 vty_out (vty, "%s", VTY_NEWLINE);
6068
6069 /* Line 4 display Community */
6070 if (attr->community)
6071 vty_out (vty, " Community: %s%s", attr->community->str,
6072 VTY_NEWLINE);
6073
6074 /* Line 5 display Extended-community */
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 vty_out (vty, " Extended Community: %s%s",
6077 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006078
6079 /* Line 6 display Originator, Cluster-id */
6080 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6081 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6082 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006083 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006084 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 vty_out (vty, " Originator: %s",
6086 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006087
6088 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6089 {
6090 int i;
6091 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006092 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6093 vty_out (vty, "%s ",
6094 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006095 }
6096 vty_out (vty, "%s", VTY_NEWLINE);
6097 }
Paul Jakma41367172007-08-06 15:24:51 +00006098
6099 /* 7: AS Pathlimit */
6100 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6101 {
6102
6103 vty_out (vty, " AS-Pathlimit: %u",
6104 attr->pathlimit.ttl);
6105 if (attr->pathlimit.as)
6106 vty_out (vty, " (%u)", attr->pathlimit.as);
6107 vty_out (vty, "%s", VTY_NEWLINE);
6108 }
6109
Paul Jakmafb982c22007-05-04 20:15:47 +00006110 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006111 bgp_damp_info_vty (vty, binfo);
6112
6113 /* Line 7 display Uptime */
6114 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6115 }
6116 vty_out (vty, "%s", VTY_NEWLINE);
6117}
6118
paulb40d9392005-08-22 22:34:41 +00006119#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 +00006120#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006121#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6122#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6123#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6124
6125enum bgp_show_type
6126{
6127 bgp_show_type_normal,
6128 bgp_show_type_regexp,
6129 bgp_show_type_prefix_list,
6130 bgp_show_type_filter_list,
6131 bgp_show_type_route_map,
6132 bgp_show_type_neighbor,
6133 bgp_show_type_cidr_only,
6134 bgp_show_type_prefix_longer,
6135 bgp_show_type_community_all,
6136 bgp_show_type_community,
6137 bgp_show_type_community_exact,
6138 bgp_show_type_community_list,
6139 bgp_show_type_community_list_exact,
6140 bgp_show_type_flap_statistics,
6141 bgp_show_type_flap_address,
6142 bgp_show_type_flap_prefix,
6143 bgp_show_type_flap_cidr_only,
6144 bgp_show_type_flap_regexp,
6145 bgp_show_type_flap_filter_list,
6146 bgp_show_type_flap_prefix_list,
6147 bgp_show_type_flap_prefix_longer,
6148 bgp_show_type_flap_route_map,
6149 bgp_show_type_flap_neighbor,
6150 bgp_show_type_dampend_paths,
6151 bgp_show_type_damp_neighbor
6152};
6153
ajs5a646652004-11-05 01:25:55 +00006154static int
paulfee0f4c2004-09-13 05:12:46 +00006155bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006156 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006157{
paul718e3742002-12-13 20:15:29 +00006158 struct bgp_info *ri;
6159 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006160 int header = 1;
paul718e3742002-12-13 20:15:29 +00006161 int display;
ajs5a646652004-11-05 01:25:55 +00006162 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006163
6164 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006165 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006166
paul718e3742002-12-13 20:15:29 +00006167 /* Start processing of routes. */
6168 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6169 if (rn->info != NULL)
6170 {
6171 display = 0;
6172
6173 for (ri = rn->info; ri; ri = ri->next)
6174 {
ajs5a646652004-11-05 01:25:55 +00006175 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006176 || type == bgp_show_type_flap_address
6177 || type == bgp_show_type_flap_prefix
6178 || type == bgp_show_type_flap_cidr_only
6179 || type == bgp_show_type_flap_regexp
6180 || type == bgp_show_type_flap_filter_list
6181 || type == bgp_show_type_flap_prefix_list
6182 || type == bgp_show_type_flap_prefix_longer
6183 || type == bgp_show_type_flap_route_map
6184 || type == bgp_show_type_flap_neighbor
6185 || type == bgp_show_type_dampend_paths
6186 || type == bgp_show_type_damp_neighbor)
6187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006188 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006189 continue;
6190 }
6191 if (type == bgp_show_type_regexp
6192 || type == bgp_show_type_flap_regexp)
6193 {
ajs5a646652004-11-05 01:25:55 +00006194 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006195
6196 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6197 continue;
6198 }
6199 if (type == bgp_show_type_prefix_list
6200 || type == bgp_show_type_flap_prefix_list)
6201 {
ajs5a646652004-11-05 01:25:55 +00006202 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006203
6204 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6205 continue;
6206 }
6207 if (type == bgp_show_type_filter_list
6208 || type == bgp_show_type_flap_filter_list)
6209 {
ajs5a646652004-11-05 01:25:55 +00006210 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006211
6212 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6213 continue;
6214 }
6215 if (type == bgp_show_type_route_map
6216 || type == bgp_show_type_flap_route_map)
6217 {
ajs5a646652004-11-05 01:25:55 +00006218 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006219 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006220 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006221 int ret;
6222
Paul Jakmafb982c22007-05-04 20:15:47 +00006223 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006224 binfo.peer = ri->peer;
6225 binfo.attr = &dummy_attr;
6226
6227 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006228
6229 bgp_attr_extra_free (&dummy_attr);
6230
paul718e3742002-12-13 20:15:29 +00006231 if (ret == RMAP_DENYMATCH)
6232 continue;
6233 }
6234 if (type == bgp_show_type_neighbor
6235 || type == bgp_show_type_flap_neighbor
6236 || type == bgp_show_type_damp_neighbor)
6237 {
ajs5a646652004-11-05 01:25:55 +00006238 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006239
6240 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6241 continue;
6242 }
6243 if (type == bgp_show_type_cidr_only
6244 || type == bgp_show_type_flap_cidr_only)
6245 {
6246 u_int32_t destination;
6247
6248 destination = ntohl (rn->p.u.prefix4.s_addr);
6249 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6250 continue;
6251 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6252 continue;
6253 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6254 continue;
6255 }
6256 if (type == bgp_show_type_prefix_longer
6257 || type == bgp_show_type_flap_prefix_longer)
6258 {
ajs5a646652004-11-05 01:25:55 +00006259 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006260
6261 if (! prefix_match (p, &rn->p))
6262 continue;
6263 }
6264 if (type == bgp_show_type_community_all)
6265 {
6266 if (! ri->attr->community)
6267 continue;
6268 }
6269 if (type == bgp_show_type_community)
6270 {
ajs5a646652004-11-05 01:25:55 +00006271 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006272
6273 if (! ri->attr->community ||
6274 ! community_match (ri->attr->community, com))
6275 continue;
6276 }
6277 if (type == bgp_show_type_community_exact)
6278 {
ajs5a646652004-11-05 01:25:55 +00006279 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006280
6281 if (! ri->attr->community ||
6282 ! community_cmp (ri->attr->community, com))
6283 continue;
6284 }
6285 if (type == bgp_show_type_community_list)
6286 {
ajs5a646652004-11-05 01:25:55 +00006287 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006288
6289 if (! community_list_match (ri->attr->community, list))
6290 continue;
6291 }
6292 if (type == bgp_show_type_community_list_exact)
6293 {
ajs5a646652004-11-05 01:25:55 +00006294 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006295
6296 if (! community_list_exact_match (ri->attr->community, list))
6297 continue;
6298 }
6299 if (type == bgp_show_type_flap_address
6300 || type == bgp_show_type_flap_prefix)
6301 {
ajs5a646652004-11-05 01:25:55 +00006302 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006303
6304 if (! prefix_match (&rn->p, p))
6305 continue;
6306
6307 if (type == bgp_show_type_flap_prefix)
6308 if (p->prefixlen != rn->p.prefixlen)
6309 continue;
6310 }
6311 if (type == bgp_show_type_dampend_paths
6312 || type == bgp_show_type_damp_neighbor)
6313 {
6314 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6315 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6316 continue;
6317 }
6318
6319 if (header)
6320 {
hasso93406d82005-02-02 14:40:33 +00006321 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6322 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6323 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006324 if (type == bgp_show_type_dampend_paths
6325 || type == bgp_show_type_damp_neighbor)
6326 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6327 else if (type == bgp_show_type_flap_statistics
6328 || type == bgp_show_type_flap_address
6329 || type == bgp_show_type_flap_prefix
6330 || type == bgp_show_type_flap_cidr_only
6331 || type == bgp_show_type_flap_regexp
6332 || type == bgp_show_type_flap_filter_list
6333 || type == bgp_show_type_flap_prefix_list
6334 || type == bgp_show_type_flap_prefix_longer
6335 || type == bgp_show_type_flap_route_map
6336 || type == bgp_show_type_flap_neighbor)
6337 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6338 else
6339 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006340 header = 0;
6341 }
6342
6343 if (type == bgp_show_type_dampend_paths
6344 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006345 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006346 else if (type == bgp_show_type_flap_statistics
6347 || type == bgp_show_type_flap_address
6348 || type == bgp_show_type_flap_prefix
6349 || type == bgp_show_type_flap_cidr_only
6350 || type == bgp_show_type_flap_regexp
6351 || type == bgp_show_type_flap_filter_list
6352 || type == bgp_show_type_flap_prefix_list
6353 || type == bgp_show_type_flap_prefix_longer
6354 || type == bgp_show_type_flap_route_map
6355 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006356 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006357 else
ajs5a646652004-11-05 01:25:55 +00006358 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006359 display++;
6360 }
6361 if (display)
ajs5a646652004-11-05 01:25:55 +00006362 output_count++;
paul718e3742002-12-13 20:15:29 +00006363 }
6364
6365 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006366 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006367 {
6368 if (type == bgp_show_type_normal)
6369 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6370 }
6371 else
6372 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006373 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006374
6375 return CMD_SUCCESS;
6376}
6377
ajs5a646652004-11-05 01:25:55 +00006378static int
paulfee0f4c2004-09-13 05:12:46 +00006379bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006380 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006381{
6382 struct bgp_table *table;
6383
6384 if (bgp == NULL) {
6385 bgp = bgp_get_default ();
6386 }
6387
6388 if (bgp == NULL)
6389 {
6390 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6391 return CMD_WARNING;
6392 }
6393
6394
6395 table = bgp->rib[afi][safi];
6396
ajs5a646652004-11-05 01:25:55 +00006397 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006398}
6399
paul718e3742002-12-13 20:15:29 +00006400/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006401static void
paul718e3742002-12-13 20:15:29 +00006402route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6403 struct bgp_node *rn,
6404 struct prefix_rd *prd, afi_t afi, safi_t safi)
6405{
6406 struct bgp_info *ri;
6407 struct prefix *p;
6408 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006409 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006410 char buf1[INET6_ADDRSTRLEN];
6411 char buf2[INET6_ADDRSTRLEN];
6412 int count = 0;
6413 int best = 0;
6414 int suppress = 0;
6415 int no_export = 0;
6416 int no_advertise = 0;
6417 int local_as = 0;
6418 int first = 0;
6419
6420 p = &rn->p;
6421 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6422 (safi == SAFI_MPLS_VPN ?
6423 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6424 safi == SAFI_MPLS_VPN ? ":" : "",
6425 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6426 p->prefixlen, VTY_NEWLINE);
6427
6428 for (ri = rn->info; ri; ri = ri->next)
6429 {
6430 count++;
6431 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6432 {
6433 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006434 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006435 suppress = 1;
6436 if (ri->attr->community != NULL)
6437 {
6438 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6439 no_advertise = 1;
6440 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6441 no_export = 1;
6442 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6443 local_as = 1;
6444 }
6445 }
6446 }
6447
6448 vty_out (vty, "Paths: (%d available", count);
6449 if (best)
6450 {
6451 vty_out (vty, ", best #%d", best);
6452 if (safi == SAFI_UNICAST)
6453 vty_out (vty, ", table Default-IP-Routing-Table");
6454 }
6455 else
6456 vty_out (vty, ", no best path");
6457 if (no_advertise)
6458 vty_out (vty, ", not advertised to any peer");
6459 else if (no_export)
6460 vty_out (vty, ", not advertised to EBGP peer");
6461 else if (local_as)
6462 vty_out (vty, ", not advertised outside local AS");
6463 if (suppress)
6464 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6465 vty_out (vty, ")%s", VTY_NEWLINE);
6466
6467 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006468 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006469 {
6470 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6471 {
6472 if (! first)
6473 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6474 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6475 first = 1;
6476 }
6477 }
6478 if (! first)
6479 vty_out (vty, " Not advertised to any peer");
6480 vty_out (vty, "%s", VTY_NEWLINE);
6481}
6482
6483/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006484static int
paulfee0f4c2004-09-13 05:12:46 +00006485bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006486 struct bgp_table *rib, const char *ip_str,
6487 afi_t afi, safi_t safi, struct prefix_rd *prd,
6488 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006489{
6490 int ret;
6491 int header;
6492 int display = 0;
6493 struct prefix match;
6494 struct bgp_node *rn;
6495 struct bgp_node *rm;
6496 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006497 struct bgp_table *table;
6498
paul718e3742002-12-13 20:15:29 +00006499 /* Check IP address argument. */
6500 ret = str2prefix (ip_str, &match);
6501 if (! ret)
6502 {
6503 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6504 return CMD_WARNING;
6505 }
6506
6507 match.family = afi2family (afi);
6508
6509 if (safi == SAFI_MPLS_VPN)
6510 {
paulfee0f4c2004-09-13 05:12:46 +00006511 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006512 {
6513 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6514 continue;
6515
6516 if ((table = rn->info) != NULL)
6517 {
6518 header = 1;
6519
6520 if ((rm = bgp_node_match (table, &match)) != NULL)
6521 {
6522 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6523 continue;
6524
6525 for (ri = rm->info; ri; ri = ri->next)
6526 {
6527 if (header)
6528 {
6529 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6530 AFI_IP, SAFI_MPLS_VPN);
6531
6532 header = 0;
6533 }
6534 display++;
6535 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6536 }
6537 }
6538 }
6539 }
6540 }
6541 else
6542 {
6543 header = 1;
6544
paulfee0f4c2004-09-13 05:12:46 +00006545 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006546 {
6547 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6548 {
6549 for (ri = rn->info; ri; ri = ri->next)
6550 {
6551 if (header)
6552 {
6553 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6554 header = 0;
6555 }
6556 display++;
6557 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6558 }
6559 }
6560 }
6561 }
6562
6563 if (! display)
6564 {
6565 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6566 return CMD_WARNING;
6567 }
6568
6569 return CMD_SUCCESS;
6570}
6571
paulfee0f4c2004-09-13 05:12:46 +00006572/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006573static int
paulfd79ac92004-10-13 05:06:08 +00006574bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006575 afi_t afi, safi_t safi, struct prefix_rd *prd,
6576 int prefix_check)
6577{
6578 struct bgp *bgp;
6579
6580 /* BGP structure lookup. */
6581 if (view_name)
6582 {
6583 bgp = bgp_lookup_by_name (view_name);
6584 if (bgp == NULL)
6585 {
6586 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6587 return CMD_WARNING;
6588 }
6589 }
6590 else
6591 {
6592 bgp = bgp_get_default ();
6593 if (bgp == NULL)
6594 {
6595 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6596 return CMD_WARNING;
6597 }
6598 }
6599
6600 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6601 afi, safi, prd, prefix_check);
6602}
6603
paul718e3742002-12-13 20:15:29 +00006604/* BGP route print out function. */
6605DEFUN (show_ip_bgp,
6606 show_ip_bgp_cmd,
6607 "show ip bgp",
6608 SHOW_STR
6609 IP_STR
6610 BGP_STR)
6611{
ajs5a646652004-11-05 01:25:55 +00006612 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006613}
6614
6615DEFUN (show_ip_bgp_ipv4,
6616 show_ip_bgp_ipv4_cmd,
6617 "show ip bgp ipv4 (unicast|multicast)",
6618 SHOW_STR
6619 IP_STR
6620 BGP_STR
6621 "Address family\n"
6622 "Address Family modifier\n"
6623 "Address Family modifier\n")
6624{
6625 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006626 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6627 NULL);
paul718e3742002-12-13 20:15:29 +00006628
ajs5a646652004-11-05 01:25:55 +00006629 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006630}
6631
6632DEFUN (show_ip_bgp_route,
6633 show_ip_bgp_route_cmd,
6634 "show ip bgp A.B.C.D",
6635 SHOW_STR
6636 IP_STR
6637 BGP_STR
6638 "Network in the BGP routing table to display\n")
6639{
6640 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6641}
6642
6643DEFUN (show_ip_bgp_ipv4_route,
6644 show_ip_bgp_ipv4_route_cmd,
6645 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6646 SHOW_STR
6647 IP_STR
6648 BGP_STR
6649 "Address family\n"
6650 "Address Family modifier\n"
6651 "Address Family modifier\n"
6652 "Network in the BGP routing table to display\n")
6653{
6654 if (strncmp (argv[0], "m", 1) == 0)
6655 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6656
6657 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6658}
6659
6660DEFUN (show_ip_bgp_vpnv4_all_route,
6661 show_ip_bgp_vpnv4_all_route_cmd,
6662 "show ip bgp vpnv4 all A.B.C.D",
6663 SHOW_STR
6664 IP_STR
6665 BGP_STR
6666 "Display VPNv4 NLRI specific information\n"
6667 "Display information about all VPNv4 NLRIs\n"
6668 "Network in the BGP routing table to display\n")
6669{
6670 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6671}
6672
6673DEFUN (show_ip_bgp_vpnv4_rd_route,
6674 show_ip_bgp_vpnv4_rd_route_cmd,
6675 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6676 SHOW_STR
6677 IP_STR
6678 BGP_STR
6679 "Display VPNv4 NLRI specific information\n"
6680 "Display information for a route distinguisher\n"
6681 "VPN Route Distinguisher\n"
6682 "Network in the BGP routing table to display\n")
6683{
6684 int ret;
6685 struct prefix_rd prd;
6686
6687 ret = str2prefix_rd (argv[0], &prd);
6688 if (! ret)
6689 {
6690 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6691 return CMD_WARNING;
6692 }
6693 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6694}
6695
6696DEFUN (show_ip_bgp_prefix,
6697 show_ip_bgp_prefix_cmd,
6698 "show ip bgp A.B.C.D/M",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6703{
6704 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6705}
6706
6707DEFUN (show_ip_bgp_ipv4_prefix,
6708 show_ip_bgp_ipv4_prefix_cmd,
6709 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6710 SHOW_STR
6711 IP_STR
6712 BGP_STR
6713 "Address family\n"
6714 "Address Family modifier\n"
6715 "Address Family modifier\n"
6716 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6717{
6718 if (strncmp (argv[0], "m", 1) == 0)
6719 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6720
6721 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6722}
6723
6724DEFUN (show_ip_bgp_vpnv4_all_prefix,
6725 show_ip_bgp_vpnv4_all_prefix_cmd,
6726 "show ip bgp vpnv4 all A.B.C.D/M",
6727 SHOW_STR
6728 IP_STR
6729 BGP_STR
6730 "Display VPNv4 NLRI specific information\n"
6731 "Display information about all VPNv4 NLRIs\n"
6732 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6733{
6734 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6735}
6736
6737DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6738 show_ip_bgp_vpnv4_rd_prefix_cmd,
6739 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6740 SHOW_STR
6741 IP_STR
6742 BGP_STR
6743 "Display VPNv4 NLRI specific information\n"
6744 "Display information for a route distinguisher\n"
6745 "VPN Route Distinguisher\n"
6746 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6747{
6748 int ret;
6749 struct prefix_rd prd;
6750
6751 ret = str2prefix_rd (argv[0], &prd);
6752 if (! ret)
6753 {
6754 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6755 return CMD_WARNING;
6756 }
6757 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6758}
6759
6760DEFUN (show_ip_bgp_view,
6761 show_ip_bgp_view_cmd,
6762 "show ip bgp view WORD",
6763 SHOW_STR
6764 IP_STR
6765 BGP_STR
6766 "BGP view\n"
6767 "BGP view name\n")
6768{
paulbb46e942003-10-24 19:02:03 +00006769 struct bgp *bgp;
6770
6771 /* BGP structure lookup. */
6772 bgp = bgp_lookup_by_name (argv[0]);
6773 if (bgp == NULL)
6774 {
6775 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6776 return CMD_WARNING;
6777 }
6778
ajs5a646652004-11-05 01:25:55 +00006779 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006780}
6781
6782DEFUN (show_ip_bgp_view_route,
6783 show_ip_bgp_view_route_cmd,
6784 "show ip bgp view WORD A.B.C.D",
6785 SHOW_STR
6786 IP_STR
6787 BGP_STR
6788 "BGP view\n"
6789 "BGP view name\n"
6790 "Network in the BGP routing table to display\n")
6791{
6792 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6793}
6794
6795DEFUN (show_ip_bgp_view_prefix,
6796 show_ip_bgp_view_prefix_cmd,
6797 "show ip bgp view WORD A.B.C.D/M",
6798 SHOW_STR
6799 IP_STR
6800 BGP_STR
6801 "BGP view\n"
6802 "BGP view name\n"
6803 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6804{
6805 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6806}
6807
6808#ifdef HAVE_IPV6
6809DEFUN (show_bgp,
6810 show_bgp_cmd,
6811 "show bgp",
6812 SHOW_STR
6813 BGP_STR)
6814{
ajs5a646652004-11-05 01:25:55 +00006815 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6816 NULL);
paul718e3742002-12-13 20:15:29 +00006817}
6818
6819ALIAS (show_bgp,
6820 show_bgp_ipv6_cmd,
6821 "show bgp ipv6",
6822 SHOW_STR
6823 BGP_STR
6824 "Address family\n")
6825
6826/* old command */
6827DEFUN (show_ipv6_bgp,
6828 show_ipv6_bgp_cmd,
6829 "show ipv6 bgp",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR)
6833{
ajs5a646652004-11-05 01:25:55 +00006834 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6835 NULL);
paul718e3742002-12-13 20:15:29 +00006836}
6837
6838DEFUN (show_bgp_route,
6839 show_bgp_route_cmd,
6840 "show bgp X:X::X:X",
6841 SHOW_STR
6842 BGP_STR
6843 "Network in the BGP routing table to display\n")
6844{
6845 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6846}
6847
6848ALIAS (show_bgp_route,
6849 show_bgp_ipv6_route_cmd,
6850 "show bgp ipv6 X:X::X:X",
6851 SHOW_STR
6852 BGP_STR
6853 "Address family\n"
6854 "Network in the BGP routing table to display\n")
6855
6856/* old command */
6857DEFUN (show_ipv6_bgp_route,
6858 show_ipv6_bgp_route_cmd,
6859 "show ipv6 bgp X:X::X:X",
6860 SHOW_STR
6861 IP_STR
6862 BGP_STR
6863 "Network in the BGP routing table to display\n")
6864{
6865 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6866}
6867
6868DEFUN (show_bgp_prefix,
6869 show_bgp_prefix_cmd,
6870 "show bgp X:X::X:X/M",
6871 SHOW_STR
6872 BGP_STR
6873 "IPv6 prefix <network>/<length>\n")
6874{
6875 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6876}
6877
6878ALIAS (show_bgp_prefix,
6879 show_bgp_ipv6_prefix_cmd,
6880 "show bgp ipv6 X:X::X:X/M",
6881 SHOW_STR
6882 BGP_STR
6883 "Address family\n"
6884 "IPv6 prefix <network>/<length>\n")
6885
6886/* old command */
6887DEFUN (show_ipv6_bgp_prefix,
6888 show_ipv6_bgp_prefix_cmd,
6889 "show ipv6 bgp X:X::X:X/M",
6890 SHOW_STR
6891 IP_STR
6892 BGP_STR
6893 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6894{
6895 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6896}
6897
paulbb46e942003-10-24 19:02:03 +00006898DEFUN (show_bgp_view,
6899 show_bgp_view_cmd,
6900 "show bgp view WORD",
6901 SHOW_STR
6902 BGP_STR
6903 "BGP view\n"
6904 "View name\n")
6905{
6906 struct bgp *bgp;
6907
6908 /* BGP structure lookup. */
6909 bgp = bgp_lookup_by_name (argv[0]);
6910 if (bgp == NULL)
6911 {
6912 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6913 return CMD_WARNING;
6914 }
6915
ajs5a646652004-11-05 01:25:55 +00006916 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006917}
6918
6919ALIAS (show_bgp_view,
6920 show_bgp_view_ipv6_cmd,
6921 "show bgp view WORD ipv6",
6922 SHOW_STR
6923 BGP_STR
6924 "BGP view\n"
6925 "View name\n"
6926 "Address family\n")
6927
6928DEFUN (show_bgp_view_route,
6929 show_bgp_view_route_cmd,
6930 "show bgp view WORD X:X::X:X",
6931 SHOW_STR
6932 BGP_STR
6933 "BGP view\n"
6934 "View name\n"
6935 "Network in the BGP routing table to display\n")
6936{
6937 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6938}
6939
6940ALIAS (show_bgp_view_route,
6941 show_bgp_view_ipv6_route_cmd,
6942 "show bgp view WORD ipv6 X:X::X:X",
6943 SHOW_STR
6944 BGP_STR
6945 "BGP view\n"
6946 "View name\n"
6947 "Address family\n"
6948 "Network in the BGP routing table to display\n")
6949
6950DEFUN (show_bgp_view_prefix,
6951 show_bgp_view_prefix_cmd,
6952 "show bgp view WORD X:X::X:X/M",
6953 SHOW_STR
6954 BGP_STR
6955 "BGP view\n"
6956 "View name\n"
6957 "IPv6 prefix <network>/<length>\n")
6958{
6959 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6960}
6961
6962ALIAS (show_bgp_view_prefix,
6963 show_bgp_view_ipv6_prefix_cmd,
6964 "show bgp view WORD ipv6 X:X::X:X/M",
6965 SHOW_STR
6966 BGP_STR
6967 "BGP view\n"
6968 "View name\n"
6969 "Address family\n"
6970 "IPv6 prefix <network>/<length>\n")
6971
paul718e3742002-12-13 20:15:29 +00006972/* old command */
6973DEFUN (show_ipv6_mbgp,
6974 show_ipv6_mbgp_cmd,
6975 "show ipv6 mbgp",
6976 SHOW_STR
6977 IP_STR
6978 MBGP_STR)
6979{
ajs5a646652004-11-05 01:25:55 +00006980 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6981 NULL);
paul718e3742002-12-13 20:15:29 +00006982}
6983
6984/* old command */
6985DEFUN (show_ipv6_mbgp_route,
6986 show_ipv6_mbgp_route_cmd,
6987 "show ipv6 mbgp X:X::X:X",
6988 SHOW_STR
6989 IP_STR
6990 MBGP_STR
6991 "Network in the MBGP routing table to display\n")
6992{
6993 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6994}
6995
6996/* old command */
6997DEFUN (show_ipv6_mbgp_prefix,
6998 show_ipv6_mbgp_prefix_cmd,
6999 "show ipv6 mbgp X:X::X:X/M",
7000 SHOW_STR
7001 IP_STR
7002 MBGP_STR
7003 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7004{
7005 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7006}
7007#endif
7008
paul718e3742002-12-13 20:15:29 +00007009
paul94f2b392005-06-28 12:44:16 +00007010static int
paulfd79ac92004-10-13 05:06:08 +00007011bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007012 safi_t safi, enum bgp_show_type type)
7013{
7014 int i;
7015 struct buffer *b;
7016 char *regstr;
7017 int first;
7018 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007019 int rc;
paul718e3742002-12-13 20:15:29 +00007020
7021 first = 0;
7022 b = buffer_new (1024);
7023 for (i = 0; i < argc; i++)
7024 {
7025 if (first)
7026 buffer_putc (b, ' ');
7027 else
7028 {
7029 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7030 continue;
7031 first = 1;
7032 }
7033
7034 buffer_putstr (b, argv[i]);
7035 }
7036 buffer_putc (b, '\0');
7037
7038 regstr = buffer_getstr (b);
7039 buffer_free (b);
7040
7041 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007042 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007043 if (! regex)
7044 {
7045 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7046 VTY_NEWLINE);
7047 return CMD_WARNING;
7048 }
7049
ajs5a646652004-11-05 01:25:55 +00007050 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7051 bgp_regex_free (regex);
7052 return rc;
paul718e3742002-12-13 20:15:29 +00007053}
7054
7055DEFUN (show_ip_bgp_regexp,
7056 show_ip_bgp_regexp_cmd,
7057 "show ip bgp regexp .LINE",
7058 SHOW_STR
7059 IP_STR
7060 BGP_STR
7061 "Display routes matching the AS path regular expression\n"
7062 "A regular-expression to match the BGP AS paths\n")
7063{
7064 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7065 bgp_show_type_regexp);
7066}
7067
7068DEFUN (show_ip_bgp_flap_regexp,
7069 show_ip_bgp_flap_regexp_cmd,
7070 "show ip bgp flap-statistics regexp .LINE",
7071 SHOW_STR
7072 IP_STR
7073 BGP_STR
7074 "Display flap statistics of routes\n"
7075 "Display routes matching the AS path regular expression\n"
7076 "A regular-expression to match the BGP AS paths\n")
7077{
7078 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7079 bgp_show_type_flap_regexp);
7080}
7081
7082DEFUN (show_ip_bgp_ipv4_regexp,
7083 show_ip_bgp_ipv4_regexp_cmd,
7084 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7085 SHOW_STR
7086 IP_STR
7087 BGP_STR
7088 "Address family\n"
7089 "Address Family modifier\n"
7090 "Address Family modifier\n"
7091 "Display routes matching the AS path regular expression\n"
7092 "A regular-expression to match the BGP AS paths\n")
7093{
7094 if (strncmp (argv[0], "m", 1) == 0)
7095 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7096 bgp_show_type_regexp);
7097
7098 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7099 bgp_show_type_regexp);
7100}
7101
7102#ifdef HAVE_IPV6
7103DEFUN (show_bgp_regexp,
7104 show_bgp_regexp_cmd,
7105 "show bgp regexp .LINE",
7106 SHOW_STR
7107 BGP_STR
7108 "Display routes matching the AS path regular expression\n"
7109 "A regular-expression to match the BGP AS paths\n")
7110{
7111 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7112 bgp_show_type_regexp);
7113}
7114
7115ALIAS (show_bgp_regexp,
7116 show_bgp_ipv6_regexp_cmd,
7117 "show bgp ipv6 regexp .LINE",
7118 SHOW_STR
7119 BGP_STR
7120 "Address family\n"
7121 "Display routes matching the AS path regular expression\n"
7122 "A regular-expression to match the BGP AS paths\n")
7123
7124/* old command */
7125DEFUN (show_ipv6_bgp_regexp,
7126 show_ipv6_bgp_regexp_cmd,
7127 "show ipv6 bgp regexp .LINE",
7128 SHOW_STR
7129 IP_STR
7130 BGP_STR
7131 "Display routes matching the AS path regular expression\n"
7132 "A regular-expression to match the BGP AS paths\n")
7133{
7134 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7135 bgp_show_type_regexp);
7136}
7137
7138/* old command */
7139DEFUN (show_ipv6_mbgp_regexp,
7140 show_ipv6_mbgp_regexp_cmd,
7141 "show ipv6 mbgp regexp .LINE",
7142 SHOW_STR
7143 IP_STR
7144 BGP_STR
7145 "Display routes matching the AS path regular expression\n"
7146 "A regular-expression to match the MBGP AS paths\n")
7147{
7148 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7149 bgp_show_type_regexp);
7150}
7151#endif /* HAVE_IPV6 */
7152
paul94f2b392005-06-28 12:44:16 +00007153static int
paulfd79ac92004-10-13 05:06:08 +00007154bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007155 safi_t safi, enum bgp_show_type type)
7156{
7157 struct prefix_list *plist;
7158
7159 plist = prefix_list_lookup (afi, prefix_list_str);
7160 if (plist == NULL)
7161 {
7162 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7163 prefix_list_str, VTY_NEWLINE);
7164 return CMD_WARNING;
7165 }
7166
ajs5a646652004-11-05 01:25:55 +00007167 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007168}
7169
7170DEFUN (show_ip_bgp_prefix_list,
7171 show_ip_bgp_prefix_list_cmd,
7172 "show ip bgp prefix-list WORD",
7173 SHOW_STR
7174 IP_STR
7175 BGP_STR
7176 "Display routes conforming to the prefix-list\n"
7177 "IP prefix-list name\n")
7178{
7179 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7180 bgp_show_type_prefix_list);
7181}
7182
7183DEFUN (show_ip_bgp_flap_prefix_list,
7184 show_ip_bgp_flap_prefix_list_cmd,
7185 "show ip bgp flap-statistics prefix-list WORD",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "Display flap statistics of routes\n"
7190 "Display routes conforming to the prefix-list\n"
7191 "IP prefix-list name\n")
7192{
7193 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7194 bgp_show_type_flap_prefix_list);
7195}
7196
7197DEFUN (show_ip_bgp_ipv4_prefix_list,
7198 show_ip_bgp_ipv4_prefix_list_cmd,
7199 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7200 SHOW_STR
7201 IP_STR
7202 BGP_STR
7203 "Address family\n"
7204 "Address Family modifier\n"
7205 "Address Family modifier\n"
7206 "Display routes conforming to the prefix-list\n"
7207 "IP prefix-list name\n")
7208{
7209 if (strncmp (argv[0], "m", 1) == 0)
7210 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7211 bgp_show_type_prefix_list);
7212
7213 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7214 bgp_show_type_prefix_list);
7215}
7216
7217#ifdef HAVE_IPV6
7218DEFUN (show_bgp_prefix_list,
7219 show_bgp_prefix_list_cmd,
7220 "show bgp prefix-list WORD",
7221 SHOW_STR
7222 BGP_STR
7223 "Display routes conforming to the prefix-list\n"
7224 "IPv6 prefix-list name\n")
7225{
7226 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7227 bgp_show_type_prefix_list);
7228}
7229
7230ALIAS (show_bgp_prefix_list,
7231 show_bgp_ipv6_prefix_list_cmd,
7232 "show bgp ipv6 prefix-list WORD",
7233 SHOW_STR
7234 BGP_STR
7235 "Address family\n"
7236 "Display routes conforming to the prefix-list\n"
7237 "IPv6 prefix-list name\n")
7238
7239/* old command */
7240DEFUN (show_ipv6_bgp_prefix_list,
7241 show_ipv6_bgp_prefix_list_cmd,
7242 "show ipv6 bgp prefix-list WORD",
7243 SHOW_STR
7244 IPV6_STR
7245 BGP_STR
7246 "Display routes matching the prefix-list\n"
7247 "IPv6 prefix-list name\n")
7248{
7249 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7250 bgp_show_type_prefix_list);
7251}
7252
7253/* old command */
7254DEFUN (show_ipv6_mbgp_prefix_list,
7255 show_ipv6_mbgp_prefix_list_cmd,
7256 "show ipv6 mbgp prefix-list WORD",
7257 SHOW_STR
7258 IPV6_STR
7259 MBGP_STR
7260 "Display routes matching the prefix-list\n"
7261 "IPv6 prefix-list name\n")
7262{
7263 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7264 bgp_show_type_prefix_list);
7265}
7266#endif /* HAVE_IPV6 */
7267
paul94f2b392005-06-28 12:44:16 +00007268static int
paulfd79ac92004-10-13 05:06:08 +00007269bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007270 safi_t safi, enum bgp_show_type type)
7271{
7272 struct as_list *as_list;
7273
7274 as_list = as_list_lookup (filter);
7275 if (as_list == NULL)
7276 {
7277 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7278 return CMD_WARNING;
7279 }
7280
ajs5a646652004-11-05 01:25:55 +00007281 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007282}
7283
7284DEFUN (show_ip_bgp_filter_list,
7285 show_ip_bgp_filter_list_cmd,
7286 "show ip bgp filter-list WORD",
7287 SHOW_STR
7288 IP_STR
7289 BGP_STR
7290 "Display routes conforming to the filter-list\n"
7291 "Regular expression access list name\n")
7292{
7293 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7294 bgp_show_type_filter_list);
7295}
7296
7297DEFUN (show_ip_bgp_flap_filter_list,
7298 show_ip_bgp_flap_filter_list_cmd,
7299 "show ip bgp flap-statistics filter-list WORD",
7300 SHOW_STR
7301 IP_STR
7302 BGP_STR
7303 "Display flap statistics of routes\n"
7304 "Display routes conforming to the filter-list\n"
7305 "Regular expression access list name\n")
7306{
7307 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7308 bgp_show_type_flap_filter_list);
7309}
7310
7311DEFUN (show_ip_bgp_ipv4_filter_list,
7312 show_ip_bgp_ipv4_filter_list_cmd,
7313 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7314 SHOW_STR
7315 IP_STR
7316 BGP_STR
7317 "Address family\n"
7318 "Address Family modifier\n"
7319 "Address Family modifier\n"
7320 "Display routes conforming to the filter-list\n"
7321 "Regular expression access list name\n")
7322{
7323 if (strncmp (argv[0], "m", 1) == 0)
7324 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7325 bgp_show_type_filter_list);
7326
7327 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7328 bgp_show_type_filter_list);
7329}
7330
7331#ifdef HAVE_IPV6
7332DEFUN (show_bgp_filter_list,
7333 show_bgp_filter_list_cmd,
7334 "show bgp filter-list WORD",
7335 SHOW_STR
7336 BGP_STR
7337 "Display routes conforming to the filter-list\n"
7338 "Regular expression access list name\n")
7339{
7340 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7341 bgp_show_type_filter_list);
7342}
7343
7344ALIAS (show_bgp_filter_list,
7345 show_bgp_ipv6_filter_list_cmd,
7346 "show bgp ipv6 filter-list WORD",
7347 SHOW_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Display routes conforming to the filter-list\n"
7351 "Regular expression access list name\n")
7352
7353/* old command */
7354DEFUN (show_ipv6_bgp_filter_list,
7355 show_ipv6_bgp_filter_list_cmd,
7356 "show ipv6 bgp filter-list WORD",
7357 SHOW_STR
7358 IPV6_STR
7359 BGP_STR
7360 "Display routes conforming to the filter-list\n"
7361 "Regular expression access list name\n")
7362{
7363 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7364 bgp_show_type_filter_list);
7365}
7366
7367/* old command */
7368DEFUN (show_ipv6_mbgp_filter_list,
7369 show_ipv6_mbgp_filter_list_cmd,
7370 "show ipv6 mbgp filter-list WORD",
7371 SHOW_STR
7372 IPV6_STR
7373 MBGP_STR
7374 "Display routes conforming to the filter-list\n"
7375 "Regular expression access list name\n")
7376{
7377 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7378 bgp_show_type_filter_list);
7379}
7380#endif /* HAVE_IPV6 */
7381
paul94f2b392005-06-28 12:44:16 +00007382static int
paulfd79ac92004-10-13 05:06:08 +00007383bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007384 safi_t safi, enum bgp_show_type type)
7385{
7386 struct route_map *rmap;
7387
7388 rmap = route_map_lookup_by_name (rmap_str);
7389 if (! rmap)
7390 {
7391 vty_out (vty, "%% %s is not a valid route-map name%s",
7392 rmap_str, VTY_NEWLINE);
7393 return CMD_WARNING;
7394 }
7395
ajs5a646652004-11-05 01:25:55 +00007396 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007397}
7398
7399DEFUN (show_ip_bgp_route_map,
7400 show_ip_bgp_route_map_cmd,
7401 "show ip bgp route-map WORD",
7402 SHOW_STR
7403 IP_STR
7404 BGP_STR
7405 "Display routes matching the route-map\n"
7406 "A route-map to match on\n")
7407{
7408 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7409 bgp_show_type_route_map);
7410}
7411
7412DEFUN (show_ip_bgp_flap_route_map,
7413 show_ip_bgp_flap_route_map_cmd,
7414 "show ip bgp flap-statistics route-map WORD",
7415 SHOW_STR
7416 IP_STR
7417 BGP_STR
7418 "Display flap statistics of routes\n"
7419 "Display routes matching the route-map\n"
7420 "A route-map to match on\n")
7421{
7422 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7423 bgp_show_type_flap_route_map);
7424}
7425
7426DEFUN (show_ip_bgp_ipv4_route_map,
7427 show_ip_bgp_ipv4_route_map_cmd,
7428 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7429 SHOW_STR
7430 IP_STR
7431 BGP_STR
7432 "Address family\n"
7433 "Address Family modifier\n"
7434 "Address Family modifier\n"
7435 "Display routes matching the route-map\n"
7436 "A route-map to match on\n")
7437{
7438 if (strncmp (argv[0], "m", 1) == 0)
7439 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7440 bgp_show_type_route_map);
7441
7442 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7443 bgp_show_type_route_map);
7444}
7445
7446DEFUN (show_bgp_route_map,
7447 show_bgp_route_map_cmd,
7448 "show bgp route-map WORD",
7449 SHOW_STR
7450 BGP_STR
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_IP6, SAFI_UNICAST,
7455 bgp_show_type_route_map);
7456}
7457
7458ALIAS (show_bgp_route_map,
7459 show_bgp_ipv6_route_map_cmd,
7460 "show bgp ipv6 route-map WORD",
7461 SHOW_STR
7462 BGP_STR
7463 "Address family\n"
7464 "Display routes matching the route-map\n"
7465 "A route-map to match on\n")
7466
7467DEFUN (show_ip_bgp_cidr_only,
7468 show_ip_bgp_cidr_only_cmd,
7469 "show ip bgp cidr-only",
7470 SHOW_STR
7471 IP_STR
7472 BGP_STR
7473 "Display only routes with non-natural netmasks\n")
7474{
7475 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007476 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007477}
7478
7479DEFUN (show_ip_bgp_flap_cidr_only,
7480 show_ip_bgp_flap_cidr_only_cmd,
7481 "show ip bgp flap-statistics cidr-only",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Display flap statistics of routes\n"
7486 "Display only routes with non-natural netmasks\n")
7487{
7488 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007489 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007490}
7491
7492DEFUN (show_ip_bgp_ipv4_cidr_only,
7493 show_ip_bgp_ipv4_cidr_only_cmd,
7494 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7495 SHOW_STR
7496 IP_STR
7497 BGP_STR
7498 "Address family\n"
7499 "Address Family modifier\n"
7500 "Address Family modifier\n"
7501 "Display only routes with non-natural netmasks\n")
7502{
7503 if (strncmp (argv[0], "m", 1) == 0)
7504 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007505 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007506
7507 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007508 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007509}
7510
7511DEFUN (show_ip_bgp_community_all,
7512 show_ip_bgp_community_all_cmd,
7513 "show ip bgp community",
7514 SHOW_STR
7515 IP_STR
7516 BGP_STR
7517 "Display routes matching the communities\n")
7518{
7519 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007520 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007521}
7522
7523DEFUN (show_ip_bgp_ipv4_community_all,
7524 show_ip_bgp_ipv4_community_all_cmd,
7525 "show ip bgp ipv4 (unicast|multicast) community",
7526 SHOW_STR
7527 IP_STR
7528 BGP_STR
7529 "Address family\n"
7530 "Address Family modifier\n"
7531 "Address Family modifier\n"
7532 "Display routes matching the communities\n")
7533{
7534 if (strncmp (argv[0], "m", 1) == 0)
7535 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007536 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007537
7538 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007539 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007540}
7541
7542#ifdef HAVE_IPV6
7543DEFUN (show_bgp_community_all,
7544 show_bgp_community_all_cmd,
7545 "show bgp community",
7546 SHOW_STR
7547 BGP_STR
7548 "Display routes matching the communities\n")
7549{
7550 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007551 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007552}
7553
7554ALIAS (show_bgp_community_all,
7555 show_bgp_ipv6_community_all_cmd,
7556 "show bgp ipv6 community",
7557 SHOW_STR
7558 BGP_STR
7559 "Address family\n"
7560 "Display routes matching the communities\n")
7561
7562/* old command */
7563DEFUN (show_ipv6_bgp_community_all,
7564 show_ipv6_bgp_community_all_cmd,
7565 "show ipv6 bgp community",
7566 SHOW_STR
7567 IPV6_STR
7568 BGP_STR
7569 "Display routes matching the communities\n")
7570{
7571 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007572 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007573}
7574
7575/* old command */
7576DEFUN (show_ipv6_mbgp_community_all,
7577 show_ipv6_mbgp_community_all_cmd,
7578 "show ipv6 mbgp community",
7579 SHOW_STR
7580 IPV6_STR
7581 MBGP_STR
7582 "Display routes matching the communities\n")
7583{
7584 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007585 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007586}
7587#endif /* HAVE_IPV6 */
7588
paul94f2b392005-06-28 12:44:16 +00007589static int
paulfd79ac92004-10-13 05:06:08 +00007590bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7591 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007592{
7593 struct community *com;
7594 struct buffer *b;
7595 int i;
7596 char *str;
7597 int first = 0;
7598
7599 b = buffer_new (1024);
7600 for (i = 0; i < argc; i++)
7601 {
7602 if (first)
7603 buffer_putc (b, ' ');
7604 else
7605 {
7606 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7607 continue;
7608 first = 1;
7609 }
7610
7611 buffer_putstr (b, argv[i]);
7612 }
7613 buffer_putc (b, '\0');
7614
7615 str = buffer_getstr (b);
7616 buffer_free (b);
7617
7618 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007619 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007620 if (! com)
7621 {
7622 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7623 return CMD_WARNING;
7624 }
7625
ajs5a646652004-11-05 01:25:55 +00007626 return bgp_show (vty, NULL, afi, safi,
7627 (exact ? bgp_show_type_community_exact :
7628 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007629}
7630
7631DEFUN (show_ip_bgp_community,
7632 show_ip_bgp_community_cmd,
7633 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7634 SHOW_STR
7635 IP_STR
7636 BGP_STR
7637 "Display routes matching the communities\n"
7638 "community number\n"
7639 "Do not send outside local AS (well-known community)\n"
7640 "Do not advertise to any peer (well-known community)\n"
7641 "Do not export to next AS (well-known community)\n")
7642{
7643 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7644}
7645
7646ALIAS (show_ip_bgp_community,
7647 show_ip_bgp_community2_cmd,
7648 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7649 SHOW_STR
7650 IP_STR
7651 BGP_STR
7652 "Display routes matching the communities\n"
7653 "community number\n"
7654 "Do not send outside local AS (well-known community)\n"
7655 "Do not advertise to any peer (well-known community)\n"
7656 "Do not export to next AS (well-known community)\n"
7657 "community number\n"
7658 "Do not send outside local AS (well-known community)\n"
7659 "Do not advertise to any peer (well-known community)\n"
7660 "Do not export to next AS (well-known community)\n")
7661
7662ALIAS (show_ip_bgp_community,
7663 show_ip_bgp_community3_cmd,
7664 "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)",
7665 SHOW_STR
7666 IP_STR
7667 BGP_STR
7668 "Display routes matching the communities\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n"
7673 "community number\n"
7674 "Do not send outside local AS (well-known community)\n"
7675 "Do not advertise to any peer (well-known community)\n"
7676 "Do not export to next AS (well-known community)\n"
7677 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n")
7681
7682ALIAS (show_ip_bgp_community,
7683 show_ip_bgp_community4_cmd,
7684 "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)",
7685 SHOW_STR
7686 IP_STR
7687 BGP_STR
7688 "Display routes matching the communities\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 "community number\n"
7694 "Do not send outside local AS (well-known community)\n"
7695 "Do not advertise to any peer (well-known community)\n"
7696 "Do not export to next AS (well-known community)\n"
7697 "community number\n"
7698 "Do not send outside local AS (well-known community)\n"
7699 "Do not advertise to any peer (well-known community)\n"
7700 "Do not export to next AS (well-known community)\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
7706DEFUN (show_ip_bgp_ipv4_community,
7707 show_ip_bgp_ipv4_community_cmd,
7708 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7709 SHOW_STR
7710 IP_STR
7711 BGP_STR
7712 "Address family\n"
7713 "Address Family modifier\n"
7714 "Address Family modifier\n"
7715 "Display routes matching the communities\n"
7716 "community number\n"
7717 "Do not send outside local AS (well-known community)\n"
7718 "Do not advertise to any peer (well-known community)\n"
7719 "Do not export to next AS (well-known community)\n")
7720{
7721 if (strncmp (argv[0], "m", 1) == 0)
7722 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7723
7724 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7725}
7726
7727ALIAS (show_ip_bgp_ipv4_community,
7728 show_ip_bgp_ipv4_community2_cmd,
7729 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7730 SHOW_STR
7731 IP_STR
7732 BGP_STR
7733 "Address family\n"
7734 "Address Family modifier\n"
7735 "Address Family modifier\n"
7736 "Display routes matching the communities\n"
7737 "community number\n"
7738 "Do not send outside local AS (well-known community)\n"
7739 "Do not advertise to any peer (well-known community)\n"
7740 "Do not export to next AS (well-known community)\n"
7741 "community number\n"
7742 "Do not send outside local AS (well-known community)\n"
7743 "Do not advertise to any peer (well-known community)\n"
7744 "Do not export to next AS (well-known community)\n")
7745
7746ALIAS (show_ip_bgp_ipv4_community,
7747 show_ip_bgp_ipv4_community3_cmd,
7748 "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)",
7749 SHOW_STR
7750 IP_STR
7751 BGP_STR
7752 "Address family\n"
7753 "Address Family modifier\n"
7754 "Address Family modifier\n"
7755 "Display routes matching the communities\n"
7756 "community number\n"
7757 "Do not send outside local AS (well-known community)\n"
7758 "Do not advertise to any peer (well-known community)\n"
7759 "Do not export to next AS (well-known community)\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n")
7768
7769ALIAS (show_ip_bgp_ipv4_community,
7770 show_ip_bgp_ipv4_community4_cmd,
7771 "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)",
7772 SHOW_STR
7773 IP_STR
7774 BGP_STR
7775 "Address family\n"
7776 "Address Family modifier\n"
7777 "Address Family modifier\n"
7778 "Display routes matching the communities\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n"
7783 "community number\n"
7784 "Do not send outside local AS (well-known community)\n"
7785 "Do not advertise to any peer (well-known community)\n"
7786 "Do not export to next AS (well-known community)\n"
7787 "community number\n"
7788 "Do not send outside local AS (well-known community)\n"
7789 "Do not advertise to any peer (well-known community)\n"
7790 "Do not export to next AS (well-known community)\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n")
7795
7796DEFUN (show_ip_bgp_community_exact,
7797 show_ip_bgp_community_exact_cmd,
7798 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7799 SHOW_STR
7800 IP_STR
7801 BGP_STR
7802 "Display routes matching the communities\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n"
7807 "Exact match of the communities")
7808{
7809 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7810}
7811
7812ALIAS (show_ip_bgp_community_exact,
7813 show_ip_bgp_community2_exact_cmd,
7814 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7815 SHOW_STR
7816 IP_STR
7817 BGP_STR
7818 "Display routes matching the communities\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 "Exact match of the communities")
7828
7829ALIAS (show_ip_bgp_community_exact,
7830 show_ip_bgp_community3_exact_cmd,
7831 "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",
7832 SHOW_STR
7833 IP_STR
7834 BGP_STR
7835 "Display routes matching the communities\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n"
7840 "community number\n"
7841 "Do not send outside local AS (well-known community)\n"
7842 "Do not advertise to any peer (well-known community)\n"
7843 "Do not export to next AS (well-known community)\n"
7844 "community number\n"
7845 "Do not send outside local AS (well-known community)\n"
7846 "Do not advertise to any peer (well-known community)\n"
7847 "Do not export to next AS (well-known community)\n"
7848 "Exact match of the communities")
7849
7850ALIAS (show_ip_bgp_community_exact,
7851 show_ip_bgp_community4_exact_cmd,
7852 "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",
7853 SHOW_STR
7854 IP_STR
7855 BGP_STR
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n"
7873 "Exact match of the communities")
7874
7875DEFUN (show_ip_bgp_ipv4_community_exact,
7876 show_ip_bgp_ipv4_community_exact_cmd,
7877 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7878 SHOW_STR
7879 IP_STR
7880 BGP_STR
7881 "Address family\n"
7882 "Address Family modifier\n"
7883 "Address Family modifier\n"
7884 "Display routes matching the communities\n"
7885 "community number\n"
7886 "Do not send outside local AS (well-known community)\n"
7887 "Do not advertise to any peer (well-known community)\n"
7888 "Do not export to next AS (well-known community)\n"
7889 "Exact match of the communities")
7890{
7891 if (strncmp (argv[0], "m", 1) == 0)
7892 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7893
7894 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7895}
7896
7897ALIAS (show_ip_bgp_ipv4_community_exact,
7898 show_ip_bgp_ipv4_community2_exact_cmd,
7899 "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",
7900 SHOW_STR
7901 IP_STR
7902 BGP_STR
7903 "Address family\n"
7904 "Address Family modifier\n"
7905 "Address Family modifier\n"
7906 "Display routes matching the communities\n"
7907 "community number\n"
7908 "Do not send outside local AS (well-known community)\n"
7909 "Do not advertise to any peer (well-known community)\n"
7910 "Do not export to next AS (well-known community)\n"
7911 "community number\n"
7912 "Do not send outside local AS (well-known community)\n"
7913 "Do not advertise to any peer (well-known community)\n"
7914 "Do not export to next AS (well-known community)\n"
7915 "Exact match of the communities")
7916
7917ALIAS (show_ip_bgp_ipv4_community_exact,
7918 show_ip_bgp_ipv4_community3_exact_cmd,
7919 "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",
7920 SHOW_STR
7921 IP_STR
7922 BGP_STR
7923 "Address family\n"
7924 "Address Family modifier\n"
7925 "Address Family modifier\n"
7926 "Display routes matching the communities\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "Exact match of the communities")
7940
7941ALIAS (show_ip_bgp_ipv4_community_exact,
7942 show_ip_bgp_ipv4_community4_exact_cmd,
7943 "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",
7944 SHOW_STR
7945 IP_STR
7946 BGP_STR
7947 "Address family\n"
7948 "Address Family modifier\n"
7949 "Address Family modifier\n"
7950 "Display routes matching the communities\n"
7951 "community number\n"
7952 "Do not send outside local AS (well-known community)\n"
7953 "Do not advertise to any peer (well-known community)\n"
7954 "Do not export to next AS (well-known community)\n"
7955 "community number\n"
7956 "Do not send outside local AS (well-known community)\n"
7957 "Do not advertise to any peer (well-known community)\n"
7958 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7968
7969#ifdef HAVE_IPV6
7970DEFUN (show_bgp_community,
7971 show_bgp_community_cmd,
7972 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7973 SHOW_STR
7974 BGP_STR
7975 "Display routes matching the communities\n"
7976 "community number\n"
7977 "Do not send outside local AS (well-known community)\n"
7978 "Do not advertise to any peer (well-known community)\n"
7979 "Do not export to next AS (well-known community)\n")
7980{
7981 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7982}
7983
7984ALIAS (show_bgp_community,
7985 show_bgp_ipv6_community_cmd,
7986 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7987 SHOW_STR
7988 BGP_STR
7989 "Address family\n"
7990 "Display routes matching the communities\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n")
7995
7996ALIAS (show_bgp_community,
7997 show_bgp_community2_cmd,
7998 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7999 SHOW_STR
8000 BGP_STR
8001 "Display routes matching the communities\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n")
8010
8011ALIAS (show_bgp_community,
8012 show_bgp_ipv6_community2_cmd,
8013 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8014 SHOW_STR
8015 BGP_STR
8016 "Address family\n"
8017 "Display routes matching the communities\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n")
8026
8027ALIAS (show_bgp_community,
8028 show_bgp_community3_cmd,
8029 "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)",
8030 SHOW_STR
8031 BGP_STR
8032 "Display routes matching the communities\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
8046ALIAS (show_bgp_community,
8047 show_bgp_ipv6_community3_cmd,
8048 "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)",
8049 SHOW_STR
8050 BGP_STR
8051 "Address family\n"
8052 "Display routes matching the communities\n"
8053 "community number\n"
8054 "Do not send outside local AS (well-known community)\n"
8055 "Do not advertise to any peer (well-known community)\n"
8056 "Do not export to next AS (well-known community)\n"
8057 "community number\n"
8058 "Do not send outside local AS (well-known community)\n"
8059 "Do not advertise to any peer (well-known community)\n"
8060 "Do not export to next AS (well-known community)\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\n")
8065
8066ALIAS (show_bgp_community,
8067 show_bgp_community4_cmd,
8068 "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)",
8069 SHOW_STR
8070 BGP_STR
8071 "Display routes matching the communities\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "community number\n"
8081 "Do not send outside local AS (well-known community)\n"
8082 "Do not advertise to any peer (well-known community)\n"
8083 "Do not export to next AS (well-known community)\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n")
8088
8089ALIAS (show_bgp_community,
8090 show_bgp_ipv6_community4_cmd,
8091 "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)",
8092 SHOW_STR
8093 BGP_STR
8094 "Address family\n"
8095 "Display routes matching the communities\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\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
8113/* old command */
8114DEFUN (show_ipv6_bgp_community,
8115 show_ipv6_bgp_community_cmd,
8116 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8117 SHOW_STR
8118 IPV6_STR
8119 BGP_STR
8120 "Display routes matching the communities\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n")
8125{
8126 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8127}
8128
8129/* old command */
8130ALIAS (show_ipv6_bgp_community,
8131 show_ipv6_bgp_community2_cmd,
8132 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8133 SHOW_STR
8134 IPV6_STR
8135 BGP_STR
8136 "Display routes matching the communities\n"
8137 "community number\n"
8138 "Do not send outside local AS (well-known community)\n"
8139 "Do not advertise to any peer (well-known community)\n"
8140 "Do not export to next AS (well-known community)\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n")
8145
8146/* old command */
8147ALIAS (show_ipv6_bgp_community,
8148 show_ipv6_bgp_community3_cmd,
8149 "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)",
8150 SHOW_STR
8151 IPV6_STR
8152 BGP_STR
8153 "Display routes matching the communities\n"
8154 "community number\n"
8155 "Do not send outside local AS (well-known community)\n"
8156 "Do not advertise to any peer (well-known community)\n"
8157 "Do not export to next AS (well-known community)\n"
8158 "community number\n"
8159 "Do not send outside local AS (well-known community)\n"
8160 "Do not advertise to any peer (well-known community)\n"
8161 "Do not export to next AS (well-known community)\n"
8162 "community number\n"
8163 "Do not send outside local AS (well-known community)\n"
8164 "Do not advertise to any peer (well-known community)\n"
8165 "Do not export to next AS (well-known community)\n")
8166
8167/* old command */
8168ALIAS (show_ipv6_bgp_community,
8169 show_ipv6_bgp_community4_cmd,
8170 "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)",
8171 SHOW_STR
8172 IPV6_STR
8173 BGP_STR
8174 "Display routes matching the communities\n"
8175 "community number\n"
8176 "Do not send outside local AS (well-known community)\n"
8177 "Do not advertise to any peer (well-known community)\n"
8178 "Do not export to next AS (well-known community)\n"
8179 "community number\n"
8180 "Do not send outside local AS (well-known community)\n"
8181 "Do not advertise to any peer (well-known community)\n"
8182 "Do not export to next AS (well-known community)\n"
8183 "community number\n"
8184 "Do not send outside local AS (well-known community)\n"
8185 "Do not advertise to any peer (well-known community)\n"
8186 "Do not export to next AS (well-known community)\n"
8187 "community number\n"
8188 "Do not send outside local AS (well-known community)\n"
8189 "Do not advertise to any peer (well-known community)\n"
8190 "Do not export to next AS (well-known community)\n")
8191
8192DEFUN (show_bgp_community_exact,
8193 show_bgp_community_exact_cmd,
8194 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8195 SHOW_STR
8196 BGP_STR
8197 "Display routes matching the communities\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "Exact match of the communities")
8203{
8204 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8205}
8206
8207ALIAS (show_bgp_community_exact,
8208 show_bgp_ipv6_community_exact_cmd,
8209 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8210 SHOW_STR
8211 BGP_STR
8212 "Address family\n"
8213 "Display routes matching the communities\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "Exact match of the communities")
8219
8220ALIAS (show_bgp_community_exact,
8221 show_bgp_community2_exact_cmd,
8222 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8223 SHOW_STR
8224 BGP_STR
8225 "Display routes matching the communities\n"
8226 "community number\n"
8227 "Do not send outside local AS (well-known community)\n"
8228 "Do not advertise to any peer (well-known community)\n"
8229 "Do not export to next AS (well-known community)\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
8236ALIAS (show_bgp_community_exact,
8237 show_bgp_ipv6_community2_exact_cmd,
8238 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8239 SHOW_STR
8240 BGP_STR
8241 "Address family\n"
8242 "Display routes matching the communities\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "Exact match of the communities")
8252
8253ALIAS (show_bgp_community_exact,
8254 show_bgp_community3_exact_cmd,
8255 "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",
8256 SHOW_STR
8257 BGP_STR
8258 "Display routes matching the communities\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n"
8271 "Exact match of the communities")
8272
8273ALIAS (show_bgp_community_exact,
8274 show_bgp_ipv6_community3_exact_cmd,
8275 "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",
8276 SHOW_STR
8277 BGP_STR
8278 "Address family\n"
8279 "Display routes matching the communities\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "Exact match of the communities")
8293
8294ALIAS (show_bgp_community_exact,
8295 show_bgp_community4_exact_cmd,
8296 "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",
8297 SHOW_STR
8298 BGP_STR
8299 "Display routes matching the communities\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8317
8318ALIAS (show_bgp_community_exact,
8319 show_bgp_ipv6_community4_exact_cmd,
8320 "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",
8321 SHOW_STR
8322 BGP_STR
8323 "Address family\n"
8324 "Display routes matching the communities\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "Exact match of the communities")
8342
8343/* old command */
8344DEFUN (show_ipv6_bgp_community_exact,
8345 show_ipv6_bgp_community_exact_cmd,
8346 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8347 SHOW_STR
8348 IPV6_STR
8349 BGP_STR
8350 "Display routes matching the communities\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n"
8355 "Exact match of the communities")
8356{
8357 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8358}
8359
8360/* old command */
8361ALIAS (show_ipv6_bgp_community_exact,
8362 show_ipv6_bgp_community2_exact_cmd,
8363 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8364 SHOW_STR
8365 IPV6_STR
8366 BGP_STR
8367 "Display routes matching the communities\n"
8368 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "Exact match of the communities")
8377
8378/* old command */
8379ALIAS (show_ipv6_bgp_community_exact,
8380 show_ipv6_bgp_community3_exact_cmd,
8381 "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",
8382 SHOW_STR
8383 IPV6_STR
8384 BGP_STR
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n"
8398 "Exact match of the communities")
8399
8400/* old command */
8401ALIAS (show_ipv6_bgp_community_exact,
8402 show_ipv6_bgp_community4_exact_cmd,
8403 "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",
8404 SHOW_STR
8405 IPV6_STR
8406 BGP_STR
8407 "Display routes matching the communities\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n"
8412 "community number\n"
8413 "Do not send outside local AS (well-known community)\n"
8414 "Do not advertise to any peer (well-known community)\n"
8415 "Do not export to next AS (well-known community)\n"
8416 "community number\n"
8417 "Do not send outside local AS (well-known community)\n"
8418 "Do not advertise to any peer (well-known community)\n"
8419 "Do not export to next AS (well-known community)\n"
8420 "community number\n"
8421 "Do not send outside local AS (well-known community)\n"
8422 "Do not advertise to any peer (well-known community)\n"
8423 "Do not export to next AS (well-known community)\n"
8424 "Exact match of the communities")
8425
8426/* old command */
8427DEFUN (show_ipv6_mbgp_community,
8428 show_ipv6_mbgp_community_cmd,
8429 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8430 SHOW_STR
8431 IPV6_STR
8432 MBGP_STR
8433 "Display routes matching the communities\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n")
8438{
8439 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8440}
8441
8442/* old command */
8443ALIAS (show_ipv6_mbgp_community,
8444 show_ipv6_mbgp_community2_cmd,
8445 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8446 SHOW_STR
8447 IPV6_STR
8448 MBGP_STR
8449 "Display routes matching the communities\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n")
8458
8459/* old command */
8460ALIAS (show_ipv6_mbgp_community,
8461 show_ipv6_mbgp_community3_cmd,
8462 "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)",
8463 SHOW_STR
8464 IPV6_STR
8465 MBGP_STR
8466 "Display routes matching the communities\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n")
8479
8480/* old command */
8481ALIAS (show_ipv6_mbgp_community,
8482 show_ipv6_mbgp_community4_cmd,
8483 "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)",
8484 SHOW_STR
8485 IPV6_STR
8486 MBGP_STR
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "community number\n"
8501 "Do not send outside local AS (well-known community)\n"
8502 "Do not advertise to any peer (well-known community)\n"
8503 "Do not export to next AS (well-known community)\n")
8504
8505/* old command */
8506DEFUN (show_ipv6_mbgp_community_exact,
8507 show_ipv6_mbgp_community_exact_cmd,
8508 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8509 SHOW_STR
8510 IPV6_STR
8511 MBGP_STR
8512 "Display routes matching the communities\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "Exact match of the communities")
8518{
8519 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8520}
8521
8522/* old command */
8523ALIAS (show_ipv6_mbgp_community_exact,
8524 show_ipv6_mbgp_community2_exact_cmd,
8525 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8526 SHOW_STR
8527 IPV6_STR
8528 MBGP_STR
8529 "Display routes matching the communities\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "Exact match of the communities")
8539
8540/* old command */
8541ALIAS (show_ipv6_mbgp_community_exact,
8542 show_ipv6_mbgp_community3_exact_cmd,
8543 "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",
8544 SHOW_STR
8545 IPV6_STR
8546 MBGP_STR
8547 "Display routes matching the communities\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "community number\n"
8557 "Do not send outside local AS (well-known community)\n"
8558 "Do not advertise to any peer (well-known community)\n"
8559 "Do not export to next AS (well-known community)\n"
8560 "Exact match of the communities")
8561
8562/* old command */
8563ALIAS (show_ipv6_mbgp_community_exact,
8564 show_ipv6_mbgp_community4_exact_cmd,
8565 "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",
8566 SHOW_STR
8567 IPV6_STR
8568 MBGP_STR
8569 "Display routes matching the communities\n"
8570 "community number\n"
8571 "Do not send outside local AS (well-known community)\n"
8572 "Do not advertise to any peer (well-known community)\n"
8573 "Do not export to next AS (well-known community)\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "Exact match of the communities")
8587#endif /* HAVE_IPV6 */
8588
paul94f2b392005-06-28 12:44:16 +00008589static int
paulfd79ac92004-10-13 05:06:08 +00008590bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008591 u_int16_t afi, u_char safi)
8592{
8593 struct community_list *list;
8594
hassofee6e4e2005-02-02 16:29:31 +00008595 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008596 if (list == NULL)
8597 {
8598 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8599 VTY_NEWLINE);
8600 return CMD_WARNING;
8601 }
8602
ajs5a646652004-11-05 01:25:55 +00008603 return bgp_show (vty, NULL, afi, safi,
8604 (exact ? bgp_show_type_community_list_exact :
8605 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008606}
8607
8608DEFUN (show_ip_bgp_community_list,
8609 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008610 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008611 SHOW_STR
8612 IP_STR
8613 BGP_STR
8614 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008615 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008616 "community-list name\n")
8617{
8618 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8619}
8620
8621DEFUN (show_ip_bgp_ipv4_community_list,
8622 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008623 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008624 SHOW_STR
8625 IP_STR
8626 BGP_STR
8627 "Address family\n"
8628 "Address Family modifier\n"
8629 "Address Family modifier\n"
8630 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008631 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008632 "community-list name\n")
8633{
8634 if (strncmp (argv[0], "m", 1) == 0)
8635 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8636
8637 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8638}
8639
8640DEFUN (show_ip_bgp_community_list_exact,
8641 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008642 "show ip bgp community-list (<1-500>|WORD) exact-match",
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 "Exact match of the communities\n")
8650{
8651 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8652}
8653
8654DEFUN (show_ip_bgp_ipv4_community_list_exact,
8655 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008656 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008657 SHOW_STR
8658 IP_STR
8659 BGP_STR
8660 "Address family\n"
8661 "Address Family modifier\n"
8662 "Address Family modifier\n"
8663 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008664 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008665 "community-list name\n"
8666 "Exact match of the communities\n")
8667{
8668 if (strncmp (argv[0], "m", 1) == 0)
8669 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8670
8671 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8672}
8673
8674#ifdef HAVE_IPV6
8675DEFUN (show_bgp_community_list,
8676 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008677 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008678 SHOW_STR
8679 BGP_STR
8680 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008681 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008682 "community-list name\n")
8683{
8684 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8685}
8686
8687ALIAS (show_bgp_community_list,
8688 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008689 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008690 SHOW_STR
8691 BGP_STR
8692 "Address family\n"
8693 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008694 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008695 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008696
8697/* old command */
8698DEFUN (show_ipv6_bgp_community_list,
8699 show_ipv6_bgp_community_list_cmd,
8700 "show ipv6 bgp community-list WORD",
8701 SHOW_STR
8702 IPV6_STR
8703 BGP_STR
8704 "Display routes matching the community-list\n"
8705 "community-list name\n")
8706{
8707 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8708}
8709
8710/* old command */
8711DEFUN (show_ipv6_mbgp_community_list,
8712 show_ipv6_mbgp_community_list_cmd,
8713 "show ipv6 mbgp community-list WORD",
8714 SHOW_STR
8715 IPV6_STR
8716 MBGP_STR
8717 "Display routes matching the community-list\n"
8718 "community-list name\n")
8719{
8720 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8721}
8722
8723DEFUN (show_bgp_community_list_exact,
8724 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008725 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008726 SHOW_STR
8727 BGP_STR
8728 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008729 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008730 "community-list name\n"
8731 "Exact match of the communities\n")
8732{
8733 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8734}
8735
8736ALIAS (show_bgp_community_list_exact,
8737 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008738 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008739 SHOW_STR
8740 BGP_STR
8741 "Address family\n"
8742 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008743 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008744 "community-list name\n"
8745 "Exact match of the communities\n")
8746
8747/* old command */
8748DEFUN (show_ipv6_bgp_community_list_exact,
8749 show_ipv6_bgp_community_list_exact_cmd,
8750 "show ipv6 bgp community-list WORD exact-match",
8751 SHOW_STR
8752 IPV6_STR
8753 BGP_STR
8754 "Display routes matching the community-list\n"
8755 "community-list name\n"
8756 "Exact match of the communities\n")
8757{
8758 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8759}
8760
8761/* old command */
8762DEFUN (show_ipv6_mbgp_community_list_exact,
8763 show_ipv6_mbgp_community_list_exact_cmd,
8764 "show ipv6 mbgp community-list WORD exact-match",
8765 SHOW_STR
8766 IPV6_STR
8767 MBGP_STR
8768 "Display routes matching the community-list\n"
8769 "community-list name\n"
8770 "Exact match of the communities\n")
8771{
8772 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8773}
8774#endif /* HAVE_IPV6 */
8775
paul94f2b392005-06-28 12:44:16 +00008776static int
paulfd79ac92004-10-13 05:06:08 +00008777bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008778 safi_t safi, enum bgp_show_type type)
8779{
8780 int ret;
8781 struct prefix *p;
8782
8783 p = prefix_new();
8784
8785 ret = str2prefix (prefix, p);
8786 if (! ret)
8787 {
8788 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8789 return CMD_WARNING;
8790 }
8791
ajs5a646652004-11-05 01:25:55 +00008792 ret = bgp_show (vty, NULL, afi, safi, type, p);
8793 prefix_free(p);
8794 return ret;
paul718e3742002-12-13 20:15:29 +00008795}
8796
8797DEFUN (show_ip_bgp_prefix_longer,
8798 show_ip_bgp_prefix_longer_cmd,
8799 "show ip bgp A.B.C.D/M longer-prefixes",
8800 SHOW_STR
8801 IP_STR
8802 BGP_STR
8803 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8804 "Display route and more specific routes\n")
8805{
8806 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8807 bgp_show_type_prefix_longer);
8808}
8809
8810DEFUN (show_ip_bgp_flap_prefix_longer,
8811 show_ip_bgp_flap_prefix_longer_cmd,
8812 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8813 SHOW_STR
8814 IP_STR
8815 BGP_STR
8816 "Display flap statistics of routes\n"
8817 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8818 "Display route and more specific routes\n")
8819{
8820 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8821 bgp_show_type_flap_prefix_longer);
8822}
8823
8824DEFUN (show_ip_bgp_ipv4_prefix_longer,
8825 show_ip_bgp_ipv4_prefix_longer_cmd,
8826 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8827 SHOW_STR
8828 IP_STR
8829 BGP_STR
8830 "Address family\n"
8831 "Address Family modifier\n"
8832 "Address Family modifier\n"
8833 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8834 "Display route and more specific routes\n")
8835{
8836 if (strncmp (argv[0], "m", 1) == 0)
8837 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8838 bgp_show_type_prefix_longer);
8839
8840 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8841 bgp_show_type_prefix_longer);
8842}
8843
8844DEFUN (show_ip_bgp_flap_address,
8845 show_ip_bgp_flap_address_cmd,
8846 "show ip bgp flap-statistics A.B.C.D",
8847 SHOW_STR
8848 IP_STR
8849 BGP_STR
8850 "Display flap statistics of routes\n"
8851 "Network in the BGP routing table to display\n")
8852{
8853 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8854 bgp_show_type_flap_address);
8855}
8856
8857DEFUN (show_ip_bgp_flap_prefix,
8858 show_ip_bgp_flap_prefix_cmd,
8859 "show ip bgp flap-statistics A.B.C.D/M",
8860 SHOW_STR
8861 IP_STR
8862 BGP_STR
8863 "Display flap statistics of routes\n"
8864 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8865{
8866 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8867 bgp_show_type_flap_prefix);
8868}
8869#ifdef HAVE_IPV6
8870DEFUN (show_bgp_prefix_longer,
8871 show_bgp_prefix_longer_cmd,
8872 "show bgp X:X::X:X/M longer-prefixes",
8873 SHOW_STR
8874 BGP_STR
8875 "IPv6 prefix <network>/<length>\n"
8876 "Display route and more specific routes\n")
8877{
8878 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8879 bgp_show_type_prefix_longer);
8880}
8881
8882ALIAS (show_bgp_prefix_longer,
8883 show_bgp_ipv6_prefix_longer_cmd,
8884 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8885 SHOW_STR
8886 BGP_STR
8887 "Address family\n"
8888 "IPv6 prefix <network>/<length>\n"
8889 "Display route and more specific routes\n")
8890
8891/* old command */
8892DEFUN (show_ipv6_bgp_prefix_longer,
8893 show_ipv6_bgp_prefix_longer_cmd,
8894 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8895 SHOW_STR
8896 IPV6_STR
8897 BGP_STR
8898 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8899 "Display route and more specific routes\n")
8900{
8901 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8902 bgp_show_type_prefix_longer);
8903}
8904
8905/* old command */
8906DEFUN (show_ipv6_mbgp_prefix_longer,
8907 show_ipv6_mbgp_prefix_longer_cmd,
8908 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8909 SHOW_STR
8910 IPV6_STR
8911 MBGP_STR
8912 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8913 "Display route and more specific routes\n")
8914{
8915 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8916 bgp_show_type_prefix_longer);
8917}
8918#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008919
paul94f2b392005-06-28 12:44:16 +00008920static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008921peer_lookup_in_view (struct vty *vty, const char *view_name,
8922 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008923{
8924 int ret;
8925 struct bgp *bgp;
8926 struct peer *peer;
8927 union sockunion su;
8928
8929 /* BGP structure lookup. */
8930 if (view_name)
8931 {
8932 bgp = bgp_lookup_by_name (view_name);
8933 if (! bgp)
8934 {
8935 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8936 return NULL;
8937 }
8938 }
paul5228ad22004-06-04 17:58:18 +00008939 else
paulbb46e942003-10-24 19:02:03 +00008940 {
8941 bgp = bgp_get_default ();
8942 if (! bgp)
8943 {
8944 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8945 return NULL;
8946 }
8947 }
8948
8949 /* Get peer sockunion. */
8950 ret = str2sockunion (ip_str, &su);
8951 if (ret < 0)
8952 {
8953 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8954 return NULL;
8955 }
8956
8957 /* Peer structure lookup. */
8958 peer = peer_lookup (bgp, &su);
8959 if (! peer)
8960 {
8961 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8962 return NULL;
8963 }
8964
8965 return peer;
8966}
Paul Jakma2815e612006-09-14 02:56:07 +00008967
8968enum bgp_stats
8969{
8970 BGP_STATS_MAXBITLEN = 0,
8971 BGP_STATS_RIB,
8972 BGP_STATS_PREFIXES,
8973 BGP_STATS_TOTPLEN,
8974 BGP_STATS_UNAGGREGATEABLE,
8975 BGP_STATS_MAX_AGGREGATEABLE,
8976 BGP_STATS_AGGREGATES,
8977 BGP_STATS_SPACE,
8978 BGP_STATS_ASPATH_COUNT,
8979 BGP_STATS_ASPATH_MAXHOPS,
8980 BGP_STATS_ASPATH_TOTHOPS,
8981 BGP_STATS_ASPATH_MAXSIZE,
8982 BGP_STATS_ASPATH_TOTSIZE,
8983 BGP_STATS_ASN_HIGHEST,
8984 BGP_STATS_MAX,
8985};
paulbb46e942003-10-24 19:02:03 +00008986
Paul Jakma2815e612006-09-14 02:56:07 +00008987static const char *table_stats_strs[] =
8988{
8989 [BGP_STATS_PREFIXES] = "Total Prefixes",
8990 [BGP_STATS_TOTPLEN] = "Average prefix length",
8991 [BGP_STATS_RIB] = "Total Advertisements",
8992 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8993 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8994 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8995 [BGP_STATS_SPACE] = "Address space advertised",
8996 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8997 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8998 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8999 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9000 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9001 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9002 [BGP_STATS_MAX] = NULL,
9003};
9004
9005struct bgp_table_stats
9006{
9007 struct bgp_table *table;
9008 unsigned long long counts[BGP_STATS_MAX];
9009};
9010
9011#if 0
9012#define TALLY_SIGFIG 100000
9013static unsigned long
9014ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9015{
9016 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9017 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9018 unsigned long ret = newtot / count;
9019
9020 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9021 return ret + 1;
9022 else
9023 return ret;
9024}
9025#endif
9026
9027static int
9028bgp_table_stats_walker (struct thread *t)
9029{
9030 struct bgp_node *rn;
9031 struct bgp_node *top;
9032 struct bgp_table_stats *ts = THREAD_ARG (t);
9033 unsigned int space = 0;
9034
Paul Jakma53d9f672006-10-15 23:41:16 +00009035 if (!(top = bgp_table_top (ts->table)))
9036 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009037
9038 switch (top->p.family)
9039 {
9040 case AF_INET:
9041 space = IPV4_MAX_BITLEN;
9042 break;
9043 case AF_INET6:
9044 space = IPV6_MAX_BITLEN;
9045 break;
9046 }
9047
9048 ts->counts[BGP_STATS_MAXBITLEN] = space;
9049
9050 for (rn = top; rn; rn = bgp_route_next (rn))
9051 {
9052 struct bgp_info *ri;
9053 struct bgp_node *prn = rn->parent;
9054 unsigned int rinum = 0;
9055
9056 if (rn == top)
9057 continue;
9058
9059 if (!rn->info)
9060 continue;
9061
9062 ts->counts[BGP_STATS_PREFIXES]++;
9063 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9064
9065#if 0
9066 ts->counts[BGP_STATS_AVGPLEN]
9067 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9068 ts->counts[BGP_STATS_AVGPLEN],
9069 rn->p.prefixlen);
9070#endif
9071
9072 /* check if the prefix is included by any other announcements */
9073 while (prn && !prn->info)
9074 prn = prn->parent;
9075
9076 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009077 {
9078 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9079 /* announced address space */
9080 if (space)
9081 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9082 }
Paul Jakma2815e612006-09-14 02:56:07 +00009083 else if (prn->info)
9084 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9085
Paul Jakma2815e612006-09-14 02:56:07 +00009086 for (ri = rn->info; ri; ri = ri->next)
9087 {
9088 rinum++;
9089 ts->counts[BGP_STATS_RIB]++;
9090
9091 if (ri->attr &&
9092 (CHECK_FLAG (ri->attr->flag,
9093 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9094 ts->counts[BGP_STATS_AGGREGATES]++;
9095
9096 /* as-path stats */
9097 if (ri->attr && ri->attr->aspath)
9098 {
9099 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9100 unsigned int size = aspath_size (ri->attr->aspath);
9101 as_t highest = aspath_highest (ri->attr->aspath);
9102
9103 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9104
9105 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9106 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9107
9108 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9109 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9110
9111 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9112 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9113#if 0
9114 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9115 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9116 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9117 hops);
9118 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9119 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9120 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9121 size);
9122#endif
9123 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9124 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9125 }
9126 }
9127 }
9128 return 0;
9129}
9130
9131static int
9132bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9133{
9134 struct bgp_table_stats ts;
9135 unsigned int i;
9136
9137 if (!bgp->rib[afi][safi])
9138 {
9139 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9140 return CMD_WARNING;
9141 }
9142
9143 memset (&ts, 0, sizeof (ts));
9144 ts.table = bgp->rib[afi][safi];
9145 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9146
9147 vty_out (vty, "BGP %s RIB statistics%s%s",
9148 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9149
9150 for (i = 0; i < BGP_STATS_MAX; i++)
9151 {
9152 if (!table_stats_strs[i])
9153 continue;
9154
9155 switch (i)
9156 {
9157#if 0
9158 case BGP_STATS_ASPATH_AVGHOPS:
9159 case BGP_STATS_ASPATH_AVGSIZE:
9160 case BGP_STATS_AVGPLEN:
9161 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9162 vty_out (vty, "%12.2f",
9163 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9164 break;
9165#endif
9166 case BGP_STATS_ASPATH_TOTHOPS:
9167 case BGP_STATS_ASPATH_TOTSIZE:
9168 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9169 vty_out (vty, "%12.2f",
9170 ts.counts[i] ?
9171 (float)ts.counts[i] /
9172 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9173 : 0);
9174 break;
9175 case BGP_STATS_TOTPLEN:
9176 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9177 vty_out (vty, "%12.2f",
9178 ts.counts[i] ?
9179 (float)ts.counts[i] /
9180 (float)ts.counts[BGP_STATS_PREFIXES]
9181 : 0);
9182 break;
9183 case BGP_STATS_SPACE:
9184 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9185 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9186 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9187 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009188 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009189 vty_out (vty, "%12.2f%s",
9190 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009191 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009192 VTY_NEWLINE);
9193 vty_out (vty, "%30s: ", "/8 equivalent ");
9194 vty_out (vty, "%12.2f%s",
9195 (float)ts.counts[BGP_STATS_SPACE] /
9196 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9197 VTY_NEWLINE);
9198 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9199 break;
9200 vty_out (vty, "%30s: ", "/24 equivalent ");
9201 vty_out (vty, "%12.2f",
9202 (float)ts.counts[BGP_STATS_SPACE] /
9203 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9204 break;
9205 default:
9206 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9207 vty_out (vty, "%12llu", ts.counts[i]);
9208 }
9209
9210 vty_out (vty, "%s", VTY_NEWLINE);
9211 }
9212 return CMD_SUCCESS;
9213}
9214
9215static int
9216bgp_table_stats_vty (struct vty *vty, const char *name,
9217 const char *afi_str, const char *safi_str)
9218{
9219 struct bgp *bgp;
9220 afi_t afi;
9221 safi_t safi;
9222
9223 if (name)
9224 bgp = bgp_lookup_by_name (name);
9225 else
9226 bgp = bgp_get_default ();
9227
9228 if (!bgp)
9229 {
9230 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9231 return CMD_WARNING;
9232 }
9233 if (strncmp (afi_str, "ipv", 3) == 0)
9234 {
9235 if (strncmp (afi_str, "ipv4", 4) == 0)
9236 afi = AFI_IP;
9237 else if (strncmp (afi_str, "ipv6", 4) == 0)
9238 afi = AFI_IP6;
9239 else
9240 {
9241 vty_out (vty, "%% Invalid address family %s%s",
9242 afi_str, VTY_NEWLINE);
9243 return CMD_WARNING;
9244 }
9245 if (strncmp (safi_str, "m", 1) == 0)
9246 safi = SAFI_MULTICAST;
9247 else if (strncmp (safi_str, "u", 1) == 0)
9248 safi = SAFI_UNICAST;
9249 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9250 safi = BGP_SAFI_VPNV4;
9251 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9252 safi = BGP_SAFI_VPNV6;
9253 else
9254 {
9255 vty_out (vty, "%% Invalid subsequent address family %s%s",
9256 safi_str, VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259 }
9260 else
9261 {
9262 vty_out (vty, "%% Invalid address family %s%s",
9263 afi_str, VTY_NEWLINE);
9264 return CMD_WARNING;
9265 }
9266
9267 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9268 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9269 {
9270 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9271 afi_str, safi_str, VTY_NEWLINE);
9272 return CMD_WARNING;
9273 }
9274 return bgp_table_stats (vty, bgp, afi, safi);
9275}
9276
9277DEFUN (show_bgp_statistics,
9278 show_bgp_statistics_cmd,
9279 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9280 SHOW_STR
9281 BGP_STR
9282 "Address family\n"
9283 "Address family\n"
9284 "Address Family modifier\n"
9285 "Address Family modifier\n"
9286 "BGP RIB advertisement statistics\n")
9287{
9288 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9289}
9290
9291ALIAS (show_bgp_statistics,
9292 show_bgp_statistics_vpnv4_cmd,
9293 "show bgp (ipv4) (vpnv4) statistics",
9294 SHOW_STR
9295 BGP_STR
9296 "Address family\n"
9297 "Address Family modifier\n"
9298 "BGP RIB advertisement statistics\n")
9299
9300DEFUN (show_bgp_statistics_view,
9301 show_bgp_statistics_view_cmd,
9302 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9303 SHOW_STR
9304 BGP_STR
9305 "BGP view\n"
9306 "Address family\n"
9307 "Address family\n"
9308 "Address Family modifier\n"
9309 "Address Family modifier\n"
9310 "BGP RIB advertisement statistics\n")
9311{
9312 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9313}
9314
9315ALIAS (show_bgp_statistics_view,
9316 show_bgp_statistics_view_vpnv4_cmd,
9317 "show bgp view WORD (ipv4) (vpnv4) statistics",
9318 SHOW_STR
9319 BGP_STR
9320 "BGP view\n"
9321 "Address family\n"
9322 "Address Family modifier\n"
9323 "BGP RIB advertisement statistics\n")
9324
Paul Jakmaff7924f2006-09-04 01:10:36 +00009325enum bgp_pcounts
9326{
9327 PCOUNT_ADJ_IN = 0,
9328 PCOUNT_DAMPED,
9329 PCOUNT_REMOVED,
9330 PCOUNT_HISTORY,
9331 PCOUNT_STALE,
9332 PCOUNT_VALID,
9333 PCOUNT_ALL,
9334 PCOUNT_COUNTED,
9335 PCOUNT_PFCNT, /* the figure we display to users */
9336 PCOUNT_MAX,
9337};
9338
9339static const char *pcount_strs[] =
9340{
9341 [PCOUNT_ADJ_IN] = "Adj-in",
9342 [PCOUNT_DAMPED] = "Damped",
9343 [PCOUNT_REMOVED] = "Removed",
9344 [PCOUNT_HISTORY] = "History",
9345 [PCOUNT_STALE] = "Stale",
9346 [PCOUNT_VALID] = "Valid",
9347 [PCOUNT_ALL] = "All RIB",
9348 [PCOUNT_COUNTED] = "PfxCt counted",
9349 [PCOUNT_PFCNT] = "Useable",
9350 [PCOUNT_MAX] = NULL,
9351};
9352
Paul Jakma2815e612006-09-14 02:56:07 +00009353struct peer_pcounts
9354{
9355 unsigned int count[PCOUNT_MAX];
9356 const struct peer *peer;
9357 const struct bgp_table *table;
9358};
9359
Paul Jakmaff7924f2006-09-04 01:10:36 +00009360static int
Paul Jakma2815e612006-09-14 02:56:07 +00009361bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009362{
9363 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009364 struct peer_pcounts *pc = THREAD_ARG (t);
9365 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009366
Paul Jakma2815e612006-09-14 02:56:07 +00009367 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009368 {
9369 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009370 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009371
9372 for (ain = rn->adj_in; ain; ain = ain->next)
9373 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009374 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009375
Paul Jakmaff7924f2006-09-04 01:10:36 +00009376 for (ri = rn->info; ri; ri = ri->next)
9377 {
9378 char buf[SU_ADDRSTRLEN];
9379
9380 if (ri->peer != peer)
9381 continue;
9382
Paul Jakma2815e612006-09-14 02:56:07 +00009383 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009384
9385 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009386 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009387 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009388 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009389 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009390 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009391 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009392 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009393 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009394 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009395 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009396 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009397
9398 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9399 {
Paul Jakma2815e612006-09-14 02:56:07 +00009400 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009401 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009402 plog_warn (peer->log,
9403 "%s [pcount] %s/%d is counted but flags 0x%x",
9404 peer->host,
9405 inet_ntop(rn->p.family, &rn->p.u.prefix,
9406 buf, SU_ADDRSTRLEN),
9407 rn->p.prefixlen,
9408 ri->flags);
9409 }
9410 else
9411 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009412 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009413 plog_warn (peer->log,
9414 "%s [pcount] %s/%d not counted but flags 0x%x",
9415 peer->host,
9416 inet_ntop(rn->p.family, &rn->p.u.prefix,
9417 buf, SU_ADDRSTRLEN),
9418 rn->p.prefixlen,
9419 ri->flags);
9420 }
9421 }
9422 }
Paul Jakma2815e612006-09-14 02:56:07 +00009423 return 0;
9424}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009425
Paul Jakma2815e612006-09-14 02:56:07 +00009426static int
9427bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9428{
9429 struct peer_pcounts pcounts = { .peer = peer };
9430 unsigned int i;
9431
9432 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9433 || !peer->bgp->rib[afi][safi])
9434 {
9435 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9436 return CMD_WARNING;
9437 }
9438
9439 memset (&pcounts, 0, sizeof(pcounts));
9440 pcounts.peer = peer;
9441 pcounts.table = peer->bgp->rib[afi][safi];
9442
9443 /* in-place call via thread subsystem so as to record execution time
9444 * stats for the thread-walk (i.e. ensure this can't be blamed on
9445 * on just vty_read()).
9446 */
9447 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9448
Paul Jakmaff7924f2006-09-04 01:10:36 +00009449 vty_out (vty, "Prefix counts for %s, %s%s",
9450 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9451 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9452 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9453 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9454
9455 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009456 vty_out (vty, "%20s: %-10d%s",
9457 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009458
Paul Jakma2815e612006-09-14 02:56:07 +00009459 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009460 {
9461 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9462 peer->host, VTY_NEWLINE);
9463 vty_out (vty, "Please report this bug, with the above command output%s",
9464 VTY_NEWLINE);
9465 }
9466
9467 return CMD_SUCCESS;
9468}
9469
9470DEFUN (show_ip_bgp_neighbor_prefix_counts,
9471 show_ip_bgp_neighbor_prefix_counts_cmd,
9472 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9473 SHOW_STR
9474 IP_STR
9475 BGP_STR
9476 "Detailed information on TCP and BGP neighbor connections\n"
9477 "Neighbor to display information about\n"
9478 "Neighbor to display information about\n"
9479 "Display detailed prefix count information\n")
9480{
9481 struct peer *peer;
9482
9483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9484 if (! peer)
9485 return CMD_WARNING;
9486
9487 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9488}
9489
9490DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9491 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9492 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9493 SHOW_STR
9494 BGP_STR
9495 "Address family\n"
9496 "Detailed information on TCP and BGP neighbor connections\n"
9497 "Neighbor to display information about\n"
9498 "Neighbor to display information about\n"
9499 "Display detailed prefix count information\n")
9500{
9501 struct peer *peer;
9502
9503 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9504 if (! peer)
9505 return CMD_WARNING;
9506
9507 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9508}
9509
9510DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9511 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9512 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9513 SHOW_STR
9514 IP_STR
9515 BGP_STR
9516 "Address family\n"
9517 "Address Family modifier\n"
9518 "Address Family modifier\n"
9519 "Detailed information on TCP and BGP neighbor connections\n"
9520 "Neighbor to display information about\n"
9521 "Neighbor to display information about\n"
9522 "Display detailed prefix count information\n")
9523{
9524 struct peer *peer;
9525
9526 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9527 if (! peer)
9528 return CMD_WARNING;
9529
9530 if (strncmp (argv[0], "m", 1) == 0)
9531 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9532
9533 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9534}
9535
9536DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9537 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9538 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9539 SHOW_STR
9540 IP_STR
9541 BGP_STR
9542 "Address family\n"
9543 "Address Family modifier\n"
9544 "Address Family modifier\n"
9545 "Detailed information on TCP and BGP neighbor connections\n"
9546 "Neighbor to display information about\n"
9547 "Neighbor to display information about\n"
9548 "Display detailed prefix count information\n")
9549{
9550 struct peer *peer;
9551
9552 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9553 if (! peer)
9554 return CMD_WARNING;
9555
9556 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9557}
9558
9559
paul94f2b392005-06-28 12:44:16 +00009560static void
paul718e3742002-12-13 20:15:29 +00009561show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9562 int in)
9563{
9564 struct bgp_table *table;
9565 struct bgp_adj_in *ain;
9566 struct bgp_adj_out *adj;
9567 unsigned long output_count;
9568 struct bgp_node *rn;
9569 int header1 = 1;
9570 struct bgp *bgp;
9571 int header2 = 1;
9572
paulbb46e942003-10-24 19:02:03 +00009573 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009574
9575 if (! bgp)
9576 return;
9577
9578 table = bgp->rib[afi][safi];
9579
9580 output_count = 0;
9581
9582 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9583 PEER_STATUS_DEFAULT_ORIGINATE))
9584 {
9585 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 +00009586 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9587 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009588
9589 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9590 VTY_NEWLINE, VTY_NEWLINE);
9591 header1 = 0;
9592 }
9593
9594 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9595 if (in)
9596 {
9597 for (ain = rn->adj_in; ain; ain = ain->next)
9598 if (ain->peer == peer)
9599 {
9600 if (header1)
9601 {
9602 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 +00009603 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9604 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009605 header1 = 0;
9606 }
9607 if (header2)
9608 {
9609 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9610 header2 = 0;
9611 }
9612 if (ain->attr)
9613 {
9614 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9615 output_count++;
9616 }
9617 }
9618 }
9619 else
9620 {
9621 for (adj = rn->adj_out; adj; adj = adj->next)
9622 if (adj->peer == peer)
9623 {
9624 if (header1)
9625 {
9626 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 +00009627 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9628 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009629 header1 = 0;
9630 }
9631 if (header2)
9632 {
9633 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9634 header2 = 0;
9635 }
9636 if (adj->attr)
9637 {
9638 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9639 output_count++;
9640 }
9641 }
9642 }
9643
9644 if (output_count != 0)
9645 vty_out (vty, "%sTotal number of prefixes %ld%s",
9646 VTY_NEWLINE, output_count, VTY_NEWLINE);
9647}
9648
paul94f2b392005-06-28 12:44:16 +00009649static int
paulbb46e942003-10-24 19:02:03 +00009650peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9651{
paul718e3742002-12-13 20:15:29 +00009652 if (! peer || ! peer->afc[afi][safi])
9653 {
9654 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657
9658 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9659 {
9660 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9661 VTY_NEWLINE);
9662 return CMD_WARNING;
9663 }
9664
9665 show_adj_route (vty, peer, afi, safi, in);
9666
9667 return CMD_SUCCESS;
9668}
9669
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009670DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9671 show_ip_bgp_view_neighbor_advertised_route_cmd,
9672 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 "BGP view\n"
9677 "View name\n"
9678 "Detailed information on TCP and BGP neighbor connections\n"
9679 "Neighbor to display information about\n"
9680 "Neighbor to display information about\n"
9681 "Display the routes advertised to a BGP neighbor\n")
9682{
9683 struct peer *peer;
9684
9685 if (argc == 2)
9686 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9687 else
9688 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9689
9690 if (! peer)
9691 return CMD_WARNING;
9692
9693 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9694}
9695
9696ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009697 show_ip_bgp_neighbor_advertised_route_cmd,
9698 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9699 SHOW_STR
9700 IP_STR
9701 BGP_STR
9702 "Detailed information on TCP and BGP neighbor connections\n"
9703 "Neighbor to display information about\n"
9704 "Neighbor to display information about\n"
9705 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009706
9707DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9708 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9709 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "Address family\n"
9714 "Address Family modifier\n"
9715 "Address Family modifier\n"
9716 "Detailed information on TCP and BGP neighbor connections\n"
9717 "Neighbor to display information about\n"
9718 "Neighbor to display information about\n"
9719 "Display the routes advertised to a BGP neighbor\n")
9720{
paulbb46e942003-10-24 19:02:03 +00009721 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009722
paulbb46e942003-10-24 19:02:03 +00009723 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9724 if (! peer)
9725 return CMD_WARNING;
9726
9727 if (strncmp (argv[0], "m", 1) == 0)
9728 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9729
9730 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009731}
9732
9733#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009734DEFUN (show_bgp_view_neighbor_advertised_route,
9735 show_bgp_view_neighbor_advertised_route_cmd,
9736 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9737 SHOW_STR
9738 BGP_STR
9739 "BGP view\n"
9740 "View name\n"
9741 "Detailed information on TCP and BGP neighbor connections\n"
9742 "Neighbor to display information about\n"
9743 "Neighbor to display information about\n"
9744 "Display the routes advertised to a BGP neighbor\n")
9745{
9746 struct peer *peer;
9747
9748 if (argc == 2)
9749 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9750 else
9751 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9752
9753 if (! peer)
9754 return CMD_WARNING;
9755
9756 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9757}
9758
9759ALIAS (show_bgp_view_neighbor_advertised_route,
9760 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9761 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9762 SHOW_STR
9763 BGP_STR
9764 "BGP view\n"
9765 "View name\n"
9766 "Address family\n"
9767 "Detailed information on TCP and BGP neighbor connections\n"
9768 "Neighbor to display information about\n"
9769 "Neighbor to display information about\n"
9770 "Display the routes advertised to a BGP neighbor\n")
9771
9772DEFUN (show_bgp_view_neighbor_received_routes,
9773 show_bgp_view_neighbor_received_routes_cmd,
9774 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9775 SHOW_STR
9776 BGP_STR
9777 "BGP view\n"
9778 "View name\n"
9779 "Detailed information on TCP and BGP neighbor connections\n"
9780 "Neighbor to display information about\n"
9781 "Neighbor to display information about\n"
9782 "Display the received routes from neighbor\n")
9783{
9784 struct peer *peer;
9785
9786 if (argc == 2)
9787 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9788 else
9789 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9790
9791 if (! peer)
9792 return CMD_WARNING;
9793
9794 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9795}
9796
9797ALIAS (show_bgp_view_neighbor_received_routes,
9798 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9799 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9800 SHOW_STR
9801 BGP_STR
9802 "BGP view\n"
9803 "View name\n"
9804 "Address family\n"
9805 "Detailed information on TCP and BGP neighbor connections\n"
9806 "Neighbor to display information about\n"
9807 "Neighbor to display information about\n"
9808 "Display the received routes from neighbor\n")
9809
9810ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009811 show_bgp_neighbor_advertised_route_cmd,
9812 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9813 SHOW_STR
9814 BGP_STR
9815 "Detailed information on TCP and BGP neighbor connections\n"
9816 "Neighbor to display information about\n"
9817 "Neighbor to display information about\n"
9818 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009819
9820ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009821 show_bgp_ipv6_neighbor_advertised_route_cmd,
9822 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9823 SHOW_STR
9824 BGP_STR
9825 "Address family\n"
9826 "Detailed information on TCP and BGP neighbor connections\n"
9827 "Neighbor to display information about\n"
9828 "Neighbor to display information about\n"
9829 "Display the routes advertised to a BGP neighbor\n")
9830
9831/* old command */
paulbb46e942003-10-24 19:02:03 +00009832ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009833 ipv6_bgp_neighbor_advertised_route_cmd,
9834 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9835 SHOW_STR
9836 IPV6_STR
9837 BGP_STR
9838 "Detailed information on TCP and BGP neighbor connections\n"
9839 "Neighbor to display information about\n"
9840 "Neighbor to display information about\n"
9841 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009842
paul718e3742002-12-13 20:15:29 +00009843/* old command */
9844DEFUN (ipv6_mbgp_neighbor_advertised_route,
9845 ipv6_mbgp_neighbor_advertised_route_cmd,
9846 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9847 SHOW_STR
9848 IPV6_STR
9849 MBGP_STR
9850 "Detailed information on TCP and BGP neighbor connections\n"
9851 "Neighbor to display information about\n"
9852 "Neighbor to display information about\n"
9853 "Display the routes advertised to a BGP neighbor\n")
9854{
paulbb46e942003-10-24 19:02:03 +00009855 struct peer *peer;
9856
9857 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9858 if (! peer)
9859 return CMD_WARNING;
9860
9861 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009862}
9863#endif /* HAVE_IPV6 */
9864
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009865DEFUN (show_ip_bgp_view_neighbor_received_routes,
9866 show_ip_bgp_view_neighbor_received_routes_cmd,
9867 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9868 SHOW_STR
9869 IP_STR
9870 BGP_STR
9871 "BGP view\n"
9872 "View name\n"
9873 "Detailed information on TCP and BGP neighbor connections\n"
9874 "Neighbor to display information about\n"
9875 "Neighbor to display information about\n"
9876 "Display the received routes from neighbor\n")
9877{
9878 struct peer *peer;
9879
9880 if (argc == 2)
9881 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9882 else
9883 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9884
9885 if (! peer)
9886 return CMD_WARNING;
9887
9888 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9889}
9890
9891ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009892 show_ip_bgp_neighbor_received_routes_cmd,
9893 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9894 SHOW_STR
9895 IP_STR
9896 BGP_STR
9897 "Detailed information on TCP and BGP neighbor connections\n"
9898 "Neighbor to display information about\n"
9899 "Neighbor to display information about\n"
9900 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009901
9902DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9903 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9904 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9905 SHOW_STR
9906 IP_STR
9907 BGP_STR
9908 "Address family\n"
9909 "Address Family modifier\n"
9910 "Address Family modifier\n"
9911 "Detailed information on TCP and BGP neighbor connections\n"
9912 "Neighbor to display information about\n"
9913 "Neighbor to display information about\n"
9914 "Display the received routes from neighbor\n")
9915{
paulbb46e942003-10-24 19:02:03 +00009916 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009917
paulbb46e942003-10-24 19:02:03 +00009918 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9919 if (! peer)
9920 return CMD_WARNING;
9921
9922 if (strncmp (argv[0], "m", 1) == 0)
9923 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9924
9925 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009926}
9927
9928DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9929 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9930 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9931 SHOW_STR
9932 IP_STR
9933 BGP_STR
9934 "Detailed information on TCP and BGP neighbor connections\n"
9935 "Neighbor to display information about\n"
9936 "Neighbor to display information about\n"
9937 "Display information received from a BGP neighbor\n"
9938 "Display the prefixlist filter\n")
9939{
9940 char name[BUFSIZ];
9941 union sockunion *su;
9942 struct peer *peer;
9943 int count;
9944
9945 su = sockunion_str2su (argv[0]);
9946 if (su == NULL)
9947 return CMD_WARNING;
9948
9949 peer = peer_lookup (NULL, su);
9950 if (! peer)
9951 return CMD_WARNING;
9952
9953 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9954 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9955 if (count)
9956 {
9957 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9958 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9959 }
9960
9961 return CMD_SUCCESS;
9962}
9963
9964DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9965 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9966 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9967 SHOW_STR
9968 IP_STR
9969 BGP_STR
9970 "Address family\n"
9971 "Address Family modifier\n"
9972 "Address Family modifier\n"
9973 "Detailed information on TCP and BGP neighbor connections\n"
9974 "Neighbor to display information about\n"
9975 "Neighbor to display information about\n"
9976 "Display information received from a BGP neighbor\n"
9977 "Display the prefixlist filter\n")
9978{
9979 char name[BUFSIZ];
9980 union sockunion *su;
9981 struct peer *peer;
9982 int count;
9983
9984 su = sockunion_str2su (argv[1]);
9985 if (su == NULL)
9986 return CMD_WARNING;
9987
9988 peer = peer_lookup (NULL, su);
9989 if (! peer)
9990 return CMD_WARNING;
9991
9992 if (strncmp (argv[0], "m", 1) == 0)
9993 {
9994 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9995 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9996 if (count)
9997 {
9998 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9999 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10000 }
10001 }
10002 else
10003 {
10004 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10005 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10006 if (count)
10007 {
10008 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10009 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10010 }
10011 }
10012
10013 return CMD_SUCCESS;
10014}
10015
10016
10017#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010018ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010019 show_bgp_neighbor_received_routes_cmd,
10020 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10021 SHOW_STR
10022 BGP_STR
10023 "Detailed information on TCP and BGP neighbor connections\n"
10024 "Neighbor to display information about\n"
10025 "Neighbor to display information about\n"
10026 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010027
paulbb46e942003-10-24 19:02:03 +000010028ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010029 show_bgp_ipv6_neighbor_received_routes_cmd,
10030 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10031 SHOW_STR
10032 BGP_STR
10033 "Address family\n"
10034 "Detailed information on TCP and BGP neighbor connections\n"
10035 "Neighbor to display information about\n"
10036 "Neighbor to display information about\n"
10037 "Display the received routes from neighbor\n")
10038
10039DEFUN (show_bgp_neighbor_received_prefix_filter,
10040 show_bgp_neighbor_received_prefix_filter_cmd,
10041 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10042 SHOW_STR
10043 BGP_STR
10044 "Detailed information on TCP and BGP neighbor connections\n"
10045 "Neighbor to display information about\n"
10046 "Neighbor to display information about\n"
10047 "Display information received from a BGP neighbor\n"
10048 "Display the prefixlist filter\n")
10049{
10050 char name[BUFSIZ];
10051 union sockunion *su;
10052 struct peer *peer;
10053 int count;
10054
10055 su = sockunion_str2su (argv[0]);
10056 if (su == NULL)
10057 return CMD_WARNING;
10058
10059 peer = peer_lookup (NULL, su);
10060 if (! peer)
10061 return CMD_WARNING;
10062
10063 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10064 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10065 if (count)
10066 {
10067 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10068 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10069 }
10070
10071 return CMD_SUCCESS;
10072}
10073
10074ALIAS (show_bgp_neighbor_received_prefix_filter,
10075 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10076 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10077 SHOW_STR
10078 BGP_STR
10079 "Address family\n"
10080 "Detailed information on TCP and BGP neighbor connections\n"
10081 "Neighbor to display information about\n"
10082 "Neighbor to display information about\n"
10083 "Display information received from a BGP neighbor\n"
10084 "Display the prefixlist filter\n")
10085
10086/* old command */
paulbb46e942003-10-24 19:02:03 +000010087ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010088 ipv6_bgp_neighbor_received_routes_cmd,
10089 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10090 SHOW_STR
10091 IPV6_STR
10092 BGP_STR
10093 "Detailed information on TCP and BGP neighbor connections\n"
10094 "Neighbor to display information about\n"
10095 "Neighbor to display information about\n"
10096 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010097
10098/* old command */
10099DEFUN (ipv6_mbgp_neighbor_received_routes,
10100 ipv6_mbgp_neighbor_received_routes_cmd,
10101 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10102 SHOW_STR
10103 IPV6_STR
10104 MBGP_STR
10105 "Detailed information on TCP and BGP neighbor connections\n"
10106 "Neighbor to display information about\n"
10107 "Neighbor to display information about\n"
10108 "Display the received routes from neighbor\n")
10109{
paulbb46e942003-10-24 19:02:03 +000010110 struct peer *peer;
10111
10112 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10113 if (! peer)
10114 return CMD_WARNING;
10115
10116 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010117}
paulbb46e942003-10-24 19:02:03 +000010118
10119DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10120 show_bgp_view_neighbor_received_prefix_filter_cmd,
10121 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10122 SHOW_STR
10123 BGP_STR
10124 "BGP view\n"
10125 "View name\n"
10126 "Detailed information on TCP and BGP neighbor connections\n"
10127 "Neighbor to display information about\n"
10128 "Neighbor to display information about\n"
10129 "Display information received from a BGP neighbor\n"
10130 "Display the prefixlist filter\n")
10131{
10132 char name[BUFSIZ];
10133 union sockunion *su;
10134 struct peer *peer;
10135 struct bgp *bgp;
10136 int count;
10137
10138 /* BGP structure lookup. */
10139 bgp = bgp_lookup_by_name (argv[0]);
10140 if (bgp == NULL)
10141 {
10142 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10143 return CMD_WARNING;
10144 }
10145
10146 su = sockunion_str2su (argv[1]);
10147 if (su == NULL)
10148 return CMD_WARNING;
10149
10150 peer = peer_lookup (bgp, su);
10151 if (! peer)
10152 return CMD_WARNING;
10153
10154 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10155 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10156 if (count)
10157 {
10158 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10159 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10160 }
10161
10162 return CMD_SUCCESS;
10163}
10164
10165ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10166 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10167 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10168 SHOW_STR
10169 BGP_STR
10170 "BGP view\n"
10171 "View name\n"
10172 "Address family\n"
10173 "Detailed information on TCP and BGP neighbor connections\n"
10174 "Neighbor to display information about\n"
10175 "Neighbor to display information about\n"
10176 "Display information received from a BGP neighbor\n"
10177 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010178#endif /* HAVE_IPV6 */
10179
paul94f2b392005-06-28 12:44:16 +000010180static int
paulbb46e942003-10-24 19:02:03 +000010181bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010182 safi_t safi, enum bgp_show_type type)
10183{
paul718e3742002-12-13 20:15:29 +000010184 if (! peer || ! peer->afc[afi][safi])
10185 {
10186 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010187 return CMD_WARNING;
10188 }
10189
ajs5a646652004-11-05 01:25:55 +000010190 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010191}
10192
10193DEFUN (show_ip_bgp_neighbor_routes,
10194 show_ip_bgp_neighbor_routes_cmd,
10195 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10196 SHOW_STR
10197 IP_STR
10198 BGP_STR
10199 "Detailed information on TCP and BGP neighbor connections\n"
10200 "Neighbor to display information about\n"
10201 "Neighbor to display information about\n"
10202 "Display routes learned from neighbor\n")
10203{
paulbb46e942003-10-24 19:02:03 +000010204 struct peer *peer;
10205
10206 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10207 if (! peer)
10208 return CMD_WARNING;
10209
10210 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010211 bgp_show_type_neighbor);
10212}
10213
10214DEFUN (show_ip_bgp_neighbor_flap,
10215 show_ip_bgp_neighbor_flap_cmd,
10216 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10217 SHOW_STR
10218 IP_STR
10219 BGP_STR
10220 "Detailed information on TCP and BGP neighbor connections\n"
10221 "Neighbor to display information about\n"
10222 "Neighbor to display information about\n"
10223 "Display flap statistics of the routes learned from neighbor\n")
10224{
paulbb46e942003-10-24 19:02:03 +000010225 struct peer *peer;
10226
10227 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10228 if (! peer)
10229 return CMD_WARNING;
10230
10231 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010232 bgp_show_type_flap_neighbor);
10233}
10234
10235DEFUN (show_ip_bgp_neighbor_damp,
10236 show_ip_bgp_neighbor_damp_cmd,
10237 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10238 SHOW_STR
10239 IP_STR
10240 BGP_STR
10241 "Detailed information on TCP and BGP neighbor connections\n"
10242 "Neighbor to display information about\n"
10243 "Neighbor to display information about\n"
10244 "Display the dampened routes received from neighbor\n")
10245{
paulbb46e942003-10-24 19:02:03 +000010246 struct peer *peer;
10247
10248 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10249 if (! peer)
10250 return CMD_WARNING;
10251
10252 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010253 bgp_show_type_damp_neighbor);
10254}
10255
10256DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10257 show_ip_bgp_ipv4_neighbor_routes_cmd,
10258 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10259 SHOW_STR
10260 IP_STR
10261 BGP_STR
10262 "Address family\n"
10263 "Address Family modifier\n"
10264 "Address Family modifier\n"
10265 "Detailed information on TCP and BGP neighbor connections\n"
10266 "Neighbor to display information about\n"
10267 "Neighbor to display information about\n"
10268 "Display routes learned from neighbor\n")
10269{
paulbb46e942003-10-24 19:02:03 +000010270 struct peer *peer;
10271
10272 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10273 if (! peer)
10274 return CMD_WARNING;
10275
paul718e3742002-12-13 20:15:29 +000010276 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010277 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010278 bgp_show_type_neighbor);
10279
paulbb46e942003-10-24 19:02:03 +000010280 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010281 bgp_show_type_neighbor);
10282}
paulbb46e942003-10-24 19:02:03 +000010283
paulfee0f4c2004-09-13 05:12:46 +000010284DEFUN (show_ip_bgp_view_rsclient,
10285 show_ip_bgp_view_rsclient_cmd,
10286 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10287 SHOW_STR
10288 IP_STR
10289 BGP_STR
10290 "BGP view\n"
10291 "BGP view name\n"
10292 "Information about Route Server Client\n"
10293 NEIGHBOR_ADDR_STR)
10294{
10295 struct bgp_table *table;
10296 struct peer *peer;
10297
10298 if (argc == 2)
10299 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10300 else
10301 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10302
10303 if (! peer)
10304 return CMD_WARNING;
10305
10306 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10307 {
10308 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10309 VTY_NEWLINE);
10310 return CMD_WARNING;
10311 }
10312
10313 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10314 PEER_FLAG_RSERVER_CLIENT))
10315 {
10316 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10317 VTY_NEWLINE);
10318 return CMD_WARNING;
10319 }
10320
10321 table = peer->rib[AFI_IP][SAFI_UNICAST];
10322
ajs5a646652004-11-05 01:25:55 +000010323 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010324}
10325
10326ALIAS (show_ip_bgp_view_rsclient,
10327 show_ip_bgp_rsclient_cmd,
10328 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10329 SHOW_STR
10330 IP_STR
10331 BGP_STR
10332 "Information about Route Server Client\n"
10333 NEIGHBOR_ADDR_STR)
10334
10335DEFUN (show_ip_bgp_view_rsclient_route,
10336 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010337 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010338 SHOW_STR
10339 IP_STR
10340 BGP_STR
10341 "BGP view\n"
10342 "BGP view name\n"
10343 "Information about Route Server Client\n"
10344 NEIGHBOR_ADDR_STR
10345 "Network in the BGP routing table to display\n")
10346{
10347 struct bgp *bgp;
10348 struct peer *peer;
10349
10350 /* BGP structure lookup. */
10351 if (argc == 3)
10352 {
10353 bgp = bgp_lookup_by_name (argv[0]);
10354 if (bgp == NULL)
10355 {
10356 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10357 return CMD_WARNING;
10358 }
10359 }
10360 else
10361 {
10362 bgp = bgp_get_default ();
10363 if (bgp == NULL)
10364 {
10365 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10366 return CMD_WARNING;
10367 }
10368 }
10369
10370 if (argc == 3)
10371 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10372 else
10373 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10374
10375 if (! peer)
10376 return CMD_WARNING;
10377
10378 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10379 {
10380 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10381 VTY_NEWLINE);
10382 return CMD_WARNING;
10383}
10384
10385 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10386 PEER_FLAG_RSERVER_CLIENT))
10387 {
10388 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10389 VTY_NEWLINE);
10390 return CMD_WARNING;
10391 }
10392
10393 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10394 (argc == 3) ? argv[2] : argv[1],
10395 AFI_IP, SAFI_UNICAST, NULL, 0);
10396}
10397
10398ALIAS (show_ip_bgp_view_rsclient_route,
10399 show_ip_bgp_rsclient_route_cmd,
10400 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10401 SHOW_STR
10402 IP_STR
10403 BGP_STR
10404 "Information about Route Server Client\n"
10405 NEIGHBOR_ADDR_STR
10406 "Network in the BGP routing table to display\n")
10407
10408DEFUN (show_ip_bgp_view_rsclient_prefix,
10409 show_ip_bgp_view_rsclient_prefix_cmd,
10410 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10411 SHOW_STR
10412 IP_STR
10413 BGP_STR
10414 "BGP view\n"
10415 "BGP view name\n"
10416 "Information about Route Server Client\n"
10417 NEIGHBOR_ADDR_STR
10418 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10419{
10420 struct bgp *bgp;
10421 struct peer *peer;
10422
10423 /* BGP structure lookup. */
10424 if (argc == 3)
10425 {
10426 bgp = bgp_lookup_by_name (argv[0]);
10427 if (bgp == NULL)
10428 {
10429 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10430 return CMD_WARNING;
10431 }
10432 }
10433 else
10434 {
10435 bgp = bgp_get_default ();
10436 if (bgp == NULL)
10437 {
10438 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10439 return CMD_WARNING;
10440 }
10441 }
10442
10443 if (argc == 3)
10444 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10445 else
10446 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10447
10448 if (! peer)
10449 return CMD_WARNING;
10450
10451 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10452 {
10453 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10454 VTY_NEWLINE);
10455 return CMD_WARNING;
10456}
10457
10458 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10459 PEER_FLAG_RSERVER_CLIENT))
10460{
10461 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10462 VTY_NEWLINE);
10463 return CMD_WARNING;
10464 }
10465
10466 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10467 (argc == 3) ? argv[2] : argv[1],
10468 AFI_IP, SAFI_UNICAST, NULL, 1);
10469}
10470
10471ALIAS (show_ip_bgp_view_rsclient_prefix,
10472 show_ip_bgp_rsclient_prefix_cmd,
10473 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10474 SHOW_STR
10475 IP_STR
10476 BGP_STR
10477 "Information about Route Server Client\n"
10478 NEIGHBOR_ADDR_STR
10479 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10480
10481
paul718e3742002-12-13 20:15:29 +000010482#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010483DEFUN (show_bgp_view_neighbor_routes,
10484 show_bgp_view_neighbor_routes_cmd,
10485 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10486 SHOW_STR
10487 BGP_STR
10488 "BGP view\n"
10489 "BGP view name\n"
10490 "Detailed information on TCP and BGP neighbor connections\n"
10491 "Neighbor to display information about\n"
10492 "Neighbor to display information about\n"
10493 "Display routes learned from neighbor\n")
10494{
10495 struct peer *peer;
10496
10497 if (argc == 2)
10498 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10499 else
10500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10501
10502 if (! peer)
10503 return CMD_WARNING;
10504
10505 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10506 bgp_show_type_neighbor);
10507}
10508
10509ALIAS (show_bgp_view_neighbor_routes,
10510 show_bgp_view_ipv6_neighbor_routes_cmd,
10511 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10512 SHOW_STR
10513 BGP_STR
10514 "BGP view\n"
10515 "BGP view name\n"
10516 "Address family\n"
10517 "Detailed information on TCP and BGP neighbor connections\n"
10518 "Neighbor to display information about\n"
10519 "Neighbor to display information about\n"
10520 "Display routes learned from neighbor\n")
10521
10522DEFUN (show_bgp_view_neighbor_damp,
10523 show_bgp_view_neighbor_damp_cmd,
10524 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10525 SHOW_STR
10526 BGP_STR
10527 "BGP view\n"
10528 "BGP view name\n"
10529 "Detailed information on TCP and BGP neighbor connections\n"
10530 "Neighbor to display information about\n"
10531 "Neighbor to display information about\n"
10532 "Display the dampened routes received from neighbor\n")
10533{
10534 struct peer *peer;
10535
10536 if (argc == 2)
10537 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10538 else
10539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10540
10541 if (! peer)
10542 return CMD_WARNING;
10543
10544 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10545 bgp_show_type_damp_neighbor);
10546}
10547
10548ALIAS (show_bgp_view_neighbor_damp,
10549 show_bgp_view_ipv6_neighbor_damp_cmd,
10550 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10551 SHOW_STR
10552 BGP_STR
10553 "BGP view\n"
10554 "BGP view name\n"
10555 "Address family\n"
10556 "Detailed information on TCP and BGP neighbor connections\n"
10557 "Neighbor to display information about\n"
10558 "Neighbor to display information about\n"
10559 "Display the dampened routes received from neighbor\n")
10560
10561DEFUN (show_bgp_view_neighbor_flap,
10562 show_bgp_view_neighbor_flap_cmd,
10563 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10564 SHOW_STR
10565 BGP_STR
10566 "BGP view\n"
10567 "BGP view name\n"
10568 "Detailed information on TCP and BGP neighbor connections\n"
10569 "Neighbor to display information about\n"
10570 "Neighbor to display information about\n"
10571 "Display flap statistics of the routes learned from neighbor\n")
10572{
10573 struct peer *peer;
10574
10575 if (argc == 2)
10576 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10577 else
10578 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10579
10580 if (! peer)
10581 return CMD_WARNING;
10582
10583 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10584 bgp_show_type_flap_neighbor);
10585}
10586
10587ALIAS (show_bgp_view_neighbor_flap,
10588 show_bgp_view_ipv6_neighbor_flap_cmd,
10589 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10590 SHOW_STR
10591 BGP_STR
10592 "BGP view\n"
10593 "BGP view name\n"
10594 "Address family\n"
10595 "Detailed information on TCP and BGP neighbor connections\n"
10596 "Neighbor to display information about\n"
10597 "Neighbor to display information about\n"
10598 "Display flap statistics of the routes learned from neighbor\n")
10599
10600ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010601 show_bgp_neighbor_routes_cmd,
10602 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10603 SHOW_STR
10604 BGP_STR
10605 "Detailed information on TCP and BGP neighbor connections\n"
10606 "Neighbor to display information about\n"
10607 "Neighbor to display information about\n"
10608 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010609
paulbb46e942003-10-24 19:02:03 +000010610
10611ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010612 show_bgp_ipv6_neighbor_routes_cmd,
10613 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10614 SHOW_STR
10615 BGP_STR
10616 "Address family\n"
10617 "Detailed information on TCP and BGP neighbor connections\n"
10618 "Neighbor to display information about\n"
10619 "Neighbor to display information about\n"
10620 "Display routes learned from neighbor\n")
10621
10622/* old command */
paulbb46e942003-10-24 19:02:03 +000010623ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010624 ipv6_bgp_neighbor_routes_cmd,
10625 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10626 SHOW_STR
10627 IPV6_STR
10628 BGP_STR
10629 "Detailed information on TCP and BGP neighbor connections\n"
10630 "Neighbor to display information about\n"
10631 "Neighbor to display information about\n"
10632 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010633
10634/* old command */
10635DEFUN (ipv6_mbgp_neighbor_routes,
10636 ipv6_mbgp_neighbor_routes_cmd,
10637 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10638 SHOW_STR
10639 IPV6_STR
10640 MBGP_STR
10641 "Detailed information on TCP and BGP neighbor connections\n"
10642 "Neighbor to display information about\n"
10643 "Neighbor to display information about\n"
10644 "Display routes learned from neighbor\n")
10645{
paulbb46e942003-10-24 19:02:03 +000010646 struct peer *peer;
10647
10648 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10649 if (! peer)
10650 return CMD_WARNING;
10651
10652 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010653 bgp_show_type_neighbor);
10654}
paulbb46e942003-10-24 19:02:03 +000010655
10656ALIAS (show_bgp_view_neighbor_flap,
10657 show_bgp_neighbor_flap_cmd,
10658 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10659 SHOW_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 flap statistics of the routes learned from neighbor\n")
10665
10666ALIAS (show_bgp_view_neighbor_flap,
10667 show_bgp_ipv6_neighbor_flap_cmd,
10668 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10669 SHOW_STR
10670 BGP_STR
10671 "Address family\n"
10672 "Detailed information on TCP and BGP neighbor connections\n"
10673 "Neighbor to display information about\n"
10674 "Neighbor to display information about\n"
10675 "Display flap statistics of the routes learned from neighbor\n")
10676
10677ALIAS (show_bgp_view_neighbor_damp,
10678 show_bgp_neighbor_damp_cmd,
10679 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10680 SHOW_STR
10681 BGP_STR
10682 "Detailed information on TCP and BGP neighbor connections\n"
10683 "Neighbor to display information about\n"
10684 "Neighbor to display information about\n"
10685 "Display the dampened routes received from neighbor\n")
10686
10687ALIAS (show_bgp_view_neighbor_damp,
10688 show_bgp_ipv6_neighbor_damp_cmd,
10689 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10690 SHOW_STR
10691 BGP_STR
10692 "Address family\n"
10693 "Detailed information on TCP and BGP neighbor connections\n"
10694 "Neighbor to display information about\n"
10695 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010696 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010697
10698DEFUN (show_bgp_view_rsclient,
10699 show_bgp_view_rsclient_cmd,
10700 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10701 SHOW_STR
10702 BGP_STR
10703 "BGP view\n"
10704 "BGP view name\n"
10705 "Information about Route Server Client\n"
10706 NEIGHBOR_ADDR_STR)
10707{
10708 struct bgp_table *table;
10709 struct peer *peer;
10710
10711 if (argc == 2)
10712 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10713 else
10714 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10715
10716 if (! peer)
10717 return CMD_WARNING;
10718
10719 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10720 {
10721 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10722 VTY_NEWLINE);
10723 return CMD_WARNING;
10724 }
10725
10726 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10727 PEER_FLAG_RSERVER_CLIENT))
10728 {
10729 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10730 VTY_NEWLINE);
10731 return CMD_WARNING;
10732 }
10733
10734 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10735
ajs5a646652004-11-05 01:25:55 +000010736 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010737}
10738
10739ALIAS (show_bgp_view_rsclient,
10740 show_bgp_rsclient_cmd,
10741 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10742 SHOW_STR
10743 BGP_STR
10744 "Information about Route Server Client\n"
10745 NEIGHBOR_ADDR_STR)
10746
10747DEFUN (show_bgp_view_rsclient_route,
10748 show_bgp_view_rsclient_route_cmd,
10749 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10750 SHOW_STR
10751 BGP_STR
10752 "BGP view\n"
10753 "BGP view name\n"
10754 "Information about Route Server Client\n"
10755 NEIGHBOR_ADDR_STR
10756 "Network in the BGP routing table to display\n")
10757{
10758 struct bgp *bgp;
10759 struct peer *peer;
10760
10761 /* BGP structure lookup. */
10762 if (argc == 3)
10763 {
10764 bgp = bgp_lookup_by_name (argv[0]);
10765 if (bgp == NULL)
10766 {
10767 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10768 return CMD_WARNING;
10769 }
10770 }
10771 else
10772 {
10773 bgp = bgp_get_default ();
10774 if (bgp == NULL)
10775 {
10776 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10777 return CMD_WARNING;
10778 }
10779 }
10780
10781 if (argc == 3)
10782 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10783 else
10784 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10785
10786 if (! peer)
10787 return CMD_WARNING;
10788
10789 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10790 {
10791 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10792 VTY_NEWLINE);
10793 return CMD_WARNING;
10794 }
10795
10796 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10797 PEER_FLAG_RSERVER_CLIENT))
10798 {
10799 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10800 VTY_NEWLINE);
10801 return CMD_WARNING;
10802 }
10803
10804 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10805 (argc == 3) ? argv[2] : argv[1],
10806 AFI_IP6, SAFI_UNICAST, NULL, 0);
10807}
10808
10809ALIAS (show_bgp_view_rsclient_route,
10810 show_bgp_rsclient_route_cmd,
10811 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10812 SHOW_STR
10813 BGP_STR
10814 "Information about Route Server Client\n"
10815 NEIGHBOR_ADDR_STR
10816 "Network in the BGP routing table to display\n")
10817
10818DEFUN (show_bgp_view_rsclient_prefix,
10819 show_bgp_view_rsclient_prefix_cmd,
10820 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10821 SHOW_STR
10822 BGP_STR
10823 "BGP view\n"
10824 "BGP view name\n"
10825 "Information about Route Server Client\n"
10826 NEIGHBOR_ADDR_STR
10827 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10828{
10829 struct bgp *bgp;
10830 struct peer *peer;
10831
10832 /* BGP structure lookup. */
10833 if (argc == 3)
10834 {
10835 bgp = bgp_lookup_by_name (argv[0]);
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842 else
10843 {
10844 bgp = bgp_get_default ();
10845 if (bgp == NULL)
10846 {
10847 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10848 return CMD_WARNING;
10849 }
10850 }
10851
10852 if (argc == 3)
10853 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10854 else
10855 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10856
10857 if (! peer)
10858 return CMD_WARNING;
10859
10860 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10861 {
10862 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10863 VTY_NEWLINE);
10864 return CMD_WARNING;
10865 }
10866
10867 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10868 PEER_FLAG_RSERVER_CLIENT))
10869 {
10870 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10871 VTY_NEWLINE);
10872 return CMD_WARNING;
10873 }
10874
10875 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10876 (argc == 3) ? argv[2] : argv[1],
10877 AFI_IP6, SAFI_UNICAST, NULL, 1);
10878}
10879
10880ALIAS (show_bgp_view_rsclient_prefix,
10881 show_bgp_rsclient_prefix_cmd,
10882 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10883 SHOW_STR
10884 BGP_STR
10885 "Information about Route Server Client\n"
10886 NEIGHBOR_ADDR_STR
10887 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10888
paul718e3742002-12-13 20:15:29 +000010889#endif /* HAVE_IPV6 */
10890
10891struct bgp_table *bgp_distance_table;
10892
10893struct bgp_distance
10894{
10895 /* Distance value for the IP source prefix. */
10896 u_char distance;
10897
10898 /* Name of the access-list to be matched. */
10899 char *access_list;
10900};
10901
paul94f2b392005-06-28 12:44:16 +000010902static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010903bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010904{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010905 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010906}
10907
paul94f2b392005-06-28 12:44:16 +000010908static void
paul718e3742002-12-13 20:15:29 +000010909bgp_distance_free (struct bgp_distance *bdistance)
10910{
10911 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10912}
10913
paul94f2b392005-06-28 12:44:16 +000010914static int
paulfd79ac92004-10-13 05:06:08 +000010915bgp_distance_set (struct vty *vty, const char *distance_str,
10916 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010917{
10918 int ret;
10919 struct prefix_ipv4 p;
10920 u_char distance;
10921 struct bgp_node *rn;
10922 struct bgp_distance *bdistance;
10923
10924 ret = str2prefix_ipv4 (ip_str, &p);
10925 if (ret == 0)
10926 {
10927 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10928 return CMD_WARNING;
10929 }
10930
10931 distance = atoi (distance_str);
10932
10933 /* Get BGP distance node. */
10934 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10935 if (rn->info)
10936 {
10937 bdistance = rn->info;
10938 bgp_unlock_node (rn);
10939 }
10940 else
10941 {
10942 bdistance = bgp_distance_new ();
10943 rn->info = bdistance;
10944 }
10945
10946 /* Set distance value. */
10947 bdistance->distance = distance;
10948
10949 /* Reset access-list configuration. */
10950 if (bdistance->access_list)
10951 {
10952 free (bdistance->access_list);
10953 bdistance->access_list = NULL;
10954 }
10955 if (access_list_str)
10956 bdistance->access_list = strdup (access_list_str);
10957
10958 return CMD_SUCCESS;
10959}
10960
paul94f2b392005-06-28 12:44:16 +000010961static int
paulfd79ac92004-10-13 05:06:08 +000010962bgp_distance_unset (struct vty *vty, const char *distance_str,
10963 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010964{
10965 int ret;
10966 struct prefix_ipv4 p;
10967 u_char distance;
10968 struct bgp_node *rn;
10969 struct bgp_distance *bdistance;
10970
10971 ret = str2prefix_ipv4 (ip_str, &p);
10972 if (ret == 0)
10973 {
10974 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10975 return CMD_WARNING;
10976 }
10977
10978 distance = atoi (distance_str);
10979
10980 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10981 if (! rn)
10982 {
10983 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10984 return CMD_WARNING;
10985 }
10986
10987 bdistance = rn->info;
10988
10989 if (bdistance->access_list)
10990 free (bdistance->access_list);
10991 bgp_distance_free (bdistance);
10992
10993 rn->info = NULL;
10994 bgp_unlock_node (rn);
10995 bgp_unlock_node (rn);
10996
10997 return CMD_SUCCESS;
10998}
10999
paul94f2b392005-06-28 12:44:16 +000011000static void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011001bgp_distance_reset (void)
paul718e3742002-12-13 20:15:29 +000011002{
11003 struct bgp_node *rn;
11004 struct bgp_distance *bdistance;
11005
11006 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11007 if ((bdistance = rn->info) != NULL)
11008 {
11009 if (bdistance->access_list)
11010 free (bdistance->access_list);
11011 bgp_distance_free (bdistance);
11012 rn->info = NULL;
11013 bgp_unlock_node (rn);
11014 }
11015}
11016
11017/* Apply BGP information to distance method. */
11018u_char
11019bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11020{
11021 struct bgp_node *rn;
11022 struct prefix_ipv4 q;
11023 struct peer *peer;
11024 struct bgp_distance *bdistance;
11025 struct access_list *alist;
11026 struct bgp_static *bgp_static;
11027
11028 if (! bgp)
11029 return 0;
11030
11031 if (p->family != AF_INET)
11032 return 0;
11033
11034 peer = rinfo->peer;
11035
11036 if (peer->su.sa.sa_family != AF_INET)
11037 return 0;
11038
11039 memset (&q, 0, sizeof (struct prefix_ipv4));
11040 q.family = AF_INET;
11041 q.prefix = peer->su.sin.sin_addr;
11042 q.prefixlen = IPV4_MAX_BITLEN;
11043
11044 /* Check source address. */
11045 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11046 if (rn)
11047 {
11048 bdistance = rn->info;
11049 bgp_unlock_node (rn);
11050
11051 if (bdistance->access_list)
11052 {
11053 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11054 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11055 return bdistance->distance;
11056 }
11057 else
11058 return bdistance->distance;
11059 }
11060
11061 /* Backdoor check. */
11062 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11063 if (rn)
11064 {
11065 bgp_static = rn->info;
11066 bgp_unlock_node (rn);
11067
11068 if (bgp_static->backdoor)
11069 {
11070 if (bgp->distance_local)
11071 return bgp->distance_local;
11072 else
11073 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11074 }
11075 }
11076
11077 if (peer_sort (peer) == BGP_PEER_EBGP)
11078 {
11079 if (bgp->distance_ebgp)
11080 return bgp->distance_ebgp;
11081 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11082 }
11083 else
11084 {
11085 if (bgp->distance_ibgp)
11086 return bgp->distance_ibgp;
11087 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11088 }
11089}
11090
11091DEFUN (bgp_distance,
11092 bgp_distance_cmd,
11093 "distance bgp <1-255> <1-255> <1-255>",
11094 "Define an administrative distance\n"
11095 "BGP distance\n"
11096 "Distance for routes external to the AS\n"
11097 "Distance for routes internal to the AS\n"
11098 "Distance for local routes\n")
11099{
11100 struct bgp *bgp;
11101
11102 bgp = vty->index;
11103
11104 bgp->distance_ebgp = atoi (argv[0]);
11105 bgp->distance_ibgp = atoi (argv[1]);
11106 bgp->distance_local = atoi (argv[2]);
11107 return CMD_SUCCESS;
11108}
11109
11110DEFUN (no_bgp_distance,
11111 no_bgp_distance_cmd,
11112 "no distance bgp <1-255> <1-255> <1-255>",
11113 NO_STR
11114 "Define an administrative distance\n"
11115 "BGP distance\n"
11116 "Distance for routes external to the AS\n"
11117 "Distance for routes internal to the AS\n"
11118 "Distance for local routes\n")
11119{
11120 struct bgp *bgp;
11121
11122 bgp = vty->index;
11123
11124 bgp->distance_ebgp= 0;
11125 bgp->distance_ibgp = 0;
11126 bgp->distance_local = 0;
11127 return CMD_SUCCESS;
11128}
11129
11130ALIAS (no_bgp_distance,
11131 no_bgp_distance2_cmd,
11132 "no distance bgp",
11133 NO_STR
11134 "Define an administrative distance\n"
11135 "BGP distance\n")
11136
11137DEFUN (bgp_distance_source,
11138 bgp_distance_source_cmd,
11139 "distance <1-255> A.B.C.D/M",
11140 "Define an administrative distance\n"
11141 "Administrative distance\n"
11142 "IP source prefix\n")
11143{
11144 bgp_distance_set (vty, argv[0], argv[1], NULL);
11145 return CMD_SUCCESS;
11146}
11147
11148DEFUN (no_bgp_distance_source,
11149 no_bgp_distance_source_cmd,
11150 "no distance <1-255> A.B.C.D/M",
11151 NO_STR
11152 "Define an administrative distance\n"
11153 "Administrative distance\n"
11154 "IP source prefix\n")
11155{
11156 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11157 return CMD_SUCCESS;
11158}
11159
11160DEFUN (bgp_distance_source_access_list,
11161 bgp_distance_source_access_list_cmd,
11162 "distance <1-255> A.B.C.D/M WORD",
11163 "Define an administrative distance\n"
11164 "Administrative distance\n"
11165 "IP source prefix\n"
11166 "Access list name\n")
11167{
11168 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11169 return CMD_SUCCESS;
11170}
11171
11172DEFUN (no_bgp_distance_source_access_list,
11173 no_bgp_distance_source_access_list_cmd,
11174 "no distance <1-255> A.B.C.D/M WORD",
11175 NO_STR
11176 "Define an administrative distance\n"
11177 "Administrative distance\n"
11178 "IP source prefix\n"
11179 "Access list name\n")
11180{
11181 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11182 return CMD_SUCCESS;
11183}
11184
11185DEFUN (bgp_damp_set,
11186 bgp_damp_set_cmd,
11187 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11188 "BGP Specific commands\n"
11189 "Enable route-flap dampening\n"
11190 "Half-life time for the penalty\n"
11191 "Value to start reusing a route\n"
11192 "Value to start suppressing a route\n"
11193 "Maximum duration to suppress a stable route\n")
11194{
11195 struct bgp *bgp;
11196 int half = DEFAULT_HALF_LIFE * 60;
11197 int reuse = DEFAULT_REUSE;
11198 int suppress = DEFAULT_SUPPRESS;
11199 int max = 4 * half;
11200
11201 if (argc == 4)
11202 {
11203 half = atoi (argv[0]) * 60;
11204 reuse = atoi (argv[1]);
11205 suppress = atoi (argv[2]);
11206 max = atoi (argv[3]) * 60;
11207 }
11208 else if (argc == 1)
11209 {
11210 half = atoi (argv[0]) * 60;
11211 max = 4 * half;
11212 }
11213
11214 bgp = vty->index;
11215 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11216 half, reuse, suppress, max);
11217}
11218
11219ALIAS (bgp_damp_set,
11220 bgp_damp_set2_cmd,
11221 "bgp dampening <1-45>",
11222 "BGP Specific commands\n"
11223 "Enable route-flap dampening\n"
11224 "Half-life time for the penalty\n")
11225
11226ALIAS (bgp_damp_set,
11227 bgp_damp_set3_cmd,
11228 "bgp dampening",
11229 "BGP Specific commands\n"
11230 "Enable route-flap dampening\n")
11231
11232DEFUN (bgp_damp_unset,
11233 bgp_damp_unset_cmd,
11234 "no bgp dampening",
11235 NO_STR
11236 "BGP Specific commands\n"
11237 "Enable route-flap dampening\n")
11238{
11239 struct bgp *bgp;
11240
11241 bgp = vty->index;
11242 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11243}
11244
11245ALIAS (bgp_damp_unset,
11246 bgp_damp_unset2_cmd,
11247 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11248 NO_STR
11249 "BGP Specific commands\n"
11250 "Enable route-flap dampening\n"
11251 "Half-life time for the penalty\n"
11252 "Value to start reusing a route\n"
11253 "Value to start suppressing a route\n"
11254 "Maximum duration to suppress a stable route\n")
11255
11256DEFUN (show_ip_bgp_dampened_paths,
11257 show_ip_bgp_dampened_paths_cmd,
11258 "show ip bgp dampened-paths",
11259 SHOW_STR
11260 IP_STR
11261 BGP_STR
11262 "Display paths suppressed due to dampening\n")
11263{
ajs5a646652004-11-05 01:25:55 +000011264 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11265 NULL);
paul718e3742002-12-13 20:15:29 +000011266}
11267
11268DEFUN (show_ip_bgp_flap_statistics,
11269 show_ip_bgp_flap_statistics_cmd,
11270 "show ip bgp flap-statistics",
11271 SHOW_STR
11272 IP_STR
11273 BGP_STR
11274 "Display flap statistics of routes\n")
11275{
ajs5a646652004-11-05 01:25:55 +000011276 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11277 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011278}
11279
11280/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011281static int
paulfd79ac92004-10-13 05:06:08 +000011282bgp_clear_damp_route (struct vty *vty, const char *view_name,
11283 const char *ip_str, afi_t afi, safi_t safi,
11284 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011285{
11286 int ret;
11287 struct prefix match;
11288 struct bgp_node *rn;
11289 struct bgp_node *rm;
11290 struct bgp_info *ri;
11291 struct bgp_info *ri_temp;
11292 struct bgp *bgp;
11293 struct bgp_table *table;
11294
11295 /* BGP structure lookup. */
11296 if (view_name)
11297 {
11298 bgp = bgp_lookup_by_name (view_name);
11299 if (bgp == NULL)
11300 {
11301 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11302 return CMD_WARNING;
11303 }
11304 }
11305 else
11306 {
11307 bgp = bgp_get_default ();
11308 if (bgp == NULL)
11309 {
11310 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11311 return CMD_WARNING;
11312 }
11313 }
11314
11315 /* Check IP address argument. */
11316 ret = str2prefix (ip_str, &match);
11317 if (! ret)
11318 {
11319 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11320 return CMD_WARNING;
11321 }
11322
11323 match.family = afi2family (afi);
11324
11325 if (safi == SAFI_MPLS_VPN)
11326 {
11327 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11328 {
11329 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11330 continue;
11331
11332 if ((table = rn->info) != NULL)
11333 if ((rm = bgp_node_match (table, &match)) != NULL)
11334 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11335 {
11336 ri = rm->info;
11337 while (ri)
11338 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011339 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011340 {
11341 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011342 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011343 ri = ri_temp;
11344 }
11345 else
11346 ri = ri->next;
11347 }
11348 }
11349 }
11350 }
11351 else
11352 {
11353 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11354 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11355 {
11356 ri = rn->info;
11357 while (ri)
11358 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011359 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011360 {
11361 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011362 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011363 ri = ri_temp;
11364 }
11365 else
11366 ri = ri->next;
11367 }
11368 }
11369 }
11370
11371 return CMD_SUCCESS;
11372}
11373
11374DEFUN (clear_ip_bgp_dampening,
11375 clear_ip_bgp_dampening_cmd,
11376 "clear ip bgp dampening",
11377 CLEAR_STR
11378 IP_STR
11379 BGP_STR
11380 "Clear route flap dampening information\n")
11381{
11382 bgp_damp_info_clean ();
11383 return CMD_SUCCESS;
11384}
11385
11386DEFUN (clear_ip_bgp_dampening_prefix,
11387 clear_ip_bgp_dampening_prefix_cmd,
11388 "clear ip bgp dampening A.B.C.D/M",
11389 CLEAR_STR
11390 IP_STR
11391 BGP_STR
11392 "Clear route flap dampening information\n"
11393 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11394{
11395 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11396 SAFI_UNICAST, NULL, 1);
11397}
11398
11399DEFUN (clear_ip_bgp_dampening_address,
11400 clear_ip_bgp_dampening_address_cmd,
11401 "clear ip bgp dampening A.B.C.D",
11402 CLEAR_STR
11403 IP_STR
11404 BGP_STR
11405 "Clear route flap dampening information\n"
11406 "Network to clear damping information\n")
11407{
11408 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11409 SAFI_UNICAST, NULL, 0);
11410}
11411
11412DEFUN (clear_ip_bgp_dampening_address_mask,
11413 clear_ip_bgp_dampening_address_mask_cmd,
11414 "clear ip bgp dampening A.B.C.D A.B.C.D",
11415 CLEAR_STR
11416 IP_STR
11417 BGP_STR
11418 "Clear route flap dampening information\n"
11419 "Network to clear damping information\n"
11420 "Network mask\n")
11421{
11422 int ret;
11423 char prefix_str[BUFSIZ];
11424
11425 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11426 if (! ret)
11427 {
11428 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11429 return CMD_WARNING;
11430 }
11431
11432 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11433 SAFI_UNICAST, NULL, 0);
11434}
11435
paul94f2b392005-06-28 12:44:16 +000011436static int
paul718e3742002-12-13 20:15:29 +000011437bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11438 afi_t afi, safi_t safi, int *write)
11439{
11440 struct bgp_node *prn;
11441 struct bgp_node *rn;
11442 struct bgp_table *table;
11443 struct prefix *p;
11444 struct prefix_rd *prd;
11445 struct bgp_static *bgp_static;
11446 u_int32_t label;
11447 char buf[SU_ADDRSTRLEN];
11448 char rdbuf[RD_ADDRSTRLEN];
11449
11450 /* Network configuration. */
11451 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11452 if ((table = prn->info) != NULL)
11453 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11454 if ((bgp_static = rn->info) != NULL)
11455 {
11456 p = &rn->p;
11457 prd = (struct prefix_rd *) &prn->p;
11458
11459 /* "address-family" display. */
11460 bgp_config_write_family_header (vty, afi, safi, write);
11461
11462 /* "network" configuration display. */
11463 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11464 label = decode_label (bgp_static->tag);
11465
11466 vty_out (vty, " network %s/%d rd %s tag %d",
11467 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11468 p->prefixlen,
11469 rdbuf, label);
11470 vty_out (vty, "%s", VTY_NEWLINE);
11471 }
11472 return 0;
11473}
11474
11475/* Configuration of static route announcement and aggregate
11476 information. */
11477int
11478bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11479 afi_t afi, safi_t safi, int *write)
11480{
11481 struct bgp_node *rn;
11482 struct prefix *p;
11483 struct bgp_static *bgp_static;
11484 struct bgp_aggregate *bgp_aggregate;
11485 char buf[SU_ADDRSTRLEN];
11486
11487 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11488 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11489
11490 /* Network configuration. */
11491 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11492 if ((bgp_static = rn->info) != NULL)
11493 {
11494 p = &rn->p;
11495
11496 /* "address-family" display. */
11497 bgp_config_write_family_header (vty, afi, safi, write);
11498
11499 /* "network" configuration display. */
11500 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11501 {
11502 u_int32_t destination;
11503 struct in_addr netmask;
11504
11505 destination = ntohl (p->u.prefix4.s_addr);
11506 masklen2ip (p->prefixlen, &netmask);
11507 vty_out (vty, " network %s",
11508 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11509
11510 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11511 || (IN_CLASSB (destination) && p->prefixlen == 16)
11512 || (IN_CLASSA (destination) && p->prefixlen == 8)
11513 || p->u.prefix4.s_addr == 0)
11514 {
11515 /* Natural mask is not display. */
11516 }
11517 else
11518 vty_out (vty, " mask %s", inet_ntoa (netmask));
11519 }
11520 else
11521 {
11522 vty_out (vty, " network %s/%d",
11523 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11524 p->prefixlen);
11525 }
11526
11527 if (bgp_static->rmap.name)
11528 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011529 else
11530 {
11531 if (bgp_static->backdoor)
11532 vty_out (vty, " backdoor");
11533 if (bgp_static->ttl)
11534 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11535 }
paul718e3742002-12-13 20:15:29 +000011536
11537 vty_out (vty, "%s", VTY_NEWLINE);
11538 }
11539
11540 /* Aggregate-address configuration. */
11541 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11542 if ((bgp_aggregate = rn->info) != NULL)
11543 {
11544 p = &rn->p;
11545
11546 /* "address-family" display. */
11547 bgp_config_write_family_header (vty, afi, safi, write);
11548
11549 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11550 {
11551 struct in_addr netmask;
11552
11553 masklen2ip (p->prefixlen, &netmask);
11554 vty_out (vty, " aggregate-address %s %s",
11555 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11556 inet_ntoa (netmask));
11557 }
11558 else
11559 {
11560 vty_out (vty, " aggregate-address %s/%d",
11561 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11562 p->prefixlen);
11563 }
11564
11565 if (bgp_aggregate->as_set)
11566 vty_out (vty, " as-set");
11567
11568 if (bgp_aggregate->summary_only)
11569 vty_out (vty, " summary-only");
11570
11571 vty_out (vty, "%s", VTY_NEWLINE);
11572 }
11573
11574 return 0;
11575}
11576
11577int
11578bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11579{
11580 struct bgp_node *rn;
11581 struct bgp_distance *bdistance;
11582
11583 /* Distance configuration. */
11584 if (bgp->distance_ebgp
11585 && bgp->distance_ibgp
11586 && bgp->distance_local
11587 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11588 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11589 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11590 vty_out (vty, " distance bgp %d %d %d%s",
11591 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11592 VTY_NEWLINE);
11593
11594 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11595 if ((bdistance = rn->info) != NULL)
11596 {
11597 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11598 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11599 bdistance->access_list ? bdistance->access_list : "",
11600 VTY_NEWLINE);
11601 }
11602
11603 return 0;
11604}
11605
11606/* Allocate routing table structure and install commands. */
11607void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011608bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011609{
11610 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011611 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011612
11613 /* IPv4 BGP commands. */
11614 install_element (BGP_NODE, &bgp_network_cmd);
11615 install_element (BGP_NODE, &bgp_network_mask_cmd);
11616 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11617 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11618 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11619 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11620 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11621 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11622 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011623 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11624 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11625 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11626 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11627 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11628 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011629 install_element (BGP_NODE, &no_bgp_network_cmd);
11630 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11631 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11632 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11633 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11634 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11635 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11636 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11637 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011638 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11639 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11640 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11641 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11642 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11643 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011644
11645 install_element (BGP_NODE, &aggregate_address_cmd);
11646 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11647 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11648 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11649 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11650 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11651 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11652 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11653 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11654 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11655 install_element (BGP_NODE, &no_aggregate_address_cmd);
11656 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11657 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11658 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11659 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11660 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11661 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11662 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11663 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11664 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11665
11666 /* IPv4 unicast configuration. */
11667 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11668 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11669 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11670 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11671 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11672 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011673 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11674 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11675 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11676 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11677 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11678 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 +000011679 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11680 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11681 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11682 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11683 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011684 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11685 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11686 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11687 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11688 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11689 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 +000011690 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11691 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11692 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11693 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11694 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11695 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11696 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11697 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11698 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11699 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11700 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11701 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11702 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11703 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11704 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11705 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11706 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11707 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11708 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11709 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11710
11711 /* IPv4 multicast configuration. */
11712 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11713 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11714 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11715 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11716 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11717 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011718 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11719 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11720 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11721 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11722 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11723 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 +000011724 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11725 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11726 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11727 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11728 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11729 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011730 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11731 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11732 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11733 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11734 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11735 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 +000011736 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11737 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11738 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11739 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11740 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11741 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11742 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11743 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11744 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11745 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11746 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11747 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11748 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11749 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11750 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11751 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11752 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11753 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11754 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11755 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11756
11757 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11770 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11776 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11778 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11779 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11780 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11781 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11782 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11783 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11784 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11785 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11786 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11787 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11788 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11789 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11790 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11791 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11792 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11793 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11794 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11795 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11796 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11797 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11798 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11799 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11800 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11801 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11802 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11803 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11804 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11805 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11806 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11808 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11809 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11810 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11811 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11812 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11813 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11814 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11815 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11816 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11817 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11818 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11819 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11820 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11821 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11822 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11823 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011824 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11825 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11826 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011827 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11828 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011829 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11830 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11831 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011832
11833 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11834 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11835 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11836 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11837 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11838 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11839 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11840 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11841 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11842 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11843 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11844 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11845 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11846 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11847 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11848 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11849 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11850 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11851 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11852 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11853 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11854 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11855 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11856 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11857 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11858 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11859 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11860 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11861 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11862 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011863
11864 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11869 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11870 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11871 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11872 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11873 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11874 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11875 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11876 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11877 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11878 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11880 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11881 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11882 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11883 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11884 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11885 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11886 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11887 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11888 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11889 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11890 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11891 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11892 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11893 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11894 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11895 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11896 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11897 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11898 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11899 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11900 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11901 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11902 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11903 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11904 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11905 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11906 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11907 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11908 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11909 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11910 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11911 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11912 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11913 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11914 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11915 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11916 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11917 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11918 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11919 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11920 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11921 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11922 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11923 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11924 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11925 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11926 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11927 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11928 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11929 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11930 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011931 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11932 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11933 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011934 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11935 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011936 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11937 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11938 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011939
11940 /* BGP dampening clear commands */
11941 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11942 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11943 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11944 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11945
Paul Jakmaff7924f2006-09-04 01:10:36 +000011946 /* prefix count */
11947 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11948 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11949 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011950#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011951 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11952
paul718e3742002-12-13 20:15:29 +000011953 /* New config IPv6 BGP commands. */
11954 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11955 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011956 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011957 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11958 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011959 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011960
11961 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11962 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11963 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11964 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11965
11966 /* Old config IPv6 BGP commands. */
11967 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11968 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11969
11970 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11971 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11972 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11973 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11974
11975 install_element (VIEW_NODE, &show_bgp_cmd);
11976 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11977 install_element (VIEW_NODE, &show_bgp_route_cmd);
11978 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11979 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11980 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11981 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11982 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11983 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11984 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11985 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11986 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11987 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11988 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11989 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11990 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11991 install_element (VIEW_NODE, &show_bgp_community_cmd);
11992 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11993 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11994 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11995 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11996 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11997 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11998 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11999 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12000 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12001 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12002 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12003 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12004 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12005 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12006 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12007 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12008 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12009 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12010 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12011 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12012 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12013 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12014 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12015 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12016 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12017 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12018 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12019 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12020 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012021 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12022 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12023 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12024 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012025 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
12026 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
12027 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012028 install_element (VIEW_NODE, &show_bgp_view_cmd);
12029 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12030 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12031 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12032 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12033 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12034 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12035 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12036 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12037 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12038 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12039 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12040 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12041 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12042 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12043 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12044 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12045 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012046 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
12047 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
12048 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012049
12050 /* Restricted:
12051 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12052 */
12053 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12054 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
12055 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12056 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
12057 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12058 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12059 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12060 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12061 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12062 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12063 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12064 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12065 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12066 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12067 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12068 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12069 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12070 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12071 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12072 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12073 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
12074 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
12075 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12076 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12077 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12078 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12079 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12080 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12081 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
12082 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012083
12084 install_element (ENABLE_NODE, &show_bgp_cmd);
12085 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
12086 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12087 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
12088 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12089 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
12090 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12091 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12092 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12093 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12094 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12095 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12096 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12097 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12098 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12099 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12100 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12101 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12102 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12103 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12104 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12105 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12106 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12107 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12108 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12109 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12110 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12111 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12112 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12113 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12114 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12115 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12116 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12117 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12118 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12119 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12120 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12121 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12122 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12123 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12124 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12125 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12126 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12127 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12128 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12129 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012130 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12131 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12132 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12133 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012134 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12135 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12136 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012137 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12138 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12139 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12140 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12141 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12142 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12143 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12144 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12145 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12146 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12147 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12148 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12149 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12150 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12151 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12152 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12153 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12154 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012155 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12156 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12157 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012158
12159 /* Statistics */
12160 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12161 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12162 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12163 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12164
paul718e3742002-12-13 20:15:29 +000012165 /* old command */
12166 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12167 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12168 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12169 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12170 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12171 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12172 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12173 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12174 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12175 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12176 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12177 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12178 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12179 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12180 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12181 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12182 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12183 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12184 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12185 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12186 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12187 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12188 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12189 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12190 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12191 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12192 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12193 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12194 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12195 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12196 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12197 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12198 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12199 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12200 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12201 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012202
paul718e3742002-12-13 20:15:29 +000012203 /* old command */
12204 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12205 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12206 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12207 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12208 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12209 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12210 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12211 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12212 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12213 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12214 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12215 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12216 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12217 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12218 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12219 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12220 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12221 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12222 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12223 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12224 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12225 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12226 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12227 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12228 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12229 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12230 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12231 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12232 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12233 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12234 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12235 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12236 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12237 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12238 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12239 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12240
12241 /* old command */
12242 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12243 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12244 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12245 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12246
12247 /* old command */
12248 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12249 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12250 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12251 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12252
12253 /* old command */
12254 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12255 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12256 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12257 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12258#endif /* HAVE_IPV6 */
12259
12260 install_element (BGP_NODE, &bgp_distance_cmd);
12261 install_element (BGP_NODE, &no_bgp_distance_cmd);
12262 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12263 install_element (BGP_NODE, &bgp_distance_source_cmd);
12264 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12265 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12266 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12267
12268 install_element (BGP_NODE, &bgp_damp_set_cmd);
12269 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12270 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12271 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12272 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12273 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12274 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12275 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12276 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12277 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12278}