blob: 6477a7cccea5c67714977130c8a306f6da4af525 [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;
paulfee0f4c2004-09-13 05:12:46 +00001072
1073 from = ri->peer;
1074 filter = &rsclient->filter[afi][safi];
paulfee0f4c2004-09-13 05:12:46 +00001075
Paul Jakma750e8142008-07-22 21:11:48 +00001076 if (DISABLE_BGP_ANNOUNCE)
1077 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001078
1079 /* Do not send back route to sender. */
1080 if (from == rsclient)
1081 return 0;
1082
1083 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001085 if (! UNSUPPRESS_MAP_NAME (filter))
1086 return 0;
1087
1088 /* Default route check. */
1089 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1090 PEER_STATUS_DEFAULT_ORIGINATE))
1091 {
1092 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1093 return 0;
1094#ifdef HAVE_IPV6
1095 else if (p->family == AF_INET6 && p->prefixlen == 0)
1096 return 0;
1097#endif /* HAVE_IPV6 */
1098 }
1099
1100 /* If the attribute has originator-id and it is same as remote
1101 peer's id. */
1102 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1103 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001104 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1105 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001106 {
1107 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001108 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001109 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1110 rsclient->host,
1111 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1112 p->prefixlen);
1113 return 0;
1114 }
1115 }
1116
1117 /* ORF prefix-list filter check */
1118 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1119 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1120 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1121 if (rsclient->orf_plist[afi][safi])
1122 {
1123 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1124 return 0;
1125 }
1126
1127 /* Output filter check. */
1128 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1129 {
1130 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001131 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001132 "%s [Update:SEND] %s/%d is filtered",
1133 rsclient->host,
1134 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1135 p->prefixlen);
1136 return 0;
1137 }
1138
1139#ifdef BGP_SEND_ASPATH_CHECK
1140 /* AS path loop check. */
1141 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1142 {
1143 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001144 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001145 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001146 rsclient->host, rsclient->as);
1147 return 0;
1148 }
1149#endif /* BGP_SEND_ASPATH_CHECK */
1150
1151 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001152 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001153
1154 /* next-hop-set */
1155 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1156#ifdef HAVE_IPV6
1157 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001158 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001159#endif /* HAVE_IPV6 */
1160 )
1161 {
1162 /* Set IPv4 nexthop. */
1163 if (p->family == AF_INET)
1164 {
1165 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001166 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001167 IPV4_MAX_BYTELEN);
1168 else
1169 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1170 }
1171#ifdef HAVE_IPV6
1172 /* Set IPv6 nexthop. */
1173 if (p->family == AF_INET6)
1174 {
1175 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001176 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001177 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001178 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001179 }
1180#endif /* HAVE_IPV6 */
1181 }
1182
1183#ifdef HAVE_IPV6
1184 if (p->family == AF_INET6)
1185 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001186 struct attr_extra *attre = attr->extra;
1187
1188 assert (attr->extra);
1189
paulfee0f4c2004-09-13 05:12:46 +00001190 /* Left nexthop_local unchanged if so configured. */
1191 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1192 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1193 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001194 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1195 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001196 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001197 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001198 }
1199
1200 /* Default nexthop_local treatment for RS-Clients */
1201 else
1202 {
1203 /* Announcer and RS-Client are both in the same network */
1204 if (rsclient->shared_network && from->shared_network &&
1205 (rsclient->ifindex == from->ifindex))
1206 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001207 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1208 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001209 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001211 }
1212
1213 /* Set link-local address for shared network peer. */
1214 else if (rsclient->shared_network
1215 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1216 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
1221
1222 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001223 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001224 }
1225
1226 }
1227#endif /* HAVE_IPV6 */
1228
1229
1230 /* If this is EBGP peer and remove-private-AS is set. */
1231 if (peer_sort (rsclient) == BGP_PEER_EBGP
1232 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1233 && aspath_private_as_check (attr->aspath))
1234 attr->aspath = aspath_empty_get ();
1235
1236 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001238 {
1239 info.peer = rsclient;
1240 info.attr = attr;
1241
1242 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1243
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001245 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1246 else
1247 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1248
1249 rsclient->rmap_type = 0;
1250
1251 if (ret == RMAP_DENYMATCH)
1252 {
1253 bgp_attr_flush (attr);
1254 return 0;
1255 }
1256 }
1257
1258 return 1;
1259}
1260
1261struct bgp_info_pair
1262{
1263 struct bgp_info *old;
1264 struct bgp_info *new;
1265};
1266
paul94f2b392005-06-28 12:44:16 +00001267static void
paulfee0f4c2004-09-13 05:12:46 +00001268bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1269{
paul718e3742002-12-13 20:15:29 +00001270 struct bgp_info *new_select;
1271 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001272 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001273 struct bgp_info *ri1;
1274 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001275 struct bgp_info *nextri = NULL;
1276
paul718e3742002-12-13 20:15:29 +00001277 /* bgp deterministic-med */
1278 new_select = NULL;
1279 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1280 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1281 {
1282 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1283 continue;
1284 if (BGP_INFO_HOLDDOWN (ri1))
1285 continue;
1286
1287 new_select = ri1;
1288 if (ri1->next)
1289 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1290 {
1291 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1292 continue;
1293 if (BGP_INFO_HOLDDOWN (ri2))
1294 continue;
1295
1296 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1297 || aspath_cmp_left_confed (ri1->attr->aspath,
1298 ri2->attr->aspath))
1299 {
1300 if (bgp_info_cmp (bgp, ri2, new_select))
1301 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001302 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001303 new_select = ri2;
1304 }
1305
Paul Jakma1a392d42006-09-07 00:24:49 +00001306 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001307 }
1308 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001309 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1310 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001311 }
1312
1313 /* Check old selected route and new selected route. */
1314 old_select = NULL;
1315 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001316 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001317 {
1318 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1319 old_select = ri;
1320
1321 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001322 {
1323 /* reap REMOVED routes, if needs be
1324 * selected route must stay for a while longer though
1325 */
1326 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1327 && (ri != old_select))
1328 bgp_info_reap (rn, ri);
1329
1330 continue;
1331 }
paul718e3742002-12-13 20:15:29 +00001332
1333 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1334 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1335 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001336 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001337 continue;
1338 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001339 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1340 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001341
1342 if (bgp_info_cmp (bgp, ri, new_select))
1343 new_select = ri;
1344 }
paulb40d9392005-08-22 22:34:41 +00001345
paulfee0f4c2004-09-13 05:12:46 +00001346 result->old = old_select;
1347 result->new = new_select;
1348
1349 return;
1350}
1351
paul94f2b392005-06-28 12:44:16 +00001352static int
paulfee0f4c2004-09-13 05:12:46 +00001353bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001354 struct bgp_node *rn, afi_t afi, safi_t safi)
1355{
paulfee0f4c2004-09-13 05:12:46 +00001356 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001357 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001358
1359 p = &rn->p;
1360
Paul Jakma9eda90c2007-08-30 13:36:17 +00001361 /* Announce route to Established peer. */
1362 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001363 return 0;
1364
Paul Jakma9eda90c2007-08-30 13:36:17 +00001365 /* Address family configuration check. */
1366 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001367 return 0;
1368
Paul Jakma9eda90c2007-08-30 13:36:17 +00001369 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001370 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1371 PEER_STATUS_ORF_WAIT_REFRESH))
1372 return 0;
1373
1374 switch (rn->table->type)
1375 {
1376 case BGP_TABLE_MAIN:
1377 /* Announcement to peer->conf. If the route is filtered,
1378 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001379 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1380 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001381 else
1382 bgp_adj_out_unset (rn, peer, p, afi, safi);
1383 break;
1384 case BGP_TABLE_RSCLIENT:
1385 /* Announcement to peer->conf. If the route is filtered,
1386 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001387 if (selected &&
1388 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1389 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1390 else
1391 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001392 break;
1393 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001394
1395 bgp_attr_extra_free (&attr);
1396
paulfee0f4c2004-09-13 05:12:46 +00001397 return 0;
paul200df112005-06-01 11:17:05 +00001398}
paulfee0f4c2004-09-13 05:12:46 +00001399
paul200df112005-06-01 11:17:05 +00001400struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001401{
paul200df112005-06-01 11:17:05 +00001402 struct bgp *bgp;
1403 struct bgp_node *rn;
1404 afi_t afi;
1405 safi_t safi;
1406};
1407
1408static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001409bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001410{
paul0fb58d52005-11-14 14:31:49 +00001411 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001412 struct bgp *bgp = pq->bgp;
1413 struct bgp_node *rn = pq->rn;
1414 afi_t afi = pq->afi;
1415 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001416 struct bgp_info *new_select;
1417 struct bgp_info *old_select;
1418 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001419 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001420 struct peer *rsclient = rn->table->owner;
1421
paulfee0f4c2004-09-13 05:12:46 +00001422 /* Best path selection. */
1423 bgp_best_selection (bgp, rn, &old_and_new);
1424 new_select = old_and_new.new;
1425 old_select = old_and_new.old;
1426
paul200df112005-06-01 11:17:05 +00001427 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1428 {
Chris Caputo228da422009-07-18 05:44:03 +00001429 if (rsclient->group)
1430 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1431 {
1432 /* Nothing to do. */
1433 if (old_select && old_select == new_select)
1434 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1435 continue;
paulfee0f4c2004-09-13 05:12:46 +00001436
Chris Caputo228da422009-07-18 05:44:03 +00001437 if (old_select)
1438 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1439 if (new_select)
1440 {
1441 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1442 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1443 }
paulfee0f4c2004-09-13 05:12:46 +00001444
Chris Caputo228da422009-07-18 05:44:03 +00001445 bgp_process_announce_selected (rsclient, new_select, rn,
1446 afi, safi);
1447 }
paul200df112005-06-01 11:17:05 +00001448 }
1449 else
1450 {
hassob7395792005-08-26 12:58:38 +00001451 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001452 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001453 if (new_select)
1454 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001455 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1456 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001457 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001458 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001459 }
paulfee0f4c2004-09-13 05:12:46 +00001460
paulb40d9392005-08-22 22:34:41 +00001461 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1462 bgp_info_reap (rn, old_select);
1463
paul200df112005-06-01 11:17:05 +00001464 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1465 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001466}
1467
paul200df112005-06-01 11:17:05 +00001468static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001469bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001470{
paul0fb58d52005-11-14 14:31:49 +00001471 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001472 struct bgp *bgp = pq->bgp;
1473 struct bgp_node *rn = pq->rn;
1474 afi_t afi = pq->afi;
1475 safi_t safi = pq->safi;
1476 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001477 struct bgp_info *new_select;
1478 struct bgp_info *old_select;
1479 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001480 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001481 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001482
paulfee0f4c2004-09-13 05:12:46 +00001483 /* Best path selection. */
1484 bgp_best_selection (bgp, rn, &old_and_new);
1485 old_select = old_and_new.old;
1486 new_select = old_and_new.new;
1487
1488 /* Nothing to do. */
1489 if (old_select && old_select == new_select)
1490 {
1491 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001492 {
1493 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1494 bgp_zebra_announce (p, old_select, bgp);
1495
1496 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1497 return WQ_SUCCESS;
1498 }
paulfee0f4c2004-09-13 05:12:46 +00001499 }
paul718e3742002-12-13 20:15:29 +00001500
hasso338b3422005-02-23 14:27:24 +00001501 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001502 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001503 if (new_select)
1504 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001505 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1506 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001507 }
1508
1509
paul718e3742002-12-13 20:15:29 +00001510 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001511 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001512 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001513 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001514 }
1515
1516 /* FIB update. */
1517 if (safi == SAFI_UNICAST && ! bgp->name &&
1518 ! bgp_option_check (BGP_OPT_NO_FIB))
1519 {
1520 if (new_select
1521 && new_select->type == ZEBRA_ROUTE_BGP
1522 && new_select->sub_type == BGP_ROUTE_NORMAL)
1523 bgp_zebra_announce (p, new_select, bgp);
1524 else
1525 {
1526 /* Withdraw the route from the kernel. */
1527 if (old_select
1528 && old_select->type == ZEBRA_ROUTE_BGP
1529 && old_select->sub_type == BGP_ROUTE_NORMAL)
1530 bgp_zebra_withdraw (p, old_select);
1531 }
1532 }
paulb40d9392005-08-22 22:34:41 +00001533
1534 /* Reap old select bgp_info, it it has been removed */
1535 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1536 bgp_info_reap (rn, old_select);
1537
paul200df112005-06-01 11:17:05 +00001538 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1539 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001540}
1541
paul200df112005-06-01 11:17:05 +00001542static void
paul0fb58d52005-11-14 14:31:49 +00001543bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001544{
paul0fb58d52005-11-14 14:31:49 +00001545 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001546 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001547
Chris Caputo228da422009-07-18 05:44:03 +00001548 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001549 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001550 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001551 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1552}
1553
1554static void
1555bgp_process_queue_init (void)
1556{
1557 bm->process_main_queue
1558 = work_queue_new (bm->master, "process_main_queue");
1559 bm->process_rsclient_queue
1560 = work_queue_new (bm->master, "process_rsclient_queue");
1561
1562 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1563 {
1564 zlog_err ("%s: Failed to allocate work queue", __func__);
1565 exit (1);
1566 }
1567
1568 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001569 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001570 bm->process_main_queue->spec.max_retries = 0;
1571 bm->process_main_queue->spec.hold = 50;
1572
1573 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1574 sizeof (struct work_queue *));
1575 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001576}
1577
1578void
paulfee0f4c2004-09-13 05:12:46 +00001579bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1580{
paul200df112005-06-01 11:17:05 +00001581 struct bgp_process_queue *pqnode;
1582
1583 /* already scheduled for processing? */
1584 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1585 return;
1586
1587 if ( (bm->process_main_queue == NULL) ||
1588 (bm->process_rsclient_queue == NULL) )
1589 bgp_process_queue_init ();
1590
1591 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1592 sizeof (struct bgp_process_queue));
1593 if (!pqnode)
1594 return;
Chris Caputo228da422009-07-18 05:44:03 +00001595
1596 /* all unlocked in bgp_processq_del */
1597 bgp_table_lock (rn->table);
1598 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001599 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001600 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001601 pqnode->afi = afi;
1602 pqnode->safi = safi;
1603
paulfee0f4c2004-09-13 05:12:46 +00001604 switch (rn->table->type)
1605 {
paul200df112005-06-01 11:17:05 +00001606 case BGP_TABLE_MAIN:
1607 work_queue_add (bm->process_main_queue, pqnode);
1608 break;
1609 case BGP_TABLE_RSCLIENT:
1610 work_queue_add (bm->process_rsclient_queue, pqnode);
1611 break;
paulfee0f4c2004-09-13 05:12:46 +00001612 }
paul200df112005-06-01 11:17:05 +00001613
1614 return;
paulfee0f4c2004-09-13 05:12:46 +00001615}
hasso0a486e52005-02-01 20:57:17 +00001616
paul94f2b392005-06-28 12:44:16 +00001617static int
hasso0a486e52005-02-01 20:57:17 +00001618bgp_maximum_prefix_restart_timer (struct thread *thread)
1619{
1620 struct peer *peer;
1621
1622 peer = THREAD_ARG (thread);
1623 peer->t_pmax_restart = NULL;
1624
1625 if (BGP_DEBUG (events, EVENTS))
1626 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1627 peer->host);
1628
1629 peer_clear (peer);
1630
1631 return 0;
1632}
1633
paulfee0f4c2004-09-13 05:12:46 +00001634int
paul5228ad22004-06-04 17:58:18 +00001635bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1636 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001637{
hassoe0701b72004-05-20 09:19:34 +00001638 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1639 return 0;
1640
1641 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001642 {
hassoe0701b72004-05-20 09:19:34 +00001643 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1644 && ! always)
1645 return 0;
paul718e3742002-12-13 20:15:29 +00001646
hassoe0701b72004-05-20 09:19:34 +00001647 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001648 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1649 "limit %ld", afi_safi_print (afi, safi), peer->host,
1650 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001651 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001652
hassoe0701b72004-05-20 09:19:34 +00001653 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1654 return 0;
paul718e3742002-12-13 20:15:29 +00001655
hassoe0701b72004-05-20 09:19:34 +00001656 {
paul5228ad22004-06-04 17:58:18 +00001657 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001658
1659 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001660 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001661
1662 ndata[0] = (afi >> 8);
1663 ndata[1] = afi;
1664 ndata[2] = safi;
1665 ndata[3] = (peer->pmax[afi][safi] >> 24);
1666 ndata[4] = (peer->pmax[afi][safi] >> 16);
1667 ndata[5] = (peer->pmax[afi][safi] >> 8);
1668 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001669
1670 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1671 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1672 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1673 }
hasso0a486e52005-02-01 20:57:17 +00001674
1675 /* restart timer start */
1676 if (peer->pmax_restart[afi][safi])
1677 {
1678 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1679
1680 if (BGP_DEBUG (events, EVENTS))
1681 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1682 peer->host, peer->v_pmax_restart);
1683
1684 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1685 peer->v_pmax_restart);
1686 }
1687
hassoe0701b72004-05-20 09:19:34 +00001688 return 1;
paul718e3742002-12-13 20:15:29 +00001689 }
hassoe0701b72004-05-20 09:19:34 +00001690 else
1691 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1692
1693 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1694 {
1695 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1696 && ! always)
1697 return 0;
1698
1699 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001700 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1701 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1702 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001703 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1704 }
1705 else
1706 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001707 return 0;
1708}
1709
paulb40d9392005-08-22 22:34:41 +00001710/* Unconditionally remove the route from the RIB, without taking
1711 * damping into consideration (eg, because the session went down)
1712 */
paul94f2b392005-06-28 12:44:16 +00001713static void
paul718e3742002-12-13 20:15:29 +00001714bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1715 afi_t afi, safi_t safi)
1716{
paul902212c2006-02-05 17:51:19 +00001717 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1718
1719 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1720 bgp_info_delete (rn, ri); /* keep historical info */
1721
paulb40d9392005-08-22 22:34:41 +00001722 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001723}
1724
paul94f2b392005-06-28 12:44:16 +00001725static void
paul718e3742002-12-13 20:15:29 +00001726bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001727 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001728{
paul718e3742002-12-13 20:15:29 +00001729 int status = BGP_DAMP_NONE;
1730
paulb40d9392005-08-22 22:34:41 +00001731 /* apply dampening, if result is suppressed, we'll be retaining
1732 * the bgp_info in the RIB for historical reference.
1733 */
1734 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1735 && peer_sort (peer) == BGP_PEER_EBGP)
1736 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1737 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001738 {
paul902212c2006-02-05 17:51:19 +00001739 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1740 return;
1741 }
1742
1743 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001744}
1745
paul94f2b392005-06-28 12:44:16 +00001746static void
paulfee0f4c2004-09-13 05:12:46 +00001747bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1748 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1749 int sub_type, struct prefix_rd *prd, u_char *tag)
1750{
1751 struct bgp_node *rn;
1752 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001753 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001754 struct attr *attr_new;
1755 struct attr *attr_new2;
1756 struct bgp_info *ri;
1757 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001758 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001759 char buf[SU_ADDRSTRLEN];
1760
1761 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1762 if (peer == rsclient)
1763 return;
1764
1765 bgp = peer->bgp;
1766 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1767
1768 /* Check previously received route. */
1769 for (ri = rn->info; ri; ri = ri->next)
1770 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1771 break;
1772
1773 /* AS path loop check. */
1774 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1775 {
1776 reason = "as-path contains our own AS;";
1777 goto filtered;
1778 }
1779
1780 /* Route reflector originator ID check. */
1781 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001782 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001783 {
1784 reason = "originator is us;";
1785 goto filtered;
1786 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001787
1788 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001789
1790 /* Apply export policy. */
1791 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1792 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1793 {
1794 reason = "export-policy;";
1795 goto filtered;
1796 }
1797
1798 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001799
paulfee0f4c2004-09-13 05:12:46 +00001800 /* Apply import policy. */
1801 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1802 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001803 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001804
1805 reason = "import-policy;";
1806 goto filtered;
1807 }
1808
1809 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001810 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001811
1812 /* IPv4 unicast next hop check. */
1813 if (afi == AFI_IP && safi == SAFI_UNICAST)
1814 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001815 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001816 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001817 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001818 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001819 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001820
1821 reason = "martian next-hop;";
1822 goto filtered;
1823 }
1824 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001825
1826 /* new_attr isn't passed to any functions after here */
1827 bgp_attr_extra_free (&new_attr);
1828
paulfee0f4c2004-09-13 05:12:46 +00001829 /* If the update is implicit withdraw. */
1830 if (ri)
1831 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001832 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001833
1834 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001835 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1836 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001837 {
1838
Paul Jakma1a392d42006-09-07 00:24:49 +00001839 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001840
1841 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001842 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001843 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1844 peer->host,
1845 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1846 p->prefixlen, rsclient->host);
1847
Chris Caputo228da422009-07-18 05:44:03 +00001848 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001849 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001850
Chris Caputo228da422009-07-18 05:44:03 +00001851 return;
paulfee0f4c2004-09-13 05:12:46 +00001852 }
1853
Paul Jakma16d2e242007-04-10 19:32:10 +00001854 /* Withdraw/Announce before we fully processed the withdraw */
1855 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1856 bgp_info_restore (rn, ri);
1857
paulfee0f4c2004-09-13 05:12:46 +00001858 /* Received Logging. */
1859 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001860 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001861 peer->host,
1862 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1863 p->prefixlen, rsclient->host);
1864
1865 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001866 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001867
1868 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001869 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001870 ri->attr = attr_new;
1871
1872 /* Update MPLS tag. */
1873 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001874 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001875
Paul Jakma1a392d42006-09-07 00:24:49 +00001876 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001877
1878 /* Process change. */
1879 bgp_process (bgp, rn, afi, safi);
1880 bgp_unlock_node (rn);
1881
1882 return;
1883 }
1884
1885 /* Received Logging. */
1886 if (BGP_DEBUG (update, UPDATE_IN))
1887 {
ajsd2c1f162004-12-08 21:10:20 +00001888 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001889 peer->host,
1890 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1891 p->prefixlen, rsclient->host);
1892 }
1893
1894 /* Make new BGP info. */
1895 new = bgp_info_new ();
1896 new->type = type;
1897 new->sub_type = sub_type;
1898 new->peer = peer;
1899 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001900 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001901
1902 /* Update MPLS tag. */
1903 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001904 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001905
Paul Jakma1a392d42006-09-07 00:24:49 +00001906 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001907
1908 /* Register new BGP information. */
1909 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001910
1911 /* route_node_get lock */
1912 bgp_unlock_node (rn);
1913
paulfee0f4c2004-09-13 05:12:46 +00001914 /* Process change. */
1915 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001916
1917 bgp_attr_extra_free (&new_attr);
1918
paulfee0f4c2004-09-13 05:12:46 +00001919 return;
1920
1921 filtered:
1922
1923 /* This BGP update is filtered. Log the reason then update BGP entry. */
1924 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001925 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001926 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1927 peer->host,
1928 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1929 p->prefixlen, rsclient->host, reason);
1930
1931 if (ri)
paulb40d9392005-08-22 22:34:41 +00001932 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001933
1934 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001935
1936 if (new_attr.extra)
1937 bgp_attr_extra_free (&new_attr);
1938
paulfee0f4c2004-09-13 05:12:46 +00001939 return;
1940}
1941
paul94f2b392005-06-28 12:44:16 +00001942static void
paulfee0f4c2004-09-13 05:12:46 +00001943bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1944 struct peer *peer, struct prefix *p, int type, int sub_type,
1945 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001946{
paulfee0f4c2004-09-13 05:12:46 +00001947 struct bgp_node *rn;
1948 struct bgp_info *ri;
1949 char buf[SU_ADDRSTRLEN];
1950
1951 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00001952 return;
paulfee0f4c2004-09-13 05:12:46 +00001953
1954 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1955
1956 /* Lookup withdrawn route. */
1957 for (ri = rn->info; ri; ri = ri->next)
1958 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1959 break;
1960
1961 /* Withdraw specified route from routing table. */
1962 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001963 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001964 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001965 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001966 "%s Can't find the route %s/%d", peer->host,
1967 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1968 p->prefixlen);
1969
1970 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00001971 bgp_unlock_node (rn);
1972}
paulfee0f4c2004-09-13 05:12:46 +00001973
paul94f2b392005-06-28 12:44:16 +00001974static int
paulfee0f4c2004-09-13 05:12:46 +00001975bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001976 afi_t afi, safi_t safi, int type, int sub_type,
1977 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1978{
1979 int ret;
1980 int aspath_loop_count = 0;
1981 struct bgp_node *rn;
1982 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001983 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00001984 struct attr *attr_new;
1985 struct bgp_info *ri;
1986 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001987 const char *reason;
paul718e3742002-12-13 20:15:29 +00001988 char buf[SU_ADDRSTRLEN];
1989
1990 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001991 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00001992
paul718e3742002-12-13 20:15:29 +00001993 /* When peer's soft reconfiguration enabled. Record input packet in
1994 Adj-RIBs-In. */
1995 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1996 && peer != bgp->peer_self && ! soft_reconfig)
1997 bgp_adj_in_set (rn, peer, attr);
1998
1999 /* Check previously received route. */
2000 for (ri = rn->info; ri; ri = ri->next)
2001 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2002 break;
2003
2004 /* AS path local-as loop check. */
2005 if (peer->change_local_as)
2006 {
2007 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2008 aspath_loop_count = 1;
2009
2010 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2011 {
2012 reason = "as-path contains our own AS;";
2013 goto filtered;
2014 }
2015 }
2016
2017 /* AS path loop check. */
2018 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2019 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2020 && aspath_loop_check(attr->aspath, bgp->confed_id)
2021 > peer->allowas_in[afi][safi]))
2022 {
2023 reason = "as-path contains our own AS;";
2024 goto filtered;
2025 }
2026
2027 /* Route reflector originator ID check. */
2028 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002029 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002030 {
2031 reason = "originator is us;";
2032 goto filtered;
2033 }
2034
2035 /* Route reflector cluster ID check. */
2036 if (bgp_cluster_filter (peer, attr))
2037 {
2038 reason = "reflected from the same cluster;";
2039 goto filtered;
2040 }
2041
2042 /* Apply incoming filter. */
2043 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2044 {
2045 reason = "filter;";
2046 goto filtered;
2047 }
2048
2049 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002050 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002051
2052 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2053 {
2054 reason = "route-map;";
2055 goto filtered;
2056 }
2057
2058 /* IPv4 unicast next hop check. */
2059 if (afi == AFI_IP && safi == SAFI_UNICAST)
2060 {
2061 /* If the peer is EBGP and nexthop is not on connected route,
2062 discard it. */
2063 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2064 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002065 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002066 {
2067 reason = "non-connected next-hop;";
2068 goto filtered;
2069 }
2070
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002071 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002072 must not be my own address. */
2073 if (bgp_nexthop_self (afi, &new_attr)
2074 || new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002075 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paul718e3742002-12-13 20:15:29 +00002076 {
2077 reason = "martian next-hop;";
2078 goto filtered;
2079 }
2080 }
2081
2082 attr_new = bgp_attr_intern (&new_attr);
2083
2084 /* If the update is implicit withdraw. */
2085 if (ri)
2086 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002087 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002088
2089 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002090 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2091 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002092 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002093 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002094
2095 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2096 && peer_sort (peer) == BGP_PEER_EBGP
2097 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2098 {
2099 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002100 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002101 peer->host,
2102 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2103 p->prefixlen);
2104
paul902212c2006-02-05 17:51:19 +00002105 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2106 {
2107 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2108 bgp_process (bgp, rn, afi, safi);
2109 }
paul718e3742002-12-13 20:15:29 +00002110 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002111 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002112 {
2113 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002114 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002115 "%s rcvd %s/%d...duplicate ignored",
2116 peer->host,
2117 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2118 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002119
2120 /* graceful restart STALE flag unset. */
2121 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2122 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002123 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002124 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002125 }
paul718e3742002-12-13 20:15:29 +00002126 }
2127
2128 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002129 bgp_attr_unintern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002130 bgp_attr_extra_free (&new_attr);
2131
paul718e3742002-12-13 20:15:29 +00002132 return 0;
2133 }
2134
Paul Jakma16d2e242007-04-10 19:32:10 +00002135 /* Withdraw/Announce before we fully processed the withdraw */
2136 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2137 {
2138 if (BGP_DEBUG (update, UPDATE_IN))
2139 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2140 peer->host,
2141 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2142 p->prefixlen);
2143 bgp_info_restore (rn, ri);
2144 }
2145
paul718e3742002-12-13 20:15:29 +00002146 /* Received Logging. */
2147 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002148 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002149 peer->host,
2150 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2151 p->prefixlen);
2152
hasso93406d82005-02-02 14:40:33 +00002153 /* graceful restart STALE flag unset. */
2154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002155 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002156
paul718e3742002-12-13 20:15:29 +00002157 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002158 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002159
2160 /* implicit withdraw, decrement aggregate and pcount here.
2161 * only if update is accepted, they'll increment below.
2162 */
paul902212c2006-02-05 17:51:19 +00002163 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2164
paul718e3742002-12-13 20:15:29 +00002165 /* Update bgp route dampening information. */
2166 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2167 && peer_sort (peer) == BGP_PEER_EBGP)
2168 {
2169 /* This is implicit withdraw so we should update dampening
2170 information. */
2171 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2172 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002173 }
2174
paul718e3742002-12-13 20:15:29 +00002175 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002176 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002177 ri->attr = attr_new;
2178
2179 /* Update MPLS tag. */
2180 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002181 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002182
2183 /* Update bgp route dampening information. */
2184 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2185 && peer_sort (peer) == BGP_PEER_EBGP)
2186 {
2187 /* Now we do normal update dampening. */
2188 ret = bgp_damp_update (ri, rn, afi, safi);
2189 if (ret == BGP_DAMP_SUPPRESSED)
2190 {
2191 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002192 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002193 return 0;
2194 }
2195 }
2196
2197 /* Nexthop reachability check. */
2198 if ((afi == AFI_IP || afi == AFI_IP6)
2199 && safi == SAFI_UNICAST
2200 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002201 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002202 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002203 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002204 {
2205 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002206 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002207 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002208 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002209 }
2210 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002211 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002212
2213 /* Process change. */
2214 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2215
2216 bgp_process (bgp, rn, afi, safi);
2217 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002218 bgp_attr_extra_free (&new_attr);
2219
paul718e3742002-12-13 20:15:29 +00002220 return 0;
2221 }
2222
2223 /* Received Logging. */
2224 if (BGP_DEBUG (update, UPDATE_IN))
2225 {
ajsd2c1f162004-12-08 21:10:20 +00002226 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002227 peer->host,
2228 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2229 p->prefixlen);
2230 }
2231
paul718e3742002-12-13 20:15:29 +00002232 /* Make new BGP info. */
2233 new = bgp_info_new ();
2234 new->type = type;
2235 new->sub_type = sub_type;
2236 new->peer = peer;
2237 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002238 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002239
2240 /* Update MPLS tag. */
2241 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002242 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002243
2244 /* Nexthop reachability check. */
2245 if ((afi == AFI_IP || afi == AFI_IP6)
2246 && safi == SAFI_UNICAST
2247 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002248 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002249 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002250 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002251 {
2252 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002253 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002254 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002256 }
2257 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002258 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002259
paul902212c2006-02-05 17:51:19 +00002260 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002261 bgp_aggregate_increment (bgp, p, new, afi, safi);
2262
2263 /* Register new BGP information. */
2264 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002265
2266 /* route_node_get lock */
2267 bgp_unlock_node (rn);
2268
Paul Jakmafb982c22007-05-04 20:15:47 +00002269 bgp_attr_extra_free (&new_attr);
2270
paul718e3742002-12-13 20:15:29 +00002271 /* If maximum prefix count is configured and current prefix
2272 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002273 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2274 return -1;
paul718e3742002-12-13 20:15:29 +00002275
2276 /* Process change. */
2277 bgp_process (bgp, rn, afi, safi);
2278
2279 return 0;
2280
2281 /* This BGP update is filtered. Log the reason then update BGP
2282 entry. */
2283 filtered:
2284 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002285 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002286 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2287 peer->host,
2288 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2289 p->prefixlen, reason);
2290
2291 if (ri)
paulb40d9392005-08-22 22:34:41 +00002292 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002293
2294 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002295
2296 bgp_attr_extra_free (&new_attr);
2297
paul718e3742002-12-13 20:15:29 +00002298 return 0;
2299}
2300
2301int
paulfee0f4c2004-09-13 05:12:46 +00002302bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2303 afi_t afi, safi_t safi, int type, int sub_type,
2304 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2305{
2306 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002307 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002308 struct bgp *bgp;
2309 int ret;
2310
2311 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2312 soft_reconfig);
2313
2314 bgp = peer->bgp;
2315
2316 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002317 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002318 {
2319 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2320 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2321 sub_type, prd, tag);
2322 }
2323
2324 return ret;
2325}
2326
2327int
paul718e3742002-12-13 20:15:29 +00002328bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002329 afi_t afi, safi_t safi, int type, int sub_type,
2330 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002331{
2332 struct bgp *bgp;
2333 char buf[SU_ADDRSTRLEN];
2334 struct bgp_node *rn;
2335 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002336 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002337 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002338
2339 bgp = peer->bgp;
2340
paulfee0f4c2004-09-13 05:12:46 +00002341 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002342 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002343 {
2344 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2345 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2346 }
2347
paul718e3742002-12-13 20:15:29 +00002348 /* Logging. */
2349 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002350 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002351 peer->host,
2352 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2353 p->prefixlen);
2354
2355 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002356 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002357
2358 /* If peer is soft reconfiguration enabled. Record input packet for
2359 further calculation. */
2360 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2361 && peer != bgp->peer_self)
2362 bgp_adj_in_unset (rn, peer);
2363
2364 /* Lookup withdrawn route. */
2365 for (ri = rn->info; ri; ri = ri->next)
2366 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2367 break;
2368
2369 /* Withdraw specified route from routing table. */
2370 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002371 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002372 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002373 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002374 "%s Can't find the route %s/%d", peer->host,
2375 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2376 p->prefixlen);
2377
2378 /* Unlock bgp_node_get() lock. */
2379 bgp_unlock_node (rn);
2380
2381 return 0;
2382}
2383
2384void
2385bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2386{
2387 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002388 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002389 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002390 struct prefix p;
2391 struct bgp_info binfo;
2392 struct peer *from;
2393 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002394
Paul Jakmab2497022007-06-14 11:17:58 +00002395 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002396 return;
2397
paul718e3742002-12-13 20:15:29 +00002398 bgp = peer->bgp;
2399 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002400
paul718e3742002-12-13 20:15:29 +00002401 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2402 aspath = attr.aspath;
2403 attr.local_pref = bgp->default_local_pref;
2404 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2405
2406 if (afi == AFI_IP)
2407 str2prefix ("0.0.0.0/0", &p);
2408#ifdef HAVE_IPV6
2409 else if (afi == AFI_IP6)
2410 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002411 struct attr_extra *ae;
2412 attr.extra = NULL;
2413
2414 ae = bgp_attr_extra_get (&attr);
2415 attr.extra = ae;
2416
paul718e3742002-12-13 20:15:29 +00002417 str2prefix ("::/0", &p);
2418
2419 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002420 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002421 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002422 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002423
2424 /* If the peer is on shared nextwork and we have link-local
2425 nexthop set it. */
2426 if (peer->shared_network
2427 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2428 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002429 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002430 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002431 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002432 }
2433 }
2434#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002435
2436 if (peer->default_rmap[afi][safi].name)
2437 {
2438 binfo.peer = bgp->peer_self;
2439 binfo.attr = &attr;
2440
paulfee0f4c2004-09-13 05:12:46 +00002441 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2442
paul718e3742002-12-13 20:15:29 +00002443 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2444 RMAP_BGP, &binfo);
2445
paulfee0f4c2004-09-13 05:12:46 +00002446 bgp->peer_self->rmap_type = 0;
2447
paul718e3742002-12-13 20:15:29 +00002448 if (ret == RMAP_DENYMATCH)
2449 {
2450 bgp_attr_flush (&attr);
2451 withdraw = 1;
2452 }
2453 }
2454
2455 if (withdraw)
2456 {
2457 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2458 bgp_default_withdraw_send (peer, afi, safi);
2459 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2460 }
2461 else
2462 {
2463 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2464 bgp_default_update_send (peer, &attr, afi, safi, from);
2465 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002466
2467 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002468 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002469}
2470
2471static void
2472bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002473 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002474{
2475 struct bgp_node *rn;
2476 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002477 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002478
paul718e3742002-12-13 20:15:29 +00002479 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002480 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002481
2482 if (safi != SAFI_MPLS_VPN
2483 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2484 bgp_default_originate (peer, afi, safi, 0);
2485
2486 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2487 for (ri = rn->info; ri; ri = ri->next)
2488 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2489 {
paulfee0f4c2004-09-13 05:12:46 +00002490 if ( (rsclient) ?
2491 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2492 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002493 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2494 else
2495 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002496
2497 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002498 }
2499}
2500
2501void
2502bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2503{
2504 struct bgp_node *rn;
2505 struct bgp_table *table;
2506
2507 if (peer->status != Established)
2508 return;
2509
2510 if (! peer->afc_nego[afi][safi])
2511 return;
2512
2513 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2514 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2515 return;
2516
2517 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002518 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002519 else
2520 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2521 rn = bgp_route_next(rn))
2522 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002523 bgp_announce_table (peer, afi, safi, table, 0);
2524
2525 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2526 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002527}
2528
2529void
2530bgp_announce_route_all (struct peer *peer)
2531{
2532 afi_t afi;
2533 safi_t safi;
2534
2535 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2536 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2537 bgp_announce_route (peer, afi, safi);
2538}
2539
2540static void
paulfee0f4c2004-09-13 05:12:46 +00002541bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2542 safi_t safi, struct bgp_table *table)
2543{
2544 struct bgp_node *rn;
2545 struct bgp_adj_in *ain;
2546
2547 if (! table)
2548 table = rsclient->bgp->rib[afi][safi];
2549
2550 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2551 for (ain = rn->adj_in; ain; ain = ain->next)
2552 {
2553 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2554 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2555 }
2556}
2557
2558void
2559bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2560{
2561 struct bgp_table *table;
2562 struct bgp_node *rn;
2563
2564 if (safi != SAFI_MPLS_VPN)
2565 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2566
2567 else
2568 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2569 rn = bgp_route_next (rn))
2570 if ((table = rn->info) != NULL)
2571 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2572}
2573
2574static void
paul718e3742002-12-13 20:15:29 +00002575bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2576 struct bgp_table *table)
2577{
2578 int ret;
2579 struct bgp_node *rn;
2580 struct bgp_adj_in *ain;
2581
2582 if (! table)
2583 table = peer->bgp->rib[afi][safi];
2584
2585 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2586 for (ain = rn->adj_in; ain; ain = ain->next)
2587 {
2588 if (ain->peer == peer)
2589 {
2590 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2591 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2592 NULL, NULL, 1);
2593 if (ret < 0)
2594 {
2595 bgp_unlock_node (rn);
2596 return;
2597 }
2598 continue;
2599 }
2600 }
2601}
2602
2603void
2604bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2605{
2606 struct bgp_node *rn;
2607 struct bgp_table *table;
2608
2609 if (peer->status != Established)
2610 return;
2611
2612 if (safi != SAFI_MPLS_VPN)
2613 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2614 else
2615 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2616 rn = bgp_route_next (rn))
2617 if ((table = rn->info) != NULL)
2618 bgp_soft_reconfig_table (peer, afi, safi, table);
2619}
2620
Chris Caputo228da422009-07-18 05:44:03 +00002621
2622struct bgp_clear_node_queue
2623{
2624 struct bgp_node *rn;
2625 enum bgp_clear_route_type purpose;
2626};
2627
paul200df112005-06-01 11:17:05 +00002628static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002629bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002630{
Chris Caputo228da422009-07-18 05:44:03 +00002631 struct bgp_clear_node_queue *cnq = data;
2632 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002633 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002634 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002635 afi_t afi = rn->table->afi;
2636 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002637
Paul Jakma64e580a2006-02-21 01:09:01 +00002638 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002639
Paul Jakma64e580a2006-02-21 01:09:01 +00002640 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002641 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002642 {
2643 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002644 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2645 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002646 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002647 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2648 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002649 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002650 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002651 break;
2652 }
paul200df112005-06-01 11:17:05 +00002653 return WQ_SUCCESS;
2654}
2655
2656static void
paul0fb58d52005-11-14 14:31:49 +00002657bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002658{
Chris Caputo228da422009-07-18 05:44:03 +00002659 struct bgp_clear_node_queue *cnq = data;
2660 struct bgp_node *rn = cnq->rn;
2661 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002662
2663 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002664 bgp_table_unlock (table);
2665 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002666}
2667
2668static void
paul94f2b392005-06-28 12:44:16 +00002669bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002670{
Paul Jakma64e580a2006-02-21 01:09:01 +00002671 struct peer *peer = wq->spec.data;
2672
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002673 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002674 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002675
2676 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002677}
2678
2679static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002680bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002681{
Paul Jakmaa2943652009-07-21 14:02:04 +01002682 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002683
Paul Jakmaa2943652009-07-21 14:02:04 +01002684 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002685#undef CLEAR_QUEUE_NAME_LEN
2686
2687 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002688 {
2689 zlog_err ("%s: Failed to allocate work queue", __func__);
2690 exit (1);
2691 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002692 peer->clear_node_queue->spec.hold = 10;
2693 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2694 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2695 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2696 peer->clear_node_queue->spec.max_retries = 0;
2697
2698 /* we only 'lock' this peer reference when the queue is actually active */
2699 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002700}
2701
paul718e3742002-12-13 20:15:29 +00002702static void
2703bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002704 struct bgp_table *table, struct peer *rsclient,
2705 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002706{
2707 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002708
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002709
paul718e3742002-12-13 20:15:29 +00002710 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002711 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002712
hasso6cf159b2005-03-21 10:28:14 +00002713 /* If still no table => afi/safi isn't configured at all or smth. */
2714 if (! table)
2715 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002716
2717 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2718 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002719 struct bgp_info *ri;
2720 struct bgp_adj_in *ain;
2721 struct bgp_adj_out *aout;
2722
Paul Jakma65ca75e2006-05-04 08:08:15 +00002723 if (rn->info == NULL)
2724 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002725
2726 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2727 * queued for every clearing peer, regardless of whether it is
2728 * relevant to the peer at hand.
2729 *
2730 * Overview: There are 3 different indices which need to be
2731 * scrubbed, potentially, when a peer is removed:
2732 *
2733 * 1 peer's routes visible via the RIB (ie accepted routes)
2734 * 2 peer's routes visible by the (optional) peer's adj-in index
2735 * 3 other routes visible by the peer's adj-out index
2736 *
2737 * 3 there is no hurry in scrubbing, once the struct peer is
2738 * removed from bgp->peer, we could just GC such deleted peer's
2739 * adj-outs at our leisure.
2740 *
2741 * 1 and 2 must be 'scrubbed' in some way, at least made
2742 * invisible via RIB index before peer session is allowed to be
2743 * brought back up. So one needs to know when such a 'search' is
2744 * complete.
2745 *
2746 * Ideally:
2747 *
2748 * - there'd be a single global queue or a single RIB walker
2749 * - rather than tracking which route_nodes still need to be
2750 * examined on a peer basis, we'd track which peers still
2751 * aren't cleared
2752 *
2753 * Given that our per-peer prefix-counts now should be reliable,
2754 * this may actually be achievable. It doesn't seem to be a huge
2755 * problem at this time,
2756 */
2757 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002758 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002759 {
Chris Caputo228da422009-07-18 05:44:03 +00002760 struct bgp_clear_node_queue *cnq;
2761
2762 /* both unlocked in bgp_clear_node_queue_del */
2763 bgp_table_lock (rn->table);
2764 bgp_lock_node (rn);
2765 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2766 sizeof (struct bgp_clear_node_queue));
2767 cnq->rn = rn;
2768 cnq->purpose = purpose;
2769 work_queue_add (peer->clear_node_queue, cnq);
2770 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002771 }
2772
2773 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002774 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002775 {
2776 bgp_adj_in_remove (rn, ain);
2777 bgp_unlock_node (rn);
2778 break;
2779 }
2780 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002781 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002782 {
2783 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2784 bgp_unlock_node (rn);
2785 break;
2786 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002787 }
2788 return;
2789}
2790
2791void
Chris Caputo228da422009-07-18 05:44:03 +00002792bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2793 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002794{
2795 struct bgp_node *rn;
2796 struct bgp_table *table;
2797 struct peer *rsclient;
2798 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002799
Paul Jakma64e580a2006-02-21 01:09:01 +00002800 if (peer->clear_node_queue == NULL)
2801 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002802
Paul Jakmaca058a32006-09-14 02:58:49 +00002803 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2804 * Idle until it receives a Clearing_Completed event. This protects
2805 * against peers which flap faster than we can we clear, which could
2806 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002807 *
2808 * a) race with routes from the new session being installed before
2809 * clear_route_node visits the node (to delete the route of that
2810 * peer)
2811 * b) resource exhaustion, clear_route_node likely leads to an entry
2812 * on the process_main queue. Fast-flapping could cause that queue
2813 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002814 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002815 if (!peer->clear_node_queue->thread)
2816 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002817
Chris Caputo228da422009-07-18 05:44:03 +00002818 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002819 {
Chris Caputo228da422009-07-18 05:44:03 +00002820 case BGP_CLEAR_ROUTE_NORMAL:
2821 if (safi != SAFI_MPLS_VPN)
2822 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2823 else
2824 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2825 rn = bgp_route_next (rn))
2826 if ((table = rn->info) != NULL)
2827 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2828
2829 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2830 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2831 PEER_FLAG_RSERVER_CLIENT))
2832 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2833 break;
2834
2835 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2836 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2837 break;
2838
2839 default:
2840 assert (0);
2841 break;
paulfee0f4c2004-09-13 05:12:46 +00002842 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002843
Paul Jakmaca058a32006-09-14 02:58:49 +00002844 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002845 * completion function won't be run by workqueue code - call it here.
2846 * XXX: Actually, this assumption doesn't hold, see
2847 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002848 *
2849 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002850 * really needed if peer state is Established - peers in
2851 * pre-Established states shouldn't have any route-update state
2852 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002853 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002854 * We still can get here in pre-Established though, through
2855 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2856 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002857 *
2858 * At some future point, this check could be move to the top of the
2859 * function, and do a quick early-return when state is
2860 * pre-Established, avoiding above list and table scans. Once we're
2861 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002862 */
2863 if (!peer->clear_node_queue->thread)
2864 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002865}
2866
2867void
2868bgp_clear_route_all (struct peer *peer)
2869{
2870 afi_t afi;
2871 safi_t safi;
2872
2873 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2874 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002875 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002876}
2877
2878void
2879bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2880{
2881 struct bgp_table *table;
2882 struct bgp_node *rn;
2883 struct bgp_adj_in *ain;
2884
2885 table = peer->bgp->rib[afi][safi];
2886
2887 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2888 for (ain = rn->adj_in; ain ; ain = ain->next)
2889 if (ain->peer == peer)
2890 {
2891 bgp_adj_in_remove (rn, ain);
2892 bgp_unlock_node (rn);
2893 break;
2894 }
2895}
hasso93406d82005-02-02 14:40:33 +00002896
2897void
2898bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2899{
2900 struct bgp_node *rn;
2901 struct bgp_info *ri;
2902 struct bgp_table *table;
2903
2904 table = peer->bgp->rib[afi][safi];
2905
2906 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2907 {
2908 for (ri = rn->info; ri; ri = ri->next)
2909 if (ri->peer == peer)
2910 {
2911 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2912 bgp_rib_remove (rn, ri, peer, afi, safi);
2913 break;
2914 }
2915 }
2916}
paul718e3742002-12-13 20:15:29 +00002917
2918/* Delete all kernel routes. */
2919void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002920bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002921{
2922 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002923 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002924 struct bgp_node *rn;
2925 struct bgp_table *table;
2926 struct bgp_info *ri;
2927
paul1eb8ef22005-04-07 07:30:20 +00002928 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002929 {
2930 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2931
2932 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2933 for (ri = rn->info; ri; ri = ri->next)
2934 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2935 && ri->type == ZEBRA_ROUTE_BGP
2936 && ri->sub_type == BGP_ROUTE_NORMAL)
2937 bgp_zebra_withdraw (&rn->p, ri);
2938
2939 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2940
2941 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2942 for (ri = rn->info; ri; ri = ri->next)
2943 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2944 && ri->type == ZEBRA_ROUTE_BGP
2945 && ri->sub_type == BGP_ROUTE_NORMAL)
2946 bgp_zebra_withdraw (&rn->p, ri);
2947 }
2948}
2949
2950void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002951bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002952{
2953 vty_reset ();
2954 bgp_zclient_reset ();
2955 access_list_reset ();
2956 prefix_list_reset ();
2957}
2958
2959/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2960 value. */
2961int
2962bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2963{
2964 u_char *pnt;
2965 u_char *lim;
2966 struct prefix p;
2967 int psize;
2968 int ret;
2969
2970 /* Check peer status. */
2971 if (peer->status != Established)
2972 return 0;
2973
2974 pnt = packet->nlri;
2975 lim = pnt + packet->length;
2976
2977 for (; pnt < lim; pnt += psize)
2978 {
2979 /* Clear prefix structure. */
2980 memset (&p, 0, sizeof (struct prefix));
2981
2982 /* Fetch prefix length. */
2983 p.prefixlen = *pnt++;
2984 p.family = afi2family (packet->afi);
2985
2986 /* Already checked in nlri_sanity_check(). We do double check
2987 here. */
2988 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2989 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2990 return -1;
2991
2992 /* Packet size overflow check. */
2993 psize = PSIZE (p.prefixlen);
2994
2995 /* When packet overflow occur return immediately. */
2996 if (pnt + psize > lim)
2997 return -1;
2998
2999 /* Fetch prefix from NLRI packet. */
3000 memcpy (&p.u.prefix, pnt, psize);
3001
3002 /* Check address. */
3003 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3004 {
3005 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3006 {
paulf5ba3872004-07-09 12:11:31 +00003007 /*
3008 * From draft-ietf-idr-bgp4-22, Section 6.3:
3009 * If a BGP router receives an UPDATE message with a
3010 * semantically incorrect NLRI field, in which a prefix is
3011 * semantically incorrect (eg. an unexpected multicast IP
3012 * address), it should ignore the prefix.
3013 */
paul718e3742002-12-13 20:15:29 +00003014 zlog (peer->log, LOG_ERR,
3015 "IPv4 unicast NLRI is multicast address %s",
3016 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003017
paul718e3742002-12-13 20:15:29 +00003018 return -1;
3019 }
3020 }
3021
3022#ifdef HAVE_IPV6
3023 /* Check address. */
3024 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3025 {
3026 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3027 {
3028 char buf[BUFSIZ];
3029
3030 zlog (peer->log, LOG_WARNING,
3031 "IPv6 link-local NLRI received %s ignore this NLRI",
3032 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3033
3034 continue;
3035 }
3036 }
3037#endif /* HAVE_IPV6 */
3038
3039 /* Normal process. */
3040 if (attr)
3041 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3042 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3043 else
3044 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3045 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3046
3047 /* Address family configuration mismatch or maximum-prefix count
3048 overflow. */
3049 if (ret < 0)
3050 return -1;
3051 }
3052
3053 /* Packet length consistency check. */
3054 if (pnt != lim)
3055 return -1;
3056
3057 return 0;
3058}
3059
3060/* NLRI encode syntax check routine. */
3061int
3062bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3063 bgp_size_t length)
3064{
3065 u_char *end;
3066 u_char prefixlen;
3067 int psize;
3068
3069 end = pnt + length;
3070
3071 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3072 syntactic validity. If the field is syntactically incorrect,
3073 then the Error Subcode is set to Invalid Network Field. */
3074
3075 while (pnt < end)
3076 {
3077 prefixlen = *pnt++;
3078
3079 /* Prefix length check. */
3080 if ((afi == AFI_IP && prefixlen > 32)
3081 || (afi == AFI_IP6 && prefixlen > 128))
3082 {
3083 plog_err (peer->log,
3084 "%s [Error] Update packet error (wrong prefix length %d)",
3085 peer->host, prefixlen);
3086 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3087 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3088 return -1;
3089 }
3090
3091 /* Packet size overflow check. */
3092 psize = PSIZE (prefixlen);
3093
3094 if (pnt + psize > end)
3095 {
3096 plog_err (peer->log,
3097 "%s [Error] Update packet error"
3098 " (prefix data overflow prefix size is %d)",
3099 peer->host, psize);
3100 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3101 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3102 return -1;
3103 }
3104
3105 pnt += psize;
3106 }
3107
3108 /* Packet length consistency check. */
3109 if (pnt != end)
3110 {
3111 plog_err (peer->log,
3112 "%s [Error] Update packet error"
3113 " (prefix length mismatch with total length)",
3114 peer->host);
3115 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3116 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3117 return -1;
3118 }
3119 return 0;
3120}
3121
paul94f2b392005-06-28 12:44:16 +00003122static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003123bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003124{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003125 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003126}
3127
paul94f2b392005-06-28 12:44:16 +00003128static void
paul718e3742002-12-13 20:15:29 +00003129bgp_static_free (struct bgp_static *bgp_static)
3130{
3131 if (bgp_static->rmap.name)
3132 free (bgp_static->rmap.name);
3133 XFREE (MTYPE_BGP_STATIC, bgp_static);
3134}
3135
paul94f2b392005-06-28 12:44:16 +00003136static void
paulfee0f4c2004-09-13 05:12:46 +00003137bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3138 struct prefix *p, afi_t afi, safi_t safi)
3139{
3140 struct bgp_node *rn;
3141 struct bgp_info *ri;
3142
3143 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3144
3145 /* Check selected route and self inserted route. */
3146 for (ri = rn->info; ri; ri = ri->next)
3147 if (ri->peer == bgp->peer_self
3148 && ri->type == ZEBRA_ROUTE_BGP
3149 && ri->sub_type == BGP_ROUTE_STATIC)
3150 break;
3151
3152 /* Withdraw static BGP route from routing table. */
3153 if (ri)
3154 {
paulfee0f4c2004-09-13 05:12:46 +00003155 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003156 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003157 }
3158
3159 /* Unlock bgp_node_lookup. */
3160 bgp_unlock_node (rn);
3161}
3162
paul94f2b392005-06-28 12:44:16 +00003163static void
paulfee0f4c2004-09-13 05:12:46 +00003164bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003165 struct bgp_static *bgp_static,
3166 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003167{
3168 struct bgp_node *rn;
3169 struct bgp_info *ri;
3170 struct bgp_info *new;
3171 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003172 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003173 struct attr attr = {0 };
3174 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003175 struct bgp *bgp;
3176 int ret;
3177 char buf[SU_ADDRSTRLEN];
3178
3179 bgp = rsclient->bgp;
3180
Paul Jakma06e110f2006-05-12 23:29:22 +00003181 assert (bgp_static);
3182 if (!bgp_static)
3183 return;
3184
paulfee0f4c2004-09-13 05:12:46 +00003185 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3186
3187 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003188
3189 attr.nexthop = bgp_static->igpnexthop;
3190 attr.med = bgp_static->igpmetric;
3191 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003192
Paul Jakma41367172007-08-06 15:24:51 +00003193 if (bgp_static->atomic)
3194 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3195
paulfee0f4c2004-09-13 05:12:46 +00003196 /* Apply network route-map for export to this rsclient. */
3197 if (bgp_static->rmap.name)
3198 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003199 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003200 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003201 info.attr = &attr_tmp;
3202
paulfee0f4c2004-09-13 05:12:46 +00003203 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3204 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3205
3206 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3207
3208 rsclient->rmap_type = 0;
3209
3210 if (ret == RMAP_DENYMATCH)
3211 {
3212 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003213 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003214
3215 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003216 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003217 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003218 bgp_attr_extra_free (&attr);
3219
paulfee0f4c2004-09-13 05:12:46 +00003220 return;
3221 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003222 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003223 }
3224 else
3225 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003226
Stephen Hemminger7badc262010-08-05 10:26:31 -07003227 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003228
paulfee0f4c2004-09-13 05:12:46 +00003229 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3230
Paul Jakmafb982c22007-05-04 20:15:47 +00003231 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3232 == RMAP_DENY)
3233 {
paulfee0f4c2004-09-13 05:12:46 +00003234 /* This BGP update is filtered. Log the reason then update BGP entry. */
3235 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003236 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003237 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3238 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3239 p->prefixlen, rsclient->host);
3240
3241 bgp->peer_self->rmap_type = 0;
3242
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003243 bgp_attr_unintern (&attr_new);
3244 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003245 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003246
3247 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3248
3249 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003250 }
paulfee0f4c2004-09-13 05:12:46 +00003251
3252 bgp->peer_self->rmap_type = 0;
3253
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003254 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003255 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003256 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003257
3258 for (ri = rn->info; ri; ri = ri->next)
3259 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3260 && ri->sub_type == BGP_ROUTE_STATIC)
3261 break;
3262
3263 if (ri)
3264 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003265 if (attrhash_cmp (ri->attr, attr_new) &&
3266 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003267 {
3268 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003269 bgp_attr_unintern (&attr_new);
3270 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003271 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003272 return;
3273 }
3274 else
3275 {
3276 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003277 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003278
3279 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003280 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3281 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003282 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003283 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003284 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003285
3286 /* Process change. */
3287 bgp_process (bgp, rn, afi, safi);
3288 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003289 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003290 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003291 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 }
paulfee0f4c2004-09-13 05:12:46 +00003293 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003294
paulfee0f4c2004-09-13 05:12:46 +00003295 /* Make new BGP info. */
3296 new = bgp_info_new ();
3297 new->type = ZEBRA_ROUTE_BGP;
3298 new->sub_type = BGP_ROUTE_STATIC;
3299 new->peer = bgp->peer_self;
3300 SET_FLAG (new->flags, BGP_INFO_VALID);
3301 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003302 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003303
3304 /* Register new BGP information. */
3305 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003306
3307 /* route_node_get lock */
3308 bgp_unlock_node (rn);
3309
paulfee0f4c2004-09-13 05:12:46 +00003310 /* Process change. */
3311 bgp_process (bgp, rn, afi, safi);
3312
3313 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003314 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003315 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003316}
3317
paul94f2b392005-06-28 12:44:16 +00003318static void
paulfee0f4c2004-09-13 05:12:46 +00003319bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003320 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3321{
3322 struct bgp_node *rn;
3323 struct bgp_info *ri;
3324 struct bgp_info *new;
3325 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003326 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003327 struct attr *attr_new;
3328 int ret;
3329
Paul Jakmadd8103a2006-05-12 23:27:30 +00003330 assert (bgp_static);
3331 if (!bgp_static)
3332 return;
3333
paulfee0f4c2004-09-13 05:12:46 +00003334 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003335
3336 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003337
3338 attr.nexthop = bgp_static->igpnexthop;
3339 attr.med = bgp_static->igpmetric;
3340 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003341
Paul Jakma41367172007-08-06 15:24:51 +00003342 if (bgp_static->atomic)
3343 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3344
paul718e3742002-12-13 20:15:29 +00003345 /* Apply route-map. */
3346 if (bgp_static->rmap.name)
3347 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003349 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003350 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003351
paulfee0f4c2004-09-13 05:12:46 +00003352 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3353
paul718e3742002-12-13 20:15:29 +00003354 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003355
paulfee0f4c2004-09-13 05:12:46 +00003356 bgp->peer_self->rmap_type = 0;
3357
paul718e3742002-12-13 20:15:29 +00003358 if (ret == RMAP_DENYMATCH)
3359 {
3360 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003361 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003362
3363 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003364 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003365 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003366 bgp_static_withdraw (bgp, p, afi, safi);
3367 return;
3368 }
paul286e1e72003-08-08 00:24:31 +00003369 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003370 }
paul286e1e72003-08-08 00:24:31 +00003371 else
3372 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003373
3374 for (ri = rn->info; ri; ri = ri->next)
3375 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3376 && ri->sub_type == BGP_ROUTE_STATIC)
3377 break;
3378
3379 if (ri)
3380 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003381 if (attrhash_cmp (ri->attr, attr_new) &&
3382 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003383 {
3384 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003385 bgp_attr_unintern (&attr_new);
3386 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003387 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003388 return;
3389 }
3390 else
3391 {
3392 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003393 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003394
3395 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003396 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3397 bgp_info_restore(rn, ri);
3398 else
3399 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003400 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003401 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003402 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003403
3404 /* Process change. */
3405 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3406 bgp_process (bgp, rn, afi, safi);
3407 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003408 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003409 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003410 return;
3411 }
3412 }
3413
3414 /* Make new BGP info. */
3415 new = bgp_info_new ();
3416 new->type = ZEBRA_ROUTE_BGP;
3417 new->sub_type = BGP_ROUTE_STATIC;
3418 new->peer = bgp->peer_self;
3419 SET_FLAG (new->flags, BGP_INFO_VALID);
3420 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003421 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003422
3423 /* Aggregate address increment. */
3424 bgp_aggregate_increment (bgp, p, new, afi, safi);
3425
3426 /* Register new BGP information. */
3427 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003428
3429 /* route_node_get lock */
3430 bgp_unlock_node (rn);
3431
paul718e3742002-12-13 20:15:29 +00003432 /* Process change. */
3433 bgp_process (bgp, rn, afi, safi);
3434
3435 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003436 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003437 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003438}
3439
3440void
paulfee0f4c2004-09-13 05:12:46 +00003441bgp_static_update (struct bgp *bgp, struct prefix *p,
3442 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3443{
3444 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003445 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003446
3447 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3448
paul1eb8ef22005-04-07 07:30:20 +00003449 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003450 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003451 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3452 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003453 }
3454}
3455
paul94f2b392005-06-28 12:44:16 +00003456static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003457bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3458 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003459{
3460 struct bgp_node *rn;
3461 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003462
paulfee0f4c2004-09-13 05:12:46 +00003463 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003464
3465 /* Make new BGP info. */
3466 new = bgp_info_new ();
3467 new->type = ZEBRA_ROUTE_BGP;
3468 new->sub_type = BGP_ROUTE_STATIC;
3469 new->peer = bgp->peer_self;
3470 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3471 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003472 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003473 new->extra = bgp_info_extra_new();
3474 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003475
3476 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003477 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003478
3479 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003480 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003481
paul200df112005-06-01 11:17:05 +00003482 /* route_node_get lock */
3483 bgp_unlock_node (rn);
3484
paul718e3742002-12-13 20:15:29 +00003485 /* Process change. */
3486 bgp_process (bgp, rn, afi, safi);
3487}
3488
3489void
3490bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3491 safi_t safi)
3492{
3493 struct bgp_node *rn;
3494 struct bgp_info *ri;
3495
paulfee0f4c2004-09-13 05:12:46 +00003496 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003497
3498 /* Check selected route and self inserted route. */
3499 for (ri = rn->info; ri; ri = ri->next)
3500 if (ri->peer == bgp->peer_self
3501 && ri->type == ZEBRA_ROUTE_BGP
3502 && ri->sub_type == BGP_ROUTE_STATIC)
3503 break;
3504
3505 /* Withdraw static BGP route from routing table. */
3506 if (ri)
3507 {
3508 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003509 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003510 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003511 }
3512
3513 /* Unlock bgp_node_lookup. */
3514 bgp_unlock_node (rn);
3515}
3516
3517void
paulfee0f4c2004-09-13 05:12:46 +00003518bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3519{
3520 struct bgp_static *bgp_static;
3521 struct bgp *bgp;
3522 struct bgp_node *rn;
3523 struct prefix *p;
3524
3525 bgp = rsclient->bgp;
3526
3527 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3528 if ((bgp_static = rn->info) != NULL)
3529 {
3530 p = &rn->p;
3531
3532 bgp_static_update_rsclient (rsclient, p, bgp_static,
3533 afi, safi);
3534 }
3535}
3536
paul94f2b392005-06-28 12:44:16 +00003537static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003538bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3539 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003540{
3541 struct bgp_node *rn;
3542 struct bgp_info *ri;
3543
paulfee0f4c2004-09-13 05:12:46 +00003544 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003545
3546 /* Check selected route and self inserted route. */
3547 for (ri = rn->info; ri; ri = ri->next)
3548 if (ri->peer == bgp->peer_self
3549 && ri->type == ZEBRA_ROUTE_BGP
3550 && ri->sub_type == BGP_ROUTE_STATIC)
3551 break;
3552
3553 /* Withdraw static BGP route from routing table. */
3554 if (ri)
3555 {
3556 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003557 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003558 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003559 }
3560
3561 /* Unlock bgp_node_lookup. */
3562 bgp_unlock_node (rn);
3563}
3564
3565/* Configure static BGP network. When user don't run zebra, static
3566 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003567static int
paulfd79ac92004-10-13 05:06:08 +00003568bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003569 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003570{
3571 int ret;
3572 struct prefix p;
3573 struct bgp_static *bgp_static;
3574 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003575 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003576
3577 /* Convert IP prefix string to struct prefix. */
3578 ret = str2prefix (ip_str, &p);
3579 if (! ret)
3580 {
3581 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3582 return CMD_WARNING;
3583 }
3584#ifdef HAVE_IPV6
3585 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3586 {
3587 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3588 VTY_NEWLINE);
3589 return CMD_WARNING;
3590 }
3591#endif /* HAVE_IPV6 */
3592
3593 apply_mask (&p);
3594
3595 /* Set BGP static route configuration. */
3596 rn = bgp_node_get (bgp->route[afi][safi], &p);
3597
3598 if (rn->info)
3599 {
3600 /* Configuration change. */
3601 bgp_static = rn->info;
3602
3603 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003604 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3605 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003606
paul718e3742002-12-13 20:15:29 +00003607 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003608
paul718e3742002-12-13 20:15:29 +00003609 if (rmap)
3610 {
3611 if (bgp_static->rmap.name)
3612 free (bgp_static->rmap.name);
3613 bgp_static->rmap.name = strdup (rmap);
3614 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3615 }
3616 else
3617 {
3618 if (bgp_static->rmap.name)
3619 free (bgp_static->rmap.name);
3620 bgp_static->rmap.name = NULL;
3621 bgp_static->rmap.map = NULL;
3622 bgp_static->valid = 0;
3623 }
3624 bgp_unlock_node (rn);
3625 }
3626 else
3627 {
3628 /* New configuration. */
3629 bgp_static = bgp_static_new ();
3630 bgp_static->backdoor = backdoor;
3631 bgp_static->valid = 0;
3632 bgp_static->igpmetric = 0;
3633 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003634
paul718e3742002-12-13 20:15:29 +00003635 if (rmap)
3636 {
3637 if (bgp_static->rmap.name)
3638 free (bgp_static->rmap.name);
3639 bgp_static->rmap.name = strdup (rmap);
3640 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3641 }
3642 rn->info = bgp_static;
3643 }
3644
3645 /* If BGP scan is not enabled, we should install this route here. */
3646 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3647 {
3648 bgp_static->valid = 1;
3649
3650 if (need_update)
3651 bgp_static_withdraw (bgp, &p, afi, safi);
3652
3653 if (! bgp_static->backdoor)
3654 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3655 }
3656
3657 return CMD_SUCCESS;
3658}
3659
3660/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003661static int
paulfd79ac92004-10-13 05:06:08 +00003662bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003663 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003664{
3665 int ret;
3666 struct prefix p;
3667 struct bgp_static *bgp_static;
3668 struct bgp_node *rn;
3669
3670 /* Convert IP prefix string to struct prefix. */
3671 ret = str2prefix (ip_str, &p);
3672 if (! ret)
3673 {
3674 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3675 return CMD_WARNING;
3676 }
3677#ifdef HAVE_IPV6
3678 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3679 {
3680 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3681 VTY_NEWLINE);
3682 return CMD_WARNING;
3683 }
3684#endif /* HAVE_IPV6 */
3685
3686 apply_mask (&p);
3687
3688 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3689 if (! rn)
3690 {
3691 vty_out (vty, "%% Can't find specified static route configuration.%s",
3692 VTY_NEWLINE);
3693 return CMD_WARNING;
3694 }
3695
3696 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003697
paul718e3742002-12-13 20:15:29 +00003698 /* Update BGP RIB. */
3699 if (! bgp_static->backdoor)
3700 bgp_static_withdraw (bgp, &p, afi, safi);
3701
3702 /* Clear configuration. */
3703 bgp_static_free (bgp_static);
3704 rn->info = NULL;
3705 bgp_unlock_node (rn);
3706 bgp_unlock_node (rn);
3707
3708 return CMD_SUCCESS;
3709}
3710
3711/* Called from bgp_delete(). Delete all static routes from the BGP
3712 instance. */
3713void
3714bgp_static_delete (struct bgp *bgp)
3715{
3716 afi_t afi;
3717 safi_t safi;
3718 struct bgp_node *rn;
3719 struct bgp_node *rm;
3720 struct bgp_table *table;
3721 struct bgp_static *bgp_static;
3722
3723 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3724 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3725 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3726 if (rn->info != NULL)
3727 {
3728 if (safi == SAFI_MPLS_VPN)
3729 {
3730 table = rn->info;
3731
3732 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3733 {
3734 bgp_static = rn->info;
3735 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3736 AFI_IP, SAFI_MPLS_VPN,
3737 (struct prefix_rd *)&rn->p,
3738 bgp_static->tag);
3739 bgp_static_free (bgp_static);
3740 rn->info = NULL;
3741 bgp_unlock_node (rn);
3742 }
3743 }
3744 else
3745 {
3746 bgp_static = rn->info;
3747 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3748 bgp_static_free (bgp_static);
3749 rn->info = NULL;
3750 bgp_unlock_node (rn);
3751 }
3752 }
3753}
3754
3755int
paulfd79ac92004-10-13 05:06:08 +00003756bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3757 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003758{
3759 int ret;
3760 struct prefix p;
3761 struct prefix_rd prd;
3762 struct bgp *bgp;
3763 struct bgp_node *prn;
3764 struct bgp_node *rn;
3765 struct bgp_table *table;
3766 struct bgp_static *bgp_static;
3767 u_char tag[3];
3768
3769 bgp = vty->index;
3770
3771 ret = str2prefix (ip_str, &p);
3772 if (! ret)
3773 {
3774 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3775 return CMD_WARNING;
3776 }
3777 apply_mask (&p);
3778
3779 ret = str2prefix_rd (rd_str, &prd);
3780 if (! ret)
3781 {
3782 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3783 return CMD_WARNING;
3784 }
3785
3786 ret = str2tag (tag_str, tag);
3787 if (! ret)
3788 {
3789 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3790 return CMD_WARNING;
3791 }
3792
3793 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3794 (struct prefix *)&prd);
3795 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003796 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003797 else
3798 bgp_unlock_node (prn);
3799 table = prn->info;
3800
3801 rn = bgp_node_get (table, &p);
3802
3803 if (rn->info)
3804 {
3805 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3806 bgp_unlock_node (rn);
3807 }
3808 else
3809 {
3810 /* New configuration. */
3811 bgp_static = bgp_static_new ();
3812 bgp_static->valid = 1;
3813 memcpy (bgp_static->tag, tag, 3);
3814 rn->info = bgp_static;
3815
3816 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3817 }
3818
3819 return CMD_SUCCESS;
3820}
3821
3822/* Configure static BGP network. */
3823int
paulfd79ac92004-10-13 05:06:08 +00003824bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3825 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003826{
3827 int ret;
3828 struct bgp *bgp;
3829 struct prefix p;
3830 struct prefix_rd prd;
3831 struct bgp_node *prn;
3832 struct bgp_node *rn;
3833 struct bgp_table *table;
3834 struct bgp_static *bgp_static;
3835 u_char tag[3];
3836
3837 bgp = vty->index;
3838
3839 /* Convert IP prefix string to struct prefix. */
3840 ret = str2prefix (ip_str, &p);
3841 if (! ret)
3842 {
3843 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3844 return CMD_WARNING;
3845 }
3846 apply_mask (&p);
3847
3848 ret = str2prefix_rd (rd_str, &prd);
3849 if (! ret)
3850 {
3851 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3852 return CMD_WARNING;
3853 }
3854
3855 ret = str2tag (tag_str, tag);
3856 if (! ret)
3857 {
3858 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3859 return CMD_WARNING;
3860 }
3861
3862 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3863 (struct prefix *)&prd);
3864 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003865 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003866 else
3867 bgp_unlock_node (prn);
3868 table = prn->info;
3869
3870 rn = bgp_node_lookup (table, &p);
3871
3872 if (rn)
3873 {
3874 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3875
3876 bgp_static = rn->info;
3877 bgp_static_free (bgp_static);
3878 rn->info = NULL;
3879 bgp_unlock_node (rn);
3880 bgp_unlock_node (rn);
3881 }
3882 else
3883 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3884
3885 return CMD_SUCCESS;
3886}
3887
3888DEFUN (bgp_network,
3889 bgp_network_cmd,
3890 "network A.B.C.D/M",
3891 "Specify a network to announce via BGP\n"
3892 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3893{
3894 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003895 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003896}
3897
3898DEFUN (bgp_network_route_map,
3899 bgp_network_route_map_cmd,
3900 "network A.B.C.D/M route-map WORD",
3901 "Specify a network to announce via BGP\n"
3902 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3903 "Route-map to modify the attributes\n"
3904 "Name of the route map\n")
3905{
3906 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003907 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003908}
3909
3910DEFUN (bgp_network_backdoor,
3911 bgp_network_backdoor_cmd,
3912 "network A.B.C.D/M backdoor",
3913 "Specify a network to announce via BGP\n"
3914 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3915 "Specify a BGP backdoor route\n")
3916{
Paul Jakma41367172007-08-06 15:24:51 +00003917 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003918 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003919}
3920
3921DEFUN (bgp_network_mask,
3922 bgp_network_mask_cmd,
3923 "network A.B.C.D mask A.B.C.D",
3924 "Specify a network to announce via BGP\n"
3925 "Network number\n"
3926 "Network mask\n"
3927 "Network mask\n")
3928{
3929 int ret;
3930 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003931
paul718e3742002-12-13 20:15:29 +00003932 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3933 if (! ret)
3934 {
3935 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3936 return CMD_WARNING;
3937 }
3938
3939 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003940 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003941}
3942
3943DEFUN (bgp_network_mask_route_map,
3944 bgp_network_mask_route_map_cmd,
3945 "network A.B.C.D mask A.B.C.D route-map WORD",
3946 "Specify a network to announce via BGP\n"
3947 "Network number\n"
3948 "Network mask\n"
3949 "Network mask\n"
3950 "Route-map to modify the attributes\n"
3951 "Name of the route map\n")
3952{
3953 int ret;
3954 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003955
paul718e3742002-12-13 20:15:29 +00003956 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3957 if (! ret)
3958 {
3959 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3960 return CMD_WARNING;
3961 }
3962
3963 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003964 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00003965}
3966
3967DEFUN (bgp_network_mask_backdoor,
3968 bgp_network_mask_backdoor_cmd,
3969 "network A.B.C.D mask A.B.C.D backdoor",
3970 "Specify a network to announce via BGP\n"
3971 "Network number\n"
3972 "Network mask\n"
3973 "Network mask\n"
3974 "Specify a BGP backdoor route\n")
3975{
3976 int ret;
3977 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003978
paul718e3742002-12-13 20:15:29 +00003979 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985
Paul Jakma41367172007-08-06 15:24:51 +00003986 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003987 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003988}
3989
3990DEFUN (bgp_network_mask_natural,
3991 bgp_network_mask_natural_cmd,
3992 "network A.B.C.D",
3993 "Specify a network to announce via BGP\n"
3994 "Network number\n")
3995{
3996 int ret;
3997 char prefix_str[BUFSIZ];
3998
3999 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4000 if (! ret)
4001 {
4002 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4003 return CMD_WARNING;
4004 }
4005
4006 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004007 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004008}
4009
4010DEFUN (bgp_network_mask_natural_route_map,
4011 bgp_network_mask_natural_route_map_cmd,
4012 "network A.B.C.D route-map WORD",
4013 "Specify a network to announce via BGP\n"
4014 "Network number\n"
4015 "Route-map to modify the attributes\n"
4016 "Name of the route map\n")
4017{
4018 int ret;
4019 char prefix_str[BUFSIZ];
4020
4021 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4022 if (! ret)
4023 {
4024 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4025 return CMD_WARNING;
4026 }
4027
4028 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004029 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004030}
4031
4032DEFUN (bgp_network_mask_natural_backdoor,
4033 bgp_network_mask_natural_backdoor_cmd,
4034 "network A.B.C.D backdoor",
4035 "Specify a network to announce via BGP\n"
4036 "Network number\n"
4037 "Specify a BGP backdoor route\n")
4038{
4039 int ret;
4040 char prefix_str[BUFSIZ];
4041
4042 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4043 if (! ret)
4044 {
4045 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4046 return CMD_WARNING;
4047 }
4048
Paul Jakma41367172007-08-06 15:24:51 +00004049 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004050 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004051}
4052
4053DEFUN (no_bgp_network,
4054 no_bgp_network_cmd,
4055 "no network A.B.C.D/M",
4056 NO_STR
4057 "Specify a network to announce via BGP\n"
4058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4059{
4060 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4061 bgp_node_safi (vty));
4062}
4063
4064ALIAS (no_bgp_network,
4065 no_bgp_network_route_map_cmd,
4066 "no network A.B.C.D/M route-map WORD",
4067 NO_STR
4068 "Specify a network to announce via BGP\n"
4069 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4070 "Route-map to modify the attributes\n"
4071 "Name of the route map\n")
4072
4073ALIAS (no_bgp_network,
4074 no_bgp_network_backdoor_cmd,
4075 "no network A.B.C.D/M backdoor",
4076 NO_STR
4077 "Specify a network to announce via BGP\n"
4078 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4079 "Specify a BGP backdoor route\n")
4080
4081DEFUN (no_bgp_network_mask,
4082 no_bgp_network_mask_cmd,
4083 "no network A.B.C.D mask A.B.C.D",
4084 NO_STR
4085 "Specify a network to announce via BGP\n"
4086 "Network number\n"
4087 "Network mask\n"
4088 "Network mask\n")
4089{
4090 int ret;
4091 char prefix_str[BUFSIZ];
4092
4093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4101 bgp_node_safi (vty));
4102}
4103
4104ALIAS (no_bgp_network_mask,
4105 no_bgp_network_mask_route_map_cmd,
4106 "no network A.B.C.D mask A.B.C.D route-map WORD",
4107 NO_STR
4108 "Specify a network to announce via BGP\n"
4109 "Network number\n"
4110 "Network mask\n"
4111 "Network mask\n"
4112 "Route-map to modify the attributes\n"
4113 "Name of the route map\n")
4114
4115ALIAS (no_bgp_network_mask,
4116 no_bgp_network_mask_backdoor_cmd,
4117 "no network A.B.C.D mask A.B.C.D backdoor",
4118 NO_STR
4119 "Specify a network to announce via BGP\n"
4120 "Network number\n"
4121 "Network mask\n"
4122 "Network mask\n"
4123 "Specify a BGP backdoor route\n")
4124
4125DEFUN (no_bgp_network_mask_natural,
4126 no_bgp_network_mask_natural_cmd,
4127 "no network A.B.C.D",
4128 NO_STR
4129 "Specify a network to announce via BGP\n"
4130 "Network number\n")
4131{
4132 int ret;
4133 char prefix_str[BUFSIZ];
4134
4135 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4136 if (! ret)
4137 {
4138 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4139 return CMD_WARNING;
4140 }
4141
4142 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4143 bgp_node_safi (vty));
4144}
4145
4146ALIAS (no_bgp_network_mask_natural,
4147 no_bgp_network_mask_natural_route_map_cmd,
4148 "no network A.B.C.D route-map WORD",
4149 NO_STR
4150 "Specify a network to announce via BGP\n"
4151 "Network number\n"
4152 "Route-map to modify the attributes\n"
4153 "Name of the route map\n")
4154
4155ALIAS (no_bgp_network_mask_natural,
4156 no_bgp_network_mask_natural_backdoor_cmd,
4157 "no network A.B.C.D backdoor",
4158 NO_STR
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "Specify a BGP backdoor route\n")
4162
4163#ifdef HAVE_IPV6
4164DEFUN (ipv6_bgp_network,
4165 ipv6_bgp_network_cmd,
4166 "network X:X::X:X/M",
4167 "Specify a network to announce via BGP\n"
4168 "IPv6 prefix <network>/<length>\n")
4169{
Paul Jakma41367172007-08-06 15:24:51 +00004170 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004171 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004172}
4173
4174DEFUN (ipv6_bgp_network_route_map,
4175 ipv6_bgp_network_route_map_cmd,
4176 "network X:X::X:X/M route-map WORD",
4177 "Specify a network to announce via BGP\n"
4178 "IPv6 prefix <network>/<length>\n"
4179 "Route-map to modify the attributes\n"
4180 "Name of the route map\n")
4181{
4182 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004183 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004184}
4185
4186DEFUN (no_ipv6_bgp_network,
4187 no_ipv6_bgp_network_cmd,
4188 "no network X:X::X:X/M",
4189 NO_STR
4190 "Specify a network to announce via BGP\n"
4191 "IPv6 prefix <network>/<length>\n")
4192{
4193 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4194}
4195
4196ALIAS (no_ipv6_bgp_network,
4197 no_ipv6_bgp_network_route_map_cmd,
4198 "no network X:X::X:X/M route-map WORD",
4199 NO_STR
4200 "Specify a network to announce via BGP\n"
4201 "IPv6 prefix <network>/<length>\n"
4202 "Route-map to modify the attributes\n"
4203 "Name of the route map\n")
4204
4205ALIAS (ipv6_bgp_network,
4206 old_ipv6_bgp_network_cmd,
4207 "ipv6 bgp network X:X::X:X/M",
4208 IPV6_STR
4209 BGP_STR
4210 "Specify a network to announce via BGP\n"
4211 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4212
4213ALIAS (no_ipv6_bgp_network,
4214 old_no_ipv6_bgp_network_cmd,
4215 "no ipv6 bgp network X:X::X:X/M",
4216 NO_STR
4217 IPV6_STR
4218 BGP_STR
4219 "Specify a network to announce via BGP\n"
4220 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4221#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004222
4223/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4224ALIAS_DEPRECATED (bgp_network,
4225 bgp_network_ttl_cmd,
4226 "network A.B.C.D/M pathlimit <0-255>",
4227 "Specify a network to announce via BGP\n"
4228 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4229 "AS-Path hopcount limit attribute\n"
4230 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4231ALIAS_DEPRECATED (bgp_network_backdoor,
4232 bgp_network_backdoor_ttl_cmd,
4233 "network A.B.C.D/M backdoor pathlimit <0-255>",
4234 "Specify a network to announce via BGP\n"
4235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4236 "Specify a BGP backdoor route\n"
4237 "AS-Path hopcount limit attribute\n"
4238 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4239ALIAS_DEPRECATED (bgp_network_mask,
4240 bgp_network_mask_ttl_cmd,
4241 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4242 "Specify a network to announce via BGP\n"
4243 "Network number\n"
4244 "Network mask\n"
4245 "Network mask\n"
4246 "AS-Path hopcount limit attribute\n"
4247 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4248ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4249 bgp_network_mask_backdoor_ttl_cmd,
4250 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4251 "Specify a network to announce via BGP\n"
4252 "Network number\n"
4253 "Network mask\n"
4254 "Network mask\n"
4255 "Specify a BGP backdoor route\n"
4256 "AS-Path hopcount limit attribute\n"
4257 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4258ALIAS_DEPRECATED (bgp_network_mask_natural,
4259 bgp_network_mask_natural_ttl_cmd,
4260 "network A.B.C.D pathlimit <0-255>",
4261 "Specify a network to announce via BGP\n"
4262 "Network number\n"
4263 "AS-Path hopcount limit attribute\n"
4264 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4265ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4266 bgp_network_mask_natural_backdoor_ttl_cmd,
4267 "network A.B.C.D backdoor pathlimit (1-255>",
4268 "Specify a network to announce via BGP\n"
4269 "Network number\n"
4270 "Specify a BGP backdoor route\n"
4271 "AS-Path hopcount limit attribute\n"
4272 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4273ALIAS_DEPRECATED (no_bgp_network,
4274 no_bgp_network_ttl_cmd,
4275 "no network A.B.C.D/M pathlimit <0-255>",
4276 NO_STR
4277 "Specify a network to announce via BGP\n"
4278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4279 "AS-Path hopcount limit attribute\n"
4280 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4281ALIAS_DEPRECATED (no_bgp_network,
4282 no_bgp_network_backdoor_ttl_cmd,
4283 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4287 "Specify a BGP backdoor route\n"
4288 "AS-Path hopcount limit attribute\n"
4289 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4290ALIAS_DEPRECATED (no_bgp_network,
4291 no_bgp_network_mask_ttl_cmd,
4292 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4293 NO_STR
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Network mask\n"
4297 "Network mask\n"
4298 "AS-Path hopcount limit attribute\n"
4299 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4300ALIAS_DEPRECATED (no_bgp_network_mask,
4301 no_bgp_network_mask_backdoor_ttl_cmd,
4302 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4303 NO_STR
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Network mask\n"
4307 "Network mask\n"
4308 "Specify a BGP backdoor route\n"
4309 "AS-Path hopcount limit attribute\n"
4310 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4311ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4312 no_bgp_network_mask_natural_ttl_cmd,
4313 "no network A.B.C.D pathlimit <0-255>",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "AS-Path hopcount limit attribute\n"
4318 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4319ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4320 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4321 "no network A.B.C.D backdoor pathlimit <0-255>",
4322 NO_STR
4323 "Specify a network to announce via BGP\n"
4324 "Network number\n"
4325 "Specify a BGP backdoor route\n"
4326 "AS-Path hopcount limit attribute\n"
4327 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004328#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004329ALIAS_DEPRECATED (ipv6_bgp_network,
4330 ipv6_bgp_network_ttl_cmd,
4331 "network X:X::X:X/M pathlimit <0-255>",
4332 "Specify a network to announce via BGP\n"
4333 "IPv6 prefix <network>/<length>\n"
4334 "AS-Path hopcount limit attribute\n"
4335 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4336ALIAS_DEPRECATED (no_ipv6_bgp_network,
4337 no_ipv6_bgp_network_ttl_cmd,
4338 "no network X:X::X:X/M pathlimit <0-255>",
4339 NO_STR
4340 "Specify a network to announce via BGP\n"
4341 "IPv6 prefix <network>/<length>\n"
4342 "AS-Path hopcount limit attribute\n"
4343 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004344#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004345
4346/* Aggreagete address:
4347
4348 advertise-map Set condition to advertise attribute
4349 as-set Generate AS set path information
4350 attribute-map Set attributes of aggregate
4351 route-map Set parameters of aggregate
4352 summary-only Filter more specific routes from updates
4353 suppress-map Conditionally filter more specific routes from updates
4354 <cr>
4355 */
4356struct bgp_aggregate
4357{
4358 /* Summary-only flag. */
4359 u_char summary_only;
4360
4361 /* AS set generation. */
4362 u_char as_set;
4363
4364 /* Route-map for aggregated route. */
4365 struct route_map *map;
4366
4367 /* Suppress-count. */
4368 unsigned long count;
4369
4370 /* SAFI configuration. */
4371 safi_t safi;
4372};
4373
paul94f2b392005-06-28 12:44:16 +00004374static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004375bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004376{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004377 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004378}
4379
paul94f2b392005-06-28 12:44:16 +00004380static void
paul718e3742002-12-13 20:15:29 +00004381bgp_aggregate_free (struct bgp_aggregate *aggregate)
4382{
4383 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4384}
4385
paul94f2b392005-06-28 12:44:16 +00004386static void
paul718e3742002-12-13 20:15:29 +00004387bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4388 afi_t afi, safi_t safi, struct bgp_info *del,
4389 struct bgp_aggregate *aggregate)
4390{
4391 struct bgp_table *table;
4392 struct bgp_node *top;
4393 struct bgp_node *rn;
4394 u_char origin;
4395 struct aspath *aspath = NULL;
4396 struct aspath *asmerge = NULL;
4397 struct community *community = NULL;
4398 struct community *commerge = NULL;
4399 struct in_addr nexthop;
4400 u_int32_t med = 0;
4401 struct bgp_info *ri;
4402 struct bgp_info *new;
4403 int first = 1;
4404 unsigned long match = 0;
4405
4406 /* Record adding route's nexthop and med. */
4407 if (rinew)
4408 {
4409 nexthop = rinew->attr->nexthop;
4410 med = rinew->attr->med;
4411 }
4412
4413 /* ORIGIN attribute: If at least one route among routes that are
4414 aggregated has ORIGIN with the value INCOMPLETE, then the
4415 aggregated route must have the ORIGIN attribute with the value
4416 INCOMPLETE. Otherwise, if at least one route among routes that
4417 are aggregated has ORIGIN with the value EGP, then the aggregated
4418 route must have the origin attribute with the value EGP. In all
4419 other case the value of the ORIGIN attribute of the aggregated
4420 route is INTERNAL. */
4421 origin = BGP_ORIGIN_IGP;
4422
4423 table = bgp->rib[afi][safi];
4424
4425 top = bgp_node_get (table, p);
4426 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4427 if (rn->p.prefixlen > p->prefixlen)
4428 {
4429 match = 0;
4430
4431 for (ri = rn->info; ri; ri = ri->next)
4432 {
4433 if (BGP_INFO_HOLDDOWN (ri))
4434 continue;
4435
4436 if (del && ri == del)
4437 continue;
4438
4439 if (! rinew && first)
4440 {
4441 nexthop = ri->attr->nexthop;
4442 med = ri->attr->med;
4443 first = 0;
4444 }
4445
4446#ifdef AGGREGATE_NEXTHOP_CHECK
4447 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4448 || ri->attr->med != med)
4449 {
4450 if (aspath)
4451 aspath_free (aspath);
4452 if (community)
4453 community_free (community);
4454 bgp_unlock_node (rn);
4455 bgp_unlock_node (top);
4456 return;
4457 }
4458#endif /* AGGREGATE_NEXTHOP_CHECK */
4459
4460 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4461 {
4462 if (aggregate->summary_only)
4463 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004464 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004465 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004466 match++;
4467 }
4468
4469 aggregate->count++;
4470
4471 if (aggregate->as_set)
4472 {
4473 if (origin < ri->attr->origin)
4474 origin = ri->attr->origin;
4475
4476 if (aspath)
4477 {
4478 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4479 aspath_free (aspath);
4480 aspath = asmerge;
4481 }
4482 else
4483 aspath = aspath_dup (ri->attr->aspath);
4484
4485 if (ri->attr->community)
4486 {
4487 if (community)
4488 {
4489 commerge = community_merge (community,
4490 ri->attr->community);
4491 community = community_uniq_sort (commerge);
4492 community_free (commerge);
4493 }
4494 else
4495 community = community_dup (ri->attr->community);
4496 }
4497 }
4498 }
4499 }
4500 if (match)
4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 bgp_unlock_node (top);
4504
4505 if (rinew)
4506 {
4507 aggregate->count++;
4508
4509 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004510 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004511
4512 if (aggregate->as_set)
4513 {
4514 if (origin < rinew->attr->origin)
4515 origin = rinew->attr->origin;
4516
4517 if (aspath)
4518 {
4519 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4520 aspath_free (aspath);
4521 aspath = asmerge;
4522 }
4523 else
4524 aspath = aspath_dup (rinew->attr->aspath);
4525
4526 if (rinew->attr->community)
4527 {
4528 if (community)
4529 {
4530 commerge = community_merge (community,
4531 rinew->attr->community);
4532 community = community_uniq_sort (commerge);
4533 community_free (commerge);
4534 }
4535 else
4536 community = community_dup (rinew->attr->community);
4537 }
4538 }
4539 }
4540
4541 if (aggregate->count > 0)
4542 {
4543 rn = bgp_node_get (table, p);
4544 new = bgp_info_new ();
4545 new->type = ZEBRA_ROUTE_BGP;
4546 new->sub_type = BGP_ROUTE_AGGREGATE;
4547 new->peer = bgp->peer_self;
4548 SET_FLAG (new->flags, BGP_INFO_VALID);
4549 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004550 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004551
4552 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004553 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004554 bgp_process (bgp, rn, afi, safi);
4555 }
4556 else
4557 {
4558 if (aspath)
4559 aspath_free (aspath);
4560 if (community)
4561 community_free (community);
4562 }
4563}
4564
4565void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4566 struct bgp_aggregate *);
4567
4568void
4569bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4570 struct bgp_info *ri, afi_t afi, safi_t safi)
4571{
4572 struct bgp_node *child;
4573 struct bgp_node *rn;
4574 struct bgp_aggregate *aggregate;
4575
4576 /* MPLS-VPN aggregation is not yet supported. */
4577 if (safi == SAFI_MPLS_VPN)
4578 return;
4579
4580 if (p->prefixlen == 0)
4581 return;
4582
4583 if (BGP_INFO_HOLDDOWN (ri))
4584 return;
4585
4586 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4587
4588 /* Aggregate address configuration check. */
4589 for (rn = child; rn; rn = rn->parent)
4590 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4591 {
4592 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004593 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004594 }
4595 bgp_unlock_node (child);
4596}
4597
4598void
4599bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4600 struct bgp_info *del, afi_t afi, safi_t safi)
4601{
4602 struct bgp_node *child;
4603 struct bgp_node *rn;
4604 struct bgp_aggregate *aggregate;
4605
4606 /* MPLS-VPN aggregation is not yet supported. */
4607 if (safi == SAFI_MPLS_VPN)
4608 return;
4609
4610 if (p->prefixlen == 0)
4611 return;
4612
4613 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4614
4615 /* Aggregate address configuration check. */
4616 for (rn = child; rn; rn = rn->parent)
4617 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4618 {
4619 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004620 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004621 }
4622 bgp_unlock_node (child);
4623}
4624
paul94f2b392005-06-28 12:44:16 +00004625static void
paul718e3742002-12-13 20:15:29 +00004626bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4627 struct bgp_aggregate *aggregate)
4628{
4629 struct bgp_table *table;
4630 struct bgp_node *top;
4631 struct bgp_node *rn;
4632 struct bgp_info *new;
4633 struct bgp_info *ri;
4634 unsigned long match;
4635 u_char origin = BGP_ORIGIN_IGP;
4636 struct aspath *aspath = NULL;
4637 struct aspath *asmerge = NULL;
4638 struct community *community = NULL;
4639 struct community *commerge = NULL;
4640
4641 table = bgp->rib[afi][safi];
4642
4643 /* Sanity check. */
4644 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4645 return;
4646 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4647 return;
4648
4649 /* If routes exists below this node, generate aggregate routes. */
4650 top = bgp_node_get (table, p);
4651 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4652 if (rn->p.prefixlen > p->prefixlen)
4653 {
4654 match = 0;
4655
4656 for (ri = rn->info; ri; ri = ri->next)
4657 {
4658 if (BGP_INFO_HOLDDOWN (ri))
4659 continue;
4660
4661 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4662 {
4663 /* summary-only aggregate route suppress aggregated
4664 route announcement. */
4665 if (aggregate->summary_only)
4666 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004667 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004668 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004669 match++;
4670 }
4671 /* as-set aggregate route generate origin, as path,
4672 community aggregation. */
4673 if (aggregate->as_set)
4674 {
4675 if (origin < ri->attr->origin)
4676 origin = ri->attr->origin;
4677
4678 if (aspath)
4679 {
4680 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4681 aspath_free (aspath);
4682 aspath = asmerge;
4683 }
4684 else
4685 aspath = aspath_dup (ri->attr->aspath);
4686
4687 if (ri->attr->community)
4688 {
4689 if (community)
4690 {
4691 commerge = community_merge (community,
4692 ri->attr->community);
4693 community = community_uniq_sort (commerge);
4694 community_free (commerge);
4695 }
4696 else
4697 community = community_dup (ri->attr->community);
4698 }
4699 }
4700 aggregate->count++;
4701 }
4702 }
4703
4704 /* If this node is suppressed, process the change. */
4705 if (match)
4706 bgp_process (bgp, rn, afi, safi);
4707 }
4708 bgp_unlock_node (top);
4709
4710 /* Add aggregate route to BGP table. */
4711 if (aggregate->count)
4712 {
4713 rn = bgp_node_get (table, p);
4714
4715 new = bgp_info_new ();
4716 new->type = ZEBRA_ROUTE_BGP;
4717 new->sub_type = BGP_ROUTE_AGGREGATE;
4718 new->peer = bgp->peer_self;
4719 SET_FLAG (new->flags, BGP_INFO_VALID);
4720 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004721 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004722
4723 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004724 bgp_unlock_node (rn);
4725
paul718e3742002-12-13 20:15:29 +00004726 /* Process change. */
4727 bgp_process (bgp, rn, afi, safi);
4728 }
4729}
4730
4731void
4732bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4733 safi_t safi, struct bgp_aggregate *aggregate)
4734{
4735 struct bgp_table *table;
4736 struct bgp_node *top;
4737 struct bgp_node *rn;
4738 struct bgp_info *ri;
4739 unsigned long match;
4740
4741 table = bgp->rib[afi][safi];
4742
4743 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4744 return;
4745 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4746 return;
4747
4748 /* If routes exists below this node, generate aggregate routes. */
4749 top = bgp_node_get (table, p);
4750 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4751 if (rn->p.prefixlen > p->prefixlen)
4752 {
4753 match = 0;
4754
4755 for (ri = rn->info; ri; ri = ri->next)
4756 {
4757 if (BGP_INFO_HOLDDOWN (ri))
4758 continue;
4759
4760 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4761 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004762 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004763 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004764 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004765
Paul Jakmafb982c22007-05-04 20:15:47 +00004766 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004767 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004768 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004769 match++;
4770 }
4771 }
4772 aggregate->count--;
4773 }
4774 }
4775
Paul Jakmafb982c22007-05-04 20:15:47 +00004776 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004777 if (match)
4778 bgp_process (bgp, rn, afi, safi);
4779 }
4780 bgp_unlock_node (top);
4781
4782 /* Delete aggregate route from BGP table. */
4783 rn = bgp_node_get (table, p);
4784
4785 for (ri = rn->info; ri; ri = ri->next)
4786 if (ri->peer == bgp->peer_self
4787 && ri->type == ZEBRA_ROUTE_BGP
4788 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4789 break;
4790
4791 /* Withdraw static BGP route from routing table. */
4792 if (ri)
4793 {
paul718e3742002-12-13 20:15:29 +00004794 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004795 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004796 }
4797
4798 /* Unlock bgp_node_lookup. */
4799 bgp_unlock_node (rn);
4800}
4801
4802/* Aggregate route attribute. */
4803#define AGGREGATE_SUMMARY_ONLY 1
4804#define AGGREGATE_AS_SET 1
4805
paul94f2b392005-06-28 12:44:16 +00004806static int
Robert Baysf6269b42010-08-05 10:26:28 -07004807bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4808 afi_t afi, safi_t safi)
4809{
4810 int ret;
4811 struct prefix p;
4812 struct bgp_node *rn;
4813 struct bgp *bgp;
4814 struct bgp_aggregate *aggregate;
4815
4816 /* Convert string to prefix structure. */
4817 ret = str2prefix (prefix_str, &p);
4818 if (!ret)
4819 {
4820 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4821 return CMD_WARNING;
4822 }
4823 apply_mask (&p);
4824
4825 /* Get BGP structure. */
4826 bgp = vty->index;
4827
4828 /* Old configuration check. */
4829 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4830 if (! rn)
4831 {
4832 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4833 VTY_NEWLINE);
4834 return CMD_WARNING;
4835 }
4836
4837 aggregate = rn->info;
4838 if (aggregate->safi & SAFI_UNICAST)
4839 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4840 if (aggregate->safi & SAFI_MULTICAST)
4841 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4842
4843 /* Unlock aggregate address configuration. */
4844 rn->info = NULL;
4845 bgp_aggregate_free (aggregate);
4846 bgp_unlock_node (rn);
4847 bgp_unlock_node (rn);
4848
4849 return CMD_SUCCESS;
4850}
4851
4852static int
4853bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004854 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004855 u_char summary_only, u_char as_set)
4856{
4857 int ret;
4858 struct prefix p;
4859 struct bgp_node *rn;
4860 struct bgp *bgp;
4861 struct bgp_aggregate *aggregate;
4862
4863 /* Convert string to prefix structure. */
4864 ret = str2prefix (prefix_str, &p);
4865 if (!ret)
4866 {
4867 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4868 return CMD_WARNING;
4869 }
4870 apply_mask (&p);
4871
4872 /* Get BGP structure. */
4873 bgp = vty->index;
4874
4875 /* Old configuration check. */
4876 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4877
4878 if (rn->info)
4879 {
4880 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004881 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004882 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4883 if (ret)
4884 {
Robert Bays368473f2010-08-05 10:26:29 -07004885 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4886 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004887 return CMD_WARNING;
4888 }
paul718e3742002-12-13 20:15:29 +00004889 }
4890
4891 /* Make aggregate address structure. */
4892 aggregate = bgp_aggregate_new ();
4893 aggregate->summary_only = summary_only;
4894 aggregate->as_set = as_set;
4895 aggregate->safi = safi;
4896 rn->info = aggregate;
4897
4898 /* Aggregate address insert into BGP routing table. */
4899 if (safi & SAFI_UNICAST)
4900 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4901 if (safi & SAFI_MULTICAST)
4902 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4903
4904 return CMD_SUCCESS;
4905}
4906
paul718e3742002-12-13 20:15:29 +00004907DEFUN (aggregate_address,
4908 aggregate_address_cmd,
4909 "aggregate-address A.B.C.D/M",
4910 "Configure BGP aggregate entries\n"
4911 "Aggregate prefix\n")
4912{
4913 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4914}
4915
4916DEFUN (aggregate_address_mask,
4917 aggregate_address_mask_cmd,
4918 "aggregate-address A.B.C.D A.B.C.D",
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate address\n"
4921 "Aggregate mask\n")
4922{
4923 int ret;
4924 char prefix_str[BUFSIZ];
4925
4926 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4927
4928 if (! ret)
4929 {
4930 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4931 return CMD_WARNING;
4932 }
4933
4934 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4935 0, 0);
4936}
4937
4938DEFUN (aggregate_address_summary_only,
4939 aggregate_address_summary_only_cmd,
4940 "aggregate-address A.B.C.D/M summary-only",
4941 "Configure BGP aggregate entries\n"
4942 "Aggregate prefix\n"
4943 "Filter more specific routes from updates\n")
4944{
4945 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4946 AGGREGATE_SUMMARY_ONLY, 0);
4947}
4948
4949DEFUN (aggregate_address_mask_summary_only,
4950 aggregate_address_mask_summary_only_cmd,
4951 "aggregate-address A.B.C.D A.B.C.D summary-only",
4952 "Configure BGP aggregate entries\n"
4953 "Aggregate address\n"
4954 "Aggregate mask\n"
4955 "Filter more specific routes from updates\n")
4956{
4957 int ret;
4958 char prefix_str[BUFSIZ];
4959
4960 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4961
4962 if (! ret)
4963 {
4964 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967
4968 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4969 AGGREGATE_SUMMARY_ONLY, 0);
4970}
4971
4972DEFUN (aggregate_address_as_set,
4973 aggregate_address_as_set_cmd,
4974 "aggregate-address A.B.C.D/M as-set",
4975 "Configure BGP aggregate entries\n"
4976 "Aggregate prefix\n"
4977 "Generate AS set path information\n")
4978{
4979 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4980 0, AGGREGATE_AS_SET);
4981}
4982
4983DEFUN (aggregate_address_mask_as_set,
4984 aggregate_address_mask_as_set_cmd,
4985 "aggregate-address A.B.C.D A.B.C.D as-set",
4986 "Configure BGP aggregate entries\n"
4987 "Aggregate address\n"
4988 "Aggregate mask\n"
4989 "Generate AS set path information\n")
4990{
4991 int ret;
4992 char prefix_str[BUFSIZ];
4993
4994 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4995
4996 if (! ret)
4997 {
4998 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001
5002 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5003 0, AGGREGATE_AS_SET);
5004}
5005
5006
5007DEFUN (aggregate_address_as_set_summary,
5008 aggregate_address_as_set_summary_cmd,
5009 "aggregate-address A.B.C.D/M as-set summary-only",
5010 "Configure BGP aggregate entries\n"
5011 "Aggregate prefix\n"
5012 "Generate AS set path information\n"
5013 "Filter more specific routes from updates\n")
5014{
5015 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5016 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5017}
5018
5019ALIAS (aggregate_address_as_set_summary,
5020 aggregate_address_summary_as_set_cmd,
5021 "aggregate-address A.B.C.D/M summary-only as-set",
5022 "Configure BGP aggregate entries\n"
5023 "Aggregate prefix\n"
5024 "Filter more specific routes from updates\n"
5025 "Generate AS set path information\n")
5026
5027DEFUN (aggregate_address_mask_as_set_summary,
5028 aggregate_address_mask_as_set_summary_cmd,
5029 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5030 "Configure BGP aggregate entries\n"
5031 "Aggregate address\n"
5032 "Aggregate mask\n"
5033 "Generate AS set path information\n"
5034 "Filter more specific routes from updates\n")
5035{
5036 int ret;
5037 char prefix_str[BUFSIZ];
5038
5039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5040
5041 if (! ret)
5042 {
5043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5044 return CMD_WARNING;
5045 }
5046
5047 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5048 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5049}
5050
5051ALIAS (aggregate_address_mask_as_set_summary,
5052 aggregate_address_mask_summary_as_set_cmd,
5053 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5054 "Configure BGP aggregate entries\n"
5055 "Aggregate address\n"
5056 "Aggregate mask\n"
5057 "Filter more specific routes from updates\n"
5058 "Generate AS set path information\n")
5059
5060DEFUN (no_aggregate_address,
5061 no_aggregate_address_cmd,
5062 "no aggregate-address A.B.C.D/M",
5063 NO_STR
5064 "Configure BGP aggregate entries\n"
5065 "Aggregate prefix\n")
5066{
5067 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5068}
5069
5070ALIAS (no_aggregate_address,
5071 no_aggregate_address_summary_only_cmd,
5072 "no aggregate-address A.B.C.D/M summary-only",
5073 NO_STR
5074 "Configure BGP aggregate entries\n"
5075 "Aggregate prefix\n"
5076 "Filter more specific routes from updates\n")
5077
5078ALIAS (no_aggregate_address,
5079 no_aggregate_address_as_set_cmd,
5080 "no aggregate-address A.B.C.D/M as-set",
5081 NO_STR
5082 "Configure BGP aggregate entries\n"
5083 "Aggregate prefix\n"
5084 "Generate AS set path information\n")
5085
5086ALIAS (no_aggregate_address,
5087 no_aggregate_address_as_set_summary_cmd,
5088 "no aggregate-address A.B.C.D/M as-set summary-only",
5089 NO_STR
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate prefix\n"
5092 "Generate AS set path information\n"
5093 "Filter more specific routes from updates\n")
5094
5095ALIAS (no_aggregate_address,
5096 no_aggregate_address_summary_as_set_cmd,
5097 "no aggregate-address A.B.C.D/M summary-only as-set",
5098 NO_STR
5099 "Configure BGP aggregate entries\n"
5100 "Aggregate prefix\n"
5101 "Filter more specific routes from updates\n"
5102 "Generate AS set path information\n")
5103
5104DEFUN (no_aggregate_address_mask,
5105 no_aggregate_address_mask_cmd,
5106 "no aggregate-address A.B.C.D A.B.C.D",
5107 NO_STR
5108 "Configure BGP aggregate entries\n"
5109 "Aggregate address\n"
5110 "Aggregate mask\n")
5111{
5112 int ret;
5113 char prefix_str[BUFSIZ];
5114
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5116
5117 if (! ret)
5118 {
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122
5123 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5124}
5125
5126ALIAS (no_aggregate_address_mask,
5127 no_aggregate_address_mask_summary_only_cmd,
5128 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5129 NO_STR
5130 "Configure BGP aggregate entries\n"
5131 "Aggregate address\n"
5132 "Aggregate mask\n"
5133 "Filter more specific routes from updates\n")
5134
5135ALIAS (no_aggregate_address_mask,
5136 no_aggregate_address_mask_as_set_cmd,
5137 "no aggregate-address A.B.C.D A.B.C.D as-set",
5138 NO_STR
5139 "Configure BGP aggregate entries\n"
5140 "Aggregate address\n"
5141 "Aggregate mask\n"
5142 "Generate AS set path information\n")
5143
5144ALIAS (no_aggregate_address_mask,
5145 no_aggregate_address_mask_as_set_summary_cmd,
5146 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5147 NO_STR
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate address\n"
5150 "Aggregate mask\n"
5151 "Generate AS set path information\n"
5152 "Filter more specific routes from updates\n")
5153
5154ALIAS (no_aggregate_address_mask,
5155 no_aggregate_address_mask_summary_as_set_cmd,
5156 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5157 NO_STR
5158 "Configure BGP aggregate entries\n"
5159 "Aggregate address\n"
5160 "Aggregate mask\n"
5161 "Filter more specific routes from updates\n"
5162 "Generate AS set path information\n")
5163
5164#ifdef HAVE_IPV6
5165DEFUN (ipv6_aggregate_address,
5166 ipv6_aggregate_address_cmd,
5167 "aggregate-address X:X::X:X/M",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate prefix\n")
5170{
5171 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5172}
5173
5174DEFUN (ipv6_aggregate_address_summary_only,
5175 ipv6_aggregate_address_summary_only_cmd,
5176 "aggregate-address X:X::X:X/M summary-only",
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180{
5181 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5182 AGGREGATE_SUMMARY_ONLY, 0);
5183}
5184
5185DEFUN (no_ipv6_aggregate_address,
5186 no_ipv6_aggregate_address_cmd,
5187 "no aggregate-address X:X::X:X/M",
5188 NO_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191{
5192 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5193}
5194
5195DEFUN (no_ipv6_aggregate_address_summary_only,
5196 no_ipv6_aggregate_address_summary_only_cmd,
5197 "no aggregate-address X:X::X:X/M summary-only",
5198 NO_STR
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate prefix\n"
5201 "Filter more specific routes from updates\n")
5202{
5203 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5204}
5205
5206ALIAS (ipv6_aggregate_address,
5207 old_ipv6_aggregate_address_cmd,
5208 "ipv6 bgp aggregate-address X:X::X:X/M",
5209 IPV6_STR
5210 BGP_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate prefix\n")
5213
5214ALIAS (ipv6_aggregate_address_summary_only,
5215 old_ipv6_aggregate_address_summary_only_cmd,
5216 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5217 IPV6_STR
5218 BGP_STR
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate prefix\n"
5221 "Filter more specific routes from updates\n")
5222
5223ALIAS (no_ipv6_aggregate_address,
5224 old_no_ipv6_aggregate_address_cmd,
5225 "no ipv6 bgp aggregate-address X:X::X:X/M",
5226 NO_STR
5227 IPV6_STR
5228 BGP_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n")
5231
5232ALIAS (no_ipv6_aggregate_address_summary_only,
5233 old_no_ipv6_aggregate_address_summary_only_cmd,
5234 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5235 NO_STR
5236 IPV6_STR
5237 BGP_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n"
5240 "Filter more specific routes from updates\n")
5241#endif /* HAVE_IPV6 */
5242
5243/* Redistribute route treatment. */
5244void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005245bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5246 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005247 u_int32_t metric, u_char type)
5248{
5249 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005250 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005251 struct bgp_info *new;
5252 struct bgp_info *bi;
5253 struct bgp_info info;
5254 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005255 struct attr attr = { 0 };
5256 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005257 struct attr *new_attr;
5258 afi_t afi;
5259 int ret;
5260
5261 /* Make default attribute. */
5262 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5263 if (nexthop)
5264 attr.nexthop = *nexthop;
5265
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005266#ifdef HAVE_IPV6
5267 if (nexthop6)
5268 {
5269 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5270 extra->mp_nexthop_global = *nexthop6;
5271 extra->mp_nexthop_len = 16;
5272 }
5273#endif
5274
paul718e3742002-12-13 20:15:29 +00005275 attr.med = metric;
5276 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5277
paul1eb8ef22005-04-07 07:30:20 +00005278 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005279 {
5280 afi = family2afi (p->family);
5281
5282 if (bgp->redist[afi][type])
5283 {
5284 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005285 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005286
5287 if (bgp->redist_metric_flag[afi][type])
5288 attr_new.med = bgp->redist_metric[afi][type];
5289
5290 /* Apply route-map. */
5291 if (bgp->rmap[afi][type].map)
5292 {
5293 info.peer = bgp->peer_self;
5294 info.attr = &attr_new;
5295
paulfee0f4c2004-09-13 05:12:46 +00005296 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5297
paul718e3742002-12-13 20:15:29 +00005298 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5299 &info);
paulfee0f4c2004-09-13 05:12:46 +00005300
5301 bgp->peer_self->rmap_type = 0;
5302
paul718e3742002-12-13 20:15:29 +00005303 if (ret == RMAP_DENYMATCH)
5304 {
5305 /* Free uninterned attribute. */
5306 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005307 bgp_attr_extra_free (&attr_new);
5308
paul718e3742002-12-13 20:15:29 +00005309 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005310 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005311 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005312 bgp_redistribute_delete (p, type);
5313 return;
5314 }
5315 }
5316
Paul Jakmafb982c22007-05-04 20:15:47 +00005317 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5318 afi, SAFI_UNICAST, p, NULL);
5319
paul718e3742002-12-13 20:15:29 +00005320 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005321 bgp_attr_extra_free (&attr_new);
5322
paul718e3742002-12-13 20:15:29 +00005323 for (bi = bn->info; bi; bi = bi->next)
5324 if (bi->peer == bgp->peer_self
5325 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5326 break;
5327
5328 if (bi)
5329 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005330 if (attrhash_cmp (bi->attr, new_attr) &&
5331 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005332 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005333 bgp_attr_unintern (&new_attr);
5334 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005335 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005336 bgp_unlock_node (bn);
5337 return;
5338 }
5339 else
5340 {
5341 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005342 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005343
5344 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005345 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5346 bgp_info_restore(bn, bi);
5347 else
5348 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005349 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005350 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005351 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005352
5353 /* Process change. */
5354 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5355 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5356 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005357 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005358 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005359 return;
5360 }
5361 }
5362
5363 new = bgp_info_new ();
5364 new->type = type;
5365 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5366 new->peer = bgp->peer_self;
5367 SET_FLAG (new->flags, BGP_INFO_VALID);
5368 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005369 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005370
5371 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5372 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005373 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005374 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5375 }
5376 }
5377
5378 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005379 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005380 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005381}
5382
5383void
5384bgp_redistribute_delete (struct prefix *p, u_char type)
5385{
5386 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005387 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005388 afi_t afi;
5389 struct bgp_node *rn;
5390 struct bgp_info *ri;
5391
paul1eb8ef22005-04-07 07:30:20 +00005392 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005393 {
5394 afi = family2afi (p->family);
5395
5396 if (bgp->redist[afi][type])
5397 {
paulfee0f4c2004-09-13 05:12:46 +00005398 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005399
5400 for (ri = rn->info; ri; ri = ri->next)
5401 if (ri->peer == bgp->peer_self
5402 && ri->type == type)
5403 break;
5404
5405 if (ri)
5406 {
5407 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005408 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005409 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005410 }
5411 bgp_unlock_node (rn);
5412 }
5413 }
5414}
5415
5416/* Withdraw specified route type's route. */
5417void
5418bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5419{
5420 struct bgp_node *rn;
5421 struct bgp_info *ri;
5422 struct bgp_table *table;
5423
5424 table = bgp->rib[afi][SAFI_UNICAST];
5425
5426 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5427 {
5428 for (ri = rn->info; ri; ri = ri->next)
5429 if (ri->peer == bgp->peer_self
5430 && ri->type == type)
5431 break;
5432
5433 if (ri)
5434 {
5435 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005436 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005437 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005438 }
5439 }
5440}
5441
5442/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005443static void
paul718e3742002-12-13 20:15:29 +00005444route_vty_out_route (struct prefix *p, struct vty *vty)
5445{
5446 int len;
5447 u_int32_t destination;
5448 char buf[BUFSIZ];
5449
5450 if (p->family == AF_INET)
5451 {
5452 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5453 destination = ntohl (p->u.prefix4.s_addr);
5454
5455 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5456 || (IN_CLASSB (destination) && p->prefixlen == 16)
5457 || (IN_CLASSA (destination) && p->prefixlen == 8)
5458 || p->u.prefix4.s_addr == 0)
5459 {
5460 /* When mask is natural, mask is not displayed. */
5461 }
5462 else
5463 len += vty_out (vty, "/%d", p->prefixlen);
5464 }
5465 else
5466 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5467 p->prefixlen);
5468
5469 len = 17 - len;
5470 if (len < 1)
5471 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5472 else
5473 vty_out (vty, "%*s", len, " ");
5474}
5475
paul718e3742002-12-13 20:15:29 +00005476enum bgp_display_type
5477{
5478 normal_list,
5479};
5480
paulb40d9392005-08-22 22:34:41 +00005481/* Print the short form route status for a bgp_info */
5482static void
5483route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005484{
paulb40d9392005-08-22 22:34:41 +00005485 /* Route status display. */
5486 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5487 vty_out (vty, "R");
5488 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005489 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005490 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005491 vty_out (vty, "s");
5492 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5493 vty_out (vty, "*");
5494 else
5495 vty_out (vty, " ");
5496
5497 /* Selected */
5498 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5499 vty_out (vty, "h");
5500 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5501 vty_out (vty, "d");
5502 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5503 vty_out (vty, ">");
5504 else
5505 vty_out (vty, " ");
5506
5507 /* Internal route. */
5508 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5509 vty_out (vty, "i");
5510 else
paulb40d9392005-08-22 22:34:41 +00005511 vty_out (vty, " ");
5512}
5513
5514/* called from terminal list command */
5515void
5516route_vty_out (struct vty *vty, struct prefix *p,
5517 struct bgp_info *binfo, int display, safi_t safi)
5518{
5519 struct attr *attr;
5520
5521 /* short status lead text */
5522 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005523
5524 /* print prefix and mask */
5525 if (! display)
5526 route_vty_out_route (p, vty);
5527 else
5528 vty_out (vty, "%*s", 17, " ");
5529
5530 /* Print attribute */
5531 attr = binfo->attr;
5532 if (attr)
5533 {
5534 if (p->family == AF_INET)
5535 {
5536 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005537 vty_out (vty, "%-16s",
5538 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005539 else
5540 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5541 }
5542#ifdef HAVE_IPV6
5543 else if (p->family == AF_INET6)
5544 {
5545 int len;
5546 char buf[BUFSIZ];
5547
5548 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005549 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5550 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005551 len = 16 - len;
5552 if (len < 1)
5553 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5554 else
5555 vty_out (vty, "%*s", len, " ");
5556 }
5557#endif /* HAVE_IPV6 */
5558
5559 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005560 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005561 else
5562 vty_out (vty, " ");
5563
5564 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005565 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005566 else
5567 vty_out (vty, " ");
5568
Paul Jakmafb982c22007-05-04 20:15:47 +00005569 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005570
Paul Jakmab2518c12006-05-12 23:48:40 +00005571 /* Print aspath */
5572 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005573 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005574
Paul Jakmab2518c12006-05-12 23:48:40 +00005575 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005576 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005577 }
paul718e3742002-12-13 20:15:29 +00005578 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005579}
5580
5581/* called from terminal list command */
5582void
5583route_vty_out_tmp (struct vty *vty, struct prefix *p,
5584 struct attr *attr, safi_t safi)
5585{
5586 /* Route status display. */
5587 vty_out (vty, "*");
5588 vty_out (vty, ">");
5589 vty_out (vty, " ");
5590
5591 /* print prefix and mask */
5592 route_vty_out_route (p, vty);
5593
5594 /* Print attribute */
5595 if (attr)
5596 {
5597 if (p->family == AF_INET)
5598 {
5599 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005600 vty_out (vty, "%-16s",
5601 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005602 else
5603 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5604 }
5605#ifdef HAVE_IPV6
5606 else if (p->family == AF_INET6)
5607 {
5608 int len;
5609 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005610
5611 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005612
5613 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005614 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5615 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005616 len = 16 - len;
5617 if (len < 1)
5618 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5619 else
5620 vty_out (vty, "%*s", len, " ");
5621 }
5622#endif /* HAVE_IPV6 */
5623
5624 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005625 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005626 else
5627 vty_out (vty, " ");
5628
5629 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005630 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005631 else
5632 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005633
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005634 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005635
Paul Jakmab2518c12006-05-12 23:48:40 +00005636 /* Print aspath */
5637 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005638 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005639
Paul Jakmab2518c12006-05-12 23:48:40 +00005640 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005641 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005642 }
paul718e3742002-12-13 20:15:29 +00005643
5644 vty_out (vty, "%s", VTY_NEWLINE);
5645}
5646
ajs5a646652004-11-05 01:25:55 +00005647void
paul718e3742002-12-13 20:15:29 +00005648route_vty_out_tag (struct vty *vty, struct prefix *p,
5649 struct bgp_info *binfo, int display, safi_t safi)
5650{
5651 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005652 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005653
5654 if (!binfo->extra)
5655 return;
5656
paulb40d9392005-08-22 22:34:41 +00005657 /* short status lead text */
5658 route_vty_short_status_out (vty, binfo);
5659
paul718e3742002-12-13 20:15:29 +00005660 /* print prefix and mask */
5661 if (! display)
5662 route_vty_out_route (p, vty);
5663 else
5664 vty_out (vty, "%*s", 17, " ");
5665
5666 /* Print attribute */
5667 attr = binfo->attr;
5668 if (attr)
5669 {
5670 if (p->family == AF_INET)
5671 {
5672 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005673 vty_out (vty, "%-16s",
5674 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005675 else
5676 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5677 }
5678#ifdef HAVE_IPV6
5679 else if (p->family == AF_INET6)
5680 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005681 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005682 char buf[BUFSIZ];
5683 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005684 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005685 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005686 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5687 buf, BUFSIZ));
5688 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005689 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005690 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5691 buf, BUFSIZ),
5692 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5693 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005694
5695 }
5696#endif /* HAVE_IPV6 */
5697 }
5698
Paul Jakmafb982c22007-05-04 20:15:47 +00005699 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005700
5701 vty_out (vty, "notag/%d", label);
5702
5703 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005704}
5705
5706/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005707static void
paul718e3742002-12-13 20:15:29 +00005708damp_route_vty_out (struct vty *vty, struct prefix *p,
5709 struct bgp_info *binfo, int display, safi_t safi)
5710{
5711 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005712 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005713 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005714
paulb40d9392005-08-22 22:34:41 +00005715 /* short status lead text */
5716 route_vty_short_status_out (vty, binfo);
5717
paul718e3742002-12-13 20:15:29 +00005718 /* print prefix and mask */
5719 if (! display)
5720 route_vty_out_route (p, vty);
5721 else
5722 vty_out (vty, "%*s", 17, " ");
5723
5724 len = vty_out (vty, "%s", binfo->peer->host);
5725 len = 17 - len;
5726 if (len < 1)
5727 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5728 else
5729 vty_out (vty, "%*s", len, " ");
5730
Chris Caputo50aef6f2009-06-23 06:06:49 +00005731 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005732
5733 /* Print attribute */
5734 attr = binfo->attr;
5735 if (attr)
5736 {
5737 /* Print aspath */
5738 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005739 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005740
5741 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005743 }
5744 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005745}
5746
paul718e3742002-12-13 20:15:29 +00005747/* flap route */
ajs5a646652004-11-05 01:25:55 +00005748static void
paul718e3742002-12-13 20:15:29 +00005749flap_route_vty_out (struct vty *vty, struct prefix *p,
5750 struct bgp_info *binfo, int display, safi_t safi)
5751{
5752 struct attr *attr;
5753 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005754 char timebuf[BGP_UPTIME_LEN];
5755 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005756
5757 if (!binfo->extra)
5758 return;
5759
5760 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005761
paulb40d9392005-08-22 22:34:41 +00005762 /* short status lead text */
5763 route_vty_short_status_out (vty, binfo);
5764
paul718e3742002-12-13 20:15:29 +00005765 /* print prefix and mask */
5766 if (! display)
5767 route_vty_out_route (p, vty);
5768 else
5769 vty_out (vty, "%*s", 17, " ");
5770
5771 len = vty_out (vty, "%s", binfo->peer->host);
5772 len = 16 - len;
5773 if (len < 1)
5774 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5775 else
5776 vty_out (vty, "%*s", len, " ");
5777
5778 len = vty_out (vty, "%d", bdi->flap);
5779 len = 5 - len;
5780 if (len < 1)
5781 vty_out (vty, " ");
5782 else
5783 vty_out (vty, "%*s ", len, " ");
5784
5785 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5786 timebuf, BGP_UPTIME_LEN));
5787
5788 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5789 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005790 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005791 else
5792 vty_out (vty, "%*s ", 8, " ");
5793
5794 /* Print attribute */
5795 attr = binfo->attr;
5796 if (attr)
5797 {
5798 /* Print aspath */
5799 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005800 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005801
5802 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005803 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005804 }
5805 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005806}
5807
paul94f2b392005-06-28 12:44:16 +00005808static void
paul718e3742002-12-13 20:15:29 +00005809route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5810 struct bgp_info *binfo, afi_t afi, safi_t safi)
5811{
5812 char buf[INET6_ADDRSTRLEN];
5813 char buf1[BUFSIZ];
5814 struct attr *attr;
5815 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005816#ifdef HAVE_CLOCK_MONOTONIC
5817 time_t tbuf;
5818#endif
paul718e3742002-12-13 20:15:29 +00005819
5820 attr = binfo->attr;
5821
5822 if (attr)
5823 {
5824 /* Line1 display AS-path, Aggregator */
5825 if (attr->aspath)
5826 {
5827 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005828 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005829 vty_out (vty, "Local");
5830 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005831 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005832 }
5833
paulb40d9392005-08-22 22:34:41 +00005834 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5835 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005836 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5837 vty_out (vty, ", (stale)");
5838 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005839 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005840 attr->extra->aggregator_as,
5841 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005842 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5843 vty_out (vty, ", (Received from a RR-client)");
5844 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5845 vty_out (vty, ", (Received from a RS-client)");
5846 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5847 vty_out (vty, ", (history entry)");
5848 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5849 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005850 vty_out (vty, "%s", VTY_NEWLINE);
5851
5852 /* Line2 display Next-hop, Neighbor, Router-id */
5853 if (p->family == AF_INET)
5854 {
5855 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005856 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005857 inet_ntoa (attr->nexthop));
5858 }
5859#ifdef HAVE_IPV6
5860 else
5861 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005862 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005863 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005864 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005865 buf, INET6_ADDRSTRLEN));
5866 }
5867#endif /* HAVE_IPV6 */
5868
5869 if (binfo->peer == bgp->peer_self)
5870 {
5871 vty_out (vty, " from %s ",
5872 p->family == AF_INET ? "0.0.0.0" : "::");
5873 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5874 }
5875 else
5876 {
5877 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5878 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005879 else if (binfo->extra && binfo->extra->igpmetric)
5880 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005881 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005882 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005883 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005884 else
5885 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5886 }
5887 vty_out (vty, "%s", VTY_NEWLINE);
5888
5889#ifdef HAVE_IPV6
5890 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005891 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005892 {
5893 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005894 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005895 buf, INET6_ADDRSTRLEN),
5896 VTY_NEWLINE);
5897 }
5898#endif /* HAVE_IPV6 */
5899
5900 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5901 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5902
5903 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005904 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005905
5906 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005907 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005908 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005909 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005910
Paul Jakmafb982c22007-05-04 20:15:47 +00005911 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005912 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005913
5914 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5915 vty_out (vty, ", valid");
5916
5917 if (binfo->peer != bgp->peer_self)
5918 {
5919 if (binfo->peer->as == binfo->peer->local_as)
5920 vty_out (vty, ", internal");
5921 else
5922 vty_out (vty, ", %s",
5923 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5924 }
5925 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5926 vty_out (vty, ", aggregated, local");
5927 else if (binfo->type != ZEBRA_ROUTE_BGP)
5928 vty_out (vty, ", sourced");
5929 else
5930 vty_out (vty, ", sourced, local");
5931
5932 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5933 vty_out (vty, ", atomic-aggregate");
5934
5935 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5936 vty_out (vty, ", best");
5937
5938 vty_out (vty, "%s", VTY_NEWLINE);
5939
5940 /* Line 4 display Community */
5941 if (attr->community)
5942 vty_out (vty, " Community: %s%s", attr->community->str,
5943 VTY_NEWLINE);
5944
5945 /* Line 5 display Extended-community */
5946 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005947 vty_out (vty, " Extended Community: %s%s",
5948 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005949
5950 /* Line 6 display Originator, Cluster-id */
5951 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5952 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5953 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005954 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005955 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005956 vty_out (vty, " Originator: %s",
5957 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005958
5959 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5960 {
5961 int i;
5962 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005963 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5964 vty_out (vty, "%s ",
5965 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00005966 }
5967 vty_out (vty, "%s", VTY_NEWLINE);
5968 }
Paul Jakma41367172007-08-06 15:24:51 +00005969
Paul Jakmafb982c22007-05-04 20:15:47 +00005970 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00005971 bgp_damp_info_vty (vty, binfo);
5972
5973 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03005974#ifdef HAVE_CLOCK_MONOTONIC
5975 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04005976 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03005977#else
5978 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5979#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00005980 }
5981 vty_out (vty, "%s", VTY_NEWLINE);
5982}
5983
paulb40d9392005-08-22 22:34:41 +00005984#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 +00005985#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005986#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5987#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5988#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5989
5990enum bgp_show_type
5991{
5992 bgp_show_type_normal,
5993 bgp_show_type_regexp,
5994 bgp_show_type_prefix_list,
5995 bgp_show_type_filter_list,
5996 bgp_show_type_route_map,
5997 bgp_show_type_neighbor,
5998 bgp_show_type_cidr_only,
5999 bgp_show_type_prefix_longer,
6000 bgp_show_type_community_all,
6001 bgp_show_type_community,
6002 bgp_show_type_community_exact,
6003 bgp_show_type_community_list,
6004 bgp_show_type_community_list_exact,
6005 bgp_show_type_flap_statistics,
6006 bgp_show_type_flap_address,
6007 bgp_show_type_flap_prefix,
6008 bgp_show_type_flap_cidr_only,
6009 bgp_show_type_flap_regexp,
6010 bgp_show_type_flap_filter_list,
6011 bgp_show_type_flap_prefix_list,
6012 bgp_show_type_flap_prefix_longer,
6013 bgp_show_type_flap_route_map,
6014 bgp_show_type_flap_neighbor,
6015 bgp_show_type_dampend_paths,
6016 bgp_show_type_damp_neighbor
6017};
6018
ajs5a646652004-11-05 01:25:55 +00006019static int
paulfee0f4c2004-09-13 05:12:46 +00006020bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006021 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006022{
paul718e3742002-12-13 20:15:29 +00006023 struct bgp_info *ri;
6024 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006025 int header = 1;
paul718e3742002-12-13 20:15:29 +00006026 int display;
ajs5a646652004-11-05 01:25:55 +00006027 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006028
6029 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006030 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006031
paul718e3742002-12-13 20:15:29 +00006032 /* Start processing of routes. */
6033 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6034 if (rn->info != NULL)
6035 {
6036 display = 0;
6037
6038 for (ri = rn->info; ri; ri = ri->next)
6039 {
ajs5a646652004-11-05 01:25:55 +00006040 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006041 || type == bgp_show_type_flap_address
6042 || type == bgp_show_type_flap_prefix
6043 || type == bgp_show_type_flap_cidr_only
6044 || type == bgp_show_type_flap_regexp
6045 || type == bgp_show_type_flap_filter_list
6046 || type == bgp_show_type_flap_prefix_list
6047 || type == bgp_show_type_flap_prefix_longer
6048 || type == bgp_show_type_flap_route_map
6049 || type == bgp_show_type_flap_neighbor
6050 || type == bgp_show_type_dampend_paths
6051 || type == bgp_show_type_damp_neighbor)
6052 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006053 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006054 continue;
6055 }
6056 if (type == bgp_show_type_regexp
6057 || type == bgp_show_type_flap_regexp)
6058 {
ajs5a646652004-11-05 01:25:55 +00006059 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006060
6061 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6062 continue;
6063 }
6064 if (type == bgp_show_type_prefix_list
6065 || type == bgp_show_type_flap_prefix_list)
6066 {
ajs5a646652004-11-05 01:25:55 +00006067 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006068
6069 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6070 continue;
6071 }
6072 if (type == bgp_show_type_filter_list
6073 || type == bgp_show_type_flap_filter_list)
6074 {
ajs5a646652004-11-05 01:25:55 +00006075 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006076
6077 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6078 continue;
6079 }
6080 if (type == bgp_show_type_route_map
6081 || type == bgp_show_type_flap_route_map)
6082 {
ajs5a646652004-11-05 01:25:55 +00006083 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006084 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006085 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006086 int ret;
6087
Paul Jakmafb982c22007-05-04 20:15:47 +00006088 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006089 binfo.peer = ri->peer;
6090 binfo.attr = &dummy_attr;
6091
6092 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006093
6094 bgp_attr_extra_free (&dummy_attr);
6095
paul718e3742002-12-13 20:15:29 +00006096 if (ret == RMAP_DENYMATCH)
6097 continue;
6098 }
6099 if (type == bgp_show_type_neighbor
6100 || type == bgp_show_type_flap_neighbor
6101 || type == bgp_show_type_damp_neighbor)
6102 {
ajs5a646652004-11-05 01:25:55 +00006103 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006104
6105 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6106 continue;
6107 }
6108 if (type == bgp_show_type_cidr_only
6109 || type == bgp_show_type_flap_cidr_only)
6110 {
6111 u_int32_t destination;
6112
6113 destination = ntohl (rn->p.u.prefix4.s_addr);
6114 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6115 continue;
6116 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6117 continue;
6118 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6119 continue;
6120 }
6121 if (type == bgp_show_type_prefix_longer
6122 || type == bgp_show_type_flap_prefix_longer)
6123 {
ajs5a646652004-11-05 01:25:55 +00006124 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006125
6126 if (! prefix_match (p, &rn->p))
6127 continue;
6128 }
6129 if (type == bgp_show_type_community_all)
6130 {
6131 if (! ri->attr->community)
6132 continue;
6133 }
6134 if (type == bgp_show_type_community)
6135 {
ajs5a646652004-11-05 01:25:55 +00006136 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006137
6138 if (! ri->attr->community ||
6139 ! community_match (ri->attr->community, com))
6140 continue;
6141 }
6142 if (type == bgp_show_type_community_exact)
6143 {
ajs5a646652004-11-05 01:25:55 +00006144 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006145
6146 if (! ri->attr->community ||
6147 ! community_cmp (ri->attr->community, com))
6148 continue;
6149 }
6150 if (type == bgp_show_type_community_list)
6151 {
ajs5a646652004-11-05 01:25:55 +00006152 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006153
6154 if (! community_list_match (ri->attr->community, list))
6155 continue;
6156 }
6157 if (type == bgp_show_type_community_list_exact)
6158 {
ajs5a646652004-11-05 01:25:55 +00006159 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006160
6161 if (! community_list_exact_match (ri->attr->community, list))
6162 continue;
6163 }
6164 if (type == bgp_show_type_flap_address
6165 || type == bgp_show_type_flap_prefix)
6166 {
ajs5a646652004-11-05 01:25:55 +00006167 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006168
6169 if (! prefix_match (&rn->p, p))
6170 continue;
6171
6172 if (type == bgp_show_type_flap_prefix)
6173 if (p->prefixlen != rn->p.prefixlen)
6174 continue;
6175 }
6176 if (type == bgp_show_type_dampend_paths
6177 || type == bgp_show_type_damp_neighbor)
6178 {
6179 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6180 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6181 continue;
6182 }
6183
6184 if (header)
6185 {
hasso93406d82005-02-02 14:40:33 +00006186 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6187 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6188 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006189 if (type == bgp_show_type_dampend_paths
6190 || type == bgp_show_type_damp_neighbor)
6191 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6192 else if (type == bgp_show_type_flap_statistics
6193 || type == bgp_show_type_flap_address
6194 || type == bgp_show_type_flap_prefix
6195 || type == bgp_show_type_flap_cidr_only
6196 || type == bgp_show_type_flap_regexp
6197 || type == bgp_show_type_flap_filter_list
6198 || type == bgp_show_type_flap_prefix_list
6199 || type == bgp_show_type_flap_prefix_longer
6200 || type == bgp_show_type_flap_route_map
6201 || type == bgp_show_type_flap_neighbor)
6202 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6203 else
6204 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006205 header = 0;
6206 }
6207
6208 if (type == bgp_show_type_dampend_paths
6209 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006210 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006211 else if (type == bgp_show_type_flap_statistics
6212 || type == bgp_show_type_flap_address
6213 || type == bgp_show_type_flap_prefix
6214 || type == bgp_show_type_flap_cidr_only
6215 || type == bgp_show_type_flap_regexp
6216 || type == bgp_show_type_flap_filter_list
6217 || type == bgp_show_type_flap_prefix_list
6218 || type == bgp_show_type_flap_prefix_longer
6219 || type == bgp_show_type_flap_route_map
6220 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006221 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006222 else
ajs5a646652004-11-05 01:25:55 +00006223 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006224 display++;
6225 }
6226 if (display)
ajs5a646652004-11-05 01:25:55 +00006227 output_count++;
paul718e3742002-12-13 20:15:29 +00006228 }
6229
6230 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006231 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006232 {
6233 if (type == bgp_show_type_normal)
6234 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6235 }
6236 else
6237 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006238 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006239
6240 return CMD_SUCCESS;
6241}
6242
ajs5a646652004-11-05 01:25:55 +00006243static int
paulfee0f4c2004-09-13 05:12:46 +00006244bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006245 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006246{
6247 struct bgp_table *table;
6248
6249 if (bgp == NULL) {
6250 bgp = bgp_get_default ();
6251 }
6252
6253 if (bgp == NULL)
6254 {
6255 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6256 return CMD_WARNING;
6257 }
6258
6259
6260 table = bgp->rib[afi][safi];
6261
ajs5a646652004-11-05 01:25:55 +00006262 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006263}
6264
paul718e3742002-12-13 20:15:29 +00006265/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006266static void
paul718e3742002-12-13 20:15:29 +00006267route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6268 struct bgp_node *rn,
6269 struct prefix_rd *prd, afi_t afi, safi_t safi)
6270{
6271 struct bgp_info *ri;
6272 struct prefix *p;
6273 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006274 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006275 char buf1[INET6_ADDRSTRLEN];
6276 char buf2[INET6_ADDRSTRLEN];
6277 int count = 0;
6278 int best = 0;
6279 int suppress = 0;
6280 int no_export = 0;
6281 int no_advertise = 0;
6282 int local_as = 0;
6283 int first = 0;
6284
6285 p = &rn->p;
6286 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6287 (safi == SAFI_MPLS_VPN ?
6288 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6289 safi == SAFI_MPLS_VPN ? ":" : "",
6290 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6291 p->prefixlen, VTY_NEWLINE);
6292
6293 for (ri = rn->info; ri; ri = ri->next)
6294 {
6295 count++;
6296 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6297 {
6298 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006299 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006300 suppress = 1;
6301 if (ri->attr->community != NULL)
6302 {
6303 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6304 no_advertise = 1;
6305 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6306 no_export = 1;
6307 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6308 local_as = 1;
6309 }
6310 }
6311 }
6312
6313 vty_out (vty, "Paths: (%d available", count);
6314 if (best)
6315 {
6316 vty_out (vty, ", best #%d", best);
6317 if (safi == SAFI_UNICAST)
6318 vty_out (vty, ", table Default-IP-Routing-Table");
6319 }
6320 else
6321 vty_out (vty, ", no best path");
6322 if (no_advertise)
6323 vty_out (vty, ", not advertised to any peer");
6324 else if (no_export)
6325 vty_out (vty, ", not advertised to EBGP peer");
6326 else if (local_as)
6327 vty_out (vty, ", not advertised outside local AS");
6328 if (suppress)
6329 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6330 vty_out (vty, ")%s", VTY_NEWLINE);
6331
6332 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006333 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006334 {
6335 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6336 {
6337 if (! first)
6338 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6339 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6340 first = 1;
6341 }
6342 }
6343 if (! first)
6344 vty_out (vty, " Not advertised to any peer");
6345 vty_out (vty, "%s", VTY_NEWLINE);
6346}
6347
6348/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006349static int
paulfee0f4c2004-09-13 05:12:46 +00006350bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006351 struct bgp_table *rib, const char *ip_str,
6352 afi_t afi, safi_t safi, struct prefix_rd *prd,
6353 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006354{
6355 int ret;
6356 int header;
6357 int display = 0;
6358 struct prefix match;
6359 struct bgp_node *rn;
6360 struct bgp_node *rm;
6361 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006362 struct bgp_table *table;
6363
paul718e3742002-12-13 20:15:29 +00006364 /* Check IP address argument. */
6365 ret = str2prefix (ip_str, &match);
6366 if (! ret)
6367 {
6368 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6369 return CMD_WARNING;
6370 }
6371
6372 match.family = afi2family (afi);
6373
6374 if (safi == SAFI_MPLS_VPN)
6375 {
paulfee0f4c2004-09-13 05:12:46 +00006376 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006377 {
6378 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6379 continue;
6380
6381 if ((table = rn->info) != NULL)
6382 {
6383 header = 1;
6384
6385 if ((rm = bgp_node_match (table, &match)) != NULL)
6386 {
6387 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006388 {
6389 bgp_unlock_node (rm);
6390 continue;
6391 }
paul718e3742002-12-13 20:15:29 +00006392
6393 for (ri = rm->info; ri; ri = ri->next)
6394 {
6395 if (header)
6396 {
6397 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6398 AFI_IP, SAFI_MPLS_VPN);
6399
6400 header = 0;
6401 }
6402 display++;
6403 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6404 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006405
6406 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006407 }
6408 }
6409 }
6410 }
6411 else
6412 {
6413 header = 1;
6414
paulfee0f4c2004-09-13 05:12:46 +00006415 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006416 {
6417 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6418 {
6419 for (ri = rn->info; ri; ri = ri->next)
6420 {
6421 if (header)
6422 {
6423 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6424 header = 0;
6425 }
6426 display++;
6427 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6428 }
6429 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006430
6431 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006432 }
6433 }
6434
6435 if (! display)
6436 {
6437 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6438 return CMD_WARNING;
6439 }
6440
6441 return CMD_SUCCESS;
6442}
6443
paulfee0f4c2004-09-13 05:12:46 +00006444/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006445static int
paulfd79ac92004-10-13 05:06:08 +00006446bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006447 afi_t afi, safi_t safi, struct prefix_rd *prd,
6448 int prefix_check)
6449{
6450 struct bgp *bgp;
6451
6452 /* BGP structure lookup. */
6453 if (view_name)
6454 {
6455 bgp = bgp_lookup_by_name (view_name);
6456 if (bgp == NULL)
6457 {
6458 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6459 return CMD_WARNING;
6460 }
6461 }
6462 else
6463 {
6464 bgp = bgp_get_default ();
6465 if (bgp == NULL)
6466 {
6467 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6468 return CMD_WARNING;
6469 }
6470 }
6471
6472 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6473 afi, safi, prd, prefix_check);
6474}
6475
paul718e3742002-12-13 20:15:29 +00006476/* BGP route print out function. */
6477DEFUN (show_ip_bgp,
6478 show_ip_bgp_cmd,
6479 "show ip bgp",
6480 SHOW_STR
6481 IP_STR
6482 BGP_STR)
6483{
ajs5a646652004-11-05 01:25:55 +00006484 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006485}
6486
6487DEFUN (show_ip_bgp_ipv4,
6488 show_ip_bgp_ipv4_cmd,
6489 "show ip bgp ipv4 (unicast|multicast)",
6490 SHOW_STR
6491 IP_STR
6492 BGP_STR
6493 "Address family\n"
6494 "Address Family modifier\n"
6495 "Address Family modifier\n")
6496{
6497 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006498 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6499 NULL);
paul718e3742002-12-13 20:15:29 +00006500
ajs5a646652004-11-05 01:25:55 +00006501 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006502}
6503
Michael Lambert95cbbd22010-07-23 14:43:04 -04006504ALIAS (show_ip_bgp_ipv4,
6505 show_bgp_ipv4_safi_cmd,
6506 "show bgp ipv4 (unicast|multicast)",
6507 SHOW_STR
6508 BGP_STR
6509 "Address family\n"
6510 "Address Family modifier\n"
6511 "Address Family modifier\n")
6512
paul718e3742002-12-13 20:15:29 +00006513DEFUN (show_ip_bgp_route,
6514 show_ip_bgp_route_cmd,
6515 "show ip bgp A.B.C.D",
6516 SHOW_STR
6517 IP_STR
6518 BGP_STR
6519 "Network in the BGP routing table to display\n")
6520{
6521 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6522}
6523
6524DEFUN (show_ip_bgp_ipv4_route,
6525 show_ip_bgp_ipv4_route_cmd,
6526 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6527 SHOW_STR
6528 IP_STR
6529 BGP_STR
6530 "Address family\n"
6531 "Address Family modifier\n"
6532 "Address Family modifier\n"
6533 "Network in the BGP routing table to display\n")
6534{
6535 if (strncmp (argv[0], "m", 1) == 0)
6536 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6537
6538 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6539}
6540
Michael Lambert95cbbd22010-07-23 14:43:04 -04006541ALIAS (show_ip_bgp_ipv4_route,
6542 show_bgp_ipv4_safi_route_cmd,
6543 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6544 SHOW_STR
6545 BGP_STR
6546 "Address family\n"
6547 "Address Family modifier\n"
6548 "Address Family modifier\n"
6549 "Network in the BGP routing table to display\n")
6550
paul718e3742002-12-13 20:15:29 +00006551DEFUN (show_ip_bgp_vpnv4_all_route,
6552 show_ip_bgp_vpnv4_all_route_cmd,
6553 "show ip bgp vpnv4 all A.B.C.D",
6554 SHOW_STR
6555 IP_STR
6556 BGP_STR
6557 "Display VPNv4 NLRI specific information\n"
6558 "Display information about all VPNv4 NLRIs\n"
6559 "Network in the BGP routing table to display\n")
6560{
6561 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6562}
6563
6564DEFUN (show_ip_bgp_vpnv4_rd_route,
6565 show_ip_bgp_vpnv4_rd_route_cmd,
6566 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6567 SHOW_STR
6568 IP_STR
6569 BGP_STR
6570 "Display VPNv4 NLRI specific information\n"
6571 "Display information for a route distinguisher\n"
6572 "VPN Route Distinguisher\n"
6573 "Network in the BGP routing table to display\n")
6574{
6575 int ret;
6576 struct prefix_rd prd;
6577
6578 ret = str2prefix_rd (argv[0], &prd);
6579 if (! ret)
6580 {
6581 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6582 return CMD_WARNING;
6583 }
6584 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6585}
6586
6587DEFUN (show_ip_bgp_prefix,
6588 show_ip_bgp_prefix_cmd,
6589 "show ip bgp A.B.C.D/M",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR
6593 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6594{
6595 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6596}
6597
6598DEFUN (show_ip_bgp_ipv4_prefix,
6599 show_ip_bgp_ipv4_prefix_cmd,
6600 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Address family\n"
6605 "Address Family modifier\n"
6606 "Address Family modifier\n"
6607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6608{
6609 if (strncmp (argv[0], "m", 1) == 0)
6610 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6611
6612 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6613}
6614
Michael Lambert95cbbd22010-07-23 14:43:04 -04006615ALIAS (show_ip_bgp_ipv4_prefix,
6616 show_bgp_ipv4_safi_prefix_cmd,
6617 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6618 SHOW_STR
6619 BGP_STR
6620 "Address family\n"
6621 "Address Family modifier\n"
6622 "Address Family modifier\n"
6623 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6624
paul718e3742002-12-13 20:15:29 +00006625DEFUN (show_ip_bgp_vpnv4_all_prefix,
6626 show_ip_bgp_vpnv4_all_prefix_cmd,
6627 "show ip bgp vpnv4 all A.B.C.D/M",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Display VPNv4 NLRI specific information\n"
6632 "Display information about all VPNv4 NLRIs\n"
6633 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6634{
6635 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6636}
6637
6638DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6639 show_ip_bgp_vpnv4_rd_prefix_cmd,
6640 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6641 SHOW_STR
6642 IP_STR
6643 BGP_STR
6644 "Display VPNv4 NLRI specific information\n"
6645 "Display information for a route distinguisher\n"
6646 "VPN Route Distinguisher\n"
6647 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6648{
6649 int ret;
6650 struct prefix_rd prd;
6651
6652 ret = str2prefix_rd (argv[0], &prd);
6653 if (! ret)
6654 {
6655 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6656 return CMD_WARNING;
6657 }
6658 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6659}
6660
6661DEFUN (show_ip_bgp_view,
6662 show_ip_bgp_view_cmd,
6663 "show ip bgp view WORD",
6664 SHOW_STR
6665 IP_STR
6666 BGP_STR
6667 "BGP view\n"
6668 "BGP view name\n")
6669{
paulbb46e942003-10-24 19:02:03 +00006670 struct bgp *bgp;
6671
6672 /* BGP structure lookup. */
6673 bgp = bgp_lookup_by_name (argv[0]);
6674 if (bgp == NULL)
6675 {
6676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6677 return CMD_WARNING;
6678 }
6679
ajs5a646652004-11-05 01:25:55 +00006680 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006681}
6682
6683DEFUN (show_ip_bgp_view_route,
6684 show_ip_bgp_view_route_cmd,
6685 "show ip bgp view WORD A.B.C.D",
6686 SHOW_STR
6687 IP_STR
6688 BGP_STR
6689 "BGP view\n"
6690 "BGP view name\n"
6691 "Network in the BGP routing table to display\n")
6692{
6693 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6694}
6695
6696DEFUN (show_ip_bgp_view_prefix,
6697 show_ip_bgp_view_prefix_cmd,
6698 "show ip bgp view WORD A.B.C.D/M",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "BGP view\n"
6703 "BGP view name\n"
6704 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6705{
6706 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6707}
6708
6709#ifdef HAVE_IPV6
6710DEFUN (show_bgp,
6711 show_bgp_cmd,
6712 "show bgp",
6713 SHOW_STR
6714 BGP_STR)
6715{
ajs5a646652004-11-05 01:25:55 +00006716 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6717 NULL);
paul718e3742002-12-13 20:15:29 +00006718}
6719
6720ALIAS (show_bgp,
6721 show_bgp_ipv6_cmd,
6722 "show bgp ipv6",
6723 SHOW_STR
6724 BGP_STR
6725 "Address family\n")
6726
Michael Lambert95cbbd22010-07-23 14:43:04 -04006727DEFUN (show_bgp_ipv6_safi,
6728 show_bgp_ipv6_safi_cmd,
6729 "show bgp ipv6 (unicast|multicast)",
6730 SHOW_STR
6731 BGP_STR
6732 "Address family\n"
6733 "Address Family modifier\n"
6734 "Address Family modifier\n")
6735{
6736 if (strncmp (argv[0], "m", 1) == 0)
6737 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6738 NULL);
6739
6740 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6741}
6742
paul718e3742002-12-13 20:15:29 +00006743/* old command */
6744DEFUN (show_ipv6_bgp,
6745 show_ipv6_bgp_cmd,
6746 "show ipv6 bgp",
6747 SHOW_STR
6748 IP_STR
6749 BGP_STR)
6750{
ajs5a646652004-11-05 01:25:55 +00006751 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6752 NULL);
paul718e3742002-12-13 20:15:29 +00006753}
6754
6755DEFUN (show_bgp_route,
6756 show_bgp_route_cmd,
6757 "show bgp X:X::X:X",
6758 SHOW_STR
6759 BGP_STR
6760 "Network in the BGP routing table to display\n")
6761{
6762 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6763}
6764
6765ALIAS (show_bgp_route,
6766 show_bgp_ipv6_route_cmd,
6767 "show bgp ipv6 X:X::X:X",
6768 SHOW_STR
6769 BGP_STR
6770 "Address family\n"
6771 "Network in the BGP routing table to display\n")
6772
Michael Lambert95cbbd22010-07-23 14:43:04 -04006773DEFUN (show_bgp_ipv6_safi_route,
6774 show_bgp_ipv6_safi_route_cmd,
6775 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6776 SHOW_STR
6777 BGP_STR
6778 "Address family\n"
6779 "Address Family modifier\n"
6780 "Address Family modifier\n"
6781 "Network in the BGP routing table to display\n")
6782{
6783 if (strncmp (argv[0], "m", 1) == 0)
6784 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6785
6786 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6787}
6788
paul718e3742002-12-13 20:15:29 +00006789/* old command */
6790DEFUN (show_ipv6_bgp_route,
6791 show_ipv6_bgp_route_cmd,
6792 "show ipv6 bgp X:X::X:X",
6793 SHOW_STR
6794 IP_STR
6795 BGP_STR
6796 "Network in the BGP routing table to display\n")
6797{
6798 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6799}
6800
6801DEFUN (show_bgp_prefix,
6802 show_bgp_prefix_cmd,
6803 "show bgp X:X::X:X/M",
6804 SHOW_STR
6805 BGP_STR
6806 "IPv6 prefix <network>/<length>\n")
6807{
6808 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6809}
6810
6811ALIAS (show_bgp_prefix,
6812 show_bgp_ipv6_prefix_cmd,
6813 "show bgp ipv6 X:X::X:X/M",
6814 SHOW_STR
6815 BGP_STR
6816 "Address family\n"
6817 "IPv6 prefix <network>/<length>\n")
6818
Michael Lambert95cbbd22010-07-23 14:43:04 -04006819DEFUN (show_bgp_ipv6_safi_prefix,
6820 show_bgp_ipv6_safi_prefix_cmd,
6821 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6822 SHOW_STR
6823 BGP_STR
6824 "Address family\n"
6825 "Address Family modifier\n"
6826 "Address Family modifier\n"
6827 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6828{
6829 if (strncmp (argv[0], "m", 1) == 0)
6830 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6831
6832 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6833}
6834
paul718e3742002-12-13 20:15:29 +00006835/* old command */
6836DEFUN (show_ipv6_bgp_prefix,
6837 show_ipv6_bgp_prefix_cmd,
6838 "show ipv6 bgp X:X::X:X/M",
6839 SHOW_STR
6840 IP_STR
6841 BGP_STR
6842 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6843{
6844 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6845}
6846
paulbb46e942003-10-24 19:02:03 +00006847DEFUN (show_bgp_view,
6848 show_bgp_view_cmd,
6849 "show bgp view WORD",
6850 SHOW_STR
6851 BGP_STR
6852 "BGP view\n"
6853 "View name\n")
6854{
6855 struct bgp *bgp;
6856
6857 /* BGP structure lookup. */
6858 bgp = bgp_lookup_by_name (argv[0]);
6859 if (bgp == NULL)
6860 {
6861 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6862 return CMD_WARNING;
6863 }
6864
ajs5a646652004-11-05 01:25:55 +00006865 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006866}
6867
6868ALIAS (show_bgp_view,
6869 show_bgp_view_ipv6_cmd,
6870 "show bgp view WORD ipv6",
6871 SHOW_STR
6872 BGP_STR
6873 "BGP view\n"
6874 "View name\n"
6875 "Address family\n")
6876
6877DEFUN (show_bgp_view_route,
6878 show_bgp_view_route_cmd,
6879 "show bgp view WORD X:X::X:X",
6880 SHOW_STR
6881 BGP_STR
6882 "BGP view\n"
6883 "View name\n"
6884 "Network in the BGP routing table to display\n")
6885{
6886 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6887}
6888
6889ALIAS (show_bgp_view_route,
6890 show_bgp_view_ipv6_route_cmd,
6891 "show bgp view WORD ipv6 X:X::X:X",
6892 SHOW_STR
6893 BGP_STR
6894 "BGP view\n"
6895 "View name\n"
6896 "Address family\n"
6897 "Network in the BGP routing table to display\n")
6898
6899DEFUN (show_bgp_view_prefix,
6900 show_bgp_view_prefix_cmd,
6901 "show bgp view WORD X:X::X:X/M",
6902 SHOW_STR
6903 BGP_STR
6904 "BGP view\n"
6905 "View name\n"
6906 "IPv6 prefix <network>/<length>\n")
6907{
6908 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6909}
6910
6911ALIAS (show_bgp_view_prefix,
6912 show_bgp_view_ipv6_prefix_cmd,
6913 "show bgp view WORD ipv6 X:X::X:X/M",
6914 SHOW_STR
6915 BGP_STR
6916 "BGP view\n"
6917 "View name\n"
6918 "Address family\n"
6919 "IPv6 prefix <network>/<length>\n")
6920
paul718e3742002-12-13 20:15:29 +00006921/* old command */
6922DEFUN (show_ipv6_mbgp,
6923 show_ipv6_mbgp_cmd,
6924 "show ipv6 mbgp",
6925 SHOW_STR
6926 IP_STR
6927 MBGP_STR)
6928{
ajs5a646652004-11-05 01:25:55 +00006929 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6930 NULL);
paul718e3742002-12-13 20:15:29 +00006931}
6932
6933/* old command */
6934DEFUN (show_ipv6_mbgp_route,
6935 show_ipv6_mbgp_route_cmd,
6936 "show ipv6 mbgp X:X::X:X",
6937 SHOW_STR
6938 IP_STR
6939 MBGP_STR
6940 "Network in the MBGP routing table to display\n")
6941{
6942 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6943}
6944
6945/* old command */
6946DEFUN (show_ipv6_mbgp_prefix,
6947 show_ipv6_mbgp_prefix_cmd,
6948 "show ipv6 mbgp X:X::X:X/M",
6949 SHOW_STR
6950 IP_STR
6951 MBGP_STR
6952 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6953{
6954 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6955}
6956#endif
6957
paul718e3742002-12-13 20:15:29 +00006958
paul94f2b392005-06-28 12:44:16 +00006959static int
paulfd79ac92004-10-13 05:06:08 +00006960bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006961 safi_t safi, enum bgp_show_type type)
6962{
6963 int i;
6964 struct buffer *b;
6965 char *regstr;
6966 int first;
6967 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006968 int rc;
paul718e3742002-12-13 20:15:29 +00006969
6970 first = 0;
6971 b = buffer_new (1024);
6972 for (i = 0; i < argc; i++)
6973 {
6974 if (first)
6975 buffer_putc (b, ' ');
6976 else
6977 {
6978 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6979 continue;
6980 first = 1;
6981 }
6982
6983 buffer_putstr (b, argv[i]);
6984 }
6985 buffer_putc (b, '\0');
6986
6987 regstr = buffer_getstr (b);
6988 buffer_free (b);
6989
6990 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006991 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006992 if (! regex)
6993 {
6994 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6995 VTY_NEWLINE);
6996 return CMD_WARNING;
6997 }
6998
ajs5a646652004-11-05 01:25:55 +00006999 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7000 bgp_regex_free (regex);
7001 return rc;
paul718e3742002-12-13 20:15:29 +00007002}
7003
7004DEFUN (show_ip_bgp_regexp,
7005 show_ip_bgp_regexp_cmd,
7006 "show ip bgp regexp .LINE",
7007 SHOW_STR
7008 IP_STR
7009 BGP_STR
7010 "Display routes matching the AS path regular expression\n"
7011 "A regular-expression to match the BGP AS paths\n")
7012{
7013 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7014 bgp_show_type_regexp);
7015}
7016
7017DEFUN (show_ip_bgp_flap_regexp,
7018 show_ip_bgp_flap_regexp_cmd,
7019 "show ip bgp flap-statistics regexp .LINE",
7020 SHOW_STR
7021 IP_STR
7022 BGP_STR
7023 "Display flap statistics of routes\n"
7024 "Display routes matching the AS path regular expression\n"
7025 "A regular-expression to match the BGP AS paths\n")
7026{
7027 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7028 bgp_show_type_flap_regexp);
7029}
7030
7031DEFUN (show_ip_bgp_ipv4_regexp,
7032 show_ip_bgp_ipv4_regexp_cmd,
7033 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7034 SHOW_STR
7035 IP_STR
7036 BGP_STR
7037 "Address family\n"
7038 "Address Family modifier\n"
7039 "Address Family modifier\n"
7040 "Display routes matching the AS path regular expression\n"
7041 "A regular-expression to match the BGP AS paths\n")
7042{
7043 if (strncmp (argv[0], "m", 1) == 0)
7044 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7045 bgp_show_type_regexp);
7046
7047 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7048 bgp_show_type_regexp);
7049}
7050
7051#ifdef HAVE_IPV6
7052DEFUN (show_bgp_regexp,
7053 show_bgp_regexp_cmd,
7054 "show bgp regexp .LINE",
7055 SHOW_STR
7056 BGP_STR
7057 "Display routes matching the AS path regular expression\n"
7058 "A regular-expression to match the BGP AS paths\n")
7059{
7060 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7061 bgp_show_type_regexp);
7062}
7063
7064ALIAS (show_bgp_regexp,
7065 show_bgp_ipv6_regexp_cmd,
7066 "show bgp ipv6 regexp .LINE",
7067 SHOW_STR
7068 BGP_STR
7069 "Address family\n"
7070 "Display routes matching the AS path regular expression\n"
7071 "A regular-expression to match the BGP AS paths\n")
7072
7073/* old command */
7074DEFUN (show_ipv6_bgp_regexp,
7075 show_ipv6_bgp_regexp_cmd,
7076 "show ipv6 bgp regexp .LINE",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Display routes matching the AS path regular expression\n"
7081 "A regular-expression to match the BGP AS paths\n")
7082{
7083 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7084 bgp_show_type_regexp);
7085}
7086
7087/* old command */
7088DEFUN (show_ipv6_mbgp_regexp,
7089 show_ipv6_mbgp_regexp_cmd,
7090 "show ipv6 mbgp regexp .LINE",
7091 SHOW_STR
7092 IP_STR
7093 BGP_STR
7094 "Display routes matching the AS path regular expression\n"
7095 "A regular-expression to match the MBGP AS paths\n")
7096{
7097 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7098 bgp_show_type_regexp);
7099}
7100#endif /* HAVE_IPV6 */
7101
paul94f2b392005-06-28 12:44:16 +00007102static int
paulfd79ac92004-10-13 05:06:08 +00007103bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007104 safi_t safi, enum bgp_show_type type)
7105{
7106 struct prefix_list *plist;
7107
7108 plist = prefix_list_lookup (afi, prefix_list_str);
7109 if (plist == NULL)
7110 {
7111 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7112 prefix_list_str, VTY_NEWLINE);
7113 return CMD_WARNING;
7114 }
7115
ajs5a646652004-11-05 01:25:55 +00007116 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007117}
7118
7119DEFUN (show_ip_bgp_prefix_list,
7120 show_ip_bgp_prefix_list_cmd,
7121 "show ip bgp prefix-list WORD",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display routes conforming to the prefix-list\n"
7126 "IP prefix-list name\n")
7127{
7128 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7129 bgp_show_type_prefix_list);
7130}
7131
7132DEFUN (show_ip_bgp_flap_prefix_list,
7133 show_ip_bgp_flap_prefix_list_cmd,
7134 "show ip bgp flap-statistics prefix-list WORD",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Display flap statistics of routes\n"
7139 "Display routes conforming to the prefix-list\n"
7140 "IP prefix-list name\n")
7141{
7142 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7143 bgp_show_type_flap_prefix_list);
7144}
7145
7146DEFUN (show_ip_bgp_ipv4_prefix_list,
7147 show_ip_bgp_ipv4_prefix_list_cmd,
7148 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7149 SHOW_STR
7150 IP_STR
7151 BGP_STR
7152 "Address family\n"
7153 "Address Family modifier\n"
7154 "Address Family modifier\n"
7155 "Display routes conforming to the prefix-list\n"
7156 "IP prefix-list name\n")
7157{
7158 if (strncmp (argv[0], "m", 1) == 0)
7159 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7160 bgp_show_type_prefix_list);
7161
7162 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7163 bgp_show_type_prefix_list);
7164}
7165
7166#ifdef HAVE_IPV6
7167DEFUN (show_bgp_prefix_list,
7168 show_bgp_prefix_list_cmd,
7169 "show bgp prefix-list WORD",
7170 SHOW_STR
7171 BGP_STR
7172 "Display routes conforming to the prefix-list\n"
7173 "IPv6 prefix-list name\n")
7174{
7175 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7176 bgp_show_type_prefix_list);
7177}
7178
7179ALIAS (show_bgp_prefix_list,
7180 show_bgp_ipv6_prefix_list_cmd,
7181 "show bgp ipv6 prefix-list WORD",
7182 SHOW_STR
7183 BGP_STR
7184 "Address family\n"
7185 "Display routes conforming to the prefix-list\n"
7186 "IPv6 prefix-list name\n")
7187
7188/* old command */
7189DEFUN (show_ipv6_bgp_prefix_list,
7190 show_ipv6_bgp_prefix_list_cmd,
7191 "show ipv6 bgp prefix-list WORD",
7192 SHOW_STR
7193 IPV6_STR
7194 BGP_STR
7195 "Display routes matching the prefix-list\n"
7196 "IPv6 prefix-list name\n")
7197{
7198 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7199 bgp_show_type_prefix_list);
7200}
7201
7202/* old command */
7203DEFUN (show_ipv6_mbgp_prefix_list,
7204 show_ipv6_mbgp_prefix_list_cmd,
7205 "show ipv6 mbgp prefix-list WORD",
7206 SHOW_STR
7207 IPV6_STR
7208 MBGP_STR
7209 "Display routes matching the prefix-list\n"
7210 "IPv6 prefix-list name\n")
7211{
7212 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7213 bgp_show_type_prefix_list);
7214}
7215#endif /* HAVE_IPV6 */
7216
paul94f2b392005-06-28 12:44:16 +00007217static int
paulfd79ac92004-10-13 05:06:08 +00007218bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007219 safi_t safi, enum bgp_show_type type)
7220{
7221 struct as_list *as_list;
7222
7223 as_list = as_list_lookup (filter);
7224 if (as_list == NULL)
7225 {
7226 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7227 return CMD_WARNING;
7228 }
7229
ajs5a646652004-11-05 01:25:55 +00007230 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007231}
7232
7233DEFUN (show_ip_bgp_filter_list,
7234 show_ip_bgp_filter_list_cmd,
7235 "show ip bgp filter-list WORD",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display routes conforming to the filter-list\n"
7240 "Regular expression access list name\n")
7241{
7242 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7243 bgp_show_type_filter_list);
7244}
7245
7246DEFUN (show_ip_bgp_flap_filter_list,
7247 show_ip_bgp_flap_filter_list_cmd,
7248 "show ip bgp flap-statistics filter-list WORD",
7249 SHOW_STR
7250 IP_STR
7251 BGP_STR
7252 "Display flap statistics of routes\n"
7253 "Display routes conforming to the filter-list\n"
7254 "Regular expression access list name\n")
7255{
7256 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7257 bgp_show_type_flap_filter_list);
7258}
7259
7260DEFUN (show_ip_bgp_ipv4_filter_list,
7261 show_ip_bgp_ipv4_filter_list_cmd,
7262 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Address family\n"
7267 "Address Family modifier\n"
7268 "Address Family modifier\n"
7269 "Display routes conforming to the filter-list\n"
7270 "Regular expression access list name\n")
7271{
7272 if (strncmp (argv[0], "m", 1) == 0)
7273 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7274 bgp_show_type_filter_list);
7275
7276 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7277 bgp_show_type_filter_list);
7278}
7279
7280#ifdef HAVE_IPV6
7281DEFUN (show_bgp_filter_list,
7282 show_bgp_filter_list_cmd,
7283 "show bgp filter-list WORD",
7284 SHOW_STR
7285 BGP_STR
7286 "Display routes conforming to the filter-list\n"
7287 "Regular expression access list name\n")
7288{
7289 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7290 bgp_show_type_filter_list);
7291}
7292
7293ALIAS (show_bgp_filter_list,
7294 show_bgp_ipv6_filter_list_cmd,
7295 "show bgp ipv6 filter-list WORD",
7296 SHOW_STR
7297 BGP_STR
7298 "Address family\n"
7299 "Display routes conforming to the filter-list\n"
7300 "Regular expression access list name\n")
7301
7302/* old command */
7303DEFUN (show_ipv6_bgp_filter_list,
7304 show_ipv6_bgp_filter_list_cmd,
7305 "show ipv6 bgp filter-list WORD",
7306 SHOW_STR
7307 IPV6_STR
7308 BGP_STR
7309 "Display routes conforming to the filter-list\n"
7310 "Regular expression access list name\n")
7311{
7312 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7313 bgp_show_type_filter_list);
7314}
7315
7316/* old command */
7317DEFUN (show_ipv6_mbgp_filter_list,
7318 show_ipv6_mbgp_filter_list_cmd,
7319 "show ipv6 mbgp filter-list WORD",
7320 SHOW_STR
7321 IPV6_STR
7322 MBGP_STR
7323 "Display routes conforming to the filter-list\n"
7324 "Regular expression access list name\n")
7325{
7326 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7327 bgp_show_type_filter_list);
7328}
7329#endif /* HAVE_IPV6 */
7330
paul94f2b392005-06-28 12:44:16 +00007331static int
paulfd79ac92004-10-13 05:06:08 +00007332bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007333 safi_t safi, enum bgp_show_type type)
7334{
7335 struct route_map *rmap;
7336
7337 rmap = route_map_lookup_by_name (rmap_str);
7338 if (! rmap)
7339 {
7340 vty_out (vty, "%% %s is not a valid route-map name%s",
7341 rmap_str, VTY_NEWLINE);
7342 return CMD_WARNING;
7343 }
7344
ajs5a646652004-11-05 01:25:55 +00007345 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007346}
7347
7348DEFUN (show_ip_bgp_route_map,
7349 show_ip_bgp_route_map_cmd,
7350 "show ip bgp route-map WORD",
7351 SHOW_STR
7352 IP_STR
7353 BGP_STR
7354 "Display routes matching the route-map\n"
7355 "A route-map to match on\n")
7356{
7357 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7358 bgp_show_type_route_map);
7359}
7360
7361DEFUN (show_ip_bgp_flap_route_map,
7362 show_ip_bgp_flap_route_map_cmd,
7363 "show ip bgp flap-statistics route-map WORD",
7364 SHOW_STR
7365 IP_STR
7366 BGP_STR
7367 "Display flap statistics of routes\n"
7368 "Display routes matching the route-map\n"
7369 "A route-map to match on\n")
7370{
7371 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7372 bgp_show_type_flap_route_map);
7373}
7374
7375DEFUN (show_ip_bgp_ipv4_route_map,
7376 show_ip_bgp_ipv4_route_map_cmd,
7377 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7378 SHOW_STR
7379 IP_STR
7380 BGP_STR
7381 "Address family\n"
7382 "Address Family modifier\n"
7383 "Address Family modifier\n"
7384 "Display routes matching the route-map\n"
7385 "A route-map to match on\n")
7386{
7387 if (strncmp (argv[0], "m", 1) == 0)
7388 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7389 bgp_show_type_route_map);
7390
7391 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_route_map);
7393}
7394
7395DEFUN (show_bgp_route_map,
7396 show_bgp_route_map_cmd,
7397 "show bgp route-map WORD",
7398 SHOW_STR
7399 BGP_STR
7400 "Display routes matching the route-map\n"
7401 "A route-map to match on\n")
7402{
7403 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7404 bgp_show_type_route_map);
7405}
7406
7407ALIAS (show_bgp_route_map,
7408 show_bgp_ipv6_route_map_cmd,
7409 "show bgp ipv6 route-map WORD",
7410 SHOW_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Display routes matching the route-map\n"
7414 "A route-map to match on\n")
7415
7416DEFUN (show_ip_bgp_cidr_only,
7417 show_ip_bgp_cidr_only_cmd,
7418 "show ip bgp cidr-only",
7419 SHOW_STR
7420 IP_STR
7421 BGP_STR
7422 "Display only routes with non-natural netmasks\n")
7423{
7424 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007425 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007426}
7427
7428DEFUN (show_ip_bgp_flap_cidr_only,
7429 show_ip_bgp_flap_cidr_only_cmd,
7430 "show ip bgp flap-statistics cidr-only",
7431 SHOW_STR
7432 IP_STR
7433 BGP_STR
7434 "Display flap statistics of routes\n"
7435 "Display only routes with non-natural netmasks\n")
7436{
7437 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007438 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007439}
7440
7441DEFUN (show_ip_bgp_ipv4_cidr_only,
7442 show_ip_bgp_ipv4_cidr_only_cmd,
7443 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7444 SHOW_STR
7445 IP_STR
7446 BGP_STR
7447 "Address family\n"
7448 "Address Family modifier\n"
7449 "Address Family modifier\n"
7450 "Display only routes with non-natural netmasks\n")
7451{
7452 if (strncmp (argv[0], "m", 1) == 0)
7453 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007454 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007455
7456 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007457 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007458}
7459
7460DEFUN (show_ip_bgp_community_all,
7461 show_ip_bgp_community_all_cmd,
7462 "show ip bgp community",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Display routes matching the communities\n")
7467{
7468 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007469 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007470}
7471
7472DEFUN (show_ip_bgp_ipv4_community_all,
7473 show_ip_bgp_ipv4_community_all_cmd,
7474 "show ip bgp ipv4 (unicast|multicast) community",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Address family\n"
7479 "Address Family modifier\n"
7480 "Address Family modifier\n"
7481 "Display routes matching the communities\n")
7482{
7483 if (strncmp (argv[0], "m", 1) == 0)
7484 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007485 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007486
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007488 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007489}
7490
7491#ifdef HAVE_IPV6
7492DEFUN (show_bgp_community_all,
7493 show_bgp_community_all_cmd,
7494 "show bgp community",
7495 SHOW_STR
7496 BGP_STR
7497 "Display routes matching the communities\n")
7498{
7499 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007500 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007501}
7502
7503ALIAS (show_bgp_community_all,
7504 show_bgp_ipv6_community_all_cmd,
7505 "show bgp ipv6 community",
7506 SHOW_STR
7507 BGP_STR
7508 "Address family\n"
7509 "Display routes matching the communities\n")
7510
7511/* old command */
7512DEFUN (show_ipv6_bgp_community_all,
7513 show_ipv6_bgp_community_all_cmd,
7514 "show ipv6 bgp community",
7515 SHOW_STR
7516 IPV6_STR
7517 BGP_STR
7518 "Display routes matching the communities\n")
7519{
7520 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007521 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007522}
7523
7524/* old command */
7525DEFUN (show_ipv6_mbgp_community_all,
7526 show_ipv6_mbgp_community_all_cmd,
7527 "show ipv6 mbgp community",
7528 SHOW_STR
7529 IPV6_STR
7530 MBGP_STR
7531 "Display routes matching the communities\n")
7532{
7533 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007534 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007535}
7536#endif /* HAVE_IPV6 */
7537
paul94f2b392005-06-28 12:44:16 +00007538static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007539bgp_show_community (struct vty *vty, const char *view_name, int argc,
7540 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007541{
7542 struct community *com;
7543 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007544 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007545 int i;
7546 char *str;
7547 int first = 0;
7548
Michael Lambert95cbbd22010-07-23 14:43:04 -04007549 /* BGP structure lookup */
7550 if (view_name)
7551 {
7552 bgp = bgp_lookup_by_name (view_name);
7553 if (bgp == NULL)
7554 {
7555 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7556 return CMD_WARNING;
7557 }
7558 }
7559 else
7560 {
7561 bgp = bgp_get_default ();
7562 if (bgp == NULL)
7563 {
7564 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7565 return CMD_WARNING;
7566 }
7567 }
7568
paul718e3742002-12-13 20:15:29 +00007569 b = buffer_new (1024);
7570 for (i = 0; i < argc; i++)
7571 {
7572 if (first)
7573 buffer_putc (b, ' ');
7574 else
7575 {
7576 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7577 continue;
7578 first = 1;
7579 }
7580
7581 buffer_putstr (b, argv[i]);
7582 }
7583 buffer_putc (b, '\0');
7584
7585 str = buffer_getstr (b);
7586 buffer_free (b);
7587
7588 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007589 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007590 if (! com)
7591 {
7592 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7593 return CMD_WARNING;
7594 }
7595
Michael Lambert95cbbd22010-07-23 14:43:04 -04007596 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007597 (exact ? bgp_show_type_community_exact :
7598 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007599}
7600
7601DEFUN (show_ip_bgp_community,
7602 show_ip_bgp_community_cmd,
7603 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7604 SHOW_STR
7605 IP_STR
7606 BGP_STR
7607 "Display routes matching the communities\n"
7608 "community number\n"
7609 "Do not send outside local AS (well-known community)\n"
7610 "Do not advertise to any peer (well-known community)\n"
7611 "Do not export to next AS (well-known community)\n")
7612{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007613 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007614}
7615
7616ALIAS (show_ip_bgp_community,
7617 show_ip_bgp_community2_cmd,
7618 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7619 SHOW_STR
7620 IP_STR
7621 BGP_STR
7622 "Display routes matching the communities\n"
7623 "community number\n"
7624 "Do not send outside local AS (well-known community)\n"
7625 "Do not advertise to any peer (well-known community)\n"
7626 "Do not export to next AS (well-known community)\n"
7627 "community number\n"
7628 "Do not send outside local AS (well-known community)\n"
7629 "Do not advertise to any peer (well-known community)\n"
7630 "Do not export to next AS (well-known community)\n")
7631
7632ALIAS (show_ip_bgp_community,
7633 show_ip_bgp_community3_cmd,
7634 "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)",
7635 SHOW_STR
7636 IP_STR
7637 BGP_STR
7638 "Display routes matching the communities\n"
7639 "community number\n"
7640 "Do not send outside local AS (well-known community)\n"
7641 "Do not advertise to any peer (well-known community)\n"
7642 "Do not export to next AS (well-known community)\n"
7643 "community number\n"
7644 "Do not send outside local AS (well-known community)\n"
7645 "Do not advertise to any peer (well-known community)\n"
7646 "Do not export to next AS (well-known community)\n"
7647 "community number\n"
7648 "Do not send outside local AS (well-known community)\n"
7649 "Do not advertise to any peer (well-known community)\n"
7650 "Do not export to next AS (well-known community)\n")
7651
7652ALIAS (show_ip_bgp_community,
7653 show_ip_bgp_community4_cmd,
7654 "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)",
7655 SHOW_STR
7656 IP_STR
7657 BGP_STR
7658 "Display routes matching the communities\n"
7659 "community number\n"
7660 "Do not send outside local AS (well-known community)\n"
7661 "Do not advertise to any peer (well-known community)\n"
7662 "Do not export to next AS (well-known community)\n"
7663 "community number\n"
7664 "Do not send outside local AS (well-known community)\n"
7665 "Do not advertise to any peer (well-known community)\n"
7666 "Do not export to next AS (well-known community)\n"
7667 "community number\n"
7668 "Do not send outside local AS (well-known community)\n"
7669 "Do not advertise to any peer (well-known community)\n"
7670 "Do not export to next AS (well-known community)\n"
7671 "community number\n"
7672 "Do not send outside local AS (well-known community)\n"
7673 "Do not advertise to any peer (well-known community)\n"
7674 "Do not export to next AS (well-known community)\n")
7675
7676DEFUN (show_ip_bgp_ipv4_community,
7677 show_ip_bgp_ipv4_community_cmd,
7678 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7679 SHOW_STR
7680 IP_STR
7681 BGP_STR
7682 "Address family\n"
7683 "Address Family modifier\n"
7684 "Address Family modifier\n"
7685 "Display routes matching the communities\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n")
7690{
7691 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007692 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007693
Michael Lambert95cbbd22010-07-23 14:43:04 -04007694 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007695}
7696
7697ALIAS (show_ip_bgp_ipv4_community,
7698 show_ip_bgp_ipv4_community2_cmd,
7699 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7700 SHOW_STR
7701 IP_STR
7702 BGP_STR
7703 "Address family\n"
7704 "Address Family modifier\n"
7705 "Address Family modifier\n"
7706 "Display routes matching the communities\n"
7707 "community number\n"
7708 "Do not send outside local AS (well-known community)\n"
7709 "Do not advertise to any peer (well-known community)\n"
7710 "Do not export to next AS (well-known community)\n"
7711 "community number\n"
7712 "Do not send outside local AS (well-known community)\n"
7713 "Do not advertise to any peer (well-known community)\n"
7714 "Do not export to next AS (well-known community)\n")
7715
7716ALIAS (show_ip_bgp_ipv4_community,
7717 show_ip_bgp_ipv4_community3_cmd,
7718 "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)",
7719 SHOW_STR
7720 IP_STR
7721 BGP_STR
7722 "Address family\n"
7723 "Address Family modifier\n"
7724 "Address Family modifier\n"
7725 "Display routes matching the communities\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "community number\n"
7735 "Do not send outside local AS (well-known community)\n"
7736 "Do not advertise to any peer (well-known community)\n"
7737 "Do not export to next AS (well-known community)\n")
7738
7739ALIAS (show_ip_bgp_ipv4_community,
7740 show_ip_bgp_ipv4_community4_cmd,
7741 "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)",
7742 SHOW_STR
7743 IP_STR
7744 BGP_STR
7745 "Address family\n"
7746 "Address Family modifier\n"
7747 "Address Family modifier\n"
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n")
7765
Michael Lambert95cbbd22010-07-23 14:43:04 -04007766DEFUN (show_bgp_view_afi_safi_community_all,
7767 show_bgp_view_afi_safi_community_all_cmd,
7768#ifdef HAVE_IPV6
7769 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7770#else
7771 "show bgp view WORD ipv4 (unicast|multicast) community",
7772#endif
7773 SHOW_STR
7774 BGP_STR
7775 "BGP view\n"
7776 "BGP view name\n"
7777 "Address family\n"
7778#ifdef HAVE_IPV6
7779 "Address family\n"
7780#endif
7781 "Address Family modifier\n"
7782 "Address Family modifier\n"
7783 "Display routes containing communities\n")
7784{
7785 int afi;
7786 int safi;
7787 struct bgp *bgp;
7788
7789 /* BGP structure lookup. */
7790 bgp = bgp_lookup_by_name (argv[0]);
7791 if (bgp == NULL)
7792 {
7793 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7794 return CMD_WARNING;
7795 }
7796
7797#ifdef HAVE_IPV6
7798 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7799 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7800#else
7801 afi = AFI_IP;
7802 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7803#endif
7804 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7805}
7806
7807DEFUN (show_bgp_view_afi_safi_community,
7808 show_bgp_view_afi_safi_community_cmd,
7809#ifdef HAVE_IPV6
7810 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7811#else
7812 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7813#endif
7814 SHOW_STR
7815 BGP_STR
7816 "BGP view\n"
7817 "BGP view name\n"
7818 "Address family\n"
7819#ifdef HAVE_IPV6
7820 "Address family\n"
7821#endif
7822 "Address family modifier\n"
7823 "Address family modifier\n"
7824 "Display routes matching the communities\n"
7825 "community number\n"
7826 "Do not send outside local AS (well-known community)\n"
7827 "Do not advertise to any peer (well-known community)\n"
7828 "Do not export to next AS (well-known community)\n")
7829{
7830 int afi;
7831 int safi;
7832
7833#ifdef HAVE_IPV6
7834 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7835 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7836 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7837#else
7838 afi = AFI_IP;
7839 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7840 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7841#endif
7842}
7843
7844ALIAS (show_bgp_view_afi_safi_community,
7845 show_bgp_view_afi_safi_community2_cmd,
7846#ifdef HAVE_IPV6
7847 "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)",
7848#else
7849 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7850#endif
7851 SHOW_STR
7852 BGP_STR
7853 "BGP view\n"
7854 "BGP view name\n"
7855 "Address family\n"
7856#ifdef HAVE_IPV6
7857 "Address family\n"
7858#endif
7859 "Address family modifier\n"
7860 "Address family modifier\n"
7861 "Display routes matching the communities\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n")
7870
7871ALIAS (show_bgp_view_afi_safi_community,
7872 show_bgp_view_afi_safi_community3_cmd,
7873#ifdef HAVE_IPV6
7874 "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)",
7875#else
7876 "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)",
7877#endif
7878 SHOW_STR
7879 BGP_STR
7880 "BGP view\n"
7881 "BGP view name\n"
7882 "Address family\n"
7883#ifdef HAVE_IPV6
7884 "Address family\n"
7885#endif
7886 "Address family modifier\n"
7887 "Address family modifier\n"
7888 "Display routes matching the communities\n"
7889 "community number\n"
7890 "Do not send outside local AS (well-known community)\n"
7891 "Do not advertise to any peer (well-known community)\n"
7892 "Do not export to next AS (well-known community)\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n")
7901
7902ALIAS (show_bgp_view_afi_safi_community,
7903 show_bgp_view_afi_safi_community4_cmd,
7904#ifdef HAVE_IPV6
7905 "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)",
7906#else
7907 "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)",
7908#endif
7909 SHOW_STR
7910 BGP_STR
7911 "BGP view\n"
7912 "BGP view name\n"
7913 "Address family\n"
7914#ifdef HAVE_IPV6
7915 "Address family\n"
7916#endif
7917 "Address family modifier\n"
7918 "Address family modifier\n"
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n")
7936
paul718e3742002-12-13 20:15:29 +00007937DEFUN (show_ip_bgp_community_exact,
7938 show_ip_bgp_community_exact_cmd,
7939 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7940 SHOW_STR
7941 IP_STR
7942 BGP_STR
7943 "Display routes matching the communities\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n"
7948 "Exact match of the communities")
7949{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007950 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007951}
7952
7953ALIAS (show_ip_bgp_community_exact,
7954 show_ip_bgp_community2_exact_cmd,
7955 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7956 SHOW_STR
7957 IP_STR
7958 BGP_STR
7959 "Display routes matching the communities\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n"
7964 "community number\n"
7965 "Do not send outside local AS (well-known community)\n"
7966 "Do not advertise to any peer (well-known community)\n"
7967 "Do not export to next AS (well-known community)\n"
7968 "Exact match of the communities")
7969
7970ALIAS (show_ip_bgp_community_exact,
7971 show_ip_bgp_community3_exact_cmd,
7972 "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",
7973 SHOW_STR
7974 IP_STR
7975 BGP_STR
7976 "Display routes matching the communities\n"
7977 "community number\n"
7978 "Do not send outside local AS (well-known community)\n"
7979 "Do not advertise to any peer (well-known community)\n"
7980 "Do not export to next AS (well-known community)\n"
7981 "community number\n"
7982 "Do not send outside local AS (well-known community)\n"
7983 "Do not advertise to any peer (well-known community)\n"
7984 "Do not export to next AS (well-known community)\n"
7985 "community number\n"
7986 "Do not send outside local AS (well-known community)\n"
7987 "Do not advertise to any peer (well-known community)\n"
7988 "Do not export to next AS (well-known community)\n"
7989 "Exact match of the communities")
7990
7991ALIAS (show_ip_bgp_community_exact,
7992 show_ip_bgp_community4_exact_cmd,
7993 "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",
7994 SHOW_STR
7995 IP_STR
7996 BGP_STR
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n"
8014 "Exact match of the communities")
8015
8016DEFUN (show_ip_bgp_ipv4_community_exact,
8017 show_ip_bgp_ipv4_community_exact_cmd,
8018 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8019 SHOW_STR
8020 IP_STR
8021 BGP_STR
8022 "Address family\n"
8023 "Address Family modifier\n"
8024 "Address Family modifier\n"
8025 "Display routes matching the communities\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "Exact match of the communities")
8031{
8032 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008033 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008034
Michael Lambert95cbbd22010-07-23 14:43:04 -04008035 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008036}
8037
8038ALIAS (show_ip_bgp_ipv4_community_exact,
8039 show_ip_bgp_ipv4_community2_exact_cmd,
8040 "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",
8041 SHOW_STR
8042 IP_STR
8043 BGP_STR
8044 "Address family\n"
8045 "Address Family modifier\n"
8046 "Address Family modifier\n"
8047 "Display routes matching the communities\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "Exact match of the communities")
8057
8058ALIAS (show_ip_bgp_ipv4_community_exact,
8059 show_ip_bgp_ipv4_community3_exact_cmd,
8060 "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",
8061 SHOW_STR
8062 IP_STR
8063 BGP_STR
8064 "Address family\n"
8065 "Address Family modifier\n"
8066 "Address Family modifier\n"
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "Exact match of the communities")
8081
8082ALIAS (show_ip_bgp_ipv4_community_exact,
8083 show_ip_bgp_ipv4_community4_exact_cmd,
8084 "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",
8085 SHOW_STR
8086 IP_STR
8087 BGP_STR
8088 "Address family\n"
8089 "Address Family modifier\n"
8090 "Address Family modifier\n"
8091 "Display routes matching the communities\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "Exact match of the communities")
8109
8110#ifdef HAVE_IPV6
8111DEFUN (show_bgp_community,
8112 show_bgp_community_cmd,
8113 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8114 SHOW_STR
8115 BGP_STR
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n")
8121{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008122 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008123}
8124
8125ALIAS (show_bgp_community,
8126 show_bgp_ipv6_community_cmd,
8127 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8128 SHOW_STR
8129 BGP_STR
8130 "Address family\n"
8131 "Display routes matching the communities\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n")
8136
8137ALIAS (show_bgp_community,
8138 show_bgp_community2_cmd,
8139 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8140 SHOW_STR
8141 BGP_STR
8142 "Display routes matching the communities\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n")
8151
8152ALIAS (show_bgp_community,
8153 show_bgp_ipv6_community2_cmd,
8154 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8155 SHOW_STR
8156 BGP_STR
8157 "Address family\n"
8158 "Display routes matching the communities\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n")
8167
8168ALIAS (show_bgp_community,
8169 show_bgp_community3_cmd,
8170 "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)",
8171 SHOW_STR
8172 BGP_STR
8173 "Display routes matching the communities\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "community number\n"
8183 "Do not send outside local AS (well-known community)\n"
8184 "Do not advertise to any peer (well-known community)\n"
8185 "Do not export to next AS (well-known community)\n")
8186
8187ALIAS (show_bgp_community,
8188 show_bgp_ipv6_community3_cmd,
8189 "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)",
8190 SHOW_STR
8191 BGP_STR
8192 "Address family\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n")
8206
8207ALIAS (show_bgp_community,
8208 show_bgp_community4_cmd,
8209 "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)",
8210 SHOW_STR
8211 BGP_STR
8212 "Display routes matching the communities\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n")
8229
8230ALIAS (show_bgp_community,
8231 show_bgp_ipv6_community4_cmd,
8232 "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)",
8233 SHOW_STR
8234 BGP_STR
8235 "Address family\n"
8236 "Display routes matching the communities\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n")
8253
8254/* old command */
8255DEFUN (show_ipv6_bgp_community,
8256 show_ipv6_bgp_community_cmd,
8257 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8258 SHOW_STR
8259 IPV6_STR
8260 BGP_STR
8261 "Display routes matching the communities\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n")
8266{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008267 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008268}
8269
8270/* old command */
8271ALIAS (show_ipv6_bgp_community,
8272 show_ipv6_bgp_community2_cmd,
8273 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8274 SHOW_STR
8275 IPV6_STR
8276 BGP_STR
8277 "Display routes matching the communities\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n")
8286
8287/* old command */
8288ALIAS (show_ipv6_bgp_community,
8289 show_ipv6_bgp_community3_cmd,
8290 "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)",
8291 SHOW_STR
8292 IPV6_STR
8293 BGP_STR
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n")
8307
8308/* old command */
8309ALIAS (show_ipv6_bgp_community,
8310 show_ipv6_bgp_community4_cmd,
8311 "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)",
8312 SHOW_STR
8313 IPV6_STR
8314 BGP_STR
8315 "Display routes matching the communities\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n")
8332
8333DEFUN (show_bgp_community_exact,
8334 show_bgp_community_exact_cmd,
8335 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8336 SHOW_STR
8337 BGP_STR
8338 "Display routes matching the communities\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "Exact match of the communities")
8344{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008345 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008346}
8347
8348ALIAS (show_bgp_community_exact,
8349 show_bgp_ipv6_community_exact_cmd,
8350 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8351 SHOW_STR
8352 BGP_STR
8353 "Address family\n"
8354 "Display routes matching the communities\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n"
8359 "Exact match of the communities")
8360
8361ALIAS (show_bgp_community_exact,
8362 show_bgp_community2_exact_cmd,
8363 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8364 SHOW_STR
8365 BGP_STR
8366 "Display routes matching the communities\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n"
8375 "Exact match of the communities")
8376
8377ALIAS (show_bgp_community_exact,
8378 show_bgp_ipv6_community2_exact_cmd,
8379 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8380 SHOW_STR
8381 BGP_STR
8382 "Address family\n"
8383 "Display routes matching the communities\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "Exact match of the communities")
8393
8394ALIAS (show_bgp_community_exact,
8395 show_bgp_community3_exact_cmd,
8396 "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",
8397 SHOW_STR
8398 BGP_STR
8399 "Display routes matching the communities\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n"
8412 "Exact match of the communities")
8413
8414ALIAS (show_bgp_community_exact,
8415 show_bgp_ipv6_community3_exact_cmd,
8416 "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",
8417 SHOW_STR
8418 BGP_STR
8419 "Address family\n"
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "Exact match of the communities")
8434
8435ALIAS (show_bgp_community_exact,
8436 show_bgp_community4_exact_cmd,
8437 "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",
8438 SHOW_STR
8439 BGP_STR
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n"
8457 "Exact match of the communities")
8458
8459ALIAS (show_bgp_community_exact,
8460 show_bgp_ipv6_community4_exact_cmd,
8461 "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",
8462 SHOW_STR
8463 BGP_STR
8464 "Address family\n"
8465 "Display routes matching the communities\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n"
8470 "community number\n"
8471 "Do not send outside local AS (well-known community)\n"
8472 "Do not advertise to any peer (well-known community)\n"
8473 "Do not export to next AS (well-known community)\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n"
8482 "Exact match of the communities")
8483
8484/* old command */
8485DEFUN (show_ipv6_bgp_community_exact,
8486 show_ipv6_bgp_community_exact_cmd,
8487 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8488 SHOW_STR
8489 IPV6_STR
8490 BGP_STR
8491 "Display routes matching the communities\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "Exact match of the communities")
8497{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008498 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008499}
8500
8501/* old command */
8502ALIAS (show_ipv6_bgp_community_exact,
8503 show_ipv6_bgp_community2_exact_cmd,
8504 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8505 SHOW_STR
8506 IPV6_STR
8507 BGP_STR
8508 "Display routes matching the communities\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "Exact match of the communities")
8518
8519/* old command */
8520ALIAS (show_ipv6_bgp_community_exact,
8521 show_ipv6_bgp_community3_exact_cmd,
8522 "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",
8523 SHOW_STR
8524 IPV6_STR
8525 BGP_STR
8526 "Display routes matching the communities\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n"
8539 "Exact match of the communities")
8540
8541/* old command */
8542ALIAS (show_ipv6_bgp_community_exact,
8543 show_ipv6_bgp_community4_exact_cmd,
8544 "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",
8545 SHOW_STR
8546 IPV6_STR
8547 BGP_STR
8548 "Display routes matching the communities\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "community number\n"
8558 "Do not send outside local AS (well-known community)\n"
8559 "Do not advertise to any peer (well-known community)\n"
8560 "Do not export to next AS (well-known community)\n"
8561 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "Exact match of the communities")
8566
8567/* old command */
8568DEFUN (show_ipv6_mbgp_community,
8569 show_ipv6_mbgp_community_cmd,
8570 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8571 SHOW_STR
8572 IPV6_STR
8573 MBGP_STR
8574 "Display routes matching the communities\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n")
8579{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008580 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008581}
8582
8583/* old command */
8584ALIAS (show_ipv6_mbgp_community,
8585 show_ipv6_mbgp_community2_cmd,
8586 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8587 SHOW_STR
8588 IPV6_STR
8589 MBGP_STR
8590 "Display routes matching the communities\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "community number\n"
8596 "Do not send outside local AS (well-known community)\n"
8597 "Do not advertise to any peer (well-known community)\n"
8598 "Do not export to next AS (well-known community)\n")
8599
8600/* old command */
8601ALIAS (show_ipv6_mbgp_community,
8602 show_ipv6_mbgp_community3_cmd,
8603 "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)",
8604 SHOW_STR
8605 IPV6_STR
8606 MBGP_STR
8607 "Display routes matching the communities\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n")
8620
8621/* old command */
8622ALIAS (show_ipv6_mbgp_community,
8623 show_ipv6_mbgp_community4_cmd,
8624 "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)",
8625 SHOW_STR
8626 IPV6_STR
8627 MBGP_STR
8628 "Display routes matching the communities\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "community number\n"
8642 "Do not send outside local AS (well-known community)\n"
8643 "Do not advertise to any peer (well-known community)\n"
8644 "Do not export to next AS (well-known community)\n")
8645
8646/* old command */
8647DEFUN (show_ipv6_mbgp_community_exact,
8648 show_ipv6_mbgp_community_exact_cmd,
8649 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8650 SHOW_STR
8651 IPV6_STR
8652 MBGP_STR
8653 "Display routes matching the communities\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "Exact match of the communities")
8659{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008660 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008661}
8662
8663/* old command */
8664ALIAS (show_ipv6_mbgp_community_exact,
8665 show_ipv6_mbgp_community2_exact_cmd,
8666 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8667 SHOW_STR
8668 IPV6_STR
8669 MBGP_STR
8670 "Display routes matching the communities\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "Exact match of the communities")
8680
8681/* old command */
8682ALIAS (show_ipv6_mbgp_community_exact,
8683 show_ipv6_mbgp_community3_exact_cmd,
8684 "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",
8685 SHOW_STR
8686 IPV6_STR
8687 MBGP_STR
8688 "Display routes matching the communities\n"
8689 "community number\n"
8690 "Do not send outside local AS (well-known community)\n"
8691 "Do not advertise to any peer (well-known community)\n"
8692 "Do not export to next AS (well-known community)\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n"
8701 "Exact match of the communities")
8702
8703/* old command */
8704ALIAS (show_ipv6_mbgp_community_exact,
8705 show_ipv6_mbgp_community4_exact_cmd,
8706 "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",
8707 SHOW_STR
8708 IPV6_STR
8709 MBGP_STR
8710 "Display routes matching the communities\n"
8711 "community number\n"
8712 "Do not send outside local AS (well-known community)\n"
8713 "Do not advertise to any peer (well-known community)\n"
8714 "Do not export to next AS (well-known community)\n"
8715 "community number\n"
8716 "Do not send outside local AS (well-known community)\n"
8717 "Do not advertise to any peer (well-known community)\n"
8718 "Do not export to next AS (well-known community)\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n"
8723 "community number\n"
8724 "Do not send outside local AS (well-known community)\n"
8725 "Do not advertise to any peer (well-known community)\n"
8726 "Do not export to next AS (well-known community)\n"
8727 "Exact match of the communities")
8728#endif /* HAVE_IPV6 */
8729
paul94f2b392005-06-28 12:44:16 +00008730static int
paulfd79ac92004-10-13 05:06:08 +00008731bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008732 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008733{
8734 struct community_list *list;
8735
hassofee6e4e2005-02-02 16:29:31 +00008736 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008737 if (list == NULL)
8738 {
8739 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8740 VTY_NEWLINE);
8741 return CMD_WARNING;
8742 }
8743
ajs5a646652004-11-05 01:25:55 +00008744 return bgp_show (vty, NULL, afi, safi,
8745 (exact ? bgp_show_type_community_list_exact :
8746 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008747}
8748
8749DEFUN (show_ip_bgp_community_list,
8750 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008751 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008752 SHOW_STR
8753 IP_STR
8754 BGP_STR
8755 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008756 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008757 "community-list name\n")
8758{
8759 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8760}
8761
8762DEFUN (show_ip_bgp_ipv4_community_list,
8763 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008764 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008765 SHOW_STR
8766 IP_STR
8767 BGP_STR
8768 "Address family\n"
8769 "Address Family modifier\n"
8770 "Address Family modifier\n"
8771 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008772 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008773 "community-list name\n")
8774{
8775 if (strncmp (argv[0], "m", 1) == 0)
8776 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8777
8778 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8779}
8780
8781DEFUN (show_ip_bgp_community_list_exact,
8782 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008783 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008784 SHOW_STR
8785 IP_STR
8786 BGP_STR
8787 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008788 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008789 "community-list name\n"
8790 "Exact match of the communities\n")
8791{
8792 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8793}
8794
8795DEFUN (show_ip_bgp_ipv4_community_list_exact,
8796 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008797 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008798 SHOW_STR
8799 IP_STR
8800 BGP_STR
8801 "Address family\n"
8802 "Address Family modifier\n"
8803 "Address Family modifier\n"
8804 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008805 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008806 "community-list name\n"
8807 "Exact match of the communities\n")
8808{
8809 if (strncmp (argv[0], "m", 1) == 0)
8810 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8811
8812 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8813}
8814
8815#ifdef HAVE_IPV6
8816DEFUN (show_bgp_community_list,
8817 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008818 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008819 SHOW_STR
8820 BGP_STR
8821 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008822 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008823 "community-list name\n")
8824{
8825 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8826}
8827
8828ALIAS (show_bgp_community_list,
8829 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008830 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008831 SHOW_STR
8832 BGP_STR
8833 "Address family\n"
8834 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008835 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008836 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008837
8838/* old command */
8839DEFUN (show_ipv6_bgp_community_list,
8840 show_ipv6_bgp_community_list_cmd,
8841 "show ipv6 bgp community-list WORD",
8842 SHOW_STR
8843 IPV6_STR
8844 BGP_STR
8845 "Display routes matching the community-list\n"
8846 "community-list name\n")
8847{
8848 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8849}
8850
8851/* old command */
8852DEFUN (show_ipv6_mbgp_community_list,
8853 show_ipv6_mbgp_community_list_cmd,
8854 "show ipv6 mbgp community-list WORD",
8855 SHOW_STR
8856 IPV6_STR
8857 MBGP_STR
8858 "Display routes matching the community-list\n"
8859 "community-list name\n")
8860{
8861 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8862}
8863
8864DEFUN (show_bgp_community_list_exact,
8865 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008866 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008867 SHOW_STR
8868 BGP_STR
8869 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008870 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008871 "community-list name\n"
8872 "Exact match of the communities\n")
8873{
8874 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8875}
8876
8877ALIAS (show_bgp_community_list_exact,
8878 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008879 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008880 SHOW_STR
8881 BGP_STR
8882 "Address family\n"
8883 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008884 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008885 "community-list name\n"
8886 "Exact match of the communities\n")
8887
8888/* old command */
8889DEFUN (show_ipv6_bgp_community_list_exact,
8890 show_ipv6_bgp_community_list_exact_cmd,
8891 "show ipv6 bgp community-list WORD exact-match",
8892 SHOW_STR
8893 IPV6_STR
8894 BGP_STR
8895 "Display routes matching the community-list\n"
8896 "community-list name\n"
8897 "Exact match of the communities\n")
8898{
8899 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8900}
8901
8902/* old command */
8903DEFUN (show_ipv6_mbgp_community_list_exact,
8904 show_ipv6_mbgp_community_list_exact_cmd,
8905 "show ipv6 mbgp community-list WORD exact-match",
8906 SHOW_STR
8907 IPV6_STR
8908 MBGP_STR
8909 "Display routes matching the community-list\n"
8910 "community-list name\n"
8911 "Exact match of the communities\n")
8912{
8913 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8914}
8915#endif /* HAVE_IPV6 */
8916
paul94f2b392005-06-28 12:44:16 +00008917static int
paulfd79ac92004-10-13 05:06:08 +00008918bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008919 safi_t safi, enum bgp_show_type type)
8920{
8921 int ret;
8922 struct prefix *p;
8923
8924 p = prefix_new();
8925
8926 ret = str2prefix (prefix, p);
8927 if (! ret)
8928 {
8929 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8930 return CMD_WARNING;
8931 }
8932
ajs5a646652004-11-05 01:25:55 +00008933 ret = bgp_show (vty, NULL, afi, safi, type, p);
8934 prefix_free(p);
8935 return ret;
paul718e3742002-12-13 20:15:29 +00008936}
8937
8938DEFUN (show_ip_bgp_prefix_longer,
8939 show_ip_bgp_prefix_longer_cmd,
8940 "show ip bgp A.B.C.D/M longer-prefixes",
8941 SHOW_STR
8942 IP_STR
8943 BGP_STR
8944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8945 "Display route and more specific routes\n")
8946{
8947 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8948 bgp_show_type_prefix_longer);
8949}
8950
8951DEFUN (show_ip_bgp_flap_prefix_longer,
8952 show_ip_bgp_flap_prefix_longer_cmd,
8953 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8954 SHOW_STR
8955 IP_STR
8956 BGP_STR
8957 "Display flap statistics of routes\n"
8958 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8959 "Display route and more specific routes\n")
8960{
8961 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8962 bgp_show_type_flap_prefix_longer);
8963}
8964
8965DEFUN (show_ip_bgp_ipv4_prefix_longer,
8966 show_ip_bgp_ipv4_prefix_longer_cmd,
8967 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8968 SHOW_STR
8969 IP_STR
8970 BGP_STR
8971 "Address family\n"
8972 "Address Family modifier\n"
8973 "Address Family modifier\n"
8974 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8975 "Display route and more specific routes\n")
8976{
8977 if (strncmp (argv[0], "m", 1) == 0)
8978 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8979 bgp_show_type_prefix_longer);
8980
8981 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8982 bgp_show_type_prefix_longer);
8983}
8984
8985DEFUN (show_ip_bgp_flap_address,
8986 show_ip_bgp_flap_address_cmd,
8987 "show ip bgp flap-statistics A.B.C.D",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Display flap statistics of routes\n"
8992 "Network in the BGP routing table to display\n")
8993{
8994 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8995 bgp_show_type_flap_address);
8996}
8997
8998DEFUN (show_ip_bgp_flap_prefix,
8999 show_ip_bgp_flap_prefix_cmd,
9000 "show ip bgp flap-statistics A.B.C.D/M",
9001 SHOW_STR
9002 IP_STR
9003 BGP_STR
9004 "Display flap statistics of routes\n"
9005 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9006{
9007 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9008 bgp_show_type_flap_prefix);
9009}
9010#ifdef HAVE_IPV6
9011DEFUN (show_bgp_prefix_longer,
9012 show_bgp_prefix_longer_cmd,
9013 "show bgp X:X::X:X/M longer-prefixes",
9014 SHOW_STR
9015 BGP_STR
9016 "IPv6 prefix <network>/<length>\n"
9017 "Display route and more specific routes\n")
9018{
9019 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9020 bgp_show_type_prefix_longer);
9021}
9022
9023ALIAS (show_bgp_prefix_longer,
9024 show_bgp_ipv6_prefix_longer_cmd,
9025 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9026 SHOW_STR
9027 BGP_STR
9028 "Address family\n"
9029 "IPv6 prefix <network>/<length>\n"
9030 "Display route and more specific routes\n")
9031
9032/* old command */
9033DEFUN (show_ipv6_bgp_prefix_longer,
9034 show_ipv6_bgp_prefix_longer_cmd,
9035 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9036 SHOW_STR
9037 IPV6_STR
9038 BGP_STR
9039 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9040 "Display route and more specific routes\n")
9041{
9042 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9043 bgp_show_type_prefix_longer);
9044}
9045
9046/* old command */
9047DEFUN (show_ipv6_mbgp_prefix_longer,
9048 show_ipv6_mbgp_prefix_longer_cmd,
9049 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9050 SHOW_STR
9051 IPV6_STR
9052 MBGP_STR
9053 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9054 "Display route and more specific routes\n")
9055{
9056 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9057 bgp_show_type_prefix_longer);
9058}
9059#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009060
paul94f2b392005-06-28 12:44:16 +00009061static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009062peer_lookup_in_view (struct vty *vty, const char *view_name,
9063 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009064{
9065 int ret;
9066 struct bgp *bgp;
9067 struct peer *peer;
9068 union sockunion su;
9069
9070 /* BGP structure lookup. */
9071 if (view_name)
9072 {
9073 bgp = bgp_lookup_by_name (view_name);
9074 if (! bgp)
9075 {
9076 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9077 return NULL;
9078 }
9079 }
paul5228ad22004-06-04 17:58:18 +00009080 else
paulbb46e942003-10-24 19:02:03 +00009081 {
9082 bgp = bgp_get_default ();
9083 if (! bgp)
9084 {
9085 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9086 return NULL;
9087 }
9088 }
9089
9090 /* Get peer sockunion. */
9091 ret = str2sockunion (ip_str, &su);
9092 if (ret < 0)
9093 {
9094 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9095 return NULL;
9096 }
9097
9098 /* Peer structure lookup. */
9099 peer = peer_lookup (bgp, &su);
9100 if (! peer)
9101 {
9102 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9103 return NULL;
9104 }
9105
9106 return peer;
9107}
Paul Jakma2815e612006-09-14 02:56:07 +00009108
9109enum bgp_stats
9110{
9111 BGP_STATS_MAXBITLEN = 0,
9112 BGP_STATS_RIB,
9113 BGP_STATS_PREFIXES,
9114 BGP_STATS_TOTPLEN,
9115 BGP_STATS_UNAGGREGATEABLE,
9116 BGP_STATS_MAX_AGGREGATEABLE,
9117 BGP_STATS_AGGREGATES,
9118 BGP_STATS_SPACE,
9119 BGP_STATS_ASPATH_COUNT,
9120 BGP_STATS_ASPATH_MAXHOPS,
9121 BGP_STATS_ASPATH_TOTHOPS,
9122 BGP_STATS_ASPATH_MAXSIZE,
9123 BGP_STATS_ASPATH_TOTSIZE,
9124 BGP_STATS_ASN_HIGHEST,
9125 BGP_STATS_MAX,
9126};
paulbb46e942003-10-24 19:02:03 +00009127
Paul Jakma2815e612006-09-14 02:56:07 +00009128static const char *table_stats_strs[] =
9129{
9130 [BGP_STATS_PREFIXES] = "Total Prefixes",
9131 [BGP_STATS_TOTPLEN] = "Average prefix length",
9132 [BGP_STATS_RIB] = "Total Advertisements",
9133 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9134 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9135 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9136 [BGP_STATS_SPACE] = "Address space advertised",
9137 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9138 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9139 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9140 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9141 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9142 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9143 [BGP_STATS_MAX] = NULL,
9144};
9145
9146struct bgp_table_stats
9147{
9148 struct bgp_table *table;
9149 unsigned long long counts[BGP_STATS_MAX];
9150};
9151
9152#if 0
9153#define TALLY_SIGFIG 100000
9154static unsigned long
9155ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9156{
9157 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9158 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9159 unsigned long ret = newtot / count;
9160
9161 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9162 return ret + 1;
9163 else
9164 return ret;
9165}
9166#endif
9167
9168static int
9169bgp_table_stats_walker (struct thread *t)
9170{
9171 struct bgp_node *rn;
9172 struct bgp_node *top;
9173 struct bgp_table_stats *ts = THREAD_ARG (t);
9174 unsigned int space = 0;
9175
Paul Jakma53d9f672006-10-15 23:41:16 +00009176 if (!(top = bgp_table_top (ts->table)))
9177 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009178
9179 switch (top->p.family)
9180 {
9181 case AF_INET:
9182 space = IPV4_MAX_BITLEN;
9183 break;
9184 case AF_INET6:
9185 space = IPV6_MAX_BITLEN;
9186 break;
9187 }
9188
9189 ts->counts[BGP_STATS_MAXBITLEN] = space;
9190
9191 for (rn = top; rn; rn = bgp_route_next (rn))
9192 {
9193 struct bgp_info *ri;
9194 struct bgp_node *prn = rn->parent;
9195 unsigned int rinum = 0;
9196
9197 if (rn == top)
9198 continue;
9199
9200 if (!rn->info)
9201 continue;
9202
9203 ts->counts[BGP_STATS_PREFIXES]++;
9204 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9205
9206#if 0
9207 ts->counts[BGP_STATS_AVGPLEN]
9208 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9209 ts->counts[BGP_STATS_AVGPLEN],
9210 rn->p.prefixlen);
9211#endif
9212
9213 /* check if the prefix is included by any other announcements */
9214 while (prn && !prn->info)
9215 prn = prn->parent;
9216
9217 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009218 {
9219 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9220 /* announced address space */
9221 if (space)
9222 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9223 }
Paul Jakma2815e612006-09-14 02:56:07 +00009224 else if (prn->info)
9225 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9226
Paul Jakma2815e612006-09-14 02:56:07 +00009227 for (ri = rn->info; ri; ri = ri->next)
9228 {
9229 rinum++;
9230 ts->counts[BGP_STATS_RIB]++;
9231
9232 if (ri->attr &&
9233 (CHECK_FLAG (ri->attr->flag,
9234 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9235 ts->counts[BGP_STATS_AGGREGATES]++;
9236
9237 /* as-path stats */
9238 if (ri->attr && ri->attr->aspath)
9239 {
9240 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9241 unsigned int size = aspath_size (ri->attr->aspath);
9242 as_t highest = aspath_highest (ri->attr->aspath);
9243
9244 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9245
9246 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9247 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9248
9249 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9250 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9251
9252 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9253 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9254#if 0
9255 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9256 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9257 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9258 hops);
9259 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9260 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9261 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9262 size);
9263#endif
9264 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9265 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9266 }
9267 }
9268 }
9269 return 0;
9270}
9271
9272static int
9273bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9274{
9275 struct bgp_table_stats ts;
9276 unsigned int i;
9277
9278 if (!bgp->rib[afi][safi])
9279 {
9280 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9281 return CMD_WARNING;
9282 }
9283
9284 memset (&ts, 0, sizeof (ts));
9285 ts.table = bgp->rib[afi][safi];
9286 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9287
9288 vty_out (vty, "BGP %s RIB statistics%s%s",
9289 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9290
9291 for (i = 0; i < BGP_STATS_MAX; i++)
9292 {
9293 if (!table_stats_strs[i])
9294 continue;
9295
9296 switch (i)
9297 {
9298#if 0
9299 case BGP_STATS_ASPATH_AVGHOPS:
9300 case BGP_STATS_ASPATH_AVGSIZE:
9301 case BGP_STATS_AVGPLEN:
9302 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9303 vty_out (vty, "%12.2f",
9304 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9305 break;
9306#endif
9307 case BGP_STATS_ASPATH_TOTHOPS:
9308 case BGP_STATS_ASPATH_TOTSIZE:
9309 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9310 vty_out (vty, "%12.2f",
9311 ts.counts[i] ?
9312 (float)ts.counts[i] /
9313 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9314 : 0);
9315 break;
9316 case BGP_STATS_TOTPLEN:
9317 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9318 vty_out (vty, "%12.2f",
9319 ts.counts[i] ?
9320 (float)ts.counts[i] /
9321 (float)ts.counts[BGP_STATS_PREFIXES]
9322 : 0);
9323 break;
9324 case BGP_STATS_SPACE:
9325 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9326 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9327 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9328 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009329 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009330 vty_out (vty, "%12.2f%s",
9331 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009332 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009333 VTY_NEWLINE);
9334 vty_out (vty, "%30s: ", "/8 equivalent ");
9335 vty_out (vty, "%12.2f%s",
9336 (float)ts.counts[BGP_STATS_SPACE] /
9337 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9338 VTY_NEWLINE);
9339 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9340 break;
9341 vty_out (vty, "%30s: ", "/24 equivalent ");
9342 vty_out (vty, "%12.2f",
9343 (float)ts.counts[BGP_STATS_SPACE] /
9344 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9345 break;
9346 default:
9347 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9348 vty_out (vty, "%12llu", ts.counts[i]);
9349 }
9350
9351 vty_out (vty, "%s", VTY_NEWLINE);
9352 }
9353 return CMD_SUCCESS;
9354}
9355
9356static int
9357bgp_table_stats_vty (struct vty *vty, const char *name,
9358 const char *afi_str, const char *safi_str)
9359{
9360 struct bgp *bgp;
9361 afi_t afi;
9362 safi_t safi;
9363
9364 if (name)
9365 bgp = bgp_lookup_by_name (name);
9366 else
9367 bgp = bgp_get_default ();
9368
9369 if (!bgp)
9370 {
9371 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9372 return CMD_WARNING;
9373 }
9374 if (strncmp (afi_str, "ipv", 3) == 0)
9375 {
9376 if (strncmp (afi_str, "ipv4", 4) == 0)
9377 afi = AFI_IP;
9378 else if (strncmp (afi_str, "ipv6", 4) == 0)
9379 afi = AFI_IP6;
9380 else
9381 {
9382 vty_out (vty, "%% Invalid address family %s%s",
9383 afi_str, VTY_NEWLINE);
9384 return CMD_WARNING;
9385 }
9386 if (strncmp (safi_str, "m", 1) == 0)
9387 safi = SAFI_MULTICAST;
9388 else if (strncmp (safi_str, "u", 1) == 0)
9389 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009390 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9391 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009392 else
9393 {
9394 vty_out (vty, "%% Invalid subsequent address family %s%s",
9395 safi_str, VTY_NEWLINE);
9396 return CMD_WARNING;
9397 }
9398 }
9399 else
9400 {
9401 vty_out (vty, "%% Invalid address family %s%s",
9402 afi_str, VTY_NEWLINE);
9403 return CMD_WARNING;
9404 }
9405
Paul Jakma2815e612006-09-14 02:56:07 +00009406 return bgp_table_stats (vty, bgp, afi, safi);
9407}
9408
9409DEFUN (show_bgp_statistics,
9410 show_bgp_statistics_cmd,
9411 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9412 SHOW_STR
9413 BGP_STR
9414 "Address family\n"
9415 "Address family\n"
9416 "Address Family modifier\n"
9417 "Address Family modifier\n"
9418 "BGP RIB advertisement statistics\n")
9419{
9420 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9421}
9422
9423ALIAS (show_bgp_statistics,
9424 show_bgp_statistics_vpnv4_cmd,
9425 "show bgp (ipv4) (vpnv4) statistics",
9426 SHOW_STR
9427 BGP_STR
9428 "Address family\n"
9429 "Address Family modifier\n"
9430 "BGP RIB advertisement statistics\n")
9431
9432DEFUN (show_bgp_statistics_view,
9433 show_bgp_statistics_view_cmd,
9434 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9435 SHOW_STR
9436 BGP_STR
9437 "BGP view\n"
9438 "Address family\n"
9439 "Address family\n"
9440 "Address Family modifier\n"
9441 "Address Family modifier\n"
9442 "BGP RIB advertisement statistics\n")
9443{
9444 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9445}
9446
9447ALIAS (show_bgp_statistics_view,
9448 show_bgp_statistics_view_vpnv4_cmd,
9449 "show bgp view WORD (ipv4) (vpnv4) statistics",
9450 SHOW_STR
9451 BGP_STR
9452 "BGP view\n"
9453 "Address family\n"
9454 "Address Family modifier\n"
9455 "BGP RIB advertisement statistics\n")
9456
Paul Jakmaff7924f2006-09-04 01:10:36 +00009457enum bgp_pcounts
9458{
9459 PCOUNT_ADJ_IN = 0,
9460 PCOUNT_DAMPED,
9461 PCOUNT_REMOVED,
9462 PCOUNT_HISTORY,
9463 PCOUNT_STALE,
9464 PCOUNT_VALID,
9465 PCOUNT_ALL,
9466 PCOUNT_COUNTED,
9467 PCOUNT_PFCNT, /* the figure we display to users */
9468 PCOUNT_MAX,
9469};
9470
9471static const char *pcount_strs[] =
9472{
9473 [PCOUNT_ADJ_IN] = "Adj-in",
9474 [PCOUNT_DAMPED] = "Damped",
9475 [PCOUNT_REMOVED] = "Removed",
9476 [PCOUNT_HISTORY] = "History",
9477 [PCOUNT_STALE] = "Stale",
9478 [PCOUNT_VALID] = "Valid",
9479 [PCOUNT_ALL] = "All RIB",
9480 [PCOUNT_COUNTED] = "PfxCt counted",
9481 [PCOUNT_PFCNT] = "Useable",
9482 [PCOUNT_MAX] = NULL,
9483};
9484
Paul Jakma2815e612006-09-14 02:56:07 +00009485struct peer_pcounts
9486{
9487 unsigned int count[PCOUNT_MAX];
9488 const struct peer *peer;
9489 const struct bgp_table *table;
9490};
9491
Paul Jakmaff7924f2006-09-04 01:10:36 +00009492static int
Paul Jakma2815e612006-09-14 02:56:07 +00009493bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009494{
9495 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009496 struct peer_pcounts *pc = THREAD_ARG (t);
9497 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009498
Paul Jakma2815e612006-09-14 02:56:07 +00009499 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009500 {
9501 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009502 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009503
9504 for (ain = rn->adj_in; ain; ain = ain->next)
9505 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009506 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009507
Paul Jakmaff7924f2006-09-04 01:10:36 +00009508 for (ri = rn->info; ri; ri = ri->next)
9509 {
9510 char buf[SU_ADDRSTRLEN];
9511
9512 if (ri->peer != peer)
9513 continue;
9514
Paul Jakma2815e612006-09-14 02:56:07 +00009515 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009516
9517 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009518 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009519 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009520 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009521 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009522 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009523 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009524 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009525 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009526 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009527 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009528 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009529
9530 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9531 {
Paul Jakma2815e612006-09-14 02:56:07 +00009532 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009533 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009534 plog_warn (peer->log,
9535 "%s [pcount] %s/%d is counted but flags 0x%x",
9536 peer->host,
9537 inet_ntop(rn->p.family, &rn->p.u.prefix,
9538 buf, SU_ADDRSTRLEN),
9539 rn->p.prefixlen,
9540 ri->flags);
9541 }
9542 else
9543 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009544 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009545 plog_warn (peer->log,
9546 "%s [pcount] %s/%d not counted but flags 0x%x",
9547 peer->host,
9548 inet_ntop(rn->p.family, &rn->p.u.prefix,
9549 buf, SU_ADDRSTRLEN),
9550 rn->p.prefixlen,
9551 ri->flags);
9552 }
9553 }
9554 }
Paul Jakma2815e612006-09-14 02:56:07 +00009555 return 0;
9556}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009557
Paul Jakma2815e612006-09-14 02:56:07 +00009558static int
9559bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9560{
9561 struct peer_pcounts pcounts = { .peer = peer };
9562 unsigned int i;
9563
9564 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9565 || !peer->bgp->rib[afi][safi])
9566 {
9567 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9568 return CMD_WARNING;
9569 }
9570
9571 memset (&pcounts, 0, sizeof(pcounts));
9572 pcounts.peer = peer;
9573 pcounts.table = peer->bgp->rib[afi][safi];
9574
9575 /* in-place call via thread subsystem so as to record execution time
9576 * stats for the thread-walk (i.e. ensure this can't be blamed on
9577 * on just vty_read()).
9578 */
9579 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9580
Paul Jakmaff7924f2006-09-04 01:10:36 +00009581 vty_out (vty, "Prefix counts for %s, %s%s",
9582 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9583 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9584 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9585 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9586
9587 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009588 vty_out (vty, "%20s: %-10d%s",
9589 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009590
Paul Jakma2815e612006-09-14 02:56:07 +00009591 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009592 {
9593 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9594 peer->host, VTY_NEWLINE);
9595 vty_out (vty, "Please report this bug, with the above command output%s",
9596 VTY_NEWLINE);
9597 }
9598
9599 return CMD_SUCCESS;
9600}
9601
9602DEFUN (show_ip_bgp_neighbor_prefix_counts,
9603 show_ip_bgp_neighbor_prefix_counts_cmd,
9604 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9605 SHOW_STR
9606 IP_STR
9607 BGP_STR
9608 "Detailed information on TCP and BGP neighbor connections\n"
9609 "Neighbor to display information about\n"
9610 "Neighbor to display information about\n"
9611 "Display detailed prefix count information\n")
9612{
9613 struct peer *peer;
9614
9615 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9616 if (! peer)
9617 return CMD_WARNING;
9618
9619 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9620}
9621
9622DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9623 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9624 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9625 SHOW_STR
9626 BGP_STR
9627 "Address family\n"
9628 "Detailed information on TCP and BGP neighbor connections\n"
9629 "Neighbor to display information about\n"
9630 "Neighbor to display information about\n"
9631 "Display detailed prefix count information\n")
9632{
9633 struct peer *peer;
9634
9635 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9636 if (! peer)
9637 return CMD_WARNING;
9638
9639 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9640}
9641
9642DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9643 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9644 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9645 SHOW_STR
9646 IP_STR
9647 BGP_STR
9648 "Address family\n"
9649 "Address Family modifier\n"
9650 "Address Family modifier\n"
9651 "Detailed information on TCP and BGP neighbor connections\n"
9652 "Neighbor to display information about\n"
9653 "Neighbor to display information about\n"
9654 "Display detailed prefix count information\n")
9655{
9656 struct peer *peer;
9657
9658 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9659 if (! peer)
9660 return CMD_WARNING;
9661
9662 if (strncmp (argv[0], "m", 1) == 0)
9663 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9664
9665 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9666}
9667
9668DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9669 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9670 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9671 SHOW_STR
9672 IP_STR
9673 BGP_STR
9674 "Address family\n"
9675 "Address Family modifier\n"
9676 "Address Family modifier\n"
9677 "Detailed information on TCP and BGP neighbor connections\n"
9678 "Neighbor to display information about\n"
9679 "Neighbor to display information about\n"
9680 "Display detailed prefix count information\n")
9681{
9682 struct peer *peer;
9683
9684 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9685 if (! peer)
9686 return CMD_WARNING;
9687
9688 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9689}
9690
9691
paul94f2b392005-06-28 12:44:16 +00009692static void
paul718e3742002-12-13 20:15:29 +00009693show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9694 int in)
9695{
9696 struct bgp_table *table;
9697 struct bgp_adj_in *ain;
9698 struct bgp_adj_out *adj;
9699 unsigned long output_count;
9700 struct bgp_node *rn;
9701 int header1 = 1;
9702 struct bgp *bgp;
9703 int header2 = 1;
9704
paulbb46e942003-10-24 19:02:03 +00009705 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009706
9707 if (! bgp)
9708 return;
9709
9710 table = bgp->rib[afi][safi];
9711
9712 output_count = 0;
9713
9714 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9715 PEER_STATUS_DEFAULT_ORIGINATE))
9716 {
9717 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 +00009718 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9719 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009720
9721 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9722 VTY_NEWLINE, VTY_NEWLINE);
9723 header1 = 0;
9724 }
9725
9726 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9727 if (in)
9728 {
9729 for (ain = rn->adj_in; ain; ain = ain->next)
9730 if (ain->peer == peer)
9731 {
9732 if (header1)
9733 {
9734 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 +00009735 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9736 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009737 header1 = 0;
9738 }
9739 if (header2)
9740 {
9741 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9742 header2 = 0;
9743 }
9744 if (ain->attr)
9745 {
9746 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9747 output_count++;
9748 }
9749 }
9750 }
9751 else
9752 {
9753 for (adj = rn->adj_out; adj; adj = adj->next)
9754 if (adj->peer == peer)
9755 {
9756 if (header1)
9757 {
9758 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 +00009759 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9760 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009761 header1 = 0;
9762 }
9763 if (header2)
9764 {
9765 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9766 header2 = 0;
9767 }
9768 if (adj->attr)
9769 {
9770 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9771 output_count++;
9772 }
9773 }
9774 }
9775
9776 if (output_count != 0)
9777 vty_out (vty, "%sTotal number of prefixes %ld%s",
9778 VTY_NEWLINE, output_count, VTY_NEWLINE);
9779}
9780
paul94f2b392005-06-28 12:44:16 +00009781static int
paulbb46e942003-10-24 19:02:03 +00009782peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9783{
paul718e3742002-12-13 20:15:29 +00009784 if (! peer || ! peer->afc[afi][safi])
9785 {
9786 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9787 return CMD_WARNING;
9788 }
9789
9790 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9791 {
9792 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9793 VTY_NEWLINE);
9794 return CMD_WARNING;
9795 }
9796
9797 show_adj_route (vty, peer, afi, safi, in);
9798
9799 return CMD_SUCCESS;
9800}
9801
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009802DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9803 show_ip_bgp_view_neighbor_advertised_route_cmd,
9804 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9805 SHOW_STR
9806 IP_STR
9807 BGP_STR
9808 "BGP view\n"
9809 "View name\n"
9810 "Detailed information on TCP and BGP neighbor connections\n"
9811 "Neighbor to display information about\n"
9812 "Neighbor to display information about\n"
9813 "Display the routes advertised to a BGP neighbor\n")
9814{
9815 struct peer *peer;
9816
9817 if (argc == 2)
9818 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9819 else
9820 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9821
9822 if (! peer)
9823 return CMD_WARNING;
9824
9825 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9826}
9827
9828ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009829 show_ip_bgp_neighbor_advertised_route_cmd,
9830 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9831 SHOW_STR
9832 IP_STR
9833 BGP_STR
9834 "Detailed information on TCP and BGP neighbor connections\n"
9835 "Neighbor to display information about\n"
9836 "Neighbor to display information about\n"
9837 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009838
9839DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9840 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9841 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9842 SHOW_STR
9843 IP_STR
9844 BGP_STR
9845 "Address family\n"
9846 "Address Family modifier\n"
9847 "Address Family modifier\n"
9848 "Detailed information on TCP and BGP neighbor connections\n"
9849 "Neighbor to display information about\n"
9850 "Neighbor to display information about\n"
9851 "Display the routes advertised to a BGP neighbor\n")
9852{
paulbb46e942003-10-24 19:02:03 +00009853 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009854
paulbb46e942003-10-24 19:02:03 +00009855 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9856 if (! peer)
9857 return CMD_WARNING;
9858
9859 if (strncmp (argv[0], "m", 1) == 0)
9860 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9861
9862 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009863}
9864
9865#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009866DEFUN (show_bgp_view_neighbor_advertised_route,
9867 show_bgp_view_neighbor_advertised_route_cmd,
9868 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9869 SHOW_STR
9870 BGP_STR
9871 "BGP view\n"
9872 "View name\n"
9873 "Detailed information on TCP and BGP neighbor connections\n"
9874 "Neighbor to display information about\n"
9875 "Neighbor to display information about\n"
9876 "Display the routes advertised to a BGP neighbor\n")
9877{
9878 struct peer *peer;
9879
9880 if (argc == 2)
9881 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9882 else
9883 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9884
9885 if (! peer)
9886 return CMD_WARNING;
9887
9888 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9889}
9890
9891ALIAS (show_bgp_view_neighbor_advertised_route,
9892 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9893 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9894 SHOW_STR
9895 BGP_STR
9896 "BGP view\n"
9897 "View name\n"
9898 "Address family\n"
9899 "Detailed information on TCP and BGP neighbor connections\n"
9900 "Neighbor to display information about\n"
9901 "Neighbor to display information about\n"
9902 "Display the routes advertised to a BGP neighbor\n")
9903
9904DEFUN (show_bgp_view_neighbor_received_routes,
9905 show_bgp_view_neighbor_received_routes_cmd,
9906 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9907 SHOW_STR
9908 BGP_STR
9909 "BGP view\n"
9910 "View name\n"
9911 "Detailed information on TCP and BGP neighbor connections\n"
9912 "Neighbor to display information about\n"
9913 "Neighbor to display information about\n"
9914 "Display the received routes from neighbor\n")
9915{
9916 struct peer *peer;
9917
9918 if (argc == 2)
9919 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9920 else
9921 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9922
9923 if (! peer)
9924 return CMD_WARNING;
9925
9926 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9927}
9928
9929ALIAS (show_bgp_view_neighbor_received_routes,
9930 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9931 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9932 SHOW_STR
9933 BGP_STR
9934 "BGP view\n"
9935 "View name\n"
9936 "Address family\n"
9937 "Detailed information on TCP and BGP neighbor connections\n"
9938 "Neighbor to display information about\n"
9939 "Neighbor to display information about\n"
9940 "Display the received routes from neighbor\n")
9941
9942ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009943 show_bgp_neighbor_advertised_route_cmd,
9944 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9945 SHOW_STR
9946 BGP_STR
9947 "Detailed information on TCP and BGP neighbor connections\n"
9948 "Neighbor to display information about\n"
9949 "Neighbor to display information about\n"
9950 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009951
9952ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009953 show_bgp_ipv6_neighbor_advertised_route_cmd,
9954 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9955 SHOW_STR
9956 BGP_STR
9957 "Address family\n"
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display the routes advertised to a BGP neighbor\n")
9962
9963/* old command */
paulbb46e942003-10-24 19:02:03 +00009964ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009965 ipv6_bgp_neighbor_advertised_route_cmd,
9966 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9967 SHOW_STR
9968 IPV6_STR
9969 BGP_STR
9970 "Detailed information on TCP and BGP neighbor connections\n"
9971 "Neighbor to display information about\n"
9972 "Neighbor to display information about\n"
9973 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009974
paul718e3742002-12-13 20:15:29 +00009975/* old command */
9976DEFUN (ipv6_mbgp_neighbor_advertised_route,
9977 ipv6_mbgp_neighbor_advertised_route_cmd,
9978 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9979 SHOW_STR
9980 IPV6_STR
9981 MBGP_STR
9982 "Detailed information on TCP and BGP neighbor connections\n"
9983 "Neighbor to display information about\n"
9984 "Neighbor to display information about\n"
9985 "Display the routes advertised to a BGP neighbor\n")
9986{
paulbb46e942003-10-24 19:02:03 +00009987 struct peer *peer;
9988
9989 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9990 if (! peer)
9991 return CMD_WARNING;
9992
9993 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009994}
9995#endif /* HAVE_IPV6 */
9996
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009997DEFUN (show_ip_bgp_view_neighbor_received_routes,
9998 show_ip_bgp_view_neighbor_received_routes_cmd,
9999 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10000 SHOW_STR
10001 IP_STR
10002 BGP_STR
10003 "BGP view\n"
10004 "View name\n"
10005 "Detailed information on TCP and BGP neighbor connections\n"
10006 "Neighbor to display information about\n"
10007 "Neighbor to display information about\n"
10008 "Display the received routes from neighbor\n")
10009{
10010 struct peer *peer;
10011
10012 if (argc == 2)
10013 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10014 else
10015 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10016
10017 if (! peer)
10018 return CMD_WARNING;
10019
10020 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10021}
10022
10023ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010024 show_ip_bgp_neighbor_received_routes_cmd,
10025 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10026 SHOW_STR
10027 IP_STR
10028 BGP_STR
10029 "Detailed information on TCP and BGP neighbor connections\n"
10030 "Neighbor to display information about\n"
10031 "Neighbor to display information about\n"
10032 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010033
10034DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10035 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10036 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10037 SHOW_STR
10038 IP_STR
10039 BGP_STR
10040 "Address family\n"
10041 "Address Family modifier\n"
10042 "Address Family modifier\n"
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display the received routes from neighbor\n")
10047{
paulbb46e942003-10-24 19:02:03 +000010048 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010049
paulbb46e942003-10-24 19:02:03 +000010050 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10051 if (! peer)
10052 return CMD_WARNING;
10053
10054 if (strncmp (argv[0], "m", 1) == 0)
10055 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10056
10057 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010058}
10059
Michael Lambert95cbbd22010-07-23 14:43:04 -040010060DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10061 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10062#ifdef HAVE_IPV6
10063 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10064#else
10065 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10066#endif
10067 SHOW_STR
10068 BGP_STR
10069 "BGP view\n"
10070 "BGP view name\n"
10071 "Address family\n"
10072#ifdef HAVE_IPV6
10073 "Address family\n"
10074#endif
10075 "Address family modifier\n"
10076 "Address family modifier\n"
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the advertised routes to neighbor\n"
10081 "Display the received routes from neighbor\n")
10082{
10083 int afi;
10084 int safi;
10085 int in;
10086 struct peer *peer;
10087
10088#ifdef HAVE_IPV6
10089 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10090#else
10091 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10092#endif
10093
10094 if (! peer)
10095 return CMD_WARNING;
10096
10097#ifdef HAVE_IPV6
10098 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10099 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10100 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10101#else
10102 afi = AFI_IP;
10103 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10104 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10105#endif
10106
10107 return peer_adj_routes (vty, peer, afi, safi, in);
10108}
10109
paul718e3742002-12-13 20:15:29 +000010110DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10111 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10112 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10113 SHOW_STR
10114 IP_STR
10115 BGP_STR
10116 "Detailed information on TCP and BGP neighbor connections\n"
10117 "Neighbor to display information about\n"
10118 "Neighbor to display information about\n"
10119 "Display information received from a BGP neighbor\n"
10120 "Display the prefixlist filter\n")
10121{
10122 char name[BUFSIZ];
10123 union sockunion *su;
10124 struct peer *peer;
10125 int count;
10126
10127 su = sockunion_str2su (argv[0]);
10128 if (su == NULL)
10129 return CMD_WARNING;
10130
10131 peer = peer_lookup (NULL, su);
10132 if (! peer)
10133 return CMD_WARNING;
10134
10135 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10136 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10137 if (count)
10138 {
10139 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10140 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10141 }
10142
10143 return CMD_SUCCESS;
10144}
10145
10146DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10147 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10148 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "Address family\n"
10153 "Address Family modifier\n"
10154 "Address Family modifier\n"
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display information received from a BGP neighbor\n"
10159 "Display the prefixlist filter\n")
10160{
10161 char name[BUFSIZ];
10162 union sockunion *su;
10163 struct peer *peer;
10164 int count;
10165
10166 su = sockunion_str2su (argv[1]);
10167 if (su == NULL)
10168 return CMD_WARNING;
10169
10170 peer = peer_lookup (NULL, su);
10171 if (! peer)
10172 return CMD_WARNING;
10173
10174 if (strncmp (argv[0], "m", 1) == 0)
10175 {
10176 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10177 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10178 if (count)
10179 {
10180 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10181 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10182 }
10183 }
10184 else
10185 {
10186 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10187 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10188 if (count)
10189 {
10190 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10191 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10192 }
10193 }
10194
10195 return CMD_SUCCESS;
10196}
10197
10198
10199#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010200ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010201 show_bgp_neighbor_received_routes_cmd,
10202 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10203 SHOW_STR
10204 BGP_STR
10205 "Detailed information on TCP and BGP neighbor connections\n"
10206 "Neighbor to display information about\n"
10207 "Neighbor to display information about\n"
10208 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010209
paulbb46e942003-10-24 19:02:03 +000010210ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010211 show_bgp_ipv6_neighbor_received_routes_cmd,
10212 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10213 SHOW_STR
10214 BGP_STR
10215 "Address family\n"
10216 "Detailed information on TCP and BGP neighbor connections\n"
10217 "Neighbor to display information about\n"
10218 "Neighbor to display information about\n"
10219 "Display the received routes from neighbor\n")
10220
10221DEFUN (show_bgp_neighbor_received_prefix_filter,
10222 show_bgp_neighbor_received_prefix_filter_cmd,
10223 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10224 SHOW_STR
10225 BGP_STR
10226 "Detailed information on TCP and BGP neighbor connections\n"
10227 "Neighbor to display information about\n"
10228 "Neighbor to display information about\n"
10229 "Display information received from a BGP neighbor\n"
10230 "Display the prefixlist filter\n")
10231{
10232 char name[BUFSIZ];
10233 union sockunion *su;
10234 struct peer *peer;
10235 int count;
10236
10237 su = sockunion_str2su (argv[0]);
10238 if (su == NULL)
10239 return CMD_WARNING;
10240
10241 peer = peer_lookup (NULL, su);
10242 if (! peer)
10243 return CMD_WARNING;
10244
10245 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10246 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10247 if (count)
10248 {
10249 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10250 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10251 }
10252
10253 return CMD_SUCCESS;
10254}
10255
10256ALIAS (show_bgp_neighbor_received_prefix_filter,
10257 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10258 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10259 SHOW_STR
10260 BGP_STR
10261 "Address family\n"
10262 "Detailed information on TCP and BGP neighbor connections\n"
10263 "Neighbor to display information about\n"
10264 "Neighbor to display information about\n"
10265 "Display information received from a BGP neighbor\n"
10266 "Display the prefixlist filter\n")
10267
10268/* old command */
paulbb46e942003-10-24 19:02:03 +000010269ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010270 ipv6_bgp_neighbor_received_routes_cmd,
10271 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10272 SHOW_STR
10273 IPV6_STR
10274 BGP_STR
10275 "Detailed information on TCP and BGP neighbor connections\n"
10276 "Neighbor to display information about\n"
10277 "Neighbor to display information about\n"
10278 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010279
10280/* old command */
10281DEFUN (ipv6_mbgp_neighbor_received_routes,
10282 ipv6_mbgp_neighbor_received_routes_cmd,
10283 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10284 SHOW_STR
10285 IPV6_STR
10286 MBGP_STR
10287 "Detailed information on TCP and BGP neighbor connections\n"
10288 "Neighbor to display information about\n"
10289 "Neighbor to display information about\n"
10290 "Display the received routes from neighbor\n")
10291{
paulbb46e942003-10-24 19:02:03 +000010292 struct peer *peer;
10293
10294 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10295 if (! peer)
10296 return CMD_WARNING;
10297
10298 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010299}
paulbb46e942003-10-24 19:02:03 +000010300
10301DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10302 show_bgp_view_neighbor_received_prefix_filter_cmd,
10303 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10304 SHOW_STR
10305 BGP_STR
10306 "BGP view\n"
10307 "View name\n"
10308 "Detailed information on TCP and BGP neighbor connections\n"
10309 "Neighbor to display information about\n"
10310 "Neighbor to display information about\n"
10311 "Display information received from a BGP neighbor\n"
10312 "Display the prefixlist filter\n")
10313{
10314 char name[BUFSIZ];
10315 union sockunion *su;
10316 struct peer *peer;
10317 struct bgp *bgp;
10318 int count;
10319
10320 /* BGP structure lookup. */
10321 bgp = bgp_lookup_by_name (argv[0]);
10322 if (bgp == NULL)
10323 {
10324 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
10327
10328 su = sockunion_str2su (argv[1]);
10329 if (su == NULL)
10330 return CMD_WARNING;
10331
10332 peer = peer_lookup (bgp, su);
10333 if (! peer)
10334 return CMD_WARNING;
10335
10336 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10337 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10338 if (count)
10339 {
10340 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10341 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10342 }
10343
10344 return CMD_SUCCESS;
10345}
10346
10347ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10348 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10349 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10350 SHOW_STR
10351 BGP_STR
10352 "BGP view\n"
10353 "View name\n"
10354 "Address family\n"
10355 "Detailed information on TCP and BGP neighbor connections\n"
10356 "Neighbor to display information about\n"
10357 "Neighbor to display information about\n"
10358 "Display information received from a BGP neighbor\n"
10359 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010360#endif /* HAVE_IPV6 */
10361
paul94f2b392005-06-28 12:44:16 +000010362static int
paulbb46e942003-10-24 19:02:03 +000010363bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010364 safi_t safi, enum bgp_show_type type)
10365{
paul718e3742002-12-13 20:15:29 +000010366 if (! peer || ! peer->afc[afi][safi])
10367 {
10368 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010369 return CMD_WARNING;
10370 }
10371
ajs5a646652004-11-05 01:25:55 +000010372 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010373}
10374
10375DEFUN (show_ip_bgp_neighbor_routes,
10376 show_ip_bgp_neighbor_routes_cmd,
10377 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10378 SHOW_STR
10379 IP_STR
10380 BGP_STR
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display routes learned from neighbor\n")
10385{
paulbb46e942003-10-24 19:02:03 +000010386 struct peer *peer;
10387
10388 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10389 if (! peer)
10390 return CMD_WARNING;
10391
10392 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010393 bgp_show_type_neighbor);
10394}
10395
10396DEFUN (show_ip_bgp_neighbor_flap,
10397 show_ip_bgp_neighbor_flap_cmd,
10398 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10399 SHOW_STR
10400 IP_STR
10401 BGP_STR
10402 "Detailed information on TCP and BGP neighbor connections\n"
10403 "Neighbor to display information about\n"
10404 "Neighbor to display information about\n"
10405 "Display flap statistics of the routes learned from neighbor\n")
10406{
paulbb46e942003-10-24 19:02:03 +000010407 struct peer *peer;
10408
10409 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10410 if (! peer)
10411 return CMD_WARNING;
10412
10413 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010414 bgp_show_type_flap_neighbor);
10415}
10416
10417DEFUN (show_ip_bgp_neighbor_damp,
10418 show_ip_bgp_neighbor_damp_cmd,
10419 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10420 SHOW_STR
10421 IP_STR
10422 BGP_STR
10423 "Detailed information on TCP and BGP neighbor connections\n"
10424 "Neighbor to display information about\n"
10425 "Neighbor to display information about\n"
10426 "Display the dampened routes received from neighbor\n")
10427{
paulbb46e942003-10-24 19:02:03 +000010428 struct peer *peer;
10429
10430 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10431 if (! peer)
10432 return CMD_WARNING;
10433
10434 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010435 bgp_show_type_damp_neighbor);
10436}
10437
10438DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10439 show_ip_bgp_ipv4_neighbor_routes_cmd,
10440 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10441 SHOW_STR
10442 IP_STR
10443 BGP_STR
10444 "Address family\n"
10445 "Address Family modifier\n"
10446 "Address Family modifier\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display routes learned from neighbor\n")
10451{
paulbb46e942003-10-24 19:02:03 +000010452 struct peer *peer;
10453
10454 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10455 if (! peer)
10456 return CMD_WARNING;
10457
paul718e3742002-12-13 20:15:29 +000010458 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010459 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010460 bgp_show_type_neighbor);
10461
paulbb46e942003-10-24 19:02:03 +000010462 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010463 bgp_show_type_neighbor);
10464}
paulbb46e942003-10-24 19:02:03 +000010465
paulfee0f4c2004-09-13 05:12:46 +000010466DEFUN (show_ip_bgp_view_rsclient,
10467 show_ip_bgp_view_rsclient_cmd,
10468 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10469 SHOW_STR
10470 IP_STR
10471 BGP_STR
10472 "BGP view\n"
10473 "BGP view name\n"
10474 "Information about Route Server Client\n"
10475 NEIGHBOR_ADDR_STR)
10476{
10477 struct bgp_table *table;
10478 struct peer *peer;
10479
10480 if (argc == 2)
10481 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10482 else
10483 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10484
10485 if (! peer)
10486 return CMD_WARNING;
10487
10488 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10489 {
10490 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10491 VTY_NEWLINE);
10492 return CMD_WARNING;
10493 }
10494
10495 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10496 PEER_FLAG_RSERVER_CLIENT))
10497 {
10498 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10499 VTY_NEWLINE);
10500 return CMD_WARNING;
10501 }
10502
10503 table = peer->rib[AFI_IP][SAFI_UNICAST];
10504
ajs5a646652004-11-05 01:25:55 +000010505 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010506}
10507
10508ALIAS (show_ip_bgp_view_rsclient,
10509 show_ip_bgp_rsclient_cmd,
10510 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10511 SHOW_STR
10512 IP_STR
10513 BGP_STR
10514 "Information about Route Server Client\n"
10515 NEIGHBOR_ADDR_STR)
10516
Michael Lambert95cbbd22010-07-23 14:43:04 -040010517DEFUN (show_bgp_view_ipv4_safi_rsclient,
10518 show_bgp_view_ipv4_safi_rsclient_cmd,
10519 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10520 SHOW_STR
10521 BGP_STR
10522 "BGP view\n"
10523 "BGP view name\n"
10524 "Address family\n"
10525 "Address Family modifier\n"
10526 "Address Family modifier\n"
10527 "Information about Route Server Client\n"
10528 NEIGHBOR_ADDR_STR)
10529{
10530 struct bgp_table *table;
10531 struct peer *peer;
10532 safi_t safi;
10533
10534 if (argc == 3) {
10535 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10536 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10537 } else {
10538 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10539 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10540 }
10541
10542 if (! peer)
10543 return CMD_WARNING;
10544
10545 if (! peer->afc[AFI_IP][safi])
10546 {
10547 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10548 VTY_NEWLINE);
10549 return CMD_WARNING;
10550 }
10551
10552 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10553 PEER_FLAG_RSERVER_CLIENT))
10554 {
10555 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10556 VTY_NEWLINE);
10557 return CMD_WARNING;
10558 }
10559
10560 table = peer->rib[AFI_IP][safi];
10561
10562 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10563}
10564
10565ALIAS (show_bgp_view_ipv4_safi_rsclient,
10566 show_bgp_ipv4_safi_rsclient_cmd,
10567 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10568 SHOW_STR
10569 BGP_STR
10570 "Address family\n"
10571 "Address Family modifier\n"
10572 "Address Family modifier\n"
10573 "Information about Route Server Client\n"
10574 NEIGHBOR_ADDR_STR)
10575
paulfee0f4c2004-09-13 05:12:46 +000010576DEFUN (show_ip_bgp_view_rsclient_route,
10577 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010578 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010579 SHOW_STR
10580 IP_STR
10581 BGP_STR
10582 "BGP view\n"
10583 "BGP view name\n"
10584 "Information about Route Server Client\n"
10585 NEIGHBOR_ADDR_STR
10586 "Network in the BGP routing table to display\n")
10587{
10588 struct bgp *bgp;
10589 struct peer *peer;
10590
10591 /* BGP structure lookup. */
10592 if (argc == 3)
10593 {
10594 bgp = bgp_lookup_by_name (argv[0]);
10595 if (bgp == NULL)
10596 {
10597 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10598 return CMD_WARNING;
10599 }
10600 }
10601 else
10602 {
10603 bgp = bgp_get_default ();
10604 if (bgp == NULL)
10605 {
10606 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10607 return CMD_WARNING;
10608 }
10609 }
10610
10611 if (argc == 3)
10612 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10613 else
10614 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10615
10616 if (! peer)
10617 return CMD_WARNING;
10618
10619 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10620 {
10621 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10622 VTY_NEWLINE);
10623 return CMD_WARNING;
10624}
10625
10626 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10627 PEER_FLAG_RSERVER_CLIENT))
10628 {
10629 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10630 VTY_NEWLINE);
10631 return CMD_WARNING;
10632 }
10633
10634 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10635 (argc == 3) ? argv[2] : argv[1],
10636 AFI_IP, SAFI_UNICAST, NULL, 0);
10637}
10638
10639ALIAS (show_ip_bgp_view_rsclient_route,
10640 show_ip_bgp_rsclient_route_cmd,
10641 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10642 SHOW_STR
10643 IP_STR
10644 BGP_STR
10645 "Information about Route Server Client\n"
10646 NEIGHBOR_ADDR_STR
10647 "Network in the BGP routing table to display\n")
10648
Michael Lambert95cbbd22010-07-23 14:43:04 -040010649DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10650 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10651 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10652 SHOW_STR
10653 BGP_STR
10654 "BGP view\n"
10655 "BGP view name\n"
10656 "Address family\n"
10657 "Address Family modifier\n"
10658 "Address Family modifier\n"
10659 "Information about Route Server Client\n"
10660 NEIGHBOR_ADDR_STR
10661 "Network in the BGP routing table to display\n")
10662{
10663 struct bgp *bgp;
10664 struct peer *peer;
10665 safi_t safi;
10666
10667 /* BGP structure lookup. */
10668 if (argc == 4)
10669 {
10670 bgp = bgp_lookup_by_name (argv[0]);
10671 if (bgp == NULL)
10672 {
10673 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10674 return CMD_WARNING;
10675 }
10676 }
10677 else
10678 {
10679 bgp = bgp_get_default ();
10680 if (bgp == NULL)
10681 {
10682 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10683 return CMD_WARNING;
10684 }
10685 }
10686
10687 if (argc == 4) {
10688 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10689 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10690 } else {
10691 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10692 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10693 }
10694
10695 if (! peer)
10696 return CMD_WARNING;
10697
10698 if (! peer->afc[AFI_IP][safi])
10699 {
10700 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10701 VTY_NEWLINE);
10702 return CMD_WARNING;
10703}
10704
10705 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10706 PEER_FLAG_RSERVER_CLIENT))
10707 {
10708 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10709 VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712
10713 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10714 (argc == 4) ? argv[3] : argv[2],
10715 AFI_IP, safi, NULL, 0);
10716}
10717
10718ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10719 show_bgp_ipv4_safi_rsclient_route_cmd,
10720 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10721 SHOW_STR
10722 BGP_STR
10723 "Address family\n"
10724 "Address Family modifier\n"
10725 "Address Family modifier\n"
10726 "Information about Route Server Client\n"
10727 NEIGHBOR_ADDR_STR
10728 "Network in the BGP routing table to display\n")
10729
paulfee0f4c2004-09-13 05:12:46 +000010730DEFUN (show_ip_bgp_view_rsclient_prefix,
10731 show_ip_bgp_view_rsclient_prefix_cmd,
10732 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10733 SHOW_STR
10734 IP_STR
10735 BGP_STR
10736 "BGP view\n"
10737 "BGP view name\n"
10738 "Information about Route Server Client\n"
10739 NEIGHBOR_ADDR_STR
10740 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10741{
10742 struct bgp *bgp;
10743 struct peer *peer;
10744
10745 /* BGP structure lookup. */
10746 if (argc == 3)
10747 {
10748 bgp = bgp_lookup_by_name (argv[0]);
10749 if (bgp == NULL)
10750 {
10751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10752 return CMD_WARNING;
10753 }
10754 }
10755 else
10756 {
10757 bgp = bgp_get_default ();
10758 if (bgp == NULL)
10759 {
10760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10761 return CMD_WARNING;
10762 }
10763 }
10764
10765 if (argc == 3)
10766 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10767 else
10768 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10769
10770 if (! peer)
10771 return CMD_WARNING;
10772
10773 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10774 {
10775 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10776 VTY_NEWLINE);
10777 return CMD_WARNING;
10778}
10779
10780 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10781 PEER_FLAG_RSERVER_CLIENT))
10782{
10783 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10784 VTY_NEWLINE);
10785 return CMD_WARNING;
10786 }
10787
10788 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10789 (argc == 3) ? argv[2] : argv[1],
10790 AFI_IP, SAFI_UNICAST, NULL, 1);
10791}
10792
10793ALIAS (show_ip_bgp_view_rsclient_prefix,
10794 show_ip_bgp_rsclient_prefix_cmd,
10795 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10796 SHOW_STR
10797 IP_STR
10798 BGP_STR
10799 "Information about Route Server Client\n"
10800 NEIGHBOR_ADDR_STR
10801 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10802
Michael Lambert95cbbd22010-07-23 14:43:04 -040010803DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10804 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10805 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10806 SHOW_STR
10807 BGP_STR
10808 "BGP view\n"
10809 "BGP view name\n"
10810 "Address family\n"
10811 "Address Family modifier\n"
10812 "Address Family modifier\n"
10813 "Information about Route Server Client\n"
10814 NEIGHBOR_ADDR_STR
10815 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10816{
10817 struct bgp *bgp;
10818 struct peer *peer;
10819 safi_t safi;
10820
10821 /* BGP structure lookup. */
10822 if (argc == 4)
10823 {
10824 bgp = bgp_lookup_by_name (argv[0]);
10825 if (bgp == NULL)
10826 {
10827 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10828 return CMD_WARNING;
10829 }
10830 }
10831 else
10832 {
10833 bgp = bgp_get_default ();
10834 if (bgp == NULL)
10835 {
10836 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10837 return CMD_WARNING;
10838 }
10839 }
10840
10841 if (argc == 4) {
10842 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10843 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10844 } else {
10845 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10846 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10847 }
10848
10849 if (! peer)
10850 return CMD_WARNING;
10851
10852 if (! peer->afc[AFI_IP][safi])
10853 {
10854 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10855 VTY_NEWLINE);
10856 return CMD_WARNING;
10857}
10858
10859 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10860 PEER_FLAG_RSERVER_CLIENT))
10861{
10862 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10863 VTY_NEWLINE);
10864 return CMD_WARNING;
10865 }
10866
10867 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10868 (argc == 4) ? argv[3] : argv[2],
10869 AFI_IP, safi, NULL, 1);
10870}
10871
10872ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10873 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10874 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10875 SHOW_STR
10876 BGP_STR
10877 "Address family\n"
10878 "Address Family modifier\n"
10879 "Address Family modifier\n"
10880 "Information about Route Server Client\n"
10881 NEIGHBOR_ADDR_STR
10882 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010883
paul718e3742002-12-13 20:15:29 +000010884#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010885DEFUN (show_bgp_view_neighbor_routes,
10886 show_bgp_view_neighbor_routes_cmd,
10887 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10888 SHOW_STR
10889 BGP_STR
10890 "BGP view\n"
10891 "BGP view name\n"
10892 "Detailed information on TCP and BGP neighbor connections\n"
10893 "Neighbor to display information about\n"
10894 "Neighbor to display information about\n"
10895 "Display routes learned from neighbor\n")
10896{
10897 struct peer *peer;
10898
10899 if (argc == 2)
10900 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10901 else
10902 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10903
10904 if (! peer)
10905 return CMD_WARNING;
10906
10907 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10908 bgp_show_type_neighbor);
10909}
10910
10911ALIAS (show_bgp_view_neighbor_routes,
10912 show_bgp_view_ipv6_neighbor_routes_cmd,
10913 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10914 SHOW_STR
10915 BGP_STR
10916 "BGP view\n"
10917 "BGP view name\n"
10918 "Address family\n"
10919 "Detailed information on TCP and BGP neighbor connections\n"
10920 "Neighbor to display information about\n"
10921 "Neighbor to display information about\n"
10922 "Display routes learned from neighbor\n")
10923
10924DEFUN (show_bgp_view_neighbor_damp,
10925 show_bgp_view_neighbor_damp_cmd,
10926 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10927 SHOW_STR
10928 BGP_STR
10929 "BGP view\n"
10930 "BGP view name\n"
10931 "Detailed information on TCP and BGP neighbor connections\n"
10932 "Neighbor to display information about\n"
10933 "Neighbor to display information about\n"
10934 "Display the dampened routes received from neighbor\n")
10935{
10936 struct peer *peer;
10937
10938 if (argc == 2)
10939 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10940 else
10941 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10942
10943 if (! peer)
10944 return CMD_WARNING;
10945
10946 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10947 bgp_show_type_damp_neighbor);
10948}
10949
10950ALIAS (show_bgp_view_neighbor_damp,
10951 show_bgp_view_ipv6_neighbor_damp_cmd,
10952 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10953 SHOW_STR
10954 BGP_STR
10955 "BGP view\n"
10956 "BGP view name\n"
10957 "Address family\n"
10958 "Detailed information on TCP and BGP neighbor connections\n"
10959 "Neighbor to display information about\n"
10960 "Neighbor to display information about\n"
10961 "Display the dampened routes received from neighbor\n")
10962
10963DEFUN (show_bgp_view_neighbor_flap,
10964 show_bgp_view_neighbor_flap_cmd,
10965 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10966 SHOW_STR
10967 BGP_STR
10968 "BGP view\n"
10969 "BGP view name\n"
10970 "Detailed information on TCP and BGP neighbor connections\n"
10971 "Neighbor to display information about\n"
10972 "Neighbor to display information about\n"
10973 "Display flap statistics of the routes learned from neighbor\n")
10974{
10975 struct peer *peer;
10976
10977 if (argc == 2)
10978 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10979 else
10980 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10981
10982 if (! peer)
10983 return CMD_WARNING;
10984
10985 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10986 bgp_show_type_flap_neighbor);
10987}
10988
10989ALIAS (show_bgp_view_neighbor_flap,
10990 show_bgp_view_ipv6_neighbor_flap_cmd,
10991 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10992 SHOW_STR
10993 BGP_STR
10994 "BGP view\n"
10995 "BGP view name\n"
10996 "Address family\n"
10997 "Detailed information on TCP and BGP neighbor connections\n"
10998 "Neighbor to display information about\n"
10999 "Neighbor to display information about\n"
11000 "Display flap statistics of the routes learned from neighbor\n")
11001
11002ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011003 show_bgp_neighbor_routes_cmd,
11004 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11005 SHOW_STR
11006 BGP_STR
11007 "Detailed information on TCP and BGP neighbor connections\n"
11008 "Neighbor to display information about\n"
11009 "Neighbor to display information about\n"
11010 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011011
paulbb46e942003-10-24 19:02:03 +000011012
11013ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011014 show_bgp_ipv6_neighbor_routes_cmd,
11015 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11016 SHOW_STR
11017 BGP_STR
11018 "Address family\n"
11019 "Detailed information on TCP and BGP neighbor connections\n"
11020 "Neighbor to display information about\n"
11021 "Neighbor to display information about\n"
11022 "Display routes learned from neighbor\n")
11023
11024/* old command */
paulbb46e942003-10-24 19:02:03 +000011025ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011026 ipv6_bgp_neighbor_routes_cmd,
11027 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11028 SHOW_STR
11029 IPV6_STR
11030 BGP_STR
11031 "Detailed information on TCP and BGP neighbor connections\n"
11032 "Neighbor to display information about\n"
11033 "Neighbor to display information about\n"
11034 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011035
11036/* old command */
11037DEFUN (ipv6_mbgp_neighbor_routes,
11038 ipv6_mbgp_neighbor_routes_cmd,
11039 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11040 SHOW_STR
11041 IPV6_STR
11042 MBGP_STR
11043 "Detailed information on TCP and BGP neighbor connections\n"
11044 "Neighbor to display information about\n"
11045 "Neighbor to display information about\n"
11046 "Display routes learned from neighbor\n")
11047{
paulbb46e942003-10-24 19:02:03 +000011048 struct peer *peer;
11049
11050 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11051 if (! peer)
11052 return CMD_WARNING;
11053
11054 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011055 bgp_show_type_neighbor);
11056}
paulbb46e942003-10-24 19:02:03 +000011057
11058ALIAS (show_bgp_view_neighbor_flap,
11059 show_bgp_neighbor_flap_cmd,
11060 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11061 SHOW_STR
11062 BGP_STR
11063 "Detailed information on TCP and BGP neighbor connections\n"
11064 "Neighbor to display information about\n"
11065 "Neighbor to display information about\n"
11066 "Display flap statistics of the routes learned from neighbor\n")
11067
11068ALIAS (show_bgp_view_neighbor_flap,
11069 show_bgp_ipv6_neighbor_flap_cmd,
11070 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11071 SHOW_STR
11072 BGP_STR
11073 "Address family\n"
11074 "Detailed information on TCP and BGP neighbor connections\n"
11075 "Neighbor to display information about\n"
11076 "Neighbor to display information about\n"
11077 "Display flap statistics of the routes learned from neighbor\n")
11078
11079ALIAS (show_bgp_view_neighbor_damp,
11080 show_bgp_neighbor_damp_cmd,
11081 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11082 SHOW_STR
11083 BGP_STR
11084 "Detailed information on TCP and BGP neighbor connections\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor to display information about\n"
11087 "Display the dampened routes received from neighbor\n")
11088
11089ALIAS (show_bgp_view_neighbor_damp,
11090 show_bgp_ipv6_neighbor_damp_cmd,
11091 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11092 SHOW_STR
11093 BGP_STR
11094 "Address family\n"
11095 "Detailed information on TCP and BGP neighbor connections\n"
11096 "Neighbor to display information about\n"
11097 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011098 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011099
11100DEFUN (show_bgp_view_rsclient,
11101 show_bgp_view_rsclient_cmd,
11102 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11103 SHOW_STR
11104 BGP_STR
11105 "BGP view\n"
11106 "BGP view name\n"
11107 "Information about Route Server Client\n"
11108 NEIGHBOR_ADDR_STR)
11109{
11110 struct bgp_table *table;
11111 struct peer *peer;
11112
11113 if (argc == 2)
11114 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11115 else
11116 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11117
11118 if (! peer)
11119 return CMD_WARNING;
11120
11121 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11122 {
11123 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11124 VTY_NEWLINE);
11125 return CMD_WARNING;
11126 }
11127
11128 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11129 PEER_FLAG_RSERVER_CLIENT))
11130 {
11131 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11132 VTY_NEWLINE);
11133 return CMD_WARNING;
11134 }
11135
11136 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11137
ajs5a646652004-11-05 01:25:55 +000011138 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011139}
11140
11141ALIAS (show_bgp_view_rsclient,
11142 show_bgp_rsclient_cmd,
11143 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11144 SHOW_STR
11145 BGP_STR
11146 "Information about Route Server Client\n"
11147 NEIGHBOR_ADDR_STR)
11148
Michael Lambert95cbbd22010-07-23 14:43:04 -040011149DEFUN (show_bgp_view_ipv6_safi_rsclient,
11150 show_bgp_view_ipv6_safi_rsclient_cmd,
11151 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11152 SHOW_STR
11153 BGP_STR
11154 "BGP view\n"
11155 "BGP view name\n"
11156 "Address family\n"
11157 "Address Family modifier\n"
11158 "Address Family modifier\n"
11159 "Information about Route Server Client\n"
11160 NEIGHBOR_ADDR_STR)
11161{
11162 struct bgp_table *table;
11163 struct peer *peer;
11164 safi_t safi;
11165
11166 if (argc == 3) {
11167 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11168 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11169 } else {
11170 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11171 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11172 }
11173
11174 if (! peer)
11175 return CMD_WARNING;
11176
11177 if (! peer->afc[AFI_IP6][safi])
11178 {
11179 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11180 VTY_NEWLINE);
11181 return CMD_WARNING;
11182 }
11183
11184 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11185 PEER_FLAG_RSERVER_CLIENT))
11186 {
11187 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11188 VTY_NEWLINE);
11189 return CMD_WARNING;
11190 }
11191
11192 table = peer->rib[AFI_IP6][safi];
11193
11194 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11195}
11196
11197ALIAS (show_bgp_view_ipv6_safi_rsclient,
11198 show_bgp_ipv6_safi_rsclient_cmd,
11199 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11200 SHOW_STR
11201 BGP_STR
11202 "Address family\n"
11203 "Address Family modifier\n"
11204 "Address Family modifier\n"
11205 "Information about Route Server Client\n"
11206 NEIGHBOR_ADDR_STR)
11207
paulfee0f4c2004-09-13 05:12:46 +000011208DEFUN (show_bgp_view_rsclient_route,
11209 show_bgp_view_rsclient_route_cmd,
11210 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11211 SHOW_STR
11212 BGP_STR
11213 "BGP view\n"
11214 "BGP view name\n"
11215 "Information about Route Server Client\n"
11216 NEIGHBOR_ADDR_STR
11217 "Network in the BGP routing table to display\n")
11218{
11219 struct bgp *bgp;
11220 struct peer *peer;
11221
11222 /* BGP structure lookup. */
11223 if (argc == 3)
11224 {
11225 bgp = bgp_lookup_by_name (argv[0]);
11226 if (bgp == NULL)
11227 {
11228 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11229 return CMD_WARNING;
11230 }
11231 }
11232 else
11233 {
11234 bgp = bgp_get_default ();
11235 if (bgp == NULL)
11236 {
11237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11238 return CMD_WARNING;
11239 }
11240 }
11241
11242 if (argc == 3)
11243 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11244 else
11245 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11246
11247 if (! peer)
11248 return CMD_WARNING;
11249
11250 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11251 {
11252 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11253 VTY_NEWLINE);
11254 return CMD_WARNING;
11255 }
11256
11257 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11258 PEER_FLAG_RSERVER_CLIENT))
11259 {
11260 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11261 VTY_NEWLINE);
11262 return CMD_WARNING;
11263 }
11264
11265 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11266 (argc == 3) ? argv[2] : argv[1],
11267 AFI_IP6, SAFI_UNICAST, NULL, 0);
11268}
11269
11270ALIAS (show_bgp_view_rsclient_route,
11271 show_bgp_rsclient_route_cmd,
11272 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11273 SHOW_STR
11274 BGP_STR
11275 "Information about Route Server Client\n"
11276 NEIGHBOR_ADDR_STR
11277 "Network in the BGP routing table to display\n")
11278
Michael Lambert95cbbd22010-07-23 14:43:04 -040011279DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11280 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11281 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11282 SHOW_STR
11283 BGP_STR
11284 "BGP view\n"
11285 "BGP view name\n"
11286 "Address family\n"
11287 "Address Family modifier\n"
11288 "Address Family modifier\n"
11289 "Information about Route Server Client\n"
11290 NEIGHBOR_ADDR_STR
11291 "Network in the BGP routing table to display\n")
11292{
11293 struct bgp *bgp;
11294 struct peer *peer;
11295 safi_t safi;
11296
11297 /* BGP structure lookup. */
11298 if (argc == 4)
11299 {
11300 bgp = bgp_lookup_by_name (argv[0]);
11301 if (bgp == NULL)
11302 {
11303 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11304 return CMD_WARNING;
11305 }
11306 }
11307 else
11308 {
11309 bgp = bgp_get_default ();
11310 if (bgp == NULL)
11311 {
11312 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11313 return CMD_WARNING;
11314 }
11315 }
11316
11317 if (argc == 4) {
11318 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11319 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11320 } else {
11321 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11322 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11323 }
11324
11325 if (! peer)
11326 return CMD_WARNING;
11327
11328 if (! peer->afc[AFI_IP6][safi])
11329 {
11330 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11331 VTY_NEWLINE);
11332 return CMD_WARNING;
11333}
11334
11335 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11336 PEER_FLAG_RSERVER_CLIENT))
11337 {
11338 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11339 VTY_NEWLINE);
11340 return CMD_WARNING;
11341 }
11342
11343 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11344 (argc == 4) ? argv[3] : argv[2],
11345 AFI_IP6, safi, NULL, 0);
11346}
11347
11348ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11349 show_bgp_ipv6_safi_rsclient_route_cmd,
11350 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11351 SHOW_STR
11352 BGP_STR
11353 "Address family\n"
11354 "Address Family modifier\n"
11355 "Address Family modifier\n"
11356 "Information about Route Server Client\n"
11357 NEIGHBOR_ADDR_STR
11358 "Network in the BGP routing table to display\n")
11359
paulfee0f4c2004-09-13 05:12:46 +000011360DEFUN (show_bgp_view_rsclient_prefix,
11361 show_bgp_view_rsclient_prefix_cmd,
11362 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11363 SHOW_STR
11364 BGP_STR
11365 "BGP view\n"
11366 "BGP view name\n"
11367 "Information about Route Server Client\n"
11368 NEIGHBOR_ADDR_STR
11369 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11370{
11371 struct bgp *bgp;
11372 struct peer *peer;
11373
11374 /* BGP structure lookup. */
11375 if (argc == 3)
11376 {
11377 bgp = bgp_lookup_by_name (argv[0]);
11378 if (bgp == NULL)
11379 {
11380 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11381 return CMD_WARNING;
11382 }
11383 }
11384 else
11385 {
11386 bgp = bgp_get_default ();
11387 if (bgp == NULL)
11388 {
11389 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11390 return CMD_WARNING;
11391 }
11392 }
11393
11394 if (argc == 3)
11395 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11396 else
11397 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11398
11399 if (! peer)
11400 return CMD_WARNING;
11401
11402 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11403 {
11404 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11405 VTY_NEWLINE);
11406 return CMD_WARNING;
11407 }
11408
11409 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11410 PEER_FLAG_RSERVER_CLIENT))
11411 {
11412 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11413 VTY_NEWLINE);
11414 return CMD_WARNING;
11415 }
11416
11417 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11418 (argc == 3) ? argv[2] : argv[1],
11419 AFI_IP6, SAFI_UNICAST, NULL, 1);
11420}
11421
11422ALIAS (show_bgp_view_rsclient_prefix,
11423 show_bgp_rsclient_prefix_cmd,
11424 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11425 SHOW_STR
11426 BGP_STR
11427 "Information about Route Server Client\n"
11428 NEIGHBOR_ADDR_STR
11429 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11430
Michael Lambert95cbbd22010-07-23 14:43:04 -040011431DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11432 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11433 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11434 SHOW_STR
11435 BGP_STR
11436 "BGP view\n"
11437 "BGP view name\n"
11438 "Address family\n"
11439 "Address Family modifier\n"
11440 "Address Family modifier\n"
11441 "Information about Route Server Client\n"
11442 NEIGHBOR_ADDR_STR
11443 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11444{
11445 struct bgp *bgp;
11446 struct peer *peer;
11447 safi_t safi;
11448
11449 /* BGP structure lookup. */
11450 if (argc == 4)
11451 {
11452 bgp = bgp_lookup_by_name (argv[0]);
11453 if (bgp == NULL)
11454 {
11455 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11456 return CMD_WARNING;
11457 }
11458 }
11459 else
11460 {
11461 bgp = bgp_get_default ();
11462 if (bgp == NULL)
11463 {
11464 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467 }
11468
11469 if (argc == 4) {
11470 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11471 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11472 } else {
11473 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11474 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11475 }
11476
11477 if (! peer)
11478 return CMD_WARNING;
11479
11480 if (! peer->afc[AFI_IP6][safi])
11481 {
11482 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11483 VTY_NEWLINE);
11484 return CMD_WARNING;
11485}
11486
11487 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11488 PEER_FLAG_RSERVER_CLIENT))
11489{
11490 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11491 VTY_NEWLINE);
11492 return CMD_WARNING;
11493 }
11494
11495 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11496 (argc == 4) ? argv[3] : argv[2],
11497 AFI_IP6, safi, NULL, 1);
11498}
11499
11500ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11501 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11502 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11503 SHOW_STR
11504 BGP_STR
11505 "Address family\n"
11506 "Address Family modifier\n"
11507 "Address Family modifier\n"
11508 "Information about Route Server Client\n"
11509 NEIGHBOR_ADDR_STR
11510 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11511
paul718e3742002-12-13 20:15:29 +000011512#endif /* HAVE_IPV6 */
11513
11514struct bgp_table *bgp_distance_table;
11515
11516struct bgp_distance
11517{
11518 /* Distance value for the IP source prefix. */
11519 u_char distance;
11520
11521 /* Name of the access-list to be matched. */
11522 char *access_list;
11523};
11524
paul94f2b392005-06-28 12:44:16 +000011525static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011526bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011527{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011528 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011529}
11530
paul94f2b392005-06-28 12:44:16 +000011531static void
paul718e3742002-12-13 20:15:29 +000011532bgp_distance_free (struct bgp_distance *bdistance)
11533{
11534 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11535}
11536
paul94f2b392005-06-28 12:44:16 +000011537static int
paulfd79ac92004-10-13 05:06:08 +000011538bgp_distance_set (struct vty *vty, const char *distance_str,
11539 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011540{
11541 int ret;
11542 struct prefix_ipv4 p;
11543 u_char distance;
11544 struct bgp_node *rn;
11545 struct bgp_distance *bdistance;
11546
11547 ret = str2prefix_ipv4 (ip_str, &p);
11548 if (ret == 0)
11549 {
11550 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553
11554 distance = atoi (distance_str);
11555
11556 /* Get BGP distance node. */
11557 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11558 if (rn->info)
11559 {
11560 bdistance = rn->info;
11561 bgp_unlock_node (rn);
11562 }
11563 else
11564 {
11565 bdistance = bgp_distance_new ();
11566 rn->info = bdistance;
11567 }
11568
11569 /* Set distance value. */
11570 bdistance->distance = distance;
11571
11572 /* Reset access-list configuration. */
11573 if (bdistance->access_list)
11574 {
11575 free (bdistance->access_list);
11576 bdistance->access_list = NULL;
11577 }
11578 if (access_list_str)
11579 bdistance->access_list = strdup (access_list_str);
11580
11581 return CMD_SUCCESS;
11582}
11583
paul94f2b392005-06-28 12:44:16 +000011584static int
paulfd79ac92004-10-13 05:06:08 +000011585bgp_distance_unset (struct vty *vty, const char *distance_str,
11586 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011587{
11588 int ret;
11589 struct prefix_ipv4 p;
11590 u_char distance;
11591 struct bgp_node *rn;
11592 struct bgp_distance *bdistance;
11593
11594 ret = str2prefix_ipv4 (ip_str, &p);
11595 if (ret == 0)
11596 {
11597 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11598 return CMD_WARNING;
11599 }
11600
11601 distance = atoi (distance_str);
11602
11603 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11604 if (! rn)
11605 {
11606 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11607 return CMD_WARNING;
11608 }
11609
11610 bdistance = rn->info;
11611
11612 if (bdistance->access_list)
11613 free (bdistance->access_list);
11614 bgp_distance_free (bdistance);
11615
11616 rn->info = NULL;
11617 bgp_unlock_node (rn);
11618 bgp_unlock_node (rn);
11619
11620 return CMD_SUCCESS;
11621}
11622
paul718e3742002-12-13 20:15:29 +000011623/* Apply BGP information to distance method. */
11624u_char
11625bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11626{
11627 struct bgp_node *rn;
11628 struct prefix_ipv4 q;
11629 struct peer *peer;
11630 struct bgp_distance *bdistance;
11631 struct access_list *alist;
11632 struct bgp_static *bgp_static;
11633
11634 if (! bgp)
11635 return 0;
11636
11637 if (p->family != AF_INET)
11638 return 0;
11639
11640 peer = rinfo->peer;
11641
11642 if (peer->su.sa.sa_family != AF_INET)
11643 return 0;
11644
11645 memset (&q, 0, sizeof (struct prefix_ipv4));
11646 q.family = AF_INET;
11647 q.prefix = peer->su.sin.sin_addr;
11648 q.prefixlen = IPV4_MAX_BITLEN;
11649
11650 /* Check source address. */
11651 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11652 if (rn)
11653 {
11654 bdistance = rn->info;
11655 bgp_unlock_node (rn);
11656
11657 if (bdistance->access_list)
11658 {
11659 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11660 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11661 return bdistance->distance;
11662 }
11663 else
11664 return bdistance->distance;
11665 }
11666
11667 /* Backdoor check. */
11668 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11669 if (rn)
11670 {
11671 bgp_static = rn->info;
11672 bgp_unlock_node (rn);
11673
11674 if (bgp_static->backdoor)
11675 {
11676 if (bgp->distance_local)
11677 return bgp->distance_local;
11678 else
11679 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11680 }
11681 }
11682
11683 if (peer_sort (peer) == BGP_PEER_EBGP)
11684 {
11685 if (bgp->distance_ebgp)
11686 return bgp->distance_ebgp;
11687 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11688 }
11689 else
11690 {
11691 if (bgp->distance_ibgp)
11692 return bgp->distance_ibgp;
11693 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11694 }
11695}
11696
11697DEFUN (bgp_distance,
11698 bgp_distance_cmd,
11699 "distance bgp <1-255> <1-255> <1-255>",
11700 "Define an administrative distance\n"
11701 "BGP distance\n"
11702 "Distance for routes external to the AS\n"
11703 "Distance for routes internal to the AS\n"
11704 "Distance for local routes\n")
11705{
11706 struct bgp *bgp;
11707
11708 bgp = vty->index;
11709
11710 bgp->distance_ebgp = atoi (argv[0]);
11711 bgp->distance_ibgp = atoi (argv[1]);
11712 bgp->distance_local = atoi (argv[2]);
11713 return CMD_SUCCESS;
11714}
11715
11716DEFUN (no_bgp_distance,
11717 no_bgp_distance_cmd,
11718 "no distance bgp <1-255> <1-255> <1-255>",
11719 NO_STR
11720 "Define an administrative distance\n"
11721 "BGP distance\n"
11722 "Distance for routes external to the AS\n"
11723 "Distance for routes internal to the AS\n"
11724 "Distance for local routes\n")
11725{
11726 struct bgp *bgp;
11727
11728 bgp = vty->index;
11729
11730 bgp->distance_ebgp= 0;
11731 bgp->distance_ibgp = 0;
11732 bgp->distance_local = 0;
11733 return CMD_SUCCESS;
11734}
11735
11736ALIAS (no_bgp_distance,
11737 no_bgp_distance2_cmd,
11738 "no distance bgp",
11739 NO_STR
11740 "Define an administrative distance\n"
11741 "BGP distance\n")
11742
11743DEFUN (bgp_distance_source,
11744 bgp_distance_source_cmd,
11745 "distance <1-255> A.B.C.D/M",
11746 "Define an administrative distance\n"
11747 "Administrative distance\n"
11748 "IP source prefix\n")
11749{
11750 bgp_distance_set (vty, argv[0], argv[1], NULL);
11751 return CMD_SUCCESS;
11752}
11753
11754DEFUN (no_bgp_distance_source,
11755 no_bgp_distance_source_cmd,
11756 "no distance <1-255> A.B.C.D/M",
11757 NO_STR
11758 "Define an administrative distance\n"
11759 "Administrative distance\n"
11760 "IP source prefix\n")
11761{
11762 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11763 return CMD_SUCCESS;
11764}
11765
11766DEFUN (bgp_distance_source_access_list,
11767 bgp_distance_source_access_list_cmd,
11768 "distance <1-255> A.B.C.D/M WORD",
11769 "Define an administrative distance\n"
11770 "Administrative distance\n"
11771 "IP source prefix\n"
11772 "Access list name\n")
11773{
11774 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11775 return CMD_SUCCESS;
11776}
11777
11778DEFUN (no_bgp_distance_source_access_list,
11779 no_bgp_distance_source_access_list_cmd,
11780 "no distance <1-255> A.B.C.D/M WORD",
11781 NO_STR
11782 "Define an administrative distance\n"
11783 "Administrative distance\n"
11784 "IP source prefix\n"
11785 "Access list name\n")
11786{
11787 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11788 return CMD_SUCCESS;
11789}
11790
11791DEFUN (bgp_damp_set,
11792 bgp_damp_set_cmd,
11793 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11794 "BGP Specific commands\n"
11795 "Enable route-flap dampening\n"
11796 "Half-life time for the penalty\n"
11797 "Value to start reusing a route\n"
11798 "Value to start suppressing a route\n"
11799 "Maximum duration to suppress a stable route\n")
11800{
11801 struct bgp *bgp;
11802 int half = DEFAULT_HALF_LIFE * 60;
11803 int reuse = DEFAULT_REUSE;
11804 int suppress = DEFAULT_SUPPRESS;
11805 int max = 4 * half;
11806
11807 if (argc == 4)
11808 {
11809 half = atoi (argv[0]) * 60;
11810 reuse = atoi (argv[1]);
11811 suppress = atoi (argv[2]);
11812 max = atoi (argv[3]) * 60;
11813 }
11814 else if (argc == 1)
11815 {
11816 half = atoi (argv[0]) * 60;
11817 max = 4 * half;
11818 }
11819
11820 bgp = vty->index;
11821 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11822 half, reuse, suppress, max);
11823}
11824
11825ALIAS (bgp_damp_set,
11826 bgp_damp_set2_cmd,
11827 "bgp dampening <1-45>",
11828 "BGP Specific commands\n"
11829 "Enable route-flap dampening\n"
11830 "Half-life time for the penalty\n")
11831
11832ALIAS (bgp_damp_set,
11833 bgp_damp_set3_cmd,
11834 "bgp dampening",
11835 "BGP Specific commands\n"
11836 "Enable route-flap dampening\n")
11837
11838DEFUN (bgp_damp_unset,
11839 bgp_damp_unset_cmd,
11840 "no bgp dampening",
11841 NO_STR
11842 "BGP Specific commands\n"
11843 "Enable route-flap dampening\n")
11844{
11845 struct bgp *bgp;
11846
11847 bgp = vty->index;
11848 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11849}
11850
11851ALIAS (bgp_damp_unset,
11852 bgp_damp_unset2_cmd,
11853 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11854 NO_STR
11855 "BGP Specific commands\n"
11856 "Enable route-flap dampening\n"
11857 "Half-life time for the penalty\n"
11858 "Value to start reusing a route\n"
11859 "Value to start suppressing a route\n"
11860 "Maximum duration to suppress a stable route\n")
11861
11862DEFUN (show_ip_bgp_dampened_paths,
11863 show_ip_bgp_dampened_paths_cmd,
11864 "show ip bgp dampened-paths",
11865 SHOW_STR
11866 IP_STR
11867 BGP_STR
11868 "Display paths suppressed due to dampening\n")
11869{
ajs5a646652004-11-05 01:25:55 +000011870 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11871 NULL);
paul718e3742002-12-13 20:15:29 +000011872}
11873
11874DEFUN (show_ip_bgp_flap_statistics,
11875 show_ip_bgp_flap_statistics_cmd,
11876 "show ip bgp flap-statistics",
11877 SHOW_STR
11878 IP_STR
11879 BGP_STR
11880 "Display flap statistics of routes\n")
11881{
ajs5a646652004-11-05 01:25:55 +000011882 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11883 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011884}
11885
11886/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011887static int
paulfd79ac92004-10-13 05:06:08 +000011888bgp_clear_damp_route (struct vty *vty, const char *view_name,
11889 const char *ip_str, afi_t afi, safi_t safi,
11890 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011891{
11892 int ret;
11893 struct prefix match;
11894 struct bgp_node *rn;
11895 struct bgp_node *rm;
11896 struct bgp_info *ri;
11897 struct bgp_info *ri_temp;
11898 struct bgp *bgp;
11899 struct bgp_table *table;
11900
11901 /* BGP structure lookup. */
11902 if (view_name)
11903 {
11904 bgp = bgp_lookup_by_name (view_name);
11905 if (bgp == NULL)
11906 {
11907 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11908 return CMD_WARNING;
11909 }
11910 }
11911 else
11912 {
11913 bgp = bgp_get_default ();
11914 if (bgp == NULL)
11915 {
11916 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11917 return CMD_WARNING;
11918 }
11919 }
11920
11921 /* Check IP address argument. */
11922 ret = str2prefix (ip_str, &match);
11923 if (! ret)
11924 {
11925 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11926 return CMD_WARNING;
11927 }
11928
11929 match.family = afi2family (afi);
11930
11931 if (safi == SAFI_MPLS_VPN)
11932 {
11933 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11934 {
11935 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11936 continue;
11937
11938 if ((table = rn->info) != NULL)
11939 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011940 {
11941 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11942 {
11943 ri = rm->info;
11944 while (ri)
11945 {
11946 if (ri->extra && ri->extra->damp_info)
11947 {
11948 ri_temp = ri->next;
11949 bgp_damp_info_free (ri->extra->damp_info, 1);
11950 ri = ri_temp;
11951 }
11952 else
11953 ri = ri->next;
11954 }
11955 }
11956
11957 bgp_unlock_node (rm);
11958 }
paul718e3742002-12-13 20:15:29 +000011959 }
11960 }
11961 else
11962 {
11963 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011964 {
11965 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11966 {
11967 ri = rn->info;
11968 while (ri)
11969 {
11970 if (ri->extra && ri->extra->damp_info)
11971 {
11972 ri_temp = ri->next;
11973 bgp_damp_info_free (ri->extra->damp_info, 1);
11974 ri = ri_temp;
11975 }
11976 else
11977 ri = ri->next;
11978 }
11979 }
11980
11981 bgp_unlock_node (rn);
11982 }
paul718e3742002-12-13 20:15:29 +000011983 }
11984
11985 return CMD_SUCCESS;
11986}
11987
11988DEFUN (clear_ip_bgp_dampening,
11989 clear_ip_bgp_dampening_cmd,
11990 "clear ip bgp dampening",
11991 CLEAR_STR
11992 IP_STR
11993 BGP_STR
11994 "Clear route flap dampening information\n")
11995{
11996 bgp_damp_info_clean ();
11997 return CMD_SUCCESS;
11998}
11999
12000DEFUN (clear_ip_bgp_dampening_prefix,
12001 clear_ip_bgp_dampening_prefix_cmd,
12002 "clear ip bgp dampening A.B.C.D/M",
12003 CLEAR_STR
12004 IP_STR
12005 BGP_STR
12006 "Clear route flap dampening information\n"
12007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12008{
12009 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12010 SAFI_UNICAST, NULL, 1);
12011}
12012
12013DEFUN (clear_ip_bgp_dampening_address,
12014 clear_ip_bgp_dampening_address_cmd,
12015 "clear ip bgp dampening A.B.C.D",
12016 CLEAR_STR
12017 IP_STR
12018 BGP_STR
12019 "Clear route flap dampening information\n"
12020 "Network to clear damping information\n")
12021{
12022 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12023 SAFI_UNICAST, NULL, 0);
12024}
12025
12026DEFUN (clear_ip_bgp_dampening_address_mask,
12027 clear_ip_bgp_dampening_address_mask_cmd,
12028 "clear ip bgp dampening A.B.C.D A.B.C.D",
12029 CLEAR_STR
12030 IP_STR
12031 BGP_STR
12032 "Clear route flap dampening information\n"
12033 "Network to clear damping information\n"
12034 "Network mask\n")
12035{
12036 int ret;
12037 char prefix_str[BUFSIZ];
12038
12039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12040 if (! ret)
12041 {
12042 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12043 return CMD_WARNING;
12044 }
12045
12046 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12047 SAFI_UNICAST, NULL, 0);
12048}
12049
paul94f2b392005-06-28 12:44:16 +000012050static int
paul718e3742002-12-13 20:15:29 +000012051bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12052 afi_t afi, safi_t safi, int *write)
12053{
12054 struct bgp_node *prn;
12055 struct bgp_node *rn;
12056 struct bgp_table *table;
12057 struct prefix *p;
12058 struct prefix_rd *prd;
12059 struct bgp_static *bgp_static;
12060 u_int32_t label;
12061 char buf[SU_ADDRSTRLEN];
12062 char rdbuf[RD_ADDRSTRLEN];
12063
12064 /* Network configuration. */
12065 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12066 if ((table = prn->info) != NULL)
12067 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12068 if ((bgp_static = rn->info) != NULL)
12069 {
12070 p = &rn->p;
12071 prd = (struct prefix_rd *) &prn->p;
12072
12073 /* "address-family" display. */
12074 bgp_config_write_family_header (vty, afi, safi, write);
12075
12076 /* "network" configuration display. */
12077 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12078 label = decode_label (bgp_static->tag);
12079
12080 vty_out (vty, " network %s/%d rd %s tag %d",
12081 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12082 p->prefixlen,
12083 rdbuf, label);
12084 vty_out (vty, "%s", VTY_NEWLINE);
12085 }
12086 return 0;
12087}
12088
12089/* Configuration of static route announcement and aggregate
12090 information. */
12091int
12092bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12093 afi_t afi, safi_t safi, int *write)
12094{
12095 struct bgp_node *rn;
12096 struct prefix *p;
12097 struct bgp_static *bgp_static;
12098 struct bgp_aggregate *bgp_aggregate;
12099 char buf[SU_ADDRSTRLEN];
12100
12101 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12102 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12103
12104 /* Network configuration. */
12105 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12106 if ((bgp_static = rn->info) != NULL)
12107 {
12108 p = &rn->p;
12109
12110 /* "address-family" display. */
12111 bgp_config_write_family_header (vty, afi, safi, write);
12112
12113 /* "network" configuration display. */
12114 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12115 {
12116 u_int32_t destination;
12117 struct in_addr netmask;
12118
12119 destination = ntohl (p->u.prefix4.s_addr);
12120 masklen2ip (p->prefixlen, &netmask);
12121 vty_out (vty, " network %s",
12122 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12123
12124 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12125 || (IN_CLASSB (destination) && p->prefixlen == 16)
12126 || (IN_CLASSA (destination) && p->prefixlen == 8)
12127 || p->u.prefix4.s_addr == 0)
12128 {
12129 /* Natural mask is not display. */
12130 }
12131 else
12132 vty_out (vty, " mask %s", inet_ntoa (netmask));
12133 }
12134 else
12135 {
12136 vty_out (vty, " network %s/%d",
12137 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12138 p->prefixlen);
12139 }
12140
12141 if (bgp_static->rmap.name)
12142 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012143 else
12144 {
12145 if (bgp_static->backdoor)
12146 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012147 }
paul718e3742002-12-13 20:15:29 +000012148
12149 vty_out (vty, "%s", VTY_NEWLINE);
12150 }
12151
12152 /* Aggregate-address configuration. */
12153 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12154 if ((bgp_aggregate = rn->info) != NULL)
12155 {
12156 p = &rn->p;
12157
12158 /* "address-family" display. */
12159 bgp_config_write_family_header (vty, afi, safi, write);
12160
12161 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12162 {
12163 struct in_addr netmask;
12164
12165 masklen2ip (p->prefixlen, &netmask);
12166 vty_out (vty, " aggregate-address %s %s",
12167 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12168 inet_ntoa (netmask));
12169 }
12170 else
12171 {
12172 vty_out (vty, " aggregate-address %s/%d",
12173 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12174 p->prefixlen);
12175 }
12176
12177 if (bgp_aggregate->as_set)
12178 vty_out (vty, " as-set");
12179
12180 if (bgp_aggregate->summary_only)
12181 vty_out (vty, " summary-only");
12182
12183 vty_out (vty, "%s", VTY_NEWLINE);
12184 }
12185
12186 return 0;
12187}
12188
12189int
12190bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12191{
12192 struct bgp_node *rn;
12193 struct bgp_distance *bdistance;
12194
12195 /* Distance configuration. */
12196 if (bgp->distance_ebgp
12197 && bgp->distance_ibgp
12198 && bgp->distance_local
12199 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12200 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12201 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12202 vty_out (vty, " distance bgp %d %d %d%s",
12203 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12204 VTY_NEWLINE);
12205
12206 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12207 if ((bdistance = rn->info) != NULL)
12208 {
12209 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12210 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12211 bdistance->access_list ? bdistance->access_list : "",
12212 VTY_NEWLINE);
12213 }
12214
12215 return 0;
12216}
12217
12218/* Allocate routing table structure and install commands. */
12219void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012220bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012221{
12222 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012223 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012224
12225 /* IPv4 BGP commands. */
12226 install_element (BGP_NODE, &bgp_network_cmd);
12227 install_element (BGP_NODE, &bgp_network_mask_cmd);
12228 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12229 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12230 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12231 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12232 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12233 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12234 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12235 install_element (BGP_NODE, &no_bgp_network_cmd);
12236 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12237 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12238 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12239 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12240 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12241 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12242 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12243 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12244
12245 install_element (BGP_NODE, &aggregate_address_cmd);
12246 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12247 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12248 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12249 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12250 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12251 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12252 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12253 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12254 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12255 install_element (BGP_NODE, &no_aggregate_address_cmd);
12256 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12257 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12258 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12259 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12260 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12261 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12262 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12263 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12264 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12265
12266 /* IPv4 unicast configuration. */
12267 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12268 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12269 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12270 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12271 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12272 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012273 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012274 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12275 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12276 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12277 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12278 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012279
paul718e3742002-12-13 20:15:29 +000012280 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12281 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12282 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12283 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12284 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12285 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12286 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12287 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12288 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12289 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12290 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12291 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12292 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12293 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12294 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12295 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12296 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12297 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12298 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12299 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12300
12301 /* IPv4 multicast configuration. */
12302 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12303 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12304 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12305 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12306 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12307 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12308 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12309 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12310 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12311 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12312 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12313 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12314 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12315 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12316 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12317 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12318 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12319 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12320 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12321 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12322 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12323 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12324 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12325 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12326 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12327 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12328 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12329 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12330 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12331 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12332 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12333 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12334
12335 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12336 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012337 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012338 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12339 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012340 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012341 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12342 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12343 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12344 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012345 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012346 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12347 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12348 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12349 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12350 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12351 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12352 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12353 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12354 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12355 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12356 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12357 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12358 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12359 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12360 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12361 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12362 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12363 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12364 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12365 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12366 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12367 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12368 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12369 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12370 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012371 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12372 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12373 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12374 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12375 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012376 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12377 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12378 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12379 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12380 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12381 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12382 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12383 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12384 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12385 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12386 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12387 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12388 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12389 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12390 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12391 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12392 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12393 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012394 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012395 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12396 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12397 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12398 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12399 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12400 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12401 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12402 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12403 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12404 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12405 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12406 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12407 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12409 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12410 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012411 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012412 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012413 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012414 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012415 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012416 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012417 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12418 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012419 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012420 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012421 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012422 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012423 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012424 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012425
12426 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12427 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12428 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012429 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012430 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12431 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12432 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012433 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012434 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12435 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12436 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12437 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12438 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12439 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12440 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12441 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12442 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12443 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12444 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12445 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012446 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12447 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12448 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12449 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12450 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012451 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12452 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12453 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12454 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12455 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12456 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12457 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12458 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12459 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012460 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012461 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012462 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012463 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012464 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012465 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012466 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012467
12468 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12469 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012470 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012471 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12472 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012473 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012474 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12475 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12476 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12477 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012478 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012479 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12480 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12481 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12482 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12483 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12484 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12485 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12486 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12487 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12488 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12489 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12490 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12491 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12492 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12493 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12494 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12495 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12496 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12497 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12498 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12499 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12500 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12501 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12502 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12503 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012504 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12505 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12506 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12507 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12508 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012509 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12510 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12511 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12512 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12513 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12514 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12515 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12516 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12517 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12518 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12519 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12520 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12521 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12522 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12523 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12524 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12525 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12526 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012527 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012528 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12529 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12530 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12531 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12532 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12533 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12534 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12535 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12536 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12537 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12538 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12539 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12540 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12542 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12543 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012544 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012545 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012546 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012547 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012548 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012549 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012550 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12551 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012552 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012553 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012554 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012556 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012557 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012558
12559 /* BGP dampening clear commands */
12560 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12561 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12562 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12563 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12564
Paul Jakmaff7924f2006-09-04 01:10:36 +000012565 /* prefix count */
12566 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012569#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012570 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12571
paul718e3742002-12-13 20:15:29 +000012572 /* New config IPv6 BGP commands. */
12573 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12574 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12575 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12576 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12577
12578 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12579 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12580 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12581 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12582
12583 /* Old config IPv6 BGP commands. */
12584 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12585 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12586
12587 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12588 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12589 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12590 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12591
12592 install_element (VIEW_NODE, &show_bgp_cmd);
12593 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012595 install_element (VIEW_NODE, &show_bgp_route_cmd);
12596 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012597 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012598 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12599 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012601 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12602 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12603 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12604 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12605 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12606 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12607 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12608 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12609 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12610 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12611 install_element (VIEW_NODE, &show_bgp_community_cmd);
12612 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12613 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12614 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12615 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12616 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12617 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12618 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12619 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12620 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12621 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12622 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12623 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12624 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12625 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12626 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12627 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12628 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12629 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12630 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12631 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12632 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12633 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12634 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12635 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12636 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12637 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12638 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12639 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12640 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012641 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12642 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12643 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12644 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012645 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012646 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012647 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012648 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012649 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012650 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012651 install_element (VIEW_NODE, &show_bgp_view_cmd);
12652 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12653 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12654 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12655 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12656 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12657 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12658 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12659 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12660 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12661 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12662 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12663 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12664 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12665 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12666 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12667 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12668 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012669 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012670 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012671 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012672 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012673 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012674 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012675
12676 /* Restricted:
12677 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12678 */
12679 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12680 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012681 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012682 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12683 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012684 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012685 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12686 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12687 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12688 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12689 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12690 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12691 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12692 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12693 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12694 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12695 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12696 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12697 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12698 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12699 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12700 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12701 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012702 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012703 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012704 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012705 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12706 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12707 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12708 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12709 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12710 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12711 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012713 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012715
12716 install_element (ENABLE_NODE, &show_bgp_cmd);
12717 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012719 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12720 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012721 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012722 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12723 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012724 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012725 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12726 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12727 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12728 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12729 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12730 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12731 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12732 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12733 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12734 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12735 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12736 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12737 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12738 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12739 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12740 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12741 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12742 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12743 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12744 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12745 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12746 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12747 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12748 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12749 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12750 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12751 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12752 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12753 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12754 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12755 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12756 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12757 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12758 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12759 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12760 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12761 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12762 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12763 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12764 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012765 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12766 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12767 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12768 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012769 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012771 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012772 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012773 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012775 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12776 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12777 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12778 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12780 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12781 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12782 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12783 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12784 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12785 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12786 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12787 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12788 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12790 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12791 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012793 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012795 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012797 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012798 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012799
12800 /* Statistics */
12801 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12802 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12805
paul718e3742002-12-13 20:15:29 +000012806 /* old command */
12807 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12808 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12809 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12810 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12811 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12812 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12813 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12814 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12815 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12816 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12817 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12818 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12819 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12820 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12821 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12822 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12823 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12824 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12825 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12826 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12827 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12828 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12829 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12830 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12831 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12832 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12833 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12834 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12835 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12836 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12837 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12838 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12839 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12840 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12841 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12842 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012843
paul718e3742002-12-13 20:15:29 +000012844 /* old command */
12845 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12846 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12847 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12848 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12849 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12850 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12851 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12852 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12853 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12854 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12855 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12856 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12857 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12858 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12859 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12860 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12861 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12862 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12863 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12864 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12865 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12866 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12867 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12868 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12869 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12870 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12871 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12872 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12873 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12874 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12875 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12876 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12877 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12878 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12879 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12880 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12881
12882 /* old command */
12883 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12884 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12885 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12886 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12887
12888 /* old command */
12889 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12890 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12891 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12892 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12893
12894 /* old command */
12895 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12896 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12897 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12898 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12899#endif /* HAVE_IPV6 */
12900
12901 install_element (BGP_NODE, &bgp_distance_cmd);
12902 install_element (BGP_NODE, &no_bgp_distance_cmd);
12903 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12904 install_element (BGP_NODE, &bgp_distance_source_cmd);
12905 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12906 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12907 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12908
12909 install_element (BGP_NODE, &bgp_damp_set_cmd);
12910 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12911 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12912 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12913 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12914 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12915 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12916 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12917 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12918 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012919
12920 /* Deprecated AS-Pathlimit commands */
12921 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12922 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12923 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12924 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12925 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12926 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12927
12928 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12929 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12930 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12931 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12932 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12933 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12934
12935 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12936 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12937 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12938 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12939 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12940 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12941
12942 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12943 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12944 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12945 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12946 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12947 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12948
12949 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12950 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12951 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12952 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12953 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12954 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12955
12956 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12957 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12958 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12959 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12960 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12961 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000012962
12963#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012964 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12965 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000012966#endif
paul718e3742002-12-13 20:15:29 +000012967}
Chris Caputo228da422009-07-18 05:44:03 +000012968
12969void
12970bgp_route_finish (void)
12971{
12972 bgp_table_unlock (bgp_distance_table);
12973 bgp_distance_table = NULL;
12974}