blob: f0dfcccddc6a5219964a2648610efe2fec0a0cb3 [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)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000140 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
paul718e3742002-12-13 20:15:29 +0000913 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000914 bgp_attr_dup (attr, ri->attr);
915
paul718e3742002-12-13 20:15:29 +0000916 /* If local-preference is not set. */
917 if ((peer_sort (peer) == BGP_PEER_IBGP
918 || peer_sort (peer) == BGP_PEER_CONFED)
919 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
920 {
921 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
922 attr->local_pref = bgp->default_local_pref;
923 }
924
paul718e3742002-12-13 20:15:29 +0000925 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
926 if (peer_sort (peer) == BGP_PEER_EBGP
927 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
928 {
929 if (ri->peer != bgp->peer_self && ! transparent
930 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
931 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
932 }
933
934 /* next-hop-set */
935 if (transparent || reflect
936 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
937 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000938#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000939 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000940 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000941#endif /* HAVE_IPV6 */
942 )))
paul718e3742002-12-13 20:15:29 +0000943 {
944 /* NEXT-HOP Unchanged. */
945 }
946 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
947 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
948#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000949 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000950 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000951#endif /* HAVE_IPV6 */
952 || (peer_sort (peer) == BGP_PEER_EBGP
953 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
954 {
955 /* Set IPv4 nexthop. */
956 if (p->family == AF_INET)
957 {
958 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000959 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
960 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000961 else
962 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
963 }
964#ifdef HAVE_IPV6
965 /* Set IPv6 nexthop. */
966 if (p->family == AF_INET6)
967 {
968 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000969 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000970 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000971 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000972 }
973#endif /* HAVE_IPV6 */
974 }
975
976#ifdef HAVE_IPV6
977 if (p->family == AF_INET6)
978 {
paulfee0f4c2004-09-13 05:12:46 +0000979 /* Left nexthop_local unchanged if so configured. */
980 if ( CHECK_FLAG (peer->af_flags[afi][safi],
981 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
982 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000983 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
984 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000985 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000986 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +0000987 }
988
989 /* Default nexthop_local treatment for non-RS-Clients */
990 else
991 {
paul718e3742002-12-13 20:15:29 +0000992 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000993 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000994
995 /* Set link-local address for shared network peer. */
996 if (peer->shared_network
997 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
998 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001000 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001002 }
1003
1004 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1005 address.*/
1006 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001008
1009 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1010 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001012 }
paulfee0f4c2004-09-13 05:12:46 +00001013
1014 }
paul718e3742002-12-13 20:15:29 +00001015#endif /* HAVE_IPV6 */
1016
1017 /* If this is EBGP peer and remove-private-AS is set. */
1018 if (peer_sort (peer) == BGP_PEER_EBGP
1019 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1020 && aspath_private_as_check (attr->aspath))
1021 attr->aspath = aspath_empty_get ();
1022
1023 /* Route map & unsuppress-map apply. */
1024 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001026 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001027 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001028 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001029
paul718e3742002-12-13 20:15:29 +00001030 info.peer = peer;
1031 info.attr = attr;
1032
1033 /* The route reflector is not allowed to modify the attributes
1034 of the reflected IBGP routes. */
1035 if (peer_sort (from) == BGP_PEER_IBGP
1036 && peer_sort (peer) == BGP_PEER_IBGP)
1037 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001039 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001040 }
paulac41b2a2003-08-12 05:32:27 +00001041
1042 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1043
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001045 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1046 else
1047 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1048
paulac41b2a2003-08-12 05:32:27 +00001049 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001050
Paul Jakma9eda90c2007-08-30 13:36:17 +00001051 if (dummy_attr.extra)
1052 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001053
paul718e3742002-12-13 20:15:29 +00001054 if (ret == RMAP_DENYMATCH)
1055 {
1056 bgp_attr_flush (attr);
1057 return 0;
1058 }
1059 }
1060 return 1;
1061}
1062
paul94f2b392005-06-28 12:44:16 +00001063static int
paulfee0f4c2004-09-13 05:12:46 +00001064bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1065 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001066{
paulfee0f4c2004-09-13 05:12:46 +00001067 int ret;
1068 char buf[SU_ADDRSTRLEN];
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 struct peer *from;
1072 struct bgp *bgp;
1073
1074 from = ri->peer;
1075 filter = &rsclient->filter[afi][safi];
1076 bgp = rsclient->bgp;
1077
Paul Jakma750e8142008-07-22 21:11:48 +00001078 if (DISABLE_BGP_ANNOUNCE)
1079 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001080
1081 /* Do not send back route to sender. */
1082 if (from == rsclient)
1083 return 0;
1084
1085 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001087 if (! UNSUPPRESS_MAP_NAME (filter))
1088 return 0;
1089
1090 /* Default route check. */
1091 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1092 PEER_STATUS_DEFAULT_ORIGINATE))
1093 {
1094 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1095 return 0;
1096#ifdef HAVE_IPV6
1097 else if (p->family == AF_INET6 && p->prefixlen == 0)
1098 return 0;
1099#endif /* HAVE_IPV6 */
1100 }
1101
1102 /* If the attribute has originator-id and it is same as remote
1103 peer's id. */
1104 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1105 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001106 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1107 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001108 {
1109 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001110 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001111 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1112 rsclient->host,
1113 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1114 p->prefixlen);
1115 return 0;
1116 }
1117 }
1118
1119 /* ORF prefix-list filter check */
1120 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1121 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1122 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1123 if (rsclient->orf_plist[afi][safi])
1124 {
1125 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1126 return 0;
1127 }
1128
1129 /* Output filter check. */
1130 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1131 {
1132 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001133 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001134 "%s [Update:SEND] %s/%d is filtered",
1135 rsclient->host,
1136 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1137 p->prefixlen);
1138 return 0;
1139 }
1140
1141#ifdef BGP_SEND_ASPATH_CHECK
1142 /* AS path loop check. */
1143 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1144 {
1145 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001146 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001147 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001148 rsclient->host, rsclient->as);
1149 return 0;
1150 }
1151#endif /* BGP_SEND_ASPATH_CHECK */
1152
1153 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001154 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001155
1156 /* next-hop-set */
1157 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1158#ifdef HAVE_IPV6
1159 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001160 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001161#endif /* HAVE_IPV6 */
1162 )
1163 {
1164 /* Set IPv4 nexthop. */
1165 if (p->family == AF_INET)
1166 {
1167 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001168 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001169 IPV4_MAX_BYTELEN);
1170 else
1171 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1172 }
1173#ifdef HAVE_IPV6
1174 /* Set IPv6 nexthop. */
1175 if (p->family == AF_INET6)
1176 {
1177 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001178 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001179 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001180 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001181 }
1182#endif /* HAVE_IPV6 */
1183 }
1184
1185#ifdef HAVE_IPV6
1186 if (p->family == AF_INET6)
1187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001188 struct attr_extra *attre = attr->extra;
1189
1190 assert (attr->extra);
1191
paulfee0f4c2004-09-13 05:12:46 +00001192 /* Left nexthop_local unchanged if so configured. */
1193 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1194 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1195 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001196 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1197 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001198 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001199 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001200 }
1201
1202 /* Default nexthop_local treatment for RS-Clients */
1203 else
1204 {
1205 /* Announcer and RS-Client are both in the same network */
1206 if (rsclient->shared_network && from->shared_network &&
1207 (rsclient->ifindex == from->ifindex))
1208 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001209 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1210 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001211 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001212 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001213 }
1214
1215 /* Set link-local address for shared network peer. */
1216 else if (rsclient->shared_network
1217 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1218 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001220 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001222 }
1223
1224 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001226 }
1227
1228 }
1229#endif /* HAVE_IPV6 */
1230
1231
1232 /* If this is EBGP peer and remove-private-AS is set. */
1233 if (peer_sort (rsclient) == BGP_PEER_EBGP
1234 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1235 && aspath_private_as_check (attr->aspath))
1236 attr->aspath = aspath_empty_get ();
1237
1238 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001240 {
1241 info.peer = rsclient;
1242 info.attr = attr;
1243
1244 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1245
Paul Jakmafb982c22007-05-04 20:15:47 +00001246 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001247 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1248 else
1249 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1250
1251 rsclient->rmap_type = 0;
1252
1253 if (ret == RMAP_DENYMATCH)
1254 {
1255 bgp_attr_flush (attr);
1256 return 0;
1257 }
1258 }
1259
1260 return 1;
1261}
1262
1263struct bgp_info_pair
1264{
1265 struct bgp_info *old;
1266 struct bgp_info *new;
1267};
1268
paul94f2b392005-06-28 12:44:16 +00001269static void
paulfee0f4c2004-09-13 05:12:46 +00001270bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1271{
paul718e3742002-12-13 20:15:29 +00001272 struct bgp_info *new_select;
1273 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001274 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001275 struct bgp_info *ri1;
1276 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001277 struct bgp_info *nextri = NULL;
1278
paul718e3742002-12-13 20:15:29 +00001279 /* bgp deterministic-med */
1280 new_select = NULL;
1281 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1282 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1283 {
1284 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1285 continue;
1286 if (BGP_INFO_HOLDDOWN (ri1))
1287 continue;
1288
1289 new_select = ri1;
1290 if (ri1->next)
1291 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1292 {
1293 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1294 continue;
1295 if (BGP_INFO_HOLDDOWN (ri2))
1296 continue;
1297
1298 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1299 || aspath_cmp_left_confed (ri1->attr->aspath,
1300 ri2->attr->aspath))
1301 {
1302 if (bgp_info_cmp (bgp, ri2, new_select))
1303 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001304 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001305 new_select = ri2;
1306 }
1307
Paul Jakma1a392d42006-09-07 00:24:49 +00001308 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001309 }
1310 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001311 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1312 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001313 }
1314
1315 /* Check old selected route and new selected route. */
1316 old_select = NULL;
1317 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001318 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001319 {
1320 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1321 old_select = ri;
1322
1323 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001324 {
1325 /* reap REMOVED routes, if needs be
1326 * selected route must stay for a while longer though
1327 */
1328 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1329 && (ri != old_select))
1330 bgp_info_reap (rn, ri);
1331
1332 continue;
1333 }
paul718e3742002-12-13 20:15:29 +00001334
1335 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1336 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1337 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001338 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001339 continue;
1340 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001341 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1342 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001343
1344 if (bgp_info_cmp (bgp, ri, new_select))
1345 new_select = ri;
1346 }
paulb40d9392005-08-22 22:34:41 +00001347
paulfee0f4c2004-09-13 05:12:46 +00001348 result->old = old_select;
1349 result->new = new_select;
1350
1351 return;
1352}
1353
paul94f2b392005-06-28 12:44:16 +00001354static int
paulfee0f4c2004-09-13 05:12:46 +00001355bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001356 struct bgp_node *rn, afi_t afi, safi_t safi)
1357{
paulfee0f4c2004-09-13 05:12:46 +00001358 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001359 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001360
1361 p = &rn->p;
1362
Paul Jakma9eda90c2007-08-30 13:36:17 +00001363 /* Announce route to Established peer. */
1364 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001365 return 0;
1366
Paul Jakma9eda90c2007-08-30 13:36:17 +00001367 /* Address family configuration check. */
1368 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001369 return 0;
1370
Paul Jakma9eda90c2007-08-30 13:36:17 +00001371 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001372 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1373 PEER_STATUS_ORF_WAIT_REFRESH))
1374 return 0;
1375
1376 switch (rn->table->type)
1377 {
1378 case BGP_TABLE_MAIN:
1379 /* Announcement to peer->conf. If the route is filtered,
1380 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001381 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1382 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001383 else
1384 bgp_adj_out_unset (rn, peer, p, afi, safi);
1385 break;
1386 case BGP_TABLE_RSCLIENT:
1387 /* Announcement to peer->conf. If the route is filtered,
1388 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001389 if (selected &&
1390 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1391 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1392 else
1393 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001394 break;
1395 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001396
1397 bgp_attr_extra_free (&attr);
1398
paulfee0f4c2004-09-13 05:12:46 +00001399 return 0;
paul200df112005-06-01 11:17:05 +00001400}
paulfee0f4c2004-09-13 05:12:46 +00001401
paul200df112005-06-01 11:17:05 +00001402struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001403{
paul200df112005-06-01 11:17:05 +00001404 struct bgp *bgp;
1405 struct bgp_node *rn;
1406 afi_t afi;
1407 safi_t safi;
1408};
1409
1410static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001411bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001412{
paul0fb58d52005-11-14 14:31:49 +00001413 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001414 struct bgp *bgp = pq->bgp;
1415 struct bgp_node *rn = pq->rn;
1416 afi_t afi = pq->afi;
1417 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001418 struct bgp_info *new_select;
1419 struct bgp_info *old_select;
1420 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001421 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001422 struct peer *rsclient = rn->table->owner;
1423
paulfee0f4c2004-09-13 05:12:46 +00001424 /* Best path selection. */
1425 bgp_best_selection (bgp, rn, &old_and_new);
1426 new_select = old_and_new.new;
1427 old_select = old_and_new.old;
1428
paul200df112005-06-01 11:17:05 +00001429 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1430 {
Chris Caputo228da422009-07-18 05:44:03 +00001431 if (rsclient->group)
1432 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1433 {
1434 /* Nothing to do. */
1435 if (old_select && old_select == new_select)
1436 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1437 continue;
paulfee0f4c2004-09-13 05:12:46 +00001438
Chris Caputo228da422009-07-18 05:44:03 +00001439 if (old_select)
1440 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1441 if (new_select)
1442 {
1443 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1444 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1445 }
paulfee0f4c2004-09-13 05:12:46 +00001446
Chris Caputo228da422009-07-18 05:44:03 +00001447 bgp_process_announce_selected (rsclient, new_select, rn,
1448 afi, safi);
1449 }
paul200df112005-06-01 11:17:05 +00001450 }
1451 else
1452 {
hassob7395792005-08-26 12:58:38 +00001453 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001454 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001455 if (new_select)
1456 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001457 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1458 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001459 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001461 }
paulfee0f4c2004-09-13 05:12:46 +00001462
paulb40d9392005-08-22 22:34:41 +00001463 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1464 bgp_info_reap (rn, old_select);
1465
paul200df112005-06-01 11:17:05 +00001466 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1467 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001468}
1469
paul200df112005-06-01 11:17:05 +00001470static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001471bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001472{
paul0fb58d52005-11-14 14:31:49 +00001473 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001474 struct bgp *bgp = pq->bgp;
1475 struct bgp_node *rn = pq->rn;
1476 afi_t afi = pq->afi;
1477 safi_t safi = pq->safi;
1478 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001479 struct bgp_info *new_select;
1480 struct bgp_info *old_select;
1481 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001482 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001483 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001484
paulfee0f4c2004-09-13 05:12:46 +00001485 /* Best path selection. */
1486 bgp_best_selection (bgp, rn, &old_and_new);
1487 old_select = old_and_new.old;
1488 new_select = old_and_new.new;
1489
1490 /* Nothing to do. */
1491 if (old_select && old_select == new_select)
1492 {
1493 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001494 {
1495 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1496 bgp_zebra_announce (p, old_select, bgp);
1497
1498 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1499 return WQ_SUCCESS;
1500 }
paulfee0f4c2004-09-13 05:12:46 +00001501 }
paul718e3742002-12-13 20:15:29 +00001502
hasso338b3422005-02-23 14:27:24 +00001503 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001504 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001505 if (new_select)
1506 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001507 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1508 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001509 }
1510
1511
paul718e3742002-12-13 20:15:29 +00001512 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001513 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001514 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001515 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001516 }
1517
1518 /* FIB update. */
1519 if (safi == SAFI_UNICAST && ! bgp->name &&
1520 ! bgp_option_check (BGP_OPT_NO_FIB))
1521 {
1522 if (new_select
1523 && new_select->type == ZEBRA_ROUTE_BGP
1524 && new_select->sub_type == BGP_ROUTE_NORMAL)
1525 bgp_zebra_announce (p, new_select, bgp);
1526 else
1527 {
1528 /* Withdraw the route from the kernel. */
1529 if (old_select
1530 && old_select->type == ZEBRA_ROUTE_BGP
1531 && old_select->sub_type == BGP_ROUTE_NORMAL)
1532 bgp_zebra_withdraw (p, old_select);
1533 }
1534 }
paulb40d9392005-08-22 22:34:41 +00001535
1536 /* Reap old select bgp_info, it it has been removed */
1537 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1538 bgp_info_reap (rn, old_select);
1539
paul200df112005-06-01 11:17:05 +00001540 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1541 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001542}
1543
paul200df112005-06-01 11:17:05 +00001544static void
paul0fb58d52005-11-14 14:31:49 +00001545bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001546{
paul0fb58d52005-11-14 14:31:49 +00001547 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001548 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001549
Chris Caputo228da422009-07-18 05:44:03 +00001550 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001551 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001552 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001553 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1554}
1555
1556static void
1557bgp_process_queue_init (void)
1558{
1559 bm->process_main_queue
1560 = work_queue_new (bm->master, "process_main_queue");
1561 bm->process_rsclient_queue
1562 = work_queue_new (bm->master, "process_rsclient_queue");
1563
1564 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1565 {
1566 zlog_err ("%s: Failed to allocate work queue", __func__);
1567 exit (1);
1568 }
1569
1570 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001571 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001572 bm->process_main_queue->spec.max_retries = 0;
1573 bm->process_main_queue->spec.hold = 50;
1574
1575 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1576 sizeof (struct work_queue *));
1577 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001578}
1579
1580void
paulfee0f4c2004-09-13 05:12:46 +00001581bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1582{
paul200df112005-06-01 11:17:05 +00001583 struct bgp_process_queue *pqnode;
1584
1585 /* already scheduled for processing? */
1586 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1587 return;
1588
1589 if ( (bm->process_main_queue == NULL) ||
1590 (bm->process_rsclient_queue == NULL) )
1591 bgp_process_queue_init ();
1592
1593 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1594 sizeof (struct bgp_process_queue));
1595 if (!pqnode)
1596 return;
Chris Caputo228da422009-07-18 05:44:03 +00001597
1598 /* all unlocked in bgp_processq_del */
1599 bgp_table_lock (rn->table);
1600 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001601 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001602 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001603 pqnode->afi = afi;
1604 pqnode->safi = safi;
1605
paulfee0f4c2004-09-13 05:12:46 +00001606 switch (rn->table->type)
1607 {
paul200df112005-06-01 11:17:05 +00001608 case BGP_TABLE_MAIN:
1609 work_queue_add (bm->process_main_queue, pqnode);
1610 break;
1611 case BGP_TABLE_RSCLIENT:
1612 work_queue_add (bm->process_rsclient_queue, pqnode);
1613 break;
paulfee0f4c2004-09-13 05:12:46 +00001614 }
paul200df112005-06-01 11:17:05 +00001615
1616 return;
paulfee0f4c2004-09-13 05:12:46 +00001617}
hasso0a486e52005-02-01 20:57:17 +00001618
paul94f2b392005-06-28 12:44:16 +00001619static int
hasso0a486e52005-02-01 20:57:17 +00001620bgp_maximum_prefix_restart_timer (struct thread *thread)
1621{
1622 struct peer *peer;
1623
1624 peer = THREAD_ARG (thread);
1625 peer->t_pmax_restart = NULL;
1626
1627 if (BGP_DEBUG (events, EVENTS))
1628 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1629 peer->host);
1630
1631 peer_clear (peer);
1632
1633 return 0;
1634}
1635
paulfee0f4c2004-09-13 05:12:46 +00001636int
paul5228ad22004-06-04 17:58:18 +00001637bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1638 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001639{
hassoe0701b72004-05-20 09:19:34 +00001640 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1641 return 0;
1642
1643 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001644 {
hassoe0701b72004-05-20 09:19:34 +00001645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1646 && ! always)
1647 return 0;
paul718e3742002-12-13 20:15:29 +00001648
hassoe0701b72004-05-20 09:19:34 +00001649 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001650 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1651 "limit %ld", afi_safi_print (afi, safi), peer->host,
1652 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001653 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001654
hassoe0701b72004-05-20 09:19:34 +00001655 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1656 return 0;
paul718e3742002-12-13 20:15:29 +00001657
hassoe0701b72004-05-20 09:19:34 +00001658 {
paul5228ad22004-06-04 17:58:18 +00001659 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001660
1661 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001662 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001663
1664 ndata[0] = (afi >> 8);
1665 ndata[1] = afi;
1666 ndata[2] = safi;
1667 ndata[3] = (peer->pmax[afi][safi] >> 24);
1668 ndata[4] = (peer->pmax[afi][safi] >> 16);
1669 ndata[5] = (peer->pmax[afi][safi] >> 8);
1670 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001671
1672 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1673 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1674 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1675 }
hasso0a486e52005-02-01 20:57:17 +00001676
1677 /* restart timer start */
1678 if (peer->pmax_restart[afi][safi])
1679 {
1680 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1681
1682 if (BGP_DEBUG (events, EVENTS))
1683 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1684 peer->host, peer->v_pmax_restart);
1685
1686 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1687 peer->v_pmax_restart);
1688 }
1689
hassoe0701b72004-05-20 09:19:34 +00001690 return 1;
paul718e3742002-12-13 20:15:29 +00001691 }
hassoe0701b72004-05-20 09:19:34 +00001692 else
1693 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1694
1695 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1696 {
1697 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1698 && ! always)
1699 return 0;
1700
1701 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001702 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1703 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1704 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001705 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1706 }
1707 else
1708 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001709 return 0;
1710}
1711
paulb40d9392005-08-22 22:34:41 +00001712/* Unconditionally remove the route from the RIB, without taking
1713 * damping into consideration (eg, because the session went down)
1714 */
paul94f2b392005-06-28 12:44:16 +00001715static void
paul718e3742002-12-13 20:15:29 +00001716bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1717 afi_t afi, safi_t safi)
1718{
paul902212c2006-02-05 17:51:19 +00001719 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1720
1721 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1722 bgp_info_delete (rn, ri); /* keep historical info */
1723
paulb40d9392005-08-22 22:34:41 +00001724 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001725}
1726
paul94f2b392005-06-28 12:44:16 +00001727static void
paul718e3742002-12-13 20:15:29 +00001728bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001729 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001730{
paul718e3742002-12-13 20:15:29 +00001731 int status = BGP_DAMP_NONE;
1732
paulb40d9392005-08-22 22:34:41 +00001733 /* apply dampening, if result is suppressed, we'll be retaining
1734 * the bgp_info in the RIB for historical reference.
1735 */
1736 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1737 && peer_sort (peer) == BGP_PEER_EBGP)
1738 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1739 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001740 {
paul902212c2006-02-05 17:51:19 +00001741 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1742 return;
1743 }
1744
1745 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001746}
1747
paul94f2b392005-06-28 12:44:16 +00001748static void
paulfee0f4c2004-09-13 05:12:46 +00001749bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1750 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1751 int sub_type, struct prefix_rd *prd, u_char *tag)
1752{
1753 struct bgp_node *rn;
1754 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001755 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001756 struct attr *attr_new;
1757 struct attr *attr_new2;
1758 struct bgp_info *ri;
1759 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001760 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001761 char buf[SU_ADDRSTRLEN];
1762
1763 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1764 if (peer == rsclient)
1765 return;
1766
1767 bgp = peer->bgp;
1768 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1769
1770 /* Check previously received route. */
1771 for (ri = rn->info; ri; ri = ri->next)
1772 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1773 break;
1774
1775 /* AS path loop check. */
1776 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1777 {
1778 reason = "as-path contains our own AS;";
1779 goto filtered;
1780 }
1781
1782 /* Route reflector originator ID check. */
1783 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001784 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001785 {
1786 reason = "originator is us;";
1787 goto filtered;
1788 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001789
1790 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001791
1792 /* Apply export policy. */
1793 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1794 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1795 {
1796 reason = "export-policy;";
1797 goto filtered;
1798 }
1799
1800 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001801
paulfee0f4c2004-09-13 05:12:46 +00001802 /* Apply import policy. */
1803 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1804 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001805 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001806
1807 reason = "import-policy;";
1808 goto filtered;
1809 }
1810
1811 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001812 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001813
1814 /* IPv4 unicast next hop check. */
1815 if (afi == AFI_IP && safi == SAFI_UNICAST)
1816 {
1817 /* Next hop must not be 0.0.0.0 nor Class E address. */
1818 if (new_attr.nexthop.s_addr == 0
1819 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1820 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001821 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001822
1823 reason = "martian next-hop;";
1824 goto filtered;
1825 }
1826 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001827
1828 /* new_attr isn't passed to any functions after here */
1829 bgp_attr_extra_free (&new_attr);
1830
paulfee0f4c2004-09-13 05:12:46 +00001831 /* If the update is implicit withdraw. */
1832 if (ri)
1833 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001834 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001835
1836 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001837 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1838 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001839 {
1840
Paul Jakma1a392d42006-09-07 00:24:49 +00001841 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001842
1843 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001844 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001845 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1846 peer->host,
1847 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1848 p->prefixlen, rsclient->host);
1849
Chris Caputo228da422009-07-18 05:44:03 +00001850 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001851 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001852
Chris Caputo228da422009-07-18 05:44:03 +00001853 return;
paulfee0f4c2004-09-13 05:12:46 +00001854 }
1855
Paul Jakma16d2e242007-04-10 19:32:10 +00001856 /* Withdraw/Announce before we fully processed the withdraw */
1857 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1858 bgp_info_restore (rn, ri);
1859
paulfee0f4c2004-09-13 05:12:46 +00001860 /* Received Logging. */
1861 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001862 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001863 peer->host,
1864 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1865 p->prefixlen, rsclient->host);
1866
1867 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001869
1870 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001871 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001872 ri->attr = attr_new;
1873
1874 /* Update MPLS tag. */
1875 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001876 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001877
Paul Jakma1a392d42006-09-07 00:24:49 +00001878 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001879
1880 /* Process change. */
1881 bgp_process (bgp, rn, afi, safi);
1882 bgp_unlock_node (rn);
1883
1884 return;
1885 }
1886
1887 /* Received Logging. */
1888 if (BGP_DEBUG (update, UPDATE_IN))
1889 {
ajsd2c1f162004-12-08 21:10:20 +00001890 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001891 peer->host,
1892 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1893 p->prefixlen, rsclient->host);
1894 }
1895
1896 /* Make new BGP info. */
1897 new = bgp_info_new ();
1898 new->type = type;
1899 new->sub_type = sub_type;
1900 new->peer = peer;
1901 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001902 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001903
1904 /* Update MPLS tag. */
1905 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001906 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001907
Paul Jakma1a392d42006-09-07 00:24:49 +00001908 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001909
1910 /* Register new BGP information. */
1911 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001912
1913 /* route_node_get lock */
1914 bgp_unlock_node (rn);
1915
paulfee0f4c2004-09-13 05:12:46 +00001916 /* Process change. */
1917 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001918
1919 bgp_attr_extra_free (&new_attr);
1920
paulfee0f4c2004-09-13 05:12:46 +00001921 return;
1922
1923 filtered:
1924
1925 /* This BGP update is filtered. Log the reason then update BGP entry. */
1926 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001927 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001928 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1929 peer->host,
1930 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1931 p->prefixlen, rsclient->host, reason);
1932
1933 if (ri)
paulb40d9392005-08-22 22:34:41 +00001934 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001937
1938 if (new_attr.extra)
1939 bgp_attr_extra_free (&new_attr);
1940
paulfee0f4c2004-09-13 05:12:46 +00001941 return;
1942}
1943
paul94f2b392005-06-28 12:44:16 +00001944static void
paulfee0f4c2004-09-13 05:12:46 +00001945bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1946 struct peer *peer, struct prefix *p, int type, int sub_type,
1947 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001948{
paulfee0f4c2004-09-13 05:12:46 +00001949 struct bgp_node *rn;
1950 struct bgp_info *ri;
1951 char buf[SU_ADDRSTRLEN];
1952
1953 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00001954 return;
paulfee0f4c2004-09-13 05:12:46 +00001955
1956 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1957
1958 /* Lookup withdrawn route. */
1959 for (ri = rn->info; ri; ri = ri->next)
1960 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1961 break;
1962
1963 /* Withdraw specified route from routing table. */
1964 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001965 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001966 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001967 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001968 "%s Can't find the route %s/%d", peer->host,
1969 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1970 p->prefixlen);
1971
1972 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00001973 bgp_unlock_node (rn);
1974}
paulfee0f4c2004-09-13 05:12:46 +00001975
paul94f2b392005-06-28 12:44:16 +00001976static int
paulfee0f4c2004-09-13 05:12:46 +00001977bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001978 afi_t afi, safi_t safi, int type, int sub_type,
1979 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1980{
1981 int ret;
1982 int aspath_loop_count = 0;
1983 struct bgp_node *rn;
1984 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001985 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00001986 struct attr *attr_new;
1987 struct bgp_info *ri;
1988 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001989 const char *reason;
paul718e3742002-12-13 20:15:29 +00001990 char buf[SU_ADDRSTRLEN];
1991
1992 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001993 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00001994
paul718e3742002-12-13 20:15:29 +00001995 /* When peer's soft reconfiguration enabled. Record input packet in
1996 Adj-RIBs-In. */
1997 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1998 && peer != bgp->peer_self && ! soft_reconfig)
1999 bgp_adj_in_set (rn, peer, attr);
2000
2001 /* Check previously received route. */
2002 for (ri = rn->info; ri; ri = ri->next)
2003 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2004 break;
2005
2006 /* AS path local-as loop check. */
2007 if (peer->change_local_as)
2008 {
2009 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2010 aspath_loop_count = 1;
2011
2012 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2013 {
2014 reason = "as-path contains our own AS;";
2015 goto filtered;
2016 }
2017 }
2018
2019 /* AS path loop check. */
2020 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2021 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2022 && aspath_loop_check(attr->aspath, bgp->confed_id)
2023 > peer->allowas_in[afi][safi]))
2024 {
2025 reason = "as-path contains our own AS;";
2026 goto filtered;
2027 }
2028
2029 /* Route reflector originator ID check. */
2030 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002031 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002032 {
2033 reason = "originator is us;";
2034 goto filtered;
2035 }
2036
2037 /* Route reflector cluster ID check. */
2038 if (bgp_cluster_filter (peer, attr))
2039 {
2040 reason = "reflected from the same cluster;";
2041 goto filtered;
2042 }
2043
2044 /* Apply incoming filter. */
2045 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2046 {
2047 reason = "filter;";
2048 goto filtered;
2049 }
2050
2051 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002053
2054 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2055 {
2056 reason = "route-map;";
2057 goto filtered;
2058 }
2059
2060 /* IPv4 unicast next hop check. */
2061 if (afi == AFI_IP && safi == SAFI_UNICAST)
2062 {
2063 /* If the peer is EBGP and nexthop is not on connected route,
2064 discard it. */
2065 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2066 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002067 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002068 {
2069 reason = "non-connected next-hop;";
2070 goto filtered;
2071 }
2072
2073 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2074 must not be my own address. */
2075 if (bgp_nexthop_self (afi, &new_attr)
2076 || new_attr.nexthop.s_addr == 0
2077 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2078 {
2079 reason = "martian next-hop;";
2080 goto filtered;
2081 }
2082 }
2083
2084 attr_new = bgp_attr_intern (&new_attr);
2085
2086 /* If the update is implicit withdraw. */
2087 if (ri)
2088 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002089 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002090
2091 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002092 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2093 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002094 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002095 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002096
2097 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2098 && peer_sort (peer) == BGP_PEER_EBGP
2099 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2100 {
2101 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002102 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002103 peer->host,
2104 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2105 p->prefixlen);
2106
paul902212c2006-02-05 17:51:19 +00002107 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2108 {
2109 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2110 bgp_process (bgp, rn, afi, safi);
2111 }
paul718e3742002-12-13 20:15:29 +00002112 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002113 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002114 {
2115 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002116 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002117 "%s rcvd %s/%d...duplicate ignored",
2118 peer->host,
2119 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2120 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002121
2122 /* graceful restart STALE flag unset. */
2123 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2124 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002125 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002126 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002127 }
paul718e3742002-12-13 20:15:29 +00002128 }
2129
2130 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002131 bgp_attr_unintern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002132 bgp_attr_extra_free (&new_attr);
2133
paul718e3742002-12-13 20:15:29 +00002134 return 0;
2135 }
2136
Paul Jakma16d2e242007-04-10 19:32:10 +00002137 /* Withdraw/Announce before we fully processed the withdraw */
2138 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2139 {
2140 if (BGP_DEBUG (update, UPDATE_IN))
2141 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2142 peer->host,
2143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2144 p->prefixlen);
2145 bgp_info_restore (rn, ri);
2146 }
2147
paul718e3742002-12-13 20:15:29 +00002148 /* Received Logging. */
2149 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002150 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002151 peer->host,
2152 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2153 p->prefixlen);
2154
hasso93406d82005-02-02 14:40:33 +00002155 /* graceful restart STALE flag unset. */
2156 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002157 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002158
paul718e3742002-12-13 20:15:29 +00002159 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002160 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002161
2162 /* implicit withdraw, decrement aggregate and pcount here.
2163 * only if update is accepted, they'll increment below.
2164 */
paul902212c2006-02-05 17:51:19 +00002165 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2166
paul718e3742002-12-13 20:15:29 +00002167 /* Update bgp route dampening information. */
2168 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2169 && peer_sort (peer) == BGP_PEER_EBGP)
2170 {
2171 /* This is implicit withdraw so we should update dampening
2172 information. */
2173 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2174 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002175 }
2176
paul718e3742002-12-13 20:15:29 +00002177 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002178 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002179 ri->attr = attr_new;
2180
2181 /* Update MPLS tag. */
2182 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002183 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002184
2185 /* Update bgp route dampening information. */
2186 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2187 && peer_sort (peer) == BGP_PEER_EBGP)
2188 {
2189 /* Now we do normal update dampening. */
2190 ret = bgp_damp_update (ri, rn, afi, safi);
2191 if (ret == BGP_DAMP_SUPPRESSED)
2192 {
2193 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002194 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002195 return 0;
2196 }
2197 }
2198
2199 /* Nexthop reachability check. */
2200 if ((afi == AFI_IP || afi == AFI_IP6)
2201 && safi == SAFI_UNICAST
2202 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002203 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002204 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002205 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002208 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002209 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002210 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002211 }
2212 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002213 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002214
2215 /* Process change. */
2216 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2217
2218 bgp_process (bgp, rn, afi, safi);
2219 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002220 bgp_attr_extra_free (&new_attr);
2221
paul718e3742002-12-13 20:15:29 +00002222 return 0;
2223 }
2224
2225 /* Received Logging. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
2227 {
ajsd2c1f162004-12-08 21:10:20 +00002228 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002229 peer->host,
2230 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen);
2232 }
2233
paul718e3742002-12-13 20:15:29 +00002234 /* Make new BGP info. */
2235 new = bgp_info_new ();
2236 new->type = type;
2237 new->sub_type = sub_type;
2238 new->peer = peer;
2239 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002240 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002241
2242 /* Update MPLS tag. */
2243 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002244 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002245
2246 /* Nexthop reachability check. */
2247 if ((afi == AFI_IP || afi == AFI_IP6)
2248 && safi == SAFI_UNICAST
2249 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002250 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002251 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002252 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002253 {
2254 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002256 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002257 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002258 }
2259 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002260 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002261
paul902212c2006-02-05 17:51:19 +00002262 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002263 bgp_aggregate_increment (bgp, p, new, afi, safi);
2264
2265 /* Register new BGP information. */
2266 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002267
2268 /* route_node_get lock */
2269 bgp_unlock_node (rn);
2270
Paul Jakmafb982c22007-05-04 20:15:47 +00002271 bgp_attr_extra_free (&new_attr);
2272
paul718e3742002-12-13 20:15:29 +00002273 /* If maximum prefix count is configured and current prefix
2274 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002275 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2276 return -1;
paul718e3742002-12-13 20:15:29 +00002277
2278 /* Process change. */
2279 bgp_process (bgp, rn, afi, safi);
2280
2281 return 0;
2282
2283 /* This BGP update is filtered. Log the reason then update BGP
2284 entry. */
2285 filtered:
2286 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002287 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002288 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2289 peer->host,
2290 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2291 p->prefixlen, reason);
2292
2293 if (ri)
paulb40d9392005-08-22 22:34:41 +00002294 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002295
2296 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002297
2298 bgp_attr_extra_free (&new_attr);
2299
paul718e3742002-12-13 20:15:29 +00002300 return 0;
2301}
2302
2303int
paulfee0f4c2004-09-13 05:12:46 +00002304bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2305 afi_t afi, safi_t safi, int type, int sub_type,
2306 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2307{
2308 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002309 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002310 struct bgp *bgp;
2311 int ret;
2312
2313 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2314 soft_reconfig);
2315
2316 bgp = peer->bgp;
2317
2318 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002319 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002320 {
2321 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2322 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2323 sub_type, prd, tag);
2324 }
2325
2326 return ret;
2327}
2328
2329int
paul718e3742002-12-13 20:15:29 +00002330bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002331 afi_t afi, safi_t safi, int type, int sub_type,
2332 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002333{
2334 struct bgp *bgp;
2335 char buf[SU_ADDRSTRLEN];
2336 struct bgp_node *rn;
2337 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002338 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002339 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002340
2341 bgp = peer->bgp;
2342
paulfee0f4c2004-09-13 05:12:46 +00002343 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002344 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002345 {
2346 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2347 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2348 }
2349
paul718e3742002-12-13 20:15:29 +00002350 /* Logging. */
2351 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002352 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002353 peer->host,
2354 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2355 p->prefixlen);
2356
2357 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002358 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002359
2360 /* If peer is soft reconfiguration enabled. Record input packet for
2361 further calculation. */
2362 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2363 && peer != bgp->peer_self)
2364 bgp_adj_in_unset (rn, peer);
2365
2366 /* Lookup withdrawn route. */
2367 for (ri = rn->info; ri; ri = ri->next)
2368 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2369 break;
2370
2371 /* Withdraw specified route from routing table. */
2372 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002373 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002374 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002375 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002376 "%s Can't find the route %s/%d", peer->host,
2377 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2378 p->prefixlen);
2379
2380 /* Unlock bgp_node_get() lock. */
2381 bgp_unlock_node (rn);
2382
2383 return 0;
2384}
2385
2386void
2387bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2388{
2389 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002390 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002391 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002392 struct prefix p;
2393 struct bgp_info binfo;
2394 struct peer *from;
2395 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002396
Paul Jakmab2497022007-06-14 11:17:58 +00002397 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002398 return;
2399
paul718e3742002-12-13 20:15:29 +00002400 bgp = peer->bgp;
2401 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002402
paul718e3742002-12-13 20:15:29 +00002403 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2404 aspath = attr.aspath;
2405 attr.local_pref = bgp->default_local_pref;
2406 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2407
2408 if (afi == AFI_IP)
2409 str2prefix ("0.0.0.0/0", &p);
2410#ifdef HAVE_IPV6
2411 else if (afi == AFI_IP6)
2412 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002413 struct attr_extra *ae;
2414 attr.extra = NULL;
2415
2416 ae = bgp_attr_extra_get (&attr);
2417 attr.extra = ae;
2418
paul718e3742002-12-13 20:15:29 +00002419 str2prefix ("::/0", &p);
2420
2421 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002422 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002423 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002424 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002425
2426 /* If the peer is on shared nextwork and we have link-local
2427 nexthop set it. */
2428 if (peer->shared_network
2429 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2430 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002431 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002432 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002433 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002434 }
2435 }
2436#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002437
2438 if (peer->default_rmap[afi][safi].name)
2439 {
2440 binfo.peer = bgp->peer_self;
2441 binfo.attr = &attr;
2442
paulfee0f4c2004-09-13 05:12:46 +00002443 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2444
paul718e3742002-12-13 20:15:29 +00002445 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2446 RMAP_BGP, &binfo);
2447
paulfee0f4c2004-09-13 05:12:46 +00002448 bgp->peer_self->rmap_type = 0;
2449
paul718e3742002-12-13 20:15:29 +00002450 if (ret == RMAP_DENYMATCH)
2451 {
2452 bgp_attr_flush (&attr);
2453 withdraw = 1;
2454 }
2455 }
2456
2457 if (withdraw)
2458 {
2459 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2460 bgp_default_withdraw_send (peer, afi, safi);
2461 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2462 }
2463 else
2464 {
2465 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2466 bgp_default_update_send (peer, &attr, afi, safi, from);
2467 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002468
2469 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002470 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002471}
2472
2473static void
2474bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002475 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002476{
2477 struct bgp_node *rn;
2478 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002479 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002480
paul718e3742002-12-13 20:15:29 +00002481 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002482 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002483
2484 if (safi != SAFI_MPLS_VPN
2485 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2486 bgp_default_originate (peer, afi, safi, 0);
2487
2488 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2489 for (ri = rn->info; ri; ri = ri->next)
2490 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2491 {
paulfee0f4c2004-09-13 05:12:46 +00002492 if ( (rsclient) ?
2493 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2494 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002495 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2496 else
2497 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002498
2499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002500 }
2501}
2502
2503void
2504bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2505{
2506 struct bgp_node *rn;
2507 struct bgp_table *table;
2508
2509 if (peer->status != Established)
2510 return;
2511
2512 if (! peer->afc_nego[afi][safi])
2513 return;
2514
2515 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2516 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2517 return;
2518
2519 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002520 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002521 else
2522 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2523 rn = bgp_route_next(rn))
2524 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002525 bgp_announce_table (peer, afi, safi, table, 0);
2526
2527 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2528 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002529}
2530
2531void
2532bgp_announce_route_all (struct peer *peer)
2533{
2534 afi_t afi;
2535 safi_t safi;
2536
2537 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2538 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2539 bgp_announce_route (peer, afi, safi);
2540}
2541
2542static void
paulfee0f4c2004-09-13 05:12:46 +00002543bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2544 safi_t safi, struct bgp_table *table)
2545{
2546 struct bgp_node *rn;
2547 struct bgp_adj_in *ain;
2548
2549 if (! table)
2550 table = rsclient->bgp->rib[afi][safi];
2551
2552 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2553 for (ain = rn->adj_in; ain; ain = ain->next)
2554 {
2555 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2556 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2557 }
2558}
2559
2560void
2561bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2562{
2563 struct bgp_table *table;
2564 struct bgp_node *rn;
2565
2566 if (safi != SAFI_MPLS_VPN)
2567 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2568
2569 else
2570 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2571 rn = bgp_route_next (rn))
2572 if ((table = rn->info) != NULL)
2573 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2574}
2575
2576static void
paul718e3742002-12-13 20:15:29 +00002577bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2578 struct bgp_table *table)
2579{
2580 int ret;
2581 struct bgp_node *rn;
2582 struct bgp_adj_in *ain;
2583
2584 if (! table)
2585 table = peer->bgp->rib[afi][safi];
2586
2587 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2588 for (ain = rn->adj_in; ain; ain = ain->next)
2589 {
2590 if (ain->peer == peer)
2591 {
2592 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2593 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2594 NULL, NULL, 1);
2595 if (ret < 0)
2596 {
2597 bgp_unlock_node (rn);
2598 return;
2599 }
2600 continue;
2601 }
2602 }
2603}
2604
2605void
2606bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2607{
2608 struct bgp_node *rn;
2609 struct bgp_table *table;
2610
2611 if (peer->status != Established)
2612 return;
2613
2614 if (safi != SAFI_MPLS_VPN)
2615 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2616 else
2617 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2618 rn = bgp_route_next (rn))
2619 if ((table = rn->info) != NULL)
2620 bgp_soft_reconfig_table (peer, afi, safi, table);
2621}
2622
Chris Caputo228da422009-07-18 05:44:03 +00002623
2624struct bgp_clear_node_queue
2625{
2626 struct bgp_node *rn;
2627 enum bgp_clear_route_type purpose;
2628};
2629
paul200df112005-06-01 11:17:05 +00002630static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002631bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002632{
Chris Caputo228da422009-07-18 05:44:03 +00002633 struct bgp_clear_node_queue *cnq = data;
2634 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002635 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002636 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002637 afi_t afi = rn->table->afi;
2638 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002639
Paul Jakma64e580a2006-02-21 01:09:01 +00002640 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002641
Paul Jakma64e580a2006-02-21 01:09:01 +00002642 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002643 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002644 {
2645 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002646 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2647 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002648 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002649 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2650 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002651 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002652 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002653 break;
2654 }
paul200df112005-06-01 11:17:05 +00002655 return WQ_SUCCESS;
2656}
2657
2658static void
paul0fb58d52005-11-14 14:31:49 +00002659bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002660{
Chris Caputo228da422009-07-18 05:44:03 +00002661 struct bgp_clear_node_queue *cnq = data;
2662 struct bgp_node *rn = cnq->rn;
2663 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002664
2665 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002666 bgp_table_unlock (table);
2667 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002668}
2669
2670static void
paul94f2b392005-06-28 12:44:16 +00002671bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002672{
Paul Jakma64e580a2006-02-21 01:09:01 +00002673 struct peer *peer = wq->spec.data;
2674
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002675 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002676 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002677
2678 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002679}
2680
2681static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002682bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002683{
Paul Jakmaa2943652009-07-21 14:02:04 +01002684 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002685
Paul Jakmaa2943652009-07-21 14:02:04 +01002686 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002687#undef CLEAR_QUEUE_NAME_LEN
2688
2689 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002690 {
2691 zlog_err ("%s: Failed to allocate work queue", __func__);
2692 exit (1);
2693 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002694 peer->clear_node_queue->spec.hold = 10;
2695 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2696 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2697 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2698 peer->clear_node_queue->spec.max_retries = 0;
2699
2700 /* we only 'lock' this peer reference when the queue is actually active */
2701 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002702}
2703
paul718e3742002-12-13 20:15:29 +00002704static void
2705bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002706 struct bgp_table *table, struct peer *rsclient,
2707 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002708{
2709 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002710
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002711
paul718e3742002-12-13 20:15:29 +00002712 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002713 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002714
hasso6cf159b2005-03-21 10:28:14 +00002715 /* If still no table => afi/safi isn't configured at all or smth. */
2716 if (! table)
2717 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002718
2719 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2720 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002721 struct bgp_info *ri;
2722 struct bgp_adj_in *ain;
2723 struct bgp_adj_out *aout;
2724
Paul Jakma65ca75e2006-05-04 08:08:15 +00002725 if (rn->info == NULL)
2726 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002727
2728 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2729 * queued for every clearing peer, regardless of whether it is
2730 * relevant to the peer at hand.
2731 *
2732 * Overview: There are 3 different indices which need to be
2733 * scrubbed, potentially, when a peer is removed:
2734 *
2735 * 1 peer's routes visible via the RIB (ie accepted routes)
2736 * 2 peer's routes visible by the (optional) peer's adj-in index
2737 * 3 other routes visible by the peer's adj-out index
2738 *
2739 * 3 there is no hurry in scrubbing, once the struct peer is
2740 * removed from bgp->peer, we could just GC such deleted peer's
2741 * adj-outs at our leisure.
2742 *
2743 * 1 and 2 must be 'scrubbed' in some way, at least made
2744 * invisible via RIB index before peer session is allowed to be
2745 * brought back up. So one needs to know when such a 'search' is
2746 * complete.
2747 *
2748 * Ideally:
2749 *
2750 * - there'd be a single global queue or a single RIB walker
2751 * - rather than tracking which route_nodes still need to be
2752 * examined on a peer basis, we'd track which peers still
2753 * aren't cleared
2754 *
2755 * Given that our per-peer prefix-counts now should be reliable,
2756 * this may actually be achievable. It doesn't seem to be a huge
2757 * problem at this time,
2758 */
2759 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002760 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002761 {
Chris Caputo228da422009-07-18 05:44:03 +00002762 struct bgp_clear_node_queue *cnq;
2763
2764 /* both unlocked in bgp_clear_node_queue_del */
2765 bgp_table_lock (rn->table);
2766 bgp_lock_node (rn);
2767 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2768 sizeof (struct bgp_clear_node_queue));
2769 cnq->rn = rn;
2770 cnq->purpose = purpose;
2771 work_queue_add (peer->clear_node_queue, cnq);
2772 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002773 }
2774
2775 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002776 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002777 {
2778 bgp_adj_in_remove (rn, ain);
2779 bgp_unlock_node (rn);
2780 break;
2781 }
2782 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002783 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002784 {
2785 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2786 bgp_unlock_node (rn);
2787 break;
2788 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002789 }
2790 return;
2791}
2792
2793void
Chris Caputo228da422009-07-18 05:44:03 +00002794bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2795 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002796{
2797 struct bgp_node *rn;
2798 struct bgp_table *table;
2799 struct peer *rsclient;
2800 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002801
Paul Jakma64e580a2006-02-21 01:09:01 +00002802 if (peer->clear_node_queue == NULL)
2803 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002804
Paul Jakmaca058a32006-09-14 02:58:49 +00002805 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2806 * Idle until it receives a Clearing_Completed event. This protects
2807 * against peers which flap faster than we can we clear, which could
2808 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002809 *
2810 * a) race with routes from the new session being installed before
2811 * clear_route_node visits the node (to delete the route of that
2812 * peer)
2813 * b) resource exhaustion, clear_route_node likely leads to an entry
2814 * on the process_main queue. Fast-flapping could cause that queue
2815 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002816 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002817 if (!peer->clear_node_queue->thread)
2818 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002819
Chris Caputo228da422009-07-18 05:44:03 +00002820 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002821 {
Chris Caputo228da422009-07-18 05:44:03 +00002822 case BGP_CLEAR_ROUTE_NORMAL:
2823 if (safi != SAFI_MPLS_VPN)
2824 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2825 else
2826 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2827 rn = bgp_route_next (rn))
2828 if ((table = rn->info) != NULL)
2829 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2830
2831 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2832 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2833 PEER_FLAG_RSERVER_CLIENT))
2834 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2835 break;
2836
2837 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2838 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2839 break;
2840
2841 default:
2842 assert (0);
2843 break;
paulfee0f4c2004-09-13 05:12:46 +00002844 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002845
Paul Jakmaca058a32006-09-14 02:58:49 +00002846 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002847 * completion function won't be run by workqueue code - call it here.
2848 * XXX: Actually, this assumption doesn't hold, see
2849 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002850 *
2851 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002852 * really needed if peer state is Established - peers in
2853 * pre-Established states shouldn't have any route-update state
2854 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002855 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002856 * We still can get here in pre-Established though, through
2857 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2858 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002859 *
2860 * At some future point, this check could be move to the top of the
2861 * function, and do a quick early-return when state is
2862 * pre-Established, avoiding above list and table scans. Once we're
2863 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002864 */
2865 if (!peer->clear_node_queue->thread)
2866 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002867}
2868
2869void
2870bgp_clear_route_all (struct peer *peer)
2871{
2872 afi_t afi;
2873 safi_t safi;
2874
2875 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2876 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002877 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002878}
2879
2880void
2881bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2882{
2883 struct bgp_table *table;
2884 struct bgp_node *rn;
2885 struct bgp_adj_in *ain;
2886
2887 table = peer->bgp->rib[afi][safi];
2888
2889 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2890 for (ain = rn->adj_in; ain ; ain = ain->next)
2891 if (ain->peer == peer)
2892 {
2893 bgp_adj_in_remove (rn, ain);
2894 bgp_unlock_node (rn);
2895 break;
2896 }
2897}
hasso93406d82005-02-02 14:40:33 +00002898
2899void
2900bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2901{
2902 struct bgp_node *rn;
2903 struct bgp_info *ri;
2904 struct bgp_table *table;
2905
2906 table = peer->bgp->rib[afi][safi];
2907
2908 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2909 {
2910 for (ri = rn->info; ri; ri = ri->next)
2911 if (ri->peer == peer)
2912 {
2913 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2914 bgp_rib_remove (rn, ri, peer, afi, safi);
2915 break;
2916 }
2917 }
2918}
paul718e3742002-12-13 20:15:29 +00002919
2920/* Delete all kernel routes. */
2921void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002922bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002923{
2924 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002925 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002926 struct bgp_node *rn;
2927 struct bgp_table *table;
2928 struct bgp_info *ri;
2929
paul1eb8ef22005-04-07 07:30:20 +00002930 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002931 {
2932 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2933
2934 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2935 for (ri = rn->info; ri; ri = ri->next)
2936 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2937 && ri->type == ZEBRA_ROUTE_BGP
2938 && ri->sub_type == BGP_ROUTE_NORMAL)
2939 bgp_zebra_withdraw (&rn->p, ri);
2940
2941 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2942
2943 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2944 for (ri = rn->info; ri; ri = ri->next)
2945 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2946 && ri->type == ZEBRA_ROUTE_BGP
2947 && ri->sub_type == BGP_ROUTE_NORMAL)
2948 bgp_zebra_withdraw (&rn->p, ri);
2949 }
2950}
2951
2952void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002953bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002954{
2955 vty_reset ();
2956 bgp_zclient_reset ();
2957 access_list_reset ();
2958 prefix_list_reset ();
2959}
2960
2961/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2962 value. */
2963int
2964bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2965{
2966 u_char *pnt;
2967 u_char *lim;
2968 struct prefix p;
2969 int psize;
2970 int ret;
2971
2972 /* Check peer status. */
2973 if (peer->status != Established)
2974 return 0;
2975
2976 pnt = packet->nlri;
2977 lim = pnt + packet->length;
2978
2979 for (; pnt < lim; pnt += psize)
2980 {
2981 /* Clear prefix structure. */
2982 memset (&p, 0, sizeof (struct prefix));
2983
2984 /* Fetch prefix length. */
2985 p.prefixlen = *pnt++;
2986 p.family = afi2family (packet->afi);
2987
2988 /* Already checked in nlri_sanity_check(). We do double check
2989 here. */
2990 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2991 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2992 return -1;
2993
2994 /* Packet size overflow check. */
2995 psize = PSIZE (p.prefixlen);
2996
2997 /* When packet overflow occur return immediately. */
2998 if (pnt + psize > lim)
2999 return -1;
3000
3001 /* Fetch prefix from NLRI packet. */
3002 memcpy (&p.u.prefix, pnt, psize);
3003
3004 /* Check address. */
3005 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3006 {
3007 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3008 {
paulf5ba3872004-07-09 12:11:31 +00003009 /*
3010 * From draft-ietf-idr-bgp4-22, Section 6.3:
3011 * If a BGP router receives an UPDATE message with a
3012 * semantically incorrect NLRI field, in which a prefix is
3013 * semantically incorrect (eg. an unexpected multicast IP
3014 * address), it should ignore the prefix.
3015 */
paul718e3742002-12-13 20:15:29 +00003016 zlog (peer->log, LOG_ERR,
3017 "IPv4 unicast NLRI is multicast address %s",
3018 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003019
paul718e3742002-12-13 20:15:29 +00003020 return -1;
3021 }
3022 }
3023
3024#ifdef HAVE_IPV6
3025 /* Check address. */
3026 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3027 {
3028 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3029 {
3030 char buf[BUFSIZ];
3031
3032 zlog (peer->log, LOG_WARNING,
3033 "IPv6 link-local NLRI received %s ignore this NLRI",
3034 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3035
3036 continue;
3037 }
3038 }
3039#endif /* HAVE_IPV6 */
3040
3041 /* Normal process. */
3042 if (attr)
3043 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3044 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3045 else
3046 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3047 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3048
3049 /* Address family configuration mismatch or maximum-prefix count
3050 overflow. */
3051 if (ret < 0)
3052 return -1;
3053 }
3054
3055 /* Packet length consistency check. */
3056 if (pnt != lim)
3057 return -1;
3058
3059 return 0;
3060}
3061
3062/* NLRI encode syntax check routine. */
3063int
3064bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3065 bgp_size_t length)
3066{
3067 u_char *end;
3068 u_char prefixlen;
3069 int psize;
3070
3071 end = pnt + length;
3072
3073 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3074 syntactic validity. If the field is syntactically incorrect,
3075 then the Error Subcode is set to Invalid Network Field. */
3076
3077 while (pnt < end)
3078 {
3079 prefixlen = *pnt++;
3080
3081 /* Prefix length check. */
3082 if ((afi == AFI_IP && prefixlen > 32)
3083 || (afi == AFI_IP6 && prefixlen > 128))
3084 {
3085 plog_err (peer->log,
3086 "%s [Error] Update packet error (wrong prefix length %d)",
3087 peer->host, prefixlen);
3088 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3089 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3090 return -1;
3091 }
3092
3093 /* Packet size overflow check. */
3094 psize = PSIZE (prefixlen);
3095
3096 if (pnt + psize > end)
3097 {
3098 plog_err (peer->log,
3099 "%s [Error] Update packet error"
3100 " (prefix data overflow prefix size is %d)",
3101 peer->host, psize);
3102 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3103 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3104 return -1;
3105 }
3106
3107 pnt += psize;
3108 }
3109
3110 /* Packet length consistency check. */
3111 if (pnt != end)
3112 {
3113 plog_err (peer->log,
3114 "%s [Error] Update packet error"
3115 " (prefix length mismatch with total length)",
3116 peer->host);
3117 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3118 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3119 return -1;
3120 }
3121 return 0;
3122}
3123
paul94f2b392005-06-28 12:44:16 +00003124static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003125bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003126{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003127 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003128}
3129
paul94f2b392005-06-28 12:44:16 +00003130static void
paul718e3742002-12-13 20:15:29 +00003131bgp_static_free (struct bgp_static *bgp_static)
3132{
3133 if (bgp_static->rmap.name)
3134 free (bgp_static->rmap.name);
3135 XFREE (MTYPE_BGP_STATIC, bgp_static);
3136}
3137
paul94f2b392005-06-28 12:44:16 +00003138static void
paulfee0f4c2004-09-13 05:12:46 +00003139bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3140 struct prefix *p, afi_t afi, safi_t safi)
3141{
3142 struct bgp_node *rn;
3143 struct bgp_info *ri;
3144
3145 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3146
3147 /* Check selected route and self inserted route. */
3148 for (ri = rn->info; ri; ri = ri->next)
3149 if (ri->peer == bgp->peer_self
3150 && ri->type == ZEBRA_ROUTE_BGP
3151 && ri->sub_type == BGP_ROUTE_STATIC)
3152 break;
3153
3154 /* Withdraw static BGP route from routing table. */
3155 if (ri)
3156 {
paulfee0f4c2004-09-13 05:12:46 +00003157 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003158 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003159 }
3160
3161 /* Unlock bgp_node_lookup. */
3162 bgp_unlock_node (rn);
3163}
3164
paul94f2b392005-06-28 12:44:16 +00003165static void
paulfee0f4c2004-09-13 05:12:46 +00003166bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003167 struct bgp_static *bgp_static,
3168 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003169{
3170 struct bgp_node *rn;
3171 struct bgp_info *ri;
3172 struct bgp_info *new;
3173 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003174 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003175 struct attr attr = {0 };
3176 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003177 struct bgp *bgp;
3178 int ret;
3179 char buf[SU_ADDRSTRLEN];
3180
3181 bgp = rsclient->bgp;
3182
Paul Jakma06e110f2006-05-12 23:29:22 +00003183 assert (bgp_static);
3184 if (!bgp_static)
3185 return;
3186
paulfee0f4c2004-09-13 05:12:46 +00003187 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3188
3189 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003190
3191 attr.nexthop = bgp_static->igpnexthop;
3192 attr.med = bgp_static->igpmetric;
3193 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003194
Paul Jakma41367172007-08-06 15:24:51 +00003195 if (bgp_static->atomic)
3196 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3197
paulfee0f4c2004-09-13 05:12:46 +00003198 /* Apply network route-map for export to this rsclient. */
3199 if (bgp_static->rmap.name)
3200 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003201 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003202 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003203 info.attr = &attr_tmp;
3204
paulfee0f4c2004-09-13 05:12:46 +00003205 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3206 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3207
3208 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3209
3210 rsclient->rmap_type = 0;
3211
3212 if (ret == RMAP_DENYMATCH)
3213 {
3214 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003215 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003216
3217 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003218 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003219 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003220 bgp_attr_extra_free (&attr);
3221
paulfee0f4c2004-09-13 05:12:46 +00003222 return;
3223 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003224 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003225 }
3226 else
3227 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003228
Stephen Hemminger7badc262010-08-05 10:26:31 -07003229 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003230
paulfee0f4c2004-09-13 05:12:46 +00003231 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3232
Paul Jakmafb982c22007-05-04 20:15:47 +00003233 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3234 == RMAP_DENY)
3235 {
paulfee0f4c2004-09-13 05:12:46 +00003236 /* This BGP update is filtered. Log the reason then update BGP entry. */
3237 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003238 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003239 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3240 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3241 p->prefixlen, rsclient->host);
3242
3243 bgp->peer_self->rmap_type = 0;
3244
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003245 bgp_attr_unintern (&attr_new);
3246 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003247 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003248
3249 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3250
3251 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003252 }
paulfee0f4c2004-09-13 05:12:46 +00003253
3254 bgp->peer_self->rmap_type = 0;
3255
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003256 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003257 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003258 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003259
3260 for (ri = rn->info; ri; ri = ri->next)
3261 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3262 && ri->sub_type == BGP_ROUTE_STATIC)
3263 break;
3264
3265 if (ri)
3266 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003267 if (attrhash_cmp (ri->attr, attr_new) &&
3268 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003269 {
3270 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003271 bgp_attr_unintern (&attr_new);
3272 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003274 return;
3275 }
3276 else
3277 {
3278 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003279 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003280
3281 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003282 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3283 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003284 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003285 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003286 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003287
3288 /* Process change. */
3289 bgp_process (bgp, rn, afi, safi);
3290 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003291 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003293 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003294 }
paulfee0f4c2004-09-13 05:12:46 +00003295 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003296
paulfee0f4c2004-09-13 05:12:46 +00003297 /* Make new BGP info. */
3298 new = bgp_info_new ();
3299 new->type = ZEBRA_ROUTE_BGP;
3300 new->sub_type = BGP_ROUTE_STATIC;
3301 new->peer = bgp->peer_self;
3302 SET_FLAG (new->flags, BGP_INFO_VALID);
3303 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003304 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003305
3306 /* Register new BGP information. */
3307 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003308
3309 /* route_node_get lock */
3310 bgp_unlock_node (rn);
3311
paulfee0f4c2004-09-13 05:12:46 +00003312 /* Process change. */
3313 bgp_process (bgp, rn, afi, safi);
3314
3315 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003316 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003317 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003318}
3319
paul94f2b392005-06-28 12:44:16 +00003320static void
paulfee0f4c2004-09-13 05:12:46 +00003321bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003322 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3323{
3324 struct bgp_node *rn;
3325 struct bgp_info *ri;
3326 struct bgp_info *new;
3327 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003328 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003329 struct attr *attr_new;
3330 int ret;
3331
Paul Jakmadd8103a2006-05-12 23:27:30 +00003332 assert (bgp_static);
3333 if (!bgp_static)
3334 return;
3335
paulfee0f4c2004-09-13 05:12:46 +00003336 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003337
3338 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003339
3340 attr.nexthop = bgp_static->igpnexthop;
3341 attr.med = bgp_static->igpmetric;
3342 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003343
Paul Jakma41367172007-08-06 15:24:51 +00003344 if (bgp_static->atomic)
3345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3346
paul718e3742002-12-13 20:15:29 +00003347 /* Apply route-map. */
3348 if (bgp_static->rmap.name)
3349 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003350 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003351 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003352 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003353
paulfee0f4c2004-09-13 05:12:46 +00003354 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3355
paul718e3742002-12-13 20:15:29 +00003356 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003357
paulfee0f4c2004-09-13 05:12:46 +00003358 bgp->peer_self->rmap_type = 0;
3359
paul718e3742002-12-13 20:15:29 +00003360 if (ret == RMAP_DENYMATCH)
3361 {
3362 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003363 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003364
3365 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003366 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003368 bgp_static_withdraw (bgp, p, afi, safi);
3369 return;
3370 }
paul286e1e72003-08-08 00:24:31 +00003371 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003372 }
paul286e1e72003-08-08 00:24:31 +00003373 else
3374 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003375
3376 for (ri = rn->info; ri; ri = ri->next)
3377 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3378 && ri->sub_type == BGP_ROUTE_STATIC)
3379 break;
3380
3381 if (ri)
3382 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003383 if (attrhash_cmp (ri->attr, attr_new) &&
3384 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003385 {
3386 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003387 bgp_attr_unintern (&attr_new);
3388 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003389 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003390 return;
3391 }
3392 else
3393 {
3394 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003395 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003396
3397 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003398 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3399 bgp_info_restore(rn, ri);
3400 else
3401 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003402 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003403 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003404 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003405
3406 /* Process change. */
3407 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3408 bgp_process (bgp, rn, afi, safi);
3409 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003410 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003411 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003412 return;
3413 }
3414 }
3415
3416 /* Make new BGP info. */
3417 new = bgp_info_new ();
3418 new->type = ZEBRA_ROUTE_BGP;
3419 new->sub_type = BGP_ROUTE_STATIC;
3420 new->peer = bgp->peer_self;
3421 SET_FLAG (new->flags, BGP_INFO_VALID);
3422 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003423 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003424
3425 /* Aggregate address increment. */
3426 bgp_aggregate_increment (bgp, p, new, afi, safi);
3427
3428 /* Register new BGP information. */
3429 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003430
3431 /* route_node_get lock */
3432 bgp_unlock_node (rn);
3433
paul718e3742002-12-13 20:15:29 +00003434 /* Process change. */
3435 bgp_process (bgp, rn, afi, safi);
3436
3437 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003438 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003439 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003440}
3441
3442void
paulfee0f4c2004-09-13 05:12:46 +00003443bgp_static_update (struct bgp *bgp, struct prefix *p,
3444 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3445{
3446 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003447 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003448
3449 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3450
paul1eb8ef22005-04-07 07:30:20 +00003451 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003452 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003453 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3454 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003455 }
3456}
3457
paul94f2b392005-06-28 12:44:16 +00003458static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003459bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3460 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003461{
3462 struct bgp_node *rn;
3463 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003464
paulfee0f4c2004-09-13 05:12:46 +00003465 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003466
3467 /* Make new BGP info. */
3468 new = bgp_info_new ();
3469 new->type = ZEBRA_ROUTE_BGP;
3470 new->sub_type = BGP_ROUTE_STATIC;
3471 new->peer = bgp->peer_self;
3472 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3473 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003474 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003475 new->extra = bgp_info_extra_new();
3476 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003477
3478 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003479 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003480
3481 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003482 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003483
paul200df112005-06-01 11:17:05 +00003484 /* route_node_get lock */
3485 bgp_unlock_node (rn);
3486
paul718e3742002-12-13 20:15:29 +00003487 /* Process change. */
3488 bgp_process (bgp, rn, afi, safi);
3489}
3490
3491void
3492bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3493 safi_t safi)
3494{
3495 struct bgp_node *rn;
3496 struct bgp_info *ri;
3497
paulfee0f4c2004-09-13 05:12:46 +00003498 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003499
3500 /* Check selected route and self inserted route. */
3501 for (ri = rn->info; ri; ri = ri->next)
3502 if (ri->peer == bgp->peer_self
3503 && ri->type == ZEBRA_ROUTE_BGP
3504 && ri->sub_type == BGP_ROUTE_STATIC)
3505 break;
3506
3507 /* Withdraw static BGP route from routing table. */
3508 if (ri)
3509 {
3510 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003511 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003512 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003513 }
3514
3515 /* Unlock bgp_node_lookup. */
3516 bgp_unlock_node (rn);
3517}
3518
3519void
paulfee0f4c2004-09-13 05:12:46 +00003520bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3521{
3522 struct bgp_static *bgp_static;
3523 struct bgp *bgp;
3524 struct bgp_node *rn;
3525 struct prefix *p;
3526
3527 bgp = rsclient->bgp;
3528
3529 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3530 if ((bgp_static = rn->info) != NULL)
3531 {
3532 p = &rn->p;
3533
3534 bgp_static_update_rsclient (rsclient, p, bgp_static,
3535 afi, safi);
3536 }
3537}
3538
paul94f2b392005-06-28 12:44:16 +00003539static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003540bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3541 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003542{
3543 struct bgp_node *rn;
3544 struct bgp_info *ri;
3545
paulfee0f4c2004-09-13 05:12:46 +00003546 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003547
3548 /* Check selected route and self inserted route. */
3549 for (ri = rn->info; ri; ri = ri->next)
3550 if (ri->peer == bgp->peer_self
3551 && ri->type == ZEBRA_ROUTE_BGP
3552 && ri->sub_type == BGP_ROUTE_STATIC)
3553 break;
3554
3555 /* Withdraw static BGP route from routing table. */
3556 if (ri)
3557 {
3558 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003559 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003560 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003561 }
3562
3563 /* Unlock bgp_node_lookup. */
3564 bgp_unlock_node (rn);
3565}
3566
3567/* Configure static BGP network. When user don't run zebra, static
3568 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003569static int
paulfd79ac92004-10-13 05:06:08 +00003570bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003571 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003572{
3573 int ret;
3574 struct prefix p;
3575 struct bgp_static *bgp_static;
3576 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003577 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003578
3579 /* Convert IP prefix string to struct prefix. */
3580 ret = str2prefix (ip_str, &p);
3581 if (! ret)
3582 {
3583 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3584 return CMD_WARNING;
3585 }
3586#ifdef HAVE_IPV6
3587 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3588 {
3589 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3590 VTY_NEWLINE);
3591 return CMD_WARNING;
3592 }
3593#endif /* HAVE_IPV6 */
3594
3595 apply_mask (&p);
3596
3597 /* Set BGP static route configuration. */
3598 rn = bgp_node_get (bgp->route[afi][safi], &p);
3599
3600 if (rn->info)
3601 {
3602 /* Configuration change. */
3603 bgp_static = rn->info;
3604
3605 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003606 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3607 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003608
paul718e3742002-12-13 20:15:29 +00003609 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003610
paul718e3742002-12-13 20:15:29 +00003611 if (rmap)
3612 {
3613 if (bgp_static->rmap.name)
3614 free (bgp_static->rmap.name);
3615 bgp_static->rmap.name = strdup (rmap);
3616 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3617 }
3618 else
3619 {
3620 if (bgp_static->rmap.name)
3621 free (bgp_static->rmap.name);
3622 bgp_static->rmap.name = NULL;
3623 bgp_static->rmap.map = NULL;
3624 bgp_static->valid = 0;
3625 }
3626 bgp_unlock_node (rn);
3627 }
3628 else
3629 {
3630 /* New configuration. */
3631 bgp_static = bgp_static_new ();
3632 bgp_static->backdoor = backdoor;
3633 bgp_static->valid = 0;
3634 bgp_static->igpmetric = 0;
3635 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003636
paul718e3742002-12-13 20:15:29 +00003637 if (rmap)
3638 {
3639 if (bgp_static->rmap.name)
3640 free (bgp_static->rmap.name);
3641 bgp_static->rmap.name = strdup (rmap);
3642 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3643 }
3644 rn->info = bgp_static;
3645 }
3646
3647 /* If BGP scan is not enabled, we should install this route here. */
3648 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3649 {
3650 bgp_static->valid = 1;
3651
3652 if (need_update)
3653 bgp_static_withdraw (bgp, &p, afi, safi);
3654
3655 if (! bgp_static->backdoor)
3656 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3657 }
3658
3659 return CMD_SUCCESS;
3660}
3661
3662/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003663static int
paulfd79ac92004-10-13 05:06:08 +00003664bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003665 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003666{
3667 int ret;
3668 struct prefix p;
3669 struct bgp_static *bgp_static;
3670 struct bgp_node *rn;
3671
3672 /* Convert IP prefix string to struct prefix. */
3673 ret = str2prefix (ip_str, &p);
3674 if (! ret)
3675 {
3676 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3677 return CMD_WARNING;
3678 }
3679#ifdef HAVE_IPV6
3680 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3681 {
3682 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3683 VTY_NEWLINE);
3684 return CMD_WARNING;
3685 }
3686#endif /* HAVE_IPV6 */
3687
3688 apply_mask (&p);
3689
3690 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3691 if (! rn)
3692 {
3693 vty_out (vty, "%% Can't find specified static route configuration.%s",
3694 VTY_NEWLINE);
3695 return CMD_WARNING;
3696 }
3697
3698 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003699
paul718e3742002-12-13 20:15:29 +00003700 /* Update BGP RIB. */
3701 if (! bgp_static->backdoor)
3702 bgp_static_withdraw (bgp, &p, afi, safi);
3703
3704 /* Clear configuration. */
3705 bgp_static_free (bgp_static);
3706 rn->info = NULL;
3707 bgp_unlock_node (rn);
3708 bgp_unlock_node (rn);
3709
3710 return CMD_SUCCESS;
3711}
3712
3713/* Called from bgp_delete(). Delete all static routes from the BGP
3714 instance. */
3715void
3716bgp_static_delete (struct bgp *bgp)
3717{
3718 afi_t afi;
3719 safi_t safi;
3720 struct bgp_node *rn;
3721 struct bgp_node *rm;
3722 struct bgp_table *table;
3723 struct bgp_static *bgp_static;
3724
3725 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3726 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3727 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3728 if (rn->info != NULL)
3729 {
3730 if (safi == SAFI_MPLS_VPN)
3731 {
3732 table = rn->info;
3733
3734 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3735 {
3736 bgp_static = rn->info;
3737 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3738 AFI_IP, SAFI_MPLS_VPN,
3739 (struct prefix_rd *)&rn->p,
3740 bgp_static->tag);
3741 bgp_static_free (bgp_static);
3742 rn->info = NULL;
3743 bgp_unlock_node (rn);
3744 }
3745 }
3746 else
3747 {
3748 bgp_static = rn->info;
3749 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3750 bgp_static_free (bgp_static);
3751 rn->info = NULL;
3752 bgp_unlock_node (rn);
3753 }
3754 }
3755}
3756
3757int
paulfd79ac92004-10-13 05:06:08 +00003758bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3759 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003760{
3761 int ret;
3762 struct prefix p;
3763 struct prefix_rd prd;
3764 struct bgp *bgp;
3765 struct bgp_node *prn;
3766 struct bgp_node *rn;
3767 struct bgp_table *table;
3768 struct bgp_static *bgp_static;
3769 u_char tag[3];
3770
3771 bgp = vty->index;
3772
3773 ret = str2prefix (ip_str, &p);
3774 if (! ret)
3775 {
3776 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3777 return CMD_WARNING;
3778 }
3779 apply_mask (&p);
3780
3781 ret = str2prefix_rd (rd_str, &prd);
3782 if (! ret)
3783 {
3784 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3785 return CMD_WARNING;
3786 }
3787
3788 ret = str2tag (tag_str, tag);
3789 if (! ret)
3790 {
3791 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3792 return CMD_WARNING;
3793 }
3794
3795 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3796 (struct prefix *)&prd);
3797 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003798 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003799 else
3800 bgp_unlock_node (prn);
3801 table = prn->info;
3802
3803 rn = bgp_node_get (table, &p);
3804
3805 if (rn->info)
3806 {
3807 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3808 bgp_unlock_node (rn);
3809 }
3810 else
3811 {
3812 /* New configuration. */
3813 bgp_static = bgp_static_new ();
3814 bgp_static->valid = 1;
3815 memcpy (bgp_static->tag, tag, 3);
3816 rn->info = bgp_static;
3817
3818 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3819 }
3820
3821 return CMD_SUCCESS;
3822}
3823
3824/* Configure static BGP network. */
3825int
paulfd79ac92004-10-13 05:06:08 +00003826bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3827 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003828{
3829 int ret;
3830 struct bgp *bgp;
3831 struct prefix p;
3832 struct prefix_rd prd;
3833 struct bgp_node *prn;
3834 struct bgp_node *rn;
3835 struct bgp_table *table;
3836 struct bgp_static *bgp_static;
3837 u_char tag[3];
3838
3839 bgp = vty->index;
3840
3841 /* Convert IP prefix string to struct prefix. */
3842 ret = str2prefix (ip_str, &p);
3843 if (! ret)
3844 {
3845 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3846 return CMD_WARNING;
3847 }
3848 apply_mask (&p);
3849
3850 ret = str2prefix_rd (rd_str, &prd);
3851 if (! ret)
3852 {
3853 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856
3857 ret = str2tag (tag_str, tag);
3858 if (! ret)
3859 {
3860 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863
3864 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3865 (struct prefix *)&prd);
3866 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003867 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003868 else
3869 bgp_unlock_node (prn);
3870 table = prn->info;
3871
3872 rn = bgp_node_lookup (table, &p);
3873
3874 if (rn)
3875 {
3876 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3877
3878 bgp_static = rn->info;
3879 bgp_static_free (bgp_static);
3880 rn->info = NULL;
3881 bgp_unlock_node (rn);
3882 bgp_unlock_node (rn);
3883 }
3884 else
3885 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3886
3887 return CMD_SUCCESS;
3888}
3889
3890DEFUN (bgp_network,
3891 bgp_network_cmd,
3892 "network A.B.C.D/M",
3893 "Specify a network to announce via BGP\n"
3894 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3895{
3896 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003897 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003898}
3899
3900DEFUN (bgp_network_route_map,
3901 bgp_network_route_map_cmd,
3902 "network A.B.C.D/M route-map WORD",
3903 "Specify a network to announce via BGP\n"
3904 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3905 "Route-map to modify the attributes\n"
3906 "Name of the route map\n")
3907{
3908 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003909 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003910}
3911
3912DEFUN (bgp_network_backdoor,
3913 bgp_network_backdoor_cmd,
3914 "network A.B.C.D/M backdoor",
3915 "Specify a network to announce via BGP\n"
3916 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3917 "Specify a BGP backdoor route\n")
3918{
Paul Jakma41367172007-08-06 15:24:51 +00003919 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003920 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003921}
3922
3923DEFUN (bgp_network_mask,
3924 bgp_network_mask_cmd,
3925 "network A.B.C.D mask A.B.C.D",
3926 "Specify a network to announce via BGP\n"
3927 "Network number\n"
3928 "Network mask\n"
3929 "Network mask\n")
3930{
3931 int ret;
3932 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003933
paul718e3742002-12-13 20:15:29 +00003934 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3935 if (! ret)
3936 {
3937 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3939 }
3940
3941 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003942 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003943}
3944
3945DEFUN (bgp_network_mask_route_map,
3946 bgp_network_mask_route_map_cmd,
3947 "network A.B.C.D mask A.B.C.D route-map WORD",
3948 "Specify a network to announce via BGP\n"
3949 "Network number\n"
3950 "Network mask\n"
3951 "Network mask\n"
3952 "Route-map to modify the attributes\n"
3953 "Name of the route map\n")
3954{
3955 int ret;
3956 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003957
paul718e3742002-12-13 20:15:29 +00003958 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3959 if (! ret)
3960 {
3961 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3962 return CMD_WARNING;
3963 }
3964
3965 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003966 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00003967}
3968
3969DEFUN (bgp_network_mask_backdoor,
3970 bgp_network_mask_backdoor_cmd,
3971 "network A.B.C.D mask A.B.C.D backdoor",
3972 "Specify a network to announce via BGP\n"
3973 "Network number\n"
3974 "Network mask\n"
3975 "Network mask\n"
3976 "Specify a BGP backdoor route\n")
3977{
3978 int ret;
3979 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003980
paul718e3742002-12-13 20:15:29 +00003981 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3982 if (! ret)
3983 {
3984 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3985 return CMD_WARNING;
3986 }
3987
Paul Jakma41367172007-08-06 15:24:51 +00003988 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003989 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003990}
3991
3992DEFUN (bgp_network_mask_natural,
3993 bgp_network_mask_natural_cmd,
3994 "network A.B.C.D",
3995 "Specify a network to announce via BGP\n"
3996 "Network number\n")
3997{
3998 int ret;
3999 char prefix_str[BUFSIZ];
4000
4001 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4002 if (! ret)
4003 {
4004 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4005 return CMD_WARNING;
4006 }
4007
4008 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004009 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004010}
4011
4012DEFUN (bgp_network_mask_natural_route_map,
4013 bgp_network_mask_natural_route_map_cmd,
4014 "network A.B.C.D route-map WORD",
4015 "Specify a network to announce via BGP\n"
4016 "Network number\n"
4017 "Route-map to modify the attributes\n"
4018 "Name of the route map\n")
4019{
4020 int ret;
4021 char prefix_str[BUFSIZ];
4022
4023 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4024 if (! ret)
4025 {
4026 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4027 return CMD_WARNING;
4028 }
4029
4030 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004031 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004032}
4033
4034DEFUN (bgp_network_mask_natural_backdoor,
4035 bgp_network_mask_natural_backdoor_cmd,
4036 "network A.B.C.D backdoor",
4037 "Specify a network to announce via BGP\n"
4038 "Network number\n"
4039 "Specify a BGP backdoor route\n")
4040{
4041 int ret;
4042 char prefix_str[BUFSIZ];
4043
4044 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4045 if (! ret)
4046 {
4047 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4048 return CMD_WARNING;
4049 }
4050
Paul Jakma41367172007-08-06 15:24:51 +00004051 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004052 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004053}
4054
4055DEFUN (no_bgp_network,
4056 no_bgp_network_cmd,
4057 "no network A.B.C.D/M",
4058 NO_STR
4059 "Specify a network to announce via BGP\n"
4060 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4061{
4062 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4063 bgp_node_safi (vty));
4064}
4065
4066ALIAS (no_bgp_network,
4067 no_bgp_network_route_map_cmd,
4068 "no network A.B.C.D/M route-map WORD",
4069 NO_STR
4070 "Specify a network to announce via BGP\n"
4071 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4072 "Route-map to modify the attributes\n"
4073 "Name of the route map\n")
4074
4075ALIAS (no_bgp_network,
4076 no_bgp_network_backdoor_cmd,
4077 "no network A.B.C.D/M backdoor",
4078 NO_STR
4079 "Specify a network to announce via BGP\n"
4080 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4081 "Specify a BGP backdoor route\n")
4082
4083DEFUN (no_bgp_network_mask,
4084 no_bgp_network_mask_cmd,
4085 "no network A.B.C.D mask A.B.C.D",
4086 NO_STR
4087 "Specify a network to announce via BGP\n"
4088 "Network number\n"
4089 "Network mask\n"
4090 "Network mask\n")
4091{
4092 int ret;
4093 char prefix_str[BUFSIZ];
4094
4095 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4096 if (! ret)
4097 {
4098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4099 return CMD_WARNING;
4100 }
4101
4102 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4103 bgp_node_safi (vty));
4104}
4105
4106ALIAS (no_bgp_network_mask,
4107 no_bgp_network_mask_route_map_cmd,
4108 "no network A.B.C.D mask A.B.C.D route-map WORD",
4109 NO_STR
4110 "Specify a network to announce via BGP\n"
4111 "Network number\n"
4112 "Network mask\n"
4113 "Network mask\n"
4114 "Route-map to modify the attributes\n"
4115 "Name of the route map\n")
4116
4117ALIAS (no_bgp_network_mask,
4118 no_bgp_network_mask_backdoor_cmd,
4119 "no network A.B.C.D mask A.B.C.D backdoor",
4120 NO_STR
4121 "Specify a network to announce via BGP\n"
4122 "Network number\n"
4123 "Network mask\n"
4124 "Network mask\n"
4125 "Specify a BGP backdoor route\n")
4126
4127DEFUN (no_bgp_network_mask_natural,
4128 no_bgp_network_mask_natural_cmd,
4129 "no network A.B.C.D",
4130 NO_STR
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n")
4133{
4134 int ret;
4135 char prefix_str[BUFSIZ];
4136
4137 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4138 if (! ret)
4139 {
4140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4141 return CMD_WARNING;
4142 }
4143
4144 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4145 bgp_node_safi (vty));
4146}
4147
4148ALIAS (no_bgp_network_mask_natural,
4149 no_bgp_network_mask_natural_route_map_cmd,
4150 "no network A.B.C.D route-map WORD",
4151 NO_STR
4152 "Specify a network to announce via BGP\n"
4153 "Network number\n"
4154 "Route-map to modify the attributes\n"
4155 "Name of the route map\n")
4156
4157ALIAS (no_bgp_network_mask_natural,
4158 no_bgp_network_mask_natural_backdoor_cmd,
4159 "no network A.B.C.D backdoor",
4160 NO_STR
4161 "Specify a network to announce via BGP\n"
4162 "Network number\n"
4163 "Specify a BGP backdoor route\n")
4164
4165#ifdef HAVE_IPV6
4166DEFUN (ipv6_bgp_network,
4167 ipv6_bgp_network_cmd,
4168 "network X:X::X:X/M",
4169 "Specify a network to announce via BGP\n"
4170 "IPv6 prefix <network>/<length>\n")
4171{
Paul Jakma41367172007-08-06 15:24:51 +00004172 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004173 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004174}
4175
4176DEFUN (ipv6_bgp_network_route_map,
4177 ipv6_bgp_network_route_map_cmd,
4178 "network X:X::X:X/M route-map WORD",
4179 "Specify a network to announce via BGP\n"
4180 "IPv6 prefix <network>/<length>\n"
4181 "Route-map to modify the attributes\n"
4182 "Name of the route map\n")
4183{
4184 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004185 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004186}
4187
4188DEFUN (no_ipv6_bgp_network,
4189 no_ipv6_bgp_network_cmd,
4190 "no network X:X::X:X/M",
4191 NO_STR
4192 "Specify a network to announce via BGP\n"
4193 "IPv6 prefix <network>/<length>\n")
4194{
4195 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4196}
4197
4198ALIAS (no_ipv6_bgp_network,
4199 no_ipv6_bgp_network_route_map_cmd,
4200 "no network X:X::X:X/M route-map WORD",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "IPv6 prefix <network>/<length>\n"
4204 "Route-map to modify the attributes\n"
4205 "Name of the route map\n")
4206
4207ALIAS (ipv6_bgp_network,
4208 old_ipv6_bgp_network_cmd,
4209 "ipv6 bgp network X:X::X:X/M",
4210 IPV6_STR
4211 BGP_STR
4212 "Specify a network to announce via BGP\n"
4213 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4214
4215ALIAS (no_ipv6_bgp_network,
4216 old_no_ipv6_bgp_network_cmd,
4217 "no ipv6 bgp network X:X::X:X/M",
4218 NO_STR
4219 IPV6_STR
4220 BGP_STR
4221 "Specify a network to announce via BGP\n"
4222 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4223#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004224
4225/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4226ALIAS_DEPRECATED (bgp_network,
4227 bgp_network_ttl_cmd,
4228 "network A.B.C.D/M pathlimit <0-255>",
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4231 "AS-Path hopcount limit attribute\n"
4232 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4233ALIAS_DEPRECATED (bgp_network_backdoor,
4234 bgp_network_backdoor_ttl_cmd,
4235 "network A.B.C.D/M backdoor pathlimit <0-255>",
4236 "Specify a network to announce via BGP\n"
4237 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4238 "Specify a BGP backdoor route\n"
4239 "AS-Path hopcount limit attribute\n"
4240 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4241ALIAS_DEPRECATED (bgp_network_mask,
4242 bgp_network_mask_ttl_cmd,
4243 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Network mask\n"
4247 "Network mask\n"
4248 "AS-Path hopcount limit attribute\n"
4249 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4250ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4251 bgp_network_mask_backdoor_ttl_cmd,
4252 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4253 "Specify a network to announce via BGP\n"
4254 "Network number\n"
4255 "Network mask\n"
4256 "Network mask\n"
4257 "Specify a BGP backdoor route\n"
4258 "AS-Path hopcount limit attribute\n"
4259 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4260ALIAS_DEPRECATED (bgp_network_mask_natural,
4261 bgp_network_mask_natural_ttl_cmd,
4262 "network A.B.C.D pathlimit <0-255>",
4263 "Specify a network to announce via BGP\n"
4264 "Network number\n"
4265 "AS-Path hopcount limit attribute\n"
4266 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4267ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4268 bgp_network_mask_natural_backdoor_ttl_cmd,
4269 "network A.B.C.D backdoor pathlimit (1-255>",
4270 "Specify a network to announce via BGP\n"
4271 "Network number\n"
4272 "Specify a BGP backdoor route\n"
4273 "AS-Path hopcount limit attribute\n"
4274 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4275ALIAS_DEPRECATED (no_bgp_network,
4276 no_bgp_network_ttl_cmd,
4277 "no network A.B.C.D/M pathlimit <0-255>",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4281 "AS-Path hopcount limit attribute\n"
4282 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4283ALIAS_DEPRECATED (no_bgp_network,
4284 no_bgp_network_backdoor_ttl_cmd,
4285 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4286 NO_STR
4287 "Specify a network to announce via BGP\n"
4288 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4289 "Specify a BGP backdoor route\n"
4290 "AS-Path hopcount limit attribute\n"
4291 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4292ALIAS_DEPRECATED (no_bgp_network,
4293 no_bgp_network_mask_ttl_cmd,
4294 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4295 NO_STR
4296 "Specify a network to announce via BGP\n"
4297 "Network number\n"
4298 "Network mask\n"
4299 "Network mask\n"
4300 "AS-Path hopcount limit attribute\n"
4301 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4302ALIAS_DEPRECATED (no_bgp_network_mask,
4303 no_bgp_network_mask_backdoor_ttl_cmd,
4304 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4305 NO_STR
4306 "Specify a network to announce via BGP\n"
4307 "Network number\n"
4308 "Network mask\n"
4309 "Network mask\n"
4310 "Specify a BGP backdoor route\n"
4311 "AS-Path hopcount limit attribute\n"
4312 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4313ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4314 no_bgp_network_mask_natural_ttl_cmd,
4315 "no network A.B.C.D pathlimit <0-255>",
4316 NO_STR
4317 "Specify a network to announce via BGP\n"
4318 "Network number\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4322 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4323 "no network A.B.C.D backdoor pathlimit <0-255>",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "Network number\n"
4327 "Specify a BGP backdoor route\n"
4328 "AS-Path hopcount limit attribute\n"
4329 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004330#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004331ALIAS_DEPRECATED (ipv6_bgp_network,
4332 ipv6_bgp_network_ttl_cmd,
4333 "network X:X::X:X/M pathlimit <0-255>",
4334 "Specify a network to announce via BGP\n"
4335 "IPv6 prefix <network>/<length>\n"
4336 "AS-Path hopcount limit attribute\n"
4337 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4338ALIAS_DEPRECATED (no_ipv6_bgp_network,
4339 no_ipv6_bgp_network_ttl_cmd,
4340 "no network X:X::X:X/M pathlimit <0-255>",
4341 NO_STR
4342 "Specify a network to announce via BGP\n"
4343 "IPv6 prefix <network>/<length>\n"
4344 "AS-Path hopcount limit attribute\n"
4345 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004346#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004347
4348/* Aggreagete address:
4349
4350 advertise-map Set condition to advertise attribute
4351 as-set Generate AS set path information
4352 attribute-map Set attributes of aggregate
4353 route-map Set parameters of aggregate
4354 summary-only Filter more specific routes from updates
4355 suppress-map Conditionally filter more specific routes from updates
4356 <cr>
4357 */
4358struct bgp_aggregate
4359{
4360 /* Summary-only flag. */
4361 u_char summary_only;
4362
4363 /* AS set generation. */
4364 u_char as_set;
4365
4366 /* Route-map for aggregated route. */
4367 struct route_map *map;
4368
4369 /* Suppress-count. */
4370 unsigned long count;
4371
4372 /* SAFI configuration. */
4373 safi_t safi;
4374};
4375
paul94f2b392005-06-28 12:44:16 +00004376static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004377bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004378{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004379 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004380}
4381
paul94f2b392005-06-28 12:44:16 +00004382static void
paul718e3742002-12-13 20:15:29 +00004383bgp_aggregate_free (struct bgp_aggregate *aggregate)
4384{
4385 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4386}
4387
paul94f2b392005-06-28 12:44:16 +00004388static void
paul718e3742002-12-13 20:15:29 +00004389bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4390 afi_t afi, safi_t safi, struct bgp_info *del,
4391 struct bgp_aggregate *aggregate)
4392{
4393 struct bgp_table *table;
4394 struct bgp_node *top;
4395 struct bgp_node *rn;
4396 u_char origin;
4397 struct aspath *aspath = NULL;
4398 struct aspath *asmerge = NULL;
4399 struct community *community = NULL;
4400 struct community *commerge = NULL;
4401 struct in_addr nexthop;
4402 u_int32_t med = 0;
4403 struct bgp_info *ri;
4404 struct bgp_info *new;
4405 int first = 1;
4406 unsigned long match = 0;
4407
4408 /* Record adding route's nexthop and med. */
4409 if (rinew)
4410 {
4411 nexthop = rinew->attr->nexthop;
4412 med = rinew->attr->med;
4413 }
4414
4415 /* ORIGIN attribute: If at least one route among routes that are
4416 aggregated has ORIGIN with the value INCOMPLETE, then the
4417 aggregated route must have the ORIGIN attribute with the value
4418 INCOMPLETE. Otherwise, if at least one route among routes that
4419 are aggregated has ORIGIN with the value EGP, then the aggregated
4420 route must have the origin attribute with the value EGP. In all
4421 other case the value of the ORIGIN attribute of the aggregated
4422 route is INTERNAL. */
4423 origin = BGP_ORIGIN_IGP;
4424
4425 table = bgp->rib[afi][safi];
4426
4427 top = bgp_node_get (table, p);
4428 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4429 if (rn->p.prefixlen > p->prefixlen)
4430 {
4431 match = 0;
4432
4433 for (ri = rn->info; ri; ri = ri->next)
4434 {
4435 if (BGP_INFO_HOLDDOWN (ri))
4436 continue;
4437
4438 if (del && ri == del)
4439 continue;
4440
4441 if (! rinew && first)
4442 {
4443 nexthop = ri->attr->nexthop;
4444 med = ri->attr->med;
4445 first = 0;
4446 }
4447
4448#ifdef AGGREGATE_NEXTHOP_CHECK
4449 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4450 || ri->attr->med != med)
4451 {
4452 if (aspath)
4453 aspath_free (aspath);
4454 if (community)
4455 community_free (community);
4456 bgp_unlock_node (rn);
4457 bgp_unlock_node (top);
4458 return;
4459 }
4460#endif /* AGGREGATE_NEXTHOP_CHECK */
4461
4462 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4463 {
4464 if (aggregate->summary_only)
4465 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004466 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004467 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004468 match++;
4469 }
4470
4471 aggregate->count++;
4472
4473 if (aggregate->as_set)
4474 {
4475 if (origin < ri->attr->origin)
4476 origin = ri->attr->origin;
4477
4478 if (aspath)
4479 {
4480 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4481 aspath_free (aspath);
4482 aspath = asmerge;
4483 }
4484 else
4485 aspath = aspath_dup (ri->attr->aspath);
4486
4487 if (ri->attr->community)
4488 {
4489 if (community)
4490 {
4491 commerge = community_merge (community,
4492 ri->attr->community);
4493 community = community_uniq_sort (commerge);
4494 community_free (commerge);
4495 }
4496 else
4497 community = community_dup (ri->attr->community);
4498 }
4499 }
4500 }
4501 }
4502 if (match)
4503 bgp_process (bgp, rn, afi, safi);
4504 }
4505 bgp_unlock_node (top);
4506
4507 if (rinew)
4508 {
4509 aggregate->count++;
4510
4511 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004512 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004513
4514 if (aggregate->as_set)
4515 {
4516 if (origin < rinew->attr->origin)
4517 origin = rinew->attr->origin;
4518
4519 if (aspath)
4520 {
4521 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4522 aspath_free (aspath);
4523 aspath = asmerge;
4524 }
4525 else
4526 aspath = aspath_dup (rinew->attr->aspath);
4527
4528 if (rinew->attr->community)
4529 {
4530 if (community)
4531 {
4532 commerge = community_merge (community,
4533 rinew->attr->community);
4534 community = community_uniq_sort (commerge);
4535 community_free (commerge);
4536 }
4537 else
4538 community = community_dup (rinew->attr->community);
4539 }
4540 }
4541 }
4542
4543 if (aggregate->count > 0)
4544 {
4545 rn = bgp_node_get (table, p);
4546 new = bgp_info_new ();
4547 new->type = ZEBRA_ROUTE_BGP;
4548 new->sub_type = BGP_ROUTE_AGGREGATE;
4549 new->peer = bgp->peer_self;
4550 SET_FLAG (new->flags, BGP_INFO_VALID);
4551 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004552 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004553
4554 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004555 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004556 bgp_process (bgp, rn, afi, safi);
4557 }
4558 else
4559 {
4560 if (aspath)
4561 aspath_free (aspath);
4562 if (community)
4563 community_free (community);
4564 }
4565}
4566
4567void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4568 struct bgp_aggregate *);
4569
4570void
4571bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4572 struct bgp_info *ri, afi_t afi, safi_t safi)
4573{
4574 struct bgp_node *child;
4575 struct bgp_node *rn;
4576 struct bgp_aggregate *aggregate;
4577
4578 /* MPLS-VPN aggregation is not yet supported. */
4579 if (safi == SAFI_MPLS_VPN)
4580 return;
4581
4582 if (p->prefixlen == 0)
4583 return;
4584
4585 if (BGP_INFO_HOLDDOWN (ri))
4586 return;
4587
4588 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4589
4590 /* Aggregate address configuration check. */
4591 for (rn = child; rn; rn = rn->parent)
4592 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4593 {
4594 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004595 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004596 }
4597 bgp_unlock_node (child);
4598}
4599
4600void
4601bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4602 struct bgp_info *del, afi_t afi, safi_t safi)
4603{
4604 struct bgp_node *child;
4605 struct bgp_node *rn;
4606 struct bgp_aggregate *aggregate;
4607
4608 /* MPLS-VPN aggregation is not yet supported. */
4609 if (safi == SAFI_MPLS_VPN)
4610 return;
4611
4612 if (p->prefixlen == 0)
4613 return;
4614
4615 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4616
4617 /* Aggregate address configuration check. */
4618 for (rn = child; rn; rn = rn->parent)
4619 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4620 {
4621 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004622 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004623 }
4624 bgp_unlock_node (child);
4625}
4626
paul94f2b392005-06-28 12:44:16 +00004627static void
paul718e3742002-12-13 20:15:29 +00004628bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4629 struct bgp_aggregate *aggregate)
4630{
4631 struct bgp_table *table;
4632 struct bgp_node *top;
4633 struct bgp_node *rn;
4634 struct bgp_info *new;
4635 struct bgp_info *ri;
4636 unsigned long match;
4637 u_char origin = BGP_ORIGIN_IGP;
4638 struct aspath *aspath = NULL;
4639 struct aspath *asmerge = NULL;
4640 struct community *community = NULL;
4641 struct community *commerge = NULL;
4642
4643 table = bgp->rib[afi][safi];
4644
4645 /* Sanity check. */
4646 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4647 return;
4648 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4649 return;
4650
4651 /* If routes exists below this node, generate aggregate routes. */
4652 top = bgp_node_get (table, p);
4653 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4654 if (rn->p.prefixlen > p->prefixlen)
4655 {
4656 match = 0;
4657
4658 for (ri = rn->info; ri; ri = ri->next)
4659 {
4660 if (BGP_INFO_HOLDDOWN (ri))
4661 continue;
4662
4663 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4664 {
4665 /* summary-only aggregate route suppress aggregated
4666 route announcement. */
4667 if (aggregate->summary_only)
4668 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004669 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004670 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004671 match++;
4672 }
4673 /* as-set aggregate route generate origin, as path,
4674 community aggregation. */
4675 if (aggregate->as_set)
4676 {
4677 if (origin < ri->attr->origin)
4678 origin = ri->attr->origin;
4679
4680 if (aspath)
4681 {
4682 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4683 aspath_free (aspath);
4684 aspath = asmerge;
4685 }
4686 else
4687 aspath = aspath_dup (ri->attr->aspath);
4688
4689 if (ri->attr->community)
4690 {
4691 if (community)
4692 {
4693 commerge = community_merge (community,
4694 ri->attr->community);
4695 community = community_uniq_sort (commerge);
4696 community_free (commerge);
4697 }
4698 else
4699 community = community_dup (ri->attr->community);
4700 }
4701 }
4702 aggregate->count++;
4703 }
4704 }
4705
4706 /* If this node is suppressed, process the change. */
4707 if (match)
4708 bgp_process (bgp, rn, afi, safi);
4709 }
4710 bgp_unlock_node (top);
4711
4712 /* Add aggregate route to BGP table. */
4713 if (aggregate->count)
4714 {
4715 rn = bgp_node_get (table, p);
4716
4717 new = bgp_info_new ();
4718 new->type = ZEBRA_ROUTE_BGP;
4719 new->sub_type = BGP_ROUTE_AGGREGATE;
4720 new->peer = bgp->peer_self;
4721 SET_FLAG (new->flags, BGP_INFO_VALID);
4722 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004723 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004724
4725 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004726 bgp_unlock_node (rn);
4727
paul718e3742002-12-13 20:15:29 +00004728 /* Process change. */
4729 bgp_process (bgp, rn, afi, safi);
4730 }
4731}
4732
4733void
4734bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4735 safi_t safi, struct bgp_aggregate *aggregate)
4736{
4737 struct bgp_table *table;
4738 struct bgp_node *top;
4739 struct bgp_node *rn;
4740 struct bgp_info *ri;
4741 unsigned long match;
4742
4743 table = bgp->rib[afi][safi];
4744
4745 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4746 return;
4747 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4748 return;
4749
4750 /* If routes exists below this node, generate aggregate routes. */
4751 top = bgp_node_get (table, p);
4752 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4753 if (rn->p.prefixlen > p->prefixlen)
4754 {
4755 match = 0;
4756
4757 for (ri = rn->info; ri; ri = ri->next)
4758 {
4759 if (BGP_INFO_HOLDDOWN (ri))
4760 continue;
4761
4762 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4763 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004764 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004765 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004766 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004767
Paul Jakmafb982c22007-05-04 20:15:47 +00004768 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004769 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004770 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004771 match++;
4772 }
4773 }
4774 aggregate->count--;
4775 }
4776 }
4777
Paul Jakmafb982c22007-05-04 20:15:47 +00004778 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004779 if (match)
4780 bgp_process (bgp, rn, afi, safi);
4781 }
4782 bgp_unlock_node (top);
4783
4784 /* Delete aggregate route from BGP table. */
4785 rn = bgp_node_get (table, p);
4786
4787 for (ri = rn->info; ri; ri = ri->next)
4788 if (ri->peer == bgp->peer_self
4789 && ri->type == ZEBRA_ROUTE_BGP
4790 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4791 break;
4792
4793 /* Withdraw static BGP route from routing table. */
4794 if (ri)
4795 {
paul718e3742002-12-13 20:15:29 +00004796 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004797 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004798 }
4799
4800 /* Unlock bgp_node_lookup. */
4801 bgp_unlock_node (rn);
4802}
4803
4804/* Aggregate route attribute. */
4805#define AGGREGATE_SUMMARY_ONLY 1
4806#define AGGREGATE_AS_SET 1
4807
paul94f2b392005-06-28 12:44:16 +00004808static int
Robert Baysf6269b42010-08-05 10:26:28 -07004809bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4810 afi_t afi, safi_t safi)
4811{
4812 int ret;
4813 struct prefix p;
4814 struct bgp_node *rn;
4815 struct bgp *bgp;
4816 struct bgp_aggregate *aggregate;
4817
4818 /* Convert string to prefix structure. */
4819 ret = str2prefix (prefix_str, &p);
4820 if (!ret)
4821 {
4822 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4823 return CMD_WARNING;
4824 }
4825 apply_mask (&p);
4826
4827 /* Get BGP structure. */
4828 bgp = vty->index;
4829
4830 /* Old configuration check. */
4831 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4832 if (! rn)
4833 {
4834 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4835 VTY_NEWLINE);
4836 return CMD_WARNING;
4837 }
4838
4839 aggregate = rn->info;
4840 if (aggregate->safi & SAFI_UNICAST)
4841 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4842 if (aggregate->safi & SAFI_MULTICAST)
4843 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4844
4845 /* Unlock aggregate address configuration. */
4846 rn->info = NULL;
4847 bgp_aggregate_free (aggregate);
4848 bgp_unlock_node (rn);
4849 bgp_unlock_node (rn);
4850
4851 return CMD_SUCCESS;
4852}
4853
4854static int
4855bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004856 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004857 u_char summary_only, u_char as_set)
4858{
4859 int ret;
4860 struct prefix p;
4861 struct bgp_node *rn;
4862 struct bgp *bgp;
4863 struct bgp_aggregate *aggregate;
4864
4865 /* Convert string to prefix structure. */
4866 ret = str2prefix (prefix_str, &p);
4867 if (!ret)
4868 {
4869 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4870 return CMD_WARNING;
4871 }
4872 apply_mask (&p);
4873
4874 /* Get BGP structure. */
4875 bgp = vty->index;
4876
4877 /* Old configuration check. */
4878 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4879
4880 if (rn->info)
4881 {
4882 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004883 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004884 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4885 if (ret)
4886 {
Robert Bays368473f2010-08-05 10:26:29 -07004887 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4888 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004889 return CMD_WARNING;
4890 }
paul718e3742002-12-13 20:15:29 +00004891 }
4892
4893 /* Make aggregate address structure. */
4894 aggregate = bgp_aggregate_new ();
4895 aggregate->summary_only = summary_only;
4896 aggregate->as_set = as_set;
4897 aggregate->safi = safi;
4898 rn->info = aggregate;
4899
4900 /* Aggregate address insert into BGP routing table. */
4901 if (safi & SAFI_UNICAST)
4902 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4903 if (safi & SAFI_MULTICAST)
4904 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4905
4906 return CMD_SUCCESS;
4907}
4908
paul718e3742002-12-13 20:15:29 +00004909DEFUN (aggregate_address,
4910 aggregate_address_cmd,
4911 "aggregate-address A.B.C.D/M",
4912 "Configure BGP aggregate entries\n"
4913 "Aggregate prefix\n")
4914{
4915 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4916}
4917
4918DEFUN (aggregate_address_mask,
4919 aggregate_address_mask_cmd,
4920 "aggregate-address A.B.C.D A.B.C.D",
4921 "Configure BGP aggregate entries\n"
4922 "Aggregate address\n"
4923 "Aggregate mask\n")
4924{
4925 int ret;
4926 char prefix_str[BUFSIZ];
4927
4928 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4929
4930 if (! ret)
4931 {
4932 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4933 return CMD_WARNING;
4934 }
4935
4936 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4937 0, 0);
4938}
4939
4940DEFUN (aggregate_address_summary_only,
4941 aggregate_address_summary_only_cmd,
4942 "aggregate-address A.B.C.D/M summary-only",
4943 "Configure BGP aggregate entries\n"
4944 "Aggregate prefix\n"
4945 "Filter more specific routes from updates\n")
4946{
4947 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4948 AGGREGATE_SUMMARY_ONLY, 0);
4949}
4950
4951DEFUN (aggregate_address_mask_summary_only,
4952 aggregate_address_mask_summary_only_cmd,
4953 "aggregate-address A.B.C.D A.B.C.D summary-only",
4954 "Configure BGP aggregate entries\n"
4955 "Aggregate address\n"
4956 "Aggregate mask\n"
4957 "Filter more specific routes from updates\n")
4958{
4959 int ret;
4960 char prefix_str[BUFSIZ];
4961
4962 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4963
4964 if (! ret)
4965 {
4966 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4967 return CMD_WARNING;
4968 }
4969
4970 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4971 AGGREGATE_SUMMARY_ONLY, 0);
4972}
4973
4974DEFUN (aggregate_address_as_set,
4975 aggregate_address_as_set_cmd,
4976 "aggregate-address A.B.C.D/M as-set",
4977 "Configure BGP aggregate entries\n"
4978 "Aggregate prefix\n"
4979 "Generate AS set path information\n")
4980{
4981 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4982 0, AGGREGATE_AS_SET);
4983}
4984
4985DEFUN (aggregate_address_mask_as_set,
4986 aggregate_address_mask_as_set_cmd,
4987 "aggregate-address A.B.C.D A.B.C.D as-set",
4988 "Configure BGP aggregate entries\n"
4989 "Aggregate address\n"
4990 "Aggregate mask\n"
4991 "Generate AS set path information\n")
4992{
4993 int ret;
4994 char prefix_str[BUFSIZ];
4995
4996 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4997
4998 if (! ret)
4999 {
5000 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5001 return CMD_WARNING;
5002 }
5003
5004 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5005 0, AGGREGATE_AS_SET);
5006}
5007
5008
5009DEFUN (aggregate_address_as_set_summary,
5010 aggregate_address_as_set_summary_cmd,
5011 "aggregate-address A.B.C.D/M as-set summary-only",
5012 "Configure BGP aggregate entries\n"
5013 "Aggregate prefix\n"
5014 "Generate AS set path information\n"
5015 "Filter more specific routes from updates\n")
5016{
5017 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5018 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5019}
5020
5021ALIAS (aggregate_address_as_set_summary,
5022 aggregate_address_summary_as_set_cmd,
5023 "aggregate-address A.B.C.D/M summary-only as-set",
5024 "Configure BGP aggregate entries\n"
5025 "Aggregate prefix\n"
5026 "Filter more specific routes from updates\n"
5027 "Generate AS set path information\n")
5028
5029DEFUN (aggregate_address_mask_as_set_summary,
5030 aggregate_address_mask_as_set_summary_cmd,
5031 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5032 "Configure BGP aggregate entries\n"
5033 "Aggregate address\n"
5034 "Aggregate mask\n"
5035 "Generate AS set path information\n"
5036 "Filter more specific routes from updates\n")
5037{
5038 int ret;
5039 char prefix_str[BUFSIZ];
5040
5041 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5042
5043 if (! ret)
5044 {
5045 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5046 return CMD_WARNING;
5047 }
5048
5049 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5050 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5051}
5052
5053ALIAS (aggregate_address_mask_as_set_summary,
5054 aggregate_address_mask_summary_as_set_cmd,
5055 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5056 "Configure BGP aggregate entries\n"
5057 "Aggregate address\n"
5058 "Aggregate mask\n"
5059 "Filter more specific routes from updates\n"
5060 "Generate AS set path information\n")
5061
5062DEFUN (no_aggregate_address,
5063 no_aggregate_address_cmd,
5064 "no aggregate-address A.B.C.D/M",
5065 NO_STR
5066 "Configure BGP aggregate entries\n"
5067 "Aggregate prefix\n")
5068{
5069 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5070}
5071
5072ALIAS (no_aggregate_address,
5073 no_aggregate_address_summary_only_cmd,
5074 "no aggregate-address A.B.C.D/M summary-only",
5075 NO_STR
5076 "Configure BGP aggregate entries\n"
5077 "Aggregate prefix\n"
5078 "Filter more specific routes from updates\n")
5079
5080ALIAS (no_aggregate_address,
5081 no_aggregate_address_as_set_cmd,
5082 "no aggregate-address A.B.C.D/M as-set",
5083 NO_STR
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate prefix\n"
5086 "Generate AS set path information\n")
5087
5088ALIAS (no_aggregate_address,
5089 no_aggregate_address_as_set_summary_cmd,
5090 "no aggregate-address A.B.C.D/M as-set summary-only",
5091 NO_STR
5092 "Configure BGP aggregate entries\n"
5093 "Aggregate prefix\n"
5094 "Generate AS set path information\n"
5095 "Filter more specific routes from updates\n")
5096
5097ALIAS (no_aggregate_address,
5098 no_aggregate_address_summary_as_set_cmd,
5099 "no aggregate-address A.B.C.D/M summary-only as-set",
5100 NO_STR
5101 "Configure BGP aggregate entries\n"
5102 "Aggregate prefix\n"
5103 "Filter more specific routes from updates\n"
5104 "Generate AS set path information\n")
5105
5106DEFUN (no_aggregate_address_mask,
5107 no_aggregate_address_mask_cmd,
5108 "no aggregate-address A.B.C.D A.B.C.D",
5109 NO_STR
5110 "Configure BGP aggregate entries\n"
5111 "Aggregate address\n"
5112 "Aggregate mask\n")
5113{
5114 int ret;
5115 char prefix_str[BUFSIZ];
5116
5117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5118
5119 if (! ret)
5120 {
5121 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5122 return CMD_WARNING;
5123 }
5124
5125 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5126}
5127
5128ALIAS (no_aggregate_address_mask,
5129 no_aggregate_address_mask_summary_only_cmd,
5130 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5131 NO_STR
5132 "Configure BGP aggregate entries\n"
5133 "Aggregate address\n"
5134 "Aggregate mask\n"
5135 "Filter more specific routes from updates\n")
5136
5137ALIAS (no_aggregate_address_mask,
5138 no_aggregate_address_mask_as_set_cmd,
5139 "no aggregate-address A.B.C.D A.B.C.D as-set",
5140 NO_STR
5141 "Configure BGP aggregate entries\n"
5142 "Aggregate address\n"
5143 "Aggregate mask\n"
5144 "Generate AS set path information\n")
5145
5146ALIAS (no_aggregate_address_mask,
5147 no_aggregate_address_mask_as_set_summary_cmd,
5148 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5149 NO_STR
5150 "Configure BGP aggregate entries\n"
5151 "Aggregate address\n"
5152 "Aggregate mask\n"
5153 "Generate AS set path information\n"
5154 "Filter more specific routes from updates\n")
5155
5156ALIAS (no_aggregate_address_mask,
5157 no_aggregate_address_mask_summary_as_set_cmd,
5158 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5159 NO_STR
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate address\n"
5162 "Aggregate mask\n"
5163 "Filter more specific routes from updates\n"
5164 "Generate AS set path information\n")
5165
5166#ifdef HAVE_IPV6
5167DEFUN (ipv6_aggregate_address,
5168 ipv6_aggregate_address_cmd,
5169 "aggregate-address X:X::X:X/M",
5170 "Configure BGP aggregate entries\n"
5171 "Aggregate prefix\n")
5172{
5173 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5174}
5175
5176DEFUN (ipv6_aggregate_address_summary_only,
5177 ipv6_aggregate_address_summary_only_cmd,
5178 "aggregate-address X:X::X:X/M summary-only",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Filter more specific routes from updates\n")
5182{
5183 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5184 AGGREGATE_SUMMARY_ONLY, 0);
5185}
5186
5187DEFUN (no_ipv6_aggregate_address,
5188 no_ipv6_aggregate_address_cmd,
5189 "no aggregate-address X:X::X:X/M",
5190 NO_STR
5191 "Configure BGP aggregate entries\n"
5192 "Aggregate prefix\n")
5193{
5194 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5195}
5196
5197DEFUN (no_ipv6_aggregate_address_summary_only,
5198 no_ipv6_aggregate_address_summary_only_cmd,
5199 "no aggregate-address X:X::X:X/M summary-only",
5200 NO_STR
5201 "Configure BGP aggregate entries\n"
5202 "Aggregate prefix\n"
5203 "Filter more specific routes from updates\n")
5204{
5205 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5206}
5207
5208ALIAS (ipv6_aggregate_address,
5209 old_ipv6_aggregate_address_cmd,
5210 "ipv6 bgp aggregate-address X:X::X:X/M",
5211 IPV6_STR
5212 BGP_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate prefix\n")
5215
5216ALIAS (ipv6_aggregate_address_summary_only,
5217 old_ipv6_aggregate_address_summary_only_cmd,
5218 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5219 IPV6_STR
5220 BGP_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate prefix\n"
5223 "Filter more specific routes from updates\n")
5224
5225ALIAS (no_ipv6_aggregate_address,
5226 old_no_ipv6_aggregate_address_cmd,
5227 "no ipv6 bgp aggregate-address X:X::X:X/M",
5228 NO_STR
5229 IPV6_STR
5230 BGP_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate prefix\n")
5233
5234ALIAS (no_ipv6_aggregate_address_summary_only,
5235 old_no_ipv6_aggregate_address_summary_only_cmd,
5236 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5237 NO_STR
5238 IPV6_STR
5239 BGP_STR
5240 "Configure BGP aggregate entries\n"
5241 "Aggregate prefix\n"
5242 "Filter more specific routes from updates\n")
5243#endif /* HAVE_IPV6 */
5244
5245/* Redistribute route treatment. */
5246void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005247bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5248 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005249 u_int32_t metric, u_char type)
5250{
5251 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005252 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005253 struct bgp_info *new;
5254 struct bgp_info *bi;
5255 struct bgp_info info;
5256 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005257 struct attr attr = { 0 };
5258 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005259 struct attr *new_attr;
5260 afi_t afi;
5261 int ret;
5262
5263 /* Make default attribute. */
5264 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5265 if (nexthop)
5266 attr.nexthop = *nexthop;
5267
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005268#ifdef HAVE_IPV6
5269 if (nexthop6)
5270 {
5271 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5272 extra->mp_nexthop_global = *nexthop6;
5273 extra->mp_nexthop_len = 16;
5274 }
5275#endif
5276
paul718e3742002-12-13 20:15:29 +00005277 attr.med = metric;
5278 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5279
paul1eb8ef22005-04-07 07:30:20 +00005280 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005281 {
5282 afi = family2afi (p->family);
5283
5284 if (bgp->redist[afi][type])
5285 {
5286 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005287 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005288
5289 if (bgp->redist_metric_flag[afi][type])
5290 attr_new.med = bgp->redist_metric[afi][type];
5291
5292 /* Apply route-map. */
5293 if (bgp->rmap[afi][type].map)
5294 {
5295 info.peer = bgp->peer_self;
5296 info.attr = &attr_new;
5297
paulfee0f4c2004-09-13 05:12:46 +00005298 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5299
paul718e3742002-12-13 20:15:29 +00005300 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5301 &info);
paulfee0f4c2004-09-13 05:12:46 +00005302
5303 bgp->peer_self->rmap_type = 0;
5304
paul718e3742002-12-13 20:15:29 +00005305 if (ret == RMAP_DENYMATCH)
5306 {
5307 /* Free uninterned attribute. */
5308 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005309 bgp_attr_extra_free (&attr_new);
5310
paul718e3742002-12-13 20:15:29 +00005311 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005312 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005313 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005314 bgp_redistribute_delete (p, type);
5315 return;
5316 }
5317 }
5318
Paul Jakmafb982c22007-05-04 20:15:47 +00005319 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5320 afi, SAFI_UNICAST, p, NULL);
5321
paul718e3742002-12-13 20:15:29 +00005322 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005323 bgp_attr_extra_free (&attr_new);
5324
paul718e3742002-12-13 20:15:29 +00005325 for (bi = bn->info; bi; bi = bi->next)
5326 if (bi->peer == bgp->peer_self
5327 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5328 break;
5329
5330 if (bi)
5331 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005332 if (attrhash_cmp (bi->attr, new_attr) &&
5333 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005334 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005335 bgp_attr_unintern (&new_attr);
5336 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005337 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005338 bgp_unlock_node (bn);
5339 return;
5340 }
5341 else
5342 {
5343 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005344 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005345
5346 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005347 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5348 bgp_info_restore(bn, bi);
5349 else
5350 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005351 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005352 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005353 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005354
5355 /* Process change. */
5356 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5357 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5358 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005359 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005360 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005361 return;
5362 }
5363 }
5364
5365 new = bgp_info_new ();
5366 new->type = type;
5367 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5368 new->peer = bgp->peer_self;
5369 SET_FLAG (new->flags, BGP_INFO_VALID);
5370 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005371 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005372
5373 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5374 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005375 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005376 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5377 }
5378 }
5379
5380 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005381 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005382 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005383}
5384
5385void
5386bgp_redistribute_delete (struct prefix *p, u_char type)
5387{
5388 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005389 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005390 afi_t afi;
5391 struct bgp_node *rn;
5392 struct bgp_info *ri;
5393
paul1eb8ef22005-04-07 07:30:20 +00005394 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005395 {
5396 afi = family2afi (p->family);
5397
5398 if (bgp->redist[afi][type])
5399 {
paulfee0f4c2004-09-13 05:12:46 +00005400 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005401
5402 for (ri = rn->info; ri; ri = ri->next)
5403 if (ri->peer == bgp->peer_self
5404 && ri->type == type)
5405 break;
5406
5407 if (ri)
5408 {
5409 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005410 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005411 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005412 }
5413 bgp_unlock_node (rn);
5414 }
5415 }
5416}
5417
5418/* Withdraw specified route type's route. */
5419void
5420bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5421{
5422 struct bgp_node *rn;
5423 struct bgp_info *ri;
5424 struct bgp_table *table;
5425
5426 table = bgp->rib[afi][SAFI_UNICAST];
5427
5428 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5429 {
5430 for (ri = rn->info; ri; ri = ri->next)
5431 if (ri->peer == bgp->peer_self
5432 && ri->type == type)
5433 break;
5434
5435 if (ri)
5436 {
5437 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005438 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005439 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005440 }
5441 }
5442}
5443
5444/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005445static void
paul718e3742002-12-13 20:15:29 +00005446route_vty_out_route (struct prefix *p, struct vty *vty)
5447{
5448 int len;
5449 u_int32_t destination;
5450 char buf[BUFSIZ];
5451
5452 if (p->family == AF_INET)
5453 {
5454 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5455 destination = ntohl (p->u.prefix4.s_addr);
5456
5457 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5458 || (IN_CLASSB (destination) && p->prefixlen == 16)
5459 || (IN_CLASSA (destination) && p->prefixlen == 8)
5460 || p->u.prefix4.s_addr == 0)
5461 {
5462 /* When mask is natural, mask is not displayed. */
5463 }
5464 else
5465 len += vty_out (vty, "/%d", p->prefixlen);
5466 }
5467 else
5468 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5469 p->prefixlen);
5470
5471 len = 17 - len;
5472 if (len < 1)
5473 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5474 else
5475 vty_out (vty, "%*s", len, " ");
5476}
5477
paul718e3742002-12-13 20:15:29 +00005478enum bgp_display_type
5479{
5480 normal_list,
5481};
5482
paulb40d9392005-08-22 22:34:41 +00005483/* Print the short form route status for a bgp_info */
5484static void
5485route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005486{
paulb40d9392005-08-22 22:34:41 +00005487 /* Route status display. */
5488 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5489 vty_out (vty, "R");
5490 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005491 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005492 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005493 vty_out (vty, "s");
5494 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5495 vty_out (vty, "*");
5496 else
5497 vty_out (vty, " ");
5498
5499 /* Selected */
5500 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5501 vty_out (vty, "h");
5502 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5503 vty_out (vty, "d");
5504 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5505 vty_out (vty, ">");
5506 else
5507 vty_out (vty, " ");
5508
5509 /* Internal route. */
5510 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5511 vty_out (vty, "i");
5512 else
paulb40d9392005-08-22 22:34:41 +00005513 vty_out (vty, " ");
5514}
5515
5516/* called from terminal list command */
5517void
5518route_vty_out (struct vty *vty, struct prefix *p,
5519 struct bgp_info *binfo, int display, safi_t safi)
5520{
5521 struct attr *attr;
5522
5523 /* short status lead text */
5524 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005525
5526 /* print prefix and mask */
5527 if (! display)
5528 route_vty_out_route (p, vty);
5529 else
5530 vty_out (vty, "%*s", 17, " ");
5531
5532 /* Print attribute */
5533 attr = binfo->attr;
5534 if (attr)
5535 {
5536 if (p->family == AF_INET)
5537 {
5538 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005539 vty_out (vty, "%-16s",
5540 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005541 else
5542 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5543 }
5544#ifdef HAVE_IPV6
5545 else if (p->family == AF_INET6)
5546 {
5547 int len;
5548 char buf[BUFSIZ];
5549
5550 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005551 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5552 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005553 len = 16 - len;
5554 if (len < 1)
5555 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5556 else
5557 vty_out (vty, "%*s", len, " ");
5558 }
5559#endif /* HAVE_IPV6 */
5560
5561 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005562 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005563 else
5564 vty_out (vty, " ");
5565
5566 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005567 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005568 else
5569 vty_out (vty, " ");
5570
Paul Jakmafb982c22007-05-04 20:15:47 +00005571 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005572
Paul Jakmab2518c12006-05-12 23:48:40 +00005573 /* Print aspath */
5574 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005575 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005576
Paul Jakmab2518c12006-05-12 23:48:40 +00005577 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005578 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005579 }
paul718e3742002-12-13 20:15:29 +00005580 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005581}
5582
5583/* called from terminal list command */
5584void
5585route_vty_out_tmp (struct vty *vty, struct prefix *p,
5586 struct attr *attr, safi_t safi)
5587{
5588 /* Route status display. */
5589 vty_out (vty, "*");
5590 vty_out (vty, ">");
5591 vty_out (vty, " ");
5592
5593 /* print prefix and mask */
5594 route_vty_out_route (p, vty);
5595
5596 /* Print attribute */
5597 if (attr)
5598 {
5599 if (p->family == AF_INET)
5600 {
5601 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005602 vty_out (vty, "%-16s",
5603 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005604 else
5605 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5606 }
5607#ifdef HAVE_IPV6
5608 else if (p->family == AF_INET6)
5609 {
5610 int len;
5611 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005612
5613 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005614
5615 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005616 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5617 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005618 len = 16 - len;
5619 if (len < 1)
5620 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5621 else
5622 vty_out (vty, "%*s", len, " ");
5623 }
5624#endif /* HAVE_IPV6 */
5625
5626 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005627 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005628 else
5629 vty_out (vty, " ");
5630
5631 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005632 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005633 else
5634 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005635
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005636 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005637
Paul Jakmab2518c12006-05-12 23:48:40 +00005638 /* Print aspath */
5639 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005640 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005641
Paul Jakmab2518c12006-05-12 23:48:40 +00005642 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005643 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005644 }
paul718e3742002-12-13 20:15:29 +00005645
5646 vty_out (vty, "%s", VTY_NEWLINE);
5647}
5648
ajs5a646652004-11-05 01:25:55 +00005649void
paul718e3742002-12-13 20:15:29 +00005650route_vty_out_tag (struct vty *vty, struct prefix *p,
5651 struct bgp_info *binfo, int display, safi_t safi)
5652{
5653 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005654 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005655
5656 if (!binfo->extra)
5657 return;
5658
paulb40d9392005-08-22 22:34:41 +00005659 /* short status lead text */
5660 route_vty_short_status_out (vty, binfo);
5661
paul718e3742002-12-13 20:15:29 +00005662 /* print prefix and mask */
5663 if (! display)
5664 route_vty_out_route (p, vty);
5665 else
5666 vty_out (vty, "%*s", 17, " ");
5667
5668 /* Print attribute */
5669 attr = binfo->attr;
5670 if (attr)
5671 {
5672 if (p->family == AF_INET)
5673 {
5674 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005675 vty_out (vty, "%-16s",
5676 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005677 else
5678 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5679 }
5680#ifdef HAVE_IPV6
5681 else if (p->family == AF_INET6)
5682 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005684 char buf[BUFSIZ];
5685 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005686 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005687 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005688 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5689 buf, BUFSIZ));
5690 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005691 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005692 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5693 buf, BUFSIZ),
5694 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5695 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005696
5697 }
5698#endif /* HAVE_IPV6 */
5699 }
5700
Paul Jakmafb982c22007-05-04 20:15:47 +00005701 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005702
5703 vty_out (vty, "notag/%d", label);
5704
5705 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005706}
5707
5708/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005709static void
paul718e3742002-12-13 20:15:29 +00005710damp_route_vty_out (struct vty *vty, struct prefix *p,
5711 struct bgp_info *binfo, int display, safi_t safi)
5712{
5713 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005714 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005715 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005716
paulb40d9392005-08-22 22:34:41 +00005717 /* short status lead text */
5718 route_vty_short_status_out (vty, binfo);
5719
paul718e3742002-12-13 20:15:29 +00005720 /* print prefix and mask */
5721 if (! display)
5722 route_vty_out_route (p, vty);
5723 else
5724 vty_out (vty, "%*s", 17, " ");
5725
5726 len = vty_out (vty, "%s", binfo->peer->host);
5727 len = 17 - len;
5728 if (len < 1)
5729 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5730 else
5731 vty_out (vty, "%*s", len, " ");
5732
Chris Caputo50aef6f2009-06-23 06:06:49 +00005733 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005734
5735 /* Print attribute */
5736 attr = binfo->attr;
5737 if (attr)
5738 {
5739 /* Print aspath */
5740 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005741 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005742
5743 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005744 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005745 }
5746 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005747}
5748
paul718e3742002-12-13 20:15:29 +00005749/* flap route */
ajs5a646652004-11-05 01:25:55 +00005750static void
paul718e3742002-12-13 20:15:29 +00005751flap_route_vty_out (struct vty *vty, struct prefix *p,
5752 struct bgp_info *binfo, int display, safi_t safi)
5753{
5754 struct attr *attr;
5755 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005756 char timebuf[BGP_UPTIME_LEN];
5757 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005758
5759 if (!binfo->extra)
5760 return;
5761
5762 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005763
paulb40d9392005-08-22 22:34:41 +00005764 /* short status lead text */
5765 route_vty_short_status_out (vty, binfo);
5766
paul718e3742002-12-13 20:15:29 +00005767 /* print prefix and mask */
5768 if (! display)
5769 route_vty_out_route (p, vty);
5770 else
5771 vty_out (vty, "%*s", 17, " ");
5772
5773 len = vty_out (vty, "%s", binfo->peer->host);
5774 len = 16 - len;
5775 if (len < 1)
5776 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5777 else
5778 vty_out (vty, "%*s", len, " ");
5779
5780 len = vty_out (vty, "%d", bdi->flap);
5781 len = 5 - len;
5782 if (len < 1)
5783 vty_out (vty, " ");
5784 else
5785 vty_out (vty, "%*s ", len, " ");
5786
5787 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5788 timebuf, BGP_UPTIME_LEN));
5789
5790 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5791 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005792 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005793 else
5794 vty_out (vty, "%*s ", 8, " ");
5795
5796 /* Print attribute */
5797 attr = binfo->attr;
5798 if (attr)
5799 {
5800 /* Print aspath */
5801 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005802 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005803
5804 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005805 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005806 }
5807 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005808}
5809
paul94f2b392005-06-28 12:44:16 +00005810static void
paul718e3742002-12-13 20:15:29 +00005811route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5812 struct bgp_info *binfo, afi_t afi, safi_t safi)
5813{
5814 char buf[INET6_ADDRSTRLEN];
5815 char buf1[BUFSIZ];
5816 struct attr *attr;
5817 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005818#ifdef HAVE_CLOCK_MONOTONIC
5819 time_t tbuf;
5820#endif
paul718e3742002-12-13 20:15:29 +00005821
5822 attr = binfo->attr;
5823
5824 if (attr)
5825 {
5826 /* Line1 display AS-path, Aggregator */
5827 if (attr->aspath)
5828 {
5829 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005830 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005831 vty_out (vty, "Local");
5832 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005833 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005834 }
5835
paulb40d9392005-08-22 22:34:41 +00005836 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5837 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005838 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5839 vty_out (vty, ", (stale)");
5840 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005841 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 attr->extra->aggregator_as,
5843 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005844 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5845 vty_out (vty, ", (Received from a RR-client)");
5846 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5847 vty_out (vty, ", (Received from a RS-client)");
5848 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5849 vty_out (vty, ", (history entry)");
5850 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5851 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005852 vty_out (vty, "%s", VTY_NEWLINE);
5853
5854 /* Line2 display Next-hop, Neighbor, Router-id */
5855 if (p->family == AF_INET)
5856 {
5857 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005858 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005859 inet_ntoa (attr->nexthop));
5860 }
5861#ifdef HAVE_IPV6
5862 else
5863 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005864 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005865 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005866 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005867 buf, INET6_ADDRSTRLEN));
5868 }
5869#endif /* HAVE_IPV6 */
5870
5871 if (binfo->peer == bgp->peer_self)
5872 {
5873 vty_out (vty, " from %s ",
5874 p->family == AF_INET ? "0.0.0.0" : "::");
5875 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5876 }
5877 else
5878 {
5879 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5880 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005881 else if (binfo->extra && binfo->extra->igpmetric)
5882 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005883 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005884 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005885 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005886 else
5887 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5888 }
5889 vty_out (vty, "%s", VTY_NEWLINE);
5890
5891#ifdef HAVE_IPV6
5892 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005893 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005894 {
5895 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005896 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005897 buf, INET6_ADDRSTRLEN),
5898 VTY_NEWLINE);
5899 }
5900#endif /* HAVE_IPV6 */
5901
5902 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5903 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5904
5905 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005906 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005907
5908 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005909 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005910 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005911 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005912
Paul Jakmafb982c22007-05-04 20:15:47 +00005913 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005914 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005915
5916 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5917 vty_out (vty, ", valid");
5918
5919 if (binfo->peer != bgp->peer_self)
5920 {
5921 if (binfo->peer->as == binfo->peer->local_as)
5922 vty_out (vty, ", internal");
5923 else
5924 vty_out (vty, ", %s",
5925 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5926 }
5927 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5928 vty_out (vty, ", aggregated, local");
5929 else if (binfo->type != ZEBRA_ROUTE_BGP)
5930 vty_out (vty, ", sourced");
5931 else
5932 vty_out (vty, ", sourced, local");
5933
5934 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5935 vty_out (vty, ", atomic-aggregate");
5936
5937 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5938 vty_out (vty, ", best");
5939
5940 vty_out (vty, "%s", VTY_NEWLINE);
5941
5942 /* Line 4 display Community */
5943 if (attr->community)
5944 vty_out (vty, " Community: %s%s", attr->community->str,
5945 VTY_NEWLINE);
5946
5947 /* Line 5 display Extended-community */
5948 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005949 vty_out (vty, " Extended Community: %s%s",
5950 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005951
5952 /* Line 6 display Originator, Cluster-id */
5953 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5954 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5955 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005956 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005957 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005958 vty_out (vty, " Originator: %s",
5959 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005960
5961 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5962 {
5963 int i;
5964 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005965 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5966 vty_out (vty, "%s ",
5967 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00005968 }
5969 vty_out (vty, "%s", VTY_NEWLINE);
5970 }
Paul Jakma41367172007-08-06 15:24:51 +00005971
Paul Jakmafb982c22007-05-04 20:15:47 +00005972 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00005973 bgp_damp_info_vty (vty, binfo);
5974
5975 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03005976#ifdef HAVE_CLOCK_MONOTONIC
5977 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04005978 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03005979#else
5980 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5981#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00005982 }
5983 vty_out (vty, "%s", VTY_NEWLINE);
5984}
5985
paulb40d9392005-08-22 22:34:41 +00005986#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 +00005987#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005988#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5989#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5990#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5991
5992enum bgp_show_type
5993{
5994 bgp_show_type_normal,
5995 bgp_show_type_regexp,
5996 bgp_show_type_prefix_list,
5997 bgp_show_type_filter_list,
5998 bgp_show_type_route_map,
5999 bgp_show_type_neighbor,
6000 bgp_show_type_cidr_only,
6001 bgp_show_type_prefix_longer,
6002 bgp_show_type_community_all,
6003 bgp_show_type_community,
6004 bgp_show_type_community_exact,
6005 bgp_show_type_community_list,
6006 bgp_show_type_community_list_exact,
6007 bgp_show_type_flap_statistics,
6008 bgp_show_type_flap_address,
6009 bgp_show_type_flap_prefix,
6010 bgp_show_type_flap_cidr_only,
6011 bgp_show_type_flap_regexp,
6012 bgp_show_type_flap_filter_list,
6013 bgp_show_type_flap_prefix_list,
6014 bgp_show_type_flap_prefix_longer,
6015 bgp_show_type_flap_route_map,
6016 bgp_show_type_flap_neighbor,
6017 bgp_show_type_dampend_paths,
6018 bgp_show_type_damp_neighbor
6019};
6020
ajs5a646652004-11-05 01:25:55 +00006021static int
paulfee0f4c2004-09-13 05:12:46 +00006022bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006023 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006024{
paul718e3742002-12-13 20:15:29 +00006025 struct bgp_info *ri;
6026 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006027 int header = 1;
paul718e3742002-12-13 20:15:29 +00006028 int display;
ajs5a646652004-11-05 01:25:55 +00006029 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006030
6031 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006032 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006033
paul718e3742002-12-13 20:15:29 +00006034 /* Start processing of routes. */
6035 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6036 if (rn->info != NULL)
6037 {
6038 display = 0;
6039
6040 for (ri = rn->info; ri; ri = ri->next)
6041 {
ajs5a646652004-11-05 01:25:55 +00006042 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006043 || type == bgp_show_type_flap_address
6044 || type == bgp_show_type_flap_prefix
6045 || type == bgp_show_type_flap_cidr_only
6046 || type == bgp_show_type_flap_regexp
6047 || type == bgp_show_type_flap_filter_list
6048 || type == bgp_show_type_flap_prefix_list
6049 || type == bgp_show_type_flap_prefix_longer
6050 || type == bgp_show_type_flap_route_map
6051 || type == bgp_show_type_flap_neighbor
6052 || type == bgp_show_type_dampend_paths
6053 || type == bgp_show_type_damp_neighbor)
6054 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006056 continue;
6057 }
6058 if (type == bgp_show_type_regexp
6059 || type == bgp_show_type_flap_regexp)
6060 {
ajs5a646652004-11-05 01:25:55 +00006061 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006062
6063 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6064 continue;
6065 }
6066 if (type == bgp_show_type_prefix_list
6067 || type == bgp_show_type_flap_prefix_list)
6068 {
ajs5a646652004-11-05 01:25:55 +00006069 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006070
6071 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6072 continue;
6073 }
6074 if (type == bgp_show_type_filter_list
6075 || type == bgp_show_type_flap_filter_list)
6076 {
ajs5a646652004-11-05 01:25:55 +00006077 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006078
6079 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6080 continue;
6081 }
6082 if (type == bgp_show_type_route_map
6083 || type == bgp_show_type_flap_route_map)
6084 {
ajs5a646652004-11-05 01:25:55 +00006085 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006086 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006087 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006088 int ret;
6089
Paul Jakmafb982c22007-05-04 20:15:47 +00006090 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006091 binfo.peer = ri->peer;
6092 binfo.attr = &dummy_attr;
6093
6094 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006095
6096 bgp_attr_extra_free (&dummy_attr);
6097
paul718e3742002-12-13 20:15:29 +00006098 if (ret == RMAP_DENYMATCH)
6099 continue;
6100 }
6101 if (type == bgp_show_type_neighbor
6102 || type == bgp_show_type_flap_neighbor
6103 || type == bgp_show_type_damp_neighbor)
6104 {
ajs5a646652004-11-05 01:25:55 +00006105 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006106
6107 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6108 continue;
6109 }
6110 if (type == bgp_show_type_cidr_only
6111 || type == bgp_show_type_flap_cidr_only)
6112 {
6113 u_int32_t destination;
6114
6115 destination = ntohl (rn->p.u.prefix4.s_addr);
6116 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6117 continue;
6118 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6119 continue;
6120 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6121 continue;
6122 }
6123 if (type == bgp_show_type_prefix_longer
6124 || type == bgp_show_type_flap_prefix_longer)
6125 {
ajs5a646652004-11-05 01:25:55 +00006126 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006127
6128 if (! prefix_match (p, &rn->p))
6129 continue;
6130 }
6131 if (type == bgp_show_type_community_all)
6132 {
6133 if (! ri->attr->community)
6134 continue;
6135 }
6136 if (type == bgp_show_type_community)
6137 {
ajs5a646652004-11-05 01:25:55 +00006138 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006139
6140 if (! ri->attr->community ||
6141 ! community_match (ri->attr->community, com))
6142 continue;
6143 }
6144 if (type == bgp_show_type_community_exact)
6145 {
ajs5a646652004-11-05 01:25:55 +00006146 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006147
6148 if (! ri->attr->community ||
6149 ! community_cmp (ri->attr->community, com))
6150 continue;
6151 }
6152 if (type == bgp_show_type_community_list)
6153 {
ajs5a646652004-11-05 01:25:55 +00006154 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006155
6156 if (! community_list_match (ri->attr->community, list))
6157 continue;
6158 }
6159 if (type == bgp_show_type_community_list_exact)
6160 {
ajs5a646652004-11-05 01:25:55 +00006161 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006162
6163 if (! community_list_exact_match (ri->attr->community, list))
6164 continue;
6165 }
6166 if (type == bgp_show_type_flap_address
6167 || type == bgp_show_type_flap_prefix)
6168 {
ajs5a646652004-11-05 01:25:55 +00006169 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006170
6171 if (! prefix_match (&rn->p, p))
6172 continue;
6173
6174 if (type == bgp_show_type_flap_prefix)
6175 if (p->prefixlen != rn->p.prefixlen)
6176 continue;
6177 }
6178 if (type == bgp_show_type_dampend_paths
6179 || type == bgp_show_type_damp_neighbor)
6180 {
6181 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6182 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6183 continue;
6184 }
6185
6186 if (header)
6187 {
hasso93406d82005-02-02 14:40:33 +00006188 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6189 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6190 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006191 if (type == bgp_show_type_dampend_paths
6192 || type == bgp_show_type_damp_neighbor)
6193 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6194 else if (type == bgp_show_type_flap_statistics
6195 || type == bgp_show_type_flap_address
6196 || type == bgp_show_type_flap_prefix
6197 || type == bgp_show_type_flap_cidr_only
6198 || type == bgp_show_type_flap_regexp
6199 || type == bgp_show_type_flap_filter_list
6200 || type == bgp_show_type_flap_prefix_list
6201 || type == bgp_show_type_flap_prefix_longer
6202 || type == bgp_show_type_flap_route_map
6203 || type == bgp_show_type_flap_neighbor)
6204 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6205 else
6206 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006207 header = 0;
6208 }
6209
6210 if (type == bgp_show_type_dampend_paths
6211 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006212 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006213 else if (type == bgp_show_type_flap_statistics
6214 || type == bgp_show_type_flap_address
6215 || type == bgp_show_type_flap_prefix
6216 || type == bgp_show_type_flap_cidr_only
6217 || type == bgp_show_type_flap_regexp
6218 || type == bgp_show_type_flap_filter_list
6219 || type == bgp_show_type_flap_prefix_list
6220 || type == bgp_show_type_flap_prefix_longer
6221 || type == bgp_show_type_flap_route_map
6222 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006223 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006224 else
ajs5a646652004-11-05 01:25:55 +00006225 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006226 display++;
6227 }
6228 if (display)
ajs5a646652004-11-05 01:25:55 +00006229 output_count++;
paul718e3742002-12-13 20:15:29 +00006230 }
6231
6232 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006233 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006234 {
6235 if (type == bgp_show_type_normal)
6236 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6237 }
6238 else
6239 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006240 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006241
6242 return CMD_SUCCESS;
6243}
6244
ajs5a646652004-11-05 01:25:55 +00006245static int
paulfee0f4c2004-09-13 05:12:46 +00006246bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006247 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006248{
6249 struct bgp_table *table;
6250
6251 if (bgp == NULL) {
6252 bgp = bgp_get_default ();
6253 }
6254
6255 if (bgp == NULL)
6256 {
6257 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6258 return CMD_WARNING;
6259 }
6260
6261
6262 table = bgp->rib[afi][safi];
6263
ajs5a646652004-11-05 01:25:55 +00006264 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006265}
6266
paul718e3742002-12-13 20:15:29 +00006267/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006268static void
paul718e3742002-12-13 20:15:29 +00006269route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6270 struct bgp_node *rn,
6271 struct prefix_rd *prd, afi_t afi, safi_t safi)
6272{
6273 struct bgp_info *ri;
6274 struct prefix *p;
6275 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006276 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006277 char buf1[INET6_ADDRSTRLEN];
6278 char buf2[INET6_ADDRSTRLEN];
6279 int count = 0;
6280 int best = 0;
6281 int suppress = 0;
6282 int no_export = 0;
6283 int no_advertise = 0;
6284 int local_as = 0;
6285 int first = 0;
6286
6287 p = &rn->p;
6288 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6289 (safi == SAFI_MPLS_VPN ?
6290 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6291 safi == SAFI_MPLS_VPN ? ":" : "",
6292 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6293 p->prefixlen, VTY_NEWLINE);
6294
6295 for (ri = rn->info; ri; ri = ri->next)
6296 {
6297 count++;
6298 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6299 {
6300 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006301 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006302 suppress = 1;
6303 if (ri->attr->community != NULL)
6304 {
6305 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6306 no_advertise = 1;
6307 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6308 no_export = 1;
6309 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6310 local_as = 1;
6311 }
6312 }
6313 }
6314
6315 vty_out (vty, "Paths: (%d available", count);
6316 if (best)
6317 {
6318 vty_out (vty, ", best #%d", best);
6319 if (safi == SAFI_UNICAST)
6320 vty_out (vty, ", table Default-IP-Routing-Table");
6321 }
6322 else
6323 vty_out (vty, ", no best path");
6324 if (no_advertise)
6325 vty_out (vty, ", not advertised to any peer");
6326 else if (no_export)
6327 vty_out (vty, ", not advertised to EBGP peer");
6328 else if (local_as)
6329 vty_out (vty, ", not advertised outside local AS");
6330 if (suppress)
6331 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6332 vty_out (vty, ")%s", VTY_NEWLINE);
6333
6334 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006335 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006336 {
6337 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6338 {
6339 if (! first)
6340 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6341 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6342 first = 1;
6343 }
6344 }
6345 if (! first)
6346 vty_out (vty, " Not advertised to any peer");
6347 vty_out (vty, "%s", VTY_NEWLINE);
6348}
6349
6350/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006351static int
paulfee0f4c2004-09-13 05:12:46 +00006352bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006353 struct bgp_table *rib, const char *ip_str,
6354 afi_t afi, safi_t safi, struct prefix_rd *prd,
6355 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006356{
6357 int ret;
6358 int header;
6359 int display = 0;
6360 struct prefix match;
6361 struct bgp_node *rn;
6362 struct bgp_node *rm;
6363 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006364 struct bgp_table *table;
6365
paul718e3742002-12-13 20:15:29 +00006366 /* Check IP address argument. */
6367 ret = str2prefix (ip_str, &match);
6368 if (! ret)
6369 {
6370 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6371 return CMD_WARNING;
6372 }
6373
6374 match.family = afi2family (afi);
6375
6376 if (safi == SAFI_MPLS_VPN)
6377 {
paulfee0f4c2004-09-13 05:12:46 +00006378 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006379 {
6380 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6381 continue;
6382
6383 if ((table = rn->info) != NULL)
6384 {
6385 header = 1;
6386
6387 if ((rm = bgp_node_match (table, &match)) != NULL)
6388 {
6389 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006390 {
6391 bgp_unlock_node (rm);
6392 continue;
6393 }
paul718e3742002-12-13 20:15:29 +00006394
6395 for (ri = rm->info; ri; ri = ri->next)
6396 {
6397 if (header)
6398 {
6399 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6400 AFI_IP, SAFI_MPLS_VPN);
6401
6402 header = 0;
6403 }
6404 display++;
6405 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6406 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006407
6408 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006409 }
6410 }
6411 }
6412 }
6413 else
6414 {
6415 header = 1;
6416
paulfee0f4c2004-09-13 05:12:46 +00006417 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006418 {
6419 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6420 {
6421 for (ri = rn->info; ri; ri = ri->next)
6422 {
6423 if (header)
6424 {
6425 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6426 header = 0;
6427 }
6428 display++;
6429 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6430 }
6431 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006432
6433 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006434 }
6435 }
6436
6437 if (! display)
6438 {
6439 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6440 return CMD_WARNING;
6441 }
6442
6443 return CMD_SUCCESS;
6444}
6445
paulfee0f4c2004-09-13 05:12:46 +00006446/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006447static int
paulfd79ac92004-10-13 05:06:08 +00006448bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006449 afi_t afi, safi_t safi, struct prefix_rd *prd,
6450 int prefix_check)
6451{
6452 struct bgp *bgp;
6453
6454 /* BGP structure lookup. */
6455 if (view_name)
6456 {
6457 bgp = bgp_lookup_by_name (view_name);
6458 if (bgp == NULL)
6459 {
6460 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6461 return CMD_WARNING;
6462 }
6463 }
6464 else
6465 {
6466 bgp = bgp_get_default ();
6467 if (bgp == NULL)
6468 {
6469 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6470 return CMD_WARNING;
6471 }
6472 }
6473
6474 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6475 afi, safi, prd, prefix_check);
6476}
6477
paul718e3742002-12-13 20:15:29 +00006478/* BGP route print out function. */
6479DEFUN (show_ip_bgp,
6480 show_ip_bgp_cmd,
6481 "show ip bgp",
6482 SHOW_STR
6483 IP_STR
6484 BGP_STR)
6485{
ajs5a646652004-11-05 01:25:55 +00006486 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006487}
6488
6489DEFUN (show_ip_bgp_ipv4,
6490 show_ip_bgp_ipv4_cmd,
6491 "show ip bgp ipv4 (unicast|multicast)",
6492 SHOW_STR
6493 IP_STR
6494 BGP_STR
6495 "Address family\n"
6496 "Address Family modifier\n"
6497 "Address Family modifier\n")
6498{
6499 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006500 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6501 NULL);
paul718e3742002-12-13 20:15:29 +00006502
ajs5a646652004-11-05 01:25:55 +00006503 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006504}
6505
Michael Lambert95cbbd22010-07-23 14:43:04 -04006506ALIAS (show_ip_bgp_ipv4,
6507 show_bgp_ipv4_safi_cmd,
6508 "show bgp ipv4 (unicast|multicast)",
6509 SHOW_STR
6510 BGP_STR
6511 "Address family\n"
6512 "Address Family modifier\n"
6513 "Address Family modifier\n")
6514
paul718e3742002-12-13 20:15:29 +00006515DEFUN (show_ip_bgp_route,
6516 show_ip_bgp_route_cmd,
6517 "show ip bgp A.B.C.D",
6518 SHOW_STR
6519 IP_STR
6520 BGP_STR
6521 "Network in the BGP routing table to display\n")
6522{
6523 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6524}
6525
6526DEFUN (show_ip_bgp_ipv4_route,
6527 show_ip_bgp_ipv4_route_cmd,
6528 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6529 SHOW_STR
6530 IP_STR
6531 BGP_STR
6532 "Address family\n"
6533 "Address Family modifier\n"
6534 "Address Family modifier\n"
6535 "Network in the BGP routing table to display\n")
6536{
6537 if (strncmp (argv[0], "m", 1) == 0)
6538 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6539
6540 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6541}
6542
Michael Lambert95cbbd22010-07-23 14:43:04 -04006543ALIAS (show_ip_bgp_ipv4_route,
6544 show_bgp_ipv4_safi_route_cmd,
6545 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6546 SHOW_STR
6547 BGP_STR
6548 "Address family\n"
6549 "Address Family modifier\n"
6550 "Address Family modifier\n"
6551 "Network in the BGP routing table to display\n")
6552
paul718e3742002-12-13 20:15:29 +00006553DEFUN (show_ip_bgp_vpnv4_all_route,
6554 show_ip_bgp_vpnv4_all_route_cmd,
6555 "show ip bgp vpnv4 all A.B.C.D",
6556 SHOW_STR
6557 IP_STR
6558 BGP_STR
6559 "Display VPNv4 NLRI specific information\n"
6560 "Display information about all VPNv4 NLRIs\n"
6561 "Network in the BGP routing table to display\n")
6562{
6563 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6564}
6565
6566DEFUN (show_ip_bgp_vpnv4_rd_route,
6567 show_ip_bgp_vpnv4_rd_route_cmd,
6568 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6569 SHOW_STR
6570 IP_STR
6571 BGP_STR
6572 "Display VPNv4 NLRI specific information\n"
6573 "Display information for a route distinguisher\n"
6574 "VPN Route Distinguisher\n"
6575 "Network in the BGP routing table to display\n")
6576{
6577 int ret;
6578 struct prefix_rd prd;
6579
6580 ret = str2prefix_rd (argv[0], &prd);
6581 if (! ret)
6582 {
6583 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6584 return CMD_WARNING;
6585 }
6586 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6587}
6588
6589DEFUN (show_ip_bgp_prefix,
6590 show_ip_bgp_prefix_cmd,
6591 "show ip bgp A.B.C.D/M",
6592 SHOW_STR
6593 IP_STR
6594 BGP_STR
6595 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6596{
6597 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6598}
6599
6600DEFUN (show_ip_bgp_ipv4_prefix,
6601 show_ip_bgp_ipv4_prefix_cmd,
6602 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6603 SHOW_STR
6604 IP_STR
6605 BGP_STR
6606 "Address family\n"
6607 "Address Family modifier\n"
6608 "Address Family modifier\n"
6609 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6610{
6611 if (strncmp (argv[0], "m", 1) == 0)
6612 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6613
6614 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6615}
6616
Michael Lambert95cbbd22010-07-23 14:43:04 -04006617ALIAS (show_ip_bgp_ipv4_prefix,
6618 show_bgp_ipv4_safi_prefix_cmd,
6619 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6620 SHOW_STR
6621 BGP_STR
6622 "Address family\n"
6623 "Address Family modifier\n"
6624 "Address Family modifier\n"
6625 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6626
paul718e3742002-12-13 20:15:29 +00006627DEFUN (show_ip_bgp_vpnv4_all_prefix,
6628 show_ip_bgp_vpnv4_all_prefix_cmd,
6629 "show ip bgp vpnv4 all A.B.C.D/M",
6630 SHOW_STR
6631 IP_STR
6632 BGP_STR
6633 "Display VPNv4 NLRI specific information\n"
6634 "Display information about all VPNv4 NLRIs\n"
6635 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6636{
6637 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6638}
6639
6640DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6641 show_ip_bgp_vpnv4_rd_prefix_cmd,
6642 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Display VPNv4 NLRI specific information\n"
6647 "Display information for a route distinguisher\n"
6648 "VPN Route Distinguisher\n"
6649 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6650{
6651 int ret;
6652 struct prefix_rd prd;
6653
6654 ret = str2prefix_rd (argv[0], &prd);
6655 if (! ret)
6656 {
6657 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6658 return CMD_WARNING;
6659 }
6660 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6661}
6662
6663DEFUN (show_ip_bgp_view,
6664 show_ip_bgp_view_cmd,
6665 "show ip bgp view WORD",
6666 SHOW_STR
6667 IP_STR
6668 BGP_STR
6669 "BGP view\n"
6670 "BGP view name\n")
6671{
paulbb46e942003-10-24 19:02:03 +00006672 struct bgp *bgp;
6673
6674 /* BGP structure lookup. */
6675 bgp = bgp_lookup_by_name (argv[0]);
6676 if (bgp == NULL)
6677 {
6678 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6679 return CMD_WARNING;
6680 }
6681
ajs5a646652004-11-05 01:25:55 +00006682 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006683}
6684
6685DEFUN (show_ip_bgp_view_route,
6686 show_ip_bgp_view_route_cmd,
6687 "show ip bgp view WORD A.B.C.D",
6688 SHOW_STR
6689 IP_STR
6690 BGP_STR
6691 "BGP view\n"
6692 "BGP view name\n"
6693 "Network in the BGP routing table to display\n")
6694{
6695 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6696}
6697
6698DEFUN (show_ip_bgp_view_prefix,
6699 show_ip_bgp_view_prefix_cmd,
6700 "show ip bgp view WORD A.B.C.D/M",
6701 SHOW_STR
6702 IP_STR
6703 BGP_STR
6704 "BGP view\n"
6705 "BGP view name\n"
6706 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6707{
6708 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6709}
6710
6711#ifdef HAVE_IPV6
6712DEFUN (show_bgp,
6713 show_bgp_cmd,
6714 "show bgp",
6715 SHOW_STR
6716 BGP_STR)
6717{
ajs5a646652004-11-05 01:25:55 +00006718 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6719 NULL);
paul718e3742002-12-13 20:15:29 +00006720}
6721
6722ALIAS (show_bgp,
6723 show_bgp_ipv6_cmd,
6724 "show bgp ipv6",
6725 SHOW_STR
6726 BGP_STR
6727 "Address family\n")
6728
Michael Lambert95cbbd22010-07-23 14:43:04 -04006729DEFUN (show_bgp_ipv6_safi,
6730 show_bgp_ipv6_safi_cmd,
6731 "show bgp ipv6 (unicast|multicast)",
6732 SHOW_STR
6733 BGP_STR
6734 "Address family\n"
6735 "Address Family modifier\n"
6736 "Address Family modifier\n")
6737{
6738 if (strncmp (argv[0], "m", 1) == 0)
6739 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6740 NULL);
6741
6742 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6743}
6744
paul718e3742002-12-13 20:15:29 +00006745/* old command */
6746DEFUN (show_ipv6_bgp,
6747 show_ipv6_bgp_cmd,
6748 "show ipv6 bgp",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR)
6752{
ajs5a646652004-11-05 01:25:55 +00006753 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6754 NULL);
paul718e3742002-12-13 20:15:29 +00006755}
6756
6757DEFUN (show_bgp_route,
6758 show_bgp_route_cmd,
6759 "show bgp X:X::X:X",
6760 SHOW_STR
6761 BGP_STR
6762 "Network in the BGP routing table to display\n")
6763{
6764 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6765}
6766
6767ALIAS (show_bgp_route,
6768 show_bgp_ipv6_route_cmd,
6769 "show bgp ipv6 X:X::X:X",
6770 SHOW_STR
6771 BGP_STR
6772 "Address family\n"
6773 "Network in the BGP routing table to display\n")
6774
Michael Lambert95cbbd22010-07-23 14:43:04 -04006775DEFUN (show_bgp_ipv6_safi_route,
6776 show_bgp_ipv6_safi_route_cmd,
6777 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6778 SHOW_STR
6779 BGP_STR
6780 "Address family\n"
6781 "Address Family modifier\n"
6782 "Address Family modifier\n"
6783 "Network in the BGP routing table to display\n")
6784{
6785 if (strncmp (argv[0], "m", 1) == 0)
6786 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6787
6788 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6789}
6790
paul718e3742002-12-13 20:15:29 +00006791/* old command */
6792DEFUN (show_ipv6_bgp_route,
6793 show_ipv6_bgp_route_cmd,
6794 "show ipv6 bgp X:X::X:X",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "Network in the BGP routing table to display\n")
6799{
6800 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6801}
6802
6803DEFUN (show_bgp_prefix,
6804 show_bgp_prefix_cmd,
6805 "show bgp X:X::X:X/M",
6806 SHOW_STR
6807 BGP_STR
6808 "IPv6 prefix <network>/<length>\n")
6809{
6810 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6811}
6812
6813ALIAS (show_bgp_prefix,
6814 show_bgp_ipv6_prefix_cmd,
6815 "show bgp ipv6 X:X::X:X/M",
6816 SHOW_STR
6817 BGP_STR
6818 "Address family\n"
6819 "IPv6 prefix <network>/<length>\n")
6820
Michael Lambert95cbbd22010-07-23 14:43:04 -04006821DEFUN (show_bgp_ipv6_safi_prefix,
6822 show_bgp_ipv6_safi_prefix_cmd,
6823 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6824 SHOW_STR
6825 BGP_STR
6826 "Address family\n"
6827 "Address Family modifier\n"
6828 "Address Family modifier\n"
6829 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6830{
6831 if (strncmp (argv[0], "m", 1) == 0)
6832 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6833
6834 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6835}
6836
paul718e3742002-12-13 20:15:29 +00006837/* old command */
6838DEFUN (show_ipv6_bgp_prefix,
6839 show_ipv6_bgp_prefix_cmd,
6840 "show ipv6 bgp X:X::X:X/M",
6841 SHOW_STR
6842 IP_STR
6843 BGP_STR
6844 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6845{
6846 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6847}
6848
paulbb46e942003-10-24 19:02:03 +00006849DEFUN (show_bgp_view,
6850 show_bgp_view_cmd,
6851 "show bgp view WORD",
6852 SHOW_STR
6853 BGP_STR
6854 "BGP view\n"
6855 "View name\n")
6856{
6857 struct bgp *bgp;
6858
6859 /* BGP structure lookup. */
6860 bgp = bgp_lookup_by_name (argv[0]);
6861 if (bgp == NULL)
6862 {
6863 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6864 return CMD_WARNING;
6865 }
6866
ajs5a646652004-11-05 01:25:55 +00006867 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006868}
6869
6870ALIAS (show_bgp_view,
6871 show_bgp_view_ipv6_cmd,
6872 "show bgp view WORD ipv6",
6873 SHOW_STR
6874 BGP_STR
6875 "BGP view\n"
6876 "View name\n"
6877 "Address family\n")
6878
6879DEFUN (show_bgp_view_route,
6880 show_bgp_view_route_cmd,
6881 "show bgp view WORD X:X::X:X",
6882 SHOW_STR
6883 BGP_STR
6884 "BGP view\n"
6885 "View name\n"
6886 "Network in the BGP routing table to display\n")
6887{
6888 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6889}
6890
6891ALIAS (show_bgp_view_route,
6892 show_bgp_view_ipv6_route_cmd,
6893 "show bgp view WORD ipv6 X:X::X:X",
6894 SHOW_STR
6895 BGP_STR
6896 "BGP view\n"
6897 "View name\n"
6898 "Address family\n"
6899 "Network in the BGP routing table to display\n")
6900
6901DEFUN (show_bgp_view_prefix,
6902 show_bgp_view_prefix_cmd,
6903 "show bgp view WORD X:X::X:X/M",
6904 SHOW_STR
6905 BGP_STR
6906 "BGP view\n"
6907 "View name\n"
6908 "IPv6 prefix <network>/<length>\n")
6909{
6910 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6911}
6912
6913ALIAS (show_bgp_view_prefix,
6914 show_bgp_view_ipv6_prefix_cmd,
6915 "show bgp view WORD ipv6 X:X::X:X/M",
6916 SHOW_STR
6917 BGP_STR
6918 "BGP view\n"
6919 "View name\n"
6920 "Address family\n"
6921 "IPv6 prefix <network>/<length>\n")
6922
paul718e3742002-12-13 20:15:29 +00006923/* old command */
6924DEFUN (show_ipv6_mbgp,
6925 show_ipv6_mbgp_cmd,
6926 "show ipv6 mbgp",
6927 SHOW_STR
6928 IP_STR
6929 MBGP_STR)
6930{
ajs5a646652004-11-05 01:25:55 +00006931 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6932 NULL);
paul718e3742002-12-13 20:15:29 +00006933}
6934
6935/* old command */
6936DEFUN (show_ipv6_mbgp_route,
6937 show_ipv6_mbgp_route_cmd,
6938 "show ipv6 mbgp X:X::X:X",
6939 SHOW_STR
6940 IP_STR
6941 MBGP_STR
6942 "Network in the MBGP routing table to display\n")
6943{
6944 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6945}
6946
6947/* old command */
6948DEFUN (show_ipv6_mbgp_prefix,
6949 show_ipv6_mbgp_prefix_cmd,
6950 "show ipv6 mbgp X:X::X:X/M",
6951 SHOW_STR
6952 IP_STR
6953 MBGP_STR
6954 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6955{
6956 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6957}
6958#endif
6959
paul718e3742002-12-13 20:15:29 +00006960
paul94f2b392005-06-28 12:44:16 +00006961static int
paulfd79ac92004-10-13 05:06:08 +00006962bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006963 safi_t safi, enum bgp_show_type type)
6964{
6965 int i;
6966 struct buffer *b;
6967 char *regstr;
6968 int first;
6969 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006970 int rc;
paul718e3742002-12-13 20:15:29 +00006971
6972 first = 0;
6973 b = buffer_new (1024);
6974 for (i = 0; i < argc; i++)
6975 {
6976 if (first)
6977 buffer_putc (b, ' ');
6978 else
6979 {
6980 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6981 continue;
6982 first = 1;
6983 }
6984
6985 buffer_putstr (b, argv[i]);
6986 }
6987 buffer_putc (b, '\0');
6988
6989 regstr = buffer_getstr (b);
6990 buffer_free (b);
6991
6992 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006993 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006994 if (! regex)
6995 {
6996 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6997 VTY_NEWLINE);
6998 return CMD_WARNING;
6999 }
7000
ajs5a646652004-11-05 01:25:55 +00007001 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7002 bgp_regex_free (regex);
7003 return rc;
paul718e3742002-12-13 20:15:29 +00007004}
7005
7006DEFUN (show_ip_bgp_regexp,
7007 show_ip_bgp_regexp_cmd,
7008 "show ip bgp regexp .LINE",
7009 SHOW_STR
7010 IP_STR
7011 BGP_STR
7012 "Display routes matching the AS path regular expression\n"
7013 "A regular-expression to match the BGP AS paths\n")
7014{
7015 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7016 bgp_show_type_regexp);
7017}
7018
7019DEFUN (show_ip_bgp_flap_regexp,
7020 show_ip_bgp_flap_regexp_cmd,
7021 "show ip bgp flap-statistics regexp .LINE",
7022 SHOW_STR
7023 IP_STR
7024 BGP_STR
7025 "Display flap statistics of routes\n"
7026 "Display routes matching the AS path regular expression\n"
7027 "A regular-expression to match the BGP AS paths\n")
7028{
7029 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7030 bgp_show_type_flap_regexp);
7031}
7032
7033DEFUN (show_ip_bgp_ipv4_regexp,
7034 show_ip_bgp_ipv4_regexp_cmd,
7035 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7036 SHOW_STR
7037 IP_STR
7038 BGP_STR
7039 "Address family\n"
7040 "Address Family modifier\n"
7041 "Address Family modifier\n"
7042 "Display routes matching the AS path regular expression\n"
7043 "A regular-expression to match the BGP AS paths\n")
7044{
7045 if (strncmp (argv[0], "m", 1) == 0)
7046 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7047 bgp_show_type_regexp);
7048
7049 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7050 bgp_show_type_regexp);
7051}
7052
7053#ifdef HAVE_IPV6
7054DEFUN (show_bgp_regexp,
7055 show_bgp_regexp_cmd,
7056 "show bgp regexp .LINE",
7057 SHOW_STR
7058 BGP_STR
7059 "Display routes matching the AS path regular expression\n"
7060 "A regular-expression to match the BGP AS paths\n")
7061{
7062 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7063 bgp_show_type_regexp);
7064}
7065
7066ALIAS (show_bgp_regexp,
7067 show_bgp_ipv6_regexp_cmd,
7068 "show bgp ipv6 regexp .LINE",
7069 SHOW_STR
7070 BGP_STR
7071 "Address family\n"
7072 "Display routes matching the AS path regular expression\n"
7073 "A regular-expression to match the BGP AS paths\n")
7074
7075/* old command */
7076DEFUN (show_ipv6_bgp_regexp,
7077 show_ipv6_bgp_regexp_cmd,
7078 "show ipv6 bgp regexp .LINE",
7079 SHOW_STR
7080 IP_STR
7081 BGP_STR
7082 "Display routes matching the AS path regular expression\n"
7083 "A regular-expression to match the BGP AS paths\n")
7084{
7085 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7086 bgp_show_type_regexp);
7087}
7088
7089/* old command */
7090DEFUN (show_ipv6_mbgp_regexp,
7091 show_ipv6_mbgp_regexp_cmd,
7092 "show ipv6 mbgp regexp .LINE",
7093 SHOW_STR
7094 IP_STR
7095 BGP_STR
7096 "Display routes matching the AS path regular expression\n"
7097 "A regular-expression to match the MBGP AS paths\n")
7098{
7099 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7100 bgp_show_type_regexp);
7101}
7102#endif /* HAVE_IPV6 */
7103
paul94f2b392005-06-28 12:44:16 +00007104static int
paulfd79ac92004-10-13 05:06:08 +00007105bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007106 safi_t safi, enum bgp_show_type type)
7107{
7108 struct prefix_list *plist;
7109
7110 plist = prefix_list_lookup (afi, prefix_list_str);
7111 if (plist == NULL)
7112 {
7113 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7114 prefix_list_str, VTY_NEWLINE);
7115 return CMD_WARNING;
7116 }
7117
ajs5a646652004-11-05 01:25:55 +00007118 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007119}
7120
7121DEFUN (show_ip_bgp_prefix_list,
7122 show_ip_bgp_prefix_list_cmd,
7123 "show ip bgp prefix-list WORD",
7124 SHOW_STR
7125 IP_STR
7126 BGP_STR
7127 "Display routes conforming to the prefix-list\n"
7128 "IP prefix-list name\n")
7129{
7130 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7131 bgp_show_type_prefix_list);
7132}
7133
7134DEFUN (show_ip_bgp_flap_prefix_list,
7135 show_ip_bgp_flap_prefix_list_cmd,
7136 "show ip bgp flap-statistics prefix-list WORD",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "Display flap statistics of routes\n"
7141 "Display routes conforming to the prefix-list\n"
7142 "IP prefix-list name\n")
7143{
7144 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7145 bgp_show_type_flap_prefix_list);
7146}
7147
7148DEFUN (show_ip_bgp_ipv4_prefix_list,
7149 show_ip_bgp_ipv4_prefix_list_cmd,
7150 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Address family\n"
7155 "Address Family modifier\n"
7156 "Address Family modifier\n"
7157 "Display routes conforming to the prefix-list\n"
7158 "IP prefix-list name\n")
7159{
7160 if (strncmp (argv[0], "m", 1) == 0)
7161 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7162 bgp_show_type_prefix_list);
7163
7164 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7165 bgp_show_type_prefix_list);
7166}
7167
7168#ifdef HAVE_IPV6
7169DEFUN (show_bgp_prefix_list,
7170 show_bgp_prefix_list_cmd,
7171 "show bgp prefix-list WORD",
7172 SHOW_STR
7173 BGP_STR
7174 "Display routes conforming to the prefix-list\n"
7175 "IPv6 prefix-list name\n")
7176{
7177 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7178 bgp_show_type_prefix_list);
7179}
7180
7181ALIAS (show_bgp_prefix_list,
7182 show_bgp_ipv6_prefix_list_cmd,
7183 "show bgp ipv6 prefix-list WORD",
7184 SHOW_STR
7185 BGP_STR
7186 "Address family\n"
7187 "Display routes conforming to the prefix-list\n"
7188 "IPv6 prefix-list name\n")
7189
7190/* old command */
7191DEFUN (show_ipv6_bgp_prefix_list,
7192 show_ipv6_bgp_prefix_list_cmd,
7193 "show ipv6 bgp prefix-list WORD",
7194 SHOW_STR
7195 IPV6_STR
7196 BGP_STR
7197 "Display routes matching the prefix-list\n"
7198 "IPv6 prefix-list name\n")
7199{
7200 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7201 bgp_show_type_prefix_list);
7202}
7203
7204/* old command */
7205DEFUN (show_ipv6_mbgp_prefix_list,
7206 show_ipv6_mbgp_prefix_list_cmd,
7207 "show ipv6 mbgp prefix-list WORD",
7208 SHOW_STR
7209 IPV6_STR
7210 MBGP_STR
7211 "Display routes matching the prefix-list\n"
7212 "IPv6 prefix-list name\n")
7213{
7214 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7215 bgp_show_type_prefix_list);
7216}
7217#endif /* HAVE_IPV6 */
7218
paul94f2b392005-06-28 12:44:16 +00007219static int
paulfd79ac92004-10-13 05:06:08 +00007220bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007221 safi_t safi, enum bgp_show_type type)
7222{
7223 struct as_list *as_list;
7224
7225 as_list = as_list_lookup (filter);
7226 if (as_list == NULL)
7227 {
7228 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7229 return CMD_WARNING;
7230 }
7231
ajs5a646652004-11-05 01:25:55 +00007232 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007233}
7234
7235DEFUN (show_ip_bgp_filter_list,
7236 show_ip_bgp_filter_list_cmd,
7237 "show ip bgp filter-list WORD",
7238 SHOW_STR
7239 IP_STR
7240 BGP_STR
7241 "Display routes conforming to the filter-list\n"
7242 "Regular expression access list name\n")
7243{
7244 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7245 bgp_show_type_filter_list);
7246}
7247
7248DEFUN (show_ip_bgp_flap_filter_list,
7249 show_ip_bgp_flap_filter_list_cmd,
7250 "show ip bgp flap-statistics filter-list WORD",
7251 SHOW_STR
7252 IP_STR
7253 BGP_STR
7254 "Display flap statistics of routes\n"
7255 "Display routes conforming to the filter-list\n"
7256 "Regular expression access list name\n")
7257{
7258 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7259 bgp_show_type_flap_filter_list);
7260}
7261
7262DEFUN (show_ip_bgp_ipv4_filter_list,
7263 show_ip_bgp_ipv4_filter_list_cmd,
7264 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7265 SHOW_STR
7266 IP_STR
7267 BGP_STR
7268 "Address family\n"
7269 "Address Family modifier\n"
7270 "Address Family modifier\n"
7271 "Display routes conforming to the filter-list\n"
7272 "Regular expression access list name\n")
7273{
7274 if (strncmp (argv[0], "m", 1) == 0)
7275 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7276 bgp_show_type_filter_list);
7277
7278 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7279 bgp_show_type_filter_list);
7280}
7281
7282#ifdef HAVE_IPV6
7283DEFUN (show_bgp_filter_list,
7284 show_bgp_filter_list_cmd,
7285 "show bgp filter-list WORD",
7286 SHOW_STR
7287 BGP_STR
7288 "Display routes conforming to the filter-list\n"
7289 "Regular expression access list name\n")
7290{
7291 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7292 bgp_show_type_filter_list);
7293}
7294
7295ALIAS (show_bgp_filter_list,
7296 show_bgp_ipv6_filter_list_cmd,
7297 "show bgp ipv6 filter-list WORD",
7298 SHOW_STR
7299 BGP_STR
7300 "Address family\n"
7301 "Display routes conforming to the filter-list\n"
7302 "Regular expression access list name\n")
7303
7304/* old command */
7305DEFUN (show_ipv6_bgp_filter_list,
7306 show_ipv6_bgp_filter_list_cmd,
7307 "show ipv6 bgp filter-list WORD",
7308 SHOW_STR
7309 IPV6_STR
7310 BGP_STR
7311 "Display routes conforming to the filter-list\n"
7312 "Regular expression access list name\n")
7313{
7314 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7315 bgp_show_type_filter_list);
7316}
7317
7318/* old command */
7319DEFUN (show_ipv6_mbgp_filter_list,
7320 show_ipv6_mbgp_filter_list_cmd,
7321 "show ipv6 mbgp filter-list WORD",
7322 SHOW_STR
7323 IPV6_STR
7324 MBGP_STR
7325 "Display routes conforming to the filter-list\n"
7326 "Regular expression access list name\n")
7327{
7328 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7329 bgp_show_type_filter_list);
7330}
7331#endif /* HAVE_IPV6 */
7332
paul94f2b392005-06-28 12:44:16 +00007333static int
paulfd79ac92004-10-13 05:06:08 +00007334bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007335 safi_t safi, enum bgp_show_type type)
7336{
7337 struct route_map *rmap;
7338
7339 rmap = route_map_lookup_by_name (rmap_str);
7340 if (! rmap)
7341 {
7342 vty_out (vty, "%% %s is not a valid route-map name%s",
7343 rmap_str, VTY_NEWLINE);
7344 return CMD_WARNING;
7345 }
7346
ajs5a646652004-11-05 01:25:55 +00007347 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007348}
7349
7350DEFUN (show_ip_bgp_route_map,
7351 show_ip_bgp_route_map_cmd,
7352 "show ip bgp route-map WORD",
7353 SHOW_STR
7354 IP_STR
7355 BGP_STR
7356 "Display routes matching the route-map\n"
7357 "A route-map to match on\n")
7358{
7359 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7360 bgp_show_type_route_map);
7361}
7362
7363DEFUN (show_ip_bgp_flap_route_map,
7364 show_ip_bgp_flap_route_map_cmd,
7365 "show ip bgp flap-statistics route-map WORD",
7366 SHOW_STR
7367 IP_STR
7368 BGP_STR
7369 "Display flap statistics of routes\n"
7370 "Display routes matching the route-map\n"
7371 "A route-map to match on\n")
7372{
7373 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7374 bgp_show_type_flap_route_map);
7375}
7376
7377DEFUN (show_ip_bgp_ipv4_route_map,
7378 show_ip_bgp_ipv4_route_map_cmd,
7379 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7380 SHOW_STR
7381 IP_STR
7382 BGP_STR
7383 "Address family\n"
7384 "Address Family modifier\n"
7385 "Address Family modifier\n"
7386 "Display routes matching the route-map\n"
7387 "A route-map to match on\n")
7388{
7389 if (strncmp (argv[0], "m", 1) == 0)
7390 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7391 bgp_show_type_route_map);
7392
7393 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7394 bgp_show_type_route_map);
7395}
7396
7397DEFUN (show_bgp_route_map,
7398 show_bgp_route_map_cmd,
7399 "show bgp route-map WORD",
7400 SHOW_STR
7401 BGP_STR
7402 "Display routes matching the route-map\n"
7403 "A route-map to match on\n")
7404{
7405 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7406 bgp_show_type_route_map);
7407}
7408
7409ALIAS (show_bgp_route_map,
7410 show_bgp_ipv6_route_map_cmd,
7411 "show bgp ipv6 route-map WORD",
7412 SHOW_STR
7413 BGP_STR
7414 "Address family\n"
7415 "Display routes matching the route-map\n"
7416 "A route-map to match on\n")
7417
7418DEFUN (show_ip_bgp_cidr_only,
7419 show_ip_bgp_cidr_only_cmd,
7420 "show ip bgp cidr-only",
7421 SHOW_STR
7422 IP_STR
7423 BGP_STR
7424 "Display only routes with non-natural netmasks\n")
7425{
7426 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007427 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007428}
7429
7430DEFUN (show_ip_bgp_flap_cidr_only,
7431 show_ip_bgp_flap_cidr_only_cmd,
7432 "show ip bgp flap-statistics cidr-only",
7433 SHOW_STR
7434 IP_STR
7435 BGP_STR
7436 "Display flap statistics of routes\n"
7437 "Display only routes with non-natural netmasks\n")
7438{
7439 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007440 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007441}
7442
7443DEFUN (show_ip_bgp_ipv4_cidr_only,
7444 show_ip_bgp_ipv4_cidr_only_cmd,
7445 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7446 SHOW_STR
7447 IP_STR
7448 BGP_STR
7449 "Address family\n"
7450 "Address Family modifier\n"
7451 "Address Family modifier\n"
7452 "Display only routes with non-natural netmasks\n")
7453{
7454 if (strncmp (argv[0], "m", 1) == 0)
7455 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007456 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007457
7458 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007459 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007460}
7461
7462DEFUN (show_ip_bgp_community_all,
7463 show_ip_bgp_community_all_cmd,
7464 "show ip bgp community",
7465 SHOW_STR
7466 IP_STR
7467 BGP_STR
7468 "Display routes matching the communities\n")
7469{
7470 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007471 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007472}
7473
7474DEFUN (show_ip_bgp_ipv4_community_all,
7475 show_ip_bgp_ipv4_community_all_cmd,
7476 "show ip bgp ipv4 (unicast|multicast) community",
7477 SHOW_STR
7478 IP_STR
7479 BGP_STR
7480 "Address family\n"
7481 "Address Family modifier\n"
7482 "Address Family modifier\n"
7483 "Display routes matching the communities\n")
7484{
7485 if (strncmp (argv[0], "m", 1) == 0)
7486 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007487 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007488
7489 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007490 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007491}
7492
7493#ifdef HAVE_IPV6
7494DEFUN (show_bgp_community_all,
7495 show_bgp_community_all_cmd,
7496 "show bgp community",
7497 SHOW_STR
7498 BGP_STR
7499 "Display routes matching the communities\n")
7500{
7501 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007502 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007503}
7504
7505ALIAS (show_bgp_community_all,
7506 show_bgp_ipv6_community_all_cmd,
7507 "show bgp ipv6 community",
7508 SHOW_STR
7509 BGP_STR
7510 "Address family\n"
7511 "Display routes matching the communities\n")
7512
7513/* old command */
7514DEFUN (show_ipv6_bgp_community_all,
7515 show_ipv6_bgp_community_all_cmd,
7516 "show ipv6 bgp community",
7517 SHOW_STR
7518 IPV6_STR
7519 BGP_STR
7520 "Display routes matching the communities\n")
7521{
7522 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007523 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007524}
7525
7526/* old command */
7527DEFUN (show_ipv6_mbgp_community_all,
7528 show_ipv6_mbgp_community_all_cmd,
7529 "show ipv6 mbgp community",
7530 SHOW_STR
7531 IPV6_STR
7532 MBGP_STR
7533 "Display routes matching the communities\n")
7534{
7535 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007536 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007537}
7538#endif /* HAVE_IPV6 */
7539
paul94f2b392005-06-28 12:44:16 +00007540static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007541bgp_show_community (struct vty *vty, const char *view_name, int argc,
7542 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007543{
7544 struct community *com;
7545 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007546 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007547 int i;
7548 char *str;
7549 int first = 0;
7550
Michael Lambert95cbbd22010-07-23 14:43:04 -04007551 /* BGP structure lookup */
7552 if (view_name)
7553 {
7554 bgp = bgp_lookup_by_name (view_name);
7555 if (bgp == NULL)
7556 {
7557 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7558 return CMD_WARNING;
7559 }
7560 }
7561 else
7562 {
7563 bgp = bgp_get_default ();
7564 if (bgp == NULL)
7565 {
7566 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7567 return CMD_WARNING;
7568 }
7569 }
7570
paul718e3742002-12-13 20:15:29 +00007571 b = buffer_new (1024);
7572 for (i = 0; i < argc; i++)
7573 {
7574 if (first)
7575 buffer_putc (b, ' ');
7576 else
7577 {
7578 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7579 continue;
7580 first = 1;
7581 }
7582
7583 buffer_putstr (b, argv[i]);
7584 }
7585 buffer_putc (b, '\0');
7586
7587 str = buffer_getstr (b);
7588 buffer_free (b);
7589
7590 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007591 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007592 if (! com)
7593 {
7594 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7595 return CMD_WARNING;
7596 }
7597
Michael Lambert95cbbd22010-07-23 14:43:04 -04007598 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007599 (exact ? bgp_show_type_community_exact :
7600 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007601}
7602
7603DEFUN (show_ip_bgp_community,
7604 show_ip_bgp_community_cmd,
7605 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7606 SHOW_STR
7607 IP_STR
7608 BGP_STR
7609 "Display routes matching the communities\n"
7610 "community number\n"
7611 "Do not send outside local AS (well-known community)\n"
7612 "Do not advertise to any peer (well-known community)\n"
7613 "Do not export to next AS (well-known community)\n")
7614{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007615 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007616}
7617
7618ALIAS (show_ip_bgp_community,
7619 show_ip_bgp_community2_cmd,
7620 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7621 SHOW_STR
7622 IP_STR
7623 BGP_STR
7624 "Display routes matching the communities\n"
7625 "community number\n"
7626 "Do not send outside local AS (well-known community)\n"
7627 "Do not advertise to any peer (well-known community)\n"
7628 "Do not export to next AS (well-known community)\n"
7629 "community number\n"
7630 "Do not send outside local AS (well-known community)\n"
7631 "Do not advertise to any peer (well-known community)\n"
7632 "Do not export to next AS (well-known community)\n")
7633
7634ALIAS (show_ip_bgp_community,
7635 show_ip_bgp_community3_cmd,
7636 "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)",
7637 SHOW_STR
7638 IP_STR
7639 BGP_STR
7640 "Display routes matching the communities\n"
7641 "community number\n"
7642 "Do not send outside local AS (well-known community)\n"
7643 "Do not advertise to any peer (well-known community)\n"
7644 "Do not export to next AS (well-known community)\n"
7645 "community number\n"
7646 "Do not send outside local AS (well-known community)\n"
7647 "Do not advertise to any peer (well-known community)\n"
7648 "Do not export to next AS (well-known community)\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n")
7653
7654ALIAS (show_ip_bgp_community,
7655 show_ip_bgp_community4_cmd,
7656 "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)",
7657 SHOW_STR
7658 IP_STR
7659 BGP_STR
7660 "Display routes matching the communities\n"
7661 "community number\n"
7662 "Do not send outside local AS (well-known community)\n"
7663 "Do not advertise to any peer (well-known community)\n"
7664 "Do not export to next AS (well-known community)\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\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
7678DEFUN (show_ip_bgp_ipv4_community,
7679 show_ip_bgp_ipv4_community_cmd,
7680 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7681 SHOW_STR
7682 IP_STR
7683 BGP_STR
7684 "Address family\n"
7685 "Address Family modifier\n"
7686 "Address Family modifier\n"
7687 "Display routes matching the communities\n"
7688 "community number\n"
7689 "Do not send outside local AS (well-known community)\n"
7690 "Do not advertise to any peer (well-known community)\n"
7691 "Do not export to next AS (well-known community)\n")
7692{
7693 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007694 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007695
Michael Lambert95cbbd22010-07-23 14:43:04 -04007696 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007697}
7698
7699ALIAS (show_ip_bgp_ipv4_community,
7700 show_ip_bgp_ipv4_community2_cmd,
7701 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7702 SHOW_STR
7703 IP_STR
7704 BGP_STR
7705 "Address family\n"
7706 "Address Family modifier\n"
7707 "Address Family modifier\n"
7708 "Display routes matching the communities\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n")
7717
7718ALIAS (show_ip_bgp_ipv4_community,
7719 show_ip_bgp_ipv4_community3_cmd,
7720 "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)",
7721 SHOW_STR
7722 IP_STR
7723 BGP_STR
7724 "Address family\n"
7725 "Address Family modifier\n"
7726 "Address Family modifier\n"
7727 "Display routes matching the communities\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n")
7740
7741ALIAS (show_ip_bgp_ipv4_community,
7742 show_ip_bgp_ipv4_community4_cmd,
7743 "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)",
7744 SHOW_STR
7745 IP_STR
7746 BGP_STR
7747 "Address family\n"
7748 "Address Family modifier\n"
7749 "Address Family modifier\n"
7750 "Display routes matching the communities\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n"
7759 "community number\n"
7760 "Do not send outside local AS (well-known community)\n"
7761 "Do not advertise to any peer (well-known community)\n"
7762 "Do not export to next AS (well-known community)\n"
7763 "community number\n"
7764 "Do not send outside local AS (well-known community)\n"
7765 "Do not advertise to any peer (well-known community)\n"
7766 "Do not export to next AS (well-known community)\n")
7767
Michael Lambert95cbbd22010-07-23 14:43:04 -04007768DEFUN (show_bgp_view_afi_safi_community_all,
7769 show_bgp_view_afi_safi_community_all_cmd,
7770#ifdef HAVE_IPV6
7771 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7772#else
7773 "show bgp view WORD ipv4 (unicast|multicast) community",
7774#endif
7775 SHOW_STR
7776 BGP_STR
7777 "BGP view\n"
7778 "BGP view name\n"
7779 "Address family\n"
7780#ifdef HAVE_IPV6
7781 "Address family\n"
7782#endif
7783 "Address Family modifier\n"
7784 "Address Family modifier\n"
7785 "Display routes containing communities\n")
7786{
7787 int afi;
7788 int safi;
7789 struct bgp *bgp;
7790
7791 /* BGP structure lookup. */
7792 bgp = bgp_lookup_by_name (argv[0]);
7793 if (bgp == NULL)
7794 {
7795 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7796 return CMD_WARNING;
7797 }
7798
7799#ifdef HAVE_IPV6
7800 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7801 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7802#else
7803 afi = AFI_IP;
7804 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7805#endif
7806 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7807}
7808
7809DEFUN (show_bgp_view_afi_safi_community,
7810 show_bgp_view_afi_safi_community_cmd,
7811#ifdef HAVE_IPV6
7812 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7813#else
7814 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7815#endif
7816 SHOW_STR
7817 BGP_STR
7818 "BGP view\n"
7819 "BGP view name\n"
7820 "Address family\n"
7821#ifdef HAVE_IPV6
7822 "Address family\n"
7823#endif
7824 "Address family modifier\n"
7825 "Address family modifier\n"
7826 "Display routes matching the communities\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n")
7831{
7832 int afi;
7833 int safi;
7834
7835#ifdef HAVE_IPV6
7836 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7837 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7838 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7839#else
7840 afi = AFI_IP;
7841 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7842 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7843#endif
7844}
7845
7846ALIAS (show_bgp_view_afi_safi_community,
7847 show_bgp_view_afi_safi_community2_cmd,
7848#ifdef HAVE_IPV6
7849 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7850#else
7851 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7852#endif
7853 SHOW_STR
7854 BGP_STR
7855 "BGP view\n"
7856 "BGP view name\n"
7857 "Address family\n"
7858#ifdef HAVE_IPV6
7859 "Address family\n"
7860#endif
7861 "Address family modifier\n"
7862 "Address family modifier\n"
7863 "Display routes matching the communities\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n")
7872
7873ALIAS (show_bgp_view_afi_safi_community,
7874 show_bgp_view_afi_safi_community3_cmd,
7875#ifdef HAVE_IPV6
7876 "show bgp view WORD (ipv4|ipv6) (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)",
7877#else
7878 "show bgp view WORD 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)",
7879#endif
7880 SHOW_STR
7881 BGP_STR
7882 "BGP view\n"
7883 "BGP view name\n"
7884 "Address family\n"
7885#ifdef HAVE_IPV6
7886 "Address family\n"
7887#endif
7888 "Address family modifier\n"
7889 "Address family modifier\n"
7890 "Display routes matching the communities\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n")
7903
7904ALIAS (show_bgp_view_afi_safi_community,
7905 show_bgp_view_afi_safi_community4_cmd,
7906#ifdef HAVE_IPV6
7907 "show bgp view WORD (ipv4|ipv6) (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)",
7908#else
7909 "show bgp view WORD 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)",
7910#endif
7911 SHOW_STR
7912 BGP_STR
7913 "BGP view\n"
7914 "BGP view name\n"
7915 "Address family\n"
7916#ifdef HAVE_IPV6
7917 "Address family\n"
7918#endif
7919 "Address family modifier\n"
7920 "Address family modifier\n"
7921 "Display routes matching the communities\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n"
7930 "community number\n"
7931 "Do not send outside local AS (well-known community)\n"
7932 "Do not advertise to any peer (well-known community)\n"
7933 "Do not export to next AS (well-known community)\n"
7934 "community number\n"
7935 "Do not send outside local AS (well-known community)\n"
7936 "Do not advertise to any peer (well-known community)\n"
7937 "Do not export to next AS (well-known community)\n")
7938
paul718e3742002-12-13 20:15:29 +00007939DEFUN (show_ip_bgp_community_exact,
7940 show_ip_bgp_community_exact_cmd,
7941 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7942 SHOW_STR
7943 IP_STR
7944 BGP_STR
7945 "Display routes matching the communities\n"
7946 "community number\n"
7947 "Do not send outside local AS (well-known community)\n"
7948 "Do not advertise to any peer (well-known community)\n"
7949 "Do not export to next AS (well-known community)\n"
7950 "Exact match of the communities")
7951{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007952 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007953}
7954
7955ALIAS (show_ip_bgp_community_exact,
7956 show_ip_bgp_community2_exact_cmd,
7957 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7958 SHOW_STR
7959 IP_STR
7960 BGP_STR
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "Exact match of the communities")
7971
7972ALIAS (show_ip_bgp_community_exact,
7973 show_ip_bgp_community3_exact_cmd,
7974 "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",
7975 SHOW_STR
7976 IP_STR
7977 BGP_STR
7978 "Display routes matching the communities\n"
7979 "community number\n"
7980 "Do not send outside local AS (well-known community)\n"
7981 "Do not advertise to any peer (well-known community)\n"
7982 "Do not export to next AS (well-known community)\n"
7983 "community number\n"
7984 "Do not send outside local AS (well-known community)\n"
7985 "Do not advertise to any peer (well-known community)\n"
7986 "Do not export to next AS (well-known community)\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "Exact match of the communities")
7992
7993ALIAS (show_ip_bgp_community_exact,
7994 show_ip_bgp_community4_exact_cmd,
7995 "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",
7996 SHOW_STR
7997 IP_STR
7998 BGP_STR
7999 "Display routes matching the communities\n"
8000 "community number\n"
8001 "Do not send outside local AS (well-known community)\n"
8002 "Do not advertise to any peer (well-known community)\n"
8003 "Do not export to next AS (well-known community)\n"
8004 "community number\n"
8005 "Do not send outside local AS (well-known community)\n"
8006 "Do not advertise to any peer (well-known community)\n"
8007 "Do not export to next AS (well-known community)\n"
8008 "community number\n"
8009 "Do not send outside local AS (well-known community)\n"
8010 "Do not advertise to any peer (well-known community)\n"
8011 "Do not export to next AS (well-known community)\n"
8012 "community number\n"
8013 "Do not send outside local AS (well-known community)\n"
8014 "Do not advertise to any peer (well-known community)\n"
8015 "Do not export to next AS (well-known community)\n"
8016 "Exact match of the communities")
8017
8018DEFUN (show_ip_bgp_ipv4_community_exact,
8019 show_ip_bgp_ipv4_community_exact_cmd,
8020 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8021 SHOW_STR
8022 IP_STR
8023 BGP_STR
8024 "Address family\n"
8025 "Address Family modifier\n"
8026 "Address Family modifier\n"
8027 "Display routes matching the communities\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n"
8032 "Exact match of the communities")
8033{
8034 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008035 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008036
Michael Lambert95cbbd22010-07-23 14:43:04 -04008037 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008038}
8039
8040ALIAS (show_ip_bgp_ipv4_community_exact,
8041 show_ip_bgp_ipv4_community2_exact_cmd,
8042 "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",
8043 SHOW_STR
8044 IP_STR
8045 BGP_STR
8046 "Address family\n"
8047 "Address Family modifier\n"
8048 "Address Family modifier\n"
8049 "Display routes matching the communities\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "Exact match of the communities")
8059
8060ALIAS (show_ip_bgp_ipv4_community_exact,
8061 show_ip_bgp_ipv4_community3_exact_cmd,
8062 "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",
8063 SHOW_STR
8064 IP_STR
8065 BGP_STR
8066 "Address family\n"
8067 "Address Family modifier\n"
8068 "Address Family modifier\n"
8069 "Display routes matching the communities\n"
8070 "community number\n"
8071 "Do not send outside local AS (well-known community)\n"
8072 "Do not advertise to any peer (well-known community)\n"
8073 "Do not export to next AS (well-known community)\n"
8074 "community number\n"
8075 "Do not send outside local AS (well-known community)\n"
8076 "Do not advertise to any peer (well-known community)\n"
8077 "Do not export to next AS (well-known community)\n"
8078 "community number\n"
8079 "Do not send outside local AS (well-known community)\n"
8080 "Do not advertise to any peer (well-known community)\n"
8081 "Do not export to next AS (well-known community)\n"
8082 "Exact match of the communities")
8083
8084ALIAS (show_ip_bgp_ipv4_community_exact,
8085 show_ip_bgp_ipv4_community4_exact_cmd,
8086 "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",
8087 SHOW_STR
8088 IP_STR
8089 BGP_STR
8090 "Address family\n"
8091 "Address Family modifier\n"
8092 "Address Family modifier\n"
8093 "Display routes matching the communities\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "community number\n"
8103 "Do not send outside local AS (well-known community)\n"
8104 "Do not advertise to any peer (well-known community)\n"
8105 "Do not export to next AS (well-known community)\n"
8106 "community number\n"
8107 "Do not send outside local AS (well-known community)\n"
8108 "Do not advertise to any peer (well-known community)\n"
8109 "Do not export to next AS (well-known community)\n"
8110 "Exact match of the communities")
8111
8112#ifdef HAVE_IPV6
8113DEFUN (show_bgp_community,
8114 show_bgp_community_cmd,
8115 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8116 SHOW_STR
8117 BGP_STR
8118 "Display routes matching the communities\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n")
8123{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008124 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008125}
8126
8127ALIAS (show_bgp_community,
8128 show_bgp_ipv6_community_cmd,
8129 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8130 SHOW_STR
8131 BGP_STR
8132 "Address family\n"
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n")
8138
8139ALIAS (show_bgp_community,
8140 show_bgp_community2_cmd,
8141 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8142 SHOW_STR
8143 BGP_STR
8144 "Display routes matching the communities\n"
8145 "community number\n"
8146 "Do not send outside local AS (well-known community)\n"
8147 "Do not advertise to any peer (well-known community)\n"
8148 "Do not export to next AS (well-known community)\n"
8149 "community number\n"
8150 "Do not send outside local AS (well-known community)\n"
8151 "Do not advertise to any peer (well-known community)\n"
8152 "Do not export to next AS (well-known community)\n")
8153
8154ALIAS (show_bgp_community,
8155 show_bgp_ipv6_community2_cmd,
8156 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8157 SHOW_STR
8158 BGP_STR
8159 "Address family\n"
8160 "Display routes matching the communities\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\n"
8165 "community number\n"
8166 "Do not send outside local AS (well-known community)\n"
8167 "Do not advertise to any peer (well-known community)\n"
8168 "Do not export to next AS (well-known community)\n")
8169
8170ALIAS (show_bgp_community,
8171 show_bgp_community3_cmd,
8172 "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)",
8173 SHOW_STR
8174 BGP_STR
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n")
8188
8189ALIAS (show_bgp_community,
8190 show_bgp_ipv6_community3_cmd,
8191 "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)",
8192 SHOW_STR
8193 BGP_STR
8194 "Address family\n"
8195 "Display routes matching the communities\n"
8196 "community number\n"
8197 "Do not send outside local AS (well-known community)\n"
8198 "Do not advertise to any peer (well-known community)\n"
8199 "Do not export to next AS (well-known community)\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\n"
8204 "community number\n"
8205 "Do not send outside local AS (well-known community)\n"
8206 "Do not advertise to any peer (well-known community)\n"
8207 "Do not export to next AS (well-known community)\n")
8208
8209ALIAS (show_bgp_community,
8210 show_bgp_community4_cmd,
8211 "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)",
8212 SHOW_STR
8213 BGP_STR
8214 "Display routes matching the communities\n"
8215 "community number\n"
8216 "Do not send outside local AS (well-known community)\n"
8217 "Do not advertise to any peer (well-known community)\n"
8218 "Do not export to next AS (well-known community)\n"
8219 "community number\n"
8220 "Do not send outside local AS (well-known community)\n"
8221 "Do not advertise to any peer (well-known community)\n"
8222 "Do not export to next AS (well-known community)\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n")
8231
8232ALIAS (show_bgp_community,
8233 show_bgp_ipv6_community4_cmd,
8234 "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)",
8235 SHOW_STR
8236 BGP_STR
8237 "Address family\n"
8238 "Display routes matching the communities\n"
8239 "community number\n"
8240 "Do not send outside local AS (well-known community)\n"
8241 "Do not advertise to any peer (well-known community)\n"
8242 "Do not export to next AS (well-known community)\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 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n")
8255
8256/* old command */
8257DEFUN (show_ipv6_bgp_community,
8258 show_ipv6_bgp_community_cmd,
8259 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8260 SHOW_STR
8261 IPV6_STR
8262 BGP_STR
8263 "Display routes matching the communities\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n")
8268{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008269 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008270}
8271
8272/* old command */
8273ALIAS (show_ipv6_bgp_community,
8274 show_ipv6_bgp_community2_cmd,
8275 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8276 SHOW_STR
8277 IPV6_STR
8278 BGP_STR
8279 "Display routes matching the communities\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n")
8288
8289/* old command */
8290ALIAS (show_ipv6_bgp_community,
8291 show_ipv6_bgp_community3_cmd,
8292 "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)",
8293 SHOW_STR
8294 IPV6_STR
8295 BGP_STR
8296 "Display routes matching the communities\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n")
8309
8310/* old command */
8311ALIAS (show_ipv6_bgp_community,
8312 show_ipv6_bgp_community4_cmd,
8313 "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)",
8314 SHOW_STR
8315 IPV6_STR
8316 BGP_STR
8317 "Display routes matching the communities\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n"
8330 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n")
8334
8335DEFUN (show_bgp_community_exact,
8336 show_bgp_community_exact_cmd,
8337 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8338 SHOW_STR
8339 BGP_STR
8340 "Display routes matching the communities\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "Exact match of the communities")
8346{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008347 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008348}
8349
8350ALIAS (show_bgp_community_exact,
8351 show_bgp_ipv6_community_exact_cmd,
8352 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8353 SHOW_STR
8354 BGP_STR
8355 "Address family\n"
8356 "Display routes matching the communities\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n"
8361 "Exact match of the communities")
8362
8363ALIAS (show_bgp_community_exact,
8364 show_bgp_community2_exact_cmd,
8365 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8366 SHOW_STR
8367 BGP_STR
8368 "Display routes matching the communities\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n"
8373 "community number\n"
8374 "Do not send outside local AS (well-known community)\n"
8375 "Do not advertise to any peer (well-known community)\n"
8376 "Do not export to next AS (well-known community)\n"
8377 "Exact match of the communities")
8378
8379ALIAS (show_bgp_community_exact,
8380 show_bgp_ipv6_community2_exact_cmd,
8381 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8382 SHOW_STR
8383 BGP_STR
8384 "Address family\n"
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 "Exact match of the communities")
8395
8396ALIAS (show_bgp_community_exact,
8397 show_bgp_community3_exact_cmd,
8398 "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",
8399 SHOW_STR
8400 BGP_STR
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n"
8410 "community number\n"
8411 "Do not send outside local AS (well-known community)\n"
8412 "Do not advertise to any peer (well-known community)\n"
8413 "Do not export to next AS (well-known community)\n"
8414 "Exact match of the communities")
8415
8416ALIAS (show_bgp_community_exact,
8417 show_bgp_ipv6_community3_exact_cmd,
8418 "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",
8419 SHOW_STR
8420 BGP_STR
8421 "Address family\n"
8422 "Display routes matching the communities\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n"
8435 "Exact match of the communities")
8436
8437ALIAS (show_bgp_community_exact,
8438 show_bgp_community4_exact_cmd,
8439 "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",
8440 SHOW_STR
8441 BGP_STR
8442 "Display routes matching the communities\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "Exact match of the communities")
8460
8461ALIAS (show_bgp_community_exact,
8462 show_bgp_ipv6_community4_exact_cmd,
8463 "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",
8464 SHOW_STR
8465 BGP_STR
8466 "Address family\n"
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n"
8484 "Exact match of the communities")
8485
8486/* old command */
8487DEFUN (show_ipv6_bgp_community_exact,
8488 show_ipv6_bgp_community_exact_cmd,
8489 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8490 SHOW_STR
8491 IPV6_STR
8492 BGP_STR
8493 "Display routes matching the communities\n"
8494 "community number\n"
8495 "Do not send outside local AS (well-known community)\n"
8496 "Do not advertise to any peer (well-known community)\n"
8497 "Do not export to next AS (well-known community)\n"
8498 "Exact match of the communities")
8499{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008500 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008501}
8502
8503/* old command */
8504ALIAS (show_ipv6_bgp_community_exact,
8505 show_ipv6_bgp_community2_exact_cmd,
8506 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8507 SHOW_STR
8508 IPV6_STR
8509 BGP_STR
8510 "Display routes matching the communities\n"
8511 "community number\n"
8512 "Do not send outside local AS (well-known community)\n"
8513 "Do not advertise to any peer (well-known community)\n"
8514 "Do not export to next AS (well-known community)\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "Exact match of the communities")
8520
8521/* old command */
8522ALIAS (show_ipv6_bgp_community_exact,
8523 show_ipv6_bgp_community3_exact_cmd,
8524 "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",
8525 SHOW_STR
8526 IPV6_STR
8527 BGP_STR
8528 "Display routes matching the communities\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n"
8541 "Exact match of the communities")
8542
8543/* old command */
8544ALIAS (show_ipv6_bgp_community_exact,
8545 show_ipv6_bgp_community4_exact_cmd,
8546 "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",
8547 SHOW_STR
8548 IPV6_STR
8549 BGP_STR
8550 "Display routes matching the communities\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "Exact match of the communities")
8568
8569/* old command */
8570DEFUN (show_ipv6_mbgp_community,
8571 show_ipv6_mbgp_community_cmd,
8572 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8573 SHOW_STR
8574 IPV6_STR
8575 MBGP_STR
8576 "Display routes matching the communities\n"
8577 "community number\n"
8578 "Do not send outside local AS (well-known community)\n"
8579 "Do not advertise to any peer (well-known community)\n"
8580 "Do not export to next AS (well-known community)\n")
8581{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008582 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008583}
8584
8585/* old command */
8586ALIAS (show_ipv6_mbgp_community,
8587 show_ipv6_mbgp_community2_cmd,
8588 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8589 SHOW_STR
8590 IPV6_STR
8591 MBGP_STR
8592 "Display routes matching the communities\n"
8593 "community number\n"
8594 "Do not send outside local AS (well-known community)\n"
8595 "Do not advertise to any peer (well-known community)\n"
8596 "Do not export to next AS (well-known community)\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n")
8601
8602/* old command */
8603ALIAS (show_ipv6_mbgp_community,
8604 show_ipv6_mbgp_community3_cmd,
8605 "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)",
8606 SHOW_STR
8607 IPV6_STR
8608 MBGP_STR
8609 "Display routes matching the communities\n"
8610 "community number\n"
8611 "Do not send outside local AS (well-known community)\n"
8612 "Do not advertise to any peer (well-known community)\n"
8613 "Do not export to next AS (well-known community)\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n")
8622
8623/* old command */
8624ALIAS (show_ipv6_mbgp_community,
8625 show_ipv6_mbgp_community4_cmd,
8626 "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)",
8627 SHOW_STR
8628 IPV6_STR
8629 MBGP_STR
8630 "Display routes matching the communities\n"
8631 "community number\n"
8632 "Do not send outside local AS (well-known community)\n"
8633 "Do not advertise to any peer (well-known community)\n"
8634 "Do not export to next AS (well-known community)\n"
8635 "community number\n"
8636 "Do not send outside local AS (well-known community)\n"
8637 "Do not advertise to any peer (well-known community)\n"
8638 "Do not export to next AS (well-known community)\n"
8639 "community number\n"
8640 "Do not send outside local AS (well-known community)\n"
8641 "Do not advertise to any peer (well-known community)\n"
8642 "Do not export to next AS (well-known community)\n"
8643 "community number\n"
8644 "Do not send outside local AS (well-known community)\n"
8645 "Do not advertise to any peer (well-known community)\n"
8646 "Do not export to next AS (well-known community)\n")
8647
8648/* old command */
8649DEFUN (show_ipv6_mbgp_community_exact,
8650 show_ipv6_mbgp_community_exact_cmd,
8651 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8652 SHOW_STR
8653 IPV6_STR
8654 MBGP_STR
8655 "Display routes matching the communities\n"
8656 "community number\n"
8657 "Do not send outside local AS (well-known community)\n"
8658 "Do not advertise to any peer (well-known community)\n"
8659 "Do not export to next AS (well-known community)\n"
8660 "Exact match of the communities")
8661{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008662 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008663}
8664
8665/* old command */
8666ALIAS (show_ipv6_mbgp_community_exact,
8667 show_ipv6_mbgp_community2_exact_cmd,
8668 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8669 SHOW_STR
8670 IPV6_STR
8671 MBGP_STR
8672 "Display routes matching the communities\n"
8673 "community number\n"
8674 "Do not send outside local AS (well-known community)\n"
8675 "Do not advertise to any peer (well-known community)\n"
8676 "Do not export to next AS (well-known community)\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "Exact match of the communities")
8682
8683/* old command */
8684ALIAS (show_ipv6_mbgp_community_exact,
8685 show_ipv6_mbgp_community3_exact_cmd,
8686 "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",
8687 SHOW_STR
8688 IPV6_STR
8689 MBGP_STR
8690 "Display routes matching the communities\n"
8691 "community number\n"
8692 "Do not send outside local AS (well-known community)\n"
8693 "Do not advertise to any peer (well-known community)\n"
8694 "Do not export to next AS (well-known community)\n"
8695 "community number\n"
8696 "Do not send outside local AS (well-known community)\n"
8697 "Do not advertise to any peer (well-known community)\n"
8698 "Do not export to next AS (well-known community)\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n"
8703 "Exact match of the communities")
8704
8705/* old command */
8706ALIAS (show_ipv6_mbgp_community_exact,
8707 show_ipv6_mbgp_community4_exact_cmd,
8708 "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",
8709 SHOW_STR
8710 IPV6_STR
8711 MBGP_STR
8712 "Display routes matching the communities\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n"
8721 "community number\n"
8722 "Do not send outside local AS (well-known community)\n"
8723 "Do not advertise to any peer (well-known community)\n"
8724 "Do not export to next AS (well-known community)\n"
8725 "community number\n"
8726 "Do not send outside local AS (well-known community)\n"
8727 "Do not advertise to any peer (well-known community)\n"
8728 "Do not export to next AS (well-known community)\n"
8729 "Exact match of the communities")
8730#endif /* HAVE_IPV6 */
8731
paul94f2b392005-06-28 12:44:16 +00008732static int
paulfd79ac92004-10-13 05:06:08 +00008733bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008734 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008735{
8736 struct community_list *list;
8737
hassofee6e4e2005-02-02 16:29:31 +00008738 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008739 if (list == NULL)
8740 {
8741 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8742 VTY_NEWLINE);
8743 return CMD_WARNING;
8744 }
8745
ajs5a646652004-11-05 01:25:55 +00008746 return bgp_show (vty, NULL, afi, safi,
8747 (exact ? bgp_show_type_community_list_exact :
8748 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008749}
8750
8751DEFUN (show_ip_bgp_community_list,
8752 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008753 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008754 SHOW_STR
8755 IP_STR
8756 BGP_STR
8757 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008758 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008759 "community-list name\n")
8760{
8761 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8762}
8763
8764DEFUN (show_ip_bgp_ipv4_community_list,
8765 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008766 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008767 SHOW_STR
8768 IP_STR
8769 BGP_STR
8770 "Address family\n"
8771 "Address Family modifier\n"
8772 "Address Family modifier\n"
8773 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008774 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008775 "community-list name\n")
8776{
8777 if (strncmp (argv[0], "m", 1) == 0)
8778 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8779
8780 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8781}
8782
8783DEFUN (show_ip_bgp_community_list_exact,
8784 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008785 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008786 SHOW_STR
8787 IP_STR
8788 BGP_STR
8789 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008790 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008791 "community-list name\n"
8792 "Exact match of the communities\n")
8793{
8794 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8795}
8796
8797DEFUN (show_ip_bgp_ipv4_community_list_exact,
8798 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008799 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008800 SHOW_STR
8801 IP_STR
8802 BGP_STR
8803 "Address family\n"
8804 "Address Family modifier\n"
8805 "Address Family modifier\n"
8806 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008807 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008808 "community-list name\n"
8809 "Exact match of the communities\n")
8810{
8811 if (strncmp (argv[0], "m", 1) == 0)
8812 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8813
8814 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8815}
8816
8817#ifdef HAVE_IPV6
8818DEFUN (show_bgp_community_list,
8819 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008820 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008821 SHOW_STR
8822 BGP_STR
8823 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008824 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008825 "community-list name\n")
8826{
8827 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8828}
8829
8830ALIAS (show_bgp_community_list,
8831 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008832 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008833 SHOW_STR
8834 BGP_STR
8835 "Address family\n"
8836 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008837 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008838 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008839
8840/* old command */
8841DEFUN (show_ipv6_bgp_community_list,
8842 show_ipv6_bgp_community_list_cmd,
8843 "show ipv6 bgp community-list WORD",
8844 SHOW_STR
8845 IPV6_STR
8846 BGP_STR
8847 "Display routes matching the community-list\n"
8848 "community-list name\n")
8849{
8850 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8851}
8852
8853/* old command */
8854DEFUN (show_ipv6_mbgp_community_list,
8855 show_ipv6_mbgp_community_list_cmd,
8856 "show ipv6 mbgp community-list WORD",
8857 SHOW_STR
8858 IPV6_STR
8859 MBGP_STR
8860 "Display routes matching the community-list\n"
8861 "community-list name\n")
8862{
8863 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8864}
8865
8866DEFUN (show_bgp_community_list_exact,
8867 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008868 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008869 SHOW_STR
8870 BGP_STR
8871 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008872 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008873 "community-list name\n"
8874 "Exact match of the communities\n")
8875{
8876 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8877}
8878
8879ALIAS (show_bgp_community_list_exact,
8880 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008881 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008882 SHOW_STR
8883 BGP_STR
8884 "Address family\n"
8885 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008886 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008887 "community-list name\n"
8888 "Exact match of the communities\n")
8889
8890/* old command */
8891DEFUN (show_ipv6_bgp_community_list_exact,
8892 show_ipv6_bgp_community_list_exact_cmd,
8893 "show ipv6 bgp community-list WORD exact-match",
8894 SHOW_STR
8895 IPV6_STR
8896 BGP_STR
8897 "Display routes matching the community-list\n"
8898 "community-list name\n"
8899 "Exact match of the communities\n")
8900{
8901 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8902}
8903
8904/* old command */
8905DEFUN (show_ipv6_mbgp_community_list_exact,
8906 show_ipv6_mbgp_community_list_exact_cmd,
8907 "show ipv6 mbgp community-list WORD exact-match",
8908 SHOW_STR
8909 IPV6_STR
8910 MBGP_STR
8911 "Display routes matching the community-list\n"
8912 "community-list name\n"
8913 "Exact match of the communities\n")
8914{
8915 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8916}
8917#endif /* HAVE_IPV6 */
8918
paul94f2b392005-06-28 12:44:16 +00008919static int
paulfd79ac92004-10-13 05:06:08 +00008920bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008921 safi_t safi, enum bgp_show_type type)
8922{
8923 int ret;
8924 struct prefix *p;
8925
8926 p = prefix_new();
8927
8928 ret = str2prefix (prefix, p);
8929 if (! ret)
8930 {
8931 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8932 return CMD_WARNING;
8933 }
8934
ajs5a646652004-11-05 01:25:55 +00008935 ret = bgp_show (vty, NULL, afi, safi, type, p);
8936 prefix_free(p);
8937 return ret;
paul718e3742002-12-13 20:15:29 +00008938}
8939
8940DEFUN (show_ip_bgp_prefix_longer,
8941 show_ip_bgp_prefix_longer_cmd,
8942 "show ip bgp A.B.C.D/M longer-prefixes",
8943 SHOW_STR
8944 IP_STR
8945 BGP_STR
8946 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8947 "Display route and more specific routes\n")
8948{
8949 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8950 bgp_show_type_prefix_longer);
8951}
8952
8953DEFUN (show_ip_bgp_flap_prefix_longer,
8954 show_ip_bgp_flap_prefix_longer_cmd,
8955 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8956 SHOW_STR
8957 IP_STR
8958 BGP_STR
8959 "Display flap statistics of routes\n"
8960 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8961 "Display route and more specific routes\n")
8962{
8963 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8964 bgp_show_type_flap_prefix_longer);
8965}
8966
8967DEFUN (show_ip_bgp_ipv4_prefix_longer,
8968 show_ip_bgp_ipv4_prefix_longer_cmd,
8969 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8970 SHOW_STR
8971 IP_STR
8972 BGP_STR
8973 "Address family\n"
8974 "Address Family modifier\n"
8975 "Address Family modifier\n"
8976 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8977 "Display route and more specific routes\n")
8978{
8979 if (strncmp (argv[0], "m", 1) == 0)
8980 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8981 bgp_show_type_prefix_longer);
8982
8983 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8984 bgp_show_type_prefix_longer);
8985}
8986
8987DEFUN (show_ip_bgp_flap_address,
8988 show_ip_bgp_flap_address_cmd,
8989 "show ip bgp flap-statistics A.B.C.D",
8990 SHOW_STR
8991 IP_STR
8992 BGP_STR
8993 "Display flap statistics of routes\n"
8994 "Network in the BGP routing table to display\n")
8995{
8996 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8997 bgp_show_type_flap_address);
8998}
8999
9000DEFUN (show_ip_bgp_flap_prefix,
9001 show_ip_bgp_flap_prefix_cmd,
9002 "show ip bgp flap-statistics A.B.C.D/M",
9003 SHOW_STR
9004 IP_STR
9005 BGP_STR
9006 "Display flap statistics of routes\n"
9007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9008{
9009 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9010 bgp_show_type_flap_prefix);
9011}
9012#ifdef HAVE_IPV6
9013DEFUN (show_bgp_prefix_longer,
9014 show_bgp_prefix_longer_cmd,
9015 "show bgp X:X::X:X/M longer-prefixes",
9016 SHOW_STR
9017 BGP_STR
9018 "IPv6 prefix <network>/<length>\n"
9019 "Display route and more specific routes\n")
9020{
9021 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9022 bgp_show_type_prefix_longer);
9023}
9024
9025ALIAS (show_bgp_prefix_longer,
9026 show_bgp_ipv6_prefix_longer_cmd,
9027 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9028 SHOW_STR
9029 BGP_STR
9030 "Address family\n"
9031 "IPv6 prefix <network>/<length>\n"
9032 "Display route and more specific routes\n")
9033
9034/* old command */
9035DEFUN (show_ipv6_bgp_prefix_longer,
9036 show_ipv6_bgp_prefix_longer_cmd,
9037 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9038 SHOW_STR
9039 IPV6_STR
9040 BGP_STR
9041 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9042 "Display route and more specific routes\n")
9043{
9044 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9045 bgp_show_type_prefix_longer);
9046}
9047
9048/* old command */
9049DEFUN (show_ipv6_mbgp_prefix_longer,
9050 show_ipv6_mbgp_prefix_longer_cmd,
9051 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9052 SHOW_STR
9053 IPV6_STR
9054 MBGP_STR
9055 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9056 "Display route and more specific routes\n")
9057{
9058 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9059 bgp_show_type_prefix_longer);
9060}
9061#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009062
paul94f2b392005-06-28 12:44:16 +00009063static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009064peer_lookup_in_view (struct vty *vty, const char *view_name,
9065 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009066{
9067 int ret;
9068 struct bgp *bgp;
9069 struct peer *peer;
9070 union sockunion su;
9071
9072 /* BGP structure lookup. */
9073 if (view_name)
9074 {
9075 bgp = bgp_lookup_by_name (view_name);
9076 if (! bgp)
9077 {
9078 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9079 return NULL;
9080 }
9081 }
paul5228ad22004-06-04 17:58:18 +00009082 else
paulbb46e942003-10-24 19:02:03 +00009083 {
9084 bgp = bgp_get_default ();
9085 if (! bgp)
9086 {
9087 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9088 return NULL;
9089 }
9090 }
9091
9092 /* Get peer sockunion. */
9093 ret = str2sockunion (ip_str, &su);
9094 if (ret < 0)
9095 {
9096 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9097 return NULL;
9098 }
9099
9100 /* Peer structure lookup. */
9101 peer = peer_lookup (bgp, &su);
9102 if (! peer)
9103 {
9104 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9105 return NULL;
9106 }
9107
9108 return peer;
9109}
Paul Jakma2815e612006-09-14 02:56:07 +00009110
9111enum bgp_stats
9112{
9113 BGP_STATS_MAXBITLEN = 0,
9114 BGP_STATS_RIB,
9115 BGP_STATS_PREFIXES,
9116 BGP_STATS_TOTPLEN,
9117 BGP_STATS_UNAGGREGATEABLE,
9118 BGP_STATS_MAX_AGGREGATEABLE,
9119 BGP_STATS_AGGREGATES,
9120 BGP_STATS_SPACE,
9121 BGP_STATS_ASPATH_COUNT,
9122 BGP_STATS_ASPATH_MAXHOPS,
9123 BGP_STATS_ASPATH_TOTHOPS,
9124 BGP_STATS_ASPATH_MAXSIZE,
9125 BGP_STATS_ASPATH_TOTSIZE,
9126 BGP_STATS_ASN_HIGHEST,
9127 BGP_STATS_MAX,
9128};
paulbb46e942003-10-24 19:02:03 +00009129
Paul Jakma2815e612006-09-14 02:56:07 +00009130static const char *table_stats_strs[] =
9131{
9132 [BGP_STATS_PREFIXES] = "Total Prefixes",
9133 [BGP_STATS_TOTPLEN] = "Average prefix length",
9134 [BGP_STATS_RIB] = "Total Advertisements",
9135 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9136 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9137 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9138 [BGP_STATS_SPACE] = "Address space advertised",
9139 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9140 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9141 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9142 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9143 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9144 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9145 [BGP_STATS_MAX] = NULL,
9146};
9147
9148struct bgp_table_stats
9149{
9150 struct bgp_table *table;
9151 unsigned long long counts[BGP_STATS_MAX];
9152};
9153
9154#if 0
9155#define TALLY_SIGFIG 100000
9156static unsigned long
9157ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9158{
9159 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9160 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9161 unsigned long ret = newtot / count;
9162
9163 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9164 return ret + 1;
9165 else
9166 return ret;
9167}
9168#endif
9169
9170static int
9171bgp_table_stats_walker (struct thread *t)
9172{
9173 struct bgp_node *rn;
9174 struct bgp_node *top;
9175 struct bgp_table_stats *ts = THREAD_ARG (t);
9176 unsigned int space = 0;
9177
Paul Jakma53d9f672006-10-15 23:41:16 +00009178 if (!(top = bgp_table_top (ts->table)))
9179 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009180
9181 switch (top->p.family)
9182 {
9183 case AF_INET:
9184 space = IPV4_MAX_BITLEN;
9185 break;
9186 case AF_INET6:
9187 space = IPV6_MAX_BITLEN;
9188 break;
9189 }
9190
9191 ts->counts[BGP_STATS_MAXBITLEN] = space;
9192
9193 for (rn = top; rn; rn = bgp_route_next (rn))
9194 {
9195 struct bgp_info *ri;
9196 struct bgp_node *prn = rn->parent;
9197 unsigned int rinum = 0;
9198
9199 if (rn == top)
9200 continue;
9201
9202 if (!rn->info)
9203 continue;
9204
9205 ts->counts[BGP_STATS_PREFIXES]++;
9206 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9207
9208#if 0
9209 ts->counts[BGP_STATS_AVGPLEN]
9210 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9211 ts->counts[BGP_STATS_AVGPLEN],
9212 rn->p.prefixlen);
9213#endif
9214
9215 /* check if the prefix is included by any other announcements */
9216 while (prn && !prn->info)
9217 prn = prn->parent;
9218
9219 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009220 {
9221 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9222 /* announced address space */
9223 if (space)
9224 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9225 }
Paul Jakma2815e612006-09-14 02:56:07 +00009226 else if (prn->info)
9227 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9228
Paul Jakma2815e612006-09-14 02:56:07 +00009229 for (ri = rn->info; ri; ri = ri->next)
9230 {
9231 rinum++;
9232 ts->counts[BGP_STATS_RIB]++;
9233
9234 if (ri->attr &&
9235 (CHECK_FLAG (ri->attr->flag,
9236 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9237 ts->counts[BGP_STATS_AGGREGATES]++;
9238
9239 /* as-path stats */
9240 if (ri->attr && ri->attr->aspath)
9241 {
9242 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9243 unsigned int size = aspath_size (ri->attr->aspath);
9244 as_t highest = aspath_highest (ri->attr->aspath);
9245
9246 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9247
9248 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9249 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9250
9251 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9252 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9253
9254 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9255 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9256#if 0
9257 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9258 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9259 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9260 hops);
9261 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9262 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9263 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9264 size);
9265#endif
9266 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9267 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9268 }
9269 }
9270 }
9271 return 0;
9272}
9273
9274static int
9275bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9276{
9277 struct bgp_table_stats ts;
9278 unsigned int i;
9279
9280 if (!bgp->rib[afi][safi])
9281 {
9282 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9283 return CMD_WARNING;
9284 }
9285
9286 memset (&ts, 0, sizeof (ts));
9287 ts.table = bgp->rib[afi][safi];
9288 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9289
9290 vty_out (vty, "BGP %s RIB statistics%s%s",
9291 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9292
9293 for (i = 0; i < BGP_STATS_MAX; i++)
9294 {
9295 if (!table_stats_strs[i])
9296 continue;
9297
9298 switch (i)
9299 {
9300#if 0
9301 case BGP_STATS_ASPATH_AVGHOPS:
9302 case BGP_STATS_ASPATH_AVGSIZE:
9303 case BGP_STATS_AVGPLEN:
9304 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9305 vty_out (vty, "%12.2f",
9306 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9307 break;
9308#endif
9309 case BGP_STATS_ASPATH_TOTHOPS:
9310 case BGP_STATS_ASPATH_TOTSIZE:
9311 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9312 vty_out (vty, "%12.2f",
9313 ts.counts[i] ?
9314 (float)ts.counts[i] /
9315 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9316 : 0);
9317 break;
9318 case BGP_STATS_TOTPLEN:
9319 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9320 vty_out (vty, "%12.2f",
9321 ts.counts[i] ?
9322 (float)ts.counts[i] /
9323 (float)ts.counts[BGP_STATS_PREFIXES]
9324 : 0);
9325 break;
9326 case BGP_STATS_SPACE:
9327 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9328 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9329 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9330 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009331 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009332 vty_out (vty, "%12.2f%s",
9333 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009334 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009335 VTY_NEWLINE);
9336 vty_out (vty, "%30s: ", "/8 equivalent ");
9337 vty_out (vty, "%12.2f%s",
9338 (float)ts.counts[BGP_STATS_SPACE] /
9339 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9340 VTY_NEWLINE);
9341 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9342 break;
9343 vty_out (vty, "%30s: ", "/24 equivalent ");
9344 vty_out (vty, "%12.2f",
9345 (float)ts.counts[BGP_STATS_SPACE] /
9346 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9347 break;
9348 default:
9349 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9350 vty_out (vty, "%12llu", ts.counts[i]);
9351 }
9352
9353 vty_out (vty, "%s", VTY_NEWLINE);
9354 }
9355 return CMD_SUCCESS;
9356}
9357
9358static int
9359bgp_table_stats_vty (struct vty *vty, const char *name,
9360 const char *afi_str, const char *safi_str)
9361{
9362 struct bgp *bgp;
9363 afi_t afi;
9364 safi_t safi;
9365
9366 if (name)
9367 bgp = bgp_lookup_by_name (name);
9368 else
9369 bgp = bgp_get_default ();
9370
9371 if (!bgp)
9372 {
9373 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9374 return CMD_WARNING;
9375 }
9376 if (strncmp (afi_str, "ipv", 3) == 0)
9377 {
9378 if (strncmp (afi_str, "ipv4", 4) == 0)
9379 afi = AFI_IP;
9380 else if (strncmp (afi_str, "ipv6", 4) == 0)
9381 afi = AFI_IP6;
9382 else
9383 {
9384 vty_out (vty, "%% Invalid address family %s%s",
9385 afi_str, VTY_NEWLINE);
9386 return CMD_WARNING;
9387 }
9388 if (strncmp (safi_str, "m", 1) == 0)
9389 safi = SAFI_MULTICAST;
9390 else if (strncmp (safi_str, "u", 1) == 0)
9391 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009392 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9393 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009394 else
9395 {
9396 vty_out (vty, "%% Invalid subsequent address family %s%s",
9397 safi_str, VTY_NEWLINE);
9398 return CMD_WARNING;
9399 }
9400 }
9401 else
9402 {
9403 vty_out (vty, "%% Invalid address family %s%s",
9404 afi_str, VTY_NEWLINE);
9405 return CMD_WARNING;
9406 }
9407
Paul Jakma2815e612006-09-14 02:56:07 +00009408 return bgp_table_stats (vty, bgp, afi, safi);
9409}
9410
9411DEFUN (show_bgp_statistics,
9412 show_bgp_statistics_cmd,
9413 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9414 SHOW_STR
9415 BGP_STR
9416 "Address family\n"
9417 "Address family\n"
9418 "Address Family modifier\n"
9419 "Address Family modifier\n"
9420 "BGP RIB advertisement statistics\n")
9421{
9422 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9423}
9424
9425ALIAS (show_bgp_statistics,
9426 show_bgp_statistics_vpnv4_cmd,
9427 "show bgp (ipv4) (vpnv4) statistics",
9428 SHOW_STR
9429 BGP_STR
9430 "Address family\n"
9431 "Address Family modifier\n"
9432 "BGP RIB advertisement statistics\n")
9433
9434DEFUN (show_bgp_statistics_view,
9435 show_bgp_statistics_view_cmd,
9436 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9437 SHOW_STR
9438 BGP_STR
9439 "BGP view\n"
9440 "Address family\n"
9441 "Address family\n"
9442 "Address Family modifier\n"
9443 "Address Family modifier\n"
9444 "BGP RIB advertisement statistics\n")
9445{
9446 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9447}
9448
9449ALIAS (show_bgp_statistics_view,
9450 show_bgp_statistics_view_vpnv4_cmd,
9451 "show bgp view WORD (ipv4) (vpnv4) statistics",
9452 SHOW_STR
9453 BGP_STR
9454 "BGP view\n"
9455 "Address family\n"
9456 "Address Family modifier\n"
9457 "BGP RIB advertisement statistics\n")
9458
Paul Jakmaff7924f2006-09-04 01:10:36 +00009459enum bgp_pcounts
9460{
9461 PCOUNT_ADJ_IN = 0,
9462 PCOUNT_DAMPED,
9463 PCOUNT_REMOVED,
9464 PCOUNT_HISTORY,
9465 PCOUNT_STALE,
9466 PCOUNT_VALID,
9467 PCOUNT_ALL,
9468 PCOUNT_COUNTED,
9469 PCOUNT_PFCNT, /* the figure we display to users */
9470 PCOUNT_MAX,
9471};
9472
9473static const char *pcount_strs[] =
9474{
9475 [PCOUNT_ADJ_IN] = "Adj-in",
9476 [PCOUNT_DAMPED] = "Damped",
9477 [PCOUNT_REMOVED] = "Removed",
9478 [PCOUNT_HISTORY] = "History",
9479 [PCOUNT_STALE] = "Stale",
9480 [PCOUNT_VALID] = "Valid",
9481 [PCOUNT_ALL] = "All RIB",
9482 [PCOUNT_COUNTED] = "PfxCt counted",
9483 [PCOUNT_PFCNT] = "Useable",
9484 [PCOUNT_MAX] = NULL,
9485};
9486
Paul Jakma2815e612006-09-14 02:56:07 +00009487struct peer_pcounts
9488{
9489 unsigned int count[PCOUNT_MAX];
9490 const struct peer *peer;
9491 const struct bgp_table *table;
9492};
9493
Paul Jakmaff7924f2006-09-04 01:10:36 +00009494static int
Paul Jakma2815e612006-09-14 02:56:07 +00009495bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009496{
9497 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009498 struct peer_pcounts *pc = THREAD_ARG (t);
9499 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009500
Paul Jakma2815e612006-09-14 02:56:07 +00009501 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009502 {
9503 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009504 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009505
9506 for (ain = rn->adj_in; ain; ain = ain->next)
9507 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009508 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009509
Paul Jakmaff7924f2006-09-04 01:10:36 +00009510 for (ri = rn->info; ri; ri = ri->next)
9511 {
9512 char buf[SU_ADDRSTRLEN];
9513
9514 if (ri->peer != peer)
9515 continue;
9516
Paul Jakma2815e612006-09-14 02:56:07 +00009517 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009518
9519 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009520 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009521 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009522 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009523 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009524 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009525 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009526 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009527 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009528 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009529 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009530 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009531
9532 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9533 {
Paul Jakma2815e612006-09-14 02:56:07 +00009534 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009535 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009536 plog_warn (peer->log,
9537 "%s [pcount] %s/%d is counted but flags 0x%x",
9538 peer->host,
9539 inet_ntop(rn->p.family, &rn->p.u.prefix,
9540 buf, SU_ADDRSTRLEN),
9541 rn->p.prefixlen,
9542 ri->flags);
9543 }
9544 else
9545 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009546 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009547 plog_warn (peer->log,
9548 "%s [pcount] %s/%d not counted but flags 0x%x",
9549 peer->host,
9550 inet_ntop(rn->p.family, &rn->p.u.prefix,
9551 buf, SU_ADDRSTRLEN),
9552 rn->p.prefixlen,
9553 ri->flags);
9554 }
9555 }
9556 }
Paul Jakma2815e612006-09-14 02:56:07 +00009557 return 0;
9558}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009559
Paul Jakma2815e612006-09-14 02:56:07 +00009560static int
9561bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9562{
9563 struct peer_pcounts pcounts = { .peer = peer };
9564 unsigned int i;
9565
9566 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9567 || !peer->bgp->rib[afi][safi])
9568 {
9569 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9570 return CMD_WARNING;
9571 }
9572
9573 memset (&pcounts, 0, sizeof(pcounts));
9574 pcounts.peer = peer;
9575 pcounts.table = peer->bgp->rib[afi][safi];
9576
9577 /* in-place call via thread subsystem so as to record execution time
9578 * stats for the thread-walk (i.e. ensure this can't be blamed on
9579 * on just vty_read()).
9580 */
9581 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9582
Paul Jakmaff7924f2006-09-04 01:10:36 +00009583 vty_out (vty, "Prefix counts for %s, %s%s",
9584 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9585 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9586 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9587 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9588
9589 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009590 vty_out (vty, "%20s: %-10d%s",
9591 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009592
Paul Jakma2815e612006-09-14 02:56:07 +00009593 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009594 {
9595 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9596 peer->host, VTY_NEWLINE);
9597 vty_out (vty, "Please report this bug, with the above command output%s",
9598 VTY_NEWLINE);
9599 }
9600
9601 return CMD_SUCCESS;
9602}
9603
9604DEFUN (show_ip_bgp_neighbor_prefix_counts,
9605 show_ip_bgp_neighbor_prefix_counts_cmd,
9606 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9607 SHOW_STR
9608 IP_STR
9609 BGP_STR
9610 "Detailed information on TCP and BGP neighbor connections\n"
9611 "Neighbor to display information about\n"
9612 "Neighbor to display information about\n"
9613 "Display detailed prefix count information\n")
9614{
9615 struct peer *peer;
9616
9617 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9618 if (! peer)
9619 return CMD_WARNING;
9620
9621 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9622}
9623
9624DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9625 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9626 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9627 SHOW_STR
9628 BGP_STR
9629 "Address family\n"
9630 "Detailed information on TCP and BGP neighbor connections\n"
9631 "Neighbor to display information about\n"
9632 "Neighbor to display information about\n"
9633 "Display detailed prefix count information\n")
9634{
9635 struct peer *peer;
9636
9637 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9638 if (! peer)
9639 return CMD_WARNING;
9640
9641 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9642}
9643
9644DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9645 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9646 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9647 SHOW_STR
9648 IP_STR
9649 BGP_STR
9650 "Address family\n"
9651 "Address Family modifier\n"
9652 "Address Family modifier\n"
9653 "Detailed information on TCP and BGP neighbor connections\n"
9654 "Neighbor to display information about\n"
9655 "Neighbor to display information about\n"
9656 "Display detailed prefix count information\n")
9657{
9658 struct peer *peer;
9659
9660 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9661 if (! peer)
9662 return CMD_WARNING;
9663
9664 if (strncmp (argv[0], "m", 1) == 0)
9665 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9666
9667 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9668}
9669
9670DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9671 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9672 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 "Address family\n"
9677 "Address Family modifier\n"
9678 "Address Family modifier\n"
9679 "Detailed information on TCP and BGP neighbor connections\n"
9680 "Neighbor to display information about\n"
9681 "Neighbor to display information about\n"
9682 "Display detailed prefix count information\n")
9683{
9684 struct peer *peer;
9685
9686 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9687 if (! peer)
9688 return CMD_WARNING;
9689
9690 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9691}
9692
9693
paul94f2b392005-06-28 12:44:16 +00009694static void
paul718e3742002-12-13 20:15:29 +00009695show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9696 int in)
9697{
9698 struct bgp_table *table;
9699 struct bgp_adj_in *ain;
9700 struct bgp_adj_out *adj;
9701 unsigned long output_count;
9702 struct bgp_node *rn;
9703 int header1 = 1;
9704 struct bgp *bgp;
9705 int header2 = 1;
9706
paulbb46e942003-10-24 19:02:03 +00009707 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009708
9709 if (! bgp)
9710 return;
9711
9712 table = bgp->rib[afi][safi];
9713
9714 output_count = 0;
9715
9716 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9717 PEER_STATUS_DEFAULT_ORIGINATE))
9718 {
9719 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 +00009720 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9721 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009722
9723 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9724 VTY_NEWLINE, VTY_NEWLINE);
9725 header1 = 0;
9726 }
9727
9728 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9729 if (in)
9730 {
9731 for (ain = rn->adj_in; ain; ain = ain->next)
9732 if (ain->peer == peer)
9733 {
9734 if (header1)
9735 {
9736 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 +00009737 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9738 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009739 header1 = 0;
9740 }
9741 if (header2)
9742 {
9743 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9744 header2 = 0;
9745 }
9746 if (ain->attr)
9747 {
9748 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9749 output_count++;
9750 }
9751 }
9752 }
9753 else
9754 {
9755 for (adj = rn->adj_out; adj; adj = adj->next)
9756 if (adj->peer == peer)
9757 {
9758 if (header1)
9759 {
9760 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 +00009761 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9762 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009763 header1 = 0;
9764 }
9765 if (header2)
9766 {
9767 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9768 header2 = 0;
9769 }
9770 if (adj->attr)
9771 {
9772 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9773 output_count++;
9774 }
9775 }
9776 }
9777
9778 if (output_count != 0)
9779 vty_out (vty, "%sTotal number of prefixes %ld%s",
9780 VTY_NEWLINE, output_count, VTY_NEWLINE);
9781}
9782
paul94f2b392005-06-28 12:44:16 +00009783static int
paulbb46e942003-10-24 19:02:03 +00009784peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9785{
paul718e3742002-12-13 20:15:29 +00009786 if (! peer || ! peer->afc[afi][safi])
9787 {
9788 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9789 return CMD_WARNING;
9790 }
9791
9792 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9793 {
9794 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9795 VTY_NEWLINE);
9796 return CMD_WARNING;
9797 }
9798
9799 show_adj_route (vty, peer, afi, safi, in);
9800
9801 return CMD_SUCCESS;
9802}
9803
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009804DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9805 show_ip_bgp_view_neighbor_advertised_route_cmd,
9806 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9807 SHOW_STR
9808 IP_STR
9809 BGP_STR
9810 "BGP view\n"
9811 "View name\n"
9812 "Detailed information on TCP and BGP neighbor connections\n"
9813 "Neighbor to display information about\n"
9814 "Neighbor to display information about\n"
9815 "Display the routes advertised to a BGP neighbor\n")
9816{
9817 struct peer *peer;
9818
9819 if (argc == 2)
9820 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9821 else
9822 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9823
9824 if (! peer)
9825 return CMD_WARNING;
9826
9827 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9828}
9829
9830ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009831 show_ip_bgp_neighbor_advertised_route_cmd,
9832 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9833 SHOW_STR
9834 IP_STR
9835 BGP_STR
9836 "Detailed information on TCP and BGP neighbor connections\n"
9837 "Neighbor to display information about\n"
9838 "Neighbor to display information about\n"
9839 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009840
9841DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9842 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9843 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9844 SHOW_STR
9845 IP_STR
9846 BGP_STR
9847 "Address family\n"
9848 "Address Family modifier\n"
9849 "Address Family modifier\n"
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;
paul718e3742002-12-13 20:15:29 +00009856
paulbb46e942003-10-24 19:02:03 +00009857 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9858 if (! peer)
9859 return CMD_WARNING;
9860
9861 if (strncmp (argv[0], "m", 1) == 0)
9862 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9863
9864 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009865}
9866
9867#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009868DEFUN (show_bgp_view_neighbor_advertised_route,
9869 show_bgp_view_neighbor_advertised_route_cmd,
9870 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9871 SHOW_STR
9872 BGP_STR
9873 "BGP view\n"
9874 "View name\n"
9875 "Detailed information on TCP and BGP neighbor connections\n"
9876 "Neighbor to display information about\n"
9877 "Neighbor to display information about\n"
9878 "Display the routes advertised to a BGP neighbor\n")
9879{
9880 struct peer *peer;
9881
9882 if (argc == 2)
9883 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9884 else
9885 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9886
9887 if (! peer)
9888 return CMD_WARNING;
9889
9890 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9891}
9892
9893ALIAS (show_bgp_view_neighbor_advertised_route,
9894 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9895 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9896 SHOW_STR
9897 BGP_STR
9898 "BGP view\n"
9899 "View name\n"
9900 "Address family\n"
9901 "Detailed information on TCP and BGP neighbor connections\n"
9902 "Neighbor to display information about\n"
9903 "Neighbor to display information about\n"
9904 "Display the routes advertised to a BGP neighbor\n")
9905
9906DEFUN (show_bgp_view_neighbor_received_routes,
9907 show_bgp_view_neighbor_received_routes_cmd,
9908 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9909 SHOW_STR
9910 BGP_STR
9911 "BGP view\n"
9912 "View name\n"
9913 "Detailed information on TCP and BGP neighbor connections\n"
9914 "Neighbor to display information about\n"
9915 "Neighbor to display information about\n"
9916 "Display the received routes from neighbor\n")
9917{
9918 struct peer *peer;
9919
9920 if (argc == 2)
9921 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9922 else
9923 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9924
9925 if (! peer)
9926 return CMD_WARNING;
9927
9928 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9929}
9930
9931ALIAS (show_bgp_view_neighbor_received_routes,
9932 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9933 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9934 SHOW_STR
9935 BGP_STR
9936 "BGP view\n"
9937 "View name\n"
9938 "Address family\n"
9939 "Detailed information on TCP and BGP neighbor connections\n"
9940 "Neighbor to display information about\n"
9941 "Neighbor to display information about\n"
9942 "Display the received routes from neighbor\n")
9943
9944ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009945 show_bgp_neighbor_advertised_route_cmd,
9946 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9947 SHOW_STR
9948 BGP_STR
9949 "Detailed information on TCP and BGP neighbor connections\n"
9950 "Neighbor to display information about\n"
9951 "Neighbor to display information about\n"
9952 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009953
9954ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009955 show_bgp_ipv6_neighbor_advertised_route_cmd,
9956 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9957 SHOW_STR
9958 BGP_STR
9959 "Address family\n"
9960 "Detailed information on TCP and BGP neighbor connections\n"
9961 "Neighbor to display information about\n"
9962 "Neighbor to display information about\n"
9963 "Display the routes advertised to a BGP neighbor\n")
9964
9965/* old command */
paulbb46e942003-10-24 19:02:03 +00009966ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009967 ipv6_bgp_neighbor_advertised_route_cmd,
9968 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9969 SHOW_STR
9970 IPV6_STR
9971 BGP_STR
9972 "Detailed information on TCP and BGP neighbor connections\n"
9973 "Neighbor to display information about\n"
9974 "Neighbor to display information about\n"
9975 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009976
paul718e3742002-12-13 20:15:29 +00009977/* old command */
9978DEFUN (ipv6_mbgp_neighbor_advertised_route,
9979 ipv6_mbgp_neighbor_advertised_route_cmd,
9980 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9981 SHOW_STR
9982 IPV6_STR
9983 MBGP_STR
9984 "Detailed information on TCP and BGP neighbor connections\n"
9985 "Neighbor to display information about\n"
9986 "Neighbor to display information about\n"
9987 "Display the routes advertised to a BGP neighbor\n")
9988{
paulbb46e942003-10-24 19:02:03 +00009989 struct peer *peer;
9990
9991 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9992 if (! peer)
9993 return CMD_WARNING;
9994
9995 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009996}
9997#endif /* HAVE_IPV6 */
9998
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009999DEFUN (show_ip_bgp_view_neighbor_received_routes,
10000 show_ip_bgp_view_neighbor_received_routes_cmd,
10001 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10002 SHOW_STR
10003 IP_STR
10004 BGP_STR
10005 "BGP view\n"
10006 "View name\n"
10007 "Detailed information on TCP and BGP neighbor connections\n"
10008 "Neighbor to display information about\n"
10009 "Neighbor to display information about\n"
10010 "Display the received routes from neighbor\n")
10011{
10012 struct peer *peer;
10013
10014 if (argc == 2)
10015 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10016 else
10017 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10018
10019 if (! peer)
10020 return CMD_WARNING;
10021
10022 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10023}
10024
10025ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010026 show_ip_bgp_neighbor_received_routes_cmd,
10027 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10028 SHOW_STR
10029 IP_STR
10030 BGP_STR
10031 "Detailed information on TCP and BGP neighbor connections\n"
10032 "Neighbor to display information about\n"
10033 "Neighbor to display information about\n"
10034 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010035
10036DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10037 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10038 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10039 SHOW_STR
10040 IP_STR
10041 BGP_STR
10042 "Address family\n"
10043 "Address Family modifier\n"
10044 "Address Family modifier\n"
10045 "Detailed information on TCP and BGP neighbor connections\n"
10046 "Neighbor to display information about\n"
10047 "Neighbor to display information about\n"
10048 "Display the received routes from neighbor\n")
10049{
paulbb46e942003-10-24 19:02:03 +000010050 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010051
paulbb46e942003-10-24 19:02:03 +000010052 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10053 if (! peer)
10054 return CMD_WARNING;
10055
10056 if (strncmp (argv[0], "m", 1) == 0)
10057 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10058
10059 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010060}
10061
Michael Lambert95cbbd22010-07-23 14:43:04 -040010062DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10063 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10064#ifdef HAVE_IPV6
10065 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10066#else
10067 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10068#endif
10069 SHOW_STR
10070 BGP_STR
10071 "BGP view\n"
10072 "BGP view name\n"
10073 "Address family\n"
10074#ifdef HAVE_IPV6
10075 "Address family\n"
10076#endif
10077 "Address family modifier\n"
10078 "Address family modifier\n"
10079 "Detailed information on TCP and BGP neighbor connections\n"
10080 "Neighbor to display information about\n"
10081 "Neighbor to display information about\n"
10082 "Display the advertised routes to neighbor\n"
10083 "Display the received routes from neighbor\n")
10084{
10085 int afi;
10086 int safi;
10087 int in;
10088 struct peer *peer;
10089
10090#ifdef HAVE_IPV6
10091 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10092#else
10093 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10094#endif
10095
10096 if (! peer)
10097 return CMD_WARNING;
10098
10099#ifdef HAVE_IPV6
10100 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10101 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10102 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10103#else
10104 afi = AFI_IP;
10105 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10106 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10107#endif
10108
10109 return peer_adj_routes (vty, peer, afi, safi, in);
10110}
10111
paul718e3742002-12-13 20:15:29 +000010112DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10113 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10114 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10115 SHOW_STR
10116 IP_STR
10117 BGP_STR
10118 "Detailed information on TCP and BGP neighbor connections\n"
10119 "Neighbor to display information about\n"
10120 "Neighbor to display information about\n"
10121 "Display information received from a BGP neighbor\n"
10122 "Display the prefixlist filter\n")
10123{
10124 char name[BUFSIZ];
10125 union sockunion *su;
10126 struct peer *peer;
10127 int count;
10128
10129 su = sockunion_str2su (argv[0]);
10130 if (su == NULL)
10131 return CMD_WARNING;
10132
10133 peer = peer_lookup (NULL, su);
10134 if (! peer)
10135 return CMD_WARNING;
10136
10137 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10138 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10139 if (count)
10140 {
10141 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10142 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10143 }
10144
10145 return CMD_SUCCESS;
10146}
10147
10148DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10149 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10150 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10151 SHOW_STR
10152 IP_STR
10153 BGP_STR
10154 "Address family\n"
10155 "Address Family modifier\n"
10156 "Address Family modifier\n"
10157 "Detailed information on TCP and BGP neighbor connections\n"
10158 "Neighbor to display information about\n"
10159 "Neighbor to display information about\n"
10160 "Display information received from a BGP neighbor\n"
10161 "Display the prefixlist filter\n")
10162{
10163 char name[BUFSIZ];
10164 union sockunion *su;
10165 struct peer *peer;
10166 int count;
10167
10168 su = sockunion_str2su (argv[1]);
10169 if (su == NULL)
10170 return CMD_WARNING;
10171
10172 peer = peer_lookup (NULL, su);
10173 if (! peer)
10174 return CMD_WARNING;
10175
10176 if (strncmp (argv[0], "m", 1) == 0)
10177 {
10178 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10179 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10180 if (count)
10181 {
10182 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10183 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10184 }
10185 }
10186 else
10187 {
10188 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10189 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10190 if (count)
10191 {
10192 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10193 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10194 }
10195 }
10196
10197 return CMD_SUCCESS;
10198}
10199
10200
10201#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010202ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010203 show_bgp_neighbor_received_routes_cmd,
10204 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10205 SHOW_STR
10206 BGP_STR
10207 "Detailed information on TCP and BGP neighbor connections\n"
10208 "Neighbor to display information about\n"
10209 "Neighbor to display information about\n"
10210 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010211
paulbb46e942003-10-24 19:02:03 +000010212ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010213 show_bgp_ipv6_neighbor_received_routes_cmd,
10214 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10215 SHOW_STR
10216 BGP_STR
10217 "Address family\n"
10218 "Detailed information on TCP and BGP neighbor connections\n"
10219 "Neighbor to display information about\n"
10220 "Neighbor to display information about\n"
10221 "Display the received routes from neighbor\n")
10222
10223DEFUN (show_bgp_neighbor_received_prefix_filter,
10224 show_bgp_neighbor_received_prefix_filter_cmd,
10225 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10226 SHOW_STR
10227 BGP_STR
10228 "Detailed information on TCP and BGP neighbor connections\n"
10229 "Neighbor to display information about\n"
10230 "Neighbor to display information about\n"
10231 "Display information received from a BGP neighbor\n"
10232 "Display the prefixlist filter\n")
10233{
10234 char name[BUFSIZ];
10235 union sockunion *su;
10236 struct peer *peer;
10237 int count;
10238
10239 su = sockunion_str2su (argv[0]);
10240 if (su == NULL)
10241 return CMD_WARNING;
10242
10243 peer = peer_lookup (NULL, su);
10244 if (! peer)
10245 return CMD_WARNING;
10246
10247 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10248 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10249 if (count)
10250 {
10251 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10252 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10253 }
10254
10255 return CMD_SUCCESS;
10256}
10257
10258ALIAS (show_bgp_neighbor_received_prefix_filter,
10259 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10260 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10261 SHOW_STR
10262 BGP_STR
10263 "Address family\n"
10264 "Detailed information on TCP and BGP neighbor connections\n"
10265 "Neighbor to display information about\n"
10266 "Neighbor to display information about\n"
10267 "Display information received from a BGP neighbor\n"
10268 "Display the prefixlist filter\n")
10269
10270/* old command */
paulbb46e942003-10-24 19:02:03 +000010271ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010272 ipv6_bgp_neighbor_received_routes_cmd,
10273 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10274 SHOW_STR
10275 IPV6_STR
10276 BGP_STR
10277 "Detailed information on TCP and BGP neighbor connections\n"
10278 "Neighbor to display information about\n"
10279 "Neighbor to display information about\n"
10280 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010281
10282/* old command */
10283DEFUN (ipv6_mbgp_neighbor_received_routes,
10284 ipv6_mbgp_neighbor_received_routes_cmd,
10285 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10286 SHOW_STR
10287 IPV6_STR
10288 MBGP_STR
10289 "Detailed information on TCP and BGP neighbor connections\n"
10290 "Neighbor to display information about\n"
10291 "Neighbor to display information about\n"
10292 "Display the received routes from neighbor\n")
10293{
paulbb46e942003-10-24 19:02:03 +000010294 struct peer *peer;
10295
10296 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10297 if (! peer)
10298 return CMD_WARNING;
10299
10300 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010301}
paulbb46e942003-10-24 19:02:03 +000010302
10303DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10304 show_bgp_view_neighbor_received_prefix_filter_cmd,
10305 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10306 SHOW_STR
10307 BGP_STR
10308 "BGP view\n"
10309 "View name\n"
10310 "Detailed information on TCP and BGP neighbor connections\n"
10311 "Neighbor to display information about\n"
10312 "Neighbor to display information about\n"
10313 "Display information received from a BGP neighbor\n"
10314 "Display the prefixlist filter\n")
10315{
10316 char name[BUFSIZ];
10317 union sockunion *su;
10318 struct peer *peer;
10319 struct bgp *bgp;
10320 int count;
10321
10322 /* BGP structure lookup. */
10323 bgp = bgp_lookup_by_name (argv[0]);
10324 if (bgp == NULL)
10325 {
10326 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10327 return CMD_WARNING;
10328 }
10329
10330 su = sockunion_str2su (argv[1]);
10331 if (su == NULL)
10332 return CMD_WARNING;
10333
10334 peer = peer_lookup (bgp, su);
10335 if (! peer)
10336 return CMD_WARNING;
10337
10338 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10339 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10340 if (count)
10341 {
10342 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10343 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10344 }
10345
10346 return CMD_SUCCESS;
10347}
10348
10349ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10350 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10351 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10352 SHOW_STR
10353 BGP_STR
10354 "BGP view\n"
10355 "View name\n"
10356 "Address family\n"
10357 "Detailed information on TCP and BGP neighbor connections\n"
10358 "Neighbor to display information about\n"
10359 "Neighbor to display information about\n"
10360 "Display information received from a BGP neighbor\n"
10361 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010362#endif /* HAVE_IPV6 */
10363
paul94f2b392005-06-28 12:44:16 +000010364static int
paulbb46e942003-10-24 19:02:03 +000010365bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010366 safi_t safi, enum bgp_show_type type)
10367{
paul718e3742002-12-13 20:15:29 +000010368 if (! peer || ! peer->afc[afi][safi])
10369 {
10370 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010371 return CMD_WARNING;
10372 }
10373
ajs5a646652004-11-05 01:25:55 +000010374 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010375}
10376
10377DEFUN (show_ip_bgp_neighbor_routes,
10378 show_ip_bgp_neighbor_routes_cmd,
10379 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10380 SHOW_STR
10381 IP_STR
10382 BGP_STR
10383 "Detailed information on TCP and BGP neighbor connections\n"
10384 "Neighbor to display information about\n"
10385 "Neighbor to display information about\n"
10386 "Display routes learned from neighbor\n")
10387{
paulbb46e942003-10-24 19:02:03 +000010388 struct peer *peer;
10389
10390 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10391 if (! peer)
10392 return CMD_WARNING;
10393
10394 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010395 bgp_show_type_neighbor);
10396}
10397
10398DEFUN (show_ip_bgp_neighbor_flap,
10399 show_ip_bgp_neighbor_flap_cmd,
10400 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10401 SHOW_STR
10402 IP_STR
10403 BGP_STR
10404 "Detailed information on TCP and BGP neighbor connections\n"
10405 "Neighbor to display information about\n"
10406 "Neighbor to display information about\n"
10407 "Display flap statistics of the routes learned from neighbor\n")
10408{
paulbb46e942003-10-24 19:02:03 +000010409 struct peer *peer;
10410
10411 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10412 if (! peer)
10413 return CMD_WARNING;
10414
10415 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010416 bgp_show_type_flap_neighbor);
10417}
10418
10419DEFUN (show_ip_bgp_neighbor_damp,
10420 show_ip_bgp_neighbor_damp_cmd,
10421 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10422 SHOW_STR
10423 IP_STR
10424 BGP_STR
10425 "Detailed information on TCP and BGP neighbor connections\n"
10426 "Neighbor to display information about\n"
10427 "Neighbor to display information about\n"
10428 "Display the dampened routes received from neighbor\n")
10429{
paulbb46e942003-10-24 19:02:03 +000010430 struct peer *peer;
10431
10432 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10433 if (! peer)
10434 return CMD_WARNING;
10435
10436 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010437 bgp_show_type_damp_neighbor);
10438}
10439
10440DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10441 show_ip_bgp_ipv4_neighbor_routes_cmd,
10442 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10443 SHOW_STR
10444 IP_STR
10445 BGP_STR
10446 "Address family\n"
10447 "Address Family modifier\n"
10448 "Address Family modifier\n"
10449 "Detailed information on TCP and BGP neighbor connections\n"
10450 "Neighbor to display information about\n"
10451 "Neighbor to display information about\n"
10452 "Display routes learned from neighbor\n")
10453{
paulbb46e942003-10-24 19:02:03 +000010454 struct peer *peer;
10455
10456 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10457 if (! peer)
10458 return CMD_WARNING;
10459
paul718e3742002-12-13 20:15:29 +000010460 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010461 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010462 bgp_show_type_neighbor);
10463
paulbb46e942003-10-24 19:02:03 +000010464 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010465 bgp_show_type_neighbor);
10466}
paulbb46e942003-10-24 19:02:03 +000010467
paulfee0f4c2004-09-13 05:12:46 +000010468DEFUN (show_ip_bgp_view_rsclient,
10469 show_ip_bgp_view_rsclient_cmd,
10470 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10471 SHOW_STR
10472 IP_STR
10473 BGP_STR
10474 "BGP view\n"
10475 "BGP view name\n"
10476 "Information about Route Server Client\n"
10477 NEIGHBOR_ADDR_STR)
10478{
10479 struct bgp_table *table;
10480 struct peer *peer;
10481
10482 if (argc == 2)
10483 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10484 else
10485 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10486
10487 if (! peer)
10488 return CMD_WARNING;
10489
10490 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10491 {
10492 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10493 VTY_NEWLINE);
10494 return CMD_WARNING;
10495 }
10496
10497 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10498 PEER_FLAG_RSERVER_CLIENT))
10499 {
10500 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10501 VTY_NEWLINE);
10502 return CMD_WARNING;
10503 }
10504
10505 table = peer->rib[AFI_IP][SAFI_UNICAST];
10506
ajs5a646652004-11-05 01:25:55 +000010507 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010508}
10509
10510ALIAS (show_ip_bgp_view_rsclient,
10511 show_ip_bgp_rsclient_cmd,
10512 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10513 SHOW_STR
10514 IP_STR
10515 BGP_STR
10516 "Information about Route Server Client\n"
10517 NEIGHBOR_ADDR_STR)
10518
Michael Lambert95cbbd22010-07-23 14:43:04 -040010519DEFUN (show_bgp_view_ipv4_safi_rsclient,
10520 show_bgp_view_ipv4_safi_rsclient_cmd,
10521 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10522 SHOW_STR
10523 BGP_STR
10524 "BGP view\n"
10525 "BGP view name\n"
10526 "Address family\n"
10527 "Address Family modifier\n"
10528 "Address Family modifier\n"
10529 "Information about Route Server Client\n"
10530 NEIGHBOR_ADDR_STR)
10531{
10532 struct bgp_table *table;
10533 struct peer *peer;
10534 safi_t safi;
10535
10536 if (argc == 3) {
10537 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10538 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10539 } else {
10540 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10541 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10542 }
10543
10544 if (! peer)
10545 return CMD_WARNING;
10546
10547 if (! peer->afc[AFI_IP][safi])
10548 {
10549 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10550 VTY_NEWLINE);
10551 return CMD_WARNING;
10552 }
10553
10554 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10555 PEER_FLAG_RSERVER_CLIENT))
10556 {
10557 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10558 VTY_NEWLINE);
10559 return CMD_WARNING;
10560 }
10561
10562 table = peer->rib[AFI_IP][safi];
10563
10564 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10565}
10566
10567ALIAS (show_bgp_view_ipv4_safi_rsclient,
10568 show_bgp_ipv4_safi_rsclient_cmd,
10569 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10570 SHOW_STR
10571 BGP_STR
10572 "Address family\n"
10573 "Address Family modifier\n"
10574 "Address Family modifier\n"
10575 "Information about Route Server Client\n"
10576 NEIGHBOR_ADDR_STR)
10577
paulfee0f4c2004-09-13 05:12:46 +000010578DEFUN (show_ip_bgp_view_rsclient_route,
10579 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010580 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010581 SHOW_STR
10582 IP_STR
10583 BGP_STR
10584 "BGP view\n"
10585 "BGP view name\n"
10586 "Information about Route Server Client\n"
10587 NEIGHBOR_ADDR_STR
10588 "Network in the BGP routing table to display\n")
10589{
10590 struct bgp *bgp;
10591 struct peer *peer;
10592
10593 /* BGP structure lookup. */
10594 if (argc == 3)
10595 {
10596 bgp = bgp_lookup_by_name (argv[0]);
10597 if (bgp == NULL)
10598 {
10599 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10600 return CMD_WARNING;
10601 }
10602 }
10603 else
10604 {
10605 bgp = bgp_get_default ();
10606 if (bgp == NULL)
10607 {
10608 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10609 return CMD_WARNING;
10610 }
10611 }
10612
10613 if (argc == 3)
10614 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10615 else
10616 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10617
10618 if (! peer)
10619 return CMD_WARNING;
10620
10621 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10622 {
10623 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10624 VTY_NEWLINE);
10625 return CMD_WARNING;
10626}
10627
10628 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10629 PEER_FLAG_RSERVER_CLIENT))
10630 {
10631 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10632 VTY_NEWLINE);
10633 return CMD_WARNING;
10634 }
10635
10636 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10637 (argc == 3) ? argv[2] : argv[1],
10638 AFI_IP, SAFI_UNICAST, NULL, 0);
10639}
10640
10641ALIAS (show_ip_bgp_view_rsclient_route,
10642 show_ip_bgp_rsclient_route_cmd,
10643 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10644 SHOW_STR
10645 IP_STR
10646 BGP_STR
10647 "Information about Route Server Client\n"
10648 NEIGHBOR_ADDR_STR
10649 "Network in the BGP routing table to display\n")
10650
Michael Lambert95cbbd22010-07-23 14:43:04 -040010651DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10652 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10653 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10654 SHOW_STR
10655 BGP_STR
10656 "BGP view\n"
10657 "BGP view name\n"
10658 "Address family\n"
10659 "Address Family modifier\n"
10660 "Address Family modifier\n"
10661 "Information about Route Server Client\n"
10662 NEIGHBOR_ADDR_STR
10663 "Network in the BGP routing table to display\n")
10664{
10665 struct bgp *bgp;
10666 struct peer *peer;
10667 safi_t safi;
10668
10669 /* BGP structure lookup. */
10670 if (argc == 4)
10671 {
10672 bgp = bgp_lookup_by_name (argv[0]);
10673 if (bgp == NULL)
10674 {
10675 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10676 return CMD_WARNING;
10677 }
10678 }
10679 else
10680 {
10681 bgp = bgp_get_default ();
10682 if (bgp == NULL)
10683 {
10684 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10685 return CMD_WARNING;
10686 }
10687 }
10688
10689 if (argc == 4) {
10690 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10691 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10692 } else {
10693 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10694 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10695 }
10696
10697 if (! peer)
10698 return CMD_WARNING;
10699
10700 if (! peer->afc[AFI_IP][safi])
10701 {
10702 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10703 VTY_NEWLINE);
10704 return CMD_WARNING;
10705}
10706
10707 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10708 PEER_FLAG_RSERVER_CLIENT))
10709 {
10710 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10711 VTY_NEWLINE);
10712 return CMD_WARNING;
10713 }
10714
10715 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10716 (argc == 4) ? argv[3] : argv[2],
10717 AFI_IP, safi, NULL, 0);
10718}
10719
10720ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10721 show_bgp_ipv4_safi_rsclient_route_cmd,
10722 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10723 SHOW_STR
10724 BGP_STR
10725 "Address family\n"
10726 "Address Family modifier\n"
10727 "Address Family modifier\n"
10728 "Information about Route Server Client\n"
10729 NEIGHBOR_ADDR_STR
10730 "Network in the BGP routing table to display\n")
10731
paulfee0f4c2004-09-13 05:12:46 +000010732DEFUN (show_ip_bgp_view_rsclient_prefix,
10733 show_ip_bgp_view_rsclient_prefix_cmd,
10734 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10735 SHOW_STR
10736 IP_STR
10737 BGP_STR
10738 "BGP view\n"
10739 "BGP view name\n"
10740 "Information about Route Server Client\n"
10741 NEIGHBOR_ADDR_STR
10742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10743{
10744 struct bgp *bgp;
10745 struct peer *peer;
10746
10747 /* BGP structure lookup. */
10748 if (argc == 3)
10749 {
10750 bgp = bgp_lookup_by_name (argv[0]);
10751 if (bgp == NULL)
10752 {
10753 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10754 return CMD_WARNING;
10755 }
10756 }
10757 else
10758 {
10759 bgp = bgp_get_default ();
10760 if (bgp == NULL)
10761 {
10762 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10763 return CMD_WARNING;
10764 }
10765 }
10766
10767 if (argc == 3)
10768 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10769 else
10770 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10771
10772 if (! peer)
10773 return CMD_WARNING;
10774
10775 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10776 {
10777 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10778 VTY_NEWLINE);
10779 return CMD_WARNING;
10780}
10781
10782 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10783 PEER_FLAG_RSERVER_CLIENT))
10784{
10785 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10786 VTY_NEWLINE);
10787 return CMD_WARNING;
10788 }
10789
10790 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10791 (argc == 3) ? argv[2] : argv[1],
10792 AFI_IP, SAFI_UNICAST, NULL, 1);
10793}
10794
10795ALIAS (show_ip_bgp_view_rsclient_prefix,
10796 show_ip_bgp_rsclient_prefix_cmd,
10797 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10798 SHOW_STR
10799 IP_STR
10800 BGP_STR
10801 "Information about Route Server Client\n"
10802 NEIGHBOR_ADDR_STR
10803 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10804
Michael Lambert95cbbd22010-07-23 14:43:04 -040010805DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10806 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10807 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10808 SHOW_STR
10809 BGP_STR
10810 "BGP view\n"
10811 "BGP view name\n"
10812 "Address family\n"
10813 "Address Family modifier\n"
10814 "Address Family modifier\n"
10815 "Information about Route Server Client\n"
10816 NEIGHBOR_ADDR_STR
10817 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10818{
10819 struct bgp *bgp;
10820 struct peer *peer;
10821 safi_t safi;
10822
10823 /* BGP structure lookup. */
10824 if (argc == 4)
10825 {
10826 bgp = bgp_lookup_by_name (argv[0]);
10827 if (bgp == NULL)
10828 {
10829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832 }
10833 else
10834 {
10835 bgp = bgp_get_default ();
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842
10843 if (argc == 4) {
10844 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10845 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10846 } else {
10847 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10848 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10849 }
10850
10851 if (! peer)
10852 return CMD_WARNING;
10853
10854 if (! peer->afc[AFI_IP][safi])
10855 {
10856 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10857 VTY_NEWLINE);
10858 return CMD_WARNING;
10859}
10860
10861 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10862 PEER_FLAG_RSERVER_CLIENT))
10863{
10864 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10865 VTY_NEWLINE);
10866 return CMD_WARNING;
10867 }
10868
10869 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10870 (argc == 4) ? argv[3] : argv[2],
10871 AFI_IP, safi, NULL, 1);
10872}
10873
10874ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10875 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10876 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10877 SHOW_STR
10878 BGP_STR
10879 "Address family\n"
10880 "Address Family modifier\n"
10881 "Address Family modifier\n"
10882 "Information about Route Server Client\n"
10883 NEIGHBOR_ADDR_STR
10884 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010885
paul718e3742002-12-13 20:15:29 +000010886#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010887DEFUN (show_bgp_view_neighbor_routes,
10888 show_bgp_view_neighbor_routes_cmd,
10889 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10890 SHOW_STR
10891 BGP_STR
10892 "BGP view\n"
10893 "BGP view name\n"
10894 "Detailed information on TCP and BGP neighbor connections\n"
10895 "Neighbor to display information about\n"
10896 "Neighbor to display information about\n"
10897 "Display routes learned from neighbor\n")
10898{
10899 struct peer *peer;
10900
10901 if (argc == 2)
10902 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10903 else
10904 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10905
10906 if (! peer)
10907 return CMD_WARNING;
10908
10909 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10910 bgp_show_type_neighbor);
10911}
10912
10913ALIAS (show_bgp_view_neighbor_routes,
10914 show_bgp_view_ipv6_neighbor_routes_cmd,
10915 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10916 SHOW_STR
10917 BGP_STR
10918 "BGP view\n"
10919 "BGP view name\n"
10920 "Address family\n"
10921 "Detailed information on TCP and BGP neighbor connections\n"
10922 "Neighbor to display information about\n"
10923 "Neighbor to display information about\n"
10924 "Display routes learned from neighbor\n")
10925
10926DEFUN (show_bgp_view_neighbor_damp,
10927 show_bgp_view_neighbor_damp_cmd,
10928 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10929 SHOW_STR
10930 BGP_STR
10931 "BGP view\n"
10932 "BGP view name\n"
10933 "Detailed information on TCP and BGP neighbor connections\n"
10934 "Neighbor to display information about\n"
10935 "Neighbor to display information about\n"
10936 "Display the dampened routes received from neighbor\n")
10937{
10938 struct peer *peer;
10939
10940 if (argc == 2)
10941 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10942 else
10943 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10944
10945 if (! peer)
10946 return CMD_WARNING;
10947
10948 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10949 bgp_show_type_damp_neighbor);
10950}
10951
10952ALIAS (show_bgp_view_neighbor_damp,
10953 show_bgp_view_ipv6_neighbor_damp_cmd,
10954 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10955 SHOW_STR
10956 BGP_STR
10957 "BGP view\n"
10958 "BGP view name\n"
10959 "Address family\n"
10960 "Detailed information on TCP and BGP neighbor connections\n"
10961 "Neighbor to display information about\n"
10962 "Neighbor to display information about\n"
10963 "Display the dampened routes received from neighbor\n")
10964
10965DEFUN (show_bgp_view_neighbor_flap,
10966 show_bgp_view_neighbor_flap_cmd,
10967 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10968 SHOW_STR
10969 BGP_STR
10970 "BGP view\n"
10971 "BGP view name\n"
10972 "Detailed information on TCP and BGP neighbor connections\n"
10973 "Neighbor to display information about\n"
10974 "Neighbor to display information about\n"
10975 "Display flap statistics of the routes learned from neighbor\n")
10976{
10977 struct peer *peer;
10978
10979 if (argc == 2)
10980 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10981 else
10982 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10983
10984 if (! peer)
10985 return CMD_WARNING;
10986
10987 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10988 bgp_show_type_flap_neighbor);
10989}
10990
10991ALIAS (show_bgp_view_neighbor_flap,
10992 show_bgp_view_ipv6_neighbor_flap_cmd,
10993 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10994 SHOW_STR
10995 BGP_STR
10996 "BGP view\n"
10997 "BGP view name\n"
10998 "Address family\n"
10999 "Detailed information on TCP and BGP neighbor connections\n"
11000 "Neighbor to display information about\n"
11001 "Neighbor to display information about\n"
11002 "Display flap statistics of the routes learned from neighbor\n")
11003
11004ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011005 show_bgp_neighbor_routes_cmd,
11006 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11007 SHOW_STR
11008 BGP_STR
11009 "Detailed information on TCP and BGP neighbor connections\n"
11010 "Neighbor to display information about\n"
11011 "Neighbor to display information about\n"
11012 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011013
paulbb46e942003-10-24 19:02:03 +000011014
11015ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011016 show_bgp_ipv6_neighbor_routes_cmd,
11017 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11018 SHOW_STR
11019 BGP_STR
11020 "Address family\n"
11021 "Detailed information on TCP and BGP neighbor connections\n"
11022 "Neighbor to display information about\n"
11023 "Neighbor to display information about\n"
11024 "Display routes learned from neighbor\n")
11025
11026/* old command */
paulbb46e942003-10-24 19:02:03 +000011027ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011028 ipv6_bgp_neighbor_routes_cmd,
11029 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11030 SHOW_STR
11031 IPV6_STR
11032 BGP_STR
11033 "Detailed information on TCP and BGP neighbor connections\n"
11034 "Neighbor to display information about\n"
11035 "Neighbor to display information about\n"
11036 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011037
11038/* old command */
11039DEFUN (ipv6_mbgp_neighbor_routes,
11040 ipv6_mbgp_neighbor_routes_cmd,
11041 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11042 SHOW_STR
11043 IPV6_STR
11044 MBGP_STR
11045 "Detailed information on TCP and BGP neighbor connections\n"
11046 "Neighbor to display information about\n"
11047 "Neighbor to display information about\n"
11048 "Display routes learned from neighbor\n")
11049{
paulbb46e942003-10-24 19:02:03 +000011050 struct peer *peer;
11051
11052 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11053 if (! peer)
11054 return CMD_WARNING;
11055
11056 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011057 bgp_show_type_neighbor);
11058}
paulbb46e942003-10-24 19:02:03 +000011059
11060ALIAS (show_bgp_view_neighbor_flap,
11061 show_bgp_neighbor_flap_cmd,
11062 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11063 SHOW_STR
11064 BGP_STR
11065 "Detailed information on TCP and BGP neighbor connections\n"
11066 "Neighbor to display information about\n"
11067 "Neighbor to display information about\n"
11068 "Display flap statistics of the routes learned from neighbor\n")
11069
11070ALIAS (show_bgp_view_neighbor_flap,
11071 show_bgp_ipv6_neighbor_flap_cmd,
11072 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11073 SHOW_STR
11074 BGP_STR
11075 "Address family\n"
11076 "Detailed information on TCP and BGP neighbor connections\n"
11077 "Neighbor to display information about\n"
11078 "Neighbor to display information about\n"
11079 "Display flap statistics of the routes learned from neighbor\n")
11080
11081ALIAS (show_bgp_view_neighbor_damp,
11082 show_bgp_neighbor_damp_cmd,
11083 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11084 SHOW_STR
11085 BGP_STR
11086 "Detailed information on TCP and BGP neighbor connections\n"
11087 "Neighbor to display information about\n"
11088 "Neighbor to display information about\n"
11089 "Display the dampened routes received from neighbor\n")
11090
11091ALIAS (show_bgp_view_neighbor_damp,
11092 show_bgp_ipv6_neighbor_damp_cmd,
11093 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11094 SHOW_STR
11095 BGP_STR
11096 "Address family\n"
11097 "Detailed information on TCP and BGP neighbor connections\n"
11098 "Neighbor to display information about\n"
11099 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011100 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011101
11102DEFUN (show_bgp_view_rsclient,
11103 show_bgp_view_rsclient_cmd,
11104 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11105 SHOW_STR
11106 BGP_STR
11107 "BGP view\n"
11108 "BGP view name\n"
11109 "Information about Route Server Client\n"
11110 NEIGHBOR_ADDR_STR)
11111{
11112 struct bgp_table *table;
11113 struct peer *peer;
11114
11115 if (argc == 2)
11116 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11117 else
11118 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11119
11120 if (! peer)
11121 return CMD_WARNING;
11122
11123 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11124 {
11125 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11126 VTY_NEWLINE);
11127 return CMD_WARNING;
11128 }
11129
11130 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11131 PEER_FLAG_RSERVER_CLIENT))
11132 {
11133 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11134 VTY_NEWLINE);
11135 return CMD_WARNING;
11136 }
11137
11138 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11139
ajs5a646652004-11-05 01:25:55 +000011140 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011141}
11142
11143ALIAS (show_bgp_view_rsclient,
11144 show_bgp_rsclient_cmd,
11145 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11146 SHOW_STR
11147 BGP_STR
11148 "Information about Route Server Client\n"
11149 NEIGHBOR_ADDR_STR)
11150
Michael Lambert95cbbd22010-07-23 14:43:04 -040011151DEFUN (show_bgp_view_ipv6_safi_rsclient,
11152 show_bgp_view_ipv6_safi_rsclient_cmd,
11153 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11154 SHOW_STR
11155 BGP_STR
11156 "BGP view\n"
11157 "BGP view name\n"
11158 "Address family\n"
11159 "Address Family modifier\n"
11160 "Address Family modifier\n"
11161 "Information about Route Server Client\n"
11162 NEIGHBOR_ADDR_STR)
11163{
11164 struct bgp_table *table;
11165 struct peer *peer;
11166 safi_t safi;
11167
11168 if (argc == 3) {
11169 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11170 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11171 } else {
11172 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11173 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11174 }
11175
11176 if (! peer)
11177 return CMD_WARNING;
11178
11179 if (! peer->afc[AFI_IP6][safi])
11180 {
11181 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11182 VTY_NEWLINE);
11183 return CMD_WARNING;
11184 }
11185
11186 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11187 PEER_FLAG_RSERVER_CLIENT))
11188 {
11189 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11190 VTY_NEWLINE);
11191 return CMD_WARNING;
11192 }
11193
11194 table = peer->rib[AFI_IP6][safi];
11195
11196 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11197}
11198
11199ALIAS (show_bgp_view_ipv6_safi_rsclient,
11200 show_bgp_ipv6_safi_rsclient_cmd,
11201 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11202 SHOW_STR
11203 BGP_STR
11204 "Address family\n"
11205 "Address Family modifier\n"
11206 "Address Family modifier\n"
11207 "Information about Route Server Client\n"
11208 NEIGHBOR_ADDR_STR)
11209
paulfee0f4c2004-09-13 05:12:46 +000011210DEFUN (show_bgp_view_rsclient_route,
11211 show_bgp_view_rsclient_route_cmd,
11212 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11213 SHOW_STR
11214 BGP_STR
11215 "BGP view\n"
11216 "BGP view name\n"
11217 "Information about Route Server Client\n"
11218 NEIGHBOR_ADDR_STR
11219 "Network in the BGP routing table to display\n")
11220{
11221 struct bgp *bgp;
11222 struct peer *peer;
11223
11224 /* BGP structure lookup. */
11225 if (argc == 3)
11226 {
11227 bgp = bgp_lookup_by_name (argv[0]);
11228 if (bgp == NULL)
11229 {
11230 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11231 return CMD_WARNING;
11232 }
11233 }
11234 else
11235 {
11236 bgp = bgp_get_default ();
11237 if (bgp == NULL)
11238 {
11239 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11240 return CMD_WARNING;
11241 }
11242 }
11243
11244 if (argc == 3)
11245 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11246 else
11247 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11248
11249 if (! peer)
11250 return CMD_WARNING;
11251
11252 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11253 {
11254 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11255 VTY_NEWLINE);
11256 return CMD_WARNING;
11257 }
11258
11259 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11260 PEER_FLAG_RSERVER_CLIENT))
11261 {
11262 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11263 VTY_NEWLINE);
11264 return CMD_WARNING;
11265 }
11266
11267 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11268 (argc == 3) ? argv[2] : argv[1],
11269 AFI_IP6, SAFI_UNICAST, NULL, 0);
11270}
11271
11272ALIAS (show_bgp_view_rsclient_route,
11273 show_bgp_rsclient_route_cmd,
11274 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11275 SHOW_STR
11276 BGP_STR
11277 "Information about Route Server Client\n"
11278 NEIGHBOR_ADDR_STR
11279 "Network in the BGP routing table to display\n")
11280
Michael Lambert95cbbd22010-07-23 14:43:04 -040011281DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11282 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11283 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11284 SHOW_STR
11285 BGP_STR
11286 "BGP view\n"
11287 "BGP view name\n"
11288 "Address family\n"
11289 "Address Family modifier\n"
11290 "Address Family modifier\n"
11291 "Information about Route Server Client\n"
11292 NEIGHBOR_ADDR_STR
11293 "Network in the BGP routing table to display\n")
11294{
11295 struct bgp *bgp;
11296 struct peer *peer;
11297 safi_t safi;
11298
11299 /* BGP structure lookup. */
11300 if (argc == 4)
11301 {
11302 bgp = bgp_lookup_by_name (argv[0]);
11303 if (bgp == NULL)
11304 {
11305 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11306 return CMD_WARNING;
11307 }
11308 }
11309 else
11310 {
11311 bgp = bgp_get_default ();
11312 if (bgp == NULL)
11313 {
11314 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11315 return CMD_WARNING;
11316 }
11317 }
11318
11319 if (argc == 4) {
11320 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11321 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11322 } else {
11323 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11324 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11325 }
11326
11327 if (! peer)
11328 return CMD_WARNING;
11329
11330 if (! peer->afc[AFI_IP6][safi])
11331 {
11332 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11333 VTY_NEWLINE);
11334 return CMD_WARNING;
11335}
11336
11337 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11338 PEER_FLAG_RSERVER_CLIENT))
11339 {
11340 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11341 VTY_NEWLINE);
11342 return CMD_WARNING;
11343 }
11344
11345 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11346 (argc == 4) ? argv[3] : argv[2],
11347 AFI_IP6, safi, NULL, 0);
11348}
11349
11350ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11351 show_bgp_ipv6_safi_rsclient_route_cmd,
11352 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11353 SHOW_STR
11354 BGP_STR
11355 "Address family\n"
11356 "Address Family modifier\n"
11357 "Address Family modifier\n"
11358 "Information about Route Server Client\n"
11359 NEIGHBOR_ADDR_STR
11360 "Network in the BGP routing table to display\n")
11361
paulfee0f4c2004-09-13 05:12:46 +000011362DEFUN (show_bgp_view_rsclient_prefix,
11363 show_bgp_view_rsclient_prefix_cmd,
11364 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11365 SHOW_STR
11366 BGP_STR
11367 "BGP view\n"
11368 "BGP view name\n"
11369 "Information about Route Server Client\n"
11370 NEIGHBOR_ADDR_STR
11371 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11372{
11373 struct bgp *bgp;
11374 struct peer *peer;
11375
11376 /* BGP structure lookup. */
11377 if (argc == 3)
11378 {
11379 bgp = bgp_lookup_by_name (argv[0]);
11380 if (bgp == NULL)
11381 {
11382 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11383 return CMD_WARNING;
11384 }
11385 }
11386 else
11387 {
11388 bgp = bgp_get_default ();
11389 if (bgp == NULL)
11390 {
11391 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11392 return CMD_WARNING;
11393 }
11394 }
11395
11396 if (argc == 3)
11397 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11398 else
11399 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11400
11401 if (! peer)
11402 return CMD_WARNING;
11403
11404 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11405 {
11406 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11407 VTY_NEWLINE);
11408 return CMD_WARNING;
11409 }
11410
11411 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11412 PEER_FLAG_RSERVER_CLIENT))
11413 {
11414 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11415 VTY_NEWLINE);
11416 return CMD_WARNING;
11417 }
11418
11419 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11420 (argc == 3) ? argv[2] : argv[1],
11421 AFI_IP6, SAFI_UNICAST, NULL, 1);
11422}
11423
11424ALIAS (show_bgp_view_rsclient_prefix,
11425 show_bgp_rsclient_prefix_cmd,
11426 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11427 SHOW_STR
11428 BGP_STR
11429 "Information about Route Server Client\n"
11430 NEIGHBOR_ADDR_STR
11431 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11432
Michael Lambert95cbbd22010-07-23 14:43:04 -040011433DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11434 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11435 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11436 SHOW_STR
11437 BGP_STR
11438 "BGP view\n"
11439 "BGP view name\n"
11440 "Address family\n"
11441 "Address Family modifier\n"
11442 "Address Family modifier\n"
11443 "Information about Route Server Client\n"
11444 NEIGHBOR_ADDR_STR
11445 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11446{
11447 struct bgp *bgp;
11448 struct peer *peer;
11449 safi_t safi;
11450
11451 /* BGP structure lookup. */
11452 if (argc == 4)
11453 {
11454 bgp = bgp_lookup_by_name (argv[0]);
11455 if (bgp == NULL)
11456 {
11457 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11458 return CMD_WARNING;
11459 }
11460 }
11461 else
11462 {
11463 bgp = bgp_get_default ();
11464 if (bgp == NULL)
11465 {
11466 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11467 return CMD_WARNING;
11468 }
11469 }
11470
11471 if (argc == 4) {
11472 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11473 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11474 } else {
11475 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11476 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11477 }
11478
11479 if (! peer)
11480 return CMD_WARNING;
11481
11482 if (! peer->afc[AFI_IP6][safi])
11483 {
11484 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11485 VTY_NEWLINE);
11486 return CMD_WARNING;
11487}
11488
11489 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11490 PEER_FLAG_RSERVER_CLIENT))
11491{
11492 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11493 VTY_NEWLINE);
11494 return CMD_WARNING;
11495 }
11496
11497 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11498 (argc == 4) ? argv[3] : argv[2],
11499 AFI_IP6, safi, NULL, 1);
11500}
11501
11502ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11503 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11504 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11505 SHOW_STR
11506 BGP_STR
11507 "Address family\n"
11508 "Address Family modifier\n"
11509 "Address Family modifier\n"
11510 "Information about Route Server Client\n"
11511 NEIGHBOR_ADDR_STR
11512 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11513
paul718e3742002-12-13 20:15:29 +000011514#endif /* HAVE_IPV6 */
11515
11516struct bgp_table *bgp_distance_table;
11517
11518struct bgp_distance
11519{
11520 /* Distance value for the IP source prefix. */
11521 u_char distance;
11522
11523 /* Name of the access-list to be matched. */
11524 char *access_list;
11525};
11526
paul94f2b392005-06-28 12:44:16 +000011527static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011528bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011529{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011530 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011531}
11532
paul94f2b392005-06-28 12:44:16 +000011533static void
paul718e3742002-12-13 20:15:29 +000011534bgp_distance_free (struct bgp_distance *bdistance)
11535{
11536 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11537}
11538
paul94f2b392005-06-28 12:44:16 +000011539static int
paulfd79ac92004-10-13 05:06:08 +000011540bgp_distance_set (struct vty *vty, const char *distance_str,
11541 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011542{
11543 int ret;
11544 struct prefix_ipv4 p;
11545 u_char distance;
11546 struct bgp_node *rn;
11547 struct bgp_distance *bdistance;
11548
11549 ret = str2prefix_ipv4 (ip_str, &p);
11550 if (ret == 0)
11551 {
11552 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11553 return CMD_WARNING;
11554 }
11555
11556 distance = atoi (distance_str);
11557
11558 /* Get BGP distance node. */
11559 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11560 if (rn->info)
11561 {
11562 bdistance = rn->info;
11563 bgp_unlock_node (rn);
11564 }
11565 else
11566 {
11567 bdistance = bgp_distance_new ();
11568 rn->info = bdistance;
11569 }
11570
11571 /* Set distance value. */
11572 bdistance->distance = distance;
11573
11574 /* Reset access-list configuration. */
11575 if (bdistance->access_list)
11576 {
11577 free (bdistance->access_list);
11578 bdistance->access_list = NULL;
11579 }
11580 if (access_list_str)
11581 bdistance->access_list = strdup (access_list_str);
11582
11583 return CMD_SUCCESS;
11584}
11585
paul94f2b392005-06-28 12:44:16 +000011586static int
paulfd79ac92004-10-13 05:06:08 +000011587bgp_distance_unset (struct vty *vty, const char *distance_str,
11588 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011589{
11590 int ret;
11591 struct prefix_ipv4 p;
11592 u_char distance;
11593 struct bgp_node *rn;
11594 struct bgp_distance *bdistance;
11595
11596 ret = str2prefix_ipv4 (ip_str, &p);
11597 if (ret == 0)
11598 {
11599 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11600 return CMD_WARNING;
11601 }
11602
11603 distance = atoi (distance_str);
11604
11605 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11606 if (! rn)
11607 {
11608 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11609 return CMD_WARNING;
11610 }
11611
11612 bdistance = rn->info;
11613
11614 if (bdistance->access_list)
11615 free (bdistance->access_list);
11616 bgp_distance_free (bdistance);
11617
11618 rn->info = NULL;
11619 bgp_unlock_node (rn);
11620 bgp_unlock_node (rn);
11621
11622 return CMD_SUCCESS;
11623}
11624
paul718e3742002-12-13 20:15:29 +000011625/* Apply BGP information to distance method. */
11626u_char
11627bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11628{
11629 struct bgp_node *rn;
11630 struct prefix_ipv4 q;
11631 struct peer *peer;
11632 struct bgp_distance *bdistance;
11633 struct access_list *alist;
11634 struct bgp_static *bgp_static;
11635
11636 if (! bgp)
11637 return 0;
11638
11639 if (p->family != AF_INET)
11640 return 0;
11641
11642 peer = rinfo->peer;
11643
11644 if (peer->su.sa.sa_family != AF_INET)
11645 return 0;
11646
11647 memset (&q, 0, sizeof (struct prefix_ipv4));
11648 q.family = AF_INET;
11649 q.prefix = peer->su.sin.sin_addr;
11650 q.prefixlen = IPV4_MAX_BITLEN;
11651
11652 /* Check source address. */
11653 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11654 if (rn)
11655 {
11656 bdistance = rn->info;
11657 bgp_unlock_node (rn);
11658
11659 if (bdistance->access_list)
11660 {
11661 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11662 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11663 return bdistance->distance;
11664 }
11665 else
11666 return bdistance->distance;
11667 }
11668
11669 /* Backdoor check. */
11670 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11671 if (rn)
11672 {
11673 bgp_static = rn->info;
11674 bgp_unlock_node (rn);
11675
11676 if (bgp_static->backdoor)
11677 {
11678 if (bgp->distance_local)
11679 return bgp->distance_local;
11680 else
11681 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11682 }
11683 }
11684
11685 if (peer_sort (peer) == BGP_PEER_EBGP)
11686 {
11687 if (bgp->distance_ebgp)
11688 return bgp->distance_ebgp;
11689 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11690 }
11691 else
11692 {
11693 if (bgp->distance_ibgp)
11694 return bgp->distance_ibgp;
11695 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11696 }
11697}
11698
11699DEFUN (bgp_distance,
11700 bgp_distance_cmd,
11701 "distance bgp <1-255> <1-255> <1-255>",
11702 "Define an administrative distance\n"
11703 "BGP distance\n"
11704 "Distance for routes external to the AS\n"
11705 "Distance for routes internal to the AS\n"
11706 "Distance for local routes\n")
11707{
11708 struct bgp *bgp;
11709
11710 bgp = vty->index;
11711
11712 bgp->distance_ebgp = atoi (argv[0]);
11713 bgp->distance_ibgp = atoi (argv[1]);
11714 bgp->distance_local = atoi (argv[2]);
11715 return CMD_SUCCESS;
11716}
11717
11718DEFUN (no_bgp_distance,
11719 no_bgp_distance_cmd,
11720 "no distance bgp <1-255> <1-255> <1-255>",
11721 NO_STR
11722 "Define an administrative distance\n"
11723 "BGP distance\n"
11724 "Distance for routes external to the AS\n"
11725 "Distance for routes internal to the AS\n"
11726 "Distance for local routes\n")
11727{
11728 struct bgp *bgp;
11729
11730 bgp = vty->index;
11731
11732 bgp->distance_ebgp= 0;
11733 bgp->distance_ibgp = 0;
11734 bgp->distance_local = 0;
11735 return CMD_SUCCESS;
11736}
11737
11738ALIAS (no_bgp_distance,
11739 no_bgp_distance2_cmd,
11740 "no distance bgp",
11741 NO_STR
11742 "Define an administrative distance\n"
11743 "BGP distance\n")
11744
11745DEFUN (bgp_distance_source,
11746 bgp_distance_source_cmd,
11747 "distance <1-255> A.B.C.D/M",
11748 "Define an administrative distance\n"
11749 "Administrative distance\n"
11750 "IP source prefix\n")
11751{
11752 bgp_distance_set (vty, argv[0], argv[1], NULL);
11753 return CMD_SUCCESS;
11754}
11755
11756DEFUN (no_bgp_distance_source,
11757 no_bgp_distance_source_cmd,
11758 "no distance <1-255> A.B.C.D/M",
11759 NO_STR
11760 "Define an administrative distance\n"
11761 "Administrative distance\n"
11762 "IP source prefix\n")
11763{
11764 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11765 return CMD_SUCCESS;
11766}
11767
11768DEFUN (bgp_distance_source_access_list,
11769 bgp_distance_source_access_list_cmd,
11770 "distance <1-255> A.B.C.D/M WORD",
11771 "Define an administrative distance\n"
11772 "Administrative distance\n"
11773 "IP source prefix\n"
11774 "Access list name\n")
11775{
11776 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11777 return CMD_SUCCESS;
11778}
11779
11780DEFUN (no_bgp_distance_source_access_list,
11781 no_bgp_distance_source_access_list_cmd,
11782 "no distance <1-255> A.B.C.D/M WORD",
11783 NO_STR
11784 "Define an administrative distance\n"
11785 "Administrative distance\n"
11786 "IP source prefix\n"
11787 "Access list name\n")
11788{
11789 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11790 return CMD_SUCCESS;
11791}
11792
11793DEFUN (bgp_damp_set,
11794 bgp_damp_set_cmd,
11795 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11796 "BGP Specific commands\n"
11797 "Enable route-flap dampening\n"
11798 "Half-life time for the penalty\n"
11799 "Value to start reusing a route\n"
11800 "Value to start suppressing a route\n"
11801 "Maximum duration to suppress a stable route\n")
11802{
11803 struct bgp *bgp;
11804 int half = DEFAULT_HALF_LIFE * 60;
11805 int reuse = DEFAULT_REUSE;
11806 int suppress = DEFAULT_SUPPRESS;
11807 int max = 4 * half;
11808
11809 if (argc == 4)
11810 {
11811 half = atoi (argv[0]) * 60;
11812 reuse = atoi (argv[1]);
11813 suppress = atoi (argv[2]);
11814 max = atoi (argv[3]) * 60;
11815 }
11816 else if (argc == 1)
11817 {
11818 half = atoi (argv[0]) * 60;
11819 max = 4 * half;
11820 }
11821
11822 bgp = vty->index;
11823 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11824 half, reuse, suppress, max);
11825}
11826
11827ALIAS (bgp_damp_set,
11828 bgp_damp_set2_cmd,
11829 "bgp dampening <1-45>",
11830 "BGP Specific commands\n"
11831 "Enable route-flap dampening\n"
11832 "Half-life time for the penalty\n")
11833
11834ALIAS (bgp_damp_set,
11835 bgp_damp_set3_cmd,
11836 "bgp dampening",
11837 "BGP Specific commands\n"
11838 "Enable route-flap dampening\n")
11839
11840DEFUN (bgp_damp_unset,
11841 bgp_damp_unset_cmd,
11842 "no bgp dampening",
11843 NO_STR
11844 "BGP Specific commands\n"
11845 "Enable route-flap dampening\n")
11846{
11847 struct bgp *bgp;
11848
11849 bgp = vty->index;
11850 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11851}
11852
11853ALIAS (bgp_damp_unset,
11854 bgp_damp_unset2_cmd,
11855 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11856 NO_STR
11857 "BGP Specific commands\n"
11858 "Enable route-flap dampening\n"
11859 "Half-life time for the penalty\n"
11860 "Value to start reusing a route\n"
11861 "Value to start suppressing a route\n"
11862 "Maximum duration to suppress a stable route\n")
11863
11864DEFUN (show_ip_bgp_dampened_paths,
11865 show_ip_bgp_dampened_paths_cmd,
11866 "show ip bgp dampened-paths",
11867 SHOW_STR
11868 IP_STR
11869 BGP_STR
11870 "Display paths suppressed due to dampening\n")
11871{
ajs5a646652004-11-05 01:25:55 +000011872 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11873 NULL);
paul718e3742002-12-13 20:15:29 +000011874}
11875
11876DEFUN (show_ip_bgp_flap_statistics,
11877 show_ip_bgp_flap_statistics_cmd,
11878 "show ip bgp flap-statistics",
11879 SHOW_STR
11880 IP_STR
11881 BGP_STR
11882 "Display flap statistics of routes\n")
11883{
ajs5a646652004-11-05 01:25:55 +000011884 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11885 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011886}
11887
11888/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011889static int
paulfd79ac92004-10-13 05:06:08 +000011890bgp_clear_damp_route (struct vty *vty, const char *view_name,
11891 const char *ip_str, afi_t afi, safi_t safi,
11892 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011893{
11894 int ret;
11895 struct prefix match;
11896 struct bgp_node *rn;
11897 struct bgp_node *rm;
11898 struct bgp_info *ri;
11899 struct bgp_info *ri_temp;
11900 struct bgp *bgp;
11901 struct bgp_table *table;
11902
11903 /* BGP structure lookup. */
11904 if (view_name)
11905 {
11906 bgp = bgp_lookup_by_name (view_name);
11907 if (bgp == NULL)
11908 {
11909 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11910 return CMD_WARNING;
11911 }
11912 }
11913 else
11914 {
11915 bgp = bgp_get_default ();
11916 if (bgp == NULL)
11917 {
11918 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11919 return CMD_WARNING;
11920 }
11921 }
11922
11923 /* Check IP address argument. */
11924 ret = str2prefix (ip_str, &match);
11925 if (! ret)
11926 {
11927 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11928 return CMD_WARNING;
11929 }
11930
11931 match.family = afi2family (afi);
11932
11933 if (safi == SAFI_MPLS_VPN)
11934 {
11935 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11936 {
11937 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11938 continue;
11939
11940 if ((table = rn->info) != NULL)
11941 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011942 {
11943 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11944 {
11945 ri = rm->info;
11946 while (ri)
11947 {
11948 if (ri->extra && ri->extra->damp_info)
11949 {
11950 ri_temp = ri->next;
11951 bgp_damp_info_free (ri->extra->damp_info, 1);
11952 ri = ri_temp;
11953 }
11954 else
11955 ri = ri->next;
11956 }
11957 }
11958
11959 bgp_unlock_node (rm);
11960 }
paul718e3742002-12-13 20:15:29 +000011961 }
11962 }
11963 else
11964 {
11965 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011966 {
11967 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11968 {
11969 ri = rn->info;
11970 while (ri)
11971 {
11972 if (ri->extra && ri->extra->damp_info)
11973 {
11974 ri_temp = ri->next;
11975 bgp_damp_info_free (ri->extra->damp_info, 1);
11976 ri = ri_temp;
11977 }
11978 else
11979 ri = ri->next;
11980 }
11981 }
11982
11983 bgp_unlock_node (rn);
11984 }
paul718e3742002-12-13 20:15:29 +000011985 }
11986
11987 return CMD_SUCCESS;
11988}
11989
11990DEFUN (clear_ip_bgp_dampening,
11991 clear_ip_bgp_dampening_cmd,
11992 "clear ip bgp dampening",
11993 CLEAR_STR
11994 IP_STR
11995 BGP_STR
11996 "Clear route flap dampening information\n")
11997{
11998 bgp_damp_info_clean ();
11999 return CMD_SUCCESS;
12000}
12001
12002DEFUN (clear_ip_bgp_dampening_prefix,
12003 clear_ip_bgp_dampening_prefix_cmd,
12004 "clear ip bgp dampening A.B.C.D/M",
12005 CLEAR_STR
12006 IP_STR
12007 BGP_STR
12008 "Clear route flap dampening information\n"
12009 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12010{
12011 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12012 SAFI_UNICAST, NULL, 1);
12013}
12014
12015DEFUN (clear_ip_bgp_dampening_address,
12016 clear_ip_bgp_dampening_address_cmd,
12017 "clear ip bgp dampening A.B.C.D",
12018 CLEAR_STR
12019 IP_STR
12020 BGP_STR
12021 "Clear route flap dampening information\n"
12022 "Network to clear damping information\n")
12023{
12024 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12025 SAFI_UNICAST, NULL, 0);
12026}
12027
12028DEFUN (clear_ip_bgp_dampening_address_mask,
12029 clear_ip_bgp_dampening_address_mask_cmd,
12030 "clear ip bgp dampening A.B.C.D A.B.C.D",
12031 CLEAR_STR
12032 IP_STR
12033 BGP_STR
12034 "Clear route flap dampening information\n"
12035 "Network to clear damping information\n"
12036 "Network mask\n")
12037{
12038 int ret;
12039 char prefix_str[BUFSIZ];
12040
12041 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12042 if (! ret)
12043 {
12044 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12045 return CMD_WARNING;
12046 }
12047
12048 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12049 SAFI_UNICAST, NULL, 0);
12050}
12051
paul94f2b392005-06-28 12:44:16 +000012052static int
paul718e3742002-12-13 20:15:29 +000012053bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12054 afi_t afi, safi_t safi, int *write)
12055{
12056 struct bgp_node *prn;
12057 struct bgp_node *rn;
12058 struct bgp_table *table;
12059 struct prefix *p;
12060 struct prefix_rd *prd;
12061 struct bgp_static *bgp_static;
12062 u_int32_t label;
12063 char buf[SU_ADDRSTRLEN];
12064 char rdbuf[RD_ADDRSTRLEN];
12065
12066 /* Network configuration. */
12067 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12068 if ((table = prn->info) != NULL)
12069 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12070 if ((bgp_static = rn->info) != NULL)
12071 {
12072 p = &rn->p;
12073 prd = (struct prefix_rd *) &prn->p;
12074
12075 /* "address-family" display. */
12076 bgp_config_write_family_header (vty, afi, safi, write);
12077
12078 /* "network" configuration display. */
12079 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12080 label = decode_label (bgp_static->tag);
12081
12082 vty_out (vty, " network %s/%d rd %s tag %d",
12083 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12084 p->prefixlen,
12085 rdbuf, label);
12086 vty_out (vty, "%s", VTY_NEWLINE);
12087 }
12088 return 0;
12089}
12090
12091/* Configuration of static route announcement and aggregate
12092 information. */
12093int
12094bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12095 afi_t afi, safi_t safi, int *write)
12096{
12097 struct bgp_node *rn;
12098 struct prefix *p;
12099 struct bgp_static *bgp_static;
12100 struct bgp_aggregate *bgp_aggregate;
12101 char buf[SU_ADDRSTRLEN];
12102
12103 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12104 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12105
12106 /* Network configuration. */
12107 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12108 if ((bgp_static = rn->info) != NULL)
12109 {
12110 p = &rn->p;
12111
12112 /* "address-family" display. */
12113 bgp_config_write_family_header (vty, afi, safi, write);
12114
12115 /* "network" configuration display. */
12116 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12117 {
12118 u_int32_t destination;
12119 struct in_addr netmask;
12120
12121 destination = ntohl (p->u.prefix4.s_addr);
12122 masklen2ip (p->prefixlen, &netmask);
12123 vty_out (vty, " network %s",
12124 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12125
12126 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12127 || (IN_CLASSB (destination) && p->prefixlen == 16)
12128 || (IN_CLASSA (destination) && p->prefixlen == 8)
12129 || p->u.prefix4.s_addr == 0)
12130 {
12131 /* Natural mask is not display. */
12132 }
12133 else
12134 vty_out (vty, " mask %s", inet_ntoa (netmask));
12135 }
12136 else
12137 {
12138 vty_out (vty, " network %s/%d",
12139 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12140 p->prefixlen);
12141 }
12142
12143 if (bgp_static->rmap.name)
12144 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012145 else
12146 {
12147 if (bgp_static->backdoor)
12148 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012149 }
paul718e3742002-12-13 20:15:29 +000012150
12151 vty_out (vty, "%s", VTY_NEWLINE);
12152 }
12153
12154 /* Aggregate-address configuration. */
12155 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12156 if ((bgp_aggregate = rn->info) != NULL)
12157 {
12158 p = &rn->p;
12159
12160 /* "address-family" display. */
12161 bgp_config_write_family_header (vty, afi, safi, write);
12162
12163 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12164 {
12165 struct in_addr netmask;
12166
12167 masklen2ip (p->prefixlen, &netmask);
12168 vty_out (vty, " aggregate-address %s %s",
12169 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12170 inet_ntoa (netmask));
12171 }
12172 else
12173 {
12174 vty_out (vty, " aggregate-address %s/%d",
12175 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12176 p->prefixlen);
12177 }
12178
12179 if (bgp_aggregate->as_set)
12180 vty_out (vty, " as-set");
12181
12182 if (bgp_aggregate->summary_only)
12183 vty_out (vty, " summary-only");
12184
12185 vty_out (vty, "%s", VTY_NEWLINE);
12186 }
12187
12188 return 0;
12189}
12190
12191int
12192bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12193{
12194 struct bgp_node *rn;
12195 struct bgp_distance *bdistance;
12196
12197 /* Distance configuration. */
12198 if (bgp->distance_ebgp
12199 && bgp->distance_ibgp
12200 && bgp->distance_local
12201 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12202 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12203 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12204 vty_out (vty, " distance bgp %d %d %d%s",
12205 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12206 VTY_NEWLINE);
12207
12208 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12209 if ((bdistance = rn->info) != NULL)
12210 {
12211 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12212 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12213 bdistance->access_list ? bdistance->access_list : "",
12214 VTY_NEWLINE);
12215 }
12216
12217 return 0;
12218}
12219
12220/* Allocate routing table structure and install commands. */
12221void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012222bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012223{
12224 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012225 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012226
12227 /* IPv4 BGP commands. */
12228 install_element (BGP_NODE, &bgp_network_cmd);
12229 install_element (BGP_NODE, &bgp_network_mask_cmd);
12230 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12231 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12232 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12233 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12234 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12235 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12236 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12237 install_element (BGP_NODE, &no_bgp_network_cmd);
12238 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12239 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12240 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12241 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12242 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12243 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12244 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12245 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12246
12247 install_element (BGP_NODE, &aggregate_address_cmd);
12248 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12249 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12250 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12251 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12252 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12253 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12254 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12255 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12256 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12257 install_element (BGP_NODE, &no_aggregate_address_cmd);
12258 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12259 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12260 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12261 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12262 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12263 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12264 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12265 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12266 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12267
12268 /* IPv4 unicast configuration. */
12269 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12270 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12271 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12272 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12273 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12274 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012275 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012276 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12277 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12278 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12279 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12280 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012281
paul718e3742002-12-13 20:15:29 +000012282 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12283 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12284 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12285 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12286 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12287 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12288 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12289 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12290 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12291 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12292 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12293 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12294 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12295 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12296 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12297 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12298 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12299 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12300 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12301 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12302
12303 /* IPv4 multicast configuration. */
12304 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12305 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12306 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12307 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12308 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12309 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12310 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12311 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12312 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12313 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12314 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12315 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12316 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12317 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12318 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12319 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12320 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12321 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12322 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12323 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12324 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12325 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12326 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12327 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12328 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12329 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12330 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12331 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12332 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12333 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12334 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12335 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12336
12337 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12338 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012339 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012340 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12341 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012342 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012343 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12344 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12345 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12346 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012347 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012348 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12349 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12350 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12351 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12352 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12353 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12354 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12355 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12356 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12357 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12358 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12359 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12360 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12361 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12362 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12363 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12364 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12365 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12366 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12367 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12368 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12369 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12370 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12371 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12372 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012373 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12374 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12375 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12376 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12377 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012378 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12379 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12380 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12381 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12382 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12383 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12384 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12386 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12387 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12388 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12389 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12390 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12391 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12392 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12393 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12394 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12395 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012396 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012397 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12399 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12400 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12401 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12402 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12403 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12404 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12405 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12406 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12407 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12409 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12410 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12411 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12412 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012413 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012414 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012415 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012416 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012417 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012418 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012419 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12420 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012421 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012422 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012423 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012424 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012425 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012426 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012427
12428 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12429 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12430 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012431 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012432 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12433 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12434 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012435 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012436 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12437 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12438 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12439 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12440 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12441 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12442 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12443 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12444 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12445 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12446 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12447 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012448 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12449 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12450 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12451 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12452 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012453 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12454 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12455 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12456 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12457 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12458 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12459 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12460 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12461 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012462 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012463 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012464 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012465 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012466 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012467 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012468 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012469
12470 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12471 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012472 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012473 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12474 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012475 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012476 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12477 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12478 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12479 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012480 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012481 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12482 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12483 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12484 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12485 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12486 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12487 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12488 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12489 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12490 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12491 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12492 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12493 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12494 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12495 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12496 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12497 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12498 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12499 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12500 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12501 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12502 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12503 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12504 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12505 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012506 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12507 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12508 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12509 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12510 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012511 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12512 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12513 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12514 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12515 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12516 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12517 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12518 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12519 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12520 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12521 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12522 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12523 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12524 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12525 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12526 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12527 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12528 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012530 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12531 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12532 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12533 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12534 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12535 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12536 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12537 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12538 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12539 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12540 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12542 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12543 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12544 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12545 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012546 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012547 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012548 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012549 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012550 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012551 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012552 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12553 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012554 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012556 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012557 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012558 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012559 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012560
12561 /* BGP dampening clear commands */
12562 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12563 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12564 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12565 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12566
Paul Jakmaff7924f2006-09-04 01:10:36 +000012567 /* prefix count */
12568 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012571#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012572 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12573
paul718e3742002-12-13 20:15:29 +000012574 /* New config IPv6 BGP commands. */
12575 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12576 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12577 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12578 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12579
12580 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12581 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12582 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12583 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12584
12585 /* Old config IPv6 BGP commands. */
12586 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12587 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12588
12589 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12590 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12591 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12592 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12593
12594 install_element (VIEW_NODE, &show_bgp_cmd);
12595 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012596 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012597 install_element (VIEW_NODE, &show_bgp_route_cmd);
12598 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012599 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012600 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12601 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012602 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012603 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12604 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12605 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12606 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12607 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12608 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12609 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12610 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12611 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12612 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12613 install_element (VIEW_NODE, &show_bgp_community_cmd);
12614 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12615 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12616 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12617 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12618 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12619 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12620 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12621 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12622 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12623 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12624 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12625 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12626 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12627 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12628 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12629 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12630 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12631 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12632 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12633 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12634 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12635 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12636 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12637 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12638 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12639 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12640 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12641 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12642 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012643 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12644 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12645 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12646 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012647 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012648 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012649 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012650 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012651 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012652 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012653 install_element (VIEW_NODE, &show_bgp_view_cmd);
12654 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12655 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12656 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12657 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12658 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12659 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12660 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12661 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12662 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12663 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12664 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12665 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12666 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12667 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12668 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12669 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12670 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012671 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012672 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012673 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012674 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012675 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012676 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012677
12678 /* Restricted:
12679 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12680 */
12681 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12682 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012683 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012684 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12685 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012686 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012687 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12688 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12689 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12690 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12691 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12692 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12693 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12694 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12695 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12696 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12697 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12698 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12699 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12700 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12701 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12702 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12703 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012704 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012705 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012706 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012707 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12708 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12709 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12710 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12711 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12712 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12713 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012715 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012717
12718 install_element (ENABLE_NODE, &show_bgp_cmd);
12719 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012721 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12722 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012723 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012724 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12725 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012726 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012727 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12728 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12729 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12730 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12731 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12732 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12733 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12734 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12735 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12736 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12737 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12738 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12739 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12740 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12741 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12742 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12743 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12744 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12745 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12746 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12747 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12748 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12749 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12750 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12751 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12752 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12753 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12754 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12755 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12756 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12757 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12758 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12759 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12760 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12761 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12762 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12763 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12764 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12765 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12766 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012767 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12768 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12769 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12770 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012771 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012772 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012773 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012775 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012776 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012777 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12778 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12780 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12781 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12782 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12783 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12784 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12785 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12786 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12787 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12788 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12790 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12791 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12793 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12794 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012795 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012797 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012798 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012799 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012800 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012801
12802 /* Statistics */
12803 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12807
paul718e3742002-12-13 20:15:29 +000012808 /* old command */
12809 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12810 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12811 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12812 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12813 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12814 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12815 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12816 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12817 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12818 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12819 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12820 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12821 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12822 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12823 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12824 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12825 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12826 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12827 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12828 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12829 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12830 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12831 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12832 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12833 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12834 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12835 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12836 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12837 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12838 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12839 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12840 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12841 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12842 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12843 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12844 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012845
paul718e3742002-12-13 20:15:29 +000012846 /* old command */
12847 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12848 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12849 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12850 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12851 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12852 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12853 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12854 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12855 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12856 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12857 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12858 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12859 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12860 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12861 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12862 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12863 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12864 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12865 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12866 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12867 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12868 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12869 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12870 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12871 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12872 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12873 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12874 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12875 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12876 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12877 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12878 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12879 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12880 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12881 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12882 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12883
12884 /* old command */
12885 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12886 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12887 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12888 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12889
12890 /* old command */
12891 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12892 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12893 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12894 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12895
12896 /* old command */
12897 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12898 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12899 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12900 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12901#endif /* HAVE_IPV6 */
12902
12903 install_element (BGP_NODE, &bgp_distance_cmd);
12904 install_element (BGP_NODE, &no_bgp_distance_cmd);
12905 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12906 install_element (BGP_NODE, &bgp_distance_source_cmd);
12907 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12908 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12909 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12910
12911 install_element (BGP_NODE, &bgp_damp_set_cmd);
12912 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12913 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12914 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12915 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12916 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12917 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12918 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12919 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12920 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012921
12922 /* Deprecated AS-Pathlimit commands */
12923 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12924 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12925 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12926 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12927 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12928 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12929
12930 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12931 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12932 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12933 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12934 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12935 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12936
12937 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12938 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12939 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12940 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12941 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12942 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12943
12944 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12945 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12946 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12947 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12948 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12949 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12950
12951 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12952 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12953 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12954 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12955 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12956 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12957
12958 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12959 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12960 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12961 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12962 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12963 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000012964
12965#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012966 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12967 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000012968#endif
paul718e3742002-12-13 20:15:29 +000012969}
Chris Caputo228da422009-07-18 05:44:03 +000012970
12971void
12972bgp_route_finish (void)
12973{
12974 bgp_table_unlock (bgp_distance_table);
12975 bgp_distance_table = NULL;
12976}