blob: 335543e08bebabc65c7c563258131fb8aee94cce [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"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000483 if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700484 {
485 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
486 *paths_eq = 1;
487 }
488 else if (new->peer->as == exist->peer->as)
489 *paths_eq = 1;
490 }
491 else
492 {
493 /*
494 * TODO: If unequal cost ibgp multipath is enabled we can
495 * mark the paths as equal here instead of returning
496 */
497 return ret;
498 }
paul718e3742002-12-13 20:15:29 +0000499
500 /* 10. If both paths are external, prefer the path that was received
501 first (the oldest one). This step minimizes route-flap, since a
502 newer path won't displace an older one, even if it was the
503 preferred route based on the additional decision criteria below. */
504 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000505 && new_sort == BGP_PEER_EBGP
506 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000507 {
508 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
509 return 1;
510 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
511 return 0;
512 }
513
514 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000515 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
516 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000517 else
518 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000519 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
520 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000521 else
522 exist_id.s_addr = exist->peer->remote_id.s_addr;
523
524 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
525 return 1;
526 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
527 return 0;
528
529 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000530 new_cluster = exist_cluster = 0;
531
532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
533 new_cluster = newattre->cluster->length;
534 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
535 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000536
537 if (new_cluster < exist_cluster)
538 return 1;
539 if (new_cluster > exist_cluster)
540 return 0;
541
542 /* 13. Neighbor address comparision. */
543 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
544
545 if (ret == 1)
546 return 0;
547 if (ret == -1)
548 return 1;
549
550 return 1;
551}
552
paul94f2b392005-06-28 12:44:16 +0000553static enum filter_type
paul718e3742002-12-13 20:15:29 +0000554bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
555 afi_t afi, safi_t safi)
556{
557 struct bgp_filter *filter;
558
559 filter = &peer->filter[afi][safi];
560
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#define FILTER_EXIST_WARN(F,f,filter) \
562 if (BGP_DEBUG (update, UPDATE_IN) \
563 && !(F ## _IN (filter))) \
564 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
565 peer->host, #f, F ## _IN_NAME(filter));
566
567 if (DISTRIBUTE_IN_NAME (filter)) {
568 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
569
paul718e3742002-12-13 20:15:29 +0000570 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
571 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 }
paul718e3742002-12-13 20:15:29 +0000573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574 if (PREFIX_LIST_IN_NAME (filter)) {
575 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
576
paul718e3742002-12-13 20:15:29 +0000577 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
578 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100579 }
paul718e3742002-12-13 20:15:29 +0000580
Paul Jakma650f76c2009-06-25 18:06:31 +0100581 if (FILTER_LIST_IN_NAME (filter)) {
582 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
583
paul718e3742002-12-13 20:15:29 +0000584 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
585 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100586 }
587
paul718e3742002-12-13 20:15:29 +0000588 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100589#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000590}
591
paul94f2b392005-06-28 12:44:16 +0000592static enum filter_type
paul718e3742002-12-13 20:15:29 +0000593bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
594 afi_t afi, safi_t safi)
595{
596 struct bgp_filter *filter;
597
598 filter = &peer->filter[afi][safi];
599
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#define FILTER_EXIST_WARN(F,f,filter) \
601 if (BGP_DEBUG (update, UPDATE_OUT) \
602 && !(F ## _OUT (filter))) \
603 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
604 peer->host, #f, F ## _OUT_NAME(filter));
605
606 if (DISTRIBUTE_OUT_NAME (filter)) {
607 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
paul718e3742002-12-13 20:15:29 +0000612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613 if (PREFIX_LIST_OUT_NAME (filter)) {
614 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
615
paul718e3742002-12-13 20:15:29 +0000616 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
617 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100618 }
paul718e3742002-12-13 20:15:29 +0000619
Paul Jakma650f76c2009-06-25 18:06:31 +0100620 if (FILTER_LIST_OUT_NAME (filter)) {
621 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
622
paul718e3742002-12-13 20:15:29 +0000623 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
624 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100625 }
paul718e3742002-12-13 20:15:29 +0000626
627 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100628#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000629}
630
631/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000632static int
paul718e3742002-12-13 20:15:29 +0000633bgp_community_filter (struct peer *peer, struct attr *attr)
634{
635 if (attr->community)
636 {
637 /* NO_ADVERTISE check. */
638 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
639 return 1;
640
641 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000642 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000643 community_include (attr->community, COMMUNITY_NO_EXPORT))
644 return 1;
645
646 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000647 if (peer->sort == BGP_PEER_EBGP
648 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000649 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
650 return 1;
651 }
652 return 0;
653}
654
655/* Route reflection loop check. */
656static int
657bgp_cluster_filter (struct peer *peer, struct attr *attr)
658{
659 struct in_addr cluster_id;
660
Paul Jakmafb982c22007-05-04 20:15:47 +0000661 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000662 {
663 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
664 cluster_id = peer->bgp->cluster_id;
665 else
666 cluster_id = peer->bgp->router_id;
667
Paul Jakmafb982c22007-05-04 20:15:47 +0000668 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000669 return 1;
670 }
671 return 0;
672}
673
paul94f2b392005-06-28 12:44:16 +0000674static int
paul718e3742002-12-13 20:15:29 +0000675bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
676 afi_t afi, safi_t safi)
677{
678 struct bgp_filter *filter;
679 struct bgp_info info;
680 route_map_result_t ret;
681
682 filter = &peer->filter[afi][safi];
683
684 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000685 if (peer->weight)
686 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000687
688 /* Route map apply. */
689 if (ROUTE_MAP_IN_NAME (filter))
690 {
691 /* Duplicate current value to new strucutre for modification. */
692 info.peer = peer;
693 info.attr = attr;
694
paulac41b2a2003-08-12 05:32:27 +0000695 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
696
paul718e3742002-12-13 20:15:29 +0000697 /* Apply BGP route map to the attribute. */
698 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000699
700 peer->rmap_type = 0;
701
paul718e3742002-12-13 20:15:29 +0000702 if (ret == RMAP_DENYMATCH)
703 {
704 /* Free newly generated AS path and community by route-map. */
705 bgp_attr_flush (attr);
706 return RMAP_DENY;
707 }
708 }
709 return RMAP_PERMIT;
710}
711
paul94f2b392005-06-28 12:44:16 +0000712static int
paulfee0f4c2004-09-13 05:12:46 +0000713bgp_export_modifier (struct peer *rsclient, struct peer *peer,
714 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
715{
716 struct bgp_filter *filter;
717 struct bgp_info info;
718 route_map_result_t ret;
719
720 filter = &peer->filter[afi][safi];
721
722 /* Route map apply. */
723 if (ROUTE_MAP_EXPORT_NAME (filter))
724 {
725 /* Duplicate current value to new strucutre for modification. */
726 info.peer = rsclient;
727 info.attr = attr;
728
729 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
730
731 /* Apply BGP route map to the attribute. */
732 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
733
734 rsclient->rmap_type = 0;
735
736 if (ret == RMAP_DENYMATCH)
737 {
738 /* Free newly generated AS path and community by route-map. */
739 bgp_attr_flush (attr);
740 return RMAP_DENY;
741 }
742 }
743 return RMAP_PERMIT;
744}
745
paul94f2b392005-06-28 12:44:16 +0000746static int
paulfee0f4c2004-09-13 05:12:46 +0000747bgp_import_modifier (struct peer *rsclient, struct peer *peer,
748 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
749{
750 struct bgp_filter *filter;
751 struct bgp_info info;
752 route_map_result_t ret;
753
754 filter = &rsclient->filter[afi][safi];
755
756 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000757 if (peer->weight)
758 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000759
760 /* Route map apply. */
761 if (ROUTE_MAP_IMPORT_NAME (filter))
762 {
763 /* Duplicate current value to new strucutre for modification. */
764 info.peer = peer;
765 info.attr = attr;
766
767 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
768
769 /* Apply BGP route map to the attribute. */
770 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
771
772 peer->rmap_type = 0;
773
774 if (ret == RMAP_DENYMATCH)
775 {
776 /* Free newly generated AS path and community by route-map. */
777 bgp_attr_flush (attr);
778 return RMAP_DENY;
779 }
780 }
781 return RMAP_PERMIT;
782}
783
paul94f2b392005-06-28 12:44:16 +0000784static int
paul718e3742002-12-13 20:15:29 +0000785bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
786 struct attr *attr, afi_t afi, safi_t safi)
787{
788 int ret;
789 char buf[SU_ADDRSTRLEN];
790 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000791 struct peer *from;
792 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000793 int transparent;
794 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700795 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000796
797 from = ri->peer;
798 filter = &peer->filter[afi][safi];
799 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700800 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000801
Paul Jakma750e8142008-07-22 21:11:48 +0000802 if (DISABLE_BGP_ANNOUNCE)
803 return 0;
paul718e3742002-12-13 20:15:29 +0000804
paulfee0f4c2004-09-13 05:12:46 +0000805 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
806 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
807 return 0;
808
paul718e3742002-12-13 20:15:29 +0000809 /* Do not send back route to sender. */
810 if (from == peer)
811 return 0;
812
paul35be31b2004-05-01 18:17:04 +0000813 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
814 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700815 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000816 return 0;
817#ifdef HAVE_IPV6
818 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700819 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000820 return 0;
821#endif
822
paul718e3742002-12-13 20:15:29 +0000823 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000825 if (! UNSUPPRESS_MAP_NAME (filter))
826 return 0;
827
828 /* Default route check. */
829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
830 {
831 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
832 return 0;
833#ifdef HAVE_IPV6
834 else if (p->family == AF_INET6 && p->prefixlen == 0)
835 return 0;
836#endif /* HAVE_IPV6 */
837 }
838
paul286e1e72003-08-08 00:24:31 +0000839 /* Transparency check. */
840 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
841 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
842 transparent = 1;
843 else
844 transparent = 0;
845
paul718e3742002-12-13 20:15:29 +0000846 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000848 return 0;
849
850 /* If the attribute has originator-id and it is same as remote
851 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700852 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000853 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700854 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000857 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000858 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
859 peer->host,
860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
861 p->prefixlen);
862 return 0;
863 }
864 }
865
866 /* ORF prefix-list filter check */
867 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
868 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
869 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
870 if (peer->orf_plist[afi][safi])
871 {
872 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
873 return 0;
874 }
875
876 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700877 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000878 {
879 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000880 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000881 "%s [Update:SEND] %s/%d is filtered",
882 peer->host,
883 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
884 p->prefixlen);
885 return 0;
886 }
887
888#ifdef BGP_SEND_ASPATH_CHECK
889 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000891 {
892 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000893 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400894 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000895 peer->host, peer->as);
896 return 0;
897 }
898#endif /* BGP_SEND_ASPATH_CHECK */
899
900 /* If we're a CONFED we need to loop check the CONFED ID too */
901 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
902 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000904 {
905 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000906 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400907 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000908 peer->host,
909 bgp->confed_id);
910 return 0;
911 }
912 }
913
914 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000915 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000916 reflect = 1;
917 else
918 reflect = 0;
919
920 /* IBGP reflection check. */
921 if (reflect)
922 {
923 /* A route from a Client peer. */
924 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 {
926 /* Reflect to all the Non-Client peers and also to the
927 Client peers other than the originator. Originator check
928 is already done. So there is noting to do. */
929 /* no bgp client-to-client reflection check. */
930 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
931 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 else
935 {
936 /* A route from a Non-client peer. Reflect to all other
937 clients. */
938 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
939 return 0;
940 }
941 }
Paul Jakma41367172007-08-06 15:24:51 +0000942
paul718e3742002-12-13 20:15:29 +0000943 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700944 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000947 if ((peer->sort == BGP_PEER_IBGP
948 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000949 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
950 {
951 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
952 attr->local_pref = bgp->default_local_pref;
953 }
954
paul718e3742002-12-13 20:15:29 +0000955 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000956 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000957 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
958 {
959 if (ri->peer != bgp->peer_self && ! transparent
960 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
961 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
962 }
963
964 /* next-hop-set */
965 if (transparent || reflect
966 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
967 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000968#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000969 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000970 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000971#endif /* HAVE_IPV6 */
972 )))
paul718e3742002-12-13 20:15:29 +0000973 {
974 /* NEXT-HOP Unchanged. */
975 }
976 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
977 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
978#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000979 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000981#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000982 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000983 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
984 {
985 /* Set IPv4 nexthop. */
986 if (p->family == AF_INET)
987 {
988 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000989 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
990 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000991 else
992 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
993 }
994#ifdef HAVE_IPV6
995 /* Set IPv6 nexthop. */
996 if (p->family == AF_INET6)
997 {
998 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001000 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001002 }
1003#endif /* HAVE_IPV6 */
1004 }
1005
1006#ifdef HAVE_IPV6
1007 if (p->family == AF_INET6)
1008 {
paulfee0f4c2004-09-13 05:12:46 +00001009 /* Left nexthop_local unchanged if so configured. */
1010 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1011 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1012 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1014 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001015 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001017 }
1018
1019 /* Default nexthop_local treatment for non-RS-Clients */
1020 else
1021 {
paul718e3742002-12-13 20:15:29 +00001022 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001024
1025 /* Set link-local address for shared network peer. */
1026 if (peer->shared_network
1027 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1028 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001029 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001030 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001032 }
1033
1034 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1035 address.*/
1036 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001038
1039 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1040 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001041 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001042 }
paulfee0f4c2004-09-13 05:12:46 +00001043
1044 }
paul718e3742002-12-13 20:15:29 +00001045#endif /* HAVE_IPV6 */
1046
1047 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001048 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001049 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1050 && aspath_private_as_check (attr->aspath))
1051 attr->aspath = aspath_empty_get ();
1052
1053 /* Route map & unsuppress-map apply. */
1054 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001056 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001057 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001058 struct attr dummy_attr;
1059 struct attr_extra dummy_extra;
1060
1061 dummy_attr.extra = &dummy_extra;
1062
paul718e3742002-12-13 20:15:29 +00001063 info.peer = peer;
1064 info.attr = attr;
1065
1066 /* The route reflector is not allowed to modify the attributes
1067 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001068 if (from->sort == BGP_PEER_IBGP
1069 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001071 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001072 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001073 }
paulac41b2a2003-08-12 05:32:27 +00001074
1075 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1076
Paul Jakmafb982c22007-05-04 20:15:47 +00001077 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001078 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1079 else
1080 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1081
paulac41b2a2003-08-12 05:32:27 +00001082 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001083
paul718e3742002-12-13 20:15:29 +00001084 if (ret == RMAP_DENYMATCH)
1085 {
1086 bgp_attr_flush (attr);
1087 return 0;
1088 }
1089 }
1090 return 1;
1091}
1092
paul94f2b392005-06-28 12:44:16 +00001093static int
paulfee0f4c2004-09-13 05:12:46 +00001094bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1095 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001096{
paulfee0f4c2004-09-13 05:12:46 +00001097 int ret;
1098 char buf[SU_ADDRSTRLEN];
1099 struct bgp_filter *filter;
1100 struct bgp_info info;
1101 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001102 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001103
1104 from = ri->peer;
1105 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001106 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001107
Paul Jakma750e8142008-07-22 21:11:48 +00001108 if (DISABLE_BGP_ANNOUNCE)
1109 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001110
1111 /* Do not send back route to sender. */
1112 if (from == rsclient)
1113 return 0;
1114
1115 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001116 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001117 if (! UNSUPPRESS_MAP_NAME (filter))
1118 return 0;
1119
1120 /* Default route check. */
1121 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1122 PEER_STATUS_DEFAULT_ORIGINATE))
1123 {
1124 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1125 return 0;
1126#ifdef HAVE_IPV6
1127 else if (p->family == AF_INET6 && p->prefixlen == 0)
1128 return 0;
1129#endif /* HAVE_IPV6 */
1130 }
1131
1132 /* If the attribute has originator-id and it is same as remote
1133 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001134 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001135 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001136 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001138 {
1139 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001140 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001141 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1142 rsclient->host,
1143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1144 p->prefixlen);
1145 return 0;
1146 }
1147 }
1148
1149 /* ORF prefix-list filter check */
1150 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1151 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1152 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1153 if (rsclient->orf_plist[afi][safi])
1154 {
1155 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1156 return 0;
1157 }
1158
1159 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001160 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001161 {
1162 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001163 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001164 "%s [Update:SEND] %s/%d is filtered",
1165 rsclient->host,
1166 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1167 p->prefixlen);
1168 return 0;
1169 }
1170
1171#ifdef BGP_SEND_ASPATH_CHECK
1172 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001173 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001174 {
1175 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001176 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001177 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001178 rsclient->host, rsclient->as);
1179 return 0;
1180 }
1181#endif /* BGP_SEND_ASPATH_CHECK */
1182
1183 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001185
1186 /* next-hop-set */
1187 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1188#ifdef HAVE_IPV6
1189 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001190 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001191#endif /* HAVE_IPV6 */
1192 )
1193 {
1194 /* Set IPv4 nexthop. */
1195 if (p->family == AF_INET)
1196 {
1197 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001198 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001199 IPV4_MAX_BYTELEN);
1200 else
1201 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1202 }
1203#ifdef HAVE_IPV6
1204 /* Set IPv6 nexthop. */
1205 if (p->family == AF_INET6)
1206 {
1207 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001211 }
1212#endif /* HAVE_IPV6 */
1213 }
1214
1215#ifdef HAVE_IPV6
1216 if (p->family == AF_INET6)
1217 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001219
paulfee0f4c2004-09-13 05:12:46 +00001220 /* Left nexthop_local unchanged if so configured. */
1221 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1222 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1223 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1225 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001226 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001228 }
1229
1230 /* Default nexthop_local treatment for RS-Clients */
1231 else
1232 {
1233 /* Announcer and RS-Client are both in the same network */
1234 if (rsclient->shared_network && from->shared_network &&
1235 (rsclient->ifindex == from->ifindex))
1236 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1238 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001239 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001241 }
1242
1243 /* Set link-local address for shared network peer. */
1244 else if (rsclient->shared_network
1245 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001248 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001250 }
1251
1252 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001254 }
1255
1256 }
1257#endif /* HAVE_IPV6 */
1258
1259
1260 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001261 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001262 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1263 && aspath_private_as_check (attr->aspath))
1264 attr->aspath = aspath_empty_get ();
1265
1266 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001268 {
1269 info.peer = rsclient;
1270 info.attr = attr;
1271
1272 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1273
Paul Jakmafb982c22007-05-04 20:15:47 +00001274 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001275 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1276 else
1277 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1278
1279 rsclient->rmap_type = 0;
1280
1281 if (ret == RMAP_DENYMATCH)
1282 {
1283 bgp_attr_flush (attr);
1284 return 0;
1285 }
1286 }
1287
1288 return 1;
1289}
1290
1291struct bgp_info_pair
1292{
1293 struct bgp_info *old;
1294 struct bgp_info *new;
1295};
1296
paul94f2b392005-06-28 12:44:16 +00001297static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001298bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1299 struct bgp_maxpaths_cfg *mpath_cfg,
1300 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001301{
paul718e3742002-12-13 20:15:29 +00001302 struct bgp_info *new_select;
1303 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001304 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001305 struct bgp_info *ri1;
1306 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001307 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001308 int paths_eq, do_mpath;
1309 struct list mp_list;
1310
1311 bgp_mp_list_init (&mp_list);
1312 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1313 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1314
paul718e3742002-12-13 20:15:29 +00001315 /* bgp deterministic-med */
1316 new_select = NULL;
1317 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1318 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1319 {
1320 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1321 continue;
1322 if (BGP_INFO_HOLDDOWN (ri1))
1323 continue;
1324
1325 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001326 if (do_mpath)
1327 bgp_mp_list_add (&mp_list, ri1);
1328 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001329 if (ri1->next)
1330 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1331 {
1332 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1333 continue;
1334 if (BGP_INFO_HOLDDOWN (ri2))
1335 continue;
1336
1337 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1338 || aspath_cmp_left_confed (ri1->attr->aspath,
1339 ri2->attr->aspath))
1340 {
Josh Bailey6918e742011-07-20 20:48:20 -07001341 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1342 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001343 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001344 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001345 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001346 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001347 if (do_mpath && !paths_eq)
1348 {
1349 bgp_mp_list_clear (&mp_list);
1350 bgp_mp_list_add (&mp_list, ri2);
1351 }
paul718e3742002-12-13 20:15:29 +00001352 }
1353
Josh Bailey6918e742011-07-20 20:48:20 -07001354 if (do_mpath && paths_eq)
1355 bgp_mp_list_add (&mp_list, ri2);
1356
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001358 }
1359 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1361 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001362
1363 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1364 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001365 }
1366
1367 /* Check old selected route and new selected route. */
1368 old_select = NULL;
1369 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001370 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001371 {
1372 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1373 old_select = ri;
1374
1375 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001376 {
1377 /* reap REMOVED routes, if needs be
1378 * selected route must stay for a while longer though
1379 */
1380 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1381 && (ri != old_select))
1382 bgp_info_reap (rn, ri);
1383
1384 continue;
1385 }
paul718e3742002-12-13 20:15:29 +00001386
1387 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1388 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1389 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001390 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001391 continue;
1392 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001393 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1394 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001395
Josh Bailey96450fa2011-07-20 20:45:12 -07001396 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1397 {
Josh Bailey6918e742011-07-20 20:48:20 -07001398 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1399 bgp_mp_dmed_deselect (new_select);
1400
Josh Bailey96450fa2011-07-20 20:45:12 -07001401 new_select = ri;
1402
1403 if (do_mpath && !paths_eq)
1404 {
1405 bgp_mp_list_clear (&mp_list);
1406 bgp_mp_list_add (&mp_list, ri);
1407 }
1408 }
Josh Bailey6918e742011-07-20 20:48:20 -07001409 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1410 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001411
1412 if (do_mpath && paths_eq)
1413 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001414 }
paulb40d9392005-08-22 22:34:41 +00001415
paulfee0f4c2004-09-13 05:12:46 +00001416
Josh Bailey6918e742011-07-20 20:48:20 -07001417 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1418 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001419
Josh Bailey0b597ef2011-07-20 20:49:11 -07001420 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001421 bgp_mp_list_clear (&mp_list);
1422
1423 result->old = old_select;
1424 result->new = new_select;
1425
1426 return;
paulfee0f4c2004-09-13 05:12:46 +00001427}
1428
paul94f2b392005-06-28 12:44:16 +00001429static int
paulfee0f4c2004-09-13 05:12:46 +00001430bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001431 struct bgp_node *rn, afi_t afi, safi_t safi)
1432{
paulfee0f4c2004-09-13 05:12:46 +00001433 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001434 struct attr attr;
1435 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001436
1437 p = &rn->p;
1438
Paul Jakma9eda90c2007-08-30 13:36:17 +00001439 /* Announce route to Established peer. */
1440 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001441 return 0;
1442
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 /* Address family configuration check. */
1444 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001445 return 0;
1446
Paul Jakma9eda90c2007-08-30 13:36:17 +00001447 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001448 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1449 PEER_STATUS_ORF_WAIT_REFRESH))
1450 return 0;
1451
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001452 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1453 attr.extra = &extra;
1454
Avneesh Sachdev67174042012-08-17 08:19:49 -07001455 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001456 {
1457 case BGP_TABLE_MAIN:
1458 /* Announcement to peer->conf. If the route is filtered,
1459 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1461 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001462 else
1463 bgp_adj_out_unset (rn, peer, p, afi, safi);
1464 break;
1465 case BGP_TABLE_RSCLIENT:
1466 /* Announcement to peer->conf. If the route is filtered,
1467 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001468 if (selected &&
1469 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1470 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1471 else
1472 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001473 break;
1474 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001475
paulfee0f4c2004-09-13 05:12:46 +00001476 return 0;
paul200df112005-06-01 11:17:05 +00001477}
paulfee0f4c2004-09-13 05:12:46 +00001478
paul200df112005-06-01 11:17:05 +00001479struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001480{
paul200df112005-06-01 11:17:05 +00001481 struct bgp *bgp;
1482 struct bgp_node *rn;
1483 afi_t afi;
1484 safi_t safi;
1485};
1486
1487static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001488bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001489{
paul0fb58d52005-11-14 14:31:49 +00001490 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001491 struct bgp *bgp = pq->bgp;
1492 struct bgp_node *rn = pq->rn;
1493 afi_t afi = pq->afi;
1494 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001495 struct bgp_info *new_select;
1496 struct bgp_info *old_select;
1497 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001498 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001499 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001500
paulfee0f4c2004-09-13 05:12:46 +00001501 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001502 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001503 new_select = old_and_new.new;
1504 old_select = old_and_new.old;
1505
paul200df112005-06-01 11:17:05 +00001506 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1507 {
Chris Caputo228da422009-07-18 05:44:03 +00001508 if (rsclient->group)
1509 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1510 {
1511 /* Nothing to do. */
1512 if (old_select && old_select == new_select)
1513 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1514 continue;
paulfee0f4c2004-09-13 05:12:46 +00001515
Chris Caputo228da422009-07-18 05:44:03 +00001516 if (old_select)
1517 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1518 if (new_select)
1519 {
1520 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1521 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001522 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1523 }
paulfee0f4c2004-09-13 05:12:46 +00001524
Chris Caputo228da422009-07-18 05:44:03 +00001525 bgp_process_announce_selected (rsclient, new_select, rn,
1526 afi, safi);
1527 }
paul200df112005-06-01 11:17:05 +00001528 }
1529 else
1530 {
hassob7395792005-08-26 12:58:38 +00001531 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001532 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001533 if (new_select)
1534 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001535 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1536 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001537 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001538 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001539 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001540 }
paulfee0f4c2004-09-13 05:12:46 +00001541
paulb40d9392005-08-22 22:34:41 +00001542 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1543 bgp_info_reap (rn, old_select);
1544
paul200df112005-06-01 11:17:05 +00001545 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1546 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001547}
1548
paul200df112005-06-01 11:17:05 +00001549static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001550bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001551{
paul0fb58d52005-11-14 14:31:49 +00001552 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001553 struct bgp *bgp = pq->bgp;
1554 struct bgp_node *rn = pq->rn;
1555 afi_t afi = pq->afi;
1556 safi_t safi = pq->safi;
1557 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001558 struct bgp_info *new_select;
1559 struct bgp_info *old_select;
1560 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001561 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001562 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001563
paulfee0f4c2004-09-13 05:12:46 +00001564 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001565 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001566 old_select = old_and_new.old;
1567 new_select = old_and_new.new;
1568
1569 /* Nothing to do. */
1570 if (old_select && old_select == new_select)
1571 {
1572 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001573 {
Josh Bailey8196f132011-07-20 20:47:07 -07001574 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1575 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001576 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001577
Josh Bailey8196f132011-07-20 20:47:07 -07001578 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001579 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1580 return WQ_SUCCESS;
1581 }
paulfee0f4c2004-09-13 05:12:46 +00001582 }
paul718e3742002-12-13 20:15:29 +00001583
hasso338b3422005-02-23 14:27:24 +00001584 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001585 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001586 if (new_select)
1587 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001588 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1589 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001591 }
1592
1593
paul718e3742002-12-13 20:15:29 +00001594 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001595 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001596 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001597 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001598 }
1599
1600 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001601 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1602 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001603 {
1604 if (new_select
1605 && new_select->type == ZEBRA_ROUTE_BGP
1606 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001607 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001608 else
1609 {
1610 /* Withdraw the route from the kernel. */
1611 if (old_select
1612 && old_select->type == ZEBRA_ROUTE_BGP
1613 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001614 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001615 }
1616 }
paulb40d9392005-08-22 22:34:41 +00001617
1618 /* Reap old select bgp_info, it it has been removed */
1619 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1620 bgp_info_reap (rn, old_select);
1621
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001624}
1625
paul200df112005-06-01 11:17:05 +00001626static void
paul0fb58d52005-11-14 14:31:49 +00001627bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001628{
paul0fb58d52005-11-14 14:31:49 +00001629 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001630 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001631
Chris Caputo228da422009-07-18 05:44:03 +00001632 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001633 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001634 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001635 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1636}
1637
1638static void
1639bgp_process_queue_init (void)
1640{
1641 bm->process_main_queue
1642 = work_queue_new (bm->master, "process_main_queue");
1643 bm->process_rsclient_queue
1644 = work_queue_new (bm->master, "process_rsclient_queue");
1645
1646 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1647 {
1648 zlog_err ("%s: Failed to allocate work queue", __func__);
1649 exit (1);
1650 }
1651
1652 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001653 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001654 bm->process_main_queue->spec.max_retries = 0;
1655 bm->process_main_queue->spec.hold = 50;
1656
1657 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1658 sizeof (struct work_queue *));
1659 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001660}
1661
1662void
paulfee0f4c2004-09-13 05:12:46 +00001663bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1664{
paul200df112005-06-01 11:17:05 +00001665 struct bgp_process_queue *pqnode;
1666
1667 /* already scheduled for processing? */
1668 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1669 return;
1670
1671 if ( (bm->process_main_queue == NULL) ||
1672 (bm->process_rsclient_queue == NULL) )
1673 bgp_process_queue_init ();
1674
1675 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1676 sizeof (struct bgp_process_queue));
1677 if (!pqnode)
1678 return;
Chris Caputo228da422009-07-18 05:44:03 +00001679
1680 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001681 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001682 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001683 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001684 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001685 pqnode->afi = afi;
1686 pqnode->safi = safi;
1687
Avneesh Sachdev67174042012-08-17 08:19:49 -07001688 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001689 {
paul200df112005-06-01 11:17:05 +00001690 case BGP_TABLE_MAIN:
1691 work_queue_add (bm->process_main_queue, pqnode);
1692 break;
1693 case BGP_TABLE_RSCLIENT:
1694 work_queue_add (bm->process_rsclient_queue, pqnode);
1695 break;
paulfee0f4c2004-09-13 05:12:46 +00001696 }
paul200df112005-06-01 11:17:05 +00001697
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001698 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001699 return;
paulfee0f4c2004-09-13 05:12:46 +00001700}
hasso0a486e52005-02-01 20:57:17 +00001701
paul94f2b392005-06-28 12:44:16 +00001702static int
hasso0a486e52005-02-01 20:57:17 +00001703bgp_maximum_prefix_restart_timer (struct thread *thread)
1704{
1705 struct peer *peer;
1706
1707 peer = THREAD_ARG (thread);
1708 peer->t_pmax_restart = NULL;
1709
1710 if (BGP_DEBUG (events, EVENTS))
1711 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1712 peer->host);
1713
1714 peer_clear (peer);
1715
1716 return 0;
1717}
1718
paulfee0f4c2004-09-13 05:12:46 +00001719int
paul5228ad22004-06-04 17:58:18 +00001720bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1721 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001722{
hassoe0701b72004-05-20 09:19:34 +00001723 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1724 return 0;
1725
1726 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001727 {
hassoe0701b72004-05-20 09:19:34 +00001728 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1729 && ! always)
1730 return 0;
paul718e3742002-12-13 20:15:29 +00001731
hassoe0701b72004-05-20 09:19:34 +00001732 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001733 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1734 "limit %ld", afi_safi_print (afi, safi), peer->host,
1735 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001736 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001737
hassoe0701b72004-05-20 09:19:34 +00001738 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1739 return 0;
paul718e3742002-12-13 20:15:29 +00001740
hassoe0701b72004-05-20 09:19:34 +00001741 {
paul5228ad22004-06-04 17:58:18 +00001742 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001743
1744 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001745 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001746
1747 ndata[0] = (afi >> 8);
1748 ndata[1] = afi;
1749 ndata[2] = safi;
1750 ndata[3] = (peer->pmax[afi][safi] >> 24);
1751 ndata[4] = (peer->pmax[afi][safi] >> 16);
1752 ndata[5] = (peer->pmax[afi][safi] >> 8);
1753 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001754
1755 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1756 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1757 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1758 }
hasso0a486e52005-02-01 20:57:17 +00001759
1760 /* restart timer start */
1761 if (peer->pmax_restart[afi][safi])
1762 {
1763 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1764
1765 if (BGP_DEBUG (events, EVENTS))
1766 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1767 peer->host, peer->v_pmax_restart);
1768
1769 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1770 peer->v_pmax_restart);
1771 }
1772
hassoe0701b72004-05-20 09:19:34 +00001773 return 1;
paul718e3742002-12-13 20:15:29 +00001774 }
hassoe0701b72004-05-20 09:19:34 +00001775 else
1776 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1777
1778 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1779 {
1780 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1781 && ! always)
1782 return 0;
1783
1784 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001785 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1786 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1787 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001788 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1789 }
1790 else
1791 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001792 return 0;
1793}
1794
paulb40d9392005-08-22 22:34:41 +00001795/* Unconditionally remove the route from the RIB, without taking
1796 * damping into consideration (eg, because the session went down)
1797 */
paul94f2b392005-06-28 12:44:16 +00001798static void
paul718e3742002-12-13 20:15:29 +00001799bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1800 afi_t afi, safi_t safi)
1801{
paul902212c2006-02-05 17:51:19 +00001802 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1803
1804 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1805 bgp_info_delete (rn, ri); /* keep historical info */
1806
paulb40d9392005-08-22 22:34:41 +00001807 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001808}
1809
paul94f2b392005-06-28 12:44:16 +00001810static void
paul718e3742002-12-13 20:15:29 +00001811bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001812 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001813{
paul718e3742002-12-13 20:15:29 +00001814 int status = BGP_DAMP_NONE;
1815
paulb40d9392005-08-22 22:34:41 +00001816 /* apply dampening, if result is suppressed, we'll be retaining
1817 * the bgp_info in the RIB for historical reference.
1818 */
1819 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001820 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001821 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1822 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001823 {
paul902212c2006-02-05 17:51:19 +00001824 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1825 return;
1826 }
1827
1828 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001829}
1830
paul94f2b392005-06-28 12:44:16 +00001831static void
paulfee0f4c2004-09-13 05:12:46 +00001832bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1833 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1834 int sub_type, struct prefix_rd *prd, u_char *tag)
1835{
1836 struct bgp_node *rn;
1837 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001838 struct attr new_attr;
1839 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001840 struct attr *attr_new;
1841 struct attr *attr_new2;
1842 struct bgp_info *ri;
1843 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001844 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001845 char buf[SU_ADDRSTRLEN];
1846
1847 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1848 if (peer == rsclient)
1849 return;
1850
1851 bgp = peer->bgp;
1852 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1853
1854 /* Check previously received route. */
1855 for (ri = rn->info; ri; ri = ri->next)
1856 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1857 break;
1858
1859 /* AS path loop check. */
1860 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1861 {
1862 reason = "as-path contains our own AS;";
1863 goto filtered;
1864 }
1865
1866 /* Route reflector originator ID check. */
1867 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001868 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001869 {
1870 reason = "originator is us;";
1871 goto filtered;
1872 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001873
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001874 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001875 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001876
1877 /* Apply export policy. */
1878 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1879 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1880 {
1881 reason = "export-policy;";
1882 goto filtered;
1883 }
1884
1885 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001886
paulfee0f4c2004-09-13 05:12:46 +00001887 /* Apply import policy. */
1888 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1889 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001890 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001891
1892 reason = "import-policy;";
1893 goto filtered;
1894 }
1895
1896 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001897 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001898
1899 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001900 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001901 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001902 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001903 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001904 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001905 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001906 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001907
1908 reason = "martian next-hop;";
1909 goto filtered;
1910 }
1911 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001912
paulfee0f4c2004-09-13 05:12:46 +00001913 /* If the update is implicit withdraw. */
1914 if (ri)
1915 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001916 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001917
1918 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001919 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1920 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001921 {
1922
Paul Jakma1a392d42006-09-07 00:24:49 +00001923 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001924
1925 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001926 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001927 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1928 peer->host,
1929 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1930 p->prefixlen, rsclient->host);
1931
Chris Caputo228da422009-07-18 05:44:03 +00001932 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001933 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001934
Chris Caputo228da422009-07-18 05:44:03 +00001935 return;
paulfee0f4c2004-09-13 05:12:46 +00001936 }
1937
Paul Jakma16d2e242007-04-10 19:32:10 +00001938 /* Withdraw/Announce before we fully processed the withdraw */
1939 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1940 bgp_info_restore (rn, ri);
1941
paulfee0f4c2004-09-13 05:12:46 +00001942 /* Received Logging. */
1943 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001944 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001945 peer->host,
1946 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1947 p->prefixlen, rsclient->host);
1948
1949 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001950 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001953 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001954 ri->attr = attr_new;
1955
1956 /* Update MPLS tag. */
1957 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001958 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001959
Paul Jakma1a392d42006-09-07 00:24:49 +00001960 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 /* Process change. */
1963 bgp_process (bgp, rn, afi, safi);
1964 bgp_unlock_node (rn);
1965
1966 return;
1967 }
1968
1969 /* Received Logging. */
1970 if (BGP_DEBUG (update, UPDATE_IN))
1971 {
ajsd2c1f162004-12-08 21:10:20 +00001972 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001973 peer->host,
1974 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1975 p->prefixlen, rsclient->host);
1976 }
1977
1978 /* Make new BGP info. */
1979 new = bgp_info_new ();
1980 new->type = type;
1981 new->sub_type = sub_type;
1982 new->peer = peer;
1983 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001984 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001985
1986 /* Update MPLS tag. */
1987 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001988 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001989
Paul Jakma1a392d42006-09-07 00:24:49 +00001990 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001991
1992 /* Register new BGP information. */
1993 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001994
1995 /* route_node_get lock */
1996 bgp_unlock_node (rn);
1997
paulfee0f4c2004-09-13 05:12:46 +00001998 /* Process change. */
1999 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002000
paulfee0f4c2004-09-13 05:12:46 +00002001 return;
2002
2003 filtered:
2004
2005 /* This BGP update is filtered. Log the reason then update BGP entry. */
2006 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002007 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002008 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2009 peer->host,
2010 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2011 p->prefixlen, rsclient->host, reason);
2012
2013 if (ri)
paulb40d9392005-08-22 22:34:41 +00002014 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002015
2016 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002017
paulfee0f4c2004-09-13 05:12:46 +00002018 return;
2019}
2020
paul94f2b392005-06-28 12:44:16 +00002021static void
paulfee0f4c2004-09-13 05:12:46 +00002022bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2023 struct peer *peer, struct prefix *p, int type, int sub_type,
2024 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002025{
paulfee0f4c2004-09-13 05:12:46 +00002026 struct bgp_node *rn;
2027 struct bgp_info *ri;
2028 char buf[SU_ADDRSTRLEN];
2029
2030 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002031 return;
paulfee0f4c2004-09-13 05:12:46 +00002032
2033 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2034
2035 /* Lookup withdrawn route. */
2036 for (ri = rn->info; ri; ri = ri->next)
2037 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2038 break;
2039
2040 /* Withdraw specified route from routing table. */
2041 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002042 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002043 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002044 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002045 "%s Can't find the route %s/%d", peer->host,
2046 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2047 p->prefixlen);
2048
2049 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002050 bgp_unlock_node (rn);
2051}
paulfee0f4c2004-09-13 05:12:46 +00002052
paul94f2b392005-06-28 12:44:16 +00002053static int
paulfee0f4c2004-09-13 05:12:46 +00002054bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002055 afi_t afi, safi_t safi, int type, int sub_type,
2056 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2057{
2058 int ret;
2059 int aspath_loop_count = 0;
2060 struct bgp_node *rn;
2061 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002062 struct attr new_attr;
2063 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002064 struct attr *attr_new;
2065 struct bgp_info *ri;
2066 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002067 const char *reason;
paul718e3742002-12-13 20:15:29 +00002068 char buf[SU_ADDRSTRLEN];
2069
2070 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002071 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002072
paul718e3742002-12-13 20:15:29 +00002073 /* When peer's soft reconfiguration enabled. Record input packet in
2074 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002075 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2076 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002077 bgp_adj_in_set (rn, peer, attr);
2078
2079 /* Check previously received route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* AS path local-as loop check. */
2085 if (peer->change_local_as)
2086 {
2087 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2088 aspath_loop_count = 1;
2089
2090 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2091 {
2092 reason = "as-path contains our own AS;";
2093 goto filtered;
2094 }
2095 }
2096
2097 /* AS path loop check. */
2098 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2099 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2100 && aspath_loop_check(attr->aspath, bgp->confed_id)
2101 > peer->allowas_in[afi][safi]))
2102 {
2103 reason = "as-path contains our own AS;";
2104 goto filtered;
2105 }
2106
2107 /* Route reflector originator ID check. */
2108 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002109 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002110 {
2111 reason = "originator is us;";
2112 goto filtered;
2113 }
2114
2115 /* Route reflector cluster ID check. */
2116 if (bgp_cluster_filter (peer, attr))
2117 {
2118 reason = "reflected from the same cluster;";
2119 goto filtered;
2120 }
2121
2122 /* Apply incoming filter. */
2123 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2124 {
2125 reason = "filter;";
2126 goto filtered;
2127 }
2128
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002129 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002130 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002131
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002132 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002133 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2134 {
2135 reason = "route-map;";
2136 goto filtered;
2137 }
2138
2139 /* IPv4 unicast next hop check. */
2140 if (afi == AFI_IP && safi == SAFI_UNICAST)
2141 {
2142 /* If the peer is EBGP and nexthop is not on connected route,
2143 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002144 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002145 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002146 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002147 {
2148 reason = "non-connected next-hop;";
2149 goto filtered;
2150 }
2151
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002152 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002153 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002154 if (new_attr.nexthop.s_addr == 0
2155 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2156 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002157 {
2158 reason = "martian next-hop;";
2159 goto filtered;
2160 }
2161 }
2162
2163 attr_new = bgp_attr_intern (&new_attr);
2164
2165 /* If the update is implicit withdraw. */
2166 if (ri)
2167 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002168 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002169
2170 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002171 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2172 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002173 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002174 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002175
2176 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002177 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002178 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2179 {
2180 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002181 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002182 peer->host,
2183 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2184 p->prefixlen);
2185
paul902212c2006-02-05 17:51:19 +00002186 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2187 {
2188 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2189 bgp_process (bgp, rn, afi, safi);
2190 }
paul718e3742002-12-13 20:15:29 +00002191 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002192 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002193 {
2194 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002195 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002196 "%s rcvd %s/%d...duplicate ignored",
2197 peer->host,
2198 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2199 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002200
2201 /* graceful restart STALE flag unset. */
2202 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2203 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002204 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002205 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002206 }
paul718e3742002-12-13 20:15:29 +00002207 }
2208
2209 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002210 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002211
paul718e3742002-12-13 20:15:29 +00002212 return 0;
2213 }
2214
Paul Jakma16d2e242007-04-10 19:32:10 +00002215 /* Withdraw/Announce before we fully processed the withdraw */
2216 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2217 {
2218 if (BGP_DEBUG (update, UPDATE_IN))
2219 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2220 peer->host,
2221 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2222 p->prefixlen);
2223 bgp_info_restore (rn, ri);
2224 }
2225
paul718e3742002-12-13 20:15:29 +00002226 /* Received Logging. */
2227 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002228 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002229 peer->host,
2230 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen);
2232
hasso93406d82005-02-02 14:40:33 +00002233 /* graceful restart STALE flag unset. */
2234 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002235 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002236
paul718e3742002-12-13 20:15:29 +00002237 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002238 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002239
2240 /* implicit withdraw, decrement aggregate and pcount here.
2241 * only if update is accepted, they'll increment below.
2242 */
paul902212c2006-02-05 17:51:19 +00002243 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2244
paul718e3742002-12-13 20:15:29 +00002245 /* Update bgp route dampening information. */
2246 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002247 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002248 {
2249 /* This is implicit withdraw so we should update dampening
2250 information. */
2251 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002253 }
2254
paul718e3742002-12-13 20:15:29 +00002255 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002256 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002257 ri->attr = attr_new;
2258
2259 /* Update MPLS tag. */
2260 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002261 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002262
2263 /* Update bgp route dampening information. */
2264 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002265 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002266 {
2267 /* Now we do normal update dampening. */
2268 ret = bgp_damp_update (ri, rn, afi, safi);
2269 if (ret == BGP_DAMP_SUPPRESSED)
2270 {
2271 bgp_unlock_node (rn);
2272 return 0;
2273 }
2274 }
2275
2276 /* Nexthop reachability check. */
2277 if ((afi == AFI_IP || afi == AFI_IP6)
2278 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002279 && (peer->sort == BGP_PEER_IBGP
2280 || peer->sort == BGP_PEER_CONFED
2281 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002282 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002283 {
2284 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002287 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002288 }
2289 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002290 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002291
2292 /* Process change. */
2293 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2294
2295 bgp_process (bgp, rn, afi, safi);
2296 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002297
paul718e3742002-12-13 20:15:29 +00002298 return 0;
2299 }
2300
2301 /* Received Logging. */
2302 if (BGP_DEBUG (update, UPDATE_IN))
2303 {
ajsd2c1f162004-12-08 21:10:20 +00002304 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002305 peer->host,
2306 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2307 p->prefixlen);
2308 }
2309
paul718e3742002-12-13 20:15:29 +00002310 /* Make new BGP info. */
2311 new = bgp_info_new ();
2312 new->type = type;
2313 new->sub_type = sub_type;
2314 new->peer = peer;
2315 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002316 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002317
2318 /* Update MPLS tag. */
2319 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002320 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002321
2322 /* Nexthop reachability check. */
2323 if ((afi == AFI_IP || afi == AFI_IP6)
2324 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002325 && (peer->sort == BGP_PEER_IBGP
2326 || peer->sort == BGP_PEER_CONFED
2327 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002328 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002329 {
2330 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002331 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002332 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002333 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002334 }
2335 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002336 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002337
paul902212c2006-02-05 17:51:19 +00002338 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002339 bgp_aggregate_increment (bgp, p, new, afi, safi);
2340
2341 /* Register new BGP information. */
2342 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002343
2344 /* route_node_get lock */
2345 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002346
paul718e3742002-12-13 20:15:29 +00002347 /* If maximum prefix count is configured and current prefix
2348 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002349 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2350 return -1;
paul718e3742002-12-13 20:15:29 +00002351
2352 /* Process change. */
2353 bgp_process (bgp, rn, afi, safi);
2354
2355 return 0;
2356
2357 /* This BGP update is filtered. Log the reason then update BGP
2358 entry. */
2359 filtered:
2360 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002361 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002362 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2363 peer->host,
2364 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2365 p->prefixlen, reason);
2366
2367 if (ri)
paulb40d9392005-08-22 22:34:41 +00002368 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002369
2370 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002371
paul718e3742002-12-13 20:15:29 +00002372 return 0;
2373}
2374
2375int
paulfee0f4c2004-09-13 05:12:46 +00002376bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2377 afi_t afi, safi_t safi, int type, int sub_type,
2378 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2379{
2380 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002381 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002382 struct bgp *bgp;
2383 int ret;
2384
2385 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2386 soft_reconfig);
2387
2388 bgp = peer->bgp;
2389
2390 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002391 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002392 {
2393 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2394 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2395 sub_type, prd, tag);
2396 }
2397
2398 return ret;
2399}
2400
2401int
paul718e3742002-12-13 20:15:29 +00002402bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002403 afi_t afi, safi_t safi, int type, int sub_type,
2404 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002405{
2406 struct bgp *bgp;
2407 char buf[SU_ADDRSTRLEN];
2408 struct bgp_node *rn;
2409 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002410 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002411 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002412
2413 bgp = peer->bgp;
2414
paulfee0f4c2004-09-13 05:12:46 +00002415 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002416 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002417 {
2418 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2419 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2420 }
2421
paul718e3742002-12-13 20:15:29 +00002422 /* Logging. */
2423 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002424 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002425 peer->host,
2426 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2427 p->prefixlen);
2428
2429 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002430 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002431
2432 /* If peer is soft reconfiguration enabled. Record input packet for
2433 further calculation. */
2434 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2435 && peer != bgp->peer_self)
2436 bgp_adj_in_unset (rn, peer);
2437
2438 /* Lookup withdrawn route. */
2439 for (ri = rn->info; ri; ri = ri->next)
2440 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2441 break;
2442
2443 /* Withdraw specified route from routing table. */
2444 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002445 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002446 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002447 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002448 "%s Can't find the route %s/%d", peer->host,
2449 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2450 p->prefixlen);
2451
2452 /* Unlock bgp_node_get() lock. */
2453 bgp_unlock_node (rn);
2454
2455 return 0;
2456}
2457
2458void
2459bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2460{
2461 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002462 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002463 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002464 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002465 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002466 struct bgp_node *rn;
2467 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002468 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002469
Paul Jakmab2497022007-06-14 11:17:58 +00002470 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002471 return;
2472
paul718e3742002-12-13 20:15:29 +00002473 bgp = peer->bgp;
2474 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002475
paul718e3742002-12-13 20:15:29 +00002476 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2477 aspath = attr.aspath;
2478 attr.local_pref = bgp->default_local_pref;
2479 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2480
2481 if (afi == AFI_IP)
2482 str2prefix ("0.0.0.0/0", &p);
2483#ifdef HAVE_IPV6
2484 else if (afi == AFI_IP6)
2485 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002486 struct attr_extra *ae = attr.extra;
2487
paul718e3742002-12-13 20:15:29 +00002488 str2prefix ("::/0", &p);
2489
2490 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002491 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002492 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002493 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002494
2495 /* If the peer is on shared nextwork and we have link-local
2496 nexthop set it. */
2497 if (peer->shared_network
2498 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2499 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002500 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002501 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002502 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002503 }
2504 }
2505#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002506
2507 if (peer->default_rmap[afi][safi].name)
2508 {
paulfee0f4c2004-09-13 05:12:46 +00002509 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002510 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2511 {
2512 for (ri = rn->info; ri; ri = ri->next)
2513 {
2514 struct attr dummy_attr;
2515 struct attr_extra dummy_extra;
2516 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002517
Christian Frankedcab1bb2012-12-07 16:45:52 +00002518 /* Provide dummy so the route-map can't modify the attributes */
2519 dummy_attr.extra = &dummy_extra;
2520 bgp_attr_dup(&dummy_attr, ri->attr);
2521 info.peer = ri->peer;
2522 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002523
Christian Frankedcab1bb2012-12-07 16:45:52 +00002524 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2525 RMAP_BGP, &info);
2526
2527 /* The route map might have set attributes. If we don't flush them
2528 * here, they will be leaked. */
2529 bgp_attr_flush(&dummy_attr);
2530 if (ret != RMAP_DENYMATCH)
2531 break;
2532 }
2533 if (ret != RMAP_DENYMATCH)
2534 break;
2535 }
paulfee0f4c2004-09-13 05:12:46 +00002536 bgp->peer_self->rmap_type = 0;
2537
paul718e3742002-12-13 20:15:29 +00002538 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002539 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002540 }
2541
2542 if (withdraw)
2543 {
2544 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2545 bgp_default_withdraw_send (peer, afi, safi);
2546 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2547 }
2548 else
2549 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002550 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2551 {
2552 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2553 bgp_default_update_send (peer, &attr, afi, safi, from);
2554 }
paul718e3742002-12-13 20:15:29 +00002555 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002556
2557 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002558 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002559}
2560
2561static void
2562bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002563 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002564{
2565 struct bgp_node *rn;
2566 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002567 struct attr attr;
2568 struct attr_extra extra;
2569
paul718e3742002-12-13 20:15:29 +00002570 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002571 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002572
2573 if (safi != SAFI_MPLS_VPN
2574 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2575 bgp_default_originate (peer, afi, safi, 0);
2576
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002577 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2578 attr.extra = &extra;
2579
paul718e3742002-12-13 20:15:29 +00002580 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2581 for (ri = rn->info; ri; ri = ri->next)
2582 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2583 {
paulfee0f4c2004-09-13 05:12:46 +00002584 if ( (rsclient) ?
2585 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2586 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002587 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2588 else
2589 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2590 }
2591}
2592
2593void
2594bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2595{
2596 struct bgp_node *rn;
2597 struct bgp_table *table;
2598
2599 if (peer->status != Established)
2600 return;
2601
2602 if (! peer->afc_nego[afi][safi])
2603 return;
2604
2605 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2606 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2607 return;
2608
2609 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002610 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002611 else
2612 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2613 rn = bgp_route_next(rn))
2614 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002615 bgp_announce_table (peer, afi, safi, table, 0);
2616
2617 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2618 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002619}
2620
2621void
2622bgp_announce_route_all (struct peer *peer)
2623{
2624 afi_t afi;
2625 safi_t safi;
2626
2627 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2628 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2629 bgp_announce_route (peer, afi, safi);
2630}
2631
2632static void
paulfee0f4c2004-09-13 05:12:46 +00002633bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002634 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002635{
2636 struct bgp_node *rn;
2637 struct bgp_adj_in *ain;
2638
2639 if (! table)
2640 table = rsclient->bgp->rib[afi][safi];
2641
2642 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2643 for (ain = rn->adj_in; ain; ain = ain->next)
2644 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002645 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002646 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002647
paulfee0f4c2004-09-13 05:12:46 +00002648 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002649 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002650 }
2651}
2652
2653void
2654bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2655{
2656 struct bgp_table *table;
2657 struct bgp_node *rn;
2658
2659 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002660 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002661
2662 else
2663 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2664 rn = bgp_route_next (rn))
2665 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002666 {
2667 struct prefix_rd prd;
2668 prd.family = AF_UNSPEC;
2669 prd.prefixlen = 64;
2670 memcpy(&prd.val, rn->p.u.val, 8);
2671
2672 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2673 }
paulfee0f4c2004-09-13 05:12:46 +00002674}
2675
2676static void
paul718e3742002-12-13 20:15:29 +00002677bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002678 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002679{
2680 int ret;
2681 struct bgp_node *rn;
2682 struct bgp_adj_in *ain;
2683
2684 if (! table)
2685 table = peer->bgp->rib[afi][safi];
2686
2687 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2688 for (ain = rn->adj_in; ain; ain = ain->next)
2689 {
2690 if (ain->peer == peer)
2691 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002692 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002693 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002694
paul718e3742002-12-13 20:15:29 +00002695 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2696 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002697 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002698
paul718e3742002-12-13 20:15:29 +00002699 if (ret < 0)
2700 {
2701 bgp_unlock_node (rn);
2702 return;
2703 }
2704 continue;
2705 }
2706 }
2707}
2708
2709void
2710bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2711{
2712 struct bgp_node *rn;
2713 struct bgp_table *table;
2714
2715 if (peer->status != Established)
2716 return;
2717
2718 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002719 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002720 else
2721 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2722 rn = bgp_route_next (rn))
2723 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002724 {
2725 struct prefix_rd prd;
2726 prd.family = AF_UNSPEC;
2727 prd.prefixlen = 64;
2728 memcpy(&prd.val, rn->p.u.val, 8);
2729
2730 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2731 }
paul718e3742002-12-13 20:15:29 +00002732}
2733
Chris Caputo228da422009-07-18 05:44:03 +00002734
2735struct bgp_clear_node_queue
2736{
2737 struct bgp_node *rn;
2738 enum bgp_clear_route_type purpose;
2739};
2740
paul200df112005-06-01 11:17:05 +00002741static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002742bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002743{
Chris Caputo228da422009-07-18 05:44:03 +00002744 struct bgp_clear_node_queue *cnq = data;
2745 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002746 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002747 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002748 afi_t afi = bgp_node_table (rn)->afi;
2749 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002750
Paul Jakma64e580a2006-02-21 01:09:01 +00002751 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002752
Paul Jakma64e580a2006-02-21 01:09:01 +00002753 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002754 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002755 {
2756 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002757 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2758 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002759 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002760 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2761 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002762 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002763 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002764 break;
2765 }
paul200df112005-06-01 11:17:05 +00002766 return WQ_SUCCESS;
2767}
2768
2769static void
paul0fb58d52005-11-14 14:31:49 +00002770bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002771{
Chris Caputo228da422009-07-18 05:44:03 +00002772 struct bgp_clear_node_queue *cnq = data;
2773 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002774 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002775
2776 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002777 bgp_table_unlock (table);
2778 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002779}
2780
2781static void
paul94f2b392005-06-28 12:44:16 +00002782bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002783{
Paul Jakma64e580a2006-02-21 01:09:01 +00002784 struct peer *peer = wq->spec.data;
2785
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002786 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002787 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002788
2789 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002790}
2791
2792static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002793bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002794{
Paul Jakmaa2943652009-07-21 14:02:04 +01002795 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002796
Paul Jakmaa2943652009-07-21 14:02:04 +01002797 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002798#undef CLEAR_QUEUE_NAME_LEN
2799
2800 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002801 {
2802 zlog_err ("%s: Failed to allocate work queue", __func__);
2803 exit (1);
2804 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002805 peer->clear_node_queue->spec.hold = 10;
2806 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2807 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2808 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2809 peer->clear_node_queue->spec.max_retries = 0;
2810
2811 /* we only 'lock' this peer reference when the queue is actually active */
2812 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002813}
2814
paul718e3742002-12-13 20:15:29 +00002815static void
2816bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002817 struct bgp_table *table, struct peer *rsclient,
2818 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002819{
2820 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002821
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002822
paul718e3742002-12-13 20:15:29 +00002823 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002824 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002825
hasso6cf159b2005-03-21 10:28:14 +00002826 /* If still no table => afi/safi isn't configured at all or smth. */
2827 if (! table)
2828 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002829
2830 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2831 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002832 struct bgp_info *ri;
2833 struct bgp_adj_in *ain;
2834 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002835
2836 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2837 * queued for every clearing peer, regardless of whether it is
2838 * relevant to the peer at hand.
2839 *
2840 * Overview: There are 3 different indices which need to be
2841 * scrubbed, potentially, when a peer is removed:
2842 *
2843 * 1 peer's routes visible via the RIB (ie accepted routes)
2844 * 2 peer's routes visible by the (optional) peer's adj-in index
2845 * 3 other routes visible by the peer's adj-out index
2846 *
2847 * 3 there is no hurry in scrubbing, once the struct peer is
2848 * removed from bgp->peer, we could just GC such deleted peer's
2849 * adj-outs at our leisure.
2850 *
2851 * 1 and 2 must be 'scrubbed' in some way, at least made
2852 * invisible via RIB index before peer session is allowed to be
2853 * brought back up. So one needs to know when such a 'search' is
2854 * complete.
2855 *
2856 * Ideally:
2857 *
2858 * - there'd be a single global queue or a single RIB walker
2859 * - rather than tracking which route_nodes still need to be
2860 * examined on a peer basis, we'd track which peers still
2861 * aren't cleared
2862 *
2863 * Given that our per-peer prefix-counts now should be reliable,
2864 * this may actually be achievable. It doesn't seem to be a huge
2865 * problem at this time,
2866 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002867 for (ain = rn->adj_in; ain; ain = ain->next)
2868 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2869 {
2870 bgp_adj_in_remove (rn, ain);
2871 bgp_unlock_node (rn);
2872 break;
2873 }
2874 for (aout = rn->adj_out; aout; aout = aout->next)
2875 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2876 {
2877 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2878 bgp_unlock_node (rn);
2879 break;
2880 }
2881
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002882 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002883 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002884 {
Chris Caputo228da422009-07-18 05:44:03 +00002885 struct bgp_clear_node_queue *cnq;
2886
2887 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002888 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002889 bgp_lock_node (rn);
2890 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2891 sizeof (struct bgp_clear_node_queue));
2892 cnq->rn = rn;
2893 cnq->purpose = purpose;
2894 work_queue_add (peer->clear_node_queue, cnq);
2895 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002896 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002897 }
2898 return;
2899}
2900
2901void
Chris Caputo228da422009-07-18 05:44:03 +00002902bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2903 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002904{
2905 struct bgp_node *rn;
2906 struct bgp_table *table;
2907 struct peer *rsclient;
2908 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002909
Paul Jakma64e580a2006-02-21 01:09:01 +00002910 if (peer->clear_node_queue == NULL)
2911 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002912
Paul Jakmaca058a32006-09-14 02:58:49 +00002913 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2914 * Idle until it receives a Clearing_Completed event. This protects
2915 * against peers which flap faster than we can we clear, which could
2916 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002917 *
2918 * a) race with routes from the new session being installed before
2919 * clear_route_node visits the node (to delete the route of that
2920 * peer)
2921 * b) resource exhaustion, clear_route_node likely leads to an entry
2922 * on the process_main queue. Fast-flapping could cause that queue
2923 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002924 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002925 if (!peer->clear_node_queue->thread)
2926 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002927
Chris Caputo228da422009-07-18 05:44:03 +00002928 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002929 {
Chris Caputo228da422009-07-18 05:44:03 +00002930 case BGP_CLEAR_ROUTE_NORMAL:
2931 if (safi != SAFI_MPLS_VPN)
2932 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2933 else
2934 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2935 rn = bgp_route_next (rn))
2936 if ((table = rn->info) != NULL)
2937 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2938
2939 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2940 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2941 PEER_FLAG_RSERVER_CLIENT))
2942 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2943 break;
2944
2945 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2946 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2947 break;
2948
2949 default:
2950 assert (0);
2951 break;
paulfee0f4c2004-09-13 05:12:46 +00002952 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002953
Paul Jakmaca058a32006-09-14 02:58:49 +00002954 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002955 * completion function won't be run by workqueue code - call it here.
2956 * XXX: Actually, this assumption doesn't hold, see
2957 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002958 *
2959 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002960 * really needed if peer state is Established - peers in
2961 * pre-Established states shouldn't have any route-update state
2962 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002963 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002964 * We still can get here in pre-Established though, through
2965 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2966 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002967 *
2968 * At some future point, this check could be move to the top of the
2969 * function, and do a quick early-return when state is
2970 * pre-Established, avoiding above list and table scans. Once we're
2971 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002972 */
2973 if (!peer->clear_node_queue->thread)
2974 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002975}
2976
2977void
2978bgp_clear_route_all (struct peer *peer)
2979{
2980 afi_t afi;
2981 safi_t safi;
2982
2983 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2984 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002985 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002986}
2987
2988void
2989bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2990{
2991 struct bgp_table *table;
2992 struct bgp_node *rn;
2993 struct bgp_adj_in *ain;
2994
2995 table = peer->bgp->rib[afi][safi];
2996
2997 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2998 for (ain = rn->adj_in; ain ; ain = ain->next)
2999 if (ain->peer == peer)
3000 {
3001 bgp_adj_in_remove (rn, ain);
3002 bgp_unlock_node (rn);
3003 break;
3004 }
3005}
hasso93406d82005-02-02 14:40:33 +00003006
3007void
3008bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3009{
3010 struct bgp_node *rn;
3011 struct bgp_info *ri;
3012 struct bgp_table *table;
3013
3014 table = peer->bgp->rib[afi][safi];
3015
3016 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3017 {
3018 for (ri = rn->info; ri; ri = ri->next)
3019 if (ri->peer == peer)
3020 {
3021 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3022 bgp_rib_remove (rn, ri, peer, afi, safi);
3023 break;
3024 }
3025 }
3026}
paul718e3742002-12-13 20:15:29 +00003027
3028/* Delete all kernel routes. */
3029void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003030bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003031{
3032 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003033 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003034 struct bgp_node *rn;
3035 struct bgp_table *table;
3036 struct bgp_info *ri;
3037
paul1eb8ef22005-04-07 07:30:20 +00003038 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003039 {
3040 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3041
3042 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3043 for (ri = rn->info; ri; ri = ri->next)
3044 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3045 && ri->type == ZEBRA_ROUTE_BGP
3046 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003047 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003048
3049 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3050
3051 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3052 for (ri = rn->info; ri; ri = ri->next)
3053 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3054 && ri->type == ZEBRA_ROUTE_BGP
3055 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003056 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003057 }
3058}
3059
3060void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003061bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003062{
3063 vty_reset ();
3064 bgp_zclient_reset ();
3065 access_list_reset ();
3066 prefix_list_reset ();
3067}
3068
3069/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3070 value. */
3071int
3072bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3073{
3074 u_char *pnt;
3075 u_char *lim;
3076 struct prefix p;
3077 int psize;
3078 int ret;
3079
3080 /* Check peer status. */
3081 if (peer->status != Established)
3082 return 0;
3083
3084 pnt = packet->nlri;
3085 lim = pnt + packet->length;
3086
3087 for (; pnt < lim; pnt += psize)
3088 {
3089 /* Clear prefix structure. */
3090 memset (&p, 0, sizeof (struct prefix));
3091
3092 /* Fetch prefix length. */
3093 p.prefixlen = *pnt++;
3094 p.family = afi2family (packet->afi);
3095
3096 /* Already checked in nlri_sanity_check(). We do double check
3097 here. */
3098 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3099 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3100 return -1;
3101
3102 /* Packet size overflow check. */
3103 psize = PSIZE (p.prefixlen);
3104
3105 /* When packet overflow occur return immediately. */
3106 if (pnt + psize > lim)
3107 return -1;
3108
3109 /* Fetch prefix from NLRI packet. */
3110 memcpy (&p.u.prefix, pnt, psize);
3111
3112 /* Check address. */
3113 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3114 {
3115 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3116 {
paulf5ba3872004-07-09 12:11:31 +00003117 /*
3118 * From draft-ietf-idr-bgp4-22, Section 6.3:
3119 * If a BGP router receives an UPDATE message with a
3120 * semantically incorrect NLRI field, in which a prefix is
3121 * semantically incorrect (eg. an unexpected multicast IP
3122 * address), it should ignore the prefix.
3123 */
paul718e3742002-12-13 20:15:29 +00003124 zlog (peer->log, LOG_ERR,
3125 "IPv4 unicast NLRI is multicast address %s",
3126 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003127
paul718e3742002-12-13 20:15:29 +00003128 return -1;
3129 }
3130 }
3131
3132#ifdef HAVE_IPV6
3133 /* Check address. */
3134 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3135 {
3136 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3137 {
3138 char buf[BUFSIZ];
3139
3140 zlog (peer->log, LOG_WARNING,
3141 "IPv6 link-local NLRI received %s ignore this NLRI",
3142 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3143
3144 continue;
3145 }
3146 }
3147#endif /* HAVE_IPV6 */
3148
3149 /* Normal process. */
3150 if (attr)
3151 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3152 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3153 else
3154 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3155 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3156
3157 /* Address family configuration mismatch or maximum-prefix count
3158 overflow. */
3159 if (ret < 0)
3160 return -1;
3161 }
3162
3163 /* Packet length consistency check. */
3164 if (pnt != lim)
3165 return -1;
3166
3167 return 0;
3168}
3169
3170/* NLRI encode syntax check routine. */
3171int
3172bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3173 bgp_size_t length)
3174{
3175 u_char *end;
3176 u_char prefixlen;
3177 int psize;
3178
3179 end = pnt + length;
3180
3181 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3182 syntactic validity. If the field is syntactically incorrect,
3183 then the Error Subcode is set to Invalid Network Field. */
3184
3185 while (pnt < end)
3186 {
3187 prefixlen = *pnt++;
3188
3189 /* Prefix length check. */
3190 if ((afi == AFI_IP && prefixlen > 32)
3191 || (afi == AFI_IP6 && prefixlen > 128))
3192 {
3193 plog_err (peer->log,
3194 "%s [Error] Update packet error (wrong prefix length %d)",
3195 peer->host, prefixlen);
3196 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3197 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3198 return -1;
3199 }
3200
3201 /* Packet size overflow check. */
3202 psize = PSIZE (prefixlen);
3203
3204 if (pnt + psize > end)
3205 {
3206 plog_err (peer->log,
3207 "%s [Error] Update packet error"
3208 " (prefix data overflow prefix size is %d)",
3209 peer->host, psize);
3210 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3211 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3212 return -1;
3213 }
3214
3215 pnt += psize;
3216 }
3217
3218 /* Packet length consistency check. */
3219 if (pnt != end)
3220 {
3221 plog_err (peer->log,
3222 "%s [Error] Update packet error"
3223 " (prefix length mismatch with total length)",
3224 peer->host);
3225 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3226 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3227 return -1;
3228 }
3229 return 0;
3230}
3231
paul94f2b392005-06-28 12:44:16 +00003232static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003233bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003234{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003235 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003236}
3237
paul94f2b392005-06-28 12:44:16 +00003238static void
paul718e3742002-12-13 20:15:29 +00003239bgp_static_free (struct bgp_static *bgp_static)
3240{
3241 if (bgp_static->rmap.name)
3242 free (bgp_static->rmap.name);
3243 XFREE (MTYPE_BGP_STATIC, bgp_static);
3244}
3245
paul94f2b392005-06-28 12:44:16 +00003246static void
paulfee0f4c2004-09-13 05:12:46 +00003247bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3248 struct prefix *p, afi_t afi, safi_t safi)
3249{
3250 struct bgp_node *rn;
3251 struct bgp_info *ri;
3252
3253 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3254
3255 /* Check selected route and self inserted route. */
3256 for (ri = rn->info; ri; ri = ri->next)
3257 if (ri->peer == bgp->peer_self
3258 && ri->type == ZEBRA_ROUTE_BGP
3259 && ri->sub_type == BGP_ROUTE_STATIC)
3260 break;
3261
3262 /* Withdraw static BGP route from routing table. */
3263 if (ri)
3264 {
paulfee0f4c2004-09-13 05:12:46 +00003265 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003266 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003267 }
3268
3269 /* Unlock bgp_node_lookup. */
3270 bgp_unlock_node (rn);
3271}
3272
paul94f2b392005-06-28 12:44:16 +00003273static void
paulfee0f4c2004-09-13 05:12:46 +00003274bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003275 struct bgp_static *bgp_static,
3276 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003277{
3278 struct bgp_node *rn;
3279 struct bgp_info *ri;
3280 struct bgp_info *new;
3281 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003282 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003283 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003284 struct attr new_attr;
3285 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003286 struct bgp *bgp;
3287 int ret;
3288 char buf[SU_ADDRSTRLEN];
3289
3290 bgp = rsclient->bgp;
3291
Paul Jakma06e110f2006-05-12 23:29:22 +00003292 assert (bgp_static);
3293 if (!bgp_static)
3294 return;
3295
paulfee0f4c2004-09-13 05:12:46 +00003296 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3297
3298 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003299
3300 attr.nexthop = bgp_static->igpnexthop;
3301 attr.med = bgp_static->igpmetric;
3302 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003303
Paul Jakma41367172007-08-06 15:24:51 +00003304 if (bgp_static->atomic)
3305 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3306
paulfee0f4c2004-09-13 05:12:46 +00003307 /* Apply network route-map for export to this rsclient. */
3308 if (bgp_static->rmap.name)
3309 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003310 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003311 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003312 info.attr = &attr_tmp;
3313
paulfee0f4c2004-09-13 05:12:46 +00003314 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3315 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3316
3317 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3318
3319 rsclient->rmap_type = 0;
3320
3321 if (ret == RMAP_DENYMATCH)
3322 {
3323 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003324 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003325
3326 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003327 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003328 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003329 bgp_attr_extra_free (&attr);
3330
paulfee0f4c2004-09-13 05:12:46 +00003331 return;
3332 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003333 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003334 }
3335 else
3336 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003337
3338 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003339 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003340
paulfee0f4c2004-09-13 05:12:46 +00003341 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3342
Paul Jakmafb982c22007-05-04 20:15:47 +00003343 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3344 == RMAP_DENY)
3345 {
paulfee0f4c2004-09-13 05:12:46 +00003346 /* This BGP update is filtered. Log the reason then update BGP entry. */
3347 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003348 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003349 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3350 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3351 p->prefixlen, rsclient->host);
3352
3353 bgp->peer_self->rmap_type = 0;
3354
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003355 bgp_attr_unintern (&attr_new);
3356 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003357 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003358
3359 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3360
3361 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 }
paulfee0f4c2004-09-13 05:12:46 +00003363
3364 bgp->peer_self->rmap_type = 0;
3365
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003366 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003367 attr_new = bgp_attr_intern (&new_attr);
3368
3369 for (ri = rn->info; ri; ri = ri->next)
3370 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3371 && ri->sub_type == BGP_ROUTE_STATIC)
3372 break;
3373
3374 if (ri)
3375 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003376 if (attrhash_cmp (ri->attr, attr_new) &&
3377 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003378 {
3379 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003380 bgp_attr_unintern (&attr_new);
3381 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003382 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003383 return;
3384 }
3385 else
3386 {
3387 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003388 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003389
3390 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003391 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3392 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003393 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003394 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003395 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003396
3397 /* Process change. */
3398 bgp_process (bgp, rn, afi, safi);
3399 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003400 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003401 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003402 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003403 }
paulfee0f4c2004-09-13 05:12:46 +00003404 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003405
paulfee0f4c2004-09-13 05:12:46 +00003406 /* Make new BGP info. */
3407 new = bgp_info_new ();
3408 new->type = ZEBRA_ROUTE_BGP;
3409 new->sub_type = BGP_ROUTE_STATIC;
3410 new->peer = bgp->peer_self;
3411 SET_FLAG (new->flags, BGP_INFO_VALID);
3412 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003413 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003414
3415 /* Register new BGP information. */
3416 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003417
3418 /* route_node_get lock */
3419 bgp_unlock_node (rn);
3420
paulfee0f4c2004-09-13 05:12:46 +00003421 /* Process change. */
3422 bgp_process (bgp, rn, afi, safi);
3423
3424 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003425 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003426 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003427}
3428
paul94f2b392005-06-28 12:44:16 +00003429static void
paulfee0f4c2004-09-13 05:12:46 +00003430bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003431 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3432{
3433 struct bgp_node *rn;
3434 struct bgp_info *ri;
3435 struct bgp_info *new;
3436 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003437 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003438 struct attr *attr_new;
3439 int ret;
3440
Paul Jakmadd8103a2006-05-12 23:27:30 +00003441 assert (bgp_static);
3442 if (!bgp_static)
3443 return;
3444
paulfee0f4c2004-09-13 05:12:46 +00003445 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003446
3447 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003448
3449 attr.nexthop = bgp_static->igpnexthop;
3450 attr.med = bgp_static->igpmetric;
3451 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003452
Paul Jakma41367172007-08-06 15:24:51 +00003453 if (bgp_static->atomic)
3454 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3455
paul718e3742002-12-13 20:15:29 +00003456 /* Apply route-map. */
3457 if (bgp_static->rmap.name)
3458 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003459 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003460 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003461 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003462
paulfee0f4c2004-09-13 05:12:46 +00003463 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3464
paul718e3742002-12-13 20:15:29 +00003465 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003466
paulfee0f4c2004-09-13 05:12:46 +00003467 bgp->peer_self->rmap_type = 0;
3468
paul718e3742002-12-13 20:15:29 +00003469 if (ret == RMAP_DENYMATCH)
3470 {
3471 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003472 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003473
3474 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003477 bgp_static_withdraw (bgp, p, afi, safi);
3478 return;
3479 }
paul286e1e72003-08-08 00:24:31 +00003480 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003481 }
paul286e1e72003-08-08 00:24:31 +00003482 else
3483 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003484
3485 for (ri = rn->info; ri; ri = ri->next)
3486 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3487 && ri->sub_type == BGP_ROUTE_STATIC)
3488 break;
3489
3490 if (ri)
3491 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003492 if (attrhash_cmp (ri->attr, attr_new) &&
3493 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003494 {
3495 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 bgp_attr_unintern (&attr_new);
3497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003499 return;
3500 }
3501 else
3502 {
3503 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003504 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003505
3506 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003507 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3508 bgp_info_restore(rn, ri);
3509 else
3510 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003511 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003512 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003513 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003514
3515 /* Process change. */
3516 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3517 bgp_process (bgp, rn, afi, safi);
3518 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003519 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003521 return;
3522 }
3523 }
3524
3525 /* Make new BGP info. */
3526 new = bgp_info_new ();
3527 new->type = ZEBRA_ROUTE_BGP;
3528 new->sub_type = BGP_ROUTE_STATIC;
3529 new->peer = bgp->peer_self;
3530 SET_FLAG (new->flags, BGP_INFO_VALID);
3531 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003532 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003533
3534 /* Aggregate address increment. */
3535 bgp_aggregate_increment (bgp, p, new, afi, safi);
3536
3537 /* Register new BGP information. */
3538 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003539
3540 /* route_node_get lock */
3541 bgp_unlock_node (rn);
3542
paul718e3742002-12-13 20:15:29 +00003543 /* Process change. */
3544 bgp_process (bgp, rn, afi, safi);
3545
3546 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003549}
3550
3551void
paulfee0f4c2004-09-13 05:12:46 +00003552bgp_static_update (struct bgp *bgp, struct prefix *p,
3553 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3554{
3555 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003556 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003557
3558 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3559
paul1eb8ef22005-04-07 07:30:20 +00003560 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003561 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003562 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3563 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003564 }
3565}
3566
paul94f2b392005-06-28 12:44:16 +00003567static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003568bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3569 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003570{
3571 struct bgp_node *rn;
3572 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003573
paulfee0f4c2004-09-13 05:12:46 +00003574 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003575
3576 /* Make new BGP info. */
3577 new = bgp_info_new ();
3578 new->type = ZEBRA_ROUTE_BGP;
3579 new->sub_type = BGP_ROUTE_STATIC;
3580 new->peer = bgp->peer_self;
3581 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3582 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003583 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003584 new->extra = bgp_info_extra_new();
3585 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003586
3587 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003588 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003589
3590 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003591 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003592
paul200df112005-06-01 11:17:05 +00003593 /* route_node_get lock */
3594 bgp_unlock_node (rn);
3595
paul718e3742002-12-13 20:15:29 +00003596 /* Process change. */
3597 bgp_process (bgp, rn, afi, safi);
3598}
3599
3600void
3601bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3602 safi_t safi)
3603{
3604 struct bgp_node *rn;
3605 struct bgp_info *ri;
3606
paulfee0f4c2004-09-13 05:12:46 +00003607 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003608
3609 /* Check selected route and self inserted route. */
3610 for (ri = rn->info; ri; ri = ri->next)
3611 if (ri->peer == bgp->peer_self
3612 && ri->type == ZEBRA_ROUTE_BGP
3613 && ri->sub_type == BGP_ROUTE_STATIC)
3614 break;
3615
3616 /* Withdraw static BGP route from routing table. */
3617 if (ri)
3618 {
3619 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003620 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003621 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003622 }
3623
3624 /* Unlock bgp_node_lookup. */
3625 bgp_unlock_node (rn);
3626}
3627
3628void
paulfee0f4c2004-09-13 05:12:46 +00003629bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3630{
3631 struct bgp_static *bgp_static;
3632 struct bgp *bgp;
3633 struct bgp_node *rn;
3634 struct prefix *p;
3635
3636 bgp = rsclient->bgp;
3637
3638 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3639 if ((bgp_static = rn->info) != NULL)
3640 {
3641 p = &rn->p;
3642
3643 bgp_static_update_rsclient (rsclient, p, bgp_static,
3644 afi, safi);
3645 }
3646}
3647
paul94f2b392005-06-28 12:44:16 +00003648static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003649bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3650 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003651{
3652 struct bgp_node *rn;
3653 struct bgp_info *ri;
3654
paulfee0f4c2004-09-13 05:12:46 +00003655 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003656
3657 /* Check selected route and self inserted route. */
3658 for (ri = rn->info; ri; ri = ri->next)
3659 if (ri->peer == bgp->peer_self
3660 && ri->type == ZEBRA_ROUTE_BGP
3661 && ri->sub_type == BGP_ROUTE_STATIC)
3662 break;
3663
3664 /* Withdraw static BGP route from routing table. */
3665 if (ri)
3666 {
3667 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003668 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003669 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003670 }
3671
3672 /* Unlock bgp_node_lookup. */
3673 bgp_unlock_node (rn);
3674}
3675
3676/* Configure static BGP network. When user don't run zebra, static
3677 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003678static int
paulfd79ac92004-10-13 05:06:08 +00003679bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003680 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003681{
3682 int ret;
3683 struct prefix p;
3684 struct bgp_static *bgp_static;
3685 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003686 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003687
3688 /* Convert IP prefix string to struct prefix. */
3689 ret = str2prefix (ip_str, &p);
3690 if (! ret)
3691 {
3692 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3693 return CMD_WARNING;
3694 }
3695#ifdef HAVE_IPV6
3696 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3697 {
3698 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3699 VTY_NEWLINE);
3700 return CMD_WARNING;
3701 }
3702#endif /* HAVE_IPV6 */
3703
3704 apply_mask (&p);
3705
3706 /* Set BGP static route configuration. */
3707 rn = bgp_node_get (bgp->route[afi][safi], &p);
3708
3709 if (rn->info)
3710 {
3711 /* Configuration change. */
3712 bgp_static = rn->info;
3713
3714 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003715 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3716 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003717
paul718e3742002-12-13 20:15:29 +00003718 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003719
paul718e3742002-12-13 20:15:29 +00003720 if (rmap)
3721 {
3722 if (bgp_static->rmap.name)
3723 free (bgp_static->rmap.name);
3724 bgp_static->rmap.name = strdup (rmap);
3725 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3726 }
3727 else
3728 {
3729 if (bgp_static->rmap.name)
3730 free (bgp_static->rmap.name);
3731 bgp_static->rmap.name = NULL;
3732 bgp_static->rmap.map = NULL;
3733 bgp_static->valid = 0;
3734 }
3735 bgp_unlock_node (rn);
3736 }
3737 else
3738 {
3739 /* New configuration. */
3740 bgp_static = bgp_static_new ();
3741 bgp_static->backdoor = backdoor;
3742 bgp_static->valid = 0;
3743 bgp_static->igpmetric = 0;
3744 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003745
paul718e3742002-12-13 20:15:29 +00003746 if (rmap)
3747 {
3748 if (bgp_static->rmap.name)
3749 free (bgp_static->rmap.name);
3750 bgp_static->rmap.name = strdup (rmap);
3751 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3752 }
3753 rn->info = bgp_static;
3754 }
3755
3756 /* If BGP scan is not enabled, we should install this route here. */
3757 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3758 {
3759 bgp_static->valid = 1;
3760
3761 if (need_update)
3762 bgp_static_withdraw (bgp, &p, afi, safi);
3763
3764 if (! bgp_static->backdoor)
3765 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3766 }
3767
3768 return CMD_SUCCESS;
3769}
3770
3771/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003772static int
paulfd79ac92004-10-13 05:06:08 +00003773bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003774 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003775{
3776 int ret;
3777 struct prefix p;
3778 struct bgp_static *bgp_static;
3779 struct bgp_node *rn;
3780
3781 /* Convert IP prefix string to struct prefix. */
3782 ret = str2prefix (ip_str, &p);
3783 if (! ret)
3784 {
3785 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3786 return CMD_WARNING;
3787 }
3788#ifdef HAVE_IPV6
3789 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3790 {
3791 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3792 VTY_NEWLINE);
3793 return CMD_WARNING;
3794 }
3795#endif /* HAVE_IPV6 */
3796
3797 apply_mask (&p);
3798
3799 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3800 if (! rn)
3801 {
3802 vty_out (vty, "%% Can't find specified static route configuration.%s",
3803 VTY_NEWLINE);
3804 return CMD_WARNING;
3805 }
3806
3807 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003808
paul718e3742002-12-13 20:15:29 +00003809 /* Update BGP RIB. */
3810 if (! bgp_static->backdoor)
3811 bgp_static_withdraw (bgp, &p, afi, safi);
3812
3813 /* Clear configuration. */
3814 bgp_static_free (bgp_static);
3815 rn->info = NULL;
3816 bgp_unlock_node (rn);
3817 bgp_unlock_node (rn);
3818
3819 return CMD_SUCCESS;
3820}
3821
3822/* Called from bgp_delete(). Delete all static routes from the BGP
3823 instance. */
3824void
3825bgp_static_delete (struct bgp *bgp)
3826{
3827 afi_t afi;
3828 safi_t safi;
3829 struct bgp_node *rn;
3830 struct bgp_node *rm;
3831 struct bgp_table *table;
3832 struct bgp_static *bgp_static;
3833
3834 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3835 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3836 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3837 if (rn->info != NULL)
3838 {
3839 if (safi == SAFI_MPLS_VPN)
3840 {
3841 table = rn->info;
3842
3843 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3844 {
3845 bgp_static = rn->info;
3846 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3847 AFI_IP, SAFI_MPLS_VPN,
3848 (struct prefix_rd *)&rn->p,
3849 bgp_static->tag);
3850 bgp_static_free (bgp_static);
3851 rn->info = NULL;
3852 bgp_unlock_node (rn);
3853 }
3854 }
3855 else
3856 {
3857 bgp_static = rn->info;
3858 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3859 bgp_static_free (bgp_static);
3860 rn->info = NULL;
3861 bgp_unlock_node (rn);
3862 }
3863 }
3864}
3865
3866int
paulfd79ac92004-10-13 05:06:08 +00003867bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3868 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003869{
3870 int ret;
3871 struct prefix p;
3872 struct prefix_rd prd;
3873 struct bgp *bgp;
3874 struct bgp_node *prn;
3875 struct bgp_node *rn;
3876 struct bgp_table *table;
3877 struct bgp_static *bgp_static;
3878 u_char tag[3];
3879
3880 bgp = vty->index;
3881
3882 ret = str2prefix (ip_str, &p);
3883 if (! ret)
3884 {
3885 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3886 return CMD_WARNING;
3887 }
3888 apply_mask (&p);
3889
3890 ret = str2prefix_rd (rd_str, &prd);
3891 if (! ret)
3892 {
3893 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3894 return CMD_WARNING;
3895 }
3896
3897 ret = str2tag (tag_str, tag);
3898 if (! ret)
3899 {
3900 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3901 return CMD_WARNING;
3902 }
3903
3904 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3905 (struct prefix *)&prd);
3906 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003907 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003908 else
3909 bgp_unlock_node (prn);
3910 table = prn->info;
3911
3912 rn = bgp_node_get (table, &p);
3913
3914 if (rn->info)
3915 {
3916 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3917 bgp_unlock_node (rn);
3918 }
3919 else
3920 {
3921 /* New configuration. */
3922 bgp_static = bgp_static_new ();
3923 bgp_static->valid = 1;
3924 memcpy (bgp_static->tag, tag, 3);
3925 rn->info = bgp_static;
3926
3927 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3928 }
3929
3930 return CMD_SUCCESS;
3931}
3932
3933/* Configure static BGP network. */
3934int
paulfd79ac92004-10-13 05:06:08 +00003935bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3936 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003937{
3938 int ret;
3939 struct bgp *bgp;
3940 struct prefix p;
3941 struct prefix_rd prd;
3942 struct bgp_node *prn;
3943 struct bgp_node *rn;
3944 struct bgp_table *table;
3945 struct bgp_static *bgp_static;
3946 u_char tag[3];
3947
3948 bgp = vty->index;
3949
3950 /* Convert IP prefix string to struct prefix. */
3951 ret = str2prefix (ip_str, &p);
3952 if (! ret)
3953 {
3954 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3955 return CMD_WARNING;
3956 }
3957 apply_mask (&p);
3958
3959 ret = str2prefix_rd (rd_str, &prd);
3960 if (! ret)
3961 {
3962 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3963 return CMD_WARNING;
3964 }
3965
3966 ret = str2tag (tag_str, tag);
3967 if (! ret)
3968 {
3969 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3970 return CMD_WARNING;
3971 }
3972
3973 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3974 (struct prefix *)&prd);
3975 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003976 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003977 else
3978 bgp_unlock_node (prn);
3979 table = prn->info;
3980
3981 rn = bgp_node_lookup (table, &p);
3982
3983 if (rn)
3984 {
3985 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3986
3987 bgp_static = rn->info;
3988 bgp_static_free (bgp_static);
3989 rn->info = NULL;
3990 bgp_unlock_node (rn);
3991 bgp_unlock_node (rn);
3992 }
3993 else
3994 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3995
3996 return CMD_SUCCESS;
3997}
3998
3999DEFUN (bgp_network,
4000 bgp_network_cmd,
4001 "network A.B.C.D/M",
4002 "Specify a network to announce via BGP\n"
4003 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4004{
4005 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004006 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004007}
4008
4009DEFUN (bgp_network_route_map,
4010 bgp_network_route_map_cmd,
4011 "network A.B.C.D/M route-map WORD",
4012 "Specify a network to announce via BGP\n"
4013 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4014 "Route-map to modify the attributes\n"
4015 "Name of the route map\n")
4016{
4017 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004018 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004019}
4020
4021DEFUN (bgp_network_backdoor,
4022 bgp_network_backdoor_cmd,
4023 "network A.B.C.D/M backdoor",
4024 "Specify a network to announce via BGP\n"
4025 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4026 "Specify a BGP backdoor route\n")
4027{
Paul Jakma41367172007-08-06 15:24:51 +00004028 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004029 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004030}
4031
4032DEFUN (bgp_network_mask,
4033 bgp_network_mask_cmd,
4034 "network A.B.C.D mask A.B.C.D",
4035 "Specify a network to announce via BGP\n"
4036 "Network number\n"
4037 "Network mask\n"
4038 "Network mask\n")
4039{
4040 int ret;
4041 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004042
paul718e3742002-12-13 20:15:29 +00004043 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4044 if (! ret)
4045 {
4046 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4047 return CMD_WARNING;
4048 }
4049
4050 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004051 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004052}
4053
4054DEFUN (bgp_network_mask_route_map,
4055 bgp_network_mask_route_map_cmd,
4056 "network A.B.C.D mask A.B.C.D route-map WORD",
4057 "Specify a network to announce via BGP\n"
4058 "Network number\n"
4059 "Network mask\n"
4060 "Network mask\n"
4061 "Route-map to modify the attributes\n"
4062 "Name of the route map\n")
4063{
4064 int ret;
4065 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004066
paul718e3742002-12-13 20:15:29 +00004067 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4068 if (! ret)
4069 {
4070 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4071 return CMD_WARNING;
4072 }
4073
4074 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004075 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004076}
4077
4078DEFUN (bgp_network_mask_backdoor,
4079 bgp_network_mask_backdoor_cmd,
4080 "network A.B.C.D mask A.B.C.D backdoor",
4081 "Specify a network to announce via BGP\n"
4082 "Network number\n"
4083 "Network mask\n"
4084 "Network mask\n"
4085 "Specify a BGP backdoor route\n")
4086{
4087 int ret;
4088 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004089
paul718e3742002-12-13 20:15:29 +00004090 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4091 if (! ret)
4092 {
4093 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4094 return CMD_WARNING;
4095 }
4096
Paul Jakma41367172007-08-06 15:24:51 +00004097 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004098 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004099}
4100
4101DEFUN (bgp_network_mask_natural,
4102 bgp_network_mask_natural_cmd,
4103 "network A.B.C.D",
4104 "Specify a network to announce via BGP\n"
4105 "Network number\n")
4106{
4107 int ret;
4108 char prefix_str[BUFSIZ];
4109
4110 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116
4117 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004118 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004119}
4120
4121DEFUN (bgp_network_mask_natural_route_map,
4122 bgp_network_mask_natural_route_map_cmd,
4123 "network A.B.C.D route-map WORD",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n"
4126 "Route-map to modify the attributes\n"
4127 "Name of the route map\n")
4128{
4129 int ret;
4130 char prefix_str[BUFSIZ];
4131
4132 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4133 if (! ret)
4134 {
4135 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4136 return CMD_WARNING;
4137 }
4138
4139 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004140 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004141}
4142
4143DEFUN (bgp_network_mask_natural_backdoor,
4144 bgp_network_mask_natural_backdoor_cmd,
4145 "network A.B.C.D backdoor",
4146 "Specify a network to announce via BGP\n"
4147 "Network number\n"
4148 "Specify a BGP backdoor route\n")
4149{
4150 int ret;
4151 char prefix_str[BUFSIZ];
4152
4153 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4154 if (! ret)
4155 {
4156 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4157 return CMD_WARNING;
4158 }
4159
Paul Jakma41367172007-08-06 15:24:51 +00004160 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004161 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004162}
4163
4164DEFUN (no_bgp_network,
4165 no_bgp_network_cmd,
4166 "no network A.B.C.D/M",
4167 NO_STR
4168 "Specify a network to announce via BGP\n"
4169 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4170{
4171 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4172 bgp_node_safi (vty));
4173}
4174
4175ALIAS (no_bgp_network,
4176 no_bgp_network_route_map_cmd,
4177 "no network A.B.C.D/M route-map WORD",
4178 NO_STR
4179 "Specify a network to announce via BGP\n"
4180 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4181 "Route-map to modify the attributes\n"
4182 "Name of the route map\n")
4183
4184ALIAS (no_bgp_network,
4185 no_bgp_network_backdoor_cmd,
4186 "no network A.B.C.D/M backdoor",
4187 NO_STR
4188 "Specify a network to announce via BGP\n"
4189 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4190 "Specify a BGP backdoor route\n")
4191
4192DEFUN (no_bgp_network_mask,
4193 no_bgp_network_mask_cmd,
4194 "no network A.B.C.D mask A.B.C.D",
4195 NO_STR
4196 "Specify a network to announce via BGP\n"
4197 "Network number\n"
4198 "Network mask\n"
4199 "Network mask\n")
4200{
4201 int ret;
4202 char prefix_str[BUFSIZ];
4203
4204 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4205 if (! ret)
4206 {
4207 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4208 return CMD_WARNING;
4209 }
4210
4211 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4212 bgp_node_safi (vty));
4213}
4214
4215ALIAS (no_bgp_network_mask,
4216 no_bgp_network_mask_route_map_cmd,
4217 "no network A.B.C.D mask A.B.C.D route-map WORD",
4218 NO_STR
4219 "Specify a network to announce via BGP\n"
4220 "Network number\n"
4221 "Network mask\n"
4222 "Network mask\n"
4223 "Route-map to modify the attributes\n"
4224 "Name of the route map\n")
4225
4226ALIAS (no_bgp_network_mask,
4227 no_bgp_network_mask_backdoor_cmd,
4228 "no network A.B.C.D mask A.B.C.D backdoor",
4229 NO_STR
4230 "Specify a network to announce via BGP\n"
4231 "Network number\n"
4232 "Network mask\n"
4233 "Network mask\n"
4234 "Specify a BGP backdoor route\n")
4235
4236DEFUN (no_bgp_network_mask_natural,
4237 no_bgp_network_mask_natural_cmd,
4238 "no network A.B.C.D",
4239 NO_STR
4240 "Specify a network to announce via BGP\n"
4241 "Network number\n")
4242{
4243 int ret;
4244 char prefix_str[BUFSIZ];
4245
4246 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4247 if (! ret)
4248 {
4249 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4250 return CMD_WARNING;
4251 }
4252
4253 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4254 bgp_node_safi (vty));
4255}
4256
4257ALIAS (no_bgp_network_mask_natural,
4258 no_bgp_network_mask_natural_route_map_cmd,
4259 "no network A.B.C.D route-map WORD",
4260 NO_STR
4261 "Specify a network to announce via BGP\n"
4262 "Network number\n"
4263 "Route-map to modify the attributes\n"
4264 "Name of the route map\n")
4265
4266ALIAS (no_bgp_network_mask_natural,
4267 no_bgp_network_mask_natural_backdoor_cmd,
4268 "no network A.B.C.D backdoor",
4269 NO_STR
4270 "Specify a network to announce via BGP\n"
4271 "Network number\n"
4272 "Specify a BGP backdoor route\n")
4273
4274#ifdef HAVE_IPV6
4275DEFUN (ipv6_bgp_network,
4276 ipv6_bgp_network_cmd,
4277 "network X:X::X:X/M",
4278 "Specify a network to announce via BGP\n"
4279 "IPv6 prefix <network>/<length>\n")
4280{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304281 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004282 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004283}
4284
4285DEFUN (ipv6_bgp_network_route_map,
4286 ipv6_bgp_network_route_map_cmd,
4287 "network X:X::X:X/M route-map WORD",
4288 "Specify a network to announce via BGP\n"
4289 "IPv6 prefix <network>/<length>\n"
4290 "Route-map to modify the attributes\n"
4291 "Name of the route map\n")
4292{
4293 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004294 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004295}
4296
4297DEFUN (no_ipv6_bgp_network,
4298 no_ipv6_bgp_network_cmd,
4299 "no network X:X::X:X/M",
4300 NO_STR
4301 "Specify a network to announce via BGP\n"
4302 "IPv6 prefix <network>/<length>\n")
4303{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304304 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004305}
4306
4307ALIAS (no_ipv6_bgp_network,
4308 no_ipv6_bgp_network_route_map_cmd,
4309 "no network X:X::X:X/M route-map WORD",
4310 NO_STR
4311 "Specify a network to announce via BGP\n"
4312 "IPv6 prefix <network>/<length>\n"
4313 "Route-map to modify the attributes\n"
4314 "Name of the route map\n")
4315
4316ALIAS (ipv6_bgp_network,
4317 old_ipv6_bgp_network_cmd,
4318 "ipv6 bgp network X:X::X:X/M",
4319 IPV6_STR
4320 BGP_STR
4321 "Specify a network to announce via BGP\n"
4322 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4323
4324ALIAS (no_ipv6_bgp_network,
4325 old_no_ipv6_bgp_network_cmd,
4326 "no ipv6 bgp network X:X::X:X/M",
4327 NO_STR
4328 IPV6_STR
4329 BGP_STR
4330 "Specify a network to announce via BGP\n"
4331 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4332#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004333
4334/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4335ALIAS_DEPRECATED (bgp_network,
4336 bgp_network_ttl_cmd,
4337 "network A.B.C.D/M pathlimit <0-255>",
4338 "Specify a network to announce via BGP\n"
4339 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4340 "AS-Path hopcount limit attribute\n"
4341 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4342ALIAS_DEPRECATED (bgp_network_backdoor,
4343 bgp_network_backdoor_ttl_cmd,
4344 "network A.B.C.D/M backdoor pathlimit <0-255>",
4345 "Specify a network to announce via BGP\n"
4346 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4347 "Specify a BGP backdoor route\n"
4348 "AS-Path hopcount limit attribute\n"
4349 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4350ALIAS_DEPRECATED (bgp_network_mask,
4351 bgp_network_mask_ttl_cmd,
4352 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4353 "Specify a network to announce via BGP\n"
4354 "Network number\n"
4355 "Network mask\n"
4356 "Network mask\n"
4357 "AS-Path hopcount limit attribute\n"
4358 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4359ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4360 bgp_network_mask_backdoor_ttl_cmd,
4361 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Specify a BGP backdoor route\n"
4367 "AS-Path hopcount limit attribute\n"
4368 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4369ALIAS_DEPRECATED (bgp_network_mask_natural,
4370 bgp_network_mask_natural_ttl_cmd,
4371 "network A.B.C.D pathlimit <0-255>",
4372 "Specify a network to announce via BGP\n"
4373 "Network number\n"
4374 "AS-Path hopcount limit attribute\n"
4375 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4376ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4377 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004378 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004379 "Specify a network to announce via BGP\n"
4380 "Network number\n"
4381 "Specify a BGP backdoor route\n"
4382 "AS-Path hopcount limit attribute\n"
4383 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4384ALIAS_DEPRECATED (no_bgp_network,
4385 no_bgp_network_ttl_cmd,
4386 "no network A.B.C.D/M pathlimit <0-255>",
4387 NO_STR
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "AS-Path hopcount limit attribute\n"
4391 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4392ALIAS_DEPRECATED (no_bgp_network,
4393 no_bgp_network_backdoor_ttl_cmd,
4394 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4395 NO_STR
4396 "Specify a network to announce via BGP\n"
4397 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4398 "Specify a BGP backdoor route\n"
4399 "AS-Path hopcount limit attribute\n"
4400 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4401ALIAS_DEPRECATED (no_bgp_network,
4402 no_bgp_network_mask_ttl_cmd,
4403 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4404 NO_STR
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "Network mask\n"
4408 "Network mask\n"
4409 "AS-Path hopcount limit attribute\n"
4410 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4411ALIAS_DEPRECATED (no_bgp_network_mask,
4412 no_bgp_network_mask_backdoor_ttl_cmd,
4413 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4414 NO_STR
4415 "Specify a network to announce via BGP\n"
4416 "Network number\n"
4417 "Network mask\n"
4418 "Network mask\n"
4419 "Specify a BGP backdoor route\n"
4420 "AS-Path hopcount limit attribute\n"
4421 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4422ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4423 no_bgp_network_mask_natural_ttl_cmd,
4424 "no network A.B.C.D pathlimit <0-255>",
4425 NO_STR
4426 "Specify a network to announce via BGP\n"
4427 "Network number\n"
4428 "AS-Path hopcount limit attribute\n"
4429 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4430ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4431 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4432 "no network A.B.C.D backdoor pathlimit <0-255>",
4433 NO_STR
4434 "Specify a network to announce via BGP\n"
4435 "Network number\n"
4436 "Specify a BGP backdoor route\n"
4437 "AS-Path hopcount limit attribute\n"
4438 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004439#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004440ALIAS_DEPRECATED (ipv6_bgp_network,
4441 ipv6_bgp_network_ttl_cmd,
4442 "network X:X::X:X/M pathlimit <0-255>",
4443 "Specify a network to announce via BGP\n"
4444 "IPv6 prefix <network>/<length>\n"
4445 "AS-Path hopcount limit attribute\n"
4446 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4447ALIAS_DEPRECATED (no_ipv6_bgp_network,
4448 no_ipv6_bgp_network_ttl_cmd,
4449 "no network X:X::X:X/M pathlimit <0-255>",
4450 NO_STR
4451 "Specify a network to announce via BGP\n"
4452 "IPv6 prefix <network>/<length>\n"
4453 "AS-Path hopcount limit attribute\n"
4454 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004455#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004456
4457/* Aggreagete address:
4458
4459 advertise-map Set condition to advertise attribute
4460 as-set Generate AS set path information
4461 attribute-map Set attributes of aggregate
4462 route-map Set parameters of aggregate
4463 summary-only Filter more specific routes from updates
4464 suppress-map Conditionally filter more specific routes from updates
4465 <cr>
4466 */
4467struct bgp_aggregate
4468{
4469 /* Summary-only flag. */
4470 u_char summary_only;
4471
4472 /* AS set generation. */
4473 u_char as_set;
4474
4475 /* Route-map for aggregated route. */
4476 struct route_map *map;
4477
4478 /* Suppress-count. */
4479 unsigned long count;
4480
4481 /* SAFI configuration. */
4482 safi_t safi;
4483};
4484
paul94f2b392005-06-28 12:44:16 +00004485static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004486bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004487{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004488 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004489}
4490
paul94f2b392005-06-28 12:44:16 +00004491static void
paul718e3742002-12-13 20:15:29 +00004492bgp_aggregate_free (struct bgp_aggregate *aggregate)
4493{
4494 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4495}
4496
paul94f2b392005-06-28 12:44:16 +00004497static void
paul718e3742002-12-13 20:15:29 +00004498bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4499 afi_t afi, safi_t safi, struct bgp_info *del,
4500 struct bgp_aggregate *aggregate)
4501{
4502 struct bgp_table *table;
4503 struct bgp_node *top;
4504 struct bgp_node *rn;
4505 u_char origin;
4506 struct aspath *aspath = NULL;
4507 struct aspath *asmerge = NULL;
4508 struct community *community = NULL;
4509 struct community *commerge = NULL;
4510 struct in_addr nexthop;
4511 u_int32_t med = 0;
4512 struct bgp_info *ri;
4513 struct bgp_info *new;
4514 int first = 1;
4515 unsigned long match = 0;
4516
4517 /* Record adding route's nexthop and med. */
4518 if (rinew)
4519 {
4520 nexthop = rinew->attr->nexthop;
4521 med = rinew->attr->med;
4522 }
4523
4524 /* ORIGIN attribute: If at least one route among routes that are
4525 aggregated has ORIGIN with the value INCOMPLETE, then the
4526 aggregated route must have the ORIGIN attribute with the value
4527 INCOMPLETE. Otherwise, if at least one route among routes that
4528 are aggregated has ORIGIN with the value EGP, then the aggregated
4529 route must have the origin attribute with the value EGP. In all
4530 other case the value of the ORIGIN attribute of the aggregated
4531 route is INTERNAL. */
4532 origin = BGP_ORIGIN_IGP;
4533
4534 table = bgp->rib[afi][safi];
4535
4536 top = bgp_node_get (table, p);
4537 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4538 if (rn->p.prefixlen > p->prefixlen)
4539 {
4540 match = 0;
4541
4542 for (ri = rn->info; ri; ri = ri->next)
4543 {
4544 if (BGP_INFO_HOLDDOWN (ri))
4545 continue;
4546
4547 if (del && ri == del)
4548 continue;
4549
4550 if (! rinew && first)
4551 {
4552 nexthop = ri->attr->nexthop;
4553 med = ri->attr->med;
4554 first = 0;
4555 }
4556
4557#ifdef AGGREGATE_NEXTHOP_CHECK
4558 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4559 || ri->attr->med != med)
4560 {
4561 if (aspath)
4562 aspath_free (aspath);
4563 if (community)
4564 community_free (community);
4565 bgp_unlock_node (rn);
4566 bgp_unlock_node (top);
4567 return;
4568 }
4569#endif /* AGGREGATE_NEXTHOP_CHECK */
4570
4571 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4572 {
4573 if (aggregate->summary_only)
4574 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004575 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004576 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004577 match++;
4578 }
4579
4580 aggregate->count++;
4581
4582 if (aggregate->as_set)
4583 {
4584 if (origin < ri->attr->origin)
4585 origin = ri->attr->origin;
4586
4587 if (aspath)
4588 {
4589 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4590 aspath_free (aspath);
4591 aspath = asmerge;
4592 }
4593 else
4594 aspath = aspath_dup (ri->attr->aspath);
4595
4596 if (ri->attr->community)
4597 {
4598 if (community)
4599 {
4600 commerge = community_merge (community,
4601 ri->attr->community);
4602 community = community_uniq_sort (commerge);
4603 community_free (commerge);
4604 }
4605 else
4606 community = community_dup (ri->attr->community);
4607 }
4608 }
4609 }
4610 }
4611 if (match)
4612 bgp_process (bgp, rn, afi, safi);
4613 }
4614 bgp_unlock_node (top);
4615
4616 if (rinew)
4617 {
4618 aggregate->count++;
4619
4620 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004621 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004622
4623 if (aggregate->as_set)
4624 {
4625 if (origin < rinew->attr->origin)
4626 origin = rinew->attr->origin;
4627
4628 if (aspath)
4629 {
4630 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4631 aspath_free (aspath);
4632 aspath = asmerge;
4633 }
4634 else
4635 aspath = aspath_dup (rinew->attr->aspath);
4636
4637 if (rinew->attr->community)
4638 {
4639 if (community)
4640 {
4641 commerge = community_merge (community,
4642 rinew->attr->community);
4643 community = community_uniq_sort (commerge);
4644 community_free (commerge);
4645 }
4646 else
4647 community = community_dup (rinew->attr->community);
4648 }
4649 }
4650 }
4651
4652 if (aggregate->count > 0)
4653 {
4654 rn = bgp_node_get (table, p);
4655 new = bgp_info_new ();
4656 new->type = ZEBRA_ROUTE_BGP;
4657 new->sub_type = BGP_ROUTE_AGGREGATE;
4658 new->peer = bgp->peer_self;
4659 SET_FLAG (new->flags, BGP_INFO_VALID);
4660 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004661 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004662
4663 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004664 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004665 bgp_process (bgp, rn, afi, safi);
4666 }
4667 else
4668 {
4669 if (aspath)
4670 aspath_free (aspath);
4671 if (community)
4672 community_free (community);
4673 }
4674}
4675
4676void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4677 struct bgp_aggregate *);
4678
4679void
4680bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4681 struct bgp_info *ri, afi_t afi, safi_t safi)
4682{
4683 struct bgp_node *child;
4684 struct bgp_node *rn;
4685 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004686 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004687
4688 /* MPLS-VPN aggregation is not yet supported. */
4689 if (safi == SAFI_MPLS_VPN)
4690 return;
4691
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004692 table = bgp->aggregate[afi][safi];
4693
4694 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004695 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004696 return;
4697
paul718e3742002-12-13 20:15:29 +00004698 if (p->prefixlen == 0)
4699 return;
4700
4701 if (BGP_INFO_HOLDDOWN (ri))
4702 return;
4703
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004704 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004705
4706 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004707 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004708 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4709 {
4710 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004711 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004712 }
4713 bgp_unlock_node (child);
4714}
4715
4716void
4717bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4718 struct bgp_info *del, afi_t afi, safi_t safi)
4719{
4720 struct bgp_node *child;
4721 struct bgp_node *rn;
4722 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004723 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004724
4725 /* MPLS-VPN aggregation is not yet supported. */
4726 if (safi == SAFI_MPLS_VPN)
4727 return;
4728
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004729 table = bgp->aggregate[afi][safi];
4730
4731 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004732 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004733 return;
4734
paul718e3742002-12-13 20:15:29 +00004735 if (p->prefixlen == 0)
4736 return;
4737
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004738 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004739
4740 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004741 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004742 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4743 {
4744 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004745 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004746 }
4747 bgp_unlock_node (child);
4748}
4749
paul94f2b392005-06-28 12:44:16 +00004750static void
paul718e3742002-12-13 20:15:29 +00004751bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4752 struct bgp_aggregate *aggregate)
4753{
4754 struct bgp_table *table;
4755 struct bgp_node *top;
4756 struct bgp_node *rn;
4757 struct bgp_info *new;
4758 struct bgp_info *ri;
4759 unsigned long match;
4760 u_char origin = BGP_ORIGIN_IGP;
4761 struct aspath *aspath = NULL;
4762 struct aspath *asmerge = NULL;
4763 struct community *community = NULL;
4764 struct community *commerge = NULL;
4765
4766 table = bgp->rib[afi][safi];
4767
4768 /* Sanity check. */
4769 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4770 return;
4771 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4772 return;
4773
4774 /* If routes exists below this node, generate aggregate routes. */
4775 top = bgp_node_get (table, p);
4776 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4777 if (rn->p.prefixlen > p->prefixlen)
4778 {
4779 match = 0;
4780
4781 for (ri = rn->info; ri; ri = ri->next)
4782 {
4783 if (BGP_INFO_HOLDDOWN (ri))
4784 continue;
4785
4786 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4787 {
4788 /* summary-only aggregate route suppress aggregated
4789 route announcement. */
4790 if (aggregate->summary_only)
4791 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004792 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004793 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004794 match++;
4795 }
4796 /* as-set aggregate route generate origin, as path,
4797 community aggregation. */
4798 if (aggregate->as_set)
4799 {
4800 if (origin < ri->attr->origin)
4801 origin = ri->attr->origin;
4802
4803 if (aspath)
4804 {
4805 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4806 aspath_free (aspath);
4807 aspath = asmerge;
4808 }
4809 else
4810 aspath = aspath_dup (ri->attr->aspath);
4811
4812 if (ri->attr->community)
4813 {
4814 if (community)
4815 {
4816 commerge = community_merge (community,
4817 ri->attr->community);
4818 community = community_uniq_sort (commerge);
4819 community_free (commerge);
4820 }
4821 else
4822 community = community_dup (ri->attr->community);
4823 }
4824 }
4825 aggregate->count++;
4826 }
4827 }
4828
4829 /* If this node is suppressed, process the change. */
4830 if (match)
4831 bgp_process (bgp, rn, afi, safi);
4832 }
4833 bgp_unlock_node (top);
4834
4835 /* Add aggregate route to BGP table. */
4836 if (aggregate->count)
4837 {
4838 rn = bgp_node_get (table, p);
4839
4840 new = bgp_info_new ();
4841 new->type = ZEBRA_ROUTE_BGP;
4842 new->sub_type = BGP_ROUTE_AGGREGATE;
4843 new->peer = bgp->peer_self;
4844 SET_FLAG (new->flags, BGP_INFO_VALID);
4845 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004846 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004847
4848 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004849 bgp_unlock_node (rn);
4850
paul718e3742002-12-13 20:15:29 +00004851 /* Process change. */
4852 bgp_process (bgp, rn, afi, safi);
4853 }
4854}
4855
4856void
4857bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4858 safi_t safi, struct bgp_aggregate *aggregate)
4859{
4860 struct bgp_table *table;
4861 struct bgp_node *top;
4862 struct bgp_node *rn;
4863 struct bgp_info *ri;
4864 unsigned long match;
4865
4866 table = bgp->rib[afi][safi];
4867
4868 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4869 return;
4870 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4871 return;
4872
4873 /* If routes exists below this node, generate aggregate routes. */
4874 top = bgp_node_get (table, p);
4875 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4876 if (rn->p.prefixlen > p->prefixlen)
4877 {
4878 match = 0;
4879
4880 for (ri = rn->info; ri; ri = ri->next)
4881 {
4882 if (BGP_INFO_HOLDDOWN (ri))
4883 continue;
4884
4885 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4886 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004887 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004888 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004889 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004890
Paul Jakmafb982c22007-05-04 20:15:47 +00004891 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004892 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004893 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004894 match++;
4895 }
4896 }
4897 aggregate->count--;
4898 }
4899 }
4900
Paul Jakmafb982c22007-05-04 20:15:47 +00004901 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004902 if (match)
4903 bgp_process (bgp, rn, afi, safi);
4904 }
4905 bgp_unlock_node (top);
4906
4907 /* Delete aggregate route from BGP table. */
4908 rn = bgp_node_get (table, p);
4909
4910 for (ri = rn->info; ri; ri = ri->next)
4911 if (ri->peer == bgp->peer_self
4912 && ri->type == ZEBRA_ROUTE_BGP
4913 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4914 break;
4915
4916 /* Withdraw static BGP route from routing table. */
4917 if (ri)
4918 {
paul718e3742002-12-13 20:15:29 +00004919 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004920 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004921 }
4922
4923 /* Unlock bgp_node_lookup. */
4924 bgp_unlock_node (rn);
4925}
4926
4927/* Aggregate route attribute. */
4928#define AGGREGATE_SUMMARY_ONLY 1
4929#define AGGREGATE_AS_SET 1
4930
paul94f2b392005-06-28 12:44:16 +00004931static int
Robert Baysf6269b42010-08-05 10:26:28 -07004932bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4933 afi_t afi, safi_t safi)
4934{
4935 int ret;
4936 struct prefix p;
4937 struct bgp_node *rn;
4938 struct bgp *bgp;
4939 struct bgp_aggregate *aggregate;
4940
4941 /* Convert string to prefix structure. */
4942 ret = str2prefix (prefix_str, &p);
4943 if (!ret)
4944 {
4945 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4946 return CMD_WARNING;
4947 }
4948 apply_mask (&p);
4949
4950 /* Get BGP structure. */
4951 bgp = vty->index;
4952
4953 /* Old configuration check. */
4954 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4955 if (! rn)
4956 {
4957 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4958 VTY_NEWLINE);
4959 return CMD_WARNING;
4960 }
4961
4962 aggregate = rn->info;
4963 if (aggregate->safi & SAFI_UNICAST)
4964 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4965 if (aggregate->safi & SAFI_MULTICAST)
4966 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4967
4968 /* Unlock aggregate address configuration. */
4969 rn->info = NULL;
4970 bgp_aggregate_free (aggregate);
4971 bgp_unlock_node (rn);
4972 bgp_unlock_node (rn);
4973
4974 return CMD_SUCCESS;
4975}
4976
4977static int
4978bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004979 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004980 u_char summary_only, u_char as_set)
4981{
4982 int ret;
4983 struct prefix p;
4984 struct bgp_node *rn;
4985 struct bgp *bgp;
4986 struct bgp_aggregate *aggregate;
4987
4988 /* Convert string to prefix structure. */
4989 ret = str2prefix (prefix_str, &p);
4990 if (!ret)
4991 {
4992 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4993 return CMD_WARNING;
4994 }
4995 apply_mask (&p);
4996
4997 /* Get BGP structure. */
4998 bgp = vty->index;
4999
5000 /* Old configuration check. */
5001 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5002
5003 if (rn->info)
5004 {
5005 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005006 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005007 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5008 if (ret)
5009 {
Robert Bays368473f2010-08-05 10:26:29 -07005010 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5011 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005012 return CMD_WARNING;
5013 }
paul718e3742002-12-13 20:15:29 +00005014 }
5015
5016 /* Make aggregate address structure. */
5017 aggregate = bgp_aggregate_new ();
5018 aggregate->summary_only = summary_only;
5019 aggregate->as_set = as_set;
5020 aggregate->safi = safi;
5021 rn->info = aggregate;
5022
5023 /* Aggregate address insert into BGP routing table. */
5024 if (safi & SAFI_UNICAST)
5025 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5026 if (safi & SAFI_MULTICAST)
5027 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5028
5029 return CMD_SUCCESS;
5030}
5031
paul718e3742002-12-13 20:15:29 +00005032DEFUN (aggregate_address,
5033 aggregate_address_cmd,
5034 "aggregate-address A.B.C.D/M",
5035 "Configure BGP aggregate entries\n"
5036 "Aggregate prefix\n")
5037{
5038 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5039}
5040
5041DEFUN (aggregate_address_mask,
5042 aggregate_address_mask_cmd,
5043 "aggregate-address A.B.C.D A.B.C.D",
5044 "Configure BGP aggregate entries\n"
5045 "Aggregate address\n"
5046 "Aggregate mask\n")
5047{
5048 int ret;
5049 char prefix_str[BUFSIZ];
5050
5051 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5052
5053 if (! ret)
5054 {
5055 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5056 return CMD_WARNING;
5057 }
5058
5059 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5060 0, 0);
5061}
5062
5063DEFUN (aggregate_address_summary_only,
5064 aggregate_address_summary_only_cmd,
5065 "aggregate-address A.B.C.D/M summary-only",
5066 "Configure BGP aggregate entries\n"
5067 "Aggregate prefix\n"
5068 "Filter more specific routes from updates\n")
5069{
5070 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5071 AGGREGATE_SUMMARY_ONLY, 0);
5072}
5073
5074DEFUN (aggregate_address_mask_summary_only,
5075 aggregate_address_mask_summary_only_cmd,
5076 "aggregate-address A.B.C.D A.B.C.D summary-only",
5077 "Configure BGP aggregate entries\n"
5078 "Aggregate address\n"
5079 "Aggregate mask\n"
5080 "Filter more specific routes from updates\n")
5081{
5082 int ret;
5083 char prefix_str[BUFSIZ];
5084
5085 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5086
5087 if (! ret)
5088 {
5089 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5090 return CMD_WARNING;
5091 }
5092
5093 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5094 AGGREGATE_SUMMARY_ONLY, 0);
5095}
5096
5097DEFUN (aggregate_address_as_set,
5098 aggregate_address_as_set_cmd,
5099 "aggregate-address A.B.C.D/M as-set",
5100 "Configure BGP aggregate entries\n"
5101 "Aggregate prefix\n"
5102 "Generate AS set path information\n")
5103{
5104 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5105 0, AGGREGATE_AS_SET);
5106}
5107
5108DEFUN (aggregate_address_mask_as_set,
5109 aggregate_address_mask_as_set_cmd,
5110 "aggregate-address A.B.C.D A.B.C.D as-set",
5111 "Configure BGP aggregate entries\n"
5112 "Aggregate address\n"
5113 "Aggregate mask\n"
5114 "Generate AS set path information\n")
5115{
5116 int ret;
5117 char prefix_str[BUFSIZ];
5118
5119 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5120
5121 if (! ret)
5122 {
5123 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5124 return CMD_WARNING;
5125 }
5126
5127 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5128 0, AGGREGATE_AS_SET);
5129}
5130
5131
5132DEFUN (aggregate_address_as_set_summary,
5133 aggregate_address_as_set_summary_cmd,
5134 "aggregate-address A.B.C.D/M as-set summary-only",
5135 "Configure BGP aggregate entries\n"
5136 "Aggregate prefix\n"
5137 "Generate AS set path information\n"
5138 "Filter more specific routes from updates\n")
5139{
5140 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5141 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5142}
5143
5144ALIAS (aggregate_address_as_set_summary,
5145 aggregate_address_summary_as_set_cmd,
5146 "aggregate-address A.B.C.D/M summary-only as-set",
5147 "Configure BGP aggregate entries\n"
5148 "Aggregate prefix\n"
5149 "Filter more specific routes from updates\n"
5150 "Generate AS set path information\n")
5151
5152DEFUN (aggregate_address_mask_as_set_summary,
5153 aggregate_address_mask_as_set_summary_cmd,
5154 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate address\n"
5157 "Aggregate mask\n"
5158 "Generate AS set path information\n"
5159 "Filter more specific routes from updates\n")
5160{
5161 int ret;
5162 char prefix_str[BUFSIZ];
5163
5164 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5165
5166 if (! ret)
5167 {
5168 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5169 return CMD_WARNING;
5170 }
5171
5172 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5173 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5174}
5175
5176ALIAS (aggregate_address_mask_as_set_summary,
5177 aggregate_address_mask_summary_as_set_cmd,
5178 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate address\n"
5181 "Aggregate mask\n"
5182 "Filter more specific routes from updates\n"
5183 "Generate AS set path information\n")
5184
5185DEFUN (no_aggregate_address,
5186 no_aggregate_address_cmd,
5187 "no aggregate-address A.B.C.D/M",
5188 NO_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191{
5192 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5193}
5194
5195ALIAS (no_aggregate_address,
5196 no_aggregate_address_summary_only_cmd,
5197 "no aggregate-address A.B.C.D/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
5203ALIAS (no_aggregate_address,
5204 no_aggregate_address_as_set_cmd,
5205 "no aggregate-address A.B.C.D/M as-set",
5206 NO_STR
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n"
5209 "Generate AS set path information\n")
5210
5211ALIAS (no_aggregate_address,
5212 no_aggregate_address_as_set_summary_cmd,
5213 "no aggregate-address A.B.C.D/M as-set summary-only",
5214 NO_STR
5215 "Configure BGP aggregate entries\n"
5216 "Aggregate prefix\n"
5217 "Generate AS set path information\n"
5218 "Filter more specific routes from updates\n")
5219
5220ALIAS (no_aggregate_address,
5221 no_aggregate_address_summary_as_set_cmd,
5222 "no aggregate-address A.B.C.D/M summary-only as-set",
5223 NO_STR
5224 "Configure BGP aggregate entries\n"
5225 "Aggregate prefix\n"
5226 "Filter more specific routes from updates\n"
5227 "Generate AS set path information\n")
5228
5229DEFUN (no_aggregate_address_mask,
5230 no_aggregate_address_mask_cmd,
5231 "no aggregate-address A.B.C.D A.B.C.D",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate address\n"
5235 "Aggregate mask\n")
5236{
5237 int ret;
5238 char prefix_str[BUFSIZ];
5239
5240 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5241
5242 if (! ret)
5243 {
5244 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5245 return CMD_WARNING;
5246 }
5247
5248 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5249}
5250
5251ALIAS (no_aggregate_address_mask,
5252 no_aggregate_address_mask_summary_only_cmd,
5253 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5254 NO_STR
5255 "Configure BGP aggregate entries\n"
5256 "Aggregate address\n"
5257 "Aggregate mask\n"
5258 "Filter more specific routes from updates\n")
5259
5260ALIAS (no_aggregate_address_mask,
5261 no_aggregate_address_mask_as_set_cmd,
5262 "no aggregate-address A.B.C.D A.B.C.D as-set",
5263 NO_STR
5264 "Configure BGP aggregate entries\n"
5265 "Aggregate address\n"
5266 "Aggregate mask\n"
5267 "Generate AS set path information\n")
5268
5269ALIAS (no_aggregate_address_mask,
5270 no_aggregate_address_mask_as_set_summary_cmd,
5271 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5272 NO_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate address\n"
5275 "Aggregate mask\n"
5276 "Generate AS set path information\n"
5277 "Filter more specific routes from updates\n")
5278
5279ALIAS (no_aggregate_address_mask,
5280 no_aggregate_address_mask_summary_as_set_cmd,
5281 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5282 NO_STR
5283 "Configure BGP aggregate entries\n"
5284 "Aggregate address\n"
5285 "Aggregate mask\n"
5286 "Filter more specific routes from updates\n"
5287 "Generate AS set path information\n")
5288
5289#ifdef HAVE_IPV6
5290DEFUN (ipv6_aggregate_address,
5291 ipv6_aggregate_address_cmd,
5292 "aggregate-address X:X::X:X/M",
5293 "Configure BGP aggregate entries\n"
5294 "Aggregate prefix\n")
5295{
5296 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5297}
5298
5299DEFUN (ipv6_aggregate_address_summary_only,
5300 ipv6_aggregate_address_summary_only_cmd,
5301 "aggregate-address X:X::X:X/M summary-only",
5302 "Configure BGP aggregate entries\n"
5303 "Aggregate prefix\n"
5304 "Filter more specific routes from updates\n")
5305{
5306 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5307 AGGREGATE_SUMMARY_ONLY, 0);
5308}
5309
5310DEFUN (no_ipv6_aggregate_address,
5311 no_ipv6_aggregate_address_cmd,
5312 "no aggregate-address X:X::X:X/M",
5313 NO_STR
5314 "Configure BGP aggregate entries\n"
5315 "Aggregate prefix\n")
5316{
5317 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5318}
5319
5320DEFUN (no_ipv6_aggregate_address_summary_only,
5321 no_ipv6_aggregate_address_summary_only_cmd,
5322 "no aggregate-address X:X::X:X/M summary-only",
5323 NO_STR
5324 "Configure BGP aggregate entries\n"
5325 "Aggregate prefix\n"
5326 "Filter more specific routes from updates\n")
5327{
5328 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5329}
5330
5331ALIAS (ipv6_aggregate_address,
5332 old_ipv6_aggregate_address_cmd,
5333 "ipv6 bgp aggregate-address X:X::X:X/M",
5334 IPV6_STR
5335 BGP_STR
5336 "Configure BGP aggregate entries\n"
5337 "Aggregate prefix\n")
5338
5339ALIAS (ipv6_aggregate_address_summary_only,
5340 old_ipv6_aggregate_address_summary_only_cmd,
5341 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5342 IPV6_STR
5343 BGP_STR
5344 "Configure BGP aggregate entries\n"
5345 "Aggregate prefix\n"
5346 "Filter more specific routes from updates\n")
5347
5348ALIAS (no_ipv6_aggregate_address,
5349 old_no_ipv6_aggregate_address_cmd,
5350 "no ipv6 bgp aggregate-address X:X::X:X/M",
5351 NO_STR
5352 IPV6_STR
5353 BGP_STR
5354 "Configure BGP aggregate entries\n"
5355 "Aggregate prefix\n")
5356
5357ALIAS (no_ipv6_aggregate_address_summary_only,
5358 old_no_ipv6_aggregate_address_summary_only_cmd,
5359 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5360 NO_STR
5361 IPV6_STR
5362 BGP_STR
5363 "Configure BGP aggregate entries\n"
5364 "Aggregate prefix\n"
5365 "Filter more specific routes from updates\n")
5366#endif /* HAVE_IPV6 */
5367
5368/* Redistribute route treatment. */
5369void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005370bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5371 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005372 u_int32_t metric, u_char type)
5373{
5374 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005375 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005376 struct bgp_info *new;
5377 struct bgp_info *bi;
5378 struct bgp_info info;
5379 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005380 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005381 struct attr *new_attr;
5382 afi_t afi;
5383 int ret;
5384
5385 /* Make default attribute. */
5386 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5387 if (nexthop)
5388 attr.nexthop = *nexthop;
5389
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005390#ifdef HAVE_IPV6
5391 if (nexthop6)
5392 {
5393 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5394 extra->mp_nexthop_global = *nexthop6;
5395 extra->mp_nexthop_len = 16;
5396 }
5397#endif
5398
paul718e3742002-12-13 20:15:29 +00005399 attr.med = metric;
5400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5401
paul1eb8ef22005-04-07 07:30:20 +00005402 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005403 {
5404 afi = family2afi (p->family);
5405
5406 if (bgp->redist[afi][type])
5407 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005408 struct attr attr_new;
5409 struct attr_extra extra_new;
5410
paul718e3742002-12-13 20:15:29 +00005411 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005412 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005413 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005414
5415 if (bgp->redist_metric_flag[afi][type])
5416 attr_new.med = bgp->redist_metric[afi][type];
5417
5418 /* Apply route-map. */
5419 if (bgp->rmap[afi][type].map)
5420 {
5421 info.peer = bgp->peer_self;
5422 info.attr = &attr_new;
5423
paulfee0f4c2004-09-13 05:12:46 +00005424 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5425
paul718e3742002-12-13 20:15:29 +00005426 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5427 &info);
paulfee0f4c2004-09-13 05:12:46 +00005428
5429 bgp->peer_self->rmap_type = 0;
5430
paul718e3742002-12-13 20:15:29 +00005431 if (ret == RMAP_DENYMATCH)
5432 {
5433 /* Free uninterned attribute. */
5434 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005435
paul718e3742002-12-13 20:15:29 +00005436 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005437 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005438 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005439 bgp_redistribute_delete (p, type);
5440 return;
5441 }
5442 }
5443
Paul Jakmafb982c22007-05-04 20:15:47 +00005444 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5445 afi, SAFI_UNICAST, p, NULL);
5446
paul718e3742002-12-13 20:15:29 +00005447 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005448
paul718e3742002-12-13 20:15:29 +00005449 for (bi = bn->info; bi; bi = bi->next)
5450 if (bi->peer == bgp->peer_self
5451 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5452 break;
5453
5454 if (bi)
5455 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005456 if (attrhash_cmp (bi->attr, new_attr) &&
5457 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005458 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005459 bgp_attr_unintern (&new_attr);
5460 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005461 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005462 bgp_unlock_node (bn);
5463 return;
5464 }
5465 else
5466 {
5467 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005468 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005469
5470 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005471 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5472 bgp_info_restore(bn, bi);
5473 else
5474 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005475 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005476 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005477 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005478
5479 /* Process change. */
5480 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5481 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5482 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005483 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005484 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005485 return;
5486 }
5487 }
5488
5489 new = bgp_info_new ();
5490 new->type = type;
5491 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5492 new->peer = bgp->peer_self;
5493 SET_FLAG (new->flags, BGP_INFO_VALID);
5494 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005495 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005496
5497 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5498 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005499 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005500 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5501 }
5502 }
5503
5504 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005505 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005506 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005507}
5508
5509void
5510bgp_redistribute_delete (struct prefix *p, u_char type)
5511{
5512 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005513 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005514 afi_t afi;
5515 struct bgp_node *rn;
5516 struct bgp_info *ri;
5517
paul1eb8ef22005-04-07 07:30:20 +00005518 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005519 {
5520 afi = family2afi (p->family);
5521
5522 if (bgp->redist[afi][type])
5523 {
paulfee0f4c2004-09-13 05:12:46 +00005524 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005525
5526 for (ri = rn->info; ri; ri = ri->next)
5527 if (ri->peer == bgp->peer_self
5528 && ri->type == type)
5529 break;
5530
5531 if (ri)
5532 {
5533 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005534 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005535 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005536 }
5537 bgp_unlock_node (rn);
5538 }
5539 }
5540}
5541
5542/* Withdraw specified route type's route. */
5543void
5544bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5545{
5546 struct bgp_node *rn;
5547 struct bgp_info *ri;
5548 struct bgp_table *table;
5549
5550 table = bgp->rib[afi][SAFI_UNICAST];
5551
5552 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5553 {
5554 for (ri = rn->info; ri; ri = ri->next)
5555 if (ri->peer == bgp->peer_self
5556 && ri->type == type)
5557 break;
5558
5559 if (ri)
5560 {
5561 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005562 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005563 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005564 }
5565 }
5566}
5567
5568/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005569static void
paul718e3742002-12-13 20:15:29 +00005570route_vty_out_route (struct prefix *p, struct vty *vty)
5571{
5572 int len;
5573 u_int32_t destination;
5574 char buf[BUFSIZ];
5575
5576 if (p->family == AF_INET)
5577 {
5578 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5579 destination = ntohl (p->u.prefix4.s_addr);
5580
5581 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5582 || (IN_CLASSB (destination) && p->prefixlen == 16)
5583 || (IN_CLASSA (destination) && p->prefixlen == 8)
5584 || p->u.prefix4.s_addr == 0)
5585 {
5586 /* When mask is natural, mask is not displayed. */
5587 }
5588 else
5589 len += vty_out (vty, "/%d", p->prefixlen);
5590 }
5591 else
5592 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5593 p->prefixlen);
5594
5595 len = 17 - len;
5596 if (len < 1)
5597 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5598 else
5599 vty_out (vty, "%*s", len, " ");
5600}
5601
paul718e3742002-12-13 20:15:29 +00005602enum bgp_display_type
5603{
5604 normal_list,
5605};
5606
paulb40d9392005-08-22 22:34:41 +00005607/* Print the short form route status for a bgp_info */
5608static void
5609route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005610{
paulb40d9392005-08-22 22:34:41 +00005611 /* Route status display. */
5612 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5613 vty_out (vty, "R");
5614 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005615 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005616 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005617 vty_out (vty, "s");
5618 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5619 vty_out (vty, "*");
5620 else
5621 vty_out (vty, " ");
5622
5623 /* Selected */
5624 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5625 vty_out (vty, "h");
5626 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5627 vty_out (vty, "d");
5628 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5629 vty_out (vty, ">");
5630 else
5631 vty_out (vty, " ");
5632
5633 /* Internal route. */
5634 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5635 vty_out (vty, "i");
5636 else
paulb40d9392005-08-22 22:34:41 +00005637 vty_out (vty, " ");
5638}
5639
5640/* called from terminal list command */
5641void
5642route_vty_out (struct vty *vty, struct prefix *p,
5643 struct bgp_info *binfo, int display, safi_t safi)
5644{
5645 struct attr *attr;
5646
5647 /* short status lead text */
5648 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005649
5650 /* print prefix and mask */
5651 if (! display)
5652 route_vty_out_route (p, vty);
5653 else
5654 vty_out (vty, "%*s", 17, " ");
5655
5656 /* Print attribute */
5657 attr = binfo->attr;
5658 if (attr)
5659 {
5660 if (p->family == AF_INET)
5661 {
5662 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005663 vty_out (vty, "%-16s",
5664 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005665 else
5666 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5667 }
5668#ifdef HAVE_IPV6
5669 else if (p->family == AF_INET6)
5670 {
5671 int len;
5672 char buf[BUFSIZ];
5673
5674 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005675 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5676 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005677 len = 16 - len;
5678 if (len < 1)
5679 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5680 else
5681 vty_out (vty, "%*s", len, " ");
5682 }
5683#endif /* HAVE_IPV6 */
5684
5685 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005686 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005687 else
5688 vty_out (vty, " ");
5689
5690 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005691 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005692 else
5693 vty_out (vty, " ");
5694
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005696
Paul Jakmab2518c12006-05-12 23:48:40 +00005697 /* Print aspath */
5698 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005699 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005700
Paul Jakmab2518c12006-05-12 23:48:40 +00005701 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005702 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005703 }
paul718e3742002-12-13 20:15:29 +00005704 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005705}
5706
5707/* called from terminal list command */
5708void
5709route_vty_out_tmp (struct vty *vty, struct prefix *p,
5710 struct attr *attr, safi_t safi)
5711{
5712 /* Route status display. */
5713 vty_out (vty, "*");
5714 vty_out (vty, ">");
5715 vty_out (vty, " ");
5716
5717 /* print prefix and mask */
5718 route_vty_out_route (p, vty);
5719
5720 /* Print attribute */
5721 if (attr)
5722 {
5723 if (p->family == AF_INET)
5724 {
5725 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005726 vty_out (vty, "%-16s",
5727 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005728 else
5729 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5730 }
5731#ifdef HAVE_IPV6
5732 else if (p->family == AF_INET6)
5733 {
5734 int len;
5735 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005736
5737 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005738
5739 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005740 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5741 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005742 len = 16 - len;
5743 if (len < 1)
5744 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5745 else
5746 vty_out (vty, "%*s", len, " ");
5747 }
5748#endif /* HAVE_IPV6 */
5749
5750 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005751 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005752 else
5753 vty_out (vty, " ");
5754
5755 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005756 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005757 else
5758 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005759
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005760 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005761
Paul Jakmab2518c12006-05-12 23:48:40 +00005762 /* Print aspath */
5763 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005764 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005765
Paul Jakmab2518c12006-05-12 23:48:40 +00005766 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005767 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005768 }
paul718e3742002-12-13 20:15:29 +00005769
5770 vty_out (vty, "%s", VTY_NEWLINE);
5771}
5772
ajs5a646652004-11-05 01:25:55 +00005773void
paul718e3742002-12-13 20:15:29 +00005774route_vty_out_tag (struct vty *vty, struct prefix *p,
5775 struct bgp_info *binfo, int display, safi_t safi)
5776{
5777 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005778 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005779
5780 if (!binfo->extra)
5781 return;
5782
paulb40d9392005-08-22 22:34:41 +00005783 /* short status lead text */
5784 route_vty_short_status_out (vty, binfo);
5785
paul718e3742002-12-13 20:15:29 +00005786 /* print prefix and mask */
5787 if (! display)
5788 route_vty_out_route (p, vty);
5789 else
5790 vty_out (vty, "%*s", 17, " ");
5791
5792 /* Print attribute */
5793 attr = binfo->attr;
5794 if (attr)
5795 {
5796 if (p->family == AF_INET)
5797 {
5798 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005799 vty_out (vty, "%-16s",
5800 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005801 else
5802 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5803 }
5804#ifdef HAVE_IPV6
5805 else if (p->family == AF_INET6)
5806 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005807 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005808 char buf[BUFSIZ];
5809 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005810 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005811 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005812 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5813 buf, BUFSIZ));
5814 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005815 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005816 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5817 buf, BUFSIZ),
5818 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5819 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005820
5821 }
5822#endif /* HAVE_IPV6 */
5823 }
5824
Paul Jakmafb982c22007-05-04 20:15:47 +00005825 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005826
5827 vty_out (vty, "notag/%d", label);
5828
5829 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005830}
5831
5832/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005833static void
paul718e3742002-12-13 20:15:29 +00005834damp_route_vty_out (struct vty *vty, struct prefix *p,
5835 struct bgp_info *binfo, int display, safi_t safi)
5836{
5837 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005838 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005839 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005840
paulb40d9392005-08-22 22:34:41 +00005841 /* short status lead text */
5842 route_vty_short_status_out (vty, binfo);
5843
paul718e3742002-12-13 20:15:29 +00005844 /* print prefix and mask */
5845 if (! display)
5846 route_vty_out_route (p, vty);
5847 else
5848 vty_out (vty, "%*s", 17, " ");
5849
5850 len = vty_out (vty, "%s", binfo->peer->host);
5851 len = 17 - len;
5852 if (len < 1)
5853 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5854 else
5855 vty_out (vty, "%*s", len, " ");
5856
Chris Caputo50aef6f2009-06-23 06:06:49 +00005857 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005858
5859 /* Print attribute */
5860 attr = binfo->attr;
5861 if (attr)
5862 {
5863 /* Print aspath */
5864 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005865 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005866
5867 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005868 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005869 }
5870 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005871}
5872
paul718e3742002-12-13 20:15:29 +00005873/* flap route */
ajs5a646652004-11-05 01:25:55 +00005874static void
paul718e3742002-12-13 20:15:29 +00005875flap_route_vty_out (struct vty *vty, struct prefix *p,
5876 struct bgp_info *binfo, int display, safi_t safi)
5877{
5878 struct attr *attr;
5879 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005880 char timebuf[BGP_UPTIME_LEN];
5881 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005882
5883 if (!binfo->extra)
5884 return;
5885
5886 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005887
paulb40d9392005-08-22 22:34:41 +00005888 /* short status lead text */
5889 route_vty_short_status_out (vty, binfo);
5890
paul718e3742002-12-13 20:15:29 +00005891 /* print prefix and mask */
5892 if (! display)
5893 route_vty_out_route (p, vty);
5894 else
5895 vty_out (vty, "%*s", 17, " ");
5896
5897 len = vty_out (vty, "%s", binfo->peer->host);
5898 len = 16 - len;
5899 if (len < 1)
5900 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5901 else
5902 vty_out (vty, "%*s", len, " ");
5903
5904 len = vty_out (vty, "%d", bdi->flap);
5905 len = 5 - len;
5906 if (len < 1)
5907 vty_out (vty, " ");
5908 else
5909 vty_out (vty, "%*s ", len, " ");
5910
5911 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5912 timebuf, BGP_UPTIME_LEN));
5913
5914 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5915 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005916 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005917 else
5918 vty_out (vty, "%*s ", 8, " ");
5919
5920 /* Print attribute */
5921 attr = binfo->attr;
5922 if (attr)
5923 {
5924 /* Print aspath */
5925 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005926 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005927
5928 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005929 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005930 }
5931 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005932}
5933
paul94f2b392005-06-28 12:44:16 +00005934static void
paul718e3742002-12-13 20:15:29 +00005935route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5936 struct bgp_info *binfo, afi_t afi, safi_t safi)
5937{
5938 char buf[INET6_ADDRSTRLEN];
5939 char buf1[BUFSIZ];
5940 struct attr *attr;
5941 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005942#ifdef HAVE_CLOCK_MONOTONIC
5943 time_t tbuf;
5944#endif
paul718e3742002-12-13 20:15:29 +00005945
5946 attr = binfo->attr;
5947
5948 if (attr)
5949 {
5950 /* Line1 display AS-path, Aggregator */
5951 if (attr->aspath)
5952 {
5953 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005954 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005955 vty_out (vty, "Local");
5956 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005957 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005958 }
5959
paulb40d9392005-08-22 22:34:41 +00005960 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5961 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005962 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5963 vty_out (vty, ", (stale)");
5964 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005965 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005966 attr->extra->aggregator_as,
5967 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005968 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5969 vty_out (vty, ", (Received from a RR-client)");
5970 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5971 vty_out (vty, ", (Received from a RS-client)");
5972 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5973 vty_out (vty, ", (history entry)");
5974 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5975 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005976 vty_out (vty, "%s", VTY_NEWLINE);
5977
5978 /* Line2 display Next-hop, Neighbor, Router-id */
5979 if (p->family == AF_INET)
5980 {
5981 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005982 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005983 inet_ntoa (attr->nexthop));
5984 }
5985#ifdef HAVE_IPV6
5986 else
5987 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005989 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005990 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005991 buf, INET6_ADDRSTRLEN));
5992 }
5993#endif /* HAVE_IPV6 */
5994
5995 if (binfo->peer == bgp->peer_self)
5996 {
5997 vty_out (vty, " from %s ",
5998 p->family == AF_INET ? "0.0.0.0" : "::");
5999 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6000 }
6001 else
6002 {
6003 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6004 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006006 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006007 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006008 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006009 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006010 else
6011 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6012 }
6013 vty_out (vty, "%s", VTY_NEWLINE);
6014
6015#ifdef HAVE_IPV6
6016 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006018 {
6019 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006021 buf, INET6_ADDRSTRLEN),
6022 VTY_NEWLINE);
6023 }
6024#endif /* HAVE_IPV6 */
6025
6026 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6027 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6028
6029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006030 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006031
6032 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006033 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006034 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006035 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006036
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006038 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006039
6040 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6041 vty_out (vty, ", valid");
6042
6043 if (binfo->peer != bgp->peer_self)
6044 {
6045 if (binfo->peer->as == binfo->peer->local_as)
6046 vty_out (vty, ", internal");
6047 else
6048 vty_out (vty, ", %s",
6049 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6050 }
6051 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6052 vty_out (vty, ", aggregated, local");
6053 else if (binfo->type != ZEBRA_ROUTE_BGP)
6054 vty_out (vty, ", sourced");
6055 else
6056 vty_out (vty, ", sourced, local");
6057
6058 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6059 vty_out (vty, ", atomic-aggregate");
6060
Josh Baileyde8d5df2011-07-20 20:46:01 -07006061 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6062 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6063 bgp_info_mpath_count (binfo)))
6064 vty_out (vty, ", multipath");
6065
paul718e3742002-12-13 20:15:29 +00006066 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6067 vty_out (vty, ", best");
6068
6069 vty_out (vty, "%s", VTY_NEWLINE);
6070
6071 /* Line 4 display Community */
6072 if (attr->community)
6073 vty_out (vty, " Community: %s%s", attr->community->str,
6074 VTY_NEWLINE);
6075
6076 /* Line 5 display Extended-community */
6077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 vty_out (vty, " Extended Community: %s%s",
6079 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006080
6081 /* Line 6 display Originator, Cluster-id */
6082 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6083 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006086 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006087 vty_out (vty, " Originator: %s",
6088 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006089
6090 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6091 {
6092 int i;
6093 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006094 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6095 vty_out (vty, "%s ",
6096 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006097 }
6098 vty_out (vty, "%s", VTY_NEWLINE);
6099 }
Paul Jakma41367172007-08-06 15:24:51 +00006100
Paul Jakmafb982c22007-05-04 20:15:47 +00006101 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006102 bgp_damp_info_vty (vty, binfo);
6103
6104 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006105#ifdef HAVE_CLOCK_MONOTONIC
6106 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006107 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006108#else
6109 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6110#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006111 }
6112 vty_out (vty, "%s", VTY_NEWLINE);
6113}
6114
paulb40d9392005-08-22 22:34:41 +00006115#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 +00006116#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006117#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6118#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6119#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6120
6121enum bgp_show_type
6122{
6123 bgp_show_type_normal,
6124 bgp_show_type_regexp,
6125 bgp_show_type_prefix_list,
6126 bgp_show_type_filter_list,
6127 bgp_show_type_route_map,
6128 bgp_show_type_neighbor,
6129 bgp_show_type_cidr_only,
6130 bgp_show_type_prefix_longer,
6131 bgp_show_type_community_all,
6132 bgp_show_type_community,
6133 bgp_show_type_community_exact,
6134 bgp_show_type_community_list,
6135 bgp_show_type_community_list_exact,
6136 bgp_show_type_flap_statistics,
6137 bgp_show_type_flap_address,
6138 bgp_show_type_flap_prefix,
6139 bgp_show_type_flap_cidr_only,
6140 bgp_show_type_flap_regexp,
6141 bgp_show_type_flap_filter_list,
6142 bgp_show_type_flap_prefix_list,
6143 bgp_show_type_flap_prefix_longer,
6144 bgp_show_type_flap_route_map,
6145 bgp_show_type_flap_neighbor,
6146 bgp_show_type_dampend_paths,
6147 bgp_show_type_damp_neighbor
6148};
6149
ajs5a646652004-11-05 01:25:55 +00006150static int
paulfee0f4c2004-09-13 05:12:46 +00006151bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006152 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006153{
paul718e3742002-12-13 20:15:29 +00006154 struct bgp_info *ri;
6155 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006156 int header = 1;
paul718e3742002-12-13 20:15:29 +00006157 int display;
ajs5a646652004-11-05 01:25:55 +00006158 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006159
6160 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006161 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006162
paul718e3742002-12-13 20:15:29 +00006163 /* Start processing of routes. */
6164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6165 if (rn->info != NULL)
6166 {
6167 display = 0;
6168
6169 for (ri = rn->info; ri; ri = ri->next)
6170 {
ajs5a646652004-11-05 01:25:55 +00006171 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006172 || type == bgp_show_type_flap_address
6173 || type == bgp_show_type_flap_prefix
6174 || type == bgp_show_type_flap_cidr_only
6175 || type == bgp_show_type_flap_regexp
6176 || type == bgp_show_type_flap_filter_list
6177 || type == bgp_show_type_flap_prefix_list
6178 || type == bgp_show_type_flap_prefix_longer
6179 || type == bgp_show_type_flap_route_map
6180 || type == bgp_show_type_flap_neighbor
6181 || type == bgp_show_type_dampend_paths
6182 || type == bgp_show_type_damp_neighbor)
6183 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006184 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006185 continue;
6186 }
6187 if (type == bgp_show_type_regexp
6188 || type == bgp_show_type_flap_regexp)
6189 {
ajs5a646652004-11-05 01:25:55 +00006190 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006191
6192 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6193 continue;
6194 }
6195 if (type == bgp_show_type_prefix_list
6196 || type == bgp_show_type_flap_prefix_list)
6197 {
ajs5a646652004-11-05 01:25:55 +00006198 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006199
6200 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6201 continue;
6202 }
6203 if (type == bgp_show_type_filter_list
6204 || type == bgp_show_type_flap_filter_list)
6205 {
ajs5a646652004-11-05 01:25:55 +00006206 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006207
6208 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6209 continue;
6210 }
6211 if (type == bgp_show_type_route_map
6212 || type == bgp_show_type_flap_route_map)
6213 {
ajs5a646652004-11-05 01:25:55 +00006214 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006215 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006216 struct attr dummy_attr;
6217 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006218 int ret;
6219
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006220 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006221 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006222
paul718e3742002-12-13 20:15:29 +00006223 binfo.peer = ri->peer;
6224 binfo.attr = &dummy_attr;
6225
6226 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006227 if (ret == RMAP_DENYMATCH)
6228 continue;
6229 }
6230 if (type == bgp_show_type_neighbor
6231 || type == bgp_show_type_flap_neighbor
6232 || type == bgp_show_type_damp_neighbor)
6233 {
ajs5a646652004-11-05 01:25:55 +00006234 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006235
6236 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6237 continue;
6238 }
6239 if (type == bgp_show_type_cidr_only
6240 || type == bgp_show_type_flap_cidr_only)
6241 {
6242 u_int32_t destination;
6243
6244 destination = ntohl (rn->p.u.prefix4.s_addr);
6245 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6246 continue;
6247 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6248 continue;
6249 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6250 continue;
6251 }
6252 if (type == bgp_show_type_prefix_longer
6253 || type == bgp_show_type_flap_prefix_longer)
6254 {
ajs5a646652004-11-05 01:25:55 +00006255 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006256
6257 if (! prefix_match (p, &rn->p))
6258 continue;
6259 }
6260 if (type == bgp_show_type_community_all)
6261 {
6262 if (! ri->attr->community)
6263 continue;
6264 }
6265 if (type == bgp_show_type_community)
6266 {
ajs5a646652004-11-05 01:25:55 +00006267 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006268
6269 if (! ri->attr->community ||
6270 ! community_match (ri->attr->community, com))
6271 continue;
6272 }
6273 if (type == bgp_show_type_community_exact)
6274 {
ajs5a646652004-11-05 01:25:55 +00006275 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006276
6277 if (! ri->attr->community ||
6278 ! community_cmp (ri->attr->community, com))
6279 continue;
6280 }
6281 if (type == bgp_show_type_community_list)
6282 {
ajs5a646652004-11-05 01:25:55 +00006283 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006284
6285 if (! community_list_match (ri->attr->community, list))
6286 continue;
6287 }
6288 if (type == bgp_show_type_community_list_exact)
6289 {
ajs5a646652004-11-05 01:25:55 +00006290 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006291
6292 if (! community_list_exact_match (ri->attr->community, list))
6293 continue;
6294 }
6295 if (type == bgp_show_type_flap_address
6296 || type == bgp_show_type_flap_prefix)
6297 {
ajs5a646652004-11-05 01:25:55 +00006298 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006299
6300 if (! prefix_match (&rn->p, p))
6301 continue;
6302
6303 if (type == bgp_show_type_flap_prefix)
6304 if (p->prefixlen != rn->p.prefixlen)
6305 continue;
6306 }
6307 if (type == bgp_show_type_dampend_paths
6308 || type == bgp_show_type_damp_neighbor)
6309 {
6310 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6311 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6312 continue;
6313 }
6314
6315 if (header)
6316 {
hasso93406d82005-02-02 14:40:33 +00006317 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6318 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6319 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006320 if (type == bgp_show_type_dampend_paths
6321 || type == bgp_show_type_damp_neighbor)
6322 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6323 else if (type == bgp_show_type_flap_statistics
6324 || type == bgp_show_type_flap_address
6325 || type == bgp_show_type_flap_prefix
6326 || type == bgp_show_type_flap_cidr_only
6327 || type == bgp_show_type_flap_regexp
6328 || type == bgp_show_type_flap_filter_list
6329 || type == bgp_show_type_flap_prefix_list
6330 || type == bgp_show_type_flap_prefix_longer
6331 || type == bgp_show_type_flap_route_map
6332 || type == bgp_show_type_flap_neighbor)
6333 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6334 else
6335 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006336 header = 0;
6337 }
6338
6339 if (type == bgp_show_type_dampend_paths
6340 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006341 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006342 else if (type == bgp_show_type_flap_statistics
6343 || type == bgp_show_type_flap_address
6344 || type == bgp_show_type_flap_prefix
6345 || type == bgp_show_type_flap_cidr_only
6346 || type == bgp_show_type_flap_regexp
6347 || type == bgp_show_type_flap_filter_list
6348 || type == bgp_show_type_flap_prefix_list
6349 || type == bgp_show_type_flap_prefix_longer
6350 || type == bgp_show_type_flap_route_map
6351 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006352 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006353 else
ajs5a646652004-11-05 01:25:55 +00006354 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006355 display++;
6356 }
6357 if (display)
ajs5a646652004-11-05 01:25:55 +00006358 output_count++;
paul718e3742002-12-13 20:15:29 +00006359 }
6360
6361 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006362 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006363 {
6364 if (type == bgp_show_type_normal)
6365 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6366 }
6367 else
6368 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006369 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006370
6371 return CMD_SUCCESS;
6372}
6373
ajs5a646652004-11-05 01:25:55 +00006374static int
paulfee0f4c2004-09-13 05:12:46 +00006375bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006376 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006377{
6378 struct bgp_table *table;
6379
6380 if (bgp == NULL) {
6381 bgp = bgp_get_default ();
6382 }
6383
6384 if (bgp == NULL)
6385 {
6386 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6387 return CMD_WARNING;
6388 }
6389
6390
6391 table = bgp->rib[afi][safi];
6392
ajs5a646652004-11-05 01:25:55 +00006393 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006394}
6395
paul718e3742002-12-13 20:15:29 +00006396/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006397static void
paul718e3742002-12-13 20:15:29 +00006398route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6399 struct bgp_node *rn,
6400 struct prefix_rd *prd, afi_t afi, safi_t safi)
6401{
6402 struct bgp_info *ri;
6403 struct prefix *p;
6404 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006405 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006406 char buf1[INET6_ADDRSTRLEN];
6407 char buf2[INET6_ADDRSTRLEN];
6408 int count = 0;
6409 int best = 0;
6410 int suppress = 0;
6411 int no_export = 0;
6412 int no_advertise = 0;
6413 int local_as = 0;
6414 int first = 0;
6415
6416 p = &rn->p;
6417 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6418 (safi == SAFI_MPLS_VPN ?
6419 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6420 safi == SAFI_MPLS_VPN ? ":" : "",
6421 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6422 p->prefixlen, VTY_NEWLINE);
6423
6424 for (ri = rn->info; ri; ri = ri->next)
6425 {
6426 count++;
6427 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6428 {
6429 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006430 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006431 suppress = 1;
6432 if (ri->attr->community != NULL)
6433 {
6434 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6435 no_advertise = 1;
6436 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6437 no_export = 1;
6438 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6439 local_as = 1;
6440 }
6441 }
6442 }
6443
6444 vty_out (vty, "Paths: (%d available", count);
6445 if (best)
6446 {
6447 vty_out (vty, ", best #%d", best);
6448 if (safi == SAFI_UNICAST)
6449 vty_out (vty, ", table Default-IP-Routing-Table");
6450 }
6451 else
6452 vty_out (vty, ", no best path");
6453 if (no_advertise)
6454 vty_out (vty, ", not advertised to any peer");
6455 else if (no_export)
6456 vty_out (vty, ", not advertised to EBGP peer");
6457 else if (local_as)
6458 vty_out (vty, ", not advertised outside local AS");
6459 if (suppress)
6460 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6461 vty_out (vty, ")%s", VTY_NEWLINE);
6462
6463 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006464 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006465 {
6466 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6467 {
6468 if (! first)
6469 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6470 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6471 first = 1;
6472 }
6473 }
6474 if (! first)
6475 vty_out (vty, " Not advertised to any peer");
6476 vty_out (vty, "%s", VTY_NEWLINE);
6477}
6478
6479/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006480static int
paulfee0f4c2004-09-13 05:12:46 +00006481bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006482 struct bgp_table *rib, const char *ip_str,
6483 afi_t afi, safi_t safi, struct prefix_rd *prd,
6484 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006485{
6486 int ret;
6487 int header;
6488 int display = 0;
6489 struct prefix match;
6490 struct bgp_node *rn;
6491 struct bgp_node *rm;
6492 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006493 struct bgp_table *table;
6494
paul718e3742002-12-13 20:15:29 +00006495 /* Check IP address argument. */
6496 ret = str2prefix (ip_str, &match);
6497 if (! ret)
6498 {
6499 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6500 return CMD_WARNING;
6501 }
6502
6503 match.family = afi2family (afi);
6504
6505 if (safi == SAFI_MPLS_VPN)
6506 {
paulfee0f4c2004-09-13 05:12:46 +00006507 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006508 {
6509 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6510 continue;
6511
6512 if ((table = rn->info) != NULL)
6513 {
6514 header = 1;
6515
6516 if ((rm = bgp_node_match (table, &match)) != NULL)
6517 {
6518 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006519 {
6520 bgp_unlock_node (rm);
6521 continue;
6522 }
paul718e3742002-12-13 20:15:29 +00006523
6524 for (ri = rm->info; ri; ri = ri->next)
6525 {
6526 if (header)
6527 {
6528 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6529 AFI_IP, SAFI_MPLS_VPN);
6530
6531 header = 0;
6532 }
6533 display++;
6534 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6535 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006536
6537 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006538 }
6539 }
6540 }
6541 }
6542 else
6543 {
6544 header = 1;
6545
paulfee0f4c2004-09-13 05:12:46 +00006546 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006547 {
6548 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6549 {
6550 for (ri = rn->info; ri; ri = ri->next)
6551 {
6552 if (header)
6553 {
6554 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6555 header = 0;
6556 }
6557 display++;
6558 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6559 }
6560 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006561
6562 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006563 }
6564 }
6565
6566 if (! display)
6567 {
6568 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6569 return CMD_WARNING;
6570 }
6571
6572 return CMD_SUCCESS;
6573}
6574
paulfee0f4c2004-09-13 05:12:46 +00006575/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006576static int
paulfd79ac92004-10-13 05:06:08 +00006577bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006578 afi_t afi, safi_t safi, struct prefix_rd *prd,
6579 int prefix_check)
6580{
6581 struct bgp *bgp;
6582
6583 /* BGP structure lookup. */
6584 if (view_name)
6585 {
6586 bgp = bgp_lookup_by_name (view_name);
6587 if (bgp == NULL)
6588 {
6589 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6590 return CMD_WARNING;
6591 }
6592 }
6593 else
6594 {
6595 bgp = bgp_get_default ();
6596 if (bgp == NULL)
6597 {
6598 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6599 return CMD_WARNING;
6600 }
6601 }
6602
6603 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6604 afi, safi, prd, prefix_check);
6605}
6606
paul718e3742002-12-13 20:15:29 +00006607/* BGP route print out function. */
6608DEFUN (show_ip_bgp,
6609 show_ip_bgp_cmd,
6610 "show ip bgp",
6611 SHOW_STR
6612 IP_STR
6613 BGP_STR)
6614{
ajs5a646652004-11-05 01:25:55 +00006615 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006616}
6617
6618DEFUN (show_ip_bgp_ipv4,
6619 show_ip_bgp_ipv4_cmd,
6620 "show ip bgp ipv4 (unicast|multicast)",
6621 SHOW_STR
6622 IP_STR
6623 BGP_STR
6624 "Address family\n"
6625 "Address Family modifier\n"
6626 "Address Family modifier\n")
6627{
6628 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006629 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6630 NULL);
paul718e3742002-12-13 20:15:29 +00006631
ajs5a646652004-11-05 01:25:55 +00006632 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006633}
6634
Michael Lambert95cbbd22010-07-23 14:43:04 -04006635ALIAS (show_ip_bgp_ipv4,
6636 show_bgp_ipv4_safi_cmd,
6637 "show bgp ipv4 (unicast|multicast)",
6638 SHOW_STR
6639 BGP_STR
6640 "Address family\n"
6641 "Address Family modifier\n"
6642 "Address Family modifier\n")
6643
paul718e3742002-12-13 20:15:29 +00006644DEFUN (show_ip_bgp_route,
6645 show_ip_bgp_route_cmd,
6646 "show ip bgp A.B.C.D",
6647 SHOW_STR
6648 IP_STR
6649 BGP_STR
6650 "Network in the BGP routing table to display\n")
6651{
6652 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6653}
6654
6655DEFUN (show_ip_bgp_ipv4_route,
6656 show_ip_bgp_ipv4_route_cmd,
6657 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6658 SHOW_STR
6659 IP_STR
6660 BGP_STR
6661 "Address family\n"
6662 "Address Family modifier\n"
6663 "Address Family modifier\n"
6664 "Network in the BGP routing table to display\n")
6665{
6666 if (strncmp (argv[0], "m", 1) == 0)
6667 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6668
6669 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6670}
6671
Michael Lambert95cbbd22010-07-23 14:43:04 -04006672ALIAS (show_ip_bgp_ipv4_route,
6673 show_bgp_ipv4_safi_route_cmd,
6674 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6675 SHOW_STR
6676 BGP_STR
6677 "Address family\n"
6678 "Address Family modifier\n"
6679 "Address Family modifier\n"
6680 "Network in the BGP routing table to display\n")
6681
paul718e3742002-12-13 20:15:29 +00006682DEFUN (show_ip_bgp_vpnv4_all_route,
6683 show_ip_bgp_vpnv4_all_route_cmd,
6684 "show ip bgp vpnv4 all A.B.C.D",
6685 SHOW_STR
6686 IP_STR
6687 BGP_STR
6688 "Display VPNv4 NLRI specific information\n"
6689 "Display information about all VPNv4 NLRIs\n"
6690 "Network in the BGP routing table to display\n")
6691{
6692 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6693}
6694
6695DEFUN (show_ip_bgp_vpnv4_rd_route,
6696 show_ip_bgp_vpnv4_rd_route_cmd,
6697 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6698 SHOW_STR
6699 IP_STR
6700 BGP_STR
6701 "Display VPNv4 NLRI specific information\n"
6702 "Display information for a route distinguisher\n"
6703 "VPN Route Distinguisher\n"
6704 "Network in the BGP routing table to display\n")
6705{
6706 int ret;
6707 struct prefix_rd prd;
6708
6709 ret = str2prefix_rd (argv[0], &prd);
6710 if (! ret)
6711 {
6712 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6713 return CMD_WARNING;
6714 }
6715 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6716}
6717
6718DEFUN (show_ip_bgp_prefix,
6719 show_ip_bgp_prefix_cmd,
6720 "show ip bgp A.B.C.D/M",
6721 SHOW_STR
6722 IP_STR
6723 BGP_STR
6724 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6725{
6726 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6727}
6728
6729DEFUN (show_ip_bgp_ipv4_prefix,
6730 show_ip_bgp_ipv4_prefix_cmd,
6731 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6732 SHOW_STR
6733 IP_STR
6734 BGP_STR
6735 "Address family\n"
6736 "Address Family modifier\n"
6737 "Address Family modifier\n"
6738 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6739{
6740 if (strncmp (argv[0], "m", 1) == 0)
6741 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6742
6743 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6744}
6745
Michael Lambert95cbbd22010-07-23 14:43:04 -04006746ALIAS (show_ip_bgp_ipv4_prefix,
6747 show_bgp_ipv4_safi_prefix_cmd,
6748 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6749 SHOW_STR
6750 BGP_STR
6751 "Address family\n"
6752 "Address Family modifier\n"
6753 "Address Family modifier\n"
6754 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6755
paul718e3742002-12-13 20:15:29 +00006756DEFUN (show_ip_bgp_vpnv4_all_prefix,
6757 show_ip_bgp_vpnv4_all_prefix_cmd,
6758 "show ip bgp vpnv4 all A.B.C.D/M",
6759 SHOW_STR
6760 IP_STR
6761 BGP_STR
6762 "Display VPNv4 NLRI specific information\n"
6763 "Display information about all VPNv4 NLRIs\n"
6764 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6765{
6766 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6767}
6768
6769DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6770 show_ip_bgp_vpnv4_rd_prefix_cmd,
6771 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6772 SHOW_STR
6773 IP_STR
6774 BGP_STR
6775 "Display VPNv4 NLRI specific information\n"
6776 "Display information for a route distinguisher\n"
6777 "VPN Route Distinguisher\n"
6778 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6779{
6780 int ret;
6781 struct prefix_rd prd;
6782
6783 ret = str2prefix_rd (argv[0], &prd);
6784 if (! ret)
6785 {
6786 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6787 return CMD_WARNING;
6788 }
6789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6790}
6791
6792DEFUN (show_ip_bgp_view,
6793 show_ip_bgp_view_cmd,
6794 "show ip bgp view WORD",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006799 "View name\n")
paul718e3742002-12-13 20:15:29 +00006800{
paulbb46e942003-10-24 19:02:03 +00006801 struct bgp *bgp;
6802
6803 /* BGP structure lookup. */
6804 bgp = bgp_lookup_by_name (argv[0]);
6805 if (bgp == NULL)
6806 {
6807 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6808 return CMD_WARNING;
6809 }
6810
ajs5a646652004-11-05 01:25:55 +00006811 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006812}
6813
6814DEFUN (show_ip_bgp_view_route,
6815 show_ip_bgp_view_route_cmd,
6816 "show ip bgp view WORD A.B.C.D",
6817 SHOW_STR
6818 IP_STR
6819 BGP_STR
6820 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006821 "View name\n"
paul718e3742002-12-13 20:15:29 +00006822 "Network in the BGP routing table to display\n")
6823{
6824 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6825}
6826
6827DEFUN (show_ip_bgp_view_prefix,
6828 show_ip_bgp_view_prefix_cmd,
6829 "show ip bgp view WORD A.B.C.D/M",
6830 SHOW_STR
6831 IP_STR
6832 BGP_STR
6833 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006834 "View name\n"
paul718e3742002-12-13 20:15:29 +00006835 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6836{
6837 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6838}
6839
6840#ifdef HAVE_IPV6
6841DEFUN (show_bgp,
6842 show_bgp_cmd,
6843 "show bgp",
6844 SHOW_STR
6845 BGP_STR)
6846{
ajs5a646652004-11-05 01:25:55 +00006847 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6848 NULL);
paul718e3742002-12-13 20:15:29 +00006849}
6850
6851ALIAS (show_bgp,
6852 show_bgp_ipv6_cmd,
6853 "show bgp ipv6",
6854 SHOW_STR
6855 BGP_STR
6856 "Address family\n")
6857
Michael Lambert95cbbd22010-07-23 14:43:04 -04006858DEFUN (show_bgp_ipv6_safi,
6859 show_bgp_ipv6_safi_cmd,
6860 "show bgp ipv6 (unicast|multicast)",
6861 SHOW_STR
6862 BGP_STR
6863 "Address family\n"
6864 "Address Family modifier\n"
6865 "Address Family modifier\n")
6866{
6867 if (strncmp (argv[0], "m", 1) == 0)
6868 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6869 NULL);
6870
6871 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6872}
6873
paul718e3742002-12-13 20:15:29 +00006874/* old command */
6875DEFUN (show_ipv6_bgp,
6876 show_ipv6_bgp_cmd,
6877 "show ipv6 bgp",
6878 SHOW_STR
6879 IP_STR
6880 BGP_STR)
6881{
ajs5a646652004-11-05 01:25:55 +00006882 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6883 NULL);
paul718e3742002-12-13 20:15:29 +00006884}
6885
6886DEFUN (show_bgp_route,
6887 show_bgp_route_cmd,
6888 "show bgp X:X::X:X",
6889 SHOW_STR
6890 BGP_STR
6891 "Network in the BGP routing table to display\n")
6892{
6893 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6894}
6895
6896ALIAS (show_bgp_route,
6897 show_bgp_ipv6_route_cmd,
6898 "show bgp ipv6 X:X::X:X",
6899 SHOW_STR
6900 BGP_STR
6901 "Address family\n"
6902 "Network in the BGP routing table to display\n")
6903
Michael Lambert95cbbd22010-07-23 14:43:04 -04006904DEFUN (show_bgp_ipv6_safi_route,
6905 show_bgp_ipv6_safi_route_cmd,
6906 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6907 SHOW_STR
6908 BGP_STR
6909 "Address family\n"
6910 "Address Family modifier\n"
6911 "Address Family modifier\n"
6912 "Network in the BGP routing table to display\n")
6913{
6914 if (strncmp (argv[0], "m", 1) == 0)
6915 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6916
6917 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6918}
6919
paul718e3742002-12-13 20:15:29 +00006920/* old command */
6921DEFUN (show_ipv6_bgp_route,
6922 show_ipv6_bgp_route_cmd,
6923 "show ipv6 bgp X:X::X:X",
6924 SHOW_STR
6925 IP_STR
6926 BGP_STR
6927 "Network in the BGP routing table to display\n")
6928{
6929 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6930}
6931
6932DEFUN (show_bgp_prefix,
6933 show_bgp_prefix_cmd,
6934 "show bgp X:X::X:X/M",
6935 SHOW_STR
6936 BGP_STR
6937 "IPv6 prefix <network>/<length>\n")
6938{
6939 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6940}
6941
6942ALIAS (show_bgp_prefix,
6943 show_bgp_ipv6_prefix_cmd,
6944 "show bgp ipv6 X:X::X:X/M",
6945 SHOW_STR
6946 BGP_STR
6947 "Address family\n"
6948 "IPv6 prefix <network>/<length>\n")
6949
Michael Lambert95cbbd22010-07-23 14:43:04 -04006950DEFUN (show_bgp_ipv6_safi_prefix,
6951 show_bgp_ipv6_safi_prefix_cmd,
6952 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6953 SHOW_STR
6954 BGP_STR
6955 "Address family\n"
6956 "Address Family modifier\n"
6957 "Address Family modifier\n"
6958 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6959{
6960 if (strncmp (argv[0], "m", 1) == 0)
6961 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6962
6963 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6964}
6965
paul718e3742002-12-13 20:15:29 +00006966/* old command */
6967DEFUN (show_ipv6_bgp_prefix,
6968 show_ipv6_bgp_prefix_cmd,
6969 "show ipv6 bgp X:X::X:X/M",
6970 SHOW_STR
6971 IP_STR
6972 BGP_STR
6973 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6974{
6975 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6976}
6977
paulbb46e942003-10-24 19:02:03 +00006978DEFUN (show_bgp_view,
6979 show_bgp_view_cmd,
6980 "show bgp view WORD",
6981 SHOW_STR
6982 BGP_STR
6983 "BGP view\n"
6984 "View name\n")
6985{
6986 struct bgp *bgp;
6987
6988 /* BGP structure lookup. */
6989 bgp = bgp_lookup_by_name (argv[0]);
6990 if (bgp == NULL)
6991 {
6992 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6993 return CMD_WARNING;
6994 }
6995
ajs5a646652004-11-05 01:25:55 +00006996 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006997}
6998
6999ALIAS (show_bgp_view,
7000 show_bgp_view_ipv6_cmd,
7001 "show bgp view WORD ipv6",
7002 SHOW_STR
7003 BGP_STR
7004 "BGP view\n"
7005 "View name\n"
7006 "Address family\n")
7007
7008DEFUN (show_bgp_view_route,
7009 show_bgp_view_route_cmd,
7010 "show bgp view WORD X:X::X:X",
7011 SHOW_STR
7012 BGP_STR
7013 "BGP view\n"
7014 "View name\n"
7015 "Network in the BGP routing table to display\n")
7016{
7017 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7018}
7019
7020ALIAS (show_bgp_view_route,
7021 show_bgp_view_ipv6_route_cmd,
7022 "show bgp view WORD ipv6 X:X::X:X",
7023 SHOW_STR
7024 BGP_STR
7025 "BGP view\n"
7026 "View name\n"
7027 "Address family\n"
7028 "Network in the BGP routing table to display\n")
7029
7030DEFUN (show_bgp_view_prefix,
7031 show_bgp_view_prefix_cmd,
7032 "show bgp view WORD X:X::X:X/M",
7033 SHOW_STR
7034 BGP_STR
7035 "BGP view\n"
7036 "View name\n"
7037 "IPv6 prefix <network>/<length>\n")
7038{
7039 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7040}
7041
7042ALIAS (show_bgp_view_prefix,
7043 show_bgp_view_ipv6_prefix_cmd,
7044 "show bgp view WORD ipv6 X:X::X:X/M",
7045 SHOW_STR
7046 BGP_STR
7047 "BGP view\n"
7048 "View name\n"
7049 "Address family\n"
7050 "IPv6 prefix <network>/<length>\n")
7051
paul718e3742002-12-13 20:15:29 +00007052/* old command */
7053DEFUN (show_ipv6_mbgp,
7054 show_ipv6_mbgp_cmd,
7055 "show ipv6 mbgp",
7056 SHOW_STR
7057 IP_STR
7058 MBGP_STR)
7059{
ajs5a646652004-11-05 01:25:55 +00007060 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7061 NULL);
paul718e3742002-12-13 20:15:29 +00007062}
7063
7064/* old command */
7065DEFUN (show_ipv6_mbgp_route,
7066 show_ipv6_mbgp_route_cmd,
7067 "show ipv6 mbgp X:X::X:X",
7068 SHOW_STR
7069 IP_STR
7070 MBGP_STR
7071 "Network in the MBGP routing table to display\n")
7072{
7073 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7074}
7075
7076/* old command */
7077DEFUN (show_ipv6_mbgp_prefix,
7078 show_ipv6_mbgp_prefix_cmd,
7079 "show ipv6 mbgp X:X::X:X/M",
7080 SHOW_STR
7081 IP_STR
7082 MBGP_STR
7083 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7084{
7085 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7086}
7087#endif
7088
paul718e3742002-12-13 20:15:29 +00007089
paul94f2b392005-06-28 12:44:16 +00007090static int
paulfd79ac92004-10-13 05:06:08 +00007091bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007092 safi_t safi, enum bgp_show_type type)
7093{
7094 int i;
7095 struct buffer *b;
7096 char *regstr;
7097 int first;
7098 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007099 int rc;
paul718e3742002-12-13 20:15:29 +00007100
7101 first = 0;
7102 b = buffer_new (1024);
7103 for (i = 0; i < argc; i++)
7104 {
7105 if (first)
7106 buffer_putc (b, ' ');
7107 else
7108 {
7109 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7110 continue;
7111 first = 1;
7112 }
7113
7114 buffer_putstr (b, argv[i]);
7115 }
7116 buffer_putc (b, '\0');
7117
7118 regstr = buffer_getstr (b);
7119 buffer_free (b);
7120
7121 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007122 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007123 if (! regex)
7124 {
7125 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7126 VTY_NEWLINE);
7127 return CMD_WARNING;
7128 }
7129
ajs5a646652004-11-05 01:25:55 +00007130 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7131 bgp_regex_free (regex);
7132 return rc;
paul718e3742002-12-13 20:15:29 +00007133}
7134
7135DEFUN (show_ip_bgp_regexp,
7136 show_ip_bgp_regexp_cmd,
7137 "show ip bgp regexp .LINE",
7138 SHOW_STR
7139 IP_STR
7140 BGP_STR
7141 "Display routes matching the AS path regular expression\n"
7142 "A regular-expression to match the BGP AS paths\n")
7143{
7144 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7145 bgp_show_type_regexp);
7146}
7147
7148DEFUN (show_ip_bgp_flap_regexp,
7149 show_ip_bgp_flap_regexp_cmd,
7150 "show ip bgp flap-statistics regexp .LINE",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Display flap statistics of routes\n"
7155 "Display routes matching the AS path regular expression\n"
7156 "A regular-expression to match the BGP AS paths\n")
7157{
7158 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7159 bgp_show_type_flap_regexp);
7160}
7161
7162DEFUN (show_ip_bgp_ipv4_regexp,
7163 show_ip_bgp_ipv4_regexp_cmd,
7164 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7165 SHOW_STR
7166 IP_STR
7167 BGP_STR
7168 "Address family\n"
7169 "Address Family modifier\n"
7170 "Address Family modifier\n"
7171 "Display routes matching the AS path regular expression\n"
7172 "A regular-expression to match the BGP AS paths\n")
7173{
7174 if (strncmp (argv[0], "m", 1) == 0)
7175 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7176 bgp_show_type_regexp);
7177
7178 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7179 bgp_show_type_regexp);
7180}
7181
7182#ifdef HAVE_IPV6
7183DEFUN (show_bgp_regexp,
7184 show_bgp_regexp_cmd,
7185 "show bgp regexp .LINE",
7186 SHOW_STR
7187 BGP_STR
7188 "Display routes matching the AS path regular expression\n"
7189 "A regular-expression to match the BGP AS paths\n")
7190{
7191 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7192 bgp_show_type_regexp);
7193}
7194
7195ALIAS (show_bgp_regexp,
7196 show_bgp_ipv6_regexp_cmd,
7197 "show bgp ipv6 regexp .LINE",
7198 SHOW_STR
7199 BGP_STR
7200 "Address family\n"
7201 "Display routes matching the AS path regular expression\n"
7202 "A regular-expression to match the BGP AS paths\n")
7203
7204/* old command */
7205DEFUN (show_ipv6_bgp_regexp,
7206 show_ipv6_bgp_regexp_cmd,
7207 "show ipv6 bgp regexp .LINE",
7208 SHOW_STR
7209 IP_STR
7210 BGP_STR
7211 "Display routes matching the AS path regular expression\n"
7212 "A regular-expression to match the BGP AS paths\n")
7213{
7214 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7215 bgp_show_type_regexp);
7216}
7217
7218/* old command */
7219DEFUN (show_ipv6_mbgp_regexp,
7220 show_ipv6_mbgp_regexp_cmd,
7221 "show ipv6 mbgp regexp .LINE",
7222 SHOW_STR
7223 IP_STR
7224 BGP_STR
7225 "Display routes matching the AS path regular expression\n"
7226 "A regular-expression to match the MBGP AS paths\n")
7227{
7228 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7229 bgp_show_type_regexp);
7230}
7231#endif /* HAVE_IPV6 */
7232
paul94f2b392005-06-28 12:44:16 +00007233static int
paulfd79ac92004-10-13 05:06:08 +00007234bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007235 safi_t safi, enum bgp_show_type type)
7236{
7237 struct prefix_list *plist;
7238
7239 plist = prefix_list_lookup (afi, prefix_list_str);
7240 if (plist == NULL)
7241 {
7242 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7243 prefix_list_str, VTY_NEWLINE);
7244 return CMD_WARNING;
7245 }
7246
ajs5a646652004-11-05 01:25:55 +00007247 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007248}
7249
7250DEFUN (show_ip_bgp_prefix_list,
7251 show_ip_bgp_prefix_list_cmd,
7252 "show ip bgp prefix-list WORD",
7253 SHOW_STR
7254 IP_STR
7255 BGP_STR
7256 "Display routes conforming to the prefix-list\n"
7257 "IP prefix-list name\n")
7258{
7259 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7260 bgp_show_type_prefix_list);
7261}
7262
7263DEFUN (show_ip_bgp_flap_prefix_list,
7264 show_ip_bgp_flap_prefix_list_cmd,
7265 "show ip bgp flap-statistics prefix-list WORD",
7266 SHOW_STR
7267 IP_STR
7268 BGP_STR
7269 "Display flap statistics of routes\n"
7270 "Display routes conforming to the prefix-list\n"
7271 "IP prefix-list name\n")
7272{
7273 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7274 bgp_show_type_flap_prefix_list);
7275}
7276
7277DEFUN (show_ip_bgp_ipv4_prefix_list,
7278 show_ip_bgp_ipv4_prefix_list_cmd,
7279 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Address family\n"
7284 "Address Family modifier\n"
7285 "Address Family modifier\n"
7286 "Display routes conforming to the prefix-list\n"
7287 "IP prefix-list name\n")
7288{
7289 if (strncmp (argv[0], "m", 1) == 0)
7290 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7291 bgp_show_type_prefix_list);
7292
7293 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7294 bgp_show_type_prefix_list);
7295}
7296
7297#ifdef HAVE_IPV6
7298DEFUN (show_bgp_prefix_list,
7299 show_bgp_prefix_list_cmd,
7300 "show bgp prefix-list WORD",
7301 SHOW_STR
7302 BGP_STR
7303 "Display routes conforming to the prefix-list\n"
7304 "IPv6 prefix-list name\n")
7305{
7306 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7307 bgp_show_type_prefix_list);
7308}
7309
7310ALIAS (show_bgp_prefix_list,
7311 show_bgp_ipv6_prefix_list_cmd,
7312 "show bgp ipv6 prefix-list WORD",
7313 SHOW_STR
7314 BGP_STR
7315 "Address family\n"
7316 "Display routes conforming to the prefix-list\n"
7317 "IPv6 prefix-list name\n")
7318
7319/* old command */
7320DEFUN (show_ipv6_bgp_prefix_list,
7321 show_ipv6_bgp_prefix_list_cmd,
7322 "show ipv6 bgp prefix-list WORD",
7323 SHOW_STR
7324 IPV6_STR
7325 BGP_STR
7326 "Display routes matching the prefix-list\n"
7327 "IPv6 prefix-list name\n")
7328{
7329 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7330 bgp_show_type_prefix_list);
7331}
7332
7333/* old command */
7334DEFUN (show_ipv6_mbgp_prefix_list,
7335 show_ipv6_mbgp_prefix_list_cmd,
7336 "show ipv6 mbgp prefix-list WORD",
7337 SHOW_STR
7338 IPV6_STR
7339 MBGP_STR
7340 "Display routes matching the prefix-list\n"
7341 "IPv6 prefix-list name\n")
7342{
7343 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7344 bgp_show_type_prefix_list);
7345}
7346#endif /* HAVE_IPV6 */
7347
paul94f2b392005-06-28 12:44:16 +00007348static int
paulfd79ac92004-10-13 05:06:08 +00007349bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007350 safi_t safi, enum bgp_show_type type)
7351{
7352 struct as_list *as_list;
7353
7354 as_list = as_list_lookup (filter);
7355 if (as_list == NULL)
7356 {
7357 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7358 return CMD_WARNING;
7359 }
7360
ajs5a646652004-11-05 01:25:55 +00007361 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007362}
7363
7364DEFUN (show_ip_bgp_filter_list,
7365 show_ip_bgp_filter_list_cmd,
7366 "show ip bgp filter-list WORD",
7367 SHOW_STR
7368 IP_STR
7369 BGP_STR
7370 "Display routes conforming to the filter-list\n"
7371 "Regular expression access list name\n")
7372{
7373 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7374 bgp_show_type_filter_list);
7375}
7376
7377DEFUN (show_ip_bgp_flap_filter_list,
7378 show_ip_bgp_flap_filter_list_cmd,
7379 "show ip bgp flap-statistics filter-list WORD",
7380 SHOW_STR
7381 IP_STR
7382 BGP_STR
7383 "Display flap statistics of routes\n"
7384 "Display routes conforming to the filter-list\n"
7385 "Regular expression access list name\n")
7386{
7387 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7388 bgp_show_type_flap_filter_list);
7389}
7390
7391DEFUN (show_ip_bgp_ipv4_filter_list,
7392 show_ip_bgp_ipv4_filter_list_cmd,
7393 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7394 SHOW_STR
7395 IP_STR
7396 BGP_STR
7397 "Address family\n"
7398 "Address Family modifier\n"
7399 "Address Family modifier\n"
7400 "Display routes conforming to the filter-list\n"
7401 "Regular expression access list name\n")
7402{
7403 if (strncmp (argv[0], "m", 1) == 0)
7404 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7405 bgp_show_type_filter_list);
7406
7407 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7408 bgp_show_type_filter_list);
7409}
7410
7411#ifdef HAVE_IPV6
7412DEFUN (show_bgp_filter_list,
7413 show_bgp_filter_list_cmd,
7414 "show bgp filter-list WORD",
7415 SHOW_STR
7416 BGP_STR
7417 "Display routes conforming to the filter-list\n"
7418 "Regular expression access list name\n")
7419{
7420 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7421 bgp_show_type_filter_list);
7422}
7423
7424ALIAS (show_bgp_filter_list,
7425 show_bgp_ipv6_filter_list_cmd,
7426 "show bgp ipv6 filter-list WORD",
7427 SHOW_STR
7428 BGP_STR
7429 "Address family\n"
7430 "Display routes conforming to the filter-list\n"
7431 "Regular expression access list name\n")
7432
7433/* old command */
7434DEFUN (show_ipv6_bgp_filter_list,
7435 show_ipv6_bgp_filter_list_cmd,
7436 "show ipv6 bgp filter-list WORD",
7437 SHOW_STR
7438 IPV6_STR
7439 BGP_STR
7440 "Display routes conforming to the filter-list\n"
7441 "Regular expression access list name\n")
7442{
7443 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7444 bgp_show_type_filter_list);
7445}
7446
7447/* old command */
7448DEFUN (show_ipv6_mbgp_filter_list,
7449 show_ipv6_mbgp_filter_list_cmd,
7450 "show ipv6 mbgp filter-list WORD",
7451 SHOW_STR
7452 IPV6_STR
7453 MBGP_STR
7454 "Display routes conforming to the filter-list\n"
7455 "Regular expression access list name\n")
7456{
7457 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7458 bgp_show_type_filter_list);
7459}
7460#endif /* HAVE_IPV6 */
7461
paul94f2b392005-06-28 12:44:16 +00007462static int
paulfd79ac92004-10-13 05:06:08 +00007463bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007464 safi_t safi, enum bgp_show_type type)
7465{
7466 struct route_map *rmap;
7467
7468 rmap = route_map_lookup_by_name (rmap_str);
7469 if (! rmap)
7470 {
7471 vty_out (vty, "%% %s is not a valid route-map name%s",
7472 rmap_str, VTY_NEWLINE);
7473 return CMD_WARNING;
7474 }
7475
ajs5a646652004-11-05 01:25:55 +00007476 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007477}
7478
7479DEFUN (show_ip_bgp_route_map,
7480 show_ip_bgp_route_map_cmd,
7481 "show ip bgp route-map WORD",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Display routes matching the route-map\n"
7486 "A route-map to match on\n")
7487{
7488 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7489 bgp_show_type_route_map);
7490}
7491
7492DEFUN (show_ip_bgp_flap_route_map,
7493 show_ip_bgp_flap_route_map_cmd,
7494 "show ip bgp flap-statistics route-map WORD",
7495 SHOW_STR
7496 IP_STR
7497 BGP_STR
7498 "Display flap statistics of routes\n"
7499 "Display routes matching the route-map\n"
7500 "A route-map to match on\n")
7501{
7502 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7503 bgp_show_type_flap_route_map);
7504}
7505
7506DEFUN (show_ip_bgp_ipv4_route_map,
7507 show_ip_bgp_ipv4_route_map_cmd,
7508 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7509 SHOW_STR
7510 IP_STR
7511 BGP_STR
7512 "Address family\n"
7513 "Address Family modifier\n"
7514 "Address Family modifier\n"
7515 "Display routes matching the route-map\n"
7516 "A route-map to match on\n")
7517{
7518 if (strncmp (argv[0], "m", 1) == 0)
7519 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7520 bgp_show_type_route_map);
7521
7522 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7523 bgp_show_type_route_map);
7524}
7525
7526DEFUN (show_bgp_route_map,
7527 show_bgp_route_map_cmd,
7528 "show bgp route-map WORD",
7529 SHOW_STR
7530 BGP_STR
7531 "Display routes matching the route-map\n"
7532 "A route-map to match on\n")
7533{
7534 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7535 bgp_show_type_route_map);
7536}
7537
7538ALIAS (show_bgp_route_map,
7539 show_bgp_ipv6_route_map_cmd,
7540 "show bgp ipv6 route-map WORD",
7541 SHOW_STR
7542 BGP_STR
7543 "Address family\n"
7544 "Display routes matching the route-map\n"
7545 "A route-map to match on\n")
7546
7547DEFUN (show_ip_bgp_cidr_only,
7548 show_ip_bgp_cidr_only_cmd,
7549 "show ip bgp cidr-only",
7550 SHOW_STR
7551 IP_STR
7552 BGP_STR
7553 "Display only routes with non-natural netmasks\n")
7554{
7555 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007556 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007557}
7558
7559DEFUN (show_ip_bgp_flap_cidr_only,
7560 show_ip_bgp_flap_cidr_only_cmd,
7561 "show ip bgp flap-statistics cidr-only",
7562 SHOW_STR
7563 IP_STR
7564 BGP_STR
7565 "Display flap statistics of routes\n"
7566 "Display only routes with non-natural netmasks\n")
7567{
7568 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007569 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007570}
7571
7572DEFUN (show_ip_bgp_ipv4_cidr_only,
7573 show_ip_bgp_ipv4_cidr_only_cmd,
7574 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7575 SHOW_STR
7576 IP_STR
7577 BGP_STR
7578 "Address family\n"
7579 "Address Family modifier\n"
7580 "Address Family modifier\n"
7581 "Display only routes with non-natural netmasks\n")
7582{
7583 if (strncmp (argv[0], "m", 1) == 0)
7584 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007585 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007586
7587 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007588 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007589}
7590
7591DEFUN (show_ip_bgp_community_all,
7592 show_ip_bgp_community_all_cmd,
7593 "show ip bgp community",
7594 SHOW_STR
7595 IP_STR
7596 BGP_STR
7597 "Display routes matching the communities\n")
7598{
7599 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007600 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007601}
7602
7603DEFUN (show_ip_bgp_ipv4_community_all,
7604 show_ip_bgp_ipv4_community_all_cmd,
7605 "show ip bgp ipv4 (unicast|multicast) community",
7606 SHOW_STR
7607 IP_STR
7608 BGP_STR
7609 "Address family\n"
7610 "Address Family modifier\n"
7611 "Address Family modifier\n"
7612 "Display routes matching the communities\n")
7613{
7614 if (strncmp (argv[0], "m", 1) == 0)
7615 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007616 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007617
7618 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007619 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007620}
7621
7622#ifdef HAVE_IPV6
7623DEFUN (show_bgp_community_all,
7624 show_bgp_community_all_cmd,
7625 "show bgp community",
7626 SHOW_STR
7627 BGP_STR
7628 "Display routes matching the communities\n")
7629{
7630 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007631 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007632}
7633
7634ALIAS (show_bgp_community_all,
7635 show_bgp_ipv6_community_all_cmd,
7636 "show bgp ipv6 community",
7637 SHOW_STR
7638 BGP_STR
7639 "Address family\n"
7640 "Display routes matching the communities\n")
7641
7642/* old command */
7643DEFUN (show_ipv6_bgp_community_all,
7644 show_ipv6_bgp_community_all_cmd,
7645 "show ipv6 bgp community",
7646 SHOW_STR
7647 IPV6_STR
7648 BGP_STR
7649 "Display routes matching the communities\n")
7650{
7651 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007652 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007653}
7654
7655/* old command */
7656DEFUN (show_ipv6_mbgp_community_all,
7657 show_ipv6_mbgp_community_all_cmd,
7658 "show ipv6 mbgp community",
7659 SHOW_STR
7660 IPV6_STR
7661 MBGP_STR
7662 "Display routes matching the communities\n")
7663{
7664 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007665 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007666}
7667#endif /* HAVE_IPV6 */
7668
paul94f2b392005-06-28 12:44:16 +00007669static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007670bgp_show_community (struct vty *vty, const char *view_name, int argc,
7671 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007672{
7673 struct community *com;
7674 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007675 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007676 int i;
7677 char *str;
7678 int first = 0;
7679
Michael Lambert95cbbd22010-07-23 14:43:04 -04007680 /* BGP structure lookup */
7681 if (view_name)
7682 {
7683 bgp = bgp_lookup_by_name (view_name);
7684 if (bgp == NULL)
7685 {
7686 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7687 return CMD_WARNING;
7688 }
7689 }
7690 else
7691 {
7692 bgp = bgp_get_default ();
7693 if (bgp == NULL)
7694 {
7695 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7696 return CMD_WARNING;
7697 }
7698 }
7699
paul718e3742002-12-13 20:15:29 +00007700 b = buffer_new (1024);
7701 for (i = 0; i < argc; i++)
7702 {
7703 if (first)
7704 buffer_putc (b, ' ');
7705 else
7706 {
7707 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7708 continue;
7709 first = 1;
7710 }
7711
7712 buffer_putstr (b, argv[i]);
7713 }
7714 buffer_putc (b, '\0');
7715
7716 str = buffer_getstr (b);
7717 buffer_free (b);
7718
7719 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007720 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007721 if (! com)
7722 {
7723 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7724 return CMD_WARNING;
7725 }
7726
Michael Lambert95cbbd22010-07-23 14:43:04 -04007727 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007728 (exact ? bgp_show_type_community_exact :
7729 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007730}
7731
7732DEFUN (show_ip_bgp_community,
7733 show_ip_bgp_community_cmd,
7734 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7735 SHOW_STR
7736 IP_STR
7737 BGP_STR
7738 "Display routes matching the communities\n"
7739 "community number\n"
7740 "Do not send outside local AS (well-known community)\n"
7741 "Do not advertise to any peer (well-known community)\n"
7742 "Do not export to next AS (well-known community)\n")
7743{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007744 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007745}
7746
7747ALIAS (show_ip_bgp_community,
7748 show_ip_bgp_community2_cmd,
7749 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7750 SHOW_STR
7751 IP_STR
7752 BGP_STR
7753 "Display routes matching the communities\n"
7754 "community number\n"
7755 "Do not send outside local AS (well-known community)\n"
7756 "Do not advertise to any peer (well-known community)\n"
7757 "Do not export to next AS (well-known community)\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n")
7762
7763ALIAS (show_ip_bgp_community,
7764 show_ip_bgp_community3_cmd,
7765 "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)",
7766 SHOW_STR
7767 IP_STR
7768 BGP_STR
7769 "Display routes matching the communities\n"
7770 "community number\n"
7771 "Do not send outside local AS (well-known community)\n"
7772 "Do not advertise to any peer (well-known community)\n"
7773 "Do not export to next AS (well-known community)\n"
7774 "community number\n"
7775 "Do not send outside local AS (well-known community)\n"
7776 "Do not advertise to any peer (well-known community)\n"
7777 "Do not export to next AS (well-known community)\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n")
7782
7783ALIAS (show_ip_bgp_community,
7784 show_ip_bgp_community4_cmd,
7785 "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)",
7786 SHOW_STR
7787 IP_STR
7788 BGP_STR
7789 "Display routes matching the communities\n"
7790 "community number\n"
7791 "Do not send outside local AS (well-known community)\n"
7792 "Do not advertise to any peer (well-known community)\n"
7793 "Do not export to next AS (well-known community)\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n"
7798 "community number\n"
7799 "Do not send outside local AS (well-known community)\n"
7800 "Do not advertise to any peer (well-known community)\n"
7801 "Do not export to next AS (well-known community)\n"
7802 "community number\n"
7803 "Do not send outside local AS (well-known community)\n"
7804 "Do not advertise to any peer (well-known community)\n"
7805 "Do not export to next AS (well-known community)\n")
7806
7807DEFUN (show_ip_bgp_ipv4_community,
7808 show_ip_bgp_ipv4_community_cmd,
7809 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7810 SHOW_STR
7811 IP_STR
7812 BGP_STR
7813 "Address family\n"
7814 "Address Family modifier\n"
7815 "Address Family modifier\n"
7816 "Display routes matching the communities\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n")
7821{
7822 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007823 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007824
Michael Lambert95cbbd22010-07-23 14:43:04 -04007825 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007826}
7827
7828ALIAS (show_ip_bgp_ipv4_community,
7829 show_ip_bgp_ipv4_community2_cmd,
7830 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7831 SHOW_STR
7832 IP_STR
7833 BGP_STR
7834 "Address family\n"
7835 "Address Family modifier\n"
7836 "Address Family modifier\n"
7837 "Display routes matching the communities\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n")
7846
7847ALIAS (show_ip_bgp_ipv4_community,
7848 show_ip_bgp_ipv4_community3_cmd,
7849 "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)",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
7853 "Address family\n"
7854 "Address Family modifier\n"
7855 "Address Family modifier\n"
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n")
7869
7870ALIAS (show_ip_bgp_ipv4_community,
7871 show_ip_bgp_ipv4_community4_cmd,
7872 "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)",
7873 SHOW_STR
7874 IP_STR
7875 BGP_STR
7876 "Address family\n"
7877 "Address Family modifier\n"
7878 "Address Family modifier\n"
7879 "Display routes matching the communities\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n")
7896
Michael Lambert95cbbd22010-07-23 14:43:04 -04007897DEFUN (show_bgp_view_afi_safi_community_all,
7898 show_bgp_view_afi_safi_community_all_cmd,
7899#ifdef HAVE_IPV6
7900 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7901#else
7902 "show bgp view WORD ipv4 (unicast|multicast) community",
7903#endif
7904 SHOW_STR
7905 BGP_STR
7906 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007907 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007908 "Address family\n"
7909#ifdef HAVE_IPV6
7910 "Address family\n"
7911#endif
7912 "Address Family modifier\n"
7913 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007914 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007915{
7916 int afi;
7917 int safi;
7918 struct bgp *bgp;
7919
7920 /* BGP structure lookup. */
7921 bgp = bgp_lookup_by_name (argv[0]);
7922 if (bgp == NULL)
7923 {
7924 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7925 return CMD_WARNING;
7926 }
7927
7928#ifdef HAVE_IPV6
7929 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7930 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7931#else
7932 afi = AFI_IP;
7933 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7934#endif
7935 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7936}
7937
7938DEFUN (show_bgp_view_afi_safi_community,
7939 show_bgp_view_afi_safi_community_cmd,
7940#ifdef HAVE_IPV6
7941 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7942#else
7943 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7944#endif
7945 SHOW_STR
7946 BGP_STR
7947 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007948 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007949 "Address family\n"
7950#ifdef HAVE_IPV6
7951 "Address family\n"
7952#endif
7953 "Address family modifier\n"
7954 "Address family modifier\n"
7955 "Display routes matching the communities\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n")
7960{
7961 int afi;
7962 int safi;
7963
7964#ifdef HAVE_IPV6
7965 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7966 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7967 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7968#else
7969 afi = AFI_IP;
7970 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7971 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7972#endif
7973}
7974
7975ALIAS (show_bgp_view_afi_safi_community,
7976 show_bgp_view_afi_safi_community2_cmd,
7977#ifdef HAVE_IPV6
7978 "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)",
7979#else
7980 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7981#endif
7982 SHOW_STR
7983 BGP_STR
7984 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007985 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007986 "Address family\n"
7987#ifdef HAVE_IPV6
7988 "Address family\n"
7989#endif
7990 "Address family modifier\n"
7991 "Address family modifier\n"
7992 "Display routes matching the communities\n"
7993 "community number\n"
7994 "Do not send outside local AS (well-known community)\n"
7995 "Do not advertise to any peer (well-known community)\n"
7996 "Do not export to next AS (well-known community)\n"
7997 "community number\n"
7998 "Do not send outside local AS (well-known community)\n"
7999 "Do not advertise to any peer (well-known community)\n"
8000 "Do not export to next AS (well-known community)\n")
8001
8002ALIAS (show_bgp_view_afi_safi_community,
8003 show_bgp_view_afi_safi_community3_cmd,
8004#ifdef HAVE_IPV6
8005 "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)",
8006#else
8007 "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)",
8008#endif
8009 SHOW_STR
8010 BGP_STR
8011 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008012 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008013 "Address family\n"
8014#ifdef HAVE_IPV6
8015 "Address family\n"
8016#endif
8017 "Address family modifier\n"
8018 "Address family modifier\n"
8019 "Display routes matching the communities\n"
8020 "community number\n"
8021 "Do not send outside local AS (well-known community)\n"
8022 "Do not advertise to any peer (well-known community)\n"
8023 "Do not export to next AS (well-known community)\n"
8024 "community number\n"
8025 "Do not send outside local AS (well-known community)\n"
8026 "Do not advertise to any peer (well-known community)\n"
8027 "Do not export to next AS (well-known community)\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n")
8032
8033ALIAS (show_bgp_view_afi_safi_community,
8034 show_bgp_view_afi_safi_community4_cmd,
8035#ifdef HAVE_IPV6
8036 "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)",
8037#else
8038 "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)",
8039#endif
8040 SHOW_STR
8041 BGP_STR
8042 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008043 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008044 "Address family\n"
8045#ifdef HAVE_IPV6
8046 "Address family\n"
8047#endif
8048 "Address family modifier\n"
8049 "Address family modifier\n"
8050 "Display routes matching the communities\n"
8051 "community number\n"
8052 "Do not send outside local AS (well-known community)\n"
8053 "Do not advertise to any peer (well-known community)\n"
8054 "Do not export to next AS (well-known community)\n"
8055 "community number\n"
8056 "Do not send outside local AS (well-known community)\n"
8057 "Do not advertise to any peer (well-known community)\n"
8058 "Do not export to next AS (well-known community)\n"
8059 "community number\n"
8060 "Do not send outside local AS (well-known community)\n"
8061 "Do not advertise to any peer (well-known community)\n"
8062 "Do not export to next AS (well-known community)\n"
8063 "community number\n"
8064 "Do not send outside local AS (well-known community)\n"
8065 "Do not advertise to any peer (well-known community)\n"
8066 "Do not export to next AS (well-known community)\n")
8067
paul718e3742002-12-13 20:15:29 +00008068DEFUN (show_ip_bgp_community_exact,
8069 show_ip_bgp_community_exact_cmd,
8070 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8071 SHOW_STR
8072 IP_STR
8073 BGP_STR
8074 "Display routes matching the communities\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n"
8079 "Exact match of the communities")
8080{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008081 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008082}
8083
8084ALIAS (show_ip_bgp_community_exact,
8085 show_ip_bgp_community2_exact_cmd,
8086 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8087 SHOW_STR
8088 IP_STR
8089 BGP_STR
8090 "Display routes matching the communities\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n"
8099 "Exact match of the communities")
8100
8101ALIAS (show_ip_bgp_community_exact,
8102 show_ip_bgp_community3_exact_cmd,
8103 "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",
8104 SHOW_STR
8105 IP_STR
8106 BGP_STR
8107 "Display routes matching the communities\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n"
8116 "community number\n"
8117 "Do not send outside local AS (well-known community)\n"
8118 "Do not advertise to any peer (well-known community)\n"
8119 "Do not export to next AS (well-known community)\n"
8120 "Exact match of the communities")
8121
8122ALIAS (show_ip_bgp_community_exact,
8123 show_ip_bgp_community4_exact_cmd,
8124 "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",
8125 SHOW_STR
8126 IP_STR
8127 BGP_STR
8128 "Display routes matching the communities\n"
8129 "community number\n"
8130 "Do not send outside local AS (well-known community)\n"
8131 "Do not advertise to any peer (well-known community)\n"
8132 "Do not export to next AS (well-known community)\n"
8133 "community number\n"
8134 "Do not send outside local AS (well-known community)\n"
8135 "Do not advertise to any peer (well-known community)\n"
8136 "Do not export to next AS (well-known community)\n"
8137 "community number\n"
8138 "Do not send outside local AS (well-known community)\n"
8139 "Do not advertise to any peer (well-known community)\n"
8140 "Do not export to next AS (well-known community)\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n"
8145 "Exact match of the communities")
8146
8147DEFUN (show_ip_bgp_ipv4_community_exact,
8148 show_ip_bgp_ipv4_community_exact_cmd,
8149 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8150 SHOW_STR
8151 IP_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "Exact match of the communities")
8162{
8163 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008164 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008165
Michael Lambert95cbbd22010-07-23 14:43:04 -04008166 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008167}
8168
8169ALIAS (show_ip_bgp_ipv4_community_exact,
8170 show_ip_bgp_ipv4_community2_exact_cmd,
8171 "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",
8172 SHOW_STR
8173 IP_STR
8174 BGP_STR
8175 "Address family\n"
8176 "Address Family modifier\n"
8177 "Address Family modifier\n"
8178 "Display routes matching the communities\n"
8179 "community number\n"
8180 "Do not send outside local AS (well-known community)\n"
8181 "Do not advertise to any peer (well-known community)\n"
8182 "Do not export to next AS (well-known community)\n"
8183 "community number\n"
8184 "Do not send outside local AS (well-known community)\n"
8185 "Do not advertise to any peer (well-known community)\n"
8186 "Do not export to next AS (well-known community)\n"
8187 "Exact match of the communities")
8188
8189ALIAS (show_ip_bgp_ipv4_community_exact,
8190 show_ip_bgp_ipv4_community3_exact_cmd,
8191 "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",
8192 SHOW_STR
8193 IP_STR
8194 BGP_STR
8195 "Address family\n"
8196 "Address Family modifier\n"
8197 "Address Family modifier\n"
8198 "Display routes matching the communities\n"
8199 "community number\n"
8200 "Do not send outside local AS (well-known community)\n"
8201 "Do not advertise to any peer (well-known community)\n"
8202 "Do not export to next AS (well-known community)\n"
8203 "community number\n"
8204 "Do not send outside local AS (well-known community)\n"
8205 "Do not advertise to any peer (well-known community)\n"
8206 "Do not export to next AS (well-known community)\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "Exact match of the communities")
8212
8213ALIAS (show_ip_bgp_ipv4_community_exact,
8214 show_ip_bgp_ipv4_community4_exact_cmd,
8215 "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",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "Address Family modifier\n"
8221 "Address Family modifier\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "community number\n"
8232 "Do not send outside local AS (well-known community)\n"
8233 "Do not advertise to any peer (well-known community)\n"
8234 "Do not export to next AS (well-known community)\n"
8235 "community number\n"
8236 "Do not send outside local AS (well-known community)\n"
8237 "Do not advertise to any peer (well-known community)\n"
8238 "Do not export to next AS (well-known community)\n"
8239 "Exact match of the communities")
8240
8241#ifdef HAVE_IPV6
8242DEFUN (show_bgp_community,
8243 show_bgp_community_cmd,
8244 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8245 SHOW_STR
8246 BGP_STR
8247 "Display routes matching the communities\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n")
8252{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008253 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008254}
8255
8256ALIAS (show_bgp_community,
8257 show_bgp_ipv6_community_cmd,
8258 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8259 SHOW_STR
8260 BGP_STR
8261 "Address family\n"
8262 "Display routes matching the communities\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n")
8267
8268ALIAS (show_bgp_community,
8269 show_bgp_community2_cmd,
8270 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8271 SHOW_STR
8272 BGP_STR
8273 "Display routes matching the communities\n"
8274 "community number\n"
8275 "Do not send outside local AS (well-known community)\n"
8276 "Do not advertise to any peer (well-known community)\n"
8277 "Do not export to next AS (well-known community)\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
8283ALIAS (show_bgp_community,
8284 show_bgp_ipv6_community2_cmd,
8285 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8286 SHOW_STR
8287 BGP_STR
8288 "Address family\n"
8289 "Display routes matching the communities\n"
8290 "community number\n"
8291 "Do not send outside local AS (well-known community)\n"
8292 "Do not advertise to any peer (well-known community)\n"
8293 "Do not export to next AS (well-known community)\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n")
8298
8299ALIAS (show_bgp_community,
8300 show_bgp_community3_cmd,
8301 "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)",
8302 SHOW_STR
8303 BGP_STR
8304 "Display routes matching the communities\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "community number\n"
8314 "Do not send outside local AS (well-known community)\n"
8315 "Do not advertise to any peer (well-known community)\n"
8316 "Do not export to next AS (well-known community)\n")
8317
8318ALIAS (show_bgp_community,
8319 show_bgp_ipv6_community3_cmd,
8320 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8321 SHOW_STR
8322 BGP_STR
8323 "Address family\n"
8324 "Display routes matching the communities\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n")
8337
8338ALIAS (show_bgp_community,
8339 show_bgp_community4_cmd,
8340 "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)",
8341 SHOW_STR
8342 BGP_STR
8343 "Display routes matching the communities\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "community number\n"
8357 "Do not send outside local AS (well-known community)\n"
8358 "Do not advertise to any peer (well-known community)\n"
8359 "Do not export to next AS (well-known community)\n")
8360
8361ALIAS (show_bgp_community,
8362 show_bgp_ipv6_community4_cmd,
8363 "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)",
8364 SHOW_STR
8365 BGP_STR
8366 "Address family\n"
8367 "Display routes matching the communities\n"
8368 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "community number\n"
8377 "Do not send outside local AS (well-known community)\n"
8378 "Do not advertise to any peer (well-known community)\n"
8379 "Do not export to next AS (well-known community)\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n")
8384
8385/* old command */
8386DEFUN (show_ipv6_bgp_community,
8387 show_ipv6_bgp_community_cmd,
8388 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8389 SHOW_STR
8390 IPV6_STR
8391 BGP_STR
8392 "Display routes matching the communities\n"
8393 "community number\n"
8394 "Do not send outside local AS (well-known community)\n"
8395 "Do not advertise to any peer (well-known community)\n"
8396 "Do not export to next AS (well-known community)\n")
8397{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008398 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008399}
8400
8401/* old command */
8402ALIAS (show_ipv6_bgp_community,
8403 show_ipv6_bgp_community2_cmd,
8404 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8405 SHOW_STR
8406 IPV6_STR
8407 BGP_STR
8408 "Display routes matching the communities\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n")
8417
8418/* old command */
8419ALIAS (show_ipv6_bgp_community,
8420 show_ipv6_bgp_community3_cmd,
8421 "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)",
8422 SHOW_STR
8423 IPV6_STR
8424 BGP_STR
8425 "Display routes matching the communities\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n")
8438
8439/* old command */
8440ALIAS (show_ipv6_bgp_community,
8441 show_ipv6_bgp_community4_cmd,
8442 "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)",
8443 SHOW_STR
8444 IPV6_STR
8445 BGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "community number\n"
8460 "Do not send outside local AS (well-known community)\n"
8461 "Do not advertise to any peer (well-known community)\n"
8462 "Do not export to next AS (well-known community)\n")
8463
8464DEFUN (show_bgp_community_exact,
8465 show_bgp_community_exact_cmd,
8466 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8467 SHOW_STR
8468 BGP_STR
8469 "Display routes matching the communities\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 "Exact match of the communities")
8475{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008476 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008477}
8478
8479ALIAS (show_bgp_community_exact,
8480 show_bgp_ipv6_community_exact_cmd,
8481 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8482 SHOW_STR
8483 BGP_STR
8484 "Address family\n"
8485 "Display routes matching the communities\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n"
8490 "Exact match of the communities")
8491
8492ALIAS (show_bgp_community_exact,
8493 show_bgp_community2_exact_cmd,
8494 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8495 SHOW_STR
8496 BGP_STR
8497 "Display routes matching the communities\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n"
8506 "Exact match of the communities")
8507
8508ALIAS (show_bgp_community_exact,
8509 show_bgp_ipv6_community2_exact_cmd,
8510 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8511 SHOW_STR
8512 BGP_STR
8513 "Address family\n"
8514 "Display routes matching the communities\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "community number\n"
8520 "Do not send outside local AS (well-known community)\n"
8521 "Do not advertise to any peer (well-known community)\n"
8522 "Do not export to next AS (well-known community)\n"
8523 "Exact match of the communities")
8524
8525ALIAS (show_bgp_community_exact,
8526 show_bgp_community3_exact_cmd,
8527 "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",
8528 SHOW_STR
8529 BGP_STR
8530 "Display routes matching the communities\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 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "Exact match of the communities")
8544
8545ALIAS (show_bgp_community_exact,
8546 show_bgp_ipv6_community3_exact_cmd,
8547 "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",
8548 SHOW_STR
8549 BGP_STR
8550 "Address family\n"
8551 "Display routes matching the communities\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "community number\n"
8557 "Do not send outside local AS (well-known community)\n"
8558 "Do not advertise to any peer (well-known community)\n"
8559 "Do not export to next AS (well-known community)\n"
8560 "community number\n"
8561 "Do not send outside local AS (well-known community)\n"
8562 "Do not advertise to any peer (well-known community)\n"
8563 "Do not export to next AS (well-known community)\n"
8564 "Exact match of the communities")
8565
8566ALIAS (show_bgp_community_exact,
8567 show_bgp_community4_exact_cmd,
8568 "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",
8569 SHOW_STR
8570 BGP_STR
8571 "Display routes matching the communities\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "Exact match of the communities")
8589
8590ALIAS (show_bgp_community_exact,
8591 show_bgp_ipv6_community4_exact_cmd,
8592 "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",
8593 SHOW_STR
8594 BGP_STR
8595 "Address family\n"
8596 "Display routes matching the communities\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "community number\n"
8610 "Do not send outside local AS (well-known community)\n"
8611 "Do not advertise to any peer (well-known community)\n"
8612 "Do not export to next AS (well-known community)\n"
8613 "Exact match of the communities")
8614
8615/* old command */
8616DEFUN (show_ipv6_bgp_community_exact,
8617 show_ipv6_bgp_community_exact_cmd,
8618 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8619 SHOW_STR
8620 IPV6_STR
8621 BGP_STR
8622 "Display routes matching the communities\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "Exact match of the communities")
8628{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008629 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008630}
8631
8632/* old command */
8633ALIAS (show_ipv6_bgp_community_exact,
8634 show_ipv6_bgp_community2_exact_cmd,
8635 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8636 SHOW_STR
8637 IPV6_STR
8638 BGP_STR
8639 "Display routes matching the communities\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "Exact match of the communities")
8649
8650/* old command */
8651ALIAS (show_ipv6_bgp_community_exact,
8652 show_ipv6_bgp_community3_exact_cmd,
8653 "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",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Display routes matching the communities\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "community number\n"
8667 "Do not send outside local AS (well-known community)\n"
8668 "Do not advertise to any peer (well-known community)\n"
8669 "Do not export to next AS (well-known community)\n"
8670 "Exact match of the communities")
8671
8672/* old command */
8673ALIAS (show_ipv6_bgp_community_exact,
8674 show_ipv6_bgp_community4_exact_cmd,
8675 "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",
8676 SHOW_STR
8677 IPV6_STR
8678 BGP_STR
8679 "Display routes matching the communities\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "community number\n"
8689 "Do not send outside local AS (well-known community)\n"
8690 "Do not advertise to any peer (well-known community)\n"
8691 "Do not export to next AS (well-known community)\n"
8692 "community number\n"
8693 "Do not send outside local AS (well-known community)\n"
8694 "Do not advertise to any peer (well-known community)\n"
8695 "Do not export to next AS (well-known community)\n"
8696 "Exact match of the communities")
8697
8698/* old command */
8699DEFUN (show_ipv6_mbgp_community,
8700 show_ipv6_mbgp_community_cmd,
8701 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8702 SHOW_STR
8703 IPV6_STR
8704 MBGP_STR
8705 "Display routes matching the communities\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n")
8710{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008711 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008712}
8713
8714/* old command */
8715ALIAS (show_ipv6_mbgp_community,
8716 show_ipv6_mbgp_community2_cmd,
8717 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8718 SHOW_STR
8719 IPV6_STR
8720 MBGP_STR
8721 "Display routes matching the communities\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n")
8730
8731/* old command */
8732ALIAS (show_ipv6_mbgp_community,
8733 show_ipv6_mbgp_community3_cmd,
8734 "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)",
8735 SHOW_STR
8736 IPV6_STR
8737 MBGP_STR
8738 "Display routes matching the communities\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "community number\n"
8744 "Do not send outside local AS (well-known community)\n"
8745 "Do not advertise to any peer (well-known community)\n"
8746 "Do not export to next AS (well-known community)\n"
8747 "community number\n"
8748 "Do not send outside local AS (well-known community)\n"
8749 "Do not advertise to any peer (well-known community)\n"
8750 "Do not export to next AS (well-known community)\n")
8751
8752/* old command */
8753ALIAS (show_ipv6_mbgp_community,
8754 show_ipv6_mbgp_community4_cmd,
8755 "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)",
8756 SHOW_STR
8757 IPV6_STR
8758 MBGP_STR
8759 "Display routes matching the communities\n"
8760 "community number\n"
8761 "Do not send outside local AS (well-known community)\n"
8762 "Do not advertise to any peer (well-known community)\n"
8763 "Do not export to next AS (well-known community)\n"
8764 "community number\n"
8765 "Do not send outside local AS (well-known community)\n"
8766 "Do not advertise to any peer (well-known community)\n"
8767 "Do not export to next AS (well-known community)\n"
8768 "community number\n"
8769 "Do not send outside local AS (well-known community)\n"
8770 "Do not advertise to any peer (well-known community)\n"
8771 "Do not export to next AS (well-known community)\n"
8772 "community number\n"
8773 "Do not send outside local AS (well-known community)\n"
8774 "Do not advertise to any peer (well-known community)\n"
8775 "Do not export to next AS (well-known community)\n")
8776
8777/* old command */
8778DEFUN (show_ipv6_mbgp_community_exact,
8779 show_ipv6_mbgp_community_exact_cmd,
8780 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8781 SHOW_STR
8782 IPV6_STR
8783 MBGP_STR
8784 "Display routes matching the communities\n"
8785 "community number\n"
8786 "Do not send outside local AS (well-known community)\n"
8787 "Do not advertise to any peer (well-known community)\n"
8788 "Do not export to next AS (well-known community)\n"
8789 "Exact match of the communities")
8790{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008791 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008792}
8793
8794/* old command */
8795ALIAS (show_ipv6_mbgp_community_exact,
8796 show_ipv6_mbgp_community2_exact_cmd,
8797 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8798 SHOW_STR
8799 IPV6_STR
8800 MBGP_STR
8801 "Display routes matching the communities\n"
8802 "community number\n"
8803 "Do not send outside local AS (well-known community)\n"
8804 "Do not advertise to any peer (well-known community)\n"
8805 "Do not export to next AS (well-known community)\n"
8806 "community number\n"
8807 "Do not send outside local AS (well-known community)\n"
8808 "Do not advertise to any peer (well-known community)\n"
8809 "Do not export to next AS (well-known community)\n"
8810 "Exact match of the communities")
8811
8812/* old command */
8813ALIAS (show_ipv6_mbgp_community_exact,
8814 show_ipv6_mbgp_community3_exact_cmd,
8815 "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",
8816 SHOW_STR
8817 IPV6_STR
8818 MBGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "Exact match of the communities")
8833
8834/* old command */
8835ALIAS (show_ipv6_mbgp_community_exact,
8836 show_ipv6_mbgp_community4_exact_cmd,
8837 "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",
8838 SHOW_STR
8839 IPV6_STR
8840 MBGP_STR
8841 "Display routes matching the communities\n"
8842 "community number\n"
8843 "Do not send outside local AS (well-known community)\n"
8844 "Do not advertise to any peer (well-known community)\n"
8845 "Do not export to next AS (well-known community)\n"
8846 "community number\n"
8847 "Do not send outside local AS (well-known community)\n"
8848 "Do not advertise to any peer (well-known community)\n"
8849 "Do not export to next AS (well-known community)\n"
8850 "community number\n"
8851 "Do not send outside local AS (well-known community)\n"
8852 "Do not advertise to any peer (well-known community)\n"
8853 "Do not export to next AS (well-known community)\n"
8854 "community number\n"
8855 "Do not send outside local AS (well-known community)\n"
8856 "Do not advertise to any peer (well-known community)\n"
8857 "Do not export to next AS (well-known community)\n"
8858 "Exact match of the communities")
8859#endif /* HAVE_IPV6 */
8860
paul94f2b392005-06-28 12:44:16 +00008861static int
paulfd79ac92004-10-13 05:06:08 +00008862bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008863 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008864{
8865 struct community_list *list;
8866
hassofee6e4e2005-02-02 16:29:31 +00008867 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008868 if (list == NULL)
8869 {
8870 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8871 VTY_NEWLINE);
8872 return CMD_WARNING;
8873 }
8874
ajs5a646652004-11-05 01:25:55 +00008875 return bgp_show (vty, NULL, afi, safi,
8876 (exact ? bgp_show_type_community_list_exact :
8877 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008878}
8879
8880DEFUN (show_ip_bgp_community_list,
8881 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008882 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008883 SHOW_STR
8884 IP_STR
8885 BGP_STR
8886 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008887 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008888 "community-list name\n")
8889{
8890 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8891}
8892
8893DEFUN (show_ip_bgp_ipv4_community_list,
8894 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008895 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 "Address family\n"
8900 "Address Family modifier\n"
8901 "Address Family modifier\n"
8902 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008903 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008904 "community-list name\n")
8905{
8906 if (strncmp (argv[0], "m", 1) == 0)
8907 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8908
8909 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8910}
8911
8912DEFUN (show_ip_bgp_community_list_exact,
8913 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008914 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008915 SHOW_STR
8916 IP_STR
8917 BGP_STR
8918 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008919 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008920 "community-list name\n"
8921 "Exact match of the communities\n")
8922{
8923 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8924}
8925
8926DEFUN (show_ip_bgp_ipv4_community_list_exact,
8927 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008928 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008929 SHOW_STR
8930 IP_STR
8931 BGP_STR
8932 "Address family\n"
8933 "Address Family modifier\n"
8934 "Address Family modifier\n"
8935 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008936 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008937 "community-list name\n"
8938 "Exact match of the communities\n")
8939{
8940 if (strncmp (argv[0], "m", 1) == 0)
8941 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8942
8943 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8944}
8945
8946#ifdef HAVE_IPV6
8947DEFUN (show_bgp_community_list,
8948 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008949 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008950 SHOW_STR
8951 BGP_STR
8952 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008953 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008954 "community-list name\n")
8955{
8956 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8957}
8958
8959ALIAS (show_bgp_community_list,
8960 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008961 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008962 SHOW_STR
8963 BGP_STR
8964 "Address family\n"
8965 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008966 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008967 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008968
8969/* old command */
8970DEFUN (show_ipv6_bgp_community_list,
8971 show_ipv6_bgp_community_list_cmd,
8972 "show ipv6 bgp community-list WORD",
8973 SHOW_STR
8974 IPV6_STR
8975 BGP_STR
8976 "Display routes matching the community-list\n"
8977 "community-list name\n")
8978{
8979 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8980}
8981
8982/* old command */
8983DEFUN (show_ipv6_mbgp_community_list,
8984 show_ipv6_mbgp_community_list_cmd,
8985 "show ipv6 mbgp community-list WORD",
8986 SHOW_STR
8987 IPV6_STR
8988 MBGP_STR
8989 "Display routes matching the community-list\n"
8990 "community-list name\n")
8991{
8992 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8993}
8994
8995DEFUN (show_bgp_community_list_exact,
8996 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008997 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008998 SHOW_STR
8999 BGP_STR
9000 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009001 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009002 "community-list name\n"
9003 "Exact match of the communities\n")
9004{
9005 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9006}
9007
9008ALIAS (show_bgp_community_list_exact,
9009 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009010 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009011 SHOW_STR
9012 BGP_STR
9013 "Address family\n"
9014 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009015 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009016 "community-list name\n"
9017 "Exact match of the communities\n")
9018
9019/* old command */
9020DEFUN (show_ipv6_bgp_community_list_exact,
9021 show_ipv6_bgp_community_list_exact_cmd,
9022 "show ipv6 bgp community-list WORD exact-match",
9023 SHOW_STR
9024 IPV6_STR
9025 BGP_STR
9026 "Display routes matching the community-list\n"
9027 "community-list name\n"
9028 "Exact match of the communities\n")
9029{
9030 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9031}
9032
9033/* old command */
9034DEFUN (show_ipv6_mbgp_community_list_exact,
9035 show_ipv6_mbgp_community_list_exact_cmd,
9036 "show ipv6 mbgp community-list WORD exact-match",
9037 SHOW_STR
9038 IPV6_STR
9039 MBGP_STR
9040 "Display routes matching the community-list\n"
9041 "community-list name\n"
9042 "Exact match of the communities\n")
9043{
9044 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9045}
9046#endif /* HAVE_IPV6 */
9047
paul94f2b392005-06-28 12:44:16 +00009048static int
paulfd79ac92004-10-13 05:06:08 +00009049bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009050 safi_t safi, enum bgp_show_type type)
9051{
9052 int ret;
9053 struct prefix *p;
9054
9055 p = prefix_new();
9056
9057 ret = str2prefix (prefix, p);
9058 if (! ret)
9059 {
9060 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9061 return CMD_WARNING;
9062 }
9063
ajs5a646652004-11-05 01:25:55 +00009064 ret = bgp_show (vty, NULL, afi, safi, type, p);
9065 prefix_free(p);
9066 return ret;
paul718e3742002-12-13 20:15:29 +00009067}
9068
9069DEFUN (show_ip_bgp_prefix_longer,
9070 show_ip_bgp_prefix_longer_cmd,
9071 "show ip bgp A.B.C.D/M longer-prefixes",
9072 SHOW_STR
9073 IP_STR
9074 BGP_STR
9075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9076 "Display route and more specific routes\n")
9077{
9078 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9079 bgp_show_type_prefix_longer);
9080}
9081
9082DEFUN (show_ip_bgp_flap_prefix_longer,
9083 show_ip_bgp_flap_prefix_longer_cmd,
9084 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9085 SHOW_STR
9086 IP_STR
9087 BGP_STR
9088 "Display flap statistics of routes\n"
9089 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9090 "Display route and more specific routes\n")
9091{
9092 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9093 bgp_show_type_flap_prefix_longer);
9094}
9095
9096DEFUN (show_ip_bgp_ipv4_prefix_longer,
9097 show_ip_bgp_ipv4_prefix_longer_cmd,
9098 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9099 SHOW_STR
9100 IP_STR
9101 BGP_STR
9102 "Address family\n"
9103 "Address Family modifier\n"
9104 "Address Family modifier\n"
9105 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9106 "Display route and more specific routes\n")
9107{
9108 if (strncmp (argv[0], "m", 1) == 0)
9109 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9110 bgp_show_type_prefix_longer);
9111
9112 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9113 bgp_show_type_prefix_longer);
9114}
9115
9116DEFUN (show_ip_bgp_flap_address,
9117 show_ip_bgp_flap_address_cmd,
9118 "show ip bgp flap-statistics A.B.C.D",
9119 SHOW_STR
9120 IP_STR
9121 BGP_STR
9122 "Display flap statistics of routes\n"
9123 "Network in the BGP routing table to display\n")
9124{
9125 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9126 bgp_show_type_flap_address);
9127}
9128
9129DEFUN (show_ip_bgp_flap_prefix,
9130 show_ip_bgp_flap_prefix_cmd,
9131 "show ip bgp flap-statistics A.B.C.D/M",
9132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Display flap statistics of routes\n"
9136 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9137{
9138 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9139 bgp_show_type_flap_prefix);
9140}
9141#ifdef HAVE_IPV6
9142DEFUN (show_bgp_prefix_longer,
9143 show_bgp_prefix_longer_cmd,
9144 "show bgp X:X::X:X/M longer-prefixes",
9145 SHOW_STR
9146 BGP_STR
9147 "IPv6 prefix <network>/<length>\n"
9148 "Display route and more specific routes\n")
9149{
9150 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9151 bgp_show_type_prefix_longer);
9152}
9153
9154ALIAS (show_bgp_prefix_longer,
9155 show_bgp_ipv6_prefix_longer_cmd,
9156 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9157 SHOW_STR
9158 BGP_STR
9159 "Address family\n"
9160 "IPv6 prefix <network>/<length>\n"
9161 "Display route and more specific routes\n")
9162
9163/* old command */
9164DEFUN (show_ipv6_bgp_prefix_longer,
9165 show_ipv6_bgp_prefix_longer_cmd,
9166 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9167 SHOW_STR
9168 IPV6_STR
9169 BGP_STR
9170 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9171 "Display route and more specific routes\n")
9172{
9173 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9174 bgp_show_type_prefix_longer);
9175}
9176
9177/* old command */
9178DEFUN (show_ipv6_mbgp_prefix_longer,
9179 show_ipv6_mbgp_prefix_longer_cmd,
9180 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9181 SHOW_STR
9182 IPV6_STR
9183 MBGP_STR
9184 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9185 "Display route and more specific routes\n")
9186{
9187 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9188 bgp_show_type_prefix_longer);
9189}
9190#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009191
paul94f2b392005-06-28 12:44:16 +00009192static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009193peer_lookup_in_view (struct vty *vty, const char *view_name,
9194 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009195{
9196 int ret;
9197 struct bgp *bgp;
9198 struct peer *peer;
9199 union sockunion su;
9200
9201 /* BGP structure lookup. */
9202 if (view_name)
9203 {
9204 bgp = bgp_lookup_by_name (view_name);
9205 if (! bgp)
9206 {
9207 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9208 return NULL;
9209 }
9210 }
paul5228ad22004-06-04 17:58:18 +00009211 else
paulbb46e942003-10-24 19:02:03 +00009212 {
9213 bgp = bgp_get_default ();
9214 if (! bgp)
9215 {
9216 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9217 return NULL;
9218 }
9219 }
9220
9221 /* Get peer sockunion. */
9222 ret = str2sockunion (ip_str, &su);
9223 if (ret < 0)
9224 {
9225 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9226 return NULL;
9227 }
9228
9229 /* Peer structure lookup. */
9230 peer = peer_lookup (bgp, &su);
9231 if (! peer)
9232 {
9233 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9234 return NULL;
9235 }
9236
9237 return peer;
9238}
Paul Jakma2815e612006-09-14 02:56:07 +00009239
9240enum bgp_stats
9241{
9242 BGP_STATS_MAXBITLEN = 0,
9243 BGP_STATS_RIB,
9244 BGP_STATS_PREFIXES,
9245 BGP_STATS_TOTPLEN,
9246 BGP_STATS_UNAGGREGATEABLE,
9247 BGP_STATS_MAX_AGGREGATEABLE,
9248 BGP_STATS_AGGREGATES,
9249 BGP_STATS_SPACE,
9250 BGP_STATS_ASPATH_COUNT,
9251 BGP_STATS_ASPATH_MAXHOPS,
9252 BGP_STATS_ASPATH_TOTHOPS,
9253 BGP_STATS_ASPATH_MAXSIZE,
9254 BGP_STATS_ASPATH_TOTSIZE,
9255 BGP_STATS_ASN_HIGHEST,
9256 BGP_STATS_MAX,
9257};
paulbb46e942003-10-24 19:02:03 +00009258
Paul Jakma2815e612006-09-14 02:56:07 +00009259static const char *table_stats_strs[] =
9260{
9261 [BGP_STATS_PREFIXES] = "Total Prefixes",
9262 [BGP_STATS_TOTPLEN] = "Average prefix length",
9263 [BGP_STATS_RIB] = "Total Advertisements",
9264 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9265 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9266 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9267 [BGP_STATS_SPACE] = "Address space advertised",
9268 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9269 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9270 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9271 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9272 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9273 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9274 [BGP_STATS_MAX] = NULL,
9275};
9276
9277struct bgp_table_stats
9278{
9279 struct bgp_table *table;
9280 unsigned long long counts[BGP_STATS_MAX];
9281};
9282
9283#if 0
9284#define TALLY_SIGFIG 100000
9285static unsigned long
9286ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9287{
9288 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9289 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9290 unsigned long ret = newtot / count;
9291
9292 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9293 return ret + 1;
9294 else
9295 return ret;
9296}
9297#endif
9298
9299static int
9300bgp_table_stats_walker (struct thread *t)
9301{
9302 struct bgp_node *rn;
9303 struct bgp_node *top;
9304 struct bgp_table_stats *ts = THREAD_ARG (t);
9305 unsigned int space = 0;
9306
Paul Jakma53d9f672006-10-15 23:41:16 +00009307 if (!(top = bgp_table_top (ts->table)))
9308 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009309
9310 switch (top->p.family)
9311 {
9312 case AF_INET:
9313 space = IPV4_MAX_BITLEN;
9314 break;
9315 case AF_INET6:
9316 space = IPV6_MAX_BITLEN;
9317 break;
9318 }
9319
9320 ts->counts[BGP_STATS_MAXBITLEN] = space;
9321
9322 for (rn = top; rn; rn = bgp_route_next (rn))
9323 {
9324 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009325 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009326 unsigned int rinum = 0;
9327
9328 if (rn == top)
9329 continue;
9330
9331 if (!rn->info)
9332 continue;
9333
9334 ts->counts[BGP_STATS_PREFIXES]++;
9335 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9336
9337#if 0
9338 ts->counts[BGP_STATS_AVGPLEN]
9339 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9340 ts->counts[BGP_STATS_AVGPLEN],
9341 rn->p.prefixlen);
9342#endif
9343
9344 /* check if the prefix is included by any other announcements */
9345 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009346 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009347
9348 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009349 {
9350 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9351 /* announced address space */
9352 if (space)
9353 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9354 }
Paul Jakma2815e612006-09-14 02:56:07 +00009355 else if (prn->info)
9356 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9357
Paul Jakma2815e612006-09-14 02:56:07 +00009358 for (ri = rn->info; ri; ri = ri->next)
9359 {
9360 rinum++;
9361 ts->counts[BGP_STATS_RIB]++;
9362
9363 if (ri->attr &&
9364 (CHECK_FLAG (ri->attr->flag,
9365 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9366 ts->counts[BGP_STATS_AGGREGATES]++;
9367
9368 /* as-path stats */
9369 if (ri->attr && ri->attr->aspath)
9370 {
9371 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9372 unsigned int size = aspath_size (ri->attr->aspath);
9373 as_t highest = aspath_highest (ri->attr->aspath);
9374
9375 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9376
9377 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9378 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9379
9380 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9381 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9382
9383 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9384 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9385#if 0
9386 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9387 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9388 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9389 hops);
9390 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9391 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9392 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9393 size);
9394#endif
9395 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9396 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9397 }
9398 }
9399 }
9400 return 0;
9401}
9402
9403static int
9404bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9405{
9406 struct bgp_table_stats ts;
9407 unsigned int i;
9408
9409 if (!bgp->rib[afi][safi])
9410 {
9411 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9412 return CMD_WARNING;
9413 }
9414
9415 memset (&ts, 0, sizeof (ts));
9416 ts.table = bgp->rib[afi][safi];
9417 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9418
9419 vty_out (vty, "BGP %s RIB statistics%s%s",
9420 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9421
9422 for (i = 0; i < BGP_STATS_MAX; i++)
9423 {
9424 if (!table_stats_strs[i])
9425 continue;
9426
9427 switch (i)
9428 {
9429#if 0
9430 case BGP_STATS_ASPATH_AVGHOPS:
9431 case BGP_STATS_ASPATH_AVGSIZE:
9432 case BGP_STATS_AVGPLEN:
9433 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9434 vty_out (vty, "%12.2f",
9435 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9436 break;
9437#endif
9438 case BGP_STATS_ASPATH_TOTHOPS:
9439 case BGP_STATS_ASPATH_TOTSIZE:
9440 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9441 vty_out (vty, "%12.2f",
9442 ts.counts[i] ?
9443 (float)ts.counts[i] /
9444 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9445 : 0);
9446 break;
9447 case BGP_STATS_TOTPLEN:
9448 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9449 vty_out (vty, "%12.2f",
9450 ts.counts[i] ?
9451 (float)ts.counts[i] /
9452 (float)ts.counts[BGP_STATS_PREFIXES]
9453 : 0);
9454 break;
9455 case BGP_STATS_SPACE:
9456 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9457 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9458 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9459 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009460 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009461 vty_out (vty, "%12.2f%s",
9462 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009463 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009464 VTY_NEWLINE);
9465 vty_out (vty, "%30s: ", "/8 equivalent ");
9466 vty_out (vty, "%12.2f%s",
9467 (float)ts.counts[BGP_STATS_SPACE] /
9468 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9469 VTY_NEWLINE);
9470 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9471 break;
9472 vty_out (vty, "%30s: ", "/24 equivalent ");
9473 vty_out (vty, "%12.2f",
9474 (float)ts.counts[BGP_STATS_SPACE] /
9475 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9476 break;
9477 default:
9478 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9479 vty_out (vty, "%12llu", ts.counts[i]);
9480 }
9481
9482 vty_out (vty, "%s", VTY_NEWLINE);
9483 }
9484 return CMD_SUCCESS;
9485}
9486
9487static int
9488bgp_table_stats_vty (struct vty *vty, const char *name,
9489 const char *afi_str, const char *safi_str)
9490{
9491 struct bgp *bgp;
9492 afi_t afi;
9493 safi_t safi;
9494
9495 if (name)
9496 bgp = bgp_lookup_by_name (name);
9497 else
9498 bgp = bgp_get_default ();
9499
9500 if (!bgp)
9501 {
9502 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9503 return CMD_WARNING;
9504 }
9505 if (strncmp (afi_str, "ipv", 3) == 0)
9506 {
9507 if (strncmp (afi_str, "ipv4", 4) == 0)
9508 afi = AFI_IP;
9509 else if (strncmp (afi_str, "ipv6", 4) == 0)
9510 afi = AFI_IP6;
9511 else
9512 {
9513 vty_out (vty, "%% Invalid address family %s%s",
9514 afi_str, VTY_NEWLINE);
9515 return CMD_WARNING;
9516 }
9517 if (strncmp (safi_str, "m", 1) == 0)
9518 safi = SAFI_MULTICAST;
9519 else if (strncmp (safi_str, "u", 1) == 0)
9520 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009521 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9522 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009523 else
9524 {
9525 vty_out (vty, "%% Invalid subsequent address family %s%s",
9526 safi_str, VTY_NEWLINE);
9527 return CMD_WARNING;
9528 }
9529 }
9530 else
9531 {
9532 vty_out (vty, "%% Invalid address family %s%s",
9533 afi_str, VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536
Paul Jakma2815e612006-09-14 02:56:07 +00009537 return bgp_table_stats (vty, bgp, afi, safi);
9538}
9539
9540DEFUN (show_bgp_statistics,
9541 show_bgp_statistics_cmd,
9542 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9543 SHOW_STR
9544 BGP_STR
9545 "Address family\n"
9546 "Address family\n"
9547 "Address Family modifier\n"
9548 "Address Family modifier\n"
9549 "BGP RIB advertisement statistics\n")
9550{
9551 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9552}
9553
9554ALIAS (show_bgp_statistics,
9555 show_bgp_statistics_vpnv4_cmd,
9556 "show bgp (ipv4) (vpnv4) statistics",
9557 SHOW_STR
9558 BGP_STR
9559 "Address family\n"
9560 "Address Family modifier\n"
9561 "BGP RIB advertisement statistics\n")
9562
9563DEFUN (show_bgp_statistics_view,
9564 show_bgp_statistics_view_cmd,
9565 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9566 SHOW_STR
9567 BGP_STR
9568 "BGP view\n"
9569 "Address family\n"
9570 "Address family\n"
9571 "Address Family modifier\n"
9572 "Address Family modifier\n"
9573 "BGP RIB advertisement statistics\n")
9574{
9575 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9576}
9577
9578ALIAS (show_bgp_statistics_view,
9579 show_bgp_statistics_view_vpnv4_cmd,
9580 "show bgp view WORD (ipv4) (vpnv4) statistics",
9581 SHOW_STR
9582 BGP_STR
9583 "BGP view\n"
9584 "Address family\n"
9585 "Address Family modifier\n"
9586 "BGP RIB advertisement statistics\n")
9587
Paul Jakmaff7924f2006-09-04 01:10:36 +00009588enum bgp_pcounts
9589{
9590 PCOUNT_ADJ_IN = 0,
9591 PCOUNT_DAMPED,
9592 PCOUNT_REMOVED,
9593 PCOUNT_HISTORY,
9594 PCOUNT_STALE,
9595 PCOUNT_VALID,
9596 PCOUNT_ALL,
9597 PCOUNT_COUNTED,
9598 PCOUNT_PFCNT, /* the figure we display to users */
9599 PCOUNT_MAX,
9600};
9601
9602static const char *pcount_strs[] =
9603{
9604 [PCOUNT_ADJ_IN] = "Adj-in",
9605 [PCOUNT_DAMPED] = "Damped",
9606 [PCOUNT_REMOVED] = "Removed",
9607 [PCOUNT_HISTORY] = "History",
9608 [PCOUNT_STALE] = "Stale",
9609 [PCOUNT_VALID] = "Valid",
9610 [PCOUNT_ALL] = "All RIB",
9611 [PCOUNT_COUNTED] = "PfxCt counted",
9612 [PCOUNT_PFCNT] = "Useable",
9613 [PCOUNT_MAX] = NULL,
9614};
9615
Paul Jakma2815e612006-09-14 02:56:07 +00009616struct peer_pcounts
9617{
9618 unsigned int count[PCOUNT_MAX];
9619 const struct peer *peer;
9620 const struct bgp_table *table;
9621};
9622
Paul Jakmaff7924f2006-09-04 01:10:36 +00009623static int
Paul Jakma2815e612006-09-14 02:56:07 +00009624bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009625{
9626 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009627 struct peer_pcounts *pc = THREAD_ARG (t);
9628 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629
Paul Jakma2815e612006-09-14 02:56:07 +00009630 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631 {
9632 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009633 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634
9635 for (ain = rn->adj_in; ain; ain = ain->next)
9636 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009637 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638
Paul Jakmaff7924f2006-09-04 01:10:36 +00009639 for (ri = rn->info; ri; ri = ri->next)
9640 {
9641 char buf[SU_ADDRSTRLEN];
9642
9643 if (ri->peer != peer)
9644 continue;
9645
Paul Jakma2815e612006-09-14 02:56:07 +00009646 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647
9648 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009649 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009650 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009651 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009652 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009653 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009654 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009655 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009656 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009657 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009658 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009659 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660
9661 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9662 {
Paul Jakma2815e612006-09-14 02:56:07 +00009663 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009664 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009665 plog_warn (peer->log,
9666 "%s [pcount] %s/%d is counted but flags 0x%x",
9667 peer->host,
9668 inet_ntop(rn->p.family, &rn->p.u.prefix,
9669 buf, SU_ADDRSTRLEN),
9670 rn->p.prefixlen,
9671 ri->flags);
9672 }
9673 else
9674 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009675 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009676 plog_warn (peer->log,
9677 "%s [pcount] %s/%d not counted but flags 0x%x",
9678 peer->host,
9679 inet_ntop(rn->p.family, &rn->p.u.prefix,
9680 buf, SU_ADDRSTRLEN),
9681 rn->p.prefixlen,
9682 ri->flags);
9683 }
9684 }
9685 }
Paul Jakma2815e612006-09-14 02:56:07 +00009686 return 0;
9687}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009688
Paul Jakma2815e612006-09-14 02:56:07 +00009689static int
9690bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9691{
9692 struct peer_pcounts pcounts = { .peer = peer };
9693 unsigned int i;
9694
9695 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9696 || !peer->bgp->rib[afi][safi])
9697 {
9698 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9699 return CMD_WARNING;
9700 }
9701
9702 memset (&pcounts, 0, sizeof(pcounts));
9703 pcounts.peer = peer;
9704 pcounts.table = peer->bgp->rib[afi][safi];
9705
9706 /* in-place call via thread subsystem so as to record execution time
9707 * stats for the thread-walk (i.e. ensure this can't be blamed on
9708 * on just vty_read()).
9709 */
9710 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9711
Paul Jakmaff7924f2006-09-04 01:10:36 +00009712 vty_out (vty, "Prefix counts for %s, %s%s",
9713 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9714 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9715 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9716 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9717
9718 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009719 vty_out (vty, "%20s: %-10d%s",
9720 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009721
Paul Jakma2815e612006-09-14 02:56:07 +00009722 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009723 {
9724 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9725 peer->host, VTY_NEWLINE);
9726 vty_out (vty, "Please report this bug, with the above command output%s",
9727 VTY_NEWLINE);
9728 }
9729
9730 return CMD_SUCCESS;
9731}
9732
9733DEFUN (show_ip_bgp_neighbor_prefix_counts,
9734 show_ip_bgp_neighbor_prefix_counts_cmd,
9735 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9736 SHOW_STR
9737 IP_STR
9738 BGP_STR
9739 "Detailed information on TCP and BGP neighbor connections\n"
9740 "Neighbor to display information about\n"
9741 "Neighbor to display information about\n"
9742 "Display detailed prefix count information\n")
9743{
9744 struct peer *peer;
9745
9746 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9747 if (! peer)
9748 return CMD_WARNING;
9749
9750 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9751}
9752
9753DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9754 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9755 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9756 SHOW_STR
9757 BGP_STR
9758 "Address family\n"
9759 "Detailed information on TCP and BGP neighbor connections\n"
9760 "Neighbor to display information about\n"
9761 "Neighbor to display information about\n"
9762 "Display detailed prefix count information\n")
9763{
9764 struct peer *peer;
9765
9766 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9767 if (! peer)
9768 return CMD_WARNING;
9769
9770 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9771}
9772
9773DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9774 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9775 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9776 SHOW_STR
9777 IP_STR
9778 BGP_STR
9779 "Address family\n"
9780 "Address Family modifier\n"
9781 "Address Family modifier\n"
9782 "Detailed information on TCP and BGP neighbor connections\n"
9783 "Neighbor to display information about\n"
9784 "Neighbor to display information about\n"
9785 "Display detailed prefix count information\n")
9786{
9787 struct peer *peer;
9788
9789 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9790 if (! peer)
9791 return CMD_WARNING;
9792
9793 if (strncmp (argv[0], "m", 1) == 0)
9794 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9795
9796 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9797}
9798
9799DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9800 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9801 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9802 SHOW_STR
9803 IP_STR
9804 BGP_STR
9805 "Address family\n"
9806 "Address Family modifier\n"
9807 "Address Family modifier\n"
9808 "Detailed information on TCP and BGP neighbor connections\n"
9809 "Neighbor to display information about\n"
9810 "Neighbor to display information about\n"
9811 "Display detailed prefix count information\n")
9812{
9813 struct peer *peer;
9814
9815 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9816 if (! peer)
9817 return CMD_WARNING;
9818
9819 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9820}
9821
9822
paul94f2b392005-06-28 12:44:16 +00009823static void
paul718e3742002-12-13 20:15:29 +00009824show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9825 int in)
9826{
9827 struct bgp_table *table;
9828 struct bgp_adj_in *ain;
9829 struct bgp_adj_out *adj;
9830 unsigned long output_count;
9831 struct bgp_node *rn;
9832 int header1 = 1;
9833 struct bgp *bgp;
9834 int header2 = 1;
9835
paulbb46e942003-10-24 19:02:03 +00009836 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009837
9838 if (! bgp)
9839 return;
9840
9841 table = bgp->rib[afi][safi];
9842
9843 output_count = 0;
9844
9845 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9846 PEER_STATUS_DEFAULT_ORIGINATE))
9847 {
9848 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 +00009849 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9850 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009851
9852 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9853 VTY_NEWLINE, VTY_NEWLINE);
9854 header1 = 0;
9855 }
9856
9857 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9858 if (in)
9859 {
9860 for (ain = rn->adj_in; ain; ain = ain->next)
9861 if (ain->peer == peer)
9862 {
9863 if (header1)
9864 {
9865 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 +00009866 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9867 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009868 header1 = 0;
9869 }
9870 if (header2)
9871 {
9872 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9873 header2 = 0;
9874 }
9875 if (ain->attr)
9876 {
9877 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9878 output_count++;
9879 }
9880 }
9881 }
9882 else
9883 {
9884 for (adj = rn->adj_out; adj; adj = adj->next)
9885 if (adj->peer == peer)
9886 {
9887 if (header1)
9888 {
9889 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 +00009890 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9891 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009892 header1 = 0;
9893 }
9894 if (header2)
9895 {
9896 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9897 header2 = 0;
9898 }
9899 if (adj->attr)
9900 {
9901 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9902 output_count++;
9903 }
9904 }
9905 }
9906
9907 if (output_count != 0)
9908 vty_out (vty, "%sTotal number of prefixes %ld%s",
9909 VTY_NEWLINE, output_count, VTY_NEWLINE);
9910}
9911
paul94f2b392005-06-28 12:44:16 +00009912static int
paulbb46e942003-10-24 19:02:03 +00009913peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9914{
paul718e3742002-12-13 20:15:29 +00009915 if (! peer || ! peer->afc[afi][safi])
9916 {
9917 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9918 return CMD_WARNING;
9919 }
9920
9921 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9922 {
9923 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9924 VTY_NEWLINE);
9925 return CMD_WARNING;
9926 }
9927
9928 show_adj_route (vty, peer, afi, safi, in);
9929
9930 return CMD_SUCCESS;
9931}
9932
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009933DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9934 show_ip_bgp_view_neighbor_advertised_route_cmd,
9935 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9936 SHOW_STR
9937 IP_STR
9938 BGP_STR
9939 "BGP view\n"
9940 "View name\n"
9941 "Detailed information on TCP and BGP neighbor connections\n"
9942 "Neighbor to display information about\n"
9943 "Neighbor to display information about\n"
9944 "Display the routes advertised to a BGP neighbor\n")
9945{
9946 struct peer *peer;
9947
9948 if (argc == 2)
9949 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9950 else
9951 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9952
9953 if (! peer)
9954 return CMD_WARNING;
9955
9956 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9957}
9958
9959ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009960 show_ip_bgp_neighbor_advertised_route_cmd,
9961 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9962 SHOW_STR
9963 IP_STR
9964 BGP_STR
9965 "Detailed information on TCP and BGP neighbor connections\n"
9966 "Neighbor to display information about\n"
9967 "Neighbor to display information about\n"
9968 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009969
9970DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9971 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9972 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9973 SHOW_STR
9974 IP_STR
9975 BGP_STR
9976 "Address family\n"
9977 "Address Family modifier\n"
9978 "Address Family modifier\n"
9979 "Detailed information on TCP and BGP neighbor connections\n"
9980 "Neighbor to display information about\n"
9981 "Neighbor to display information about\n"
9982 "Display the routes advertised to a BGP neighbor\n")
9983{
paulbb46e942003-10-24 19:02:03 +00009984 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009985
paulbb46e942003-10-24 19:02:03 +00009986 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9987 if (! peer)
9988 return CMD_WARNING;
9989
9990 if (strncmp (argv[0], "m", 1) == 0)
9991 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9992
9993 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009994}
9995
9996#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009997DEFUN (show_bgp_view_neighbor_advertised_route,
9998 show_bgp_view_neighbor_advertised_route_cmd,
9999 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10000 SHOW_STR
10001 BGP_STR
10002 "BGP view\n"
10003 "View name\n"
10004 "Detailed information on TCP and BGP neighbor connections\n"
10005 "Neighbor to display information about\n"
10006 "Neighbor to display information about\n"
10007 "Display the routes advertised to a BGP neighbor\n")
10008{
10009 struct peer *peer;
10010
10011 if (argc == 2)
10012 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10013 else
10014 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10015
10016 if (! peer)
10017 return CMD_WARNING;
10018
10019 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10020}
10021
10022ALIAS (show_bgp_view_neighbor_advertised_route,
10023 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10024 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10025 SHOW_STR
10026 BGP_STR
10027 "BGP view\n"
10028 "View name\n"
10029 "Address family\n"
10030 "Detailed information on TCP and BGP neighbor connections\n"
10031 "Neighbor to display information about\n"
10032 "Neighbor to display information about\n"
10033 "Display the routes advertised to a BGP neighbor\n")
10034
10035DEFUN (show_bgp_view_neighbor_received_routes,
10036 show_bgp_view_neighbor_received_routes_cmd,
10037 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10038 SHOW_STR
10039 BGP_STR
10040 "BGP view\n"
10041 "View name\n"
10042 "Detailed information on TCP and BGP neighbor connections\n"
10043 "Neighbor to display information about\n"
10044 "Neighbor to display information about\n"
10045 "Display the received routes from neighbor\n")
10046{
10047 struct peer *peer;
10048
10049 if (argc == 2)
10050 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10051 else
10052 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10053
10054 if (! peer)
10055 return CMD_WARNING;
10056
10057 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10058}
10059
10060ALIAS (show_bgp_view_neighbor_received_routes,
10061 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10062 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10063 SHOW_STR
10064 BGP_STR
10065 "BGP view\n"
10066 "View name\n"
10067 "Address family\n"
10068 "Detailed information on TCP and BGP neighbor connections\n"
10069 "Neighbor to display information about\n"
10070 "Neighbor to display information about\n"
10071 "Display the received routes from neighbor\n")
10072
10073ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010074 show_bgp_neighbor_advertised_route_cmd,
10075 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10076 SHOW_STR
10077 BGP_STR
10078 "Detailed information on TCP and BGP neighbor connections\n"
10079 "Neighbor to display information about\n"
10080 "Neighbor to display information about\n"
10081 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010082
10083ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010084 show_bgp_ipv6_neighbor_advertised_route_cmd,
10085 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10086 SHOW_STR
10087 BGP_STR
10088 "Address family\n"
10089 "Detailed information on TCP and BGP neighbor connections\n"
10090 "Neighbor to display information about\n"
10091 "Neighbor to display information about\n"
10092 "Display the routes advertised to a BGP neighbor\n")
10093
10094/* old command */
paulbb46e942003-10-24 19:02:03 +000010095ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010096 ipv6_bgp_neighbor_advertised_route_cmd,
10097 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10098 SHOW_STR
10099 IPV6_STR
10100 BGP_STR
10101 "Detailed information on TCP and BGP neighbor connections\n"
10102 "Neighbor to display information about\n"
10103 "Neighbor to display information about\n"
10104 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010105
paul718e3742002-12-13 20:15:29 +000010106/* old command */
10107DEFUN (ipv6_mbgp_neighbor_advertised_route,
10108 ipv6_mbgp_neighbor_advertised_route_cmd,
10109 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10110 SHOW_STR
10111 IPV6_STR
10112 MBGP_STR
10113 "Detailed information on TCP and BGP neighbor connections\n"
10114 "Neighbor to display information about\n"
10115 "Neighbor to display information about\n"
10116 "Display the routes advertised to a BGP neighbor\n")
10117{
paulbb46e942003-10-24 19:02:03 +000010118 struct peer *peer;
10119
10120 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10121 if (! peer)
10122 return CMD_WARNING;
10123
10124 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010125}
10126#endif /* HAVE_IPV6 */
10127
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010128DEFUN (show_ip_bgp_view_neighbor_received_routes,
10129 show_ip_bgp_view_neighbor_received_routes_cmd,
10130 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10131 SHOW_STR
10132 IP_STR
10133 BGP_STR
10134 "BGP view\n"
10135 "View name\n"
10136 "Detailed information on TCP and BGP neighbor connections\n"
10137 "Neighbor to display information about\n"
10138 "Neighbor to display information about\n"
10139 "Display the received routes from neighbor\n")
10140{
10141 struct peer *peer;
10142
10143 if (argc == 2)
10144 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10145 else
10146 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10147
10148 if (! peer)
10149 return CMD_WARNING;
10150
10151 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10152}
10153
10154ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010155 show_ip_bgp_neighbor_received_routes_cmd,
10156 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10157 SHOW_STR
10158 IP_STR
10159 BGP_STR
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010164
10165DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10166 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10167 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10168 SHOW_STR
10169 IP_STR
10170 BGP_STR
10171 "Address family\n"
10172 "Address Family modifier\n"
10173 "Address Family modifier\n"
10174 "Detailed information on TCP and BGP neighbor connections\n"
10175 "Neighbor to display information about\n"
10176 "Neighbor to display information about\n"
10177 "Display the received routes from neighbor\n")
10178{
paulbb46e942003-10-24 19:02:03 +000010179 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010180
paulbb46e942003-10-24 19:02:03 +000010181 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10182 if (! peer)
10183 return CMD_WARNING;
10184
10185 if (strncmp (argv[0], "m", 1) == 0)
10186 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10187
10188 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010189}
10190
Michael Lambert95cbbd22010-07-23 14:43:04 -040010191DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10192 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10193#ifdef HAVE_IPV6
10194 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10195#else
10196 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10197#endif
10198 SHOW_STR
10199 BGP_STR
10200 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010201 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010202 "Address family\n"
10203#ifdef HAVE_IPV6
10204 "Address family\n"
10205#endif
10206 "Address family modifier\n"
10207 "Address family modifier\n"
10208 "Detailed information on TCP and BGP neighbor connections\n"
10209 "Neighbor to display information about\n"
10210 "Neighbor to display information about\n"
10211 "Display the advertised routes to neighbor\n"
10212 "Display the received routes from neighbor\n")
10213{
10214 int afi;
10215 int safi;
10216 int in;
10217 struct peer *peer;
10218
10219#ifdef HAVE_IPV6
10220 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10221#else
10222 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10223#endif
10224
10225 if (! peer)
10226 return CMD_WARNING;
10227
10228#ifdef HAVE_IPV6
10229 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10230 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10231 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10232#else
10233 afi = AFI_IP;
10234 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10235 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10236#endif
10237
10238 return peer_adj_routes (vty, peer, afi, safi, in);
10239}
10240
paul718e3742002-12-13 20:15:29 +000010241DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10242 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10243 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10244 SHOW_STR
10245 IP_STR
10246 BGP_STR
10247 "Detailed information on TCP and BGP neighbor connections\n"
10248 "Neighbor to display information about\n"
10249 "Neighbor to display information about\n"
10250 "Display information received from a BGP neighbor\n"
10251 "Display the prefixlist filter\n")
10252{
10253 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010254 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010255 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010256 int count, ret;
paul718e3742002-12-13 20:15:29 +000010257
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010258 ret = str2sockunion (argv[0], &su);
10259 if (ret < 0)
10260 {
10261 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10262 return CMD_WARNING;
10263 }
paul718e3742002-12-13 20:15:29 +000010264
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010265 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010266 if (! peer)
10267 return CMD_WARNING;
10268
10269 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10270 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10271 if (count)
10272 {
10273 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10274 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10275 }
10276
10277 return CMD_SUCCESS;
10278}
10279
10280DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10281 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10282 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10283 SHOW_STR
10284 IP_STR
10285 BGP_STR
10286 "Address family\n"
10287 "Address Family modifier\n"
10288 "Address Family modifier\n"
10289 "Detailed information on TCP and BGP neighbor connections\n"
10290 "Neighbor to display information about\n"
10291 "Neighbor to display information about\n"
10292 "Display information received from a BGP neighbor\n"
10293 "Display the prefixlist filter\n")
10294{
10295 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010296 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010297 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010298 int count, ret;
paul718e3742002-12-13 20:15:29 +000010299
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010300 ret = str2sockunion (argv[1], &su);
10301 if (ret < 0)
10302 {
10303 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10304 return CMD_WARNING;
10305 }
paul718e3742002-12-13 20:15:29 +000010306
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010307 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010308 if (! peer)
10309 return CMD_WARNING;
10310
10311 if (strncmp (argv[0], "m", 1) == 0)
10312 {
10313 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10314 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10315 if (count)
10316 {
10317 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10318 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10319 }
10320 }
10321 else
10322 {
10323 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10324 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10325 if (count)
10326 {
10327 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10328 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10329 }
10330 }
10331
10332 return CMD_SUCCESS;
10333}
10334
10335
10336#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010337ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010338 show_bgp_neighbor_received_routes_cmd,
10339 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10340 SHOW_STR
10341 BGP_STR
10342 "Detailed information on TCP and BGP neighbor connections\n"
10343 "Neighbor to display information about\n"
10344 "Neighbor to display information about\n"
10345 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010346
paulbb46e942003-10-24 19:02:03 +000010347ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010348 show_bgp_ipv6_neighbor_received_routes_cmd,
10349 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10350 SHOW_STR
10351 BGP_STR
10352 "Address family\n"
10353 "Detailed information on TCP and BGP neighbor connections\n"
10354 "Neighbor to display information about\n"
10355 "Neighbor to display information about\n"
10356 "Display the received routes from neighbor\n")
10357
10358DEFUN (show_bgp_neighbor_received_prefix_filter,
10359 show_bgp_neighbor_received_prefix_filter_cmd,
10360 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10361 SHOW_STR
10362 BGP_STR
10363 "Detailed information on TCP and BGP neighbor connections\n"
10364 "Neighbor to display information about\n"
10365 "Neighbor to display information about\n"
10366 "Display information received from a BGP neighbor\n"
10367 "Display the prefixlist filter\n")
10368{
10369 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010370 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010371 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010372 int count, ret;
paul718e3742002-12-13 20:15:29 +000010373
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010374 ret = str2sockunion (argv[0], &su);
10375 if (ret < 0)
10376 {
10377 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10378 return CMD_WARNING;
10379 }
paul718e3742002-12-13 20:15:29 +000010380
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010381 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010382 if (! peer)
10383 return CMD_WARNING;
10384
10385 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10386 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10387 if (count)
10388 {
10389 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10390 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10391 }
10392
10393 return CMD_SUCCESS;
10394}
10395
10396ALIAS (show_bgp_neighbor_received_prefix_filter,
10397 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10398 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10399 SHOW_STR
10400 BGP_STR
10401 "Address family\n"
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 information received from a BGP neighbor\n"
10406 "Display the prefixlist filter\n")
10407
10408/* old command */
paulbb46e942003-10-24 19:02:03 +000010409ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010410 ipv6_bgp_neighbor_received_routes_cmd,
10411 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10412 SHOW_STR
10413 IPV6_STR
10414 BGP_STR
10415 "Detailed information on TCP and BGP neighbor connections\n"
10416 "Neighbor to display information about\n"
10417 "Neighbor to display information about\n"
10418 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010419
10420/* old command */
10421DEFUN (ipv6_mbgp_neighbor_received_routes,
10422 ipv6_mbgp_neighbor_received_routes_cmd,
10423 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10424 SHOW_STR
10425 IPV6_STR
10426 MBGP_STR
10427 "Detailed information on TCP and BGP neighbor connections\n"
10428 "Neighbor to display information about\n"
10429 "Neighbor to display information about\n"
10430 "Display the received routes from neighbor\n")
10431{
paulbb46e942003-10-24 19:02:03 +000010432 struct peer *peer;
10433
10434 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10435 if (! peer)
10436 return CMD_WARNING;
10437
10438 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010439}
paulbb46e942003-10-24 19:02:03 +000010440
10441DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10442 show_bgp_view_neighbor_received_prefix_filter_cmd,
10443 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10444 SHOW_STR
10445 BGP_STR
10446 "BGP view\n"
10447 "View name\n"
10448 "Detailed information on TCP and BGP neighbor connections\n"
10449 "Neighbor to display information about\n"
10450 "Neighbor to display information about\n"
10451 "Display information received from a BGP neighbor\n"
10452 "Display the prefixlist filter\n")
10453{
10454 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010455 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010456 struct peer *peer;
10457 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010458 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010459
10460 /* BGP structure lookup. */
10461 bgp = bgp_lookup_by_name (argv[0]);
10462 if (bgp == NULL)
10463 {
10464 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10465 return CMD_WARNING;
10466 }
10467
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010468 ret = str2sockunion (argv[1], &su);
10469 if (ret < 0)
10470 {
10471 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10472 return CMD_WARNING;
10473 }
paulbb46e942003-10-24 19:02:03 +000010474
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010475 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010476 if (! peer)
10477 return CMD_WARNING;
10478
10479 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10480 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10481 if (count)
10482 {
10483 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10484 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10485 }
10486
10487 return CMD_SUCCESS;
10488}
10489
10490ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10491 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10492 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10493 SHOW_STR
10494 BGP_STR
10495 "BGP view\n"
10496 "View name\n"
10497 "Address family\n"
10498 "Detailed information on TCP and BGP neighbor connections\n"
10499 "Neighbor to display information about\n"
10500 "Neighbor to display information about\n"
10501 "Display information received from a BGP neighbor\n"
10502 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010503#endif /* HAVE_IPV6 */
10504
paul94f2b392005-06-28 12:44:16 +000010505static int
paulbb46e942003-10-24 19:02:03 +000010506bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010507 safi_t safi, enum bgp_show_type type)
10508{
paul718e3742002-12-13 20:15:29 +000010509 if (! peer || ! peer->afc[afi][safi])
10510 {
10511 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010512 return CMD_WARNING;
10513 }
10514
ajs5a646652004-11-05 01:25:55 +000010515 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010516}
10517
10518DEFUN (show_ip_bgp_neighbor_routes,
10519 show_ip_bgp_neighbor_routes_cmd,
10520 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10521 SHOW_STR
10522 IP_STR
10523 BGP_STR
10524 "Detailed information on TCP and BGP neighbor connections\n"
10525 "Neighbor to display information about\n"
10526 "Neighbor to display information about\n"
10527 "Display routes learned from neighbor\n")
10528{
paulbb46e942003-10-24 19:02:03 +000010529 struct peer *peer;
10530
10531 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10532 if (! peer)
10533 return CMD_WARNING;
10534
10535 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010536 bgp_show_type_neighbor);
10537}
10538
10539DEFUN (show_ip_bgp_neighbor_flap,
10540 show_ip_bgp_neighbor_flap_cmd,
10541 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10542 SHOW_STR
10543 IP_STR
10544 BGP_STR
10545 "Detailed information on TCP and BGP neighbor connections\n"
10546 "Neighbor to display information about\n"
10547 "Neighbor to display information about\n"
10548 "Display flap statistics of the routes learned from neighbor\n")
10549{
paulbb46e942003-10-24 19:02:03 +000010550 struct peer *peer;
10551
10552 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10553 if (! peer)
10554 return CMD_WARNING;
10555
10556 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010557 bgp_show_type_flap_neighbor);
10558}
10559
10560DEFUN (show_ip_bgp_neighbor_damp,
10561 show_ip_bgp_neighbor_damp_cmd,
10562 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10563 SHOW_STR
10564 IP_STR
10565 BGP_STR
10566 "Detailed information on TCP and BGP neighbor connections\n"
10567 "Neighbor to display information about\n"
10568 "Neighbor to display information about\n"
10569 "Display the dampened routes received from neighbor\n")
10570{
paulbb46e942003-10-24 19:02:03 +000010571 struct peer *peer;
10572
10573 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10574 if (! peer)
10575 return CMD_WARNING;
10576
10577 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010578 bgp_show_type_damp_neighbor);
10579}
10580
10581DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10582 show_ip_bgp_ipv4_neighbor_routes_cmd,
10583 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10584 SHOW_STR
10585 IP_STR
10586 BGP_STR
10587 "Address family\n"
10588 "Address Family modifier\n"
10589 "Address Family modifier\n"
10590 "Detailed information on TCP and BGP neighbor connections\n"
10591 "Neighbor to display information about\n"
10592 "Neighbor to display information about\n"
10593 "Display routes learned from neighbor\n")
10594{
paulbb46e942003-10-24 19:02:03 +000010595 struct peer *peer;
10596
10597 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10598 if (! peer)
10599 return CMD_WARNING;
10600
paul718e3742002-12-13 20:15:29 +000010601 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010602 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010603 bgp_show_type_neighbor);
10604
paulbb46e942003-10-24 19:02:03 +000010605 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010606 bgp_show_type_neighbor);
10607}
paulbb46e942003-10-24 19:02:03 +000010608
paulfee0f4c2004-09-13 05:12:46 +000010609DEFUN (show_ip_bgp_view_rsclient,
10610 show_ip_bgp_view_rsclient_cmd,
10611 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10612 SHOW_STR
10613 IP_STR
10614 BGP_STR
10615 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010616 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010617 "Information about Route Server Client\n"
10618 NEIGHBOR_ADDR_STR)
10619{
10620 struct bgp_table *table;
10621 struct peer *peer;
10622
10623 if (argc == 2)
10624 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10625 else
10626 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10627
10628 if (! peer)
10629 return CMD_WARNING;
10630
10631 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10632 {
10633 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10634 VTY_NEWLINE);
10635 return CMD_WARNING;
10636 }
10637
10638 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10639 PEER_FLAG_RSERVER_CLIENT))
10640 {
10641 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10642 VTY_NEWLINE);
10643 return CMD_WARNING;
10644 }
10645
10646 table = peer->rib[AFI_IP][SAFI_UNICAST];
10647
ajs5a646652004-11-05 01:25:55 +000010648 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010649}
10650
10651ALIAS (show_ip_bgp_view_rsclient,
10652 show_ip_bgp_rsclient_cmd,
10653 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10654 SHOW_STR
10655 IP_STR
10656 BGP_STR
10657 "Information about Route Server Client\n"
10658 NEIGHBOR_ADDR_STR)
10659
Michael Lambert95cbbd22010-07-23 14:43:04 -040010660DEFUN (show_bgp_view_ipv4_safi_rsclient,
10661 show_bgp_view_ipv4_safi_rsclient_cmd,
10662 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10663 SHOW_STR
10664 BGP_STR
10665 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010666 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010667 "Address family\n"
10668 "Address Family modifier\n"
10669 "Address Family modifier\n"
10670 "Information about Route Server Client\n"
10671 NEIGHBOR_ADDR_STR)
10672{
10673 struct bgp_table *table;
10674 struct peer *peer;
10675 safi_t safi;
10676
10677 if (argc == 3) {
10678 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10679 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10680 } else {
10681 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10682 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10683 }
10684
10685 if (! peer)
10686 return CMD_WARNING;
10687
10688 if (! peer->afc[AFI_IP][safi])
10689 {
10690 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10691 VTY_NEWLINE);
10692 return CMD_WARNING;
10693 }
10694
10695 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10696 PEER_FLAG_RSERVER_CLIENT))
10697 {
10698 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10699 VTY_NEWLINE);
10700 return CMD_WARNING;
10701 }
10702
10703 table = peer->rib[AFI_IP][safi];
10704
10705 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10706}
10707
10708ALIAS (show_bgp_view_ipv4_safi_rsclient,
10709 show_bgp_ipv4_safi_rsclient_cmd,
10710 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10711 SHOW_STR
10712 BGP_STR
10713 "Address family\n"
10714 "Address Family modifier\n"
10715 "Address Family modifier\n"
10716 "Information about Route Server Client\n"
10717 NEIGHBOR_ADDR_STR)
10718
paulfee0f4c2004-09-13 05:12:46 +000010719DEFUN (show_ip_bgp_view_rsclient_route,
10720 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010721 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010722 SHOW_STR
10723 IP_STR
10724 BGP_STR
10725 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010726 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010727 "Information about Route Server Client\n"
10728 NEIGHBOR_ADDR_STR
10729 "Network in the BGP routing table to display\n")
10730{
10731 struct bgp *bgp;
10732 struct peer *peer;
10733
10734 /* BGP structure lookup. */
10735 if (argc == 3)
10736 {
10737 bgp = bgp_lookup_by_name (argv[0]);
10738 if (bgp == NULL)
10739 {
10740 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10741 return CMD_WARNING;
10742 }
10743 }
10744 else
10745 {
10746 bgp = bgp_get_default ();
10747 if (bgp == NULL)
10748 {
10749 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10750 return CMD_WARNING;
10751 }
10752 }
10753
10754 if (argc == 3)
10755 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10756 else
10757 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10758
10759 if (! peer)
10760 return CMD_WARNING;
10761
10762 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10763 {
10764 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10765 VTY_NEWLINE);
10766 return CMD_WARNING;
10767}
10768
10769 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10770 PEER_FLAG_RSERVER_CLIENT))
10771 {
10772 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10773 VTY_NEWLINE);
10774 return CMD_WARNING;
10775 }
10776
10777 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10778 (argc == 3) ? argv[2] : argv[1],
10779 AFI_IP, SAFI_UNICAST, NULL, 0);
10780}
10781
10782ALIAS (show_ip_bgp_view_rsclient_route,
10783 show_ip_bgp_rsclient_route_cmd,
10784 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10785 SHOW_STR
10786 IP_STR
10787 BGP_STR
10788 "Information about Route Server Client\n"
10789 NEIGHBOR_ADDR_STR
10790 "Network in the BGP routing table to display\n")
10791
Michael Lambert95cbbd22010-07-23 14:43:04 -040010792DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10793 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10794 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10795 SHOW_STR
10796 BGP_STR
10797 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010798 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010799 "Address family\n"
10800 "Address Family modifier\n"
10801 "Address Family modifier\n"
10802 "Information about Route Server Client\n"
10803 NEIGHBOR_ADDR_STR
10804 "Network in the BGP routing table to display\n")
10805{
10806 struct bgp *bgp;
10807 struct peer *peer;
10808 safi_t safi;
10809
10810 /* BGP structure lookup. */
10811 if (argc == 4)
10812 {
10813 bgp = bgp_lookup_by_name (argv[0]);
10814 if (bgp == NULL)
10815 {
10816 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10817 return CMD_WARNING;
10818 }
10819 }
10820 else
10821 {
10822 bgp = bgp_get_default ();
10823 if (bgp == NULL)
10824 {
10825 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10826 return CMD_WARNING;
10827 }
10828 }
10829
10830 if (argc == 4) {
10831 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10832 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10833 } else {
10834 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10835 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10836 }
10837
10838 if (! peer)
10839 return CMD_WARNING;
10840
10841 if (! peer->afc[AFI_IP][safi])
10842 {
10843 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10844 VTY_NEWLINE);
10845 return CMD_WARNING;
10846}
10847
10848 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10849 PEER_FLAG_RSERVER_CLIENT))
10850 {
10851 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10852 VTY_NEWLINE);
10853 return CMD_WARNING;
10854 }
10855
10856 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10857 (argc == 4) ? argv[3] : argv[2],
10858 AFI_IP, safi, NULL, 0);
10859}
10860
10861ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10862 show_bgp_ipv4_safi_rsclient_route_cmd,
10863 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10864 SHOW_STR
10865 BGP_STR
10866 "Address family\n"
10867 "Address Family modifier\n"
10868 "Address Family modifier\n"
10869 "Information about Route Server Client\n"
10870 NEIGHBOR_ADDR_STR
10871 "Network in the BGP routing table to display\n")
10872
paulfee0f4c2004-09-13 05:12:46 +000010873DEFUN (show_ip_bgp_view_rsclient_prefix,
10874 show_ip_bgp_view_rsclient_prefix_cmd,
10875 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10876 SHOW_STR
10877 IP_STR
10878 BGP_STR
10879 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010880 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010881 "Information about Route Server Client\n"
10882 NEIGHBOR_ADDR_STR
10883 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10884{
10885 struct bgp *bgp;
10886 struct peer *peer;
10887
10888 /* BGP structure lookup. */
10889 if (argc == 3)
10890 {
10891 bgp = bgp_lookup_by_name (argv[0]);
10892 if (bgp == NULL)
10893 {
10894 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10895 return CMD_WARNING;
10896 }
10897 }
10898 else
10899 {
10900 bgp = bgp_get_default ();
10901 if (bgp == NULL)
10902 {
10903 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10904 return CMD_WARNING;
10905 }
10906 }
10907
10908 if (argc == 3)
10909 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10910 else
10911 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10912
10913 if (! peer)
10914 return CMD_WARNING;
10915
10916 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10917 {
10918 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10919 VTY_NEWLINE);
10920 return CMD_WARNING;
10921}
10922
10923 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10924 PEER_FLAG_RSERVER_CLIENT))
10925{
10926 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10927 VTY_NEWLINE);
10928 return CMD_WARNING;
10929 }
10930
10931 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10932 (argc == 3) ? argv[2] : argv[1],
10933 AFI_IP, SAFI_UNICAST, NULL, 1);
10934}
10935
10936ALIAS (show_ip_bgp_view_rsclient_prefix,
10937 show_ip_bgp_rsclient_prefix_cmd,
10938 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10939 SHOW_STR
10940 IP_STR
10941 BGP_STR
10942 "Information about Route Server Client\n"
10943 NEIGHBOR_ADDR_STR
10944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10945
Michael Lambert95cbbd22010-07-23 14:43:04 -040010946DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10947 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10948 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10949 SHOW_STR
10950 BGP_STR
10951 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010952 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010953 "Address family\n"
10954 "Address Family modifier\n"
10955 "Address Family modifier\n"
10956 "Information about Route Server Client\n"
10957 NEIGHBOR_ADDR_STR
10958 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10959{
10960 struct bgp *bgp;
10961 struct peer *peer;
10962 safi_t safi;
10963
10964 /* BGP structure lookup. */
10965 if (argc == 4)
10966 {
10967 bgp = bgp_lookup_by_name (argv[0]);
10968 if (bgp == NULL)
10969 {
10970 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10971 return CMD_WARNING;
10972 }
10973 }
10974 else
10975 {
10976 bgp = bgp_get_default ();
10977 if (bgp == NULL)
10978 {
10979 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10980 return CMD_WARNING;
10981 }
10982 }
10983
10984 if (argc == 4) {
10985 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10986 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10987 } else {
10988 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10989 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10990 }
10991
10992 if (! peer)
10993 return CMD_WARNING;
10994
10995 if (! peer->afc[AFI_IP][safi])
10996 {
10997 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10998 VTY_NEWLINE);
10999 return CMD_WARNING;
11000}
11001
11002 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11003 PEER_FLAG_RSERVER_CLIENT))
11004{
11005 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11006 VTY_NEWLINE);
11007 return CMD_WARNING;
11008 }
11009
11010 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11011 (argc == 4) ? argv[3] : argv[2],
11012 AFI_IP, safi, NULL, 1);
11013}
11014
11015ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11016 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11017 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11018 SHOW_STR
11019 BGP_STR
11020 "Address family\n"
11021 "Address Family modifier\n"
11022 "Address Family modifier\n"
11023 "Information about Route Server Client\n"
11024 NEIGHBOR_ADDR_STR
11025 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011026
paul718e3742002-12-13 20:15:29 +000011027#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011028DEFUN (show_bgp_view_neighbor_routes,
11029 show_bgp_view_neighbor_routes_cmd,
11030 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11031 SHOW_STR
11032 BGP_STR
11033 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011034 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011035 "Detailed information on TCP and BGP neighbor connections\n"
11036 "Neighbor to display information about\n"
11037 "Neighbor to display information about\n"
11038 "Display routes learned from neighbor\n")
11039{
11040 struct peer *peer;
11041
11042 if (argc == 2)
11043 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11044 else
11045 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11046
11047 if (! peer)
11048 return CMD_WARNING;
11049
11050 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11051 bgp_show_type_neighbor);
11052}
11053
11054ALIAS (show_bgp_view_neighbor_routes,
11055 show_bgp_view_ipv6_neighbor_routes_cmd,
11056 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11057 SHOW_STR
11058 BGP_STR
11059 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011060 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011061 "Address family\n"
11062 "Detailed information on TCP and BGP neighbor connections\n"
11063 "Neighbor to display information about\n"
11064 "Neighbor to display information about\n"
11065 "Display routes learned from neighbor\n")
11066
11067DEFUN (show_bgp_view_neighbor_damp,
11068 show_bgp_view_neighbor_damp_cmd,
11069 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11070 SHOW_STR
11071 BGP_STR
11072 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011073 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011074 "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 the dampened routes received from neighbor\n")
11078{
11079 struct peer *peer;
11080
11081 if (argc == 2)
11082 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11083 else
11084 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11085
11086 if (! peer)
11087 return CMD_WARNING;
11088
11089 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11090 bgp_show_type_damp_neighbor);
11091}
11092
11093ALIAS (show_bgp_view_neighbor_damp,
11094 show_bgp_view_ipv6_neighbor_damp_cmd,
11095 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11096 SHOW_STR
11097 BGP_STR
11098 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011099 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011100 "Address family\n"
11101 "Detailed information on TCP and BGP neighbor connections\n"
11102 "Neighbor to display information about\n"
11103 "Neighbor to display information about\n"
11104 "Display the dampened routes received from neighbor\n")
11105
11106DEFUN (show_bgp_view_neighbor_flap,
11107 show_bgp_view_neighbor_flap_cmd,
11108 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11109 SHOW_STR
11110 BGP_STR
11111 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011112 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011113 "Detailed information on TCP and BGP neighbor connections\n"
11114 "Neighbor to display information about\n"
11115 "Neighbor to display information about\n"
11116 "Display flap statistics of the routes learned from neighbor\n")
11117{
11118 struct peer *peer;
11119
11120 if (argc == 2)
11121 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11122 else
11123 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11124
11125 if (! peer)
11126 return CMD_WARNING;
11127
11128 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11129 bgp_show_type_flap_neighbor);
11130}
11131
11132ALIAS (show_bgp_view_neighbor_flap,
11133 show_bgp_view_ipv6_neighbor_flap_cmd,
11134 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11135 SHOW_STR
11136 BGP_STR
11137 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011138 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011139 "Address family\n"
11140 "Detailed information on TCP and BGP neighbor connections\n"
11141 "Neighbor to display information about\n"
11142 "Neighbor to display information about\n"
11143 "Display flap statistics of the routes learned from neighbor\n")
11144
11145ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011146 show_bgp_neighbor_routes_cmd,
11147 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11148 SHOW_STR
11149 BGP_STR
11150 "Detailed information on TCP and BGP neighbor connections\n"
11151 "Neighbor to display information about\n"
11152 "Neighbor to display information about\n"
11153 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011154
paulbb46e942003-10-24 19:02:03 +000011155
11156ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011157 show_bgp_ipv6_neighbor_routes_cmd,
11158 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11159 SHOW_STR
11160 BGP_STR
11161 "Address family\n"
11162 "Detailed information on TCP and BGP neighbor connections\n"
11163 "Neighbor to display information about\n"
11164 "Neighbor to display information about\n"
11165 "Display routes learned from neighbor\n")
11166
11167/* old command */
paulbb46e942003-10-24 19:02:03 +000011168ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011169 ipv6_bgp_neighbor_routes_cmd,
11170 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11171 SHOW_STR
11172 IPV6_STR
11173 BGP_STR
11174 "Detailed information on TCP and BGP neighbor connections\n"
11175 "Neighbor to display information about\n"
11176 "Neighbor to display information about\n"
11177 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011178
11179/* old command */
11180DEFUN (ipv6_mbgp_neighbor_routes,
11181 ipv6_mbgp_neighbor_routes_cmd,
11182 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11183 SHOW_STR
11184 IPV6_STR
11185 MBGP_STR
11186 "Detailed information on TCP and BGP neighbor connections\n"
11187 "Neighbor to display information about\n"
11188 "Neighbor to display information about\n"
11189 "Display routes learned from neighbor\n")
11190{
paulbb46e942003-10-24 19:02:03 +000011191 struct peer *peer;
11192
11193 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11194 if (! peer)
11195 return CMD_WARNING;
11196
11197 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011198 bgp_show_type_neighbor);
11199}
paulbb46e942003-10-24 19:02:03 +000011200
11201ALIAS (show_bgp_view_neighbor_flap,
11202 show_bgp_neighbor_flap_cmd,
11203 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11204 SHOW_STR
11205 BGP_STR
11206 "Detailed information on TCP and BGP neighbor connections\n"
11207 "Neighbor to display information about\n"
11208 "Neighbor to display information about\n"
11209 "Display flap statistics of the routes learned from neighbor\n")
11210
11211ALIAS (show_bgp_view_neighbor_flap,
11212 show_bgp_ipv6_neighbor_flap_cmd,
11213 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11214 SHOW_STR
11215 BGP_STR
11216 "Address family\n"
11217 "Detailed information on TCP and BGP neighbor connections\n"
11218 "Neighbor to display information about\n"
11219 "Neighbor to display information about\n"
11220 "Display flap statistics of the routes learned from neighbor\n")
11221
11222ALIAS (show_bgp_view_neighbor_damp,
11223 show_bgp_neighbor_damp_cmd,
11224 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11225 SHOW_STR
11226 BGP_STR
11227 "Detailed information on TCP and BGP neighbor connections\n"
11228 "Neighbor to display information about\n"
11229 "Neighbor to display information about\n"
11230 "Display the dampened routes received from neighbor\n")
11231
11232ALIAS (show_bgp_view_neighbor_damp,
11233 show_bgp_ipv6_neighbor_damp_cmd,
11234 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11235 SHOW_STR
11236 BGP_STR
11237 "Address family\n"
11238 "Detailed information on TCP and BGP neighbor connections\n"
11239 "Neighbor to display information about\n"
11240 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011241 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011242
11243DEFUN (show_bgp_view_rsclient,
11244 show_bgp_view_rsclient_cmd,
11245 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11246 SHOW_STR
11247 BGP_STR
11248 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011249 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011250 "Information about Route Server Client\n"
11251 NEIGHBOR_ADDR_STR)
11252{
11253 struct bgp_table *table;
11254 struct peer *peer;
11255
11256 if (argc == 2)
11257 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11258 else
11259 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11260
11261 if (! peer)
11262 return CMD_WARNING;
11263
11264 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11265 {
11266 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11267 VTY_NEWLINE);
11268 return CMD_WARNING;
11269 }
11270
11271 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11272 PEER_FLAG_RSERVER_CLIENT))
11273 {
11274 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11275 VTY_NEWLINE);
11276 return CMD_WARNING;
11277 }
11278
11279 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11280
ajs5a646652004-11-05 01:25:55 +000011281 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011282}
11283
11284ALIAS (show_bgp_view_rsclient,
11285 show_bgp_rsclient_cmd,
11286 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11287 SHOW_STR
11288 BGP_STR
11289 "Information about Route Server Client\n"
11290 NEIGHBOR_ADDR_STR)
11291
Michael Lambert95cbbd22010-07-23 14:43:04 -040011292DEFUN (show_bgp_view_ipv6_safi_rsclient,
11293 show_bgp_view_ipv6_safi_rsclient_cmd,
11294 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11295 SHOW_STR
11296 BGP_STR
11297 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011298 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011299 "Address family\n"
11300 "Address Family modifier\n"
11301 "Address Family modifier\n"
11302 "Information about Route Server Client\n"
11303 NEIGHBOR_ADDR_STR)
11304{
11305 struct bgp_table *table;
11306 struct peer *peer;
11307 safi_t safi;
11308
11309 if (argc == 3) {
11310 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11311 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11312 } else {
11313 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11314 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11315 }
11316
11317 if (! peer)
11318 return CMD_WARNING;
11319
11320 if (! peer->afc[AFI_IP6][safi])
11321 {
11322 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11323 VTY_NEWLINE);
11324 return CMD_WARNING;
11325 }
11326
11327 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11328 PEER_FLAG_RSERVER_CLIENT))
11329 {
11330 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11331 VTY_NEWLINE);
11332 return CMD_WARNING;
11333 }
11334
11335 table = peer->rib[AFI_IP6][safi];
11336
11337 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11338}
11339
11340ALIAS (show_bgp_view_ipv6_safi_rsclient,
11341 show_bgp_ipv6_safi_rsclient_cmd,
11342 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11343 SHOW_STR
11344 BGP_STR
11345 "Address family\n"
11346 "Address Family modifier\n"
11347 "Address Family modifier\n"
11348 "Information about Route Server Client\n"
11349 NEIGHBOR_ADDR_STR)
11350
paulfee0f4c2004-09-13 05:12:46 +000011351DEFUN (show_bgp_view_rsclient_route,
11352 show_bgp_view_rsclient_route_cmd,
11353 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11354 SHOW_STR
11355 BGP_STR
11356 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011357 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011358 "Information about Route Server Client\n"
11359 NEIGHBOR_ADDR_STR
11360 "Network in the BGP routing table to display\n")
11361{
11362 struct bgp *bgp;
11363 struct peer *peer;
11364
11365 /* BGP structure lookup. */
11366 if (argc == 3)
11367 {
11368 bgp = bgp_lookup_by_name (argv[0]);
11369 if (bgp == NULL)
11370 {
11371 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11372 return CMD_WARNING;
11373 }
11374 }
11375 else
11376 {
11377 bgp = bgp_get_default ();
11378 if (bgp == NULL)
11379 {
11380 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11381 return CMD_WARNING;
11382 }
11383 }
11384
11385 if (argc == 3)
11386 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11387 else
11388 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11389
11390 if (! peer)
11391 return CMD_WARNING;
11392
11393 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11394 {
11395 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11396 VTY_NEWLINE);
11397 return CMD_WARNING;
11398 }
11399
11400 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11401 PEER_FLAG_RSERVER_CLIENT))
11402 {
11403 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11404 VTY_NEWLINE);
11405 return CMD_WARNING;
11406 }
11407
11408 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11409 (argc == 3) ? argv[2] : argv[1],
11410 AFI_IP6, SAFI_UNICAST, NULL, 0);
11411}
11412
11413ALIAS (show_bgp_view_rsclient_route,
11414 show_bgp_rsclient_route_cmd,
11415 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11416 SHOW_STR
11417 BGP_STR
11418 "Information about Route Server Client\n"
11419 NEIGHBOR_ADDR_STR
11420 "Network in the BGP routing table to display\n")
11421
Michael Lambert95cbbd22010-07-23 14:43:04 -040011422DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11423 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11424 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11425 SHOW_STR
11426 BGP_STR
11427 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011428 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011429 "Address family\n"
11430 "Address Family modifier\n"
11431 "Address Family modifier\n"
11432 "Information about Route Server Client\n"
11433 NEIGHBOR_ADDR_STR
11434 "Network in the BGP routing table to display\n")
11435{
11436 struct bgp *bgp;
11437 struct peer *peer;
11438 safi_t safi;
11439
11440 /* BGP structure lookup. */
11441 if (argc == 4)
11442 {
11443 bgp = bgp_lookup_by_name (argv[0]);
11444 if (bgp == NULL)
11445 {
11446 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11447 return CMD_WARNING;
11448 }
11449 }
11450 else
11451 {
11452 bgp = bgp_get_default ();
11453 if (bgp == NULL)
11454 {
11455 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11456 return CMD_WARNING;
11457 }
11458 }
11459
11460 if (argc == 4) {
11461 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11462 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11463 } else {
11464 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11465 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11466 }
11467
11468 if (! peer)
11469 return CMD_WARNING;
11470
11471 if (! peer->afc[AFI_IP6][safi])
11472 {
11473 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11474 VTY_NEWLINE);
11475 return CMD_WARNING;
11476}
11477
11478 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11479 PEER_FLAG_RSERVER_CLIENT))
11480 {
11481 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11482 VTY_NEWLINE);
11483 return CMD_WARNING;
11484 }
11485
11486 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11487 (argc == 4) ? argv[3] : argv[2],
11488 AFI_IP6, safi, NULL, 0);
11489}
11490
11491ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11492 show_bgp_ipv6_safi_rsclient_route_cmd,
11493 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11494 SHOW_STR
11495 BGP_STR
11496 "Address family\n"
11497 "Address Family modifier\n"
11498 "Address Family modifier\n"
11499 "Information about Route Server Client\n"
11500 NEIGHBOR_ADDR_STR
11501 "Network in the BGP routing table to display\n")
11502
paulfee0f4c2004-09-13 05:12:46 +000011503DEFUN (show_bgp_view_rsclient_prefix,
11504 show_bgp_view_rsclient_prefix_cmd,
11505 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11506 SHOW_STR
11507 BGP_STR
11508 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011509 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011510 "Information about Route Server Client\n"
11511 NEIGHBOR_ADDR_STR
11512 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11513{
11514 struct bgp *bgp;
11515 struct peer *peer;
11516
11517 /* BGP structure lookup. */
11518 if (argc == 3)
11519 {
11520 bgp = bgp_lookup_by_name (argv[0]);
11521 if (bgp == NULL)
11522 {
11523 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11524 return CMD_WARNING;
11525 }
11526 }
11527 else
11528 {
11529 bgp = bgp_get_default ();
11530 if (bgp == NULL)
11531 {
11532 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11533 return CMD_WARNING;
11534 }
11535 }
11536
11537 if (argc == 3)
11538 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11539 else
11540 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11541
11542 if (! peer)
11543 return CMD_WARNING;
11544
11545 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11546 {
11547 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11548 VTY_NEWLINE);
11549 return CMD_WARNING;
11550 }
11551
11552 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11553 PEER_FLAG_RSERVER_CLIENT))
11554 {
11555 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11556 VTY_NEWLINE);
11557 return CMD_WARNING;
11558 }
11559
11560 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11561 (argc == 3) ? argv[2] : argv[1],
11562 AFI_IP6, SAFI_UNICAST, NULL, 1);
11563}
11564
11565ALIAS (show_bgp_view_rsclient_prefix,
11566 show_bgp_rsclient_prefix_cmd,
11567 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11568 SHOW_STR
11569 BGP_STR
11570 "Information about Route Server Client\n"
11571 NEIGHBOR_ADDR_STR
11572 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11573
Michael Lambert95cbbd22010-07-23 14:43:04 -040011574DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11575 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11576 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11577 SHOW_STR
11578 BGP_STR
11579 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011580 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011581 "Address family\n"
11582 "Address Family modifier\n"
11583 "Address Family modifier\n"
11584 "Information about Route Server Client\n"
11585 NEIGHBOR_ADDR_STR
11586 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11587{
11588 struct bgp *bgp;
11589 struct peer *peer;
11590 safi_t safi;
11591
11592 /* BGP structure lookup. */
11593 if (argc == 4)
11594 {
11595 bgp = bgp_lookup_by_name (argv[0]);
11596 if (bgp == NULL)
11597 {
11598 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11599 return CMD_WARNING;
11600 }
11601 }
11602 else
11603 {
11604 bgp = bgp_get_default ();
11605 if (bgp == NULL)
11606 {
11607 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11608 return CMD_WARNING;
11609 }
11610 }
11611
11612 if (argc == 4) {
11613 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11614 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11615 } else {
11616 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11617 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11618 }
11619
11620 if (! peer)
11621 return CMD_WARNING;
11622
11623 if (! peer->afc[AFI_IP6][safi])
11624 {
11625 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11626 VTY_NEWLINE);
11627 return CMD_WARNING;
11628}
11629
11630 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11631 PEER_FLAG_RSERVER_CLIENT))
11632{
11633 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11634 VTY_NEWLINE);
11635 return CMD_WARNING;
11636 }
11637
11638 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11639 (argc == 4) ? argv[3] : argv[2],
11640 AFI_IP6, safi, NULL, 1);
11641}
11642
11643ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11644 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11645 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11646 SHOW_STR
11647 BGP_STR
11648 "Address family\n"
11649 "Address Family modifier\n"
11650 "Address Family modifier\n"
11651 "Information about Route Server Client\n"
11652 NEIGHBOR_ADDR_STR
11653 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11654
paul718e3742002-12-13 20:15:29 +000011655#endif /* HAVE_IPV6 */
11656
11657struct bgp_table *bgp_distance_table;
11658
11659struct bgp_distance
11660{
11661 /* Distance value for the IP source prefix. */
11662 u_char distance;
11663
11664 /* Name of the access-list to be matched. */
11665 char *access_list;
11666};
11667
paul94f2b392005-06-28 12:44:16 +000011668static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011669bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011670{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011671 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011672}
11673
paul94f2b392005-06-28 12:44:16 +000011674static void
paul718e3742002-12-13 20:15:29 +000011675bgp_distance_free (struct bgp_distance *bdistance)
11676{
11677 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11678}
11679
paul94f2b392005-06-28 12:44:16 +000011680static int
paulfd79ac92004-10-13 05:06:08 +000011681bgp_distance_set (struct vty *vty, const char *distance_str,
11682 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011683{
11684 int ret;
11685 struct prefix_ipv4 p;
11686 u_char distance;
11687 struct bgp_node *rn;
11688 struct bgp_distance *bdistance;
11689
11690 ret = str2prefix_ipv4 (ip_str, &p);
11691 if (ret == 0)
11692 {
11693 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11694 return CMD_WARNING;
11695 }
11696
11697 distance = atoi (distance_str);
11698
11699 /* Get BGP distance node. */
11700 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11701 if (rn->info)
11702 {
11703 bdistance = rn->info;
11704 bgp_unlock_node (rn);
11705 }
11706 else
11707 {
11708 bdistance = bgp_distance_new ();
11709 rn->info = bdistance;
11710 }
11711
11712 /* Set distance value. */
11713 bdistance->distance = distance;
11714
11715 /* Reset access-list configuration. */
11716 if (bdistance->access_list)
11717 {
11718 free (bdistance->access_list);
11719 bdistance->access_list = NULL;
11720 }
11721 if (access_list_str)
11722 bdistance->access_list = strdup (access_list_str);
11723
11724 return CMD_SUCCESS;
11725}
11726
paul94f2b392005-06-28 12:44:16 +000011727static int
paulfd79ac92004-10-13 05:06:08 +000011728bgp_distance_unset (struct vty *vty, const char *distance_str,
11729 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011730{
11731 int ret;
11732 struct prefix_ipv4 p;
11733 u_char distance;
11734 struct bgp_node *rn;
11735 struct bgp_distance *bdistance;
11736
11737 ret = str2prefix_ipv4 (ip_str, &p);
11738 if (ret == 0)
11739 {
11740 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11741 return CMD_WARNING;
11742 }
11743
11744 distance = atoi (distance_str);
11745
11746 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11747 if (! rn)
11748 {
11749 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11750 return CMD_WARNING;
11751 }
11752
11753 bdistance = rn->info;
11754
11755 if (bdistance->access_list)
11756 free (bdistance->access_list);
11757 bgp_distance_free (bdistance);
11758
11759 rn->info = NULL;
11760 bgp_unlock_node (rn);
11761 bgp_unlock_node (rn);
11762
11763 return CMD_SUCCESS;
11764}
11765
paul718e3742002-12-13 20:15:29 +000011766/* Apply BGP information to distance method. */
11767u_char
11768bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11769{
11770 struct bgp_node *rn;
11771 struct prefix_ipv4 q;
11772 struct peer *peer;
11773 struct bgp_distance *bdistance;
11774 struct access_list *alist;
11775 struct bgp_static *bgp_static;
11776
11777 if (! bgp)
11778 return 0;
11779
11780 if (p->family != AF_INET)
11781 return 0;
11782
11783 peer = rinfo->peer;
11784
11785 if (peer->su.sa.sa_family != AF_INET)
11786 return 0;
11787
11788 memset (&q, 0, sizeof (struct prefix_ipv4));
11789 q.family = AF_INET;
11790 q.prefix = peer->su.sin.sin_addr;
11791 q.prefixlen = IPV4_MAX_BITLEN;
11792
11793 /* Check source address. */
11794 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11795 if (rn)
11796 {
11797 bdistance = rn->info;
11798 bgp_unlock_node (rn);
11799
11800 if (bdistance->access_list)
11801 {
11802 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11803 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11804 return bdistance->distance;
11805 }
11806 else
11807 return bdistance->distance;
11808 }
11809
11810 /* Backdoor check. */
11811 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11812 if (rn)
11813 {
11814 bgp_static = rn->info;
11815 bgp_unlock_node (rn);
11816
11817 if (bgp_static->backdoor)
11818 {
11819 if (bgp->distance_local)
11820 return bgp->distance_local;
11821 else
11822 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11823 }
11824 }
11825
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011826 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011827 {
11828 if (bgp->distance_ebgp)
11829 return bgp->distance_ebgp;
11830 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11831 }
11832 else
11833 {
11834 if (bgp->distance_ibgp)
11835 return bgp->distance_ibgp;
11836 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11837 }
11838}
11839
11840DEFUN (bgp_distance,
11841 bgp_distance_cmd,
11842 "distance bgp <1-255> <1-255> <1-255>",
11843 "Define an administrative distance\n"
11844 "BGP distance\n"
11845 "Distance for routes external to the AS\n"
11846 "Distance for routes internal to the AS\n"
11847 "Distance for local routes\n")
11848{
11849 struct bgp *bgp;
11850
11851 bgp = vty->index;
11852
11853 bgp->distance_ebgp = atoi (argv[0]);
11854 bgp->distance_ibgp = atoi (argv[1]);
11855 bgp->distance_local = atoi (argv[2]);
11856 return CMD_SUCCESS;
11857}
11858
11859DEFUN (no_bgp_distance,
11860 no_bgp_distance_cmd,
11861 "no distance bgp <1-255> <1-255> <1-255>",
11862 NO_STR
11863 "Define an administrative distance\n"
11864 "BGP distance\n"
11865 "Distance for routes external to the AS\n"
11866 "Distance for routes internal to the AS\n"
11867 "Distance for local routes\n")
11868{
11869 struct bgp *bgp;
11870
11871 bgp = vty->index;
11872
11873 bgp->distance_ebgp= 0;
11874 bgp->distance_ibgp = 0;
11875 bgp->distance_local = 0;
11876 return CMD_SUCCESS;
11877}
11878
11879ALIAS (no_bgp_distance,
11880 no_bgp_distance2_cmd,
11881 "no distance bgp",
11882 NO_STR
11883 "Define an administrative distance\n"
11884 "BGP distance\n")
11885
11886DEFUN (bgp_distance_source,
11887 bgp_distance_source_cmd,
11888 "distance <1-255> A.B.C.D/M",
11889 "Define an administrative distance\n"
11890 "Administrative distance\n"
11891 "IP source prefix\n")
11892{
11893 bgp_distance_set (vty, argv[0], argv[1], NULL);
11894 return CMD_SUCCESS;
11895}
11896
11897DEFUN (no_bgp_distance_source,
11898 no_bgp_distance_source_cmd,
11899 "no distance <1-255> A.B.C.D/M",
11900 NO_STR
11901 "Define an administrative distance\n"
11902 "Administrative distance\n"
11903 "IP source prefix\n")
11904{
11905 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11906 return CMD_SUCCESS;
11907}
11908
11909DEFUN (bgp_distance_source_access_list,
11910 bgp_distance_source_access_list_cmd,
11911 "distance <1-255> A.B.C.D/M WORD",
11912 "Define an administrative distance\n"
11913 "Administrative distance\n"
11914 "IP source prefix\n"
11915 "Access list name\n")
11916{
11917 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11918 return CMD_SUCCESS;
11919}
11920
11921DEFUN (no_bgp_distance_source_access_list,
11922 no_bgp_distance_source_access_list_cmd,
11923 "no distance <1-255> A.B.C.D/M WORD",
11924 NO_STR
11925 "Define an administrative distance\n"
11926 "Administrative distance\n"
11927 "IP source prefix\n"
11928 "Access list name\n")
11929{
11930 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11931 return CMD_SUCCESS;
11932}
11933
11934DEFUN (bgp_damp_set,
11935 bgp_damp_set_cmd,
11936 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11937 "BGP Specific commands\n"
11938 "Enable route-flap dampening\n"
11939 "Half-life time for the penalty\n"
11940 "Value to start reusing a route\n"
11941 "Value to start suppressing a route\n"
11942 "Maximum duration to suppress a stable route\n")
11943{
11944 struct bgp *bgp;
11945 int half = DEFAULT_HALF_LIFE * 60;
11946 int reuse = DEFAULT_REUSE;
11947 int suppress = DEFAULT_SUPPRESS;
11948 int max = 4 * half;
11949
11950 if (argc == 4)
11951 {
11952 half = atoi (argv[0]) * 60;
11953 reuse = atoi (argv[1]);
11954 suppress = atoi (argv[2]);
11955 max = atoi (argv[3]) * 60;
11956 }
11957 else if (argc == 1)
11958 {
11959 half = atoi (argv[0]) * 60;
11960 max = 4 * half;
11961 }
11962
11963 bgp = vty->index;
11964 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11965 half, reuse, suppress, max);
11966}
11967
11968ALIAS (bgp_damp_set,
11969 bgp_damp_set2_cmd,
11970 "bgp dampening <1-45>",
11971 "BGP Specific commands\n"
11972 "Enable route-flap dampening\n"
11973 "Half-life time for the penalty\n")
11974
11975ALIAS (bgp_damp_set,
11976 bgp_damp_set3_cmd,
11977 "bgp dampening",
11978 "BGP Specific commands\n"
11979 "Enable route-flap dampening\n")
11980
11981DEFUN (bgp_damp_unset,
11982 bgp_damp_unset_cmd,
11983 "no bgp dampening",
11984 NO_STR
11985 "BGP Specific commands\n"
11986 "Enable route-flap dampening\n")
11987{
11988 struct bgp *bgp;
11989
11990 bgp = vty->index;
11991 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11992}
11993
11994ALIAS (bgp_damp_unset,
11995 bgp_damp_unset2_cmd,
11996 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11997 NO_STR
11998 "BGP Specific commands\n"
11999 "Enable route-flap dampening\n"
12000 "Half-life time for the penalty\n"
12001 "Value to start reusing a route\n"
12002 "Value to start suppressing a route\n"
12003 "Maximum duration to suppress a stable route\n")
12004
12005DEFUN (show_ip_bgp_dampened_paths,
12006 show_ip_bgp_dampened_paths_cmd,
12007 "show ip bgp dampened-paths",
12008 SHOW_STR
12009 IP_STR
12010 BGP_STR
12011 "Display paths suppressed due to dampening\n")
12012{
ajs5a646652004-11-05 01:25:55 +000012013 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12014 NULL);
paul718e3742002-12-13 20:15:29 +000012015}
12016
12017DEFUN (show_ip_bgp_flap_statistics,
12018 show_ip_bgp_flap_statistics_cmd,
12019 "show ip bgp flap-statistics",
12020 SHOW_STR
12021 IP_STR
12022 BGP_STR
12023 "Display flap statistics of routes\n")
12024{
ajs5a646652004-11-05 01:25:55 +000012025 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12026 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012027}
12028
12029/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012030static int
paulfd79ac92004-10-13 05:06:08 +000012031bgp_clear_damp_route (struct vty *vty, const char *view_name,
12032 const char *ip_str, afi_t afi, safi_t safi,
12033 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012034{
12035 int ret;
12036 struct prefix match;
12037 struct bgp_node *rn;
12038 struct bgp_node *rm;
12039 struct bgp_info *ri;
12040 struct bgp_info *ri_temp;
12041 struct bgp *bgp;
12042 struct bgp_table *table;
12043
12044 /* BGP structure lookup. */
12045 if (view_name)
12046 {
12047 bgp = bgp_lookup_by_name (view_name);
12048 if (bgp == NULL)
12049 {
12050 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12051 return CMD_WARNING;
12052 }
12053 }
12054 else
12055 {
12056 bgp = bgp_get_default ();
12057 if (bgp == NULL)
12058 {
12059 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12060 return CMD_WARNING;
12061 }
12062 }
12063
12064 /* Check IP address argument. */
12065 ret = str2prefix (ip_str, &match);
12066 if (! ret)
12067 {
12068 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12069 return CMD_WARNING;
12070 }
12071
12072 match.family = afi2family (afi);
12073
12074 if (safi == SAFI_MPLS_VPN)
12075 {
12076 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12077 {
12078 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12079 continue;
12080
12081 if ((table = rn->info) != NULL)
12082 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012083 {
12084 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12085 {
12086 ri = rm->info;
12087 while (ri)
12088 {
12089 if (ri->extra && ri->extra->damp_info)
12090 {
12091 ri_temp = ri->next;
12092 bgp_damp_info_free (ri->extra->damp_info, 1);
12093 ri = ri_temp;
12094 }
12095 else
12096 ri = ri->next;
12097 }
12098 }
12099
12100 bgp_unlock_node (rm);
12101 }
paul718e3742002-12-13 20:15:29 +000012102 }
12103 }
12104 else
12105 {
12106 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012107 {
12108 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12109 {
12110 ri = rn->info;
12111 while (ri)
12112 {
12113 if (ri->extra && ri->extra->damp_info)
12114 {
12115 ri_temp = ri->next;
12116 bgp_damp_info_free (ri->extra->damp_info, 1);
12117 ri = ri_temp;
12118 }
12119 else
12120 ri = ri->next;
12121 }
12122 }
12123
12124 bgp_unlock_node (rn);
12125 }
paul718e3742002-12-13 20:15:29 +000012126 }
12127
12128 return CMD_SUCCESS;
12129}
12130
12131DEFUN (clear_ip_bgp_dampening,
12132 clear_ip_bgp_dampening_cmd,
12133 "clear ip bgp dampening",
12134 CLEAR_STR
12135 IP_STR
12136 BGP_STR
12137 "Clear route flap dampening information\n")
12138{
12139 bgp_damp_info_clean ();
12140 return CMD_SUCCESS;
12141}
12142
12143DEFUN (clear_ip_bgp_dampening_prefix,
12144 clear_ip_bgp_dampening_prefix_cmd,
12145 "clear ip bgp dampening A.B.C.D/M",
12146 CLEAR_STR
12147 IP_STR
12148 BGP_STR
12149 "Clear route flap dampening information\n"
12150 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12151{
12152 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12153 SAFI_UNICAST, NULL, 1);
12154}
12155
12156DEFUN (clear_ip_bgp_dampening_address,
12157 clear_ip_bgp_dampening_address_cmd,
12158 "clear ip bgp dampening A.B.C.D",
12159 CLEAR_STR
12160 IP_STR
12161 BGP_STR
12162 "Clear route flap dampening information\n"
12163 "Network to clear damping information\n")
12164{
12165 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12166 SAFI_UNICAST, NULL, 0);
12167}
12168
12169DEFUN (clear_ip_bgp_dampening_address_mask,
12170 clear_ip_bgp_dampening_address_mask_cmd,
12171 "clear ip bgp dampening A.B.C.D A.B.C.D",
12172 CLEAR_STR
12173 IP_STR
12174 BGP_STR
12175 "Clear route flap dampening information\n"
12176 "Network to clear damping information\n"
12177 "Network mask\n")
12178{
12179 int ret;
12180 char prefix_str[BUFSIZ];
12181
12182 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12183 if (! ret)
12184 {
12185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12186 return CMD_WARNING;
12187 }
12188
12189 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12190 SAFI_UNICAST, NULL, 0);
12191}
12192
paul94f2b392005-06-28 12:44:16 +000012193static int
paul718e3742002-12-13 20:15:29 +000012194bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12195 afi_t afi, safi_t safi, int *write)
12196{
12197 struct bgp_node *prn;
12198 struct bgp_node *rn;
12199 struct bgp_table *table;
12200 struct prefix *p;
12201 struct prefix_rd *prd;
12202 struct bgp_static *bgp_static;
12203 u_int32_t label;
12204 char buf[SU_ADDRSTRLEN];
12205 char rdbuf[RD_ADDRSTRLEN];
12206
12207 /* Network configuration. */
12208 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12209 if ((table = prn->info) != NULL)
12210 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12211 if ((bgp_static = rn->info) != NULL)
12212 {
12213 p = &rn->p;
12214 prd = (struct prefix_rd *) &prn->p;
12215
12216 /* "address-family" display. */
12217 bgp_config_write_family_header (vty, afi, safi, write);
12218
12219 /* "network" configuration display. */
12220 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12221 label = decode_label (bgp_static->tag);
12222
12223 vty_out (vty, " network %s/%d rd %s tag %d",
12224 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12225 p->prefixlen,
12226 rdbuf, label);
12227 vty_out (vty, "%s", VTY_NEWLINE);
12228 }
12229 return 0;
12230}
12231
12232/* Configuration of static route announcement and aggregate
12233 information. */
12234int
12235bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12236 afi_t afi, safi_t safi, int *write)
12237{
12238 struct bgp_node *rn;
12239 struct prefix *p;
12240 struct bgp_static *bgp_static;
12241 struct bgp_aggregate *bgp_aggregate;
12242 char buf[SU_ADDRSTRLEN];
12243
12244 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12245 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12246
12247 /* Network configuration. */
12248 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12249 if ((bgp_static = rn->info) != NULL)
12250 {
12251 p = &rn->p;
12252
12253 /* "address-family" display. */
12254 bgp_config_write_family_header (vty, afi, safi, write);
12255
12256 /* "network" configuration display. */
12257 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12258 {
12259 u_int32_t destination;
12260 struct in_addr netmask;
12261
12262 destination = ntohl (p->u.prefix4.s_addr);
12263 masklen2ip (p->prefixlen, &netmask);
12264 vty_out (vty, " network %s",
12265 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12266
12267 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12268 || (IN_CLASSB (destination) && p->prefixlen == 16)
12269 || (IN_CLASSA (destination) && p->prefixlen == 8)
12270 || p->u.prefix4.s_addr == 0)
12271 {
12272 /* Natural mask is not display. */
12273 }
12274 else
12275 vty_out (vty, " mask %s", inet_ntoa (netmask));
12276 }
12277 else
12278 {
12279 vty_out (vty, " network %s/%d",
12280 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12281 p->prefixlen);
12282 }
12283
12284 if (bgp_static->rmap.name)
12285 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012286 else
12287 {
12288 if (bgp_static->backdoor)
12289 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012290 }
paul718e3742002-12-13 20:15:29 +000012291
12292 vty_out (vty, "%s", VTY_NEWLINE);
12293 }
12294
12295 /* Aggregate-address configuration. */
12296 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12297 if ((bgp_aggregate = rn->info) != NULL)
12298 {
12299 p = &rn->p;
12300
12301 /* "address-family" display. */
12302 bgp_config_write_family_header (vty, afi, safi, write);
12303
12304 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12305 {
12306 struct in_addr netmask;
12307
12308 masklen2ip (p->prefixlen, &netmask);
12309 vty_out (vty, " aggregate-address %s %s",
12310 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12311 inet_ntoa (netmask));
12312 }
12313 else
12314 {
12315 vty_out (vty, " aggregate-address %s/%d",
12316 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12317 p->prefixlen);
12318 }
12319
12320 if (bgp_aggregate->as_set)
12321 vty_out (vty, " as-set");
12322
12323 if (bgp_aggregate->summary_only)
12324 vty_out (vty, " summary-only");
12325
12326 vty_out (vty, "%s", VTY_NEWLINE);
12327 }
12328
12329 return 0;
12330}
12331
12332int
12333bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12334{
12335 struct bgp_node *rn;
12336 struct bgp_distance *bdistance;
12337
12338 /* Distance configuration. */
12339 if (bgp->distance_ebgp
12340 && bgp->distance_ibgp
12341 && bgp->distance_local
12342 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12343 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12344 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12345 vty_out (vty, " distance bgp %d %d %d%s",
12346 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12347 VTY_NEWLINE);
12348
12349 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12350 if ((bdistance = rn->info) != NULL)
12351 {
12352 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12353 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12354 bdistance->access_list ? bdistance->access_list : "",
12355 VTY_NEWLINE);
12356 }
12357
12358 return 0;
12359}
12360
12361/* Allocate routing table structure and install commands. */
12362void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012363bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012364{
12365 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012366 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012367
12368 /* IPv4 BGP commands. */
12369 install_element (BGP_NODE, &bgp_network_cmd);
12370 install_element (BGP_NODE, &bgp_network_mask_cmd);
12371 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12372 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12373 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12374 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12375 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12376 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12377 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12378 install_element (BGP_NODE, &no_bgp_network_cmd);
12379 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12380 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12381 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12382 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12383 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12384 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12385 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12386 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12387
12388 install_element (BGP_NODE, &aggregate_address_cmd);
12389 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12390 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12391 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12392 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12393 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12394 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12395 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12396 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12397 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12398 install_element (BGP_NODE, &no_aggregate_address_cmd);
12399 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12400 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12401 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12402 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12403 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12404 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12405 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12406 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12407 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12408
12409 /* IPv4 unicast configuration. */
12410 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12411 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12412 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12413 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12414 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12415 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012416 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012417 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12418 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12419 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12420 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12421 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012422
paul718e3742002-12-13 20:15:29 +000012423 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12424 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12425 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12426 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12427 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12428 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12429 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12430 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12431 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12432 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12433 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12434 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12435 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12436 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12437 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12438 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12439 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12440 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12441 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12442 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12443
12444 /* IPv4 multicast configuration. */
12445 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12446 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12447 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12448 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12449 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12450 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12455 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12456 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12457 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12458 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12459 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12460 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12461 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12462 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12463 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12464 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12465 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12466 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12476 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12477
12478 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012480 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012481 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012483 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012484 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012488 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012489 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12517 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12518 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012519 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012537 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012538 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012554 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012556 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012557 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012558 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012559 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012560 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012562 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012563 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012564 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012565 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012566 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012567 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012568
12569 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012572 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012573 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012577 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12582 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12583 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12584 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12585 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012589 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12590 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12591 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12592 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12593 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012594 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012603 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012604 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012605 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012606 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012607 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012608 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012609 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012610
12611 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012613 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012614 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012616 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012617 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012622 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012647 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12648 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12649 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12650 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12651 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012652 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012670 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012671 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012687 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012688 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012689 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012690 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012691 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012692 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012693 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012695 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012696 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012697 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012698 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012699 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012700 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012701
12702 /* BGP dampening clear commands */
12703 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12704 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12705 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12706 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12707
Paul Jakmaff7924f2006-09-04 01:10:36 +000012708 /* prefix count */
12709 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12710 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12711 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012712#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012713 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12714
paul718e3742002-12-13 20:15:29 +000012715 /* New config IPv6 BGP commands. */
12716 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12717 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12718 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12719 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12720
12721 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12722 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12723 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12724 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12725
G.Balaji73bfe0b2011-09-23 22:36:20 +053012726 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12727 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12728
paul718e3742002-12-13 20:15:29 +000012729 /* Old config IPv6 BGP commands. */
12730 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12731 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12732
12733 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12734 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12735 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12736 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12737
12738 install_element (VIEW_NODE, &show_bgp_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012740 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012741 install_element (VIEW_NODE, &show_bgp_route_cmd);
12742 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012743 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012744 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012746 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012747 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12749 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12751 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12753 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12755 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12757 install_element (VIEW_NODE, &show_bgp_community_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12759 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12761 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12762 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12763 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12765 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12767 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12769 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12771 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12773 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12775 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12777 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12779 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12781 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12783 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12785 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012787 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12789 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012791 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012792 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012793 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012795 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012797 install_element (VIEW_NODE, &show_bgp_view_cmd);
12798 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12799 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12800 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12801 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12802 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12807 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12808 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12809 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12810 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12811 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12812 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12813 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12814 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012815 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012816 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012817 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012819 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012821
12822 /* Restricted:
12823 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12824 */
12825 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012828 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012830 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012831 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12840 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12841 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12843 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012849 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012851 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012858 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012859 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012860 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012861
12862 install_element (ENABLE_NODE, &show_bgp_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012864 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012865 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012867 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012868 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012870 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012871 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012911 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012915 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012916 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012917 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012919 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012920 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012921 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012939 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012940 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012941 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012943 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012944 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012945
12946 /* Statistics */
12947 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12951
paul718e3742002-12-13 20:15:29 +000012952 /* old command */
12953 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012989
paul718e3742002-12-13 20:15:29 +000012990 /* old command */
12991 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13027
13028 /* old command */
13029 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13030 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13031 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13032 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13033
13034 /* old command */
13035 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13036 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13037 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13038 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13039
13040 /* old command */
13041 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13042 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13043 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13044 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13045#endif /* HAVE_IPV6 */
13046
13047 install_element (BGP_NODE, &bgp_distance_cmd);
13048 install_element (BGP_NODE, &no_bgp_distance_cmd);
13049 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13050 install_element (BGP_NODE, &bgp_distance_source_cmd);
13051 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13052 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13053 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13054
13055 install_element (BGP_NODE, &bgp_damp_set_cmd);
13056 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13057 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13058 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13059 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13064 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013065
13066 /* Deprecated AS-Pathlimit commands */
13067 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13068 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13069 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13070 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13071 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13072 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13073
13074 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13075 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13076 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13077 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13078 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13079 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13080
13081 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13086 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13087
13088 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13089 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13090 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13091 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13092 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13093 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13094
13095 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13096 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13097 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13098 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13099 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13100 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13101
13102 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13103 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13104 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13105 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13106 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13107 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013108
13109#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013110 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13111 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013112#endif
paul718e3742002-12-13 20:15:29 +000013113}
Chris Caputo228da422009-07-18 05:44:03 +000013114
13115void
13116bgp_route_finish (void)
13117{
13118 bgp_table_unlock (bgp_distance_table);
13119 bgp_distance_table = NULL;
13120}