blob: 7f68b8d0aa4eafa876a7d92a6211c760f3c15c5c [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 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
paul94f2b392005-06-28 12:44:16 +0000566static enum filter_type
paul718e3742002-12-13 20:15:29 +0000567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
paul718e3742002-12-13 20:15:29 +0000583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 }
paul718e3742002-12-13 20:15:29 +0000586
Paul Jakma650f76c2009-06-25 18:06:31 +0100587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
paul718e3742002-12-13 20:15:29 +0000590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 }
paul718e3742002-12-13 20:15:29 +0000593
Paul Jakma650f76c2009-06-25 18:06:31 +0100594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
paul718e3742002-12-13 20:15:29 +0000597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 }
600
paul718e3742002-12-13 20:15:29 +0000601 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000603}
604
paul94f2b392005-06-28 12:44:16 +0000605static enum filter_type
paul718e3742002-12-13 20:15:29 +0000606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
paul718e3742002-12-13 20:15:29 +0000622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624 }
paul718e3742002-12-13 20:15:29 +0000625
Paul Jakma650f76c2009-06-25 18:06:31 +0100626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
paul718e3742002-12-13 20:15:29 +0000629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100631 }
paul718e3742002-12-13 20:15:29 +0000632
Paul Jakma650f76c2009-06-25 18:06:31 +0100633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
paul718e3742002-12-13 20:15:29 +0000636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 }
paul718e3742002-12-13 20:15:29 +0000639
640 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000642}
643
644/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000645static int
paul718e3742002-12-13 20:15:29 +0000646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000655 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
Paul Jakmafb982c22007-05-04 20:15:47 +0000674 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000682 return 1;
683 }
684 return 0;
685}
686
paul94f2b392005-06-28 12:44:16 +0000687static int
paul718e3742002-12-13 20:15:29 +0000688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
paulac41b2a2003-08-12 05:32:27 +0000708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
paul718e3742002-12-13 20:15:29 +0000710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000712
713 peer->rmap_type = 0;
714
paul718e3742002-12-13 20:15:29 +0000715 if (ret == RMAP_DENYMATCH)
716 {
717 /* Free newly generated AS path and community by route-map. */
718 bgp_attr_flush (attr);
719 return RMAP_DENY;
720 }
721 }
722 return RMAP_PERMIT;
723}
724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
paul35be31b2004-05-01 18:17:04 +0000826 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
827 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700828 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000829 return 0;
830#ifdef HAVE_IPV6
831 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700832 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000833 return 0;
834#endif
835
paul718e3742002-12-13 20:15:29 +0000836 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000837 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000838 if (! UNSUPPRESS_MAP_NAME (filter))
839 return 0;
840
841 /* Default route check. */
842 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
843 {
844 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
845 return 0;
846#ifdef HAVE_IPV6
847 else if (p->family == AF_INET6 && p->prefixlen == 0)
848 return 0;
849#endif /* HAVE_IPV6 */
850 }
851
paul286e1e72003-08-08 00:24:31 +0000852 /* Transparency check. */
853 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
854 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
855 transparent = 1;
856 else
857 transparent = 0;
858
paul718e3742002-12-13 20:15:29 +0000859 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700860 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000861 return 0;
862
863 /* If the attribute has originator-id and it is same as remote
864 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700865 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000866 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700867 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000868 {
869 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000870 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000871 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
872 peer->host,
873 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
874 p->prefixlen);
875 return 0;
876 }
877 }
878
879 /* ORF prefix-list filter check */
880 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
881 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
882 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
883 if (peer->orf_plist[afi][safi])
884 {
885 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
886 return 0;
887 }
888
889 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
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,
paul718e3742002-12-13 20:15:29 +0000894 "%s [Update:SEND] %s/%d is filtered",
895 peer->host,
896 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
897 p->prefixlen);
898 return 0;
899 }
900
901#ifdef BGP_SEND_ASPATH_CHECK
902 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check (riattr->aspath, peer->as))
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, peer->as);
909 return 0;
910 }
911#endif /* BGP_SEND_ASPATH_CHECK */
912
913 /* If we're a CONFED we need to loop check the CONFED ID too */
914 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
915 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700916 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000917 {
918 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000919 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400920 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000921 peer->host,
922 bgp->confed_id);
923 return 0;
924 }
925 }
926
927 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000928 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000929 reflect = 1;
930 else
931 reflect = 0;
932
933 /* IBGP reflection check. */
934 if (reflect)
935 {
936 /* A route from a Client peer. */
937 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
938 {
939 /* Reflect to all the Non-Client peers and also to the
940 Client peers other than the originator. Originator check
941 is already done. So there is noting to do. */
942 /* no bgp client-to-client reflection check. */
943 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
944 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
945 return 0;
946 }
947 else
948 {
949 /* A route from a Non-client peer. Reflect to all other
950 clients. */
951 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
952 return 0;
953 }
954 }
Paul Jakma41367172007-08-06 15:24:51 +0000955
paul718e3742002-12-13 20:15:29 +0000956 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700957 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000958
paul718e3742002-12-13 20:15:29 +0000959 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000960 if ((peer->sort == BGP_PEER_IBGP
961 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000962 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
963 {
964 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
965 attr->local_pref = bgp->default_local_pref;
966 }
967
paul718e3742002-12-13 20:15:29 +0000968 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000969 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000970 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
971 {
972 if (ri->peer != bgp->peer_self && ! transparent
973 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
974 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
975 }
976
977 /* next-hop-set */
978 if (transparent || reflect
979 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
980 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000981#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000982 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000983 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000984#endif /* HAVE_IPV6 */
985 )))
paul718e3742002-12-13 20:15:29 +0000986 {
987 /* NEXT-HOP Unchanged. */
988 }
989 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
990 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
991#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000992 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000993 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000994#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000995 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000996 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
997 {
998 /* Set IPv4 nexthop. */
999 if (p->family == AF_INET)
1000 {
1001 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001002 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1003 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001004 else
1005 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1006 }
1007#ifdef HAVE_IPV6
1008 /* Set IPv6 nexthop. */
1009 if (p->family == AF_INET6)
1010 {
1011 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001013 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001014 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001015 }
1016#endif /* HAVE_IPV6 */
1017 }
1018
1019#ifdef HAVE_IPV6
1020 if (p->family == AF_INET6)
1021 {
paulfee0f4c2004-09-13 05:12:46 +00001022 /* Left nexthop_local unchanged if so configured. */
1023 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1024 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1025 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001026 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1027 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001028 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001029 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001030 }
1031
1032 /* Default nexthop_local treatment for non-RS-Clients */
1033 else
1034 {
paul718e3742002-12-13 20:15:29 +00001035 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001036 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001037
1038 /* Set link-local address for shared network peer. */
1039 if (peer->shared_network
1040 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1041 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001042 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001043 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001045 }
1046
1047 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1048 address.*/
1049 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001050 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001051
1052 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1053 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001054 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001055 }
paulfee0f4c2004-09-13 05:12:46 +00001056
1057 }
paul718e3742002-12-13 20:15:29 +00001058#endif /* HAVE_IPV6 */
1059
1060 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001061 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001062 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1063 && aspath_private_as_check (attr->aspath))
1064 attr->aspath = aspath_empty_get ();
1065
1066 /* Route map & unsuppress-map apply. */
1067 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001068 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001069 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001070 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001071 struct attr dummy_attr;
1072 struct attr_extra dummy_extra;
1073
1074 dummy_attr.extra = &dummy_extra;
1075
paul718e3742002-12-13 20:15:29 +00001076 info.peer = peer;
1077 info.attr = attr;
1078
1079 /* The route reflector is not allowed to modify the attributes
1080 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001081 if (from->sort == BGP_PEER_IBGP
1082 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001084 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001085 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001086 }
paulac41b2a2003-08-12 05:32:27 +00001087
1088 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1089
Paul Jakmafb982c22007-05-04 20:15:47 +00001090 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001091 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1092 else
1093 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1094
paulac41b2a2003-08-12 05:32:27 +00001095 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001096
paul718e3742002-12-13 20:15:29 +00001097 if (ret == RMAP_DENYMATCH)
1098 {
1099 bgp_attr_flush (attr);
1100 return 0;
1101 }
1102 }
1103 return 1;
1104}
1105
paul94f2b392005-06-28 12:44:16 +00001106static int
paulfee0f4c2004-09-13 05:12:46 +00001107bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1108 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001109{
paulfee0f4c2004-09-13 05:12:46 +00001110 int ret;
1111 char buf[SU_ADDRSTRLEN];
1112 struct bgp_filter *filter;
1113 struct bgp_info info;
1114 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001115 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001116
1117 from = ri->peer;
1118 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001119 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001120
Paul Jakma750e8142008-07-22 21:11:48 +00001121 if (DISABLE_BGP_ANNOUNCE)
1122 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001123
1124 /* Do not send back route to sender. */
1125 if (from == rsclient)
1126 return 0;
1127
1128 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001129 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001130 if (! UNSUPPRESS_MAP_NAME (filter))
1131 return 0;
1132
1133 /* Default route check. */
1134 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1135 PEER_STATUS_DEFAULT_ORIGINATE))
1136 {
1137 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1138 return 0;
1139#ifdef HAVE_IPV6
1140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
1142#endif /* HAVE_IPV6 */
1143 }
1144
1145 /* If the attribute has originator-id and it is same as remote
1146 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001147 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001148 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001149 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001150 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001151 {
1152 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001153 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001154 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1155 rsclient->host,
1156 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1157 p->prefixlen);
1158 return 0;
1159 }
1160 }
1161
1162 /* ORF prefix-list filter check */
1163 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1164 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1165 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1166 if (rsclient->orf_plist[afi][safi])
1167 {
1168 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1169 return 0;
1170 }
1171
1172 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001173 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
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,
paulfee0f4c2004-09-13 05:12:46 +00001177 "%s [Update:SEND] %s/%d is filtered",
1178 rsclient->host,
1179 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1180 p->prefixlen);
1181 return 0;
1182 }
1183
1184#ifdef BGP_SEND_ASPATH_CHECK
1185 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001186 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001187 {
1188 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001189 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001190 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001191 rsclient->host, rsclient->as);
1192 return 0;
1193 }
1194#endif /* BGP_SEND_ASPATH_CHECK */
1195
1196 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001197 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001198
1199 /* next-hop-set */
1200 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1201#ifdef HAVE_IPV6
1202 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001203 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001204#endif /* HAVE_IPV6 */
1205 )
1206 {
1207 /* Set IPv4 nexthop. */
1208 if (p->family == AF_INET)
1209 {
1210 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001211 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001212 IPV4_MAX_BYTELEN);
1213 else
1214 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1215 }
1216#ifdef HAVE_IPV6
1217 /* Set IPv6 nexthop. */
1218 if (p->family == AF_INET6)
1219 {
1220 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001222 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001223 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001224 }
1225#endif /* HAVE_IPV6 */
1226 }
1227
1228#ifdef HAVE_IPV6
1229 if (p->family == AF_INET6)
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001232
paulfee0f4c2004-09-13 05:12:46 +00001233 /* Left nexthop_local unchanged if so configured. */
1234 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1235 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
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 /* Default nexthop_local treatment for RS-Clients */
1244 else
1245 {
1246 /* Announcer and RS-Client are both in the same network */
1247 if (rsclient->shared_network && from->shared_network &&
1248 (rsclient->ifindex == from->ifindex))
1249 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001250 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1251 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001252 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001254 }
1255
1256 /* Set link-local address for shared network peer. */
1257 else if (rsclient->shared_network
1258 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1259 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001261 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001262 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001263 }
1264
1265 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001266 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001267 }
1268
1269 }
1270#endif /* HAVE_IPV6 */
1271
1272
1273 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001274 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001275 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1276 && aspath_private_as_check (attr->aspath))
1277 attr->aspath = aspath_empty_get ();
1278
1279 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001280 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001281 {
1282 info.peer = rsclient;
1283 info.attr = attr;
1284
1285 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1286
Paul Jakmafb982c22007-05-04 20:15:47 +00001287 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001288 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1289 else
1290 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1291
1292 rsclient->rmap_type = 0;
1293
1294 if (ret == RMAP_DENYMATCH)
1295 {
1296 bgp_attr_flush (attr);
1297 return 0;
1298 }
1299 }
1300
1301 return 1;
1302}
1303
1304struct bgp_info_pair
1305{
1306 struct bgp_info *old;
1307 struct bgp_info *new;
1308};
1309
paul94f2b392005-06-28 12:44:16 +00001310static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001311bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1312 struct bgp_maxpaths_cfg *mpath_cfg,
1313 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001314{
paul718e3742002-12-13 20:15:29 +00001315 struct bgp_info *new_select;
1316 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001317 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001318 struct bgp_info *ri1;
1319 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001320 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001321 int paths_eq, do_mpath;
1322 struct list mp_list;
1323
1324 bgp_mp_list_init (&mp_list);
1325 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1326 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1327
paul718e3742002-12-13 20:15:29 +00001328 /* bgp deterministic-med */
1329 new_select = NULL;
1330 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1331 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1332 {
1333 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1334 continue;
1335 if (BGP_INFO_HOLDDOWN (ri1))
1336 continue;
1337
1338 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001339 if (do_mpath)
1340 bgp_mp_list_add (&mp_list, ri1);
1341 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001342 if (ri1->next)
1343 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1344 {
1345 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1346 continue;
1347 if (BGP_INFO_HOLDDOWN (ri2))
1348 continue;
1349
1350 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1351 || aspath_cmp_left_confed (ri1->attr->aspath,
1352 ri2->attr->aspath))
1353 {
Josh Bailey6918e742011-07-20 20:48:20 -07001354 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1355 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001356 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001357 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001358 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001359 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001360 if (do_mpath && !paths_eq)
1361 {
1362 bgp_mp_list_clear (&mp_list);
1363 bgp_mp_list_add (&mp_list, ri2);
1364 }
paul718e3742002-12-13 20:15:29 +00001365 }
1366
Josh Bailey6918e742011-07-20 20:48:20 -07001367 if (do_mpath && paths_eq)
1368 bgp_mp_list_add (&mp_list, ri2);
1369
Paul Jakma1a392d42006-09-07 00:24:49 +00001370 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001371 }
1372 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001373 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1374 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001375
1376 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1377 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001378 }
1379
1380 /* Check old selected route and new selected route. */
1381 old_select = NULL;
1382 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001383 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001384 {
1385 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1386 old_select = ri;
1387
1388 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001389 {
1390 /* reap REMOVED routes, if needs be
1391 * selected route must stay for a while longer though
1392 */
1393 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1394 && (ri != old_select))
1395 bgp_info_reap (rn, ri);
1396
1397 continue;
1398 }
paul718e3742002-12-13 20:15:29 +00001399
1400 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1401 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1402 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001403 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001404 continue;
1405 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001406 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1407 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001408
Josh Bailey96450fa2011-07-20 20:45:12 -07001409 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1410 {
Josh Bailey6918e742011-07-20 20:48:20 -07001411 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1412 bgp_mp_dmed_deselect (new_select);
1413
Josh Bailey96450fa2011-07-20 20:45:12 -07001414 new_select = ri;
1415
1416 if (do_mpath && !paths_eq)
1417 {
1418 bgp_mp_list_clear (&mp_list);
1419 bgp_mp_list_add (&mp_list, ri);
1420 }
1421 }
Josh Bailey6918e742011-07-20 20:48:20 -07001422 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1423 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001424
1425 if (do_mpath && paths_eq)
1426 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001427 }
paulb40d9392005-08-22 22:34:41 +00001428
paulfee0f4c2004-09-13 05:12:46 +00001429
Josh Bailey6918e742011-07-20 20:48:20 -07001430 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1431 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001432
Josh Bailey0b597ef2011-07-20 20:49:11 -07001433 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001434 bgp_mp_list_clear (&mp_list);
1435
1436 result->old = old_select;
1437 result->new = new_select;
1438
1439 return;
paulfee0f4c2004-09-13 05:12:46 +00001440}
1441
paul94f2b392005-06-28 12:44:16 +00001442static int
paulfee0f4c2004-09-13 05:12:46 +00001443bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001444 struct bgp_node *rn, afi_t afi, safi_t safi)
1445{
paulfee0f4c2004-09-13 05:12:46 +00001446 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001447 struct attr attr;
1448 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001449
1450 p = &rn->p;
1451
Paul Jakma9eda90c2007-08-30 13:36:17 +00001452 /* Announce route to Established peer. */
1453 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001454 return 0;
1455
Paul Jakma9eda90c2007-08-30 13:36:17 +00001456 /* Address family configuration check. */
1457 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001458 return 0;
1459
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001461 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1462 PEER_STATUS_ORF_WAIT_REFRESH))
1463 return 0;
1464
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1466 attr.extra = &extra;
1467
Avneesh Sachdev67174042012-08-17 08:19:49 -07001468 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001469 {
1470 case BGP_TABLE_MAIN:
1471 /* Announcement to peer->conf. If the route is filtered,
1472 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1474 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001475 else
1476 bgp_adj_out_unset (rn, peer, p, afi, safi);
1477 break;
1478 case BGP_TABLE_RSCLIENT:
1479 /* Announcement to peer->conf. If the route is filtered,
1480 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 if (selected &&
1482 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1483 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1484 else
1485 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001486 break;
1487 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001488
paulfee0f4c2004-09-13 05:12:46 +00001489 return 0;
paul200df112005-06-01 11:17:05 +00001490}
paulfee0f4c2004-09-13 05:12:46 +00001491
paul200df112005-06-01 11:17:05 +00001492struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001493{
paul200df112005-06-01 11:17:05 +00001494 struct bgp *bgp;
1495 struct bgp_node *rn;
1496 afi_t afi;
1497 safi_t safi;
1498};
1499
1500static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001501bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001502{
paul0fb58d52005-11-14 14:31:49 +00001503 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001504 struct bgp *bgp = pq->bgp;
1505 struct bgp_node *rn = pq->rn;
1506 afi_t afi = pq->afi;
1507 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001508 struct bgp_info *new_select;
1509 struct bgp_info *old_select;
1510 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001511 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001512 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001513
paulfee0f4c2004-09-13 05:12:46 +00001514 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001515 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001516 new_select = old_and_new.new;
1517 old_select = old_and_new.old;
1518
paul200df112005-06-01 11:17:05 +00001519 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1520 {
Chris Caputo228da422009-07-18 05:44:03 +00001521 if (rsclient->group)
1522 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1523 {
1524 /* Nothing to do. */
1525 if (old_select && old_select == new_select)
1526 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1527 continue;
paulfee0f4c2004-09-13 05:12:46 +00001528
Chris Caputo228da422009-07-18 05:44:03 +00001529 if (old_select)
1530 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1531 if (new_select)
1532 {
1533 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1534 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001535 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1536 }
paulfee0f4c2004-09-13 05:12:46 +00001537
Chris Caputo228da422009-07-18 05:44:03 +00001538 bgp_process_announce_selected (rsclient, new_select, rn,
1539 afi, safi);
1540 }
paul200df112005-06-01 11:17:05 +00001541 }
1542 else
1543 {
hassob7395792005-08-26 12:58:38 +00001544 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001545 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001546 if (new_select)
1547 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001548 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1549 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001550 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001551 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001552 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001553 }
paulfee0f4c2004-09-13 05:12:46 +00001554
paulb40d9392005-08-22 22:34:41 +00001555 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1556 bgp_info_reap (rn, old_select);
1557
paul200df112005-06-01 11:17:05 +00001558 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1559 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001560}
1561
paul200df112005-06-01 11:17:05 +00001562static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001563bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001564{
paul0fb58d52005-11-14 14:31:49 +00001565 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001566 struct bgp *bgp = pq->bgp;
1567 struct bgp_node *rn = pq->rn;
1568 afi_t afi = pq->afi;
1569 safi_t safi = pq->safi;
1570 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001571 struct bgp_info *new_select;
1572 struct bgp_info *old_select;
1573 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001574 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001575 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001576
paulfee0f4c2004-09-13 05:12:46 +00001577 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001578 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001579 old_select = old_and_new.old;
1580 new_select = old_and_new.new;
1581
1582 /* Nothing to do. */
1583 if (old_select && old_select == new_select)
1584 {
1585 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001586 {
Josh Bailey8196f132011-07-20 20:47:07 -07001587 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1588 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001589 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001590
Josh Bailey8196f132011-07-20 20:47:07 -07001591 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001592 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1593 return WQ_SUCCESS;
1594 }
paulfee0f4c2004-09-13 05:12:46 +00001595 }
paul718e3742002-12-13 20:15:29 +00001596
hasso338b3422005-02-23 14:27:24 +00001597 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001598 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001599 if (new_select)
1600 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001601 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1602 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001603 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001604 }
1605
1606
paul718e3742002-12-13 20:15:29 +00001607 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001608 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001609 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001610 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001611 }
1612
1613 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001614 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1615 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001616 {
1617 if (new_select
1618 && new_select->type == ZEBRA_ROUTE_BGP
1619 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001620 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001621 else
1622 {
1623 /* Withdraw the route from the kernel. */
1624 if (old_select
1625 && old_select->type == ZEBRA_ROUTE_BGP
1626 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001627 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001628 }
1629 }
paulb40d9392005-08-22 22:34:41 +00001630
1631 /* Reap old select bgp_info, it it has been removed */
1632 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1633 bgp_info_reap (rn, old_select);
1634
paul200df112005-06-01 11:17:05 +00001635 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1636 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001637}
1638
paul200df112005-06-01 11:17:05 +00001639static void
paul0fb58d52005-11-14 14:31:49 +00001640bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001641{
paul0fb58d52005-11-14 14:31:49 +00001642 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001643 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001644
Chris Caputo228da422009-07-18 05:44:03 +00001645 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001646 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001647 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001648 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1649}
1650
1651static void
1652bgp_process_queue_init (void)
1653{
1654 bm->process_main_queue
1655 = work_queue_new (bm->master, "process_main_queue");
1656 bm->process_rsclient_queue
1657 = work_queue_new (bm->master, "process_rsclient_queue");
1658
1659 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1660 {
1661 zlog_err ("%s: Failed to allocate work queue", __func__);
1662 exit (1);
1663 }
1664
1665 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001666 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001667 bm->process_main_queue->spec.max_retries = 0;
1668 bm->process_main_queue->spec.hold = 50;
1669
1670 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1671 sizeof (struct work_queue *));
1672 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001673}
1674
1675void
paulfee0f4c2004-09-13 05:12:46 +00001676bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1677{
paul200df112005-06-01 11:17:05 +00001678 struct bgp_process_queue *pqnode;
1679
1680 /* already scheduled for processing? */
1681 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1682 return;
1683
1684 if ( (bm->process_main_queue == NULL) ||
1685 (bm->process_rsclient_queue == NULL) )
1686 bgp_process_queue_init ();
1687
1688 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1689 sizeof (struct bgp_process_queue));
1690 if (!pqnode)
1691 return;
Chris Caputo228da422009-07-18 05:44:03 +00001692
1693 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001694 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001695 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001696 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001697 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001698 pqnode->afi = afi;
1699 pqnode->safi = safi;
1700
Avneesh Sachdev67174042012-08-17 08:19:49 -07001701 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001702 {
paul200df112005-06-01 11:17:05 +00001703 case BGP_TABLE_MAIN:
1704 work_queue_add (bm->process_main_queue, pqnode);
1705 break;
1706 case BGP_TABLE_RSCLIENT:
1707 work_queue_add (bm->process_rsclient_queue, pqnode);
1708 break;
paulfee0f4c2004-09-13 05:12:46 +00001709 }
paul200df112005-06-01 11:17:05 +00001710
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001711 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001712 return;
paulfee0f4c2004-09-13 05:12:46 +00001713}
hasso0a486e52005-02-01 20:57:17 +00001714
paul94f2b392005-06-28 12:44:16 +00001715static int
hasso0a486e52005-02-01 20:57:17 +00001716bgp_maximum_prefix_restart_timer (struct thread *thread)
1717{
1718 struct peer *peer;
1719
1720 peer = THREAD_ARG (thread);
1721 peer->t_pmax_restart = NULL;
1722
1723 if (BGP_DEBUG (events, EVENTS))
1724 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1725 peer->host);
1726
1727 peer_clear (peer);
1728
1729 return 0;
1730}
1731
paulfee0f4c2004-09-13 05:12:46 +00001732int
paul5228ad22004-06-04 17:58:18 +00001733bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1734 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001735{
hassoe0701b72004-05-20 09:19:34 +00001736 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1737 return 0;
1738
1739 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001740 {
hassoe0701b72004-05-20 09:19:34 +00001741 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1742 && ! always)
1743 return 0;
paul718e3742002-12-13 20:15:29 +00001744
hassoe0701b72004-05-20 09:19:34 +00001745 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001746 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1747 "limit %ld", afi_safi_print (afi, safi), peer->host,
1748 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001749 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001750
hassoe0701b72004-05-20 09:19:34 +00001751 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1752 return 0;
paul718e3742002-12-13 20:15:29 +00001753
hassoe0701b72004-05-20 09:19:34 +00001754 {
paul5228ad22004-06-04 17:58:18 +00001755 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001756
1757 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001758 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001759
1760 ndata[0] = (afi >> 8);
1761 ndata[1] = afi;
1762 ndata[2] = safi;
1763 ndata[3] = (peer->pmax[afi][safi] >> 24);
1764 ndata[4] = (peer->pmax[afi][safi] >> 16);
1765 ndata[5] = (peer->pmax[afi][safi] >> 8);
1766 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001767
1768 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1769 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1770 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1771 }
hasso0a486e52005-02-01 20:57:17 +00001772
1773 /* restart timer start */
1774 if (peer->pmax_restart[afi][safi])
1775 {
1776 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1777
1778 if (BGP_DEBUG (events, EVENTS))
1779 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1780 peer->host, peer->v_pmax_restart);
1781
1782 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1783 peer->v_pmax_restart);
1784 }
1785
hassoe0701b72004-05-20 09:19:34 +00001786 return 1;
paul718e3742002-12-13 20:15:29 +00001787 }
hassoe0701b72004-05-20 09:19:34 +00001788 else
1789 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1790
1791 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1792 {
1793 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1794 && ! always)
1795 return 0;
1796
1797 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001798 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1799 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1800 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001801 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1802 }
1803 else
1804 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001805 return 0;
1806}
1807
paulb40d9392005-08-22 22:34:41 +00001808/* Unconditionally remove the route from the RIB, without taking
1809 * damping into consideration (eg, because the session went down)
1810 */
paul94f2b392005-06-28 12:44:16 +00001811static void
paul718e3742002-12-13 20:15:29 +00001812bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1813 afi_t afi, safi_t safi)
1814{
paul902212c2006-02-05 17:51:19 +00001815 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1816
1817 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1818 bgp_info_delete (rn, ri); /* keep historical info */
1819
paulb40d9392005-08-22 22:34:41 +00001820 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001821}
1822
paul94f2b392005-06-28 12:44:16 +00001823static void
paul718e3742002-12-13 20:15:29 +00001824bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001825 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001826{
paul718e3742002-12-13 20:15:29 +00001827 int status = BGP_DAMP_NONE;
1828
paulb40d9392005-08-22 22:34:41 +00001829 /* apply dampening, if result is suppressed, we'll be retaining
1830 * the bgp_info in the RIB for historical reference.
1831 */
1832 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001833 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001834 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1835 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001836 {
paul902212c2006-02-05 17:51:19 +00001837 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1838 return;
1839 }
1840
1841 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001842}
1843
paul94f2b392005-06-28 12:44:16 +00001844static void
paulfee0f4c2004-09-13 05:12:46 +00001845bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1846 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1847 int sub_type, struct prefix_rd *prd, u_char *tag)
1848{
1849 struct bgp_node *rn;
1850 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001851 struct attr new_attr;
1852 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001853 struct attr *attr_new;
1854 struct attr *attr_new2;
1855 struct bgp_info *ri;
1856 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001857 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001858 char buf[SU_ADDRSTRLEN];
1859
1860 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1861 if (peer == rsclient)
1862 return;
1863
1864 bgp = peer->bgp;
1865 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1866
1867 /* Check previously received route. */
1868 for (ri = rn->info; ri; ri = ri->next)
1869 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1870 break;
1871
1872 /* AS path loop check. */
1873 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1874 {
1875 reason = "as-path contains our own AS;";
1876 goto filtered;
1877 }
1878
1879 /* Route reflector originator ID check. */
1880 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001881 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001882 {
1883 reason = "originator is us;";
1884 goto filtered;
1885 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001886
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001887 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001888 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 /* Apply export policy. */
1891 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1892 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1893 {
1894 reason = "export-policy;";
1895 goto filtered;
1896 }
1897
1898 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001899
paulfee0f4c2004-09-13 05:12:46 +00001900 /* Apply import policy. */
1901 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1902 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001903 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001904
1905 reason = "import-policy;";
1906 goto filtered;
1907 }
1908
1909 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001910 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001911
1912 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001913 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001914 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001915 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001916 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001917 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001918 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001919 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 reason = "martian next-hop;";
1922 goto filtered;
1923 }
1924 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001925
paulfee0f4c2004-09-13 05:12:46 +00001926 /* If the update is implicit withdraw. */
1927 if (ri)
1928 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001929 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001930
1931 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001932 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1933 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001934 {
1935
Paul Jakma1a392d42006-09-07 00:24:49 +00001936 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001937
1938 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001939 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001940 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1941 peer->host,
1942 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1943 p->prefixlen, rsclient->host);
1944
Chris Caputo228da422009-07-18 05:44:03 +00001945 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001946 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001947
Chris Caputo228da422009-07-18 05:44:03 +00001948 return;
paulfee0f4c2004-09-13 05:12:46 +00001949 }
1950
Paul Jakma16d2e242007-04-10 19:32:10 +00001951 /* Withdraw/Announce before we fully processed the withdraw */
1952 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1953 bgp_info_restore (rn, ri);
1954
paulfee0f4c2004-09-13 05:12:46 +00001955 /* Received Logging. */
1956 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001957 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001958 peer->host,
1959 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1960 p->prefixlen, rsclient->host);
1961
1962 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001963 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001964
1965 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001966 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001967 ri->attr = attr_new;
1968
1969 /* Update MPLS tag. */
1970 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001971 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001972
Paul Jakma1a392d42006-09-07 00:24:49 +00001973 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001974
1975 /* Process change. */
1976 bgp_process (bgp, rn, afi, safi);
1977 bgp_unlock_node (rn);
1978
1979 return;
1980 }
1981
1982 /* Received Logging. */
1983 if (BGP_DEBUG (update, UPDATE_IN))
1984 {
ajsd2c1f162004-12-08 21:10:20 +00001985 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001986 peer->host,
1987 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1988 p->prefixlen, rsclient->host);
1989 }
1990
1991 /* Make new BGP info. */
1992 new = bgp_info_new ();
1993 new->type = type;
1994 new->sub_type = sub_type;
1995 new->peer = peer;
1996 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001997 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001998
1999 /* Update MPLS tag. */
2000 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002001 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002002
Paul Jakma1a392d42006-09-07 00:24:49 +00002003 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002004
2005 /* Register new BGP information. */
2006 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002007
2008 /* route_node_get lock */
2009 bgp_unlock_node (rn);
2010
paulfee0f4c2004-09-13 05:12:46 +00002011 /* Process change. */
2012 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002013
paulfee0f4c2004-09-13 05:12:46 +00002014 return;
2015
2016 filtered:
2017
2018 /* This BGP update is filtered. Log the reason then update BGP entry. */
2019 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002020 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002021 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2022 peer->host,
2023 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2024 p->prefixlen, rsclient->host, reason);
2025
2026 if (ri)
paulb40d9392005-08-22 22:34:41 +00002027 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002028
2029 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002030
paulfee0f4c2004-09-13 05:12:46 +00002031 return;
2032}
2033
paul94f2b392005-06-28 12:44:16 +00002034static void
paulfee0f4c2004-09-13 05:12:46 +00002035bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2036 struct peer *peer, struct prefix *p, int type, int sub_type,
2037 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002038{
paulfee0f4c2004-09-13 05:12:46 +00002039 struct bgp_node *rn;
2040 struct bgp_info *ri;
2041 char buf[SU_ADDRSTRLEN];
2042
2043 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002044 return;
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2047
2048 /* Lookup withdrawn route. */
2049 for (ri = rn->info; ri; ri = ri->next)
2050 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2051 break;
2052
2053 /* Withdraw specified route from routing table. */
2054 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002055 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002056 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002057 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002058 "%s Can't find the route %s/%d", peer->host,
2059 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2060 p->prefixlen);
2061
2062 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002063 bgp_unlock_node (rn);
2064}
paulfee0f4c2004-09-13 05:12:46 +00002065
paul94f2b392005-06-28 12:44:16 +00002066static int
paulfee0f4c2004-09-13 05:12:46 +00002067bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002068 afi_t afi, safi_t safi, int type, int sub_type,
2069 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2070{
2071 int ret;
2072 int aspath_loop_count = 0;
2073 struct bgp_node *rn;
2074 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075 struct attr new_attr;
2076 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002077 struct attr *attr_new;
2078 struct bgp_info *ri;
2079 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002080 const char *reason;
paul718e3742002-12-13 20:15:29 +00002081 char buf[SU_ADDRSTRLEN];
2082
2083 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002084 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002085
paul718e3742002-12-13 20:15:29 +00002086 /* When peer's soft reconfiguration enabled. Record input packet in
2087 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002088 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2089 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002090 bgp_adj_in_set (rn, peer, attr);
2091
2092 /* Check previously received route. */
2093 for (ri = rn->info; ri; ri = ri->next)
2094 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2095 break;
2096
2097 /* AS path local-as loop check. */
2098 if (peer->change_local_as)
2099 {
2100 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2101 aspath_loop_count = 1;
2102
2103 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2104 {
2105 reason = "as-path contains our own AS;";
2106 goto filtered;
2107 }
2108 }
2109
2110 /* AS path loop check. */
2111 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2112 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2113 && aspath_loop_check(attr->aspath, bgp->confed_id)
2114 > peer->allowas_in[afi][safi]))
2115 {
2116 reason = "as-path contains our own AS;";
2117 goto filtered;
2118 }
2119
2120 /* Route reflector originator ID check. */
2121 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002122 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002123 {
2124 reason = "originator is us;";
2125 goto filtered;
2126 }
2127
2128 /* Route reflector cluster ID check. */
2129 if (bgp_cluster_filter (peer, attr))
2130 {
2131 reason = "reflected from the same cluster;";
2132 goto filtered;
2133 }
2134
2135 /* Apply incoming filter. */
2136 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2137 {
2138 reason = "filter;";
2139 goto filtered;
2140 }
2141
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002142 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002143 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002144
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002145 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002146 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2147 {
2148 reason = "route-map;";
2149 goto filtered;
2150 }
2151
2152 /* IPv4 unicast next hop check. */
2153 if (afi == AFI_IP && safi == SAFI_UNICAST)
2154 {
2155 /* If the peer is EBGP and nexthop is not on connected route,
2156 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002157 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002158 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002159 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002160 {
2161 reason = "non-connected next-hop;";
2162 goto filtered;
2163 }
2164
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002165 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002166 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002167 if (new_attr.nexthop.s_addr == 0
2168 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2169 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002170 {
2171 reason = "martian next-hop;";
2172 goto filtered;
2173 }
2174 }
2175
2176 attr_new = bgp_attr_intern (&new_attr);
2177
2178 /* If the update is implicit withdraw. */
2179 if (ri)
2180 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002181 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002182
2183 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002184 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2185 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002186 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002187 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002188
2189 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002190 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002191 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2192 {
2193 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002194 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002195 peer->host,
2196 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2197 p->prefixlen);
2198
paul902212c2006-02-05 17:51:19 +00002199 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2200 {
2201 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2202 bgp_process (bgp, rn, afi, safi);
2203 }
paul718e3742002-12-13 20:15:29 +00002204 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002205 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002206 {
2207 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002208 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002209 "%s rcvd %s/%d...duplicate ignored",
2210 peer->host,
2211 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2212 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002213
2214 /* graceful restart STALE flag unset. */
2215 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2216 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002217 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002218 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002219 }
paul718e3742002-12-13 20:15:29 +00002220 }
2221
2222 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002223 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002224
paul718e3742002-12-13 20:15:29 +00002225 return 0;
2226 }
2227
Paul Jakma16d2e242007-04-10 19:32:10 +00002228 /* Withdraw/Announce before we fully processed the withdraw */
2229 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2230 {
2231 if (BGP_DEBUG (update, UPDATE_IN))
2232 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2233 peer->host,
2234 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2235 p->prefixlen);
2236 bgp_info_restore (rn, ri);
2237 }
2238
paul718e3742002-12-13 20:15:29 +00002239 /* Received Logging. */
2240 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002241 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002242 peer->host,
2243 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2244 p->prefixlen);
2245
hasso93406d82005-02-02 14:40:33 +00002246 /* graceful restart STALE flag unset. */
2247 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002248 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002249
paul718e3742002-12-13 20:15:29 +00002250 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002251 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002252
2253 /* implicit withdraw, decrement aggregate and pcount here.
2254 * only if update is accepted, they'll increment below.
2255 */
paul902212c2006-02-05 17:51:19 +00002256 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2257
paul718e3742002-12-13 20:15:29 +00002258 /* Update bgp route dampening information. */
2259 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002260 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002261 {
2262 /* This is implicit withdraw so we should update dampening
2263 information. */
2264 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2265 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002266 }
2267
paul718e3742002-12-13 20:15:29 +00002268 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002269 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002270 ri->attr = attr_new;
2271
2272 /* Update MPLS tag. */
2273 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002274 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002275
2276 /* Update bgp route dampening information. */
2277 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002278 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002279 {
2280 /* Now we do normal update dampening. */
2281 ret = bgp_damp_update (ri, rn, afi, safi);
2282 if (ret == BGP_DAMP_SUPPRESSED)
2283 {
2284 bgp_unlock_node (rn);
2285 return 0;
2286 }
2287 }
2288
2289 /* Nexthop reachability check. */
2290 if ((afi == AFI_IP || afi == AFI_IP6)
2291 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002292 && (peer->sort == BGP_PEER_IBGP
2293 || peer->sort == BGP_PEER_CONFED
2294 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002295 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002296 {
2297 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002298 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002299 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002300 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002301 }
2302 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002303 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002304
2305 /* Process change. */
2306 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2307
2308 bgp_process (bgp, rn, afi, safi);
2309 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002310
paul718e3742002-12-13 20:15:29 +00002311 return 0;
2312 }
2313
2314 /* Received Logging. */
2315 if (BGP_DEBUG (update, UPDATE_IN))
2316 {
ajsd2c1f162004-12-08 21:10:20 +00002317 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002318 peer->host,
2319 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2320 p->prefixlen);
2321 }
2322
paul718e3742002-12-13 20:15:29 +00002323 /* Make new BGP info. */
2324 new = bgp_info_new ();
2325 new->type = type;
2326 new->sub_type = sub_type;
2327 new->peer = peer;
2328 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002329 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002330
2331 /* Update MPLS tag. */
2332 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002333 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002334
2335 /* Nexthop reachability check. */
2336 if ((afi == AFI_IP || afi == AFI_IP6)
2337 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002338 && (peer->sort == BGP_PEER_IBGP
2339 || peer->sort == BGP_PEER_CONFED
2340 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002341 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002342 {
2343 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002344 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002345 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002346 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002347 }
2348 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002349 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002350
paul902212c2006-02-05 17:51:19 +00002351 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002352 bgp_aggregate_increment (bgp, p, new, afi, safi);
2353
2354 /* Register new BGP information. */
2355 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002356
2357 /* route_node_get lock */
2358 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002359
paul718e3742002-12-13 20:15:29 +00002360 /* If maximum prefix count is configured and current prefix
2361 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002362 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2363 return -1;
paul718e3742002-12-13 20:15:29 +00002364
2365 /* Process change. */
2366 bgp_process (bgp, rn, afi, safi);
2367
2368 return 0;
2369
2370 /* This BGP update is filtered. Log the reason then update BGP
2371 entry. */
2372 filtered:
2373 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002374 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002375 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2376 peer->host,
2377 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2378 p->prefixlen, reason);
2379
2380 if (ri)
paulb40d9392005-08-22 22:34:41 +00002381 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002382
2383 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002384
paul718e3742002-12-13 20:15:29 +00002385 return 0;
2386}
2387
2388int
paulfee0f4c2004-09-13 05:12:46 +00002389bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2390 afi_t afi, safi_t safi, int type, int sub_type,
2391 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2392{
2393 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002394 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002395 struct bgp *bgp;
2396 int ret;
2397
2398 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2399 soft_reconfig);
2400
2401 bgp = peer->bgp;
2402
2403 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002404 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002405 {
2406 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2407 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2408 sub_type, prd, tag);
2409 }
2410
2411 return ret;
2412}
2413
2414int
paul718e3742002-12-13 20:15:29 +00002415bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002416 afi_t afi, safi_t safi, int type, int sub_type,
2417 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002418{
2419 struct bgp *bgp;
2420 char buf[SU_ADDRSTRLEN];
2421 struct bgp_node *rn;
2422 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002423 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002424 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002425
2426 bgp = peer->bgp;
2427
paulfee0f4c2004-09-13 05:12:46 +00002428 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002429 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002430 {
2431 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2432 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2433 }
2434
paul718e3742002-12-13 20:15:29 +00002435 /* Logging. */
2436 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002437 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002438 peer->host,
2439 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2440 p->prefixlen);
2441
2442 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002443 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002444
2445 /* If peer is soft reconfiguration enabled. Record input packet for
2446 further calculation. */
2447 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2448 && peer != bgp->peer_self)
2449 bgp_adj_in_unset (rn, peer);
2450
2451 /* Lookup withdrawn route. */
2452 for (ri = rn->info; ri; ri = ri->next)
2453 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2454 break;
2455
2456 /* Withdraw specified route from routing table. */
2457 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002458 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002459 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002460 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002461 "%s Can't find the route %s/%d", peer->host,
2462 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2463 p->prefixlen);
2464
2465 /* Unlock bgp_node_get() lock. */
2466 bgp_unlock_node (rn);
2467
2468 return 0;
2469}
2470
2471void
2472bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2473{
2474 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002475 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002476 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002477 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002478 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002479 struct bgp_node *rn;
2480 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002481 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002482
Paul Jakmab2497022007-06-14 11:17:58 +00002483 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002484 return;
2485
paul718e3742002-12-13 20:15:29 +00002486 bgp = peer->bgp;
2487 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002488
paul718e3742002-12-13 20:15:29 +00002489 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2490 aspath = attr.aspath;
2491 attr.local_pref = bgp->default_local_pref;
2492 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2493
2494 if (afi == AFI_IP)
2495 str2prefix ("0.0.0.0/0", &p);
2496#ifdef HAVE_IPV6
2497 else if (afi == AFI_IP6)
2498 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002499 struct attr_extra *ae = attr.extra;
2500
paul718e3742002-12-13 20:15:29 +00002501 str2prefix ("::/0", &p);
2502
2503 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002504 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002505 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002506 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002507
2508 /* If the peer is on shared nextwork and we have link-local
2509 nexthop set it. */
2510 if (peer->shared_network
2511 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2512 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002513 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002514 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002515 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002516 }
2517 }
2518#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002519
2520 if (peer->default_rmap[afi][safi].name)
2521 {
paulfee0f4c2004-09-13 05:12:46 +00002522 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002523 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2524 {
2525 for (ri = rn->info; ri; ri = ri->next)
2526 {
2527 struct attr dummy_attr;
2528 struct attr_extra dummy_extra;
2529 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002530
Christian Frankedcab1bb2012-12-07 16:45:52 +00002531 /* Provide dummy so the route-map can't modify the attributes */
2532 dummy_attr.extra = &dummy_extra;
2533 bgp_attr_dup(&dummy_attr, ri->attr);
2534 info.peer = ri->peer;
2535 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002536
Christian Frankedcab1bb2012-12-07 16:45:52 +00002537 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2538 RMAP_BGP, &info);
2539
2540 /* The route map might have set attributes. If we don't flush them
2541 * here, they will be leaked. */
2542 bgp_attr_flush(&dummy_attr);
2543 if (ret != RMAP_DENYMATCH)
2544 break;
2545 }
2546 if (ret != RMAP_DENYMATCH)
2547 break;
2548 }
paulfee0f4c2004-09-13 05:12:46 +00002549 bgp->peer_self->rmap_type = 0;
2550
paul718e3742002-12-13 20:15:29 +00002551 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002552 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002553 }
2554
2555 if (withdraw)
2556 {
2557 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2558 bgp_default_withdraw_send (peer, afi, safi);
2559 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2560 }
2561 else
2562 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002563 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2564 {
2565 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2566 bgp_default_update_send (peer, &attr, afi, safi, from);
2567 }
paul718e3742002-12-13 20:15:29 +00002568 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002569
2570 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002571 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002572}
2573
2574static void
2575bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002576 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002577{
2578 struct bgp_node *rn;
2579 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002580 struct attr attr;
2581 struct attr_extra extra;
2582
paul718e3742002-12-13 20:15:29 +00002583 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002584 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002585
2586 if (safi != SAFI_MPLS_VPN
2587 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2588 bgp_default_originate (peer, afi, safi, 0);
2589
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002590 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2591 attr.extra = &extra;
2592
paul718e3742002-12-13 20:15:29 +00002593 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2594 for (ri = rn->info; ri; ri = ri->next)
2595 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2596 {
paulfee0f4c2004-09-13 05:12:46 +00002597 if ( (rsclient) ?
2598 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2599 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002600 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2601 else
2602 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2603 }
2604}
2605
2606void
2607bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2608{
2609 struct bgp_node *rn;
2610 struct bgp_table *table;
2611
2612 if (peer->status != Established)
2613 return;
2614
2615 if (! peer->afc_nego[afi][safi])
2616 return;
2617
2618 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2619 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2620 return;
2621
2622 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002623 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002624 else
2625 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2626 rn = bgp_route_next(rn))
2627 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002628 bgp_announce_table (peer, afi, safi, table, 0);
2629
2630 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2631 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002632}
2633
2634void
2635bgp_announce_route_all (struct peer *peer)
2636{
2637 afi_t afi;
2638 safi_t safi;
2639
2640 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2641 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2642 bgp_announce_route (peer, afi, safi);
2643}
2644
2645static void
paulfee0f4c2004-09-13 05:12:46 +00002646bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002647 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002648{
2649 struct bgp_node *rn;
2650 struct bgp_adj_in *ain;
2651
2652 if (! table)
2653 table = rsclient->bgp->rib[afi][safi];
2654
2655 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2656 for (ain = rn->adj_in; ain; ain = ain->next)
2657 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002658 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002659 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002660
paulfee0f4c2004-09-13 05:12:46 +00002661 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002662 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002663 }
2664}
2665
2666void
2667bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2668{
2669 struct bgp_table *table;
2670 struct bgp_node *rn;
2671
2672 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002673 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002674
2675 else
2676 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2677 rn = bgp_route_next (rn))
2678 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002679 {
2680 struct prefix_rd prd;
2681 prd.family = AF_UNSPEC;
2682 prd.prefixlen = 64;
2683 memcpy(&prd.val, rn->p.u.val, 8);
2684
2685 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2686 }
paulfee0f4c2004-09-13 05:12:46 +00002687}
2688
2689static void
paul718e3742002-12-13 20:15:29 +00002690bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002691 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002692{
2693 int ret;
2694 struct bgp_node *rn;
2695 struct bgp_adj_in *ain;
2696
2697 if (! table)
2698 table = peer->bgp->rib[afi][safi];
2699
2700 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2701 for (ain = rn->adj_in; ain; ain = ain->next)
2702 {
2703 if (ain->peer == peer)
2704 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002705 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002706 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707
paul718e3742002-12-13 20:15:29 +00002708 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2709 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002710 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002711
paul718e3742002-12-13 20:15:29 +00002712 if (ret < 0)
2713 {
2714 bgp_unlock_node (rn);
2715 return;
2716 }
2717 continue;
2718 }
2719 }
2720}
2721
2722void
2723bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2724{
2725 struct bgp_node *rn;
2726 struct bgp_table *table;
2727
2728 if (peer->status != Established)
2729 return;
2730
2731 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002732 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002733 else
2734 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2735 rn = bgp_route_next (rn))
2736 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737 {
2738 struct prefix_rd prd;
2739 prd.family = AF_UNSPEC;
2740 prd.prefixlen = 64;
2741 memcpy(&prd.val, rn->p.u.val, 8);
2742
2743 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2744 }
paul718e3742002-12-13 20:15:29 +00002745}
2746
Chris Caputo228da422009-07-18 05:44:03 +00002747
2748struct bgp_clear_node_queue
2749{
2750 struct bgp_node *rn;
2751 enum bgp_clear_route_type purpose;
2752};
2753
paul200df112005-06-01 11:17:05 +00002754static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002755bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002756{
Chris Caputo228da422009-07-18 05:44:03 +00002757 struct bgp_clear_node_queue *cnq = data;
2758 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002759 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002760 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002761 afi_t afi = bgp_node_table (rn)->afi;
2762 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002763
Paul Jakma64e580a2006-02-21 01:09:01 +00002764 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002765
Paul Jakma64e580a2006-02-21 01:09:01 +00002766 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002767 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002768 {
2769 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002770 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2771 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002772 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002773 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2774 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002775 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002776 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002777 break;
2778 }
paul200df112005-06-01 11:17:05 +00002779 return WQ_SUCCESS;
2780}
2781
2782static void
paul0fb58d52005-11-14 14:31:49 +00002783bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002784{
Chris Caputo228da422009-07-18 05:44:03 +00002785 struct bgp_clear_node_queue *cnq = data;
2786 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002787 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002788
2789 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002790 bgp_table_unlock (table);
2791 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002792}
2793
2794static void
paul94f2b392005-06-28 12:44:16 +00002795bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002796{
Paul Jakma64e580a2006-02-21 01:09:01 +00002797 struct peer *peer = wq->spec.data;
2798
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002799 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002800 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002801
2802 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002803}
2804
2805static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002806bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002807{
Paul Jakmaa2943652009-07-21 14:02:04 +01002808 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002809
Paul Jakmaa2943652009-07-21 14:02:04 +01002810 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002811#undef CLEAR_QUEUE_NAME_LEN
2812
2813 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002814 {
2815 zlog_err ("%s: Failed to allocate work queue", __func__);
2816 exit (1);
2817 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002818 peer->clear_node_queue->spec.hold = 10;
2819 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2820 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2821 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2822 peer->clear_node_queue->spec.max_retries = 0;
2823
2824 /* we only 'lock' this peer reference when the queue is actually active */
2825 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002826}
2827
paul718e3742002-12-13 20:15:29 +00002828static void
2829bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002830 struct bgp_table *table, struct peer *rsclient,
2831 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002832{
2833 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002834
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002835
paul718e3742002-12-13 20:15:29 +00002836 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002837 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002838
hasso6cf159b2005-03-21 10:28:14 +00002839 /* If still no table => afi/safi isn't configured at all or smth. */
2840 if (! table)
2841 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002842
2843 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2844 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002845 struct bgp_info *ri;
2846 struct bgp_adj_in *ain;
2847 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002848
2849 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2850 * queued for every clearing peer, regardless of whether it is
2851 * relevant to the peer at hand.
2852 *
2853 * Overview: There are 3 different indices which need to be
2854 * scrubbed, potentially, when a peer is removed:
2855 *
2856 * 1 peer's routes visible via the RIB (ie accepted routes)
2857 * 2 peer's routes visible by the (optional) peer's adj-in index
2858 * 3 other routes visible by the peer's adj-out index
2859 *
2860 * 3 there is no hurry in scrubbing, once the struct peer is
2861 * removed from bgp->peer, we could just GC such deleted peer's
2862 * adj-outs at our leisure.
2863 *
2864 * 1 and 2 must be 'scrubbed' in some way, at least made
2865 * invisible via RIB index before peer session is allowed to be
2866 * brought back up. So one needs to know when such a 'search' is
2867 * complete.
2868 *
2869 * Ideally:
2870 *
2871 * - there'd be a single global queue or a single RIB walker
2872 * - rather than tracking which route_nodes still need to be
2873 * examined on a peer basis, we'd track which peers still
2874 * aren't cleared
2875 *
2876 * Given that our per-peer prefix-counts now should be reliable,
2877 * this may actually be achievable. It doesn't seem to be a huge
2878 * problem at this time,
2879 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002880 for (ain = rn->adj_in; ain; ain = ain->next)
2881 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2882 {
2883 bgp_adj_in_remove (rn, ain);
2884 bgp_unlock_node (rn);
2885 break;
2886 }
2887 for (aout = rn->adj_out; aout; aout = aout->next)
2888 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2889 {
2890 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2891 bgp_unlock_node (rn);
2892 break;
2893 }
2894
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002895 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002896 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897 {
Chris Caputo228da422009-07-18 05:44:03 +00002898 struct bgp_clear_node_queue *cnq;
2899
2900 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002901 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002902 bgp_lock_node (rn);
2903 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2904 sizeof (struct bgp_clear_node_queue));
2905 cnq->rn = rn;
2906 cnq->purpose = purpose;
2907 work_queue_add (peer->clear_node_queue, cnq);
2908 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002909 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002910 }
2911 return;
2912}
2913
2914void
Chris Caputo228da422009-07-18 05:44:03 +00002915bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2916 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002917{
2918 struct bgp_node *rn;
2919 struct bgp_table *table;
2920 struct peer *rsclient;
2921 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002922
Paul Jakma64e580a2006-02-21 01:09:01 +00002923 if (peer->clear_node_queue == NULL)
2924 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002925
Paul Jakmaca058a32006-09-14 02:58:49 +00002926 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2927 * Idle until it receives a Clearing_Completed event. This protects
2928 * against peers which flap faster than we can we clear, which could
2929 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002930 *
2931 * a) race with routes from the new session being installed before
2932 * clear_route_node visits the node (to delete the route of that
2933 * peer)
2934 * b) resource exhaustion, clear_route_node likely leads to an entry
2935 * on the process_main queue. Fast-flapping could cause that queue
2936 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002937 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002938 if (!peer->clear_node_queue->thread)
2939 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002940
Chris Caputo228da422009-07-18 05:44:03 +00002941 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002942 {
Chris Caputo228da422009-07-18 05:44:03 +00002943 case BGP_CLEAR_ROUTE_NORMAL:
2944 if (safi != SAFI_MPLS_VPN)
2945 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2946 else
2947 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2948 rn = bgp_route_next (rn))
2949 if ((table = rn->info) != NULL)
2950 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2951
2952 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2953 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2954 PEER_FLAG_RSERVER_CLIENT))
2955 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2956 break;
2957
2958 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2959 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2960 break;
2961
2962 default:
2963 assert (0);
2964 break;
paulfee0f4c2004-09-13 05:12:46 +00002965 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002966
Paul Jakmaca058a32006-09-14 02:58:49 +00002967 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002968 * completion function won't be run by workqueue code - call it here.
2969 * XXX: Actually, this assumption doesn't hold, see
2970 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002971 *
2972 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002973 * really needed if peer state is Established - peers in
2974 * pre-Established states shouldn't have any route-update state
2975 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002976 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002977 * We still can get here in pre-Established though, through
2978 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2979 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002980 *
2981 * At some future point, this check could be move to the top of the
2982 * function, and do a quick early-return when state is
2983 * pre-Established, avoiding above list and table scans. Once we're
2984 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002985 */
2986 if (!peer->clear_node_queue->thread)
2987 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002988}
2989
2990void
2991bgp_clear_route_all (struct peer *peer)
2992{
2993 afi_t afi;
2994 safi_t safi;
2995
2996 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2997 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002998 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002999}
3000
3001void
3002bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3003{
3004 struct bgp_table *table;
3005 struct bgp_node *rn;
3006 struct bgp_adj_in *ain;
3007
3008 table = peer->bgp->rib[afi][safi];
3009
3010 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3011 for (ain = rn->adj_in; ain ; ain = ain->next)
3012 if (ain->peer == peer)
3013 {
3014 bgp_adj_in_remove (rn, ain);
3015 bgp_unlock_node (rn);
3016 break;
3017 }
3018}
hasso93406d82005-02-02 14:40:33 +00003019
3020void
3021bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3022{
3023 struct bgp_node *rn;
3024 struct bgp_info *ri;
3025 struct bgp_table *table;
3026
3027 table = peer->bgp->rib[afi][safi];
3028
3029 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3030 {
3031 for (ri = rn->info; ri; ri = ri->next)
3032 if (ri->peer == peer)
3033 {
3034 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3035 bgp_rib_remove (rn, ri, peer, afi, safi);
3036 break;
3037 }
3038 }
3039}
paul718e3742002-12-13 20:15:29 +00003040
3041/* Delete all kernel routes. */
3042void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003043bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003044{
3045 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003046 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003047 struct bgp_node *rn;
3048 struct bgp_table *table;
3049 struct bgp_info *ri;
3050
paul1eb8ef22005-04-07 07:30:20 +00003051 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003052 {
3053 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3054
3055 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3056 for (ri = rn->info; ri; ri = ri->next)
3057 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3058 && ri->type == ZEBRA_ROUTE_BGP
3059 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003060 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003061
3062 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3063
3064 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3065 for (ri = rn->info; ri; ri = ri->next)
3066 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3067 && ri->type == ZEBRA_ROUTE_BGP
3068 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003069 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003070 }
3071}
3072
3073void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003074bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003075{
3076 vty_reset ();
3077 bgp_zclient_reset ();
3078 access_list_reset ();
3079 prefix_list_reset ();
3080}
3081
3082/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3083 value. */
3084int
3085bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3086{
3087 u_char *pnt;
3088 u_char *lim;
3089 struct prefix p;
3090 int psize;
3091 int ret;
3092
3093 /* Check peer status. */
3094 if (peer->status != Established)
3095 return 0;
3096
3097 pnt = packet->nlri;
3098 lim = pnt + packet->length;
3099
3100 for (; pnt < lim; pnt += psize)
3101 {
3102 /* Clear prefix structure. */
3103 memset (&p, 0, sizeof (struct prefix));
3104
3105 /* Fetch prefix length. */
3106 p.prefixlen = *pnt++;
3107 p.family = afi2family (packet->afi);
3108
3109 /* Already checked in nlri_sanity_check(). We do double check
3110 here. */
3111 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3112 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3113 return -1;
3114
3115 /* Packet size overflow check. */
3116 psize = PSIZE (p.prefixlen);
3117
3118 /* When packet overflow occur return immediately. */
3119 if (pnt + psize > lim)
3120 return -1;
3121
3122 /* Fetch prefix from NLRI packet. */
3123 memcpy (&p.u.prefix, pnt, psize);
3124
3125 /* Check address. */
3126 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3127 {
3128 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3129 {
paulf5ba3872004-07-09 12:11:31 +00003130 /*
3131 * From draft-ietf-idr-bgp4-22, Section 6.3:
3132 * If a BGP router receives an UPDATE message with a
3133 * semantically incorrect NLRI field, in which a prefix is
3134 * semantically incorrect (eg. an unexpected multicast IP
3135 * address), it should ignore the prefix.
3136 */
paul718e3742002-12-13 20:15:29 +00003137 zlog (peer->log, LOG_ERR,
3138 "IPv4 unicast NLRI is multicast address %s",
3139 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003140
paul718e3742002-12-13 20:15:29 +00003141 return -1;
3142 }
3143 }
3144
3145#ifdef HAVE_IPV6
3146 /* Check address. */
3147 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3148 {
3149 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3150 {
3151 char buf[BUFSIZ];
3152
3153 zlog (peer->log, LOG_WARNING,
3154 "IPv6 link-local NLRI received %s ignore this NLRI",
3155 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3156
3157 continue;
3158 }
3159 }
3160#endif /* HAVE_IPV6 */
3161
3162 /* Normal process. */
3163 if (attr)
3164 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3165 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3166 else
3167 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3168 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3169
3170 /* Address family configuration mismatch or maximum-prefix count
3171 overflow. */
3172 if (ret < 0)
3173 return -1;
3174 }
3175
3176 /* Packet length consistency check. */
3177 if (pnt != lim)
3178 return -1;
3179
3180 return 0;
3181}
3182
3183/* NLRI encode syntax check routine. */
3184int
3185bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3186 bgp_size_t length)
3187{
3188 u_char *end;
3189 u_char prefixlen;
3190 int psize;
3191
3192 end = pnt + length;
3193
3194 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3195 syntactic validity. If the field is syntactically incorrect,
3196 then the Error Subcode is set to Invalid Network Field. */
3197
3198 while (pnt < end)
3199 {
3200 prefixlen = *pnt++;
3201
3202 /* Prefix length check. */
3203 if ((afi == AFI_IP && prefixlen > 32)
3204 || (afi == AFI_IP6 && prefixlen > 128))
3205 {
3206 plog_err (peer->log,
3207 "%s [Error] Update packet error (wrong prefix length %d)",
3208 peer->host, prefixlen);
3209 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3210 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3211 return -1;
3212 }
3213
3214 /* Packet size overflow check. */
3215 psize = PSIZE (prefixlen);
3216
3217 if (pnt + psize > end)
3218 {
3219 plog_err (peer->log,
3220 "%s [Error] Update packet error"
3221 " (prefix data overflow prefix size is %d)",
3222 peer->host, psize);
3223 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3224 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3225 return -1;
3226 }
3227
3228 pnt += psize;
3229 }
3230
3231 /* Packet length consistency check. */
3232 if (pnt != end)
3233 {
3234 plog_err (peer->log,
3235 "%s [Error] Update packet error"
3236 " (prefix length mismatch with total length)",
3237 peer->host);
3238 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3239 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3240 return -1;
3241 }
3242 return 0;
3243}
3244
paul94f2b392005-06-28 12:44:16 +00003245static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003246bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003247{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003248 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003249}
3250
paul94f2b392005-06-28 12:44:16 +00003251static void
paul718e3742002-12-13 20:15:29 +00003252bgp_static_free (struct bgp_static *bgp_static)
3253{
3254 if (bgp_static->rmap.name)
3255 free (bgp_static->rmap.name);
3256 XFREE (MTYPE_BGP_STATIC, bgp_static);
3257}
3258
paul94f2b392005-06-28 12:44:16 +00003259static void
paulfee0f4c2004-09-13 05:12:46 +00003260bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3261 struct prefix *p, afi_t afi, safi_t safi)
3262{
3263 struct bgp_node *rn;
3264 struct bgp_info *ri;
3265
3266 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3267
3268 /* Check selected route and self inserted route. */
3269 for (ri = rn->info; ri; ri = ri->next)
3270 if (ri->peer == bgp->peer_self
3271 && ri->type == ZEBRA_ROUTE_BGP
3272 && ri->sub_type == BGP_ROUTE_STATIC)
3273 break;
3274
3275 /* Withdraw static BGP route from routing table. */
3276 if (ri)
3277 {
paulfee0f4c2004-09-13 05:12:46 +00003278 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003279 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003280 }
3281
3282 /* Unlock bgp_node_lookup. */
3283 bgp_unlock_node (rn);
3284}
3285
paul94f2b392005-06-28 12:44:16 +00003286static void
paulfee0f4c2004-09-13 05:12:46 +00003287bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003288 struct bgp_static *bgp_static,
3289 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003290{
3291 struct bgp_node *rn;
3292 struct bgp_info *ri;
3293 struct bgp_info *new;
3294 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003295 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003296 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003297 struct attr new_attr;
3298 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003299 struct bgp *bgp;
3300 int ret;
3301 char buf[SU_ADDRSTRLEN];
3302
3303 bgp = rsclient->bgp;
3304
Paul Jakma06e110f2006-05-12 23:29:22 +00003305 assert (bgp_static);
3306 if (!bgp_static)
3307 return;
3308
paulfee0f4c2004-09-13 05:12:46 +00003309 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3310
3311 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003312
3313 attr.nexthop = bgp_static->igpnexthop;
3314 attr.med = bgp_static->igpmetric;
3315 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003316
Paul Jakma41367172007-08-06 15:24:51 +00003317 if (bgp_static->atomic)
3318 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3319
paulfee0f4c2004-09-13 05:12:46 +00003320 /* Apply network route-map for export to this rsclient. */
3321 if (bgp_static->rmap.name)
3322 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003323 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003324 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003325 info.attr = &attr_tmp;
3326
paulfee0f4c2004-09-13 05:12:46 +00003327 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3328 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3329
3330 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3331
3332 rsclient->rmap_type = 0;
3333
3334 if (ret == RMAP_DENYMATCH)
3335 {
3336 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003337 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003338
3339 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003340 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003341 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003342 bgp_attr_extra_free (&attr);
3343
paulfee0f4c2004-09-13 05:12:46 +00003344 return;
3345 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003347 }
3348 else
3349 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003350
3351 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003352 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003353
paulfee0f4c2004-09-13 05:12:46 +00003354 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3355
Paul Jakmafb982c22007-05-04 20:15:47 +00003356 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3357 == RMAP_DENY)
3358 {
paulfee0f4c2004-09-13 05:12:46 +00003359 /* This BGP update is filtered. Log the reason then update BGP entry. */
3360 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003361 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003362 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3363 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3364 p->prefixlen, rsclient->host);
3365
3366 bgp->peer_self->rmap_type = 0;
3367
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003368 bgp_attr_unintern (&attr_new);
3369 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003370 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003371
3372 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3373
3374 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003375 }
paulfee0f4c2004-09-13 05:12:46 +00003376
3377 bgp->peer_self->rmap_type = 0;
3378
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003379 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003380 attr_new = bgp_attr_intern (&new_attr);
3381
3382 for (ri = rn->info; ri; ri = ri->next)
3383 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3384 && ri->sub_type == BGP_ROUTE_STATIC)
3385 break;
3386
3387 if (ri)
3388 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003389 if (attrhash_cmp (ri->attr, attr_new) &&
3390 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003391 {
3392 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003393 bgp_attr_unintern (&attr_new);
3394 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003395 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003396 return;
3397 }
3398 else
3399 {
3400 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003401 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003402
3403 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003404 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3405 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003406 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003407 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003408 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003409
3410 /* Process change. */
3411 bgp_process (bgp, rn, afi, safi);
3412 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003413 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003414 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003415 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 }
paulfee0f4c2004-09-13 05:12:46 +00003417 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003418
paulfee0f4c2004-09-13 05:12:46 +00003419 /* Make new BGP info. */
3420 new = bgp_info_new ();
3421 new->type = ZEBRA_ROUTE_BGP;
3422 new->sub_type = BGP_ROUTE_STATIC;
3423 new->peer = bgp->peer_self;
3424 SET_FLAG (new->flags, BGP_INFO_VALID);
3425 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003426 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003427
3428 /* Register new BGP information. */
3429 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003430
3431 /* route_node_get lock */
3432 bgp_unlock_node (rn);
3433
paulfee0f4c2004-09-13 05:12:46 +00003434 /* Process change. */
3435 bgp_process (bgp, rn, afi, safi);
3436
3437 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003438 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003439 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003440}
3441
paul94f2b392005-06-28 12:44:16 +00003442static void
paulfee0f4c2004-09-13 05:12:46 +00003443bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003444 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3445{
3446 struct bgp_node *rn;
3447 struct bgp_info *ri;
3448 struct bgp_info *new;
3449 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003450 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003451 struct attr *attr_new;
3452 int ret;
3453
Paul Jakmadd8103a2006-05-12 23:27:30 +00003454 assert (bgp_static);
3455 if (!bgp_static)
3456 return;
3457
paulfee0f4c2004-09-13 05:12:46 +00003458 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003459
3460 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003461
3462 attr.nexthop = bgp_static->igpnexthop;
3463 attr.med = bgp_static->igpmetric;
3464 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003465
Paul Jakma41367172007-08-06 15:24:51 +00003466 if (bgp_static->atomic)
3467 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3468
paul718e3742002-12-13 20:15:29 +00003469 /* Apply route-map. */
3470 if (bgp_static->rmap.name)
3471 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003472 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003473 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003474 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003475
paulfee0f4c2004-09-13 05:12:46 +00003476 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3477
paul718e3742002-12-13 20:15:29 +00003478 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003479
paulfee0f4c2004-09-13 05:12:46 +00003480 bgp->peer_self->rmap_type = 0;
3481
paul718e3742002-12-13 20:15:29 +00003482 if (ret == RMAP_DENYMATCH)
3483 {
3484 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003485 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003486
3487 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003488 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003489 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003490 bgp_static_withdraw (bgp, p, afi, safi);
3491 return;
3492 }
paul286e1e72003-08-08 00:24:31 +00003493 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003494 }
paul286e1e72003-08-08 00:24:31 +00003495 else
3496 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003497
3498 for (ri = rn->info; ri; ri = ri->next)
3499 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3500 && ri->sub_type == BGP_ROUTE_STATIC)
3501 break;
3502
3503 if (ri)
3504 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003505 if (attrhash_cmp (ri->attr, attr_new) &&
3506 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003507 {
3508 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003509 bgp_attr_unintern (&attr_new);
3510 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003511 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003512 return;
3513 }
3514 else
3515 {
3516 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003517 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003518
3519 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003520 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3521 bgp_info_restore(rn, ri);
3522 else
3523 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003524 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003525 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003526 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003527
3528 /* Process change. */
3529 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3530 bgp_process (bgp, rn, afi, safi);
3531 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003532 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003533 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003534 return;
3535 }
3536 }
3537
3538 /* Make new BGP info. */
3539 new = bgp_info_new ();
3540 new->type = ZEBRA_ROUTE_BGP;
3541 new->sub_type = BGP_ROUTE_STATIC;
3542 new->peer = bgp->peer_self;
3543 SET_FLAG (new->flags, BGP_INFO_VALID);
3544 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003545 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003546
3547 /* Aggregate address increment. */
3548 bgp_aggregate_increment (bgp, p, new, afi, safi);
3549
3550 /* Register new BGP information. */
3551 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003552
3553 /* route_node_get lock */
3554 bgp_unlock_node (rn);
3555
paul718e3742002-12-13 20:15:29 +00003556 /* Process change. */
3557 bgp_process (bgp, rn, afi, safi);
3558
3559 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003560 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003561 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003562}
3563
3564void
paulfee0f4c2004-09-13 05:12:46 +00003565bgp_static_update (struct bgp *bgp, struct prefix *p,
3566 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3567{
3568 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003569 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003570
3571 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3572
paul1eb8ef22005-04-07 07:30:20 +00003573 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003574 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003575 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3576 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003577 }
3578}
3579
paul94f2b392005-06-28 12:44:16 +00003580static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003581bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3582 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003583{
3584 struct bgp_node *rn;
3585 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003586
paulfee0f4c2004-09-13 05:12:46 +00003587 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003588
3589 /* Make new BGP info. */
3590 new = bgp_info_new ();
3591 new->type = ZEBRA_ROUTE_BGP;
3592 new->sub_type = BGP_ROUTE_STATIC;
3593 new->peer = bgp->peer_self;
3594 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3595 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003596 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003597 new->extra = bgp_info_extra_new();
3598 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003599
3600 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003601 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003602
3603 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003604 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003605
paul200df112005-06-01 11:17:05 +00003606 /* route_node_get lock */
3607 bgp_unlock_node (rn);
3608
paul718e3742002-12-13 20:15:29 +00003609 /* Process change. */
3610 bgp_process (bgp, rn, afi, safi);
3611}
3612
3613void
3614bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3615 safi_t safi)
3616{
3617 struct bgp_node *rn;
3618 struct bgp_info *ri;
3619
paulfee0f4c2004-09-13 05:12:46 +00003620 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003621
3622 /* Check selected route and self inserted route. */
3623 for (ri = rn->info; ri; ri = ri->next)
3624 if (ri->peer == bgp->peer_self
3625 && ri->type == ZEBRA_ROUTE_BGP
3626 && ri->sub_type == BGP_ROUTE_STATIC)
3627 break;
3628
3629 /* Withdraw static BGP route from routing table. */
3630 if (ri)
3631 {
3632 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003633 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003634 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003635 }
3636
3637 /* Unlock bgp_node_lookup. */
3638 bgp_unlock_node (rn);
3639}
3640
3641void
paulfee0f4c2004-09-13 05:12:46 +00003642bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3643{
3644 struct bgp_static *bgp_static;
3645 struct bgp *bgp;
3646 struct bgp_node *rn;
3647 struct prefix *p;
3648
3649 bgp = rsclient->bgp;
3650
3651 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3652 if ((bgp_static = rn->info) != NULL)
3653 {
3654 p = &rn->p;
3655
3656 bgp_static_update_rsclient (rsclient, p, bgp_static,
3657 afi, safi);
3658 }
3659}
3660
paul94f2b392005-06-28 12:44:16 +00003661static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003662bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3663 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003664{
3665 struct bgp_node *rn;
3666 struct bgp_info *ri;
3667
paulfee0f4c2004-09-13 05:12:46 +00003668 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003669
3670 /* Check selected route and self inserted route. */
3671 for (ri = rn->info; ri; ri = ri->next)
3672 if (ri->peer == bgp->peer_self
3673 && ri->type == ZEBRA_ROUTE_BGP
3674 && ri->sub_type == BGP_ROUTE_STATIC)
3675 break;
3676
3677 /* Withdraw static BGP route from routing table. */
3678 if (ri)
3679 {
3680 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003681 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003682 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003683 }
3684
3685 /* Unlock bgp_node_lookup. */
3686 bgp_unlock_node (rn);
3687}
3688
3689/* Configure static BGP network. When user don't run zebra, static
3690 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003691static int
paulfd79ac92004-10-13 05:06:08 +00003692bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003693 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003694{
3695 int ret;
3696 struct prefix p;
3697 struct bgp_static *bgp_static;
3698 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003699 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003700
3701 /* Convert IP prefix string to struct prefix. */
3702 ret = str2prefix (ip_str, &p);
3703 if (! ret)
3704 {
3705 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3706 return CMD_WARNING;
3707 }
3708#ifdef HAVE_IPV6
3709 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3710 {
3711 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3712 VTY_NEWLINE);
3713 return CMD_WARNING;
3714 }
3715#endif /* HAVE_IPV6 */
3716
3717 apply_mask (&p);
3718
3719 /* Set BGP static route configuration. */
3720 rn = bgp_node_get (bgp->route[afi][safi], &p);
3721
3722 if (rn->info)
3723 {
3724 /* Configuration change. */
3725 bgp_static = rn->info;
3726
3727 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003728 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3729 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003730
paul718e3742002-12-13 20:15:29 +00003731 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003732
paul718e3742002-12-13 20:15:29 +00003733 if (rmap)
3734 {
3735 if (bgp_static->rmap.name)
3736 free (bgp_static->rmap.name);
3737 bgp_static->rmap.name = strdup (rmap);
3738 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3739 }
3740 else
3741 {
3742 if (bgp_static->rmap.name)
3743 free (bgp_static->rmap.name);
3744 bgp_static->rmap.name = NULL;
3745 bgp_static->rmap.map = NULL;
3746 bgp_static->valid = 0;
3747 }
3748 bgp_unlock_node (rn);
3749 }
3750 else
3751 {
3752 /* New configuration. */
3753 bgp_static = bgp_static_new ();
3754 bgp_static->backdoor = backdoor;
3755 bgp_static->valid = 0;
3756 bgp_static->igpmetric = 0;
3757 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003758
paul718e3742002-12-13 20:15:29 +00003759 if (rmap)
3760 {
3761 if (bgp_static->rmap.name)
3762 free (bgp_static->rmap.name);
3763 bgp_static->rmap.name = strdup (rmap);
3764 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3765 }
3766 rn->info = bgp_static;
3767 }
3768
3769 /* If BGP scan is not enabled, we should install this route here. */
3770 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3771 {
3772 bgp_static->valid = 1;
3773
3774 if (need_update)
3775 bgp_static_withdraw (bgp, &p, afi, safi);
3776
3777 if (! bgp_static->backdoor)
3778 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3779 }
3780
3781 return CMD_SUCCESS;
3782}
3783
3784/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003785static int
paulfd79ac92004-10-13 05:06:08 +00003786bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003787 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003788{
3789 int ret;
3790 struct prefix p;
3791 struct bgp_static *bgp_static;
3792 struct bgp_node *rn;
3793
3794 /* Convert IP prefix string to struct prefix. */
3795 ret = str2prefix (ip_str, &p);
3796 if (! ret)
3797 {
3798 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3799 return CMD_WARNING;
3800 }
3801#ifdef HAVE_IPV6
3802 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3803 {
3804 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3805 VTY_NEWLINE);
3806 return CMD_WARNING;
3807 }
3808#endif /* HAVE_IPV6 */
3809
3810 apply_mask (&p);
3811
3812 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3813 if (! rn)
3814 {
3815 vty_out (vty, "%% Can't find specified static route configuration.%s",
3816 VTY_NEWLINE);
3817 return CMD_WARNING;
3818 }
3819
3820 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003821
paul718e3742002-12-13 20:15:29 +00003822 /* Update BGP RIB. */
3823 if (! bgp_static->backdoor)
3824 bgp_static_withdraw (bgp, &p, afi, safi);
3825
3826 /* Clear configuration. */
3827 bgp_static_free (bgp_static);
3828 rn->info = NULL;
3829 bgp_unlock_node (rn);
3830 bgp_unlock_node (rn);
3831
3832 return CMD_SUCCESS;
3833}
3834
3835/* Called from bgp_delete(). Delete all static routes from the BGP
3836 instance. */
3837void
3838bgp_static_delete (struct bgp *bgp)
3839{
3840 afi_t afi;
3841 safi_t safi;
3842 struct bgp_node *rn;
3843 struct bgp_node *rm;
3844 struct bgp_table *table;
3845 struct bgp_static *bgp_static;
3846
3847 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3848 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3849 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3850 if (rn->info != NULL)
3851 {
3852 if (safi == SAFI_MPLS_VPN)
3853 {
3854 table = rn->info;
3855
3856 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3857 {
3858 bgp_static = rn->info;
3859 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3860 AFI_IP, SAFI_MPLS_VPN,
3861 (struct prefix_rd *)&rn->p,
3862 bgp_static->tag);
3863 bgp_static_free (bgp_static);
3864 rn->info = NULL;
3865 bgp_unlock_node (rn);
3866 }
3867 }
3868 else
3869 {
3870 bgp_static = rn->info;
3871 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3872 bgp_static_free (bgp_static);
3873 rn->info = NULL;
3874 bgp_unlock_node (rn);
3875 }
3876 }
3877}
3878
3879int
paulfd79ac92004-10-13 05:06:08 +00003880bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3881 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003882{
3883 int ret;
3884 struct prefix p;
3885 struct prefix_rd prd;
3886 struct bgp *bgp;
3887 struct bgp_node *prn;
3888 struct bgp_node *rn;
3889 struct bgp_table *table;
3890 struct bgp_static *bgp_static;
3891 u_char tag[3];
3892
3893 bgp = vty->index;
3894
3895 ret = str2prefix (ip_str, &p);
3896 if (! ret)
3897 {
3898 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3899 return CMD_WARNING;
3900 }
3901 apply_mask (&p);
3902
3903 ret = str2prefix_rd (rd_str, &prd);
3904 if (! ret)
3905 {
3906 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3907 return CMD_WARNING;
3908 }
3909
3910 ret = str2tag (tag_str, tag);
3911 if (! ret)
3912 {
3913 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3914 return CMD_WARNING;
3915 }
3916
3917 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3918 (struct prefix *)&prd);
3919 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003920 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003921 else
3922 bgp_unlock_node (prn);
3923 table = prn->info;
3924
3925 rn = bgp_node_get (table, &p);
3926
3927 if (rn->info)
3928 {
3929 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3930 bgp_unlock_node (rn);
3931 }
3932 else
3933 {
3934 /* New configuration. */
3935 bgp_static = bgp_static_new ();
3936 bgp_static->valid = 1;
3937 memcpy (bgp_static->tag, tag, 3);
3938 rn->info = bgp_static;
3939
3940 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3941 }
3942
3943 return CMD_SUCCESS;
3944}
3945
3946/* Configure static BGP network. */
3947int
paulfd79ac92004-10-13 05:06:08 +00003948bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3949 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003950{
3951 int ret;
3952 struct bgp *bgp;
3953 struct prefix p;
3954 struct prefix_rd prd;
3955 struct bgp_node *prn;
3956 struct bgp_node *rn;
3957 struct bgp_table *table;
3958 struct bgp_static *bgp_static;
3959 u_char tag[3];
3960
3961 bgp = vty->index;
3962
3963 /* Convert IP prefix string to struct prefix. */
3964 ret = str2prefix (ip_str, &p);
3965 if (! ret)
3966 {
3967 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3968 return CMD_WARNING;
3969 }
3970 apply_mask (&p);
3971
3972 ret = str2prefix_rd (rd_str, &prd);
3973 if (! ret)
3974 {
3975 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3976 return CMD_WARNING;
3977 }
3978
3979 ret = str2tag (tag_str, tag);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985
3986 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3987 (struct prefix *)&prd);
3988 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003989 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003990 else
3991 bgp_unlock_node (prn);
3992 table = prn->info;
3993
3994 rn = bgp_node_lookup (table, &p);
3995
3996 if (rn)
3997 {
3998 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3999
4000 bgp_static = rn->info;
4001 bgp_static_free (bgp_static);
4002 rn->info = NULL;
4003 bgp_unlock_node (rn);
4004 bgp_unlock_node (rn);
4005 }
4006 else
4007 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4008
4009 return CMD_SUCCESS;
4010}
4011
4012DEFUN (bgp_network,
4013 bgp_network_cmd,
4014 "network A.B.C.D/M",
4015 "Specify a network to announce via BGP\n"
4016 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4017{
4018 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004019 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004020}
4021
4022DEFUN (bgp_network_route_map,
4023 bgp_network_route_map_cmd,
4024 "network A.B.C.D/M route-map WORD",
4025 "Specify a network to announce via BGP\n"
4026 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4027 "Route-map to modify the attributes\n"
4028 "Name of the route map\n")
4029{
4030 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004031 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004032}
4033
4034DEFUN (bgp_network_backdoor,
4035 bgp_network_backdoor_cmd,
4036 "network A.B.C.D/M backdoor",
4037 "Specify a network to announce via BGP\n"
4038 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4039 "Specify a BGP backdoor route\n")
4040{
Paul Jakma41367172007-08-06 15:24:51 +00004041 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004042 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004043}
4044
4045DEFUN (bgp_network_mask,
4046 bgp_network_mask_cmd,
4047 "network A.B.C.D mask A.B.C.D",
4048 "Specify a network to announce via BGP\n"
4049 "Network number\n"
4050 "Network mask\n"
4051 "Network mask\n")
4052{
4053 int ret;
4054 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004055
paul718e3742002-12-13 20:15:29 +00004056 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4057 if (! ret)
4058 {
4059 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4060 return CMD_WARNING;
4061 }
4062
4063 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004064 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004065}
4066
4067DEFUN (bgp_network_mask_route_map,
4068 bgp_network_mask_route_map_cmd,
4069 "network A.B.C.D mask A.B.C.D route-map WORD",
4070 "Specify a network to announce via BGP\n"
4071 "Network number\n"
4072 "Network mask\n"
4073 "Network mask\n"
4074 "Route-map to modify the attributes\n"
4075 "Name of the route map\n")
4076{
4077 int ret;
4078 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004079
paul718e3742002-12-13 20:15:29 +00004080 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4081 if (! ret)
4082 {
4083 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4084 return CMD_WARNING;
4085 }
4086
4087 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004088 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004089}
4090
4091DEFUN (bgp_network_mask_backdoor,
4092 bgp_network_mask_backdoor_cmd,
4093 "network A.B.C.D mask A.B.C.D backdoor",
4094 "Specify a network to announce via BGP\n"
4095 "Network number\n"
4096 "Network mask\n"
4097 "Network mask\n"
4098 "Specify a BGP backdoor route\n")
4099{
4100 int ret;
4101 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004102
paul718e3742002-12-13 20:15:29 +00004103 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4104 if (! ret)
4105 {
4106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4107 return CMD_WARNING;
4108 }
4109
Paul Jakma41367172007-08-06 15:24:51 +00004110 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004111 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004112}
4113
4114DEFUN (bgp_network_mask_natural,
4115 bgp_network_mask_natural_cmd,
4116 "network A.B.C.D",
4117 "Specify a network to announce via BGP\n"
4118 "Network number\n")
4119{
4120 int ret;
4121 char prefix_str[BUFSIZ];
4122
4123 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4124 if (! ret)
4125 {
4126 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4127 return CMD_WARNING;
4128 }
4129
4130 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004131 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004132}
4133
4134DEFUN (bgp_network_mask_natural_route_map,
4135 bgp_network_mask_natural_route_map_cmd,
4136 "network A.B.C.D route-map WORD",
4137 "Specify a network to announce via BGP\n"
4138 "Network number\n"
4139 "Route-map to modify the attributes\n"
4140 "Name of the route map\n")
4141{
4142 int ret;
4143 char prefix_str[BUFSIZ];
4144
4145 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4146 if (! ret)
4147 {
4148 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4149 return CMD_WARNING;
4150 }
4151
4152 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004153 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004154}
4155
4156DEFUN (bgp_network_mask_natural_backdoor,
4157 bgp_network_mask_natural_backdoor_cmd,
4158 "network A.B.C.D backdoor",
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "Specify a BGP backdoor route\n")
4162{
4163 int ret;
4164 char prefix_str[BUFSIZ];
4165
4166 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4167 if (! ret)
4168 {
4169 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4170 return CMD_WARNING;
4171 }
4172
Paul Jakma41367172007-08-06 15:24:51 +00004173 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004174 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004175}
4176
4177DEFUN (no_bgp_network,
4178 no_bgp_network_cmd,
4179 "no network A.B.C.D/M",
4180 NO_STR
4181 "Specify a network to announce via BGP\n"
4182 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4183{
4184 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4185 bgp_node_safi (vty));
4186}
4187
4188ALIAS (no_bgp_network,
4189 no_bgp_network_route_map_cmd,
4190 "no network A.B.C.D/M route-map WORD",
4191 NO_STR
4192 "Specify a network to announce via BGP\n"
4193 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4194 "Route-map to modify the attributes\n"
4195 "Name of the route map\n")
4196
4197ALIAS (no_bgp_network,
4198 no_bgp_network_backdoor_cmd,
4199 "no network A.B.C.D/M backdoor",
4200 NO_STR
4201 "Specify a network to announce via BGP\n"
4202 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4203 "Specify a BGP backdoor route\n")
4204
4205DEFUN (no_bgp_network_mask,
4206 no_bgp_network_mask_cmd,
4207 "no network A.B.C.D mask A.B.C.D",
4208 NO_STR
4209 "Specify a network to announce via BGP\n"
4210 "Network number\n"
4211 "Network mask\n"
4212 "Network mask\n")
4213{
4214 int ret;
4215 char prefix_str[BUFSIZ];
4216
4217 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4218 if (! ret)
4219 {
4220 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4221 return CMD_WARNING;
4222 }
4223
4224 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4225 bgp_node_safi (vty));
4226}
4227
4228ALIAS (no_bgp_network_mask,
4229 no_bgp_network_mask_route_map_cmd,
4230 "no network A.B.C.D mask A.B.C.D route-map WORD",
4231 NO_STR
4232 "Specify a network to announce via BGP\n"
4233 "Network number\n"
4234 "Network mask\n"
4235 "Network mask\n"
4236 "Route-map to modify the attributes\n"
4237 "Name of the route map\n")
4238
4239ALIAS (no_bgp_network_mask,
4240 no_bgp_network_mask_backdoor_cmd,
4241 "no network A.B.C.D mask A.B.C.D backdoor",
4242 NO_STR
4243 "Specify a network to announce via BGP\n"
4244 "Network number\n"
4245 "Network mask\n"
4246 "Network mask\n"
4247 "Specify a BGP backdoor route\n")
4248
4249DEFUN (no_bgp_network_mask_natural,
4250 no_bgp_network_mask_natural_cmd,
4251 "no network A.B.C.D",
4252 NO_STR
4253 "Specify a network to announce via BGP\n"
4254 "Network number\n")
4255{
4256 int ret;
4257 char prefix_str[BUFSIZ];
4258
4259 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4260 if (! ret)
4261 {
4262 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4263 return CMD_WARNING;
4264 }
4265
4266 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4267 bgp_node_safi (vty));
4268}
4269
4270ALIAS (no_bgp_network_mask_natural,
4271 no_bgp_network_mask_natural_route_map_cmd,
4272 "no network A.B.C.D route-map WORD",
4273 NO_STR
4274 "Specify a network to announce via BGP\n"
4275 "Network number\n"
4276 "Route-map to modify the attributes\n"
4277 "Name of the route map\n")
4278
4279ALIAS (no_bgp_network_mask_natural,
4280 no_bgp_network_mask_natural_backdoor_cmd,
4281 "no network A.B.C.D backdoor",
4282 NO_STR
4283 "Specify a network to announce via BGP\n"
4284 "Network number\n"
4285 "Specify a BGP backdoor route\n")
4286
4287#ifdef HAVE_IPV6
4288DEFUN (ipv6_bgp_network,
4289 ipv6_bgp_network_cmd,
4290 "network X:X::X:X/M",
4291 "Specify a network to announce via BGP\n"
4292 "IPv6 prefix <network>/<length>\n")
4293{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304294 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004295 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004296}
4297
4298DEFUN (ipv6_bgp_network_route_map,
4299 ipv6_bgp_network_route_map_cmd,
4300 "network X:X::X:X/M route-map WORD",
4301 "Specify a network to announce via BGP\n"
4302 "IPv6 prefix <network>/<length>\n"
4303 "Route-map to modify the attributes\n"
4304 "Name of the route map\n")
4305{
4306 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004307 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004308}
4309
4310DEFUN (no_ipv6_bgp_network,
4311 no_ipv6_bgp_network_cmd,
4312 "no network X:X::X:X/M",
4313 NO_STR
4314 "Specify a network to announce via BGP\n"
4315 "IPv6 prefix <network>/<length>\n")
4316{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304317 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004318}
4319
4320ALIAS (no_ipv6_bgp_network,
4321 no_ipv6_bgp_network_route_map_cmd,
4322 "no network X:X::X:X/M route-map WORD",
4323 NO_STR
4324 "Specify a network to announce via BGP\n"
4325 "IPv6 prefix <network>/<length>\n"
4326 "Route-map to modify the attributes\n"
4327 "Name of the route map\n")
4328
4329ALIAS (ipv6_bgp_network,
4330 old_ipv6_bgp_network_cmd,
4331 "ipv6 bgp network X:X::X:X/M",
4332 IPV6_STR
4333 BGP_STR
4334 "Specify a network to announce via BGP\n"
4335 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4336
4337ALIAS (no_ipv6_bgp_network,
4338 old_no_ipv6_bgp_network_cmd,
4339 "no ipv6 bgp network X:X::X:X/M",
4340 NO_STR
4341 IPV6_STR
4342 BGP_STR
4343 "Specify a network to announce via BGP\n"
4344 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4345#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004346
4347/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4348ALIAS_DEPRECATED (bgp_network,
4349 bgp_network_ttl_cmd,
4350 "network A.B.C.D/M pathlimit <0-255>",
4351 "Specify a network to announce via BGP\n"
4352 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355ALIAS_DEPRECATED (bgp_network_backdoor,
4356 bgp_network_backdoor_ttl_cmd,
4357 "network A.B.C.D/M backdoor pathlimit <0-255>",
4358 "Specify a network to announce via BGP\n"
4359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4360 "Specify a BGP backdoor route\n"
4361 "AS-Path hopcount limit attribute\n"
4362 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4363ALIAS_DEPRECATED (bgp_network_mask,
4364 bgp_network_mask_ttl_cmd,
4365 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4366 "Specify a network to announce via BGP\n"
4367 "Network number\n"
4368 "Network mask\n"
4369 "Network mask\n"
4370 "AS-Path hopcount limit attribute\n"
4371 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4372ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4373 bgp_network_mask_backdoor_ttl_cmd,
4374 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4375 "Specify a network to announce via BGP\n"
4376 "Network number\n"
4377 "Network mask\n"
4378 "Network mask\n"
4379 "Specify a BGP backdoor route\n"
4380 "AS-Path hopcount limit attribute\n"
4381 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4382ALIAS_DEPRECATED (bgp_network_mask_natural,
4383 bgp_network_mask_natural_ttl_cmd,
4384 "network A.B.C.D pathlimit <0-255>",
4385 "Specify a network to announce via BGP\n"
4386 "Network number\n"
4387 "AS-Path hopcount limit attribute\n"
4388 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4389ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4390 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004391 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004392 "Specify a network to announce via BGP\n"
4393 "Network number\n"
4394 "Specify a BGP backdoor route\n"
4395 "AS-Path hopcount limit attribute\n"
4396 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4397ALIAS_DEPRECATED (no_bgp_network,
4398 no_bgp_network_ttl_cmd,
4399 "no network A.B.C.D/M pathlimit <0-255>",
4400 NO_STR
4401 "Specify a network to announce via BGP\n"
4402 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4403 "AS-Path hopcount limit attribute\n"
4404 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4405ALIAS_DEPRECATED (no_bgp_network,
4406 no_bgp_network_backdoor_ttl_cmd,
4407 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4408 NO_STR
4409 "Specify a network to announce via BGP\n"
4410 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4411 "Specify a BGP backdoor route\n"
4412 "AS-Path hopcount limit attribute\n"
4413 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4414ALIAS_DEPRECATED (no_bgp_network,
4415 no_bgp_network_mask_ttl_cmd,
4416 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4417 NO_STR
4418 "Specify a network to announce via BGP\n"
4419 "Network number\n"
4420 "Network mask\n"
4421 "Network mask\n"
4422 "AS-Path hopcount limit attribute\n"
4423 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4424ALIAS_DEPRECATED (no_bgp_network_mask,
4425 no_bgp_network_mask_backdoor_ttl_cmd,
4426 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4427 NO_STR
4428 "Specify a network to announce via BGP\n"
4429 "Network number\n"
4430 "Network mask\n"
4431 "Network mask\n"
4432 "Specify a BGP backdoor route\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4436 no_bgp_network_mask_natural_ttl_cmd,
4437 "no network A.B.C.D pathlimit <0-255>",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "Network number\n"
4441 "AS-Path hopcount limit attribute\n"
4442 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4443ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4444 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4445 "no network A.B.C.D backdoor pathlimit <0-255>",
4446 NO_STR
4447 "Specify a network to announce via BGP\n"
4448 "Network number\n"
4449 "Specify a BGP backdoor route\n"
4450 "AS-Path hopcount limit attribute\n"
4451 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004452#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004453ALIAS_DEPRECATED (ipv6_bgp_network,
4454 ipv6_bgp_network_ttl_cmd,
4455 "network X:X::X:X/M pathlimit <0-255>",
4456 "Specify a network to announce via BGP\n"
4457 "IPv6 prefix <network>/<length>\n"
4458 "AS-Path hopcount limit attribute\n"
4459 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4460ALIAS_DEPRECATED (no_ipv6_bgp_network,
4461 no_ipv6_bgp_network_ttl_cmd,
4462 "no network X:X::X:X/M pathlimit <0-255>",
4463 NO_STR
4464 "Specify a network to announce via BGP\n"
4465 "IPv6 prefix <network>/<length>\n"
4466 "AS-Path hopcount limit attribute\n"
4467 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004468#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004469
4470/* Aggreagete address:
4471
4472 advertise-map Set condition to advertise attribute
4473 as-set Generate AS set path information
4474 attribute-map Set attributes of aggregate
4475 route-map Set parameters of aggregate
4476 summary-only Filter more specific routes from updates
4477 suppress-map Conditionally filter more specific routes from updates
4478 <cr>
4479 */
4480struct bgp_aggregate
4481{
4482 /* Summary-only flag. */
4483 u_char summary_only;
4484
4485 /* AS set generation. */
4486 u_char as_set;
4487
4488 /* Route-map for aggregated route. */
4489 struct route_map *map;
4490
4491 /* Suppress-count. */
4492 unsigned long count;
4493
4494 /* SAFI configuration. */
4495 safi_t safi;
4496};
4497
paul94f2b392005-06-28 12:44:16 +00004498static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004499bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004500{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004501 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004502}
4503
paul94f2b392005-06-28 12:44:16 +00004504static void
paul718e3742002-12-13 20:15:29 +00004505bgp_aggregate_free (struct bgp_aggregate *aggregate)
4506{
4507 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4508}
4509
paul94f2b392005-06-28 12:44:16 +00004510static void
paul718e3742002-12-13 20:15:29 +00004511bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4512 afi_t afi, safi_t safi, struct bgp_info *del,
4513 struct bgp_aggregate *aggregate)
4514{
4515 struct bgp_table *table;
4516 struct bgp_node *top;
4517 struct bgp_node *rn;
4518 u_char origin;
4519 struct aspath *aspath = NULL;
4520 struct aspath *asmerge = NULL;
4521 struct community *community = NULL;
4522 struct community *commerge = NULL;
4523 struct in_addr nexthop;
4524 u_int32_t med = 0;
4525 struct bgp_info *ri;
4526 struct bgp_info *new;
4527 int first = 1;
4528 unsigned long match = 0;
4529
4530 /* Record adding route's nexthop and med. */
4531 if (rinew)
4532 {
4533 nexthop = rinew->attr->nexthop;
4534 med = rinew->attr->med;
4535 }
4536
4537 /* ORIGIN attribute: If at least one route among routes that are
4538 aggregated has ORIGIN with the value INCOMPLETE, then the
4539 aggregated route must have the ORIGIN attribute with the value
4540 INCOMPLETE. Otherwise, if at least one route among routes that
4541 are aggregated has ORIGIN with the value EGP, then the aggregated
4542 route must have the origin attribute with the value EGP. In all
4543 other case the value of the ORIGIN attribute of the aggregated
4544 route is INTERNAL. */
4545 origin = BGP_ORIGIN_IGP;
4546
4547 table = bgp->rib[afi][safi];
4548
4549 top = bgp_node_get (table, p);
4550 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4551 if (rn->p.prefixlen > p->prefixlen)
4552 {
4553 match = 0;
4554
4555 for (ri = rn->info; ri; ri = ri->next)
4556 {
4557 if (BGP_INFO_HOLDDOWN (ri))
4558 continue;
4559
4560 if (del && ri == del)
4561 continue;
4562
4563 if (! rinew && first)
4564 {
4565 nexthop = ri->attr->nexthop;
4566 med = ri->attr->med;
4567 first = 0;
4568 }
4569
4570#ifdef AGGREGATE_NEXTHOP_CHECK
4571 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4572 || ri->attr->med != med)
4573 {
4574 if (aspath)
4575 aspath_free (aspath);
4576 if (community)
4577 community_free (community);
4578 bgp_unlock_node (rn);
4579 bgp_unlock_node (top);
4580 return;
4581 }
4582#endif /* AGGREGATE_NEXTHOP_CHECK */
4583
4584 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4585 {
4586 if (aggregate->summary_only)
4587 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004588 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004589 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004590 match++;
4591 }
4592
4593 aggregate->count++;
4594
4595 if (aggregate->as_set)
4596 {
4597 if (origin < ri->attr->origin)
4598 origin = ri->attr->origin;
4599
4600 if (aspath)
4601 {
4602 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4603 aspath_free (aspath);
4604 aspath = asmerge;
4605 }
4606 else
4607 aspath = aspath_dup (ri->attr->aspath);
4608
4609 if (ri->attr->community)
4610 {
4611 if (community)
4612 {
4613 commerge = community_merge (community,
4614 ri->attr->community);
4615 community = community_uniq_sort (commerge);
4616 community_free (commerge);
4617 }
4618 else
4619 community = community_dup (ri->attr->community);
4620 }
4621 }
4622 }
4623 }
4624 if (match)
4625 bgp_process (bgp, rn, afi, safi);
4626 }
4627 bgp_unlock_node (top);
4628
4629 if (rinew)
4630 {
4631 aggregate->count++;
4632
4633 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004634 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004635
4636 if (aggregate->as_set)
4637 {
4638 if (origin < rinew->attr->origin)
4639 origin = rinew->attr->origin;
4640
4641 if (aspath)
4642 {
4643 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4644 aspath_free (aspath);
4645 aspath = asmerge;
4646 }
4647 else
4648 aspath = aspath_dup (rinew->attr->aspath);
4649
4650 if (rinew->attr->community)
4651 {
4652 if (community)
4653 {
4654 commerge = community_merge (community,
4655 rinew->attr->community);
4656 community = community_uniq_sort (commerge);
4657 community_free (commerge);
4658 }
4659 else
4660 community = community_dup (rinew->attr->community);
4661 }
4662 }
4663 }
4664
4665 if (aggregate->count > 0)
4666 {
4667 rn = bgp_node_get (table, p);
4668 new = bgp_info_new ();
4669 new->type = ZEBRA_ROUTE_BGP;
4670 new->sub_type = BGP_ROUTE_AGGREGATE;
4671 new->peer = bgp->peer_self;
4672 SET_FLAG (new->flags, BGP_INFO_VALID);
4673 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004674 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004675
4676 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004677 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004678 bgp_process (bgp, rn, afi, safi);
4679 }
4680 else
4681 {
4682 if (aspath)
4683 aspath_free (aspath);
4684 if (community)
4685 community_free (community);
4686 }
4687}
4688
4689void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4690 struct bgp_aggregate *);
4691
4692void
4693bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4694 struct bgp_info *ri, afi_t afi, safi_t safi)
4695{
4696 struct bgp_node *child;
4697 struct bgp_node *rn;
4698 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004699 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004700
4701 /* MPLS-VPN aggregation is not yet supported. */
4702 if (safi == SAFI_MPLS_VPN)
4703 return;
4704
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004705 table = bgp->aggregate[afi][safi];
4706
4707 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004708 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004709 return;
4710
paul718e3742002-12-13 20:15:29 +00004711 if (p->prefixlen == 0)
4712 return;
4713
4714 if (BGP_INFO_HOLDDOWN (ri))
4715 return;
4716
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004717 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004718
4719 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004720 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004721 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4722 {
4723 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004724 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004725 }
4726 bgp_unlock_node (child);
4727}
4728
4729void
4730bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4731 struct bgp_info *del, afi_t afi, safi_t safi)
4732{
4733 struct bgp_node *child;
4734 struct bgp_node *rn;
4735 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004736 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004737
4738 /* MPLS-VPN aggregation is not yet supported. */
4739 if (safi == SAFI_MPLS_VPN)
4740 return;
4741
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004742 table = bgp->aggregate[afi][safi];
4743
4744 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004745 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004746 return;
4747
paul718e3742002-12-13 20:15:29 +00004748 if (p->prefixlen == 0)
4749 return;
4750
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004751 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004752
4753 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004754 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004755 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4756 {
4757 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004758 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004759 }
4760 bgp_unlock_node (child);
4761}
4762
paul94f2b392005-06-28 12:44:16 +00004763static void
paul718e3742002-12-13 20:15:29 +00004764bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4765 struct bgp_aggregate *aggregate)
4766{
4767 struct bgp_table *table;
4768 struct bgp_node *top;
4769 struct bgp_node *rn;
4770 struct bgp_info *new;
4771 struct bgp_info *ri;
4772 unsigned long match;
4773 u_char origin = BGP_ORIGIN_IGP;
4774 struct aspath *aspath = NULL;
4775 struct aspath *asmerge = NULL;
4776 struct community *community = NULL;
4777 struct community *commerge = NULL;
4778
4779 table = bgp->rib[afi][safi];
4780
4781 /* Sanity check. */
4782 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4783 return;
4784 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4785 return;
4786
4787 /* If routes exists below this node, generate aggregate routes. */
4788 top = bgp_node_get (table, p);
4789 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4790 if (rn->p.prefixlen > p->prefixlen)
4791 {
4792 match = 0;
4793
4794 for (ri = rn->info; ri; ri = ri->next)
4795 {
4796 if (BGP_INFO_HOLDDOWN (ri))
4797 continue;
4798
4799 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4800 {
4801 /* summary-only aggregate route suppress aggregated
4802 route announcement. */
4803 if (aggregate->summary_only)
4804 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004805 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004806 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004807 match++;
4808 }
4809 /* as-set aggregate route generate origin, as path,
4810 community aggregation. */
4811 if (aggregate->as_set)
4812 {
4813 if (origin < ri->attr->origin)
4814 origin = ri->attr->origin;
4815
4816 if (aspath)
4817 {
4818 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4819 aspath_free (aspath);
4820 aspath = asmerge;
4821 }
4822 else
4823 aspath = aspath_dup (ri->attr->aspath);
4824
4825 if (ri->attr->community)
4826 {
4827 if (community)
4828 {
4829 commerge = community_merge (community,
4830 ri->attr->community);
4831 community = community_uniq_sort (commerge);
4832 community_free (commerge);
4833 }
4834 else
4835 community = community_dup (ri->attr->community);
4836 }
4837 }
4838 aggregate->count++;
4839 }
4840 }
4841
4842 /* If this node is suppressed, process the change. */
4843 if (match)
4844 bgp_process (bgp, rn, afi, safi);
4845 }
4846 bgp_unlock_node (top);
4847
4848 /* Add aggregate route to BGP table. */
4849 if (aggregate->count)
4850 {
4851 rn = bgp_node_get (table, p);
4852
4853 new = bgp_info_new ();
4854 new->type = ZEBRA_ROUTE_BGP;
4855 new->sub_type = BGP_ROUTE_AGGREGATE;
4856 new->peer = bgp->peer_self;
4857 SET_FLAG (new->flags, BGP_INFO_VALID);
4858 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004859 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004860
4861 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004862 bgp_unlock_node (rn);
4863
paul718e3742002-12-13 20:15:29 +00004864 /* Process change. */
4865 bgp_process (bgp, rn, afi, safi);
4866 }
4867}
4868
4869void
4870bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4871 safi_t safi, struct bgp_aggregate *aggregate)
4872{
4873 struct bgp_table *table;
4874 struct bgp_node *top;
4875 struct bgp_node *rn;
4876 struct bgp_info *ri;
4877 unsigned long match;
4878
4879 table = bgp->rib[afi][safi];
4880
4881 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4882 return;
4883 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4884 return;
4885
4886 /* If routes exists below this node, generate aggregate routes. */
4887 top = bgp_node_get (table, p);
4888 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4889 if (rn->p.prefixlen > p->prefixlen)
4890 {
4891 match = 0;
4892
4893 for (ri = rn->info; ri; ri = ri->next)
4894 {
4895 if (BGP_INFO_HOLDDOWN (ri))
4896 continue;
4897
4898 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4899 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004900 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004901 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004902 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004903
Paul Jakmafb982c22007-05-04 20:15:47 +00004904 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004905 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004906 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004907 match++;
4908 }
4909 }
4910 aggregate->count--;
4911 }
4912 }
4913
Paul Jakmafb982c22007-05-04 20:15:47 +00004914 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004915 if (match)
4916 bgp_process (bgp, rn, afi, safi);
4917 }
4918 bgp_unlock_node (top);
4919
4920 /* Delete aggregate route from BGP table. */
4921 rn = bgp_node_get (table, p);
4922
4923 for (ri = rn->info; ri; ri = ri->next)
4924 if (ri->peer == bgp->peer_self
4925 && ri->type == ZEBRA_ROUTE_BGP
4926 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4927 break;
4928
4929 /* Withdraw static BGP route from routing table. */
4930 if (ri)
4931 {
paul718e3742002-12-13 20:15:29 +00004932 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004933 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004934 }
4935
4936 /* Unlock bgp_node_lookup. */
4937 bgp_unlock_node (rn);
4938}
4939
4940/* Aggregate route attribute. */
4941#define AGGREGATE_SUMMARY_ONLY 1
4942#define AGGREGATE_AS_SET 1
4943
paul94f2b392005-06-28 12:44:16 +00004944static int
Robert Baysf6269b42010-08-05 10:26:28 -07004945bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4946 afi_t afi, safi_t safi)
4947{
4948 int ret;
4949 struct prefix p;
4950 struct bgp_node *rn;
4951 struct bgp *bgp;
4952 struct bgp_aggregate *aggregate;
4953
4954 /* Convert string to prefix structure. */
4955 ret = str2prefix (prefix_str, &p);
4956 if (!ret)
4957 {
4958 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4959 return CMD_WARNING;
4960 }
4961 apply_mask (&p);
4962
4963 /* Get BGP structure. */
4964 bgp = vty->index;
4965
4966 /* Old configuration check. */
4967 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4968 if (! rn)
4969 {
4970 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4971 VTY_NEWLINE);
4972 return CMD_WARNING;
4973 }
4974
4975 aggregate = rn->info;
4976 if (aggregate->safi & SAFI_UNICAST)
4977 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4978 if (aggregate->safi & SAFI_MULTICAST)
4979 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4980
4981 /* Unlock aggregate address configuration. */
4982 rn->info = NULL;
4983 bgp_aggregate_free (aggregate);
4984 bgp_unlock_node (rn);
4985 bgp_unlock_node (rn);
4986
4987 return CMD_SUCCESS;
4988}
4989
4990static int
4991bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004992 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004993 u_char summary_only, u_char as_set)
4994{
4995 int ret;
4996 struct prefix p;
4997 struct bgp_node *rn;
4998 struct bgp *bgp;
4999 struct bgp_aggregate *aggregate;
5000
5001 /* Convert string to prefix structure. */
5002 ret = str2prefix (prefix_str, &p);
5003 if (!ret)
5004 {
5005 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5006 return CMD_WARNING;
5007 }
5008 apply_mask (&p);
5009
5010 /* Get BGP structure. */
5011 bgp = vty->index;
5012
5013 /* Old configuration check. */
5014 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5015
5016 if (rn->info)
5017 {
5018 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005019 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005020 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5021 if (ret)
5022 {
Robert Bays368473f2010-08-05 10:26:29 -07005023 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5024 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005025 return CMD_WARNING;
5026 }
paul718e3742002-12-13 20:15:29 +00005027 }
5028
5029 /* Make aggregate address structure. */
5030 aggregate = bgp_aggregate_new ();
5031 aggregate->summary_only = summary_only;
5032 aggregate->as_set = as_set;
5033 aggregate->safi = safi;
5034 rn->info = aggregate;
5035
5036 /* Aggregate address insert into BGP routing table. */
5037 if (safi & SAFI_UNICAST)
5038 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5039 if (safi & SAFI_MULTICAST)
5040 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5041
5042 return CMD_SUCCESS;
5043}
5044
paul718e3742002-12-13 20:15:29 +00005045DEFUN (aggregate_address,
5046 aggregate_address_cmd,
5047 "aggregate-address A.B.C.D/M",
5048 "Configure BGP aggregate entries\n"
5049 "Aggregate prefix\n")
5050{
5051 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5052}
5053
5054DEFUN (aggregate_address_mask,
5055 aggregate_address_mask_cmd,
5056 "aggregate-address A.B.C.D A.B.C.D",
5057 "Configure BGP aggregate entries\n"
5058 "Aggregate address\n"
5059 "Aggregate mask\n")
5060{
5061 int ret;
5062 char prefix_str[BUFSIZ];
5063
5064 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5065
5066 if (! ret)
5067 {
5068 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5069 return CMD_WARNING;
5070 }
5071
5072 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5073 0, 0);
5074}
5075
5076DEFUN (aggregate_address_summary_only,
5077 aggregate_address_summary_only_cmd,
5078 "aggregate-address A.B.C.D/M summary-only",
5079 "Configure BGP aggregate entries\n"
5080 "Aggregate prefix\n"
5081 "Filter more specific routes from updates\n")
5082{
5083 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5084 AGGREGATE_SUMMARY_ONLY, 0);
5085}
5086
5087DEFUN (aggregate_address_mask_summary_only,
5088 aggregate_address_mask_summary_only_cmd,
5089 "aggregate-address A.B.C.D A.B.C.D summary-only",
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate address\n"
5092 "Aggregate mask\n"
5093 "Filter more specific routes from updates\n")
5094{
5095 int ret;
5096 char prefix_str[BUFSIZ];
5097
5098 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5099
5100 if (! ret)
5101 {
5102 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5103 return CMD_WARNING;
5104 }
5105
5106 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5107 AGGREGATE_SUMMARY_ONLY, 0);
5108}
5109
5110DEFUN (aggregate_address_as_set,
5111 aggregate_address_as_set_cmd,
5112 "aggregate-address A.B.C.D/M as-set",
5113 "Configure BGP aggregate entries\n"
5114 "Aggregate prefix\n"
5115 "Generate AS set path information\n")
5116{
5117 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5118 0, AGGREGATE_AS_SET);
5119}
5120
5121DEFUN (aggregate_address_mask_as_set,
5122 aggregate_address_mask_as_set_cmd,
5123 "aggregate-address A.B.C.D A.B.C.D as-set",
5124 "Configure BGP aggregate entries\n"
5125 "Aggregate address\n"
5126 "Aggregate mask\n"
5127 "Generate AS set path information\n")
5128{
5129 int ret;
5130 char prefix_str[BUFSIZ];
5131
5132 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5133
5134 if (! ret)
5135 {
5136 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5137 return CMD_WARNING;
5138 }
5139
5140 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5141 0, AGGREGATE_AS_SET);
5142}
5143
5144
5145DEFUN (aggregate_address_as_set_summary,
5146 aggregate_address_as_set_summary_cmd,
5147 "aggregate-address A.B.C.D/M as-set summary-only",
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate prefix\n"
5150 "Generate AS set path information\n"
5151 "Filter more specific routes from updates\n")
5152{
5153 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5154 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5155}
5156
5157ALIAS (aggregate_address_as_set_summary,
5158 aggregate_address_summary_as_set_cmd,
5159 "aggregate-address A.B.C.D/M summary-only as-set",
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate prefix\n"
5162 "Filter more specific routes from updates\n"
5163 "Generate AS set path information\n")
5164
5165DEFUN (aggregate_address_mask_as_set_summary,
5166 aggregate_address_mask_as_set_summary_cmd,
5167 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate address\n"
5170 "Aggregate mask\n"
5171 "Generate AS set path information\n"
5172 "Filter more specific routes from updates\n")
5173{
5174 int ret;
5175 char prefix_str[BUFSIZ];
5176
5177 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5178
5179 if (! ret)
5180 {
5181 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5182 return CMD_WARNING;
5183 }
5184
5185 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5186 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5187}
5188
5189ALIAS (aggregate_address_mask_as_set_summary,
5190 aggregate_address_mask_summary_as_set_cmd,
5191 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate address\n"
5194 "Aggregate mask\n"
5195 "Filter more specific routes from updates\n"
5196 "Generate AS set path information\n")
5197
5198DEFUN (no_aggregate_address,
5199 no_aggregate_address_cmd,
5200 "no aggregate-address A.B.C.D/M",
5201 NO_STR
5202 "Configure BGP aggregate entries\n"
5203 "Aggregate prefix\n")
5204{
5205 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5206}
5207
5208ALIAS (no_aggregate_address,
5209 no_aggregate_address_summary_only_cmd,
5210 "no aggregate-address A.B.C.D/M summary-only",
5211 NO_STR
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate prefix\n"
5214 "Filter more specific routes from updates\n")
5215
5216ALIAS (no_aggregate_address,
5217 no_aggregate_address_as_set_cmd,
5218 "no aggregate-address A.B.C.D/M as-set",
5219 NO_STR
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate prefix\n"
5222 "Generate AS set path information\n")
5223
5224ALIAS (no_aggregate_address,
5225 no_aggregate_address_as_set_summary_cmd,
5226 "no aggregate-address A.B.C.D/M as-set summary-only",
5227 NO_STR
5228 "Configure BGP aggregate entries\n"
5229 "Aggregate prefix\n"
5230 "Generate AS set path information\n"
5231 "Filter more specific routes from updates\n")
5232
5233ALIAS (no_aggregate_address,
5234 no_aggregate_address_summary_as_set_cmd,
5235 "no aggregate-address A.B.C.D/M summary-only as-set",
5236 NO_STR
5237 "Configure BGP aggregate entries\n"
5238 "Aggregate prefix\n"
5239 "Filter more specific routes from updates\n"
5240 "Generate AS set path information\n")
5241
5242DEFUN (no_aggregate_address_mask,
5243 no_aggregate_address_mask_cmd,
5244 "no aggregate-address A.B.C.D A.B.C.D",
5245 NO_STR
5246 "Configure BGP aggregate entries\n"
5247 "Aggregate address\n"
5248 "Aggregate mask\n")
5249{
5250 int ret;
5251 char prefix_str[BUFSIZ];
5252
5253 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5254
5255 if (! ret)
5256 {
5257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5258 return CMD_WARNING;
5259 }
5260
5261 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5262}
5263
5264ALIAS (no_aggregate_address_mask,
5265 no_aggregate_address_mask_summary_only_cmd,
5266 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate address\n"
5270 "Aggregate mask\n"
5271 "Filter more specific routes from updates\n")
5272
5273ALIAS (no_aggregate_address_mask,
5274 no_aggregate_address_mask_as_set_cmd,
5275 "no aggregate-address A.B.C.D A.B.C.D as-set",
5276 NO_STR
5277 "Configure BGP aggregate entries\n"
5278 "Aggregate address\n"
5279 "Aggregate mask\n"
5280 "Generate AS set path information\n")
5281
5282ALIAS (no_aggregate_address_mask,
5283 no_aggregate_address_mask_as_set_summary_cmd,
5284 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5285 NO_STR
5286 "Configure BGP aggregate entries\n"
5287 "Aggregate address\n"
5288 "Aggregate mask\n"
5289 "Generate AS set path information\n"
5290 "Filter more specific routes from updates\n")
5291
5292ALIAS (no_aggregate_address_mask,
5293 no_aggregate_address_mask_summary_as_set_cmd,
5294 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5295 NO_STR
5296 "Configure BGP aggregate entries\n"
5297 "Aggregate address\n"
5298 "Aggregate mask\n"
5299 "Filter more specific routes from updates\n"
5300 "Generate AS set path information\n")
5301
5302#ifdef HAVE_IPV6
5303DEFUN (ipv6_aggregate_address,
5304 ipv6_aggregate_address_cmd,
5305 "aggregate-address X:X::X:X/M",
5306 "Configure BGP aggregate entries\n"
5307 "Aggregate prefix\n")
5308{
5309 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5310}
5311
5312DEFUN (ipv6_aggregate_address_summary_only,
5313 ipv6_aggregate_address_summary_only_cmd,
5314 "aggregate-address X:X::X:X/M summary-only",
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate prefix\n"
5317 "Filter more specific routes from updates\n")
5318{
5319 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5320 AGGREGATE_SUMMARY_ONLY, 0);
5321}
5322
5323DEFUN (no_ipv6_aggregate_address,
5324 no_ipv6_aggregate_address_cmd,
5325 "no aggregate-address X:X::X:X/M",
5326 NO_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate prefix\n")
5329{
5330 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5331}
5332
5333DEFUN (no_ipv6_aggregate_address_summary_only,
5334 no_ipv6_aggregate_address_summary_only_cmd,
5335 "no aggregate-address X:X::X:X/M summary-only",
5336 NO_STR
5337 "Configure BGP aggregate entries\n"
5338 "Aggregate prefix\n"
5339 "Filter more specific routes from updates\n")
5340{
5341 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5342}
5343
5344ALIAS (ipv6_aggregate_address,
5345 old_ipv6_aggregate_address_cmd,
5346 "ipv6 bgp aggregate-address X:X::X:X/M",
5347 IPV6_STR
5348 BGP_STR
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate prefix\n")
5351
5352ALIAS (ipv6_aggregate_address_summary_only,
5353 old_ipv6_aggregate_address_summary_only_cmd,
5354 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5355 IPV6_STR
5356 BGP_STR
5357 "Configure BGP aggregate entries\n"
5358 "Aggregate prefix\n"
5359 "Filter more specific routes from updates\n")
5360
5361ALIAS (no_ipv6_aggregate_address,
5362 old_no_ipv6_aggregate_address_cmd,
5363 "no ipv6 bgp aggregate-address X:X::X:X/M",
5364 NO_STR
5365 IPV6_STR
5366 BGP_STR
5367 "Configure BGP aggregate entries\n"
5368 "Aggregate prefix\n")
5369
5370ALIAS (no_ipv6_aggregate_address_summary_only,
5371 old_no_ipv6_aggregate_address_summary_only_cmd,
5372 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5373 NO_STR
5374 IPV6_STR
5375 BGP_STR
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate prefix\n"
5378 "Filter more specific routes from updates\n")
5379#endif /* HAVE_IPV6 */
5380
5381/* Redistribute route treatment. */
5382void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005383bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5384 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005385 u_int32_t metric, u_char type)
5386{
5387 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005388 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005389 struct bgp_info *new;
5390 struct bgp_info *bi;
5391 struct bgp_info info;
5392 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005393 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005394 struct attr *new_attr;
5395 afi_t afi;
5396 int ret;
5397
5398 /* Make default attribute. */
5399 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5400 if (nexthop)
5401 attr.nexthop = *nexthop;
5402
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005403#ifdef HAVE_IPV6
5404 if (nexthop6)
5405 {
5406 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5407 extra->mp_nexthop_global = *nexthop6;
5408 extra->mp_nexthop_len = 16;
5409 }
5410#endif
5411
paul718e3742002-12-13 20:15:29 +00005412 attr.med = metric;
5413 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5414
paul1eb8ef22005-04-07 07:30:20 +00005415 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005416 {
5417 afi = family2afi (p->family);
5418
5419 if (bgp->redist[afi][type])
5420 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005421 struct attr attr_new;
5422 struct attr_extra extra_new;
5423
paul718e3742002-12-13 20:15:29 +00005424 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005425 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005426 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005427
5428 if (bgp->redist_metric_flag[afi][type])
5429 attr_new.med = bgp->redist_metric[afi][type];
5430
5431 /* Apply route-map. */
5432 if (bgp->rmap[afi][type].map)
5433 {
5434 info.peer = bgp->peer_self;
5435 info.attr = &attr_new;
5436
paulfee0f4c2004-09-13 05:12:46 +00005437 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5438
paul718e3742002-12-13 20:15:29 +00005439 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5440 &info);
paulfee0f4c2004-09-13 05:12:46 +00005441
5442 bgp->peer_self->rmap_type = 0;
5443
paul718e3742002-12-13 20:15:29 +00005444 if (ret == RMAP_DENYMATCH)
5445 {
5446 /* Free uninterned attribute. */
5447 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005448
paul718e3742002-12-13 20:15:29 +00005449 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005450 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005451 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005452 bgp_redistribute_delete (p, type);
5453 return;
5454 }
5455 }
5456
Paul Jakmafb982c22007-05-04 20:15:47 +00005457 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5458 afi, SAFI_UNICAST, p, NULL);
5459
paul718e3742002-12-13 20:15:29 +00005460 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005461
paul718e3742002-12-13 20:15:29 +00005462 for (bi = bn->info; bi; bi = bi->next)
5463 if (bi->peer == bgp->peer_self
5464 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5465 break;
5466
5467 if (bi)
5468 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005469 if (attrhash_cmp (bi->attr, new_attr) &&
5470 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005471 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005472 bgp_attr_unintern (&new_attr);
5473 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005474 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005475 bgp_unlock_node (bn);
5476 return;
5477 }
5478 else
5479 {
5480 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005481 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005482
5483 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005484 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5485 bgp_info_restore(bn, bi);
5486 else
5487 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005488 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005489 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005490 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005491
5492 /* Process change. */
5493 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5494 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5495 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005496 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005497 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005498 return;
5499 }
5500 }
5501
5502 new = bgp_info_new ();
5503 new->type = type;
5504 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5505 new->peer = bgp->peer_self;
5506 SET_FLAG (new->flags, BGP_INFO_VALID);
5507 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005508 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005509
5510 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5511 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005512 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005513 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5514 }
5515 }
5516
5517 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005518 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005519 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005520}
5521
5522void
5523bgp_redistribute_delete (struct prefix *p, u_char type)
5524{
5525 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005526 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005527 afi_t afi;
5528 struct bgp_node *rn;
5529 struct bgp_info *ri;
5530
paul1eb8ef22005-04-07 07:30:20 +00005531 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005532 {
5533 afi = family2afi (p->family);
5534
5535 if (bgp->redist[afi][type])
5536 {
paulfee0f4c2004-09-13 05:12:46 +00005537 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005538
5539 for (ri = rn->info; ri; ri = ri->next)
5540 if (ri->peer == bgp->peer_self
5541 && ri->type == type)
5542 break;
5543
5544 if (ri)
5545 {
5546 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005547 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005548 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005549 }
5550 bgp_unlock_node (rn);
5551 }
5552 }
5553}
5554
5555/* Withdraw specified route type's route. */
5556void
5557bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5558{
5559 struct bgp_node *rn;
5560 struct bgp_info *ri;
5561 struct bgp_table *table;
5562
5563 table = bgp->rib[afi][SAFI_UNICAST];
5564
5565 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5566 {
5567 for (ri = rn->info; ri; ri = ri->next)
5568 if (ri->peer == bgp->peer_self
5569 && ri->type == type)
5570 break;
5571
5572 if (ri)
5573 {
5574 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005575 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005576 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005577 }
5578 }
5579}
5580
5581/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005582static void
paul718e3742002-12-13 20:15:29 +00005583route_vty_out_route (struct prefix *p, struct vty *vty)
5584{
5585 int len;
5586 u_int32_t destination;
5587 char buf[BUFSIZ];
5588
5589 if (p->family == AF_INET)
5590 {
5591 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5592 destination = ntohl (p->u.prefix4.s_addr);
5593
5594 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5595 || (IN_CLASSB (destination) && p->prefixlen == 16)
5596 || (IN_CLASSA (destination) && p->prefixlen == 8)
5597 || p->u.prefix4.s_addr == 0)
5598 {
5599 /* When mask is natural, mask is not displayed. */
5600 }
5601 else
5602 len += vty_out (vty, "/%d", p->prefixlen);
5603 }
5604 else
5605 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5606 p->prefixlen);
5607
5608 len = 17 - len;
5609 if (len < 1)
5610 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5611 else
5612 vty_out (vty, "%*s", len, " ");
5613}
5614
paul718e3742002-12-13 20:15:29 +00005615enum bgp_display_type
5616{
5617 normal_list,
5618};
5619
paulb40d9392005-08-22 22:34:41 +00005620/* Print the short form route status for a bgp_info */
5621static void
5622route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005623{
paulb40d9392005-08-22 22:34:41 +00005624 /* Route status display. */
5625 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5626 vty_out (vty, "R");
5627 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005628 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005629 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005630 vty_out (vty, "s");
5631 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5632 vty_out (vty, "*");
5633 else
5634 vty_out (vty, " ");
5635
5636 /* Selected */
5637 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5638 vty_out (vty, "h");
5639 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5640 vty_out (vty, "d");
5641 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5642 vty_out (vty, ">");
5643 else
5644 vty_out (vty, " ");
5645
5646 /* Internal route. */
5647 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5648 vty_out (vty, "i");
5649 else
paulb40d9392005-08-22 22:34:41 +00005650 vty_out (vty, " ");
5651}
5652
5653/* called from terminal list command */
5654void
5655route_vty_out (struct vty *vty, struct prefix *p,
5656 struct bgp_info *binfo, int display, safi_t safi)
5657{
5658 struct attr *attr;
5659
5660 /* short status lead text */
5661 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005662
5663 /* print prefix and mask */
5664 if (! display)
5665 route_vty_out_route (p, vty);
5666 else
5667 vty_out (vty, "%*s", 17, " ");
5668
5669 /* Print attribute */
5670 attr = binfo->attr;
5671 if (attr)
5672 {
5673 if (p->family == AF_INET)
5674 {
5675 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005676 vty_out (vty, "%-16s",
5677 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005678 else
5679 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5680 }
5681#ifdef HAVE_IPV6
5682 else if (p->family == AF_INET6)
5683 {
5684 int len;
5685 char buf[BUFSIZ];
5686
5687 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005688 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5689 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005690 len = 16 - len;
5691 if (len < 1)
5692 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5693 else
5694 vty_out (vty, "%*s", len, " ");
5695 }
5696#endif /* HAVE_IPV6 */
5697
5698 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005699 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005700 else
5701 vty_out (vty, " ");
5702
5703 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005704 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005705 else
5706 vty_out (vty, " ");
5707
Paul Jakmafb982c22007-05-04 20:15:47 +00005708 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005709
Paul Jakmab2518c12006-05-12 23:48:40 +00005710 /* Print aspath */
5711 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005712 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005713
Paul Jakmab2518c12006-05-12 23:48:40 +00005714 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005715 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005716 }
paul718e3742002-12-13 20:15:29 +00005717 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005718}
5719
5720/* called from terminal list command */
5721void
5722route_vty_out_tmp (struct vty *vty, struct prefix *p,
5723 struct attr *attr, safi_t safi)
5724{
5725 /* Route status display. */
5726 vty_out (vty, "*");
5727 vty_out (vty, ">");
5728 vty_out (vty, " ");
5729
5730 /* print prefix and mask */
5731 route_vty_out_route (p, vty);
5732
5733 /* Print attribute */
5734 if (attr)
5735 {
5736 if (p->family == AF_INET)
5737 {
5738 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005739 vty_out (vty, "%-16s",
5740 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005741 else
5742 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5743 }
5744#ifdef HAVE_IPV6
5745 else if (p->family == AF_INET6)
5746 {
5747 int len;
5748 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005749
5750 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005751
5752 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005753 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5754 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005755 len = 16 - len;
5756 if (len < 1)
5757 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5758 else
5759 vty_out (vty, "%*s", len, " ");
5760 }
5761#endif /* HAVE_IPV6 */
5762
5763 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005764 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005765 else
5766 vty_out (vty, " ");
5767
5768 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005769 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005770 else
5771 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005772
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005773 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005774
Paul Jakmab2518c12006-05-12 23:48:40 +00005775 /* Print aspath */
5776 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005777 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005778
Paul Jakmab2518c12006-05-12 23:48:40 +00005779 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005780 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005781 }
paul718e3742002-12-13 20:15:29 +00005782
5783 vty_out (vty, "%s", VTY_NEWLINE);
5784}
5785
ajs5a646652004-11-05 01:25:55 +00005786void
paul718e3742002-12-13 20:15:29 +00005787route_vty_out_tag (struct vty *vty, struct prefix *p,
5788 struct bgp_info *binfo, int display, safi_t safi)
5789{
5790 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005791 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005792
5793 if (!binfo->extra)
5794 return;
5795
paulb40d9392005-08-22 22:34:41 +00005796 /* short status lead text */
5797 route_vty_short_status_out (vty, binfo);
5798
paul718e3742002-12-13 20:15:29 +00005799 /* print prefix and mask */
5800 if (! display)
5801 route_vty_out_route (p, vty);
5802 else
5803 vty_out (vty, "%*s", 17, " ");
5804
5805 /* Print attribute */
5806 attr = binfo->attr;
5807 if (attr)
5808 {
5809 if (p->family == AF_INET)
5810 {
5811 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005812 vty_out (vty, "%-16s",
5813 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005814 else
5815 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5816 }
5817#ifdef HAVE_IPV6
5818 else if (p->family == AF_INET6)
5819 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005820 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005821 char buf[BUFSIZ];
5822 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005823 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005824 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005825 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5826 buf, BUFSIZ));
5827 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005828 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005829 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5830 buf, BUFSIZ),
5831 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5832 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005833
5834 }
5835#endif /* HAVE_IPV6 */
5836 }
5837
Paul Jakmafb982c22007-05-04 20:15:47 +00005838 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005839
5840 vty_out (vty, "notag/%d", label);
5841
5842 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005843}
5844
5845/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005846static void
paul718e3742002-12-13 20:15:29 +00005847damp_route_vty_out (struct vty *vty, struct prefix *p,
5848 struct bgp_info *binfo, int display, safi_t safi)
5849{
5850 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005851 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005852 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005853
paulb40d9392005-08-22 22:34:41 +00005854 /* short status lead text */
5855 route_vty_short_status_out (vty, binfo);
5856
paul718e3742002-12-13 20:15:29 +00005857 /* print prefix and mask */
5858 if (! display)
5859 route_vty_out_route (p, vty);
5860 else
5861 vty_out (vty, "%*s", 17, " ");
5862
5863 len = vty_out (vty, "%s", binfo->peer->host);
5864 len = 17 - len;
5865 if (len < 1)
5866 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5867 else
5868 vty_out (vty, "%*s", len, " ");
5869
Chris Caputo50aef6f2009-06-23 06:06:49 +00005870 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005871
5872 /* Print attribute */
5873 attr = binfo->attr;
5874 if (attr)
5875 {
5876 /* Print aspath */
5877 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005878 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005879
5880 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005881 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005882 }
5883 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005884}
5885
paul718e3742002-12-13 20:15:29 +00005886/* flap route */
ajs5a646652004-11-05 01:25:55 +00005887static void
paul718e3742002-12-13 20:15:29 +00005888flap_route_vty_out (struct vty *vty, struct prefix *p,
5889 struct bgp_info *binfo, int display, safi_t safi)
5890{
5891 struct attr *attr;
5892 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005893 char timebuf[BGP_UPTIME_LEN];
5894 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005895
5896 if (!binfo->extra)
5897 return;
5898
5899 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005900
paulb40d9392005-08-22 22:34:41 +00005901 /* short status lead text */
5902 route_vty_short_status_out (vty, binfo);
5903
paul718e3742002-12-13 20:15:29 +00005904 /* print prefix and mask */
5905 if (! display)
5906 route_vty_out_route (p, vty);
5907 else
5908 vty_out (vty, "%*s", 17, " ");
5909
5910 len = vty_out (vty, "%s", binfo->peer->host);
5911 len = 16 - len;
5912 if (len < 1)
5913 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5914 else
5915 vty_out (vty, "%*s", len, " ");
5916
5917 len = vty_out (vty, "%d", bdi->flap);
5918 len = 5 - len;
5919 if (len < 1)
5920 vty_out (vty, " ");
5921 else
5922 vty_out (vty, "%*s ", len, " ");
5923
5924 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5925 timebuf, BGP_UPTIME_LEN));
5926
5927 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5928 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005929 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005930 else
5931 vty_out (vty, "%*s ", 8, " ");
5932
5933 /* Print attribute */
5934 attr = binfo->attr;
5935 if (attr)
5936 {
5937 /* Print aspath */
5938 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005939 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005940
5941 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005942 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005943 }
5944 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005945}
5946
paul94f2b392005-06-28 12:44:16 +00005947static void
paul718e3742002-12-13 20:15:29 +00005948route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5949 struct bgp_info *binfo, afi_t afi, safi_t safi)
5950{
5951 char buf[INET6_ADDRSTRLEN];
5952 char buf1[BUFSIZ];
5953 struct attr *attr;
5954 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005955#ifdef HAVE_CLOCK_MONOTONIC
5956 time_t tbuf;
5957#endif
paul718e3742002-12-13 20:15:29 +00005958
5959 attr = binfo->attr;
5960
5961 if (attr)
5962 {
5963 /* Line1 display AS-path, Aggregator */
5964 if (attr->aspath)
5965 {
5966 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005967 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005968 vty_out (vty, "Local");
5969 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005970 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005971 }
5972
paulb40d9392005-08-22 22:34:41 +00005973 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5974 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005975 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5976 vty_out (vty, ", (stale)");
5977 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005978 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005979 attr->extra->aggregator_as,
5980 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005981 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5982 vty_out (vty, ", (Received from a RR-client)");
5983 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5984 vty_out (vty, ", (Received from a RS-client)");
5985 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5986 vty_out (vty, ", (history entry)");
5987 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5988 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005989 vty_out (vty, "%s", VTY_NEWLINE);
5990
5991 /* Line2 display Next-hop, Neighbor, Router-id */
5992 if (p->family == AF_INET)
5993 {
5994 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005995 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005996 inet_ntoa (attr->nexthop));
5997 }
5998#ifdef HAVE_IPV6
5999 else
6000 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006002 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006003 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006004 buf, INET6_ADDRSTRLEN));
6005 }
6006#endif /* HAVE_IPV6 */
6007
6008 if (binfo->peer == bgp->peer_self)
6009 {
6010 vty_out (vty, " from %s ",
6011 p->family == AF_INET ? "0.0.0.0" : "::");
6012 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6013 }
6014 else
6015 {
6016 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6017 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006018 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006019 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006020 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006021 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006022 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006023 else
6024 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6025 }
6026 vty_out (vty, "%s", VTY_NEWLINE);
6027
6028#ifdef HAVE_IPV6
6029 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006030 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006031 {
6032 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006034 buf, INET6_ADDRSTRLEN),
6035 VTY_NEWLINE);
6036 }
6037#endif /* HAVE_IPV6 */
6038
6039 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6040 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6041
6042 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006043 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006044
6045 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006046 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006047 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006048 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006049
Paul Jakmafb982c22007-05-04 20:15:47 +00006050 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006051 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006052
6053 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6054 vty_out (vty, ", valid");
6055
6056 if (binfo->peer != bgp->peer_self)
6057 {
6058 if (binfo->peer->as == binfo->peer->local_as)
6059 vty_out (vty, ", internal");
6060 else
6061 vty_out (vty, ", %s",
6062 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6063 }
6064 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6065 vty_out (vty, ", aggregated, local");
6066 else if (binfo->type != ZEBRA_ROUTE_BGP)
6067 vty_out (vty, ", sourced");
6068 else
6069 vty_out (vty, ", sourced, local");
6070
6071 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6072 vty_out (vty, ", atomic-aggregate");
6073
Josh Baileyde8d5df2011-07-20 20:46:01 -07006074 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6075 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6076 bgp_info_mpath_count (binfo)))
6077 vty_out (vty, ", multipath");
6078
paul718e3742002-12-13 20:15:29 +00006079 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6080 vty_out (vty, ", best");
6081
6082 vty_out (vty, "%s", VTY_NEWLINE);
6083
6084 /* Line 4 display Community */
6085 if (attr->community)
6086 vty_out (vty, " Community: %s%s", attr->community->str,
6087 VTY_NEWLINE);
6088
6089 /* Line 5 display Extended-community */
6090 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006091 vty_out (vty, " Extended Community: %s%s",
6092 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006093
6094 /* Line 6 display Originator, Cluster-id */
6095 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6096 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6097 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006098 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006099 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006100 vty_out (vty, " Originator: %s",
6101 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006102
6103 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6104 {
6105 int i;
6106 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006107 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6108 vty_out (vty, "%s ",
6109 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006110 }
6111 vty_out (vty, "%s", VTY_NEWLINE);
6112 }
Paul Jakma41367172007-08-06 15:24:51 +00006113
Paul Jakmafb982c22007-05-04 20:15:47 +00006114 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006115 bgp_damp_info_vty (vty, binfo);
6116
6117 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006118#ifdef HAVE_CLOCK_MONOTONIC
6119 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006120 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006121#else
6122 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6123#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006124 }
6125 vty_out (vty, "%s", VTY_NEWLINE);
6126}
6127
paulb40d9392005-08-22 22:34:41 +00006128#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 +00006129#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006130#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6131#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6132#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6133
6134enum bgp_show_type
6135{
6136 bgp_show_type_normal,
6137 bgp_show_type_regexp,
6138 bgp_show_type_prefix_list,
6139 bgp_show_type_filter_list,
6140 bgp_show_type_route_map,
6141 bgp_show_type_neighbor,
6142 bgp_show_type_cidr_only,
6143 bgp_show_type_prefix_longer,
6144 bgp_show_type_community_all,
6145 bgp_show_type_community,
6146 bgp_show_type_community_exact,
6147 bgp_show_type_community_list,
6148 bgp_show_type_community_list_exact,
6149 bgp_show_type_flap_statistics,
6150 bgp_show_type_flap_address,
6151 bgp_show_type_flap_prefix,
6152 bgp_show_type_flap_cidr_only,
6153 bgp_show_type_flap_regexp,
6154 bgp_show_type_flap_filter_list,
6155 bgp_show_type_flap_prefix_list,
6156 bgp_show_type_flap_prefix_longer,
6157 bgp_show_type_flap_route_map,
6158 bgp_show_type_flap_neighbor,
6159 bgp_show_type_dampend_paths,
6160 bgp_show_type_damp_neighbor
6161};
6162
ajs5a646652004-11-05 01:25:55 +00006163static int
paulfee0f4c2004-09-13 05:12:46 +00006164bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006165 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006166{
paul718e3742002-12-13 20:15:29 +00006167 struct bgp_info *ri;
6168 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006169 int header = 1;
paul718e3742002-12-13 20:15:29 +00006170 int display;
ajs5a646652004-11-05 01:25:55 +00006171 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006172
6173 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006174 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006175
paul718e3742002-12-13 20:15:29 +00006176 /* Start processing of routes. */
6177 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6178 if (rn->info != NULL)
6179 {
6180 display = 0;
6181
6182 for (ri = rn->info; ri; ri = ri->next)
6183 {
ajs5a646652004-11-05 01:25:55 +00006184 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006185 || type == bgp_show_type_flap_address
6186 || type == bgp_show_type_flap_prefix
6187 || type == bgp_show_type_flap_cidr_only
6188 || type == bgp_show_type_flap_regexp
6189 || type == bgp_show_type_flap_filter_list
6190 || type == bgp_show_type_flap_prefix_list
6191 || type == bgp_show_type_flap_prefix_longer
6192 || type == bgp_show_type_flap_route_map
6193 || type == bgp_show_type_flap_neighbor
6194 || type == bgp_show_type_dampend_paths
6195 || type == bgp_show_type_damp_neighbor)
6196 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006197 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006198 continue;
6199 }
6200 if (type == bgp_show_type_regexp
6201 || type == bgp_show_type_flap_regexp)
6202 {
ajs5a646652004-11-05 01:25:55 +00006203 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006204
6205 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6206 continue;
6207 }
6208 if (type == bgp_show_type_prefix_list
6209 || type == bgp_show_type_flap_prefix_list)
6210 {
ajs5a646652004-11-05 01:25:55 +00006211 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006212
6213 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6214 continue;
6215 }
6216 if (type == bgp_show_type_filter_list
6217 || type == bgp_show_type_flap_filter_list)
6218 {
ajs5a646652004-11-05 01:25:55 +00006219 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006220
6221 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6222 continue;
6223 }
6224 if (type == bgp_show_type_route_map
6225 || type == bgp_show_type_flap_route_map)
6226 {
ajs5a646652004-11-05 01:25:55 +00006227 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006228 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006229 struct attr dummy_attr;
6230 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006231 int ret;
6232
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006233 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006234 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006235
paul718e3742002-12-13 20:15:29 +00006236 binfo.peer = ri->peer;
6237 binfo.attr = &dummy_attr;
6238
6239 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006240 if (ret == RMAP_DENYMATCH)
6241 continue;
6242 }
6243 if (type == bgp_show_type_neighbor
6244 || type == bgp_show_type_flap_neighbor
6245 || type == bgp_show_type_damp_neighbor)
6246 {
ajs5a646652004-11-05 01:25:55 +00006247 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006248
6249 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6250 continue;
6251 }
6252 if (type == bgp_show_type_cidr_only
6253 || type == bgp_show_type_flap_cidr_only)
6254 {
6255 u_int32_t destination;
6256
6257 destination = ntohl (rn->p.u.prefix4.s_addr);
6258 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6259 continue;
6260 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6261 continue;
6262 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6263 continue;
6264 }
6265 if (type == bgp_show_type_prefix_longer
6266 || type == bgp_show_type_flap_prefix_longer)
6267 {
ajs5a646652004-11-05 01:25:55 +00006268 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006269
6270 if (! prefix_match (p, &rn->p))
6271 continue;
6272 }
6273 if (type == bgp_show_type_community_all)
6274 {
6275 if (! ri->attr->community)
6276 continue;
6277 }
6278 if (type == bgp_show_type_community)
6279 {
ajs5a646652004-11-05 01:25:55 +00006280 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006281
6282 if (! ri->attr->community ||
6283 ! community_match (ri->attr->community, com))
6284 continue;
6285 }
6286 if (type == bgp_show_type_community_exact)
6287 {
ajs5a646652004-11-05 01:25:55 +00006288 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006289
6290 if (! ri->attr->community ||
6291 ! community_cmp (ri->attr->community, com))
6292 continue;
6293 }
6294 if (type == bgp_show_type_community_list)
6295 {
ajs5a646652004-11-05 01:25:55 +00006296 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006297
6298 if (! community_list_match (ri->attr->community, list))
6299 continue;
6300 }
6301 if (type == bgp_show_type_community_list_exact)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! community_list_exact_match (ri->attr->community, list))
6306 continue;
6307 }
6308 if (type == bgp_show_type_flap_address
6309 || type == bgp_show_type_flap_prefix)
6310 {
ajs5a646652004-11-05 01:25:55 +00006311 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006312
6313 if (! prefix_match (&rn->p, p))
6314 continue;
6315
6316 if (type == bgp_show_type_flap_prefix)
6317 if (p->prefixlen != rn->p.prefixlen)
6318 continue;
6319 }
6320 if (type == bgp_show_type_dampend_paths
6321 || type == bgp_show_type_damp_neighbor)
6322 {
6323 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6324 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6325 continue;
6326 }
6327
6328 if (header)
6329 {
hasso93406d82005-02-02 14:40:33 +00006330 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6331 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6332 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006333 if (type == bgp_show_type_dampend_paths
6334 || type == bgp_show_type_damp_neighbor)
6335 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6336 else if (type == bgp_show_type_flap_statistics
6337 || type == bgp_show_type_flap_address
6338 || type == bgp_show_type_flap_prefix
6339 || type == bgp_show_type_flap_cidr_only
6340 || type == bgp_show_type_flap_regexp
6341 || type == bgp_show_type_flap_filter_list
6342 || type == bgp_show_type_flap_prefix_list
6343 || type == bgp_show_type_flap_prefix_longer
6344 || type == bgp_show_type_flap_route_map
6345 || type == bgp_show_type_flap_neighbor)
6346 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6347 else
6348 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006349 header = 0;
6350 }
6351
6352 if (type == bgp_show_type_dampend_paths
6353 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006354 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006355 else if (type == bgp_show_type_flap_statistics
6356 || type == bgp_show_type_flap_address
6357 || type == bgp_show_type_flap_prefix
6358 || type == bgp_show_type_flap_cidr_only
6359 || type == bgp_show_type_flap_regexp
6360 || type == bgp_show_type_flap_filter_list
6361 || type == bgp_show_type_flap_prefix_list
6362 || type == bgp_show_type_flap_prefix_longer
6363 || type == bgp_show_type_flap_route_map
6364 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006365 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006366 else
ajs5a646652004-11-05 01:25:55 +00006367 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006368 display++;
6369 }
6370 if (display)
ajs5a646652004-11-05 01:25:55 +00006371 output_count++;
paul718e3742002-12-13 20:15:29 +00006372 }
6373
6374 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006375 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006376 {
6377 if (type == bgp_show_type_normal)
6378 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6379 }
6380 else
6381 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006382 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006383
6384 return CMD_SUCCESS;
6385}
6386
ajs5a646652004-11-05 01:25:55 +00006387static int
paulfee0f4c2004-09-13 05:12:46 +00006388bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006389 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006390{
6391 struct bgp_table *table;
6392
6393 if (bgp == NULL) {
6394 bgp = bgp_get_default ();
6395 }
6396
6397 if (bgp == NULL)
6398 {
6399 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6400 return CMD_WARNING;
6401 }
6402
6403
6404 table = bgp->rib[afi][safi];
6405
ajs5a646652004-11-05 01:25:55 +00006406 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006407}
6408
paul718e3742002-12-13 20:15:29 +00006409/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006410static void
paul718e3742002-12-13 20:15:29 +00006411route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6412 struct bgp_node *rn,
6413 struct prefix_rd *prd, afi_t afi, safi_t safi)
6414{
6415 struct bgp_info *ri;
6416 struct prefix *p;
6417 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006418 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006419 char buf1[INET6_ADDRSTRLEN];
6420 char buf2[INET6_ADDRSTRLEN];
6421 int count = 0;
6422 int best = 0;
6423 int suppress = 0;
6424 int no_export = 0;
6425 int no_advertise = 0;
6426 int local_as = 0;
6427 int first = 0;
6428
6429 p = &rn->p;
6430 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6431 (safi == SAFI_MPLS_VPN ?
6432 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6433 safi == SAFI_MPLS_VPN ? ":" : "",
6434 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6435 p->prefixlen, VTY_NEWLINE);
6436
6437 for (ri = rn->info; ri; ri = ri->next)
6438 {
6439 count++;
6440 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6441 {
6442 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006443 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006444 suppress = 1;
6445 if (ri->attr->community != NULL)
6446 {
6447 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6448 no_advertise = 1;
6449 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6450 no_export = 1;
6451 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6452 local_as = 1;
6453 }
6454 }
6455 }
6456
6457 vty_out (vty, "Paths: (%d available", count);
6458 if (best)
6459 {
6460 vty_out (vty, ", best #%d", best);
6461 if (safi == SAFI_UNICAST)
6462 vty_out (vty, ", table Default-IP-Routing-Table");
6463 }
6464 else
6465 vty_out (vty, ", no best path");
6466 if (no_advertise)
6467 vty_out (vty, ", not advertised to any peer");
6468 else if (no_export)
6469 vty_out (vty, ", not advertised to EBGP peer");
6470 else if (local_as)
6471 vty_out (vty, ", not advertised outside local AS");
6472 if (suppress)
6473 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6474 vty_out (vty, ")%s", VTY_NEWLINE);
6475
6476 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006477 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006478 {
6479 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6480 {
6481 if (! first)
6482 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6483 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6484 first = 1;
6485 }
6486 }
6487 if (! first)
6488 vty_out (vty, " Not advertised to any peer");
6489 vty_out (vty, "%s", VTY_NEWLINE);
6490}
6491
6492/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006493static int
paulfee0f4c2004-09-13 05:12:46 +00006494bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006495 struct bgp_table *rib, const char *ip_str,
6496 afi_t afi, safi_t safi, struct prefix_rd *prd,
6497 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006498{
6499 int ret;
6500 int header;
6501 int display = 0;
6502 struct prefix match;
6503 struct bgp_node *rn;
6504 struct bgp_node *rm;
6505 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006506 struct bgp_table *table;
6507
paul718e3742002-12-13 20:15:29 +00006508 /* Check IP address argument. */
6509 ret = str2prefix (ip_str, &match);
6510 if (! ret)
6511 {
6512 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6513 return CMD_WARNING;
6514 }
6515
6516 match.family = afi2family (afi);
6517
6518 if (safi == SAFI_MPLS_VPN)
6519 {
paulfee0f4c2004-09-13 05:12:46 +00006520 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006521 {
6522 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6523 continue;
6524
6525 if ((table = rn->info) != NULL)
6526 {
6527 header = 1;
6528
6529 if ((rm = bgp_node_match (table, &match)) != NULL)
6530 {
6531 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006532 {
6533 bgp_unlock_node (rm);
6534 continue;
6535 }
paul718e3742002-12-13 20:15:29 +00006536
6537 for (ri = rm->info; ri; ri = ri->next)
6538 {
6539 if (header)
6540 {
6541 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6542 AFI_IP, SAFI_MPLS_VPN);
6543
6544 header = 0;
6545 }
6546 display++;
6547 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6548 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006549
6550 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006551 }
6552 }
6553 }
6554 }
6555 else
6556 {
6557 header = 1;
6558
paulfee0f4c2004-09-13 05:12:46 +00006559 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006560 {
6561 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6562 {
6563 for (ri = rn->info; ri; ri = ri->next)
6564 {
6565 if (header)
6566 {
6567 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6568 header = 0;
6569 }
6570 display++;
6571 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6572 }
6573 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006574
6575 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006576 }
6577 }
6578
6579 if (! display)
6580 {
6581 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6582 return CMD_WARNING;
6583 }
6584
6585 return CMD_SUCCESS;
6586}
6587
paulfee0f4c2004-09-13 05:12:46 +00006588/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006589static int
paulfd79ac92004-10-13 05:06:08 +00006590bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006591 afi_t afi, safi_t safi, struct prefix_rd *prd,
6592 int prefix_check)
6593{
6594 struct bgp *bgp;
6595
6596 /* BGP structure lookup. */
6597 if (view_name)
6598 {
6599 bgp = bgp_lookup_by_name (view_name);
6600 if (bgp == NULL)
6601 {
6602 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6603 return CMD_WARNING;
6604 }
6605 }
6606 else
6607 {
6608 bgp = bgp_get_default ();
6609 if (bgp == NULL)
6610 {
6611 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6612 return CMD_WARNING;
6613 }
6614 }
6615
6616 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6617 afi, safi, prd, prefix_check);
6618}
6619
paul718e3742002-12-13 20:15:29 +00006620/* BGP route print out function. */
6621DEFUN (show_ip_bgp,
6622 show_ip_bgp_cmd,
6623 "show ip bgp",
6624 SHOW_STR
6625 IP_STR
6626 BGP_STR)
6627{
ajs5a646652004-11-05 01:25:55 +00006628 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006629}
6630
6631DEFUN (show_ip_bgp_ipv4,
6632 show_ip_bgp_ipv4_cmd,
6633 "show ip bgp ipv4 (unicast|multicast)",
6634 SHOW_STR
6635 IP_STR
6636 BGP_STR
6637 "Address family\n"
6638 "Address Family modifier\n"
6639 "Address Family modifier\n")
6640{
6641 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006642 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6643 NULL);
paul718e3742002-12-13 20:15:29 +00006644
ajs5a646652004-11-05 01:25:55 +00006645 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006646}
6647
Michael Lambert95cbbd22010-07-23 14:43:04 -04006648ALIAS (show_ip_bgp_ipv4,
6649 show_bgp_ipv4_safi_cmd,
6650 "show bgp ipv4 (unicast|multicast)",
6651 SHOW_STR
6652 BGP_STR
6653 "Address family\n"
6654 "Address Family modifier\n"
6655 "Address Family modifier\n")
6656
paul718e3742002-12-13 20:15:29 +00006657DEFUN (show_ip_bgp_route,
6658 show_ip_bgp_route_cmd,
6659 "show ip bgp A.B.C.D",
6660 SHOW_STR
6661 IP_STR
6662 BGP_STR
6663 "Network in the BGP routing table to display\n")
6664{
6665 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6666}
6667
6668DEFUN (show_ip_bgp_ipv4_route,
6669 show_ip_bgp_ipv4_route_cmd,
6670 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6671 SHOW_STR
6672 IP_STR
6673 BGP_STR
6674 "Address family\n"
6675 "Address Family modifier\n"
6676 "Address Family modifier\n"
6677 "Network in the BGP routing table to display\n")
6678{
6679 if (strncmp (argv[0], "m", 1) == 0)
6680 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6681
6682 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6683}
6684
Michael Lambert95cbbd22010-07-23 14:43:04 -04006685ALIAS (show_ip_bgp_ipv4_route,
6686 show_bgp_ipv4_safi_route_cmd,
6687 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6688 SHOW_STR
6689 BGP_STR
6690 "Address family\n"
6691 "Address Family modifier\n"
6692 "Address Family modifier\n"
6693 "Network in the BGP routing table to display\n")
6694
paul718e3742002-12-13 20:15:29 +00006695DEFUN (show_ip_bgp_vpnv4_all_route,
6696 show_ip_bgp_vpnv4_all_route_cmd,
6697 "show ip bgp vpnv4 all A.B.C.D",
6698 SHOW_STR
6699 IP_STR
6700 BGP_STR
6701 "Display VPNv4 NLRI specific information\n"
6702 "Display information about all VPNv4 NLRIs\n"
6703 "Network in the BGP routing table to display\n")
6704{
6705 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6706}
6707
6708DEFUN (show_ip_bgp_vpnv4_rd_route,
6709 show_ip_bgp_vpnv4_rd_route_cmd,
6710 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "Display VPNv4 NLRI specific information\n"
6715 "Display information for a route distinguisher\n"
6716 "VPN Route Distinguisher\n"
6717 "Network in the BGP routing table to display\n")
6718{
6719 int ret;
6720 struct prefix_rd prd;
6721
6722 ret = str2prefix_rd (argv[0], &prd);
6723 if (! ret)
6724 {
6725 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6726 return CMD_WARNING;
6727 }
6728 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6729}
6730
6731DEFUN (show_ip_bgp_prefix,
6732 show_ip_bgp_prefix_cmd,
6733 "show ip bgp A.B.C.D/M",
6734 SHOW_STR
6735 IP_STR
6736 BGP_STR
6737 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6738{
6739 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6740}
6741
6742DEFUN (show_ip_bgp_ipv4_prefix,
6743 show_ip_bgp_ipv4_prefix_cmd,
6744 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6745 SHOW_STR
6746 IP_STR
6747 BGP_STR
6748 "Address family\n"
6749 "Address Family modifier\n"
6750 "Address Family modifier\n"
6751 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6752{
6753 if (strncmp (argv[0], "m", 1) == 0)
6754 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6755
6756 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6757}
6758
Michael Lambert95cbbd22010-07-23 14:43:04 -04006759ALIAS (show_ip_bgp_ipv4_prefix,
6760 show_bgp_ipv4_safi_prefix_cmd,
6761 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6762 SHOW_STR
6763 BGP_STR
6764 "Address family\n"
6765 "Address Family modifier\n"
6766 "Address Family modifier\n"
6767 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6768
paul718e3742002-12-13 20:15:29 +00006769DEFUN (show_ip_bgp_vpnv4_all_prefix,
6770 show_ip_bgp_vpnv4_all_prefix_cmd,
6771 "show ip bgp vpnv4 all A.B.C.D/M",
6772 SHOW_STR
6773 IP_STR
6774 BGP_STR
6775 "Display VPNv4 NLRI specific information\n"
6776 "Display information about all VPNv4 NLRIs\n"
6777 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6778{
6779 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6780}
6781
6782DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6783 show_ip_bgp_vpnv4_rd_prefix_cmd,
6784 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6785 SHOW_STR
6786 IP_STR
6787 BGP_STR
6788 "Display VPNv4 NLRI specific information\n"
6789 "Display information for a route distinguisher\n"
6790 "VPN Route Distinguisher\n"
6791 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6792{
6793 int ret;
6794 struct prefix_rd prd;
6795
6796 ret = str2prefix_rd (argv[0], &prd);
6797 if (! ret)
6798 {
6799 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6800 return CMD_WARNING;
6801 }
6802 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6803}
6804
6805DEFUN (show_ip_bgp_view,
6806 show_ip_bgp_view_cmd,
6807 "show ip bgp view WORD",
6808 SHOW_STR
6809 IP_STR
6810 BGP_STR
6811 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006812 "View name\n")
paul718e3742002-12-13 20:15:29 +00006813{
paulbb46e942003-10-24 19:02:03 +00006814 struct bgp *bgp;
6815
6816 /* BGP structure lookup. */
6817 bgp = bgp_lookup_by_name (argv[0]);
6818 if (bgp == NULL)
6819 {
6820 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6821 return CMD_WARNING;
6822 }
6823
ajs5a646652004-11-05 01:25:55 +00006824 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006825}
6826
6827DEFUN (show_ip_bgp_view_route,
6828 show_ip_bgp_view_route_cmd,
6829 "show ip bgp view WORD A.B.C.D",
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 "Network in the BGP routing table to display\n")
6836{
6837 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6838}
6839
6840DEFUN (show_ip_bgp_view_prefix,
6841 show_ip_bgp_view_prefix_cmd,
6842 "show ip bgp view WORD A.B.C.D/M",
6843 SHOW_STR
6844 IP_STR
6845 BGP_STR
6846 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006847 "View name\n"
paul718e3742002-12-13 20:15:29 +00006848 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6849{
6850 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6851}
6852
6853#ifdef HAVE_IPV6
6854DEFUN (show_bgp,
6855 show_bgp_cmd,
6856 "show bgp",
6857 SHOW_STR
6858 BGP_STR)
6859{
ajs5a646652004-11-05 01:25:55 +00006860 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6861 NULL);
paul718e3742002-12-13 20:15:29 +00006862}
6863
6864ALIAS (show_bgp,
6865 show_bgp_ipv6_cmd,
6866 "show bgp ipv6",
6867 SHOW_STR
6868 BGP_STR
6869 "Address family\n")
6870
Michael Lambert95cbbd22010-07-23 14:43:04 -04006871DEFUN (show_bgp_ipv6_safi,
6872 show_bgp_ipv6_safi_cmd,
6873 "show bgp ipv6 (unicast|multicast)",
6874 SHOW_STR
6875 BGP_STR
6876 "Address family\n"
6877 "Address Family modifier\n"
6878 "Address Family modifier\n")
6879{
6880 if (strncmp (argv[0], "m", 1) == 0)
6881 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6882 NULL);
6883
6884 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6885}
6886
paul718e3742002-12-13 20:15:29 +00006887/* old command */
6888DEFUN (show_ipv6_bgp,
6889 show_ipv6_bgp_cmd,
6890 "show ipv6 bgp",
6891 SHOW_STR
6892 IP_STR
6893 BGP_STR)
6894{
ajs5a646652004-11-05 01:25:55 +00006895 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6896 NULL);
paul718e3742002-12-13 20:15:29 +00006897}
6898
6899DEFUN (show_bgp_route,
6900 show_bgp_route_cmd,
6901 "show bgp X:X::X:X",
6902 SHOW_STR
6903 BGP_STR
6904 "Network in the BGP routing table to display\n")
6905{
6906 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6907}
6908
6909ALIAS (show_bgp_route,
6910 show_bgp_ipv6_route_cmd,
6911 "show bgp ipv6 X:X::X:X",
6912 SHOW_STR
6913 BGP_STR
6914 "Address family\n"
6915 "Network in the BGP routing table to display\n")
6916
Michael Lambert95cbbd22010-07-23 14:43:04 -04006917DEFUN (show_bgp_ipv6_safi_route,
6918 show_bgp_ipv6_safi_route_cmd,
6919 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6920 SHOW_STR
6921 BGP_STR
6922 "Address family\n"
6923 "Address Family modifier\n"
6924 "Address Family modifier\n"
6925 "Network in the BGP routing table to display\n")
6926{
6927 if (strncmp (argv[0], "m", 1) == 0)
6928 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6929
6930 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6931}
6932
paul718e3742002-12-13 20:15:29 +00006933/* old command */
6934DEFUN (show_ipv6_bgp_route,
6935 show_ipv6_bgp_route_cmd,
6936 "show ipv6 bgp X:X::X:X",
6937 SHOW_STR
6938 IP_STR
6939 BGP_STR
6940 "Network in the BGP routing table to display\n")
6941{
6942 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6943}
6944
6945DEFUN (show_bgp_prefix,
6946 show_bgp_prefix_cmd,
6947 "show bgp X:X::X:X/M",
6948 SHOW_STR
6949 BGP_STR
6950 "IPv6 prefix <network>/<length>\n")
6951{
6952 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6953}
6954
6955ALIAS (show_bgp_prefix,
6956 show_bgp_ipv6_prefix_cmd,
6957 "show bgp ipv6 X:X::X:X/M",
6958 SHOW_STR
6959 BGP_STR
6960 "Address family\n"
6961 "IPv6 prefix <network>/<length>\n")
6962
Michael Lambert95cbbd22010-07-23 14:43:04 -04006963DEFUN (show_bgp_ipv6_safi_prefix,
6964 show_bgp_ipv6_safi_prefix_cmd,
6965 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6966 SHOW_STR
6967 BGP_STR
6968 "Address family\n"
6969 "Address Family modifier\n"
6970 "Address Family modifier\n"
6971 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6972{
6973 if (strncmp (argv[0], "m", 1) == 0)
6974 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6975
6976 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6977}
6978
paul718e3742002-12-13 20:15:29 +00006979/* old command */
6980DEFUN (show_ipv6_bgp_prefix,
6981 show_ipv6_bgp_prefix_cmd,
6982 "show ipv6 bgp X:X::X:X/M",
6983 SHOW_STR
6984 IP_STR
6985 BGP_STR
6986 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6987{
6988 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6989}
6990
paulbb46e942003-10-24 19:02:03 +00006991DEFUN (show_bgp_view,
6992 show_bgp_view_cmd,
6993 "show bgp view WORD",
6994 SHOW_STR
6995 BGP_STR
6996 "BGP view\n"
6997 "View name\n")
6998{
6999 struct bgp *bgp;
7000
7001 /* BGP structure lookup. */
7002 bgp = bgp_lookup_by_name (argv[0]);
7003 if (bgp == NULL)
7004 {
7005 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7006 return CMD_WARNING;
7007 }
7008
ajs5a646652004-11-05 01:25:55 +00007009 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007010}
7011
7012ALIAS (show_bgp_view,
7013 show_bgp_view_ipv6_cmd,
7014 "show bgp view WORD ipv6",
7015 SHOW_STR
7016 BGP_STR
7017 "BGP view\n"
7018 "View name\n"
7019 "Address family\n")
7020
7021DEFUN (show_bgp_view_route,
7022 show_bgp_view_route_cmd,
7023 "show bgp view WORD X:X::X:X",
7024 SHOW_STR
7025 BGP_STR
7026 "BGP view\n"
7027 "View name\n"
7028 "Network in the BGP routing table to display\n")
7029{
7030 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7031}
7032
7033ALIAS (show_bgp_view_route,
7034 show_bgp_view_ipv6_route_cmd,
7035 "show bgp view WORD ipv6 X:X::X:X",
7036 SHOW_STR
7037 BGP_STR
7038 "BGP view\n"
7039 "View name\n"
7040 "Address family\n"
7041 "Network in the BGP routing table to display\n")
7042
7043DEFUN (show_bgp_view_prefix,
7044 show_bgp_view_prefix_cmd,
7045 "show bgp view WORD X:X::X:X/M",
7046 SHOW_STR
7047 BGP_STR
7048 "BGP view\n"
7049 "View name\n"
7050 "IPv6 prefix <network>/<length>\n")
7051{
7052 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7053}
7054
7055ALIAS (show_bgp_view_prefix,
7056 show_bgp_view_ipv6_prefix_cmd,
7057 "show bgp view WORD ipv6 X:X::X:X/M",
7058 SHOW_STR
7059 BGP_STR
7060 "BGP view\n"
7061 "View name\n"
7062 "Address family\n"
7063 "IPv6 prefix <network>/<length>\n")
7064
paul718e3742002-12-13 20:15:29 +00007065/* old command */
7066DEFUN (show_ipv6_mbgp,
7067 show_ipv6_mbgp_cmd,
7068 "show ipv6 mbgp",
7069 SHOW_STR
7070 IP_STR
7071 MBGP_STR)
7072{
ajs5a646652004-11-05 01:25:55 +00007073 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7074 NULL);
paul718e3742002-12-13 20:15:29 +00007075}
7076
7077/* old command */
7078DEFUN (show_ipv6_mbgp_route,
7079 show_ipv6_mbgp_route_cmd,
7080 "show ipv6 mbgp X:X::X:X",
7081 SHOW_STR
7082 IP_STR
7083 MBGP_STR
7084 "Network in the MBGP routing table to display\n")
7085{
7086 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7087}
7088
7089/* old command */
7090DEFUN (show_ipv6_mbgp_prefix,
7091 show_ipv6_mbgp_prefix_cmd,
7092 "show ipv6 mbgp X:X::X:X/M",
7093 SHOW_STR
7094 IP_STR
7095 MBGP_STR
7096 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7097{
7098 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7099}
7100#endif
7101
paul718e3742002-12-13 20:15:29 +00007102
paul94f2b392005-06-28 12:44:16 +00007103static int
paulfd79ac92004-10-13 05:06:08 +00007104bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007105 safi_t safi, enum bgp_show_type type)
7106{
7107 int i;
7108 struct buffer *b;
7109 char *regstr;
7110 int first;
7111 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007112 int rc;
paul718e3742002-12-13 20:15:29 +00007113
7114 first = 0;
7115 b = buffer_new (1024);
7116 for (i = 0; i < argc; i++)
7117 {
7118 if (first)
7119 buffer_putc (b, ' ');
7120 else
7121 {
7122 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7123 continue;
7124 first = 1;
7125 }
7126
7127 buffer_putstr (b, argv[i]);
7128 }
7129 buffer_putc (b, '\0');
7130
7131 regstr = buffer_getstr (b);
7132 buffer_free (b);
7133
7134 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007135 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007136 if (! regex)
7137 {
7138 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7139 VTY_NEWLINE);
7140 return CMD_WARNING;
7141 }
7142
ajs5a646652004-11-05 01:25:55 +00007143 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7144 bgp_regex_free (regex);
7145 return rc;
paul718e3742002-12-13 20:15:29 +00007146}
7147
7148DEFUN (show_ip_bgp_regexp,
7149 show_ip_bgp_regexp_cmd,
7150 "show ip bgp regexp .LINE",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Display routes matching the AS path regular expression\n"
7155 "A regular-expression to match the BGP AS paths\n")
7156{
7157 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7158 bgp_show_type_regexp);
7159}
7160
7161DEFUN (show_ip_bgp_flap_regexp,
7162 show_ip_bgp_flap_regexp_cmd,
7163 "show ip bgp flap-statistics regexp .LINE",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Display flap statistics of routes\n"
7168 "Display routes matching the AS path regular expression\n"
7169 "A regular-expression to match the BGP AS paths\n")
7170{
7171 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7172 bgp_show_type_flap_regexp);
7173}
7174
7175DEFUN (show_ip_bgp_ipv4_regexp,
7176 show_ip_bgp_ipv4_regexp_cmd,
7177 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7178 SHOW_STR
7179 IP_STR
7180 BGP_STR
7181 "Address family\n"
7182 "Address Family modifier\n"
7183 "Address Family modifier\n"
7184 "Display routes matching the AS path regular expression\n"
7185 "A regular-expression to match the BGP AS paths\n")
7186{
7187 if (strncmp (argv[0], "m", 1) == 0)
7188 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7189 bgp_show_type_regexp);
7190
7191 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7192 bgp_show_type_regexp);
7193}
7194
7195#ifdef HAVE_IPV6
7196DEFUN (show_bgp_regexp,
7197 show_bgp_regexp_cmd,
7198 "show bgp regexp .LINE",
7199 SHOW_STR
7200 BGP_STR
7201 "Display routes matching the AS path regular expression\n"
7202 "A regular-expression to match the BGP AS paths\n")
7203{
7204 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7205 bgp_show_type_regexp);
7206}
7207
7208ALIAS (show_bgp_regexp,
7209 show_bgp_ipv6_regexp_cmd,
7210 "show bgp ipv6 regexp .LINE",
7211 SHOW_STR
7212 BGP_STR
7213 "Address family\n"
7214 "Display routes matching the AS path regular expression\n"
7215 "A regular-expression to match the BGP AS paths\n")
7216
7217/* old command */
7218DEFUN (show_ipv6_bgp_regexp,
7219 show_ipv6_bgp_regexp_cmd,
7220 "show ipv6 bgp regexp .LINE",
7221 SHOW_STR
7222 IP_STR
7223 BGP_STR
7224 "Display routes matching the AS path regular expression\n"
7225 "A regular-expression to match the BGP AS paths\n")
7226{
7227 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7228 bgp_show_type_regexp);
7229}
7230
7231/* old command */
7232DEFUN (show_ipv6_mbgp_regexp,
7233 show_ipv6_mbgp_regexp_cmd,
7234 "show ipv6 mbgp regexp .LINE",
7235 SHOW_STR
7236 IP_STR
7237 BGP_STR
7238 "Display routes matching the AS path regular expression\n"
7239 "A regular-expression to match the MBGP AS paths\n")
7240{
7241 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7242 bgp_show_type_regexp);
7243}
7244#endif /* HAVE_IPV6 */
7245
paul94f2b392005-06-28 12:44:16 +00007246static int
paulfd79ac92004-10-13 05:06:08 +00007247bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007248 safi_t safi, enum bgp_show_type type)
7249{
7250 struct prefix_list *plist;
7251
7252 plist = prefix_list_lookup (afi, prefix_list_str);
7253 if (plist == NULL)
7254 {
7255 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7256 prefix_list_str, VTY_NEWLINE);
7257 return CMD_WARNING;
7258 }
7259
ajs5a646652004-11-05 01:25:55 +00007260 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007261}
7262
7263DEFUN (show_ip_bgp_prefix_list,
7264 show_ip_bgp_prefix_list_cmd,
7265 "show ip bgp prefix-list WORD",
7266 SHOW_STR
7267 IP_STR
7268 BGP_STR
7269 "Display routes conforming to the prefix-list\n"
7270 "IP prefix-list name\n")
7271{
7272 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7273 bgp_show_type_prefix_list);
7274}
7275
7276DEFUN (show_ip_bgp_flap_prefix_list,
7277 show_ip_bgp_flap_prefix_list_cmd,
7278 "show ip bgp flap-statistics prefix-list WORD",
7279 SHOW_STR
7280 IP_STR
7281 BGP_STR
7282 "Display flap statistics of routes\n"
7283 "Display routes conforming to the prefix-list\n"
7284 "IP prefix-list name\n")
7285{
7286 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7287 bgp_show_type_flap_prefix_list);
7288}
7289
7290DEFUN (show_ip_bgp_ipv4_prefix_list,
7291 show_ip_bgp_ipv4_prefix_list_cmd,
7292 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7293 SHOW_STR
7294 IP_STR
7295 BGP_STR
7296 "Address family\n"
7297 "Address Family modifier\n"
7298 "Address Family modifier\n"
7299 "Display routes conforming to the prefix-list\n"
7300 "IP prefix-list name\n")
7301{
7302 if (strncmp (argv[0], "m", 1) == 0)
7303 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7304 bgp_show_type_prefix_list);
7305
7306 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7307 bgp_show_type_prefix_list);
7308}
7309
7310#ifdef HAVE_IPV6
7311DEFUN (show_bgp_prefix_list,
7312 show_bgp_prefix_list_cmd,
7313 "show bgp prefix-list WORD",
7314 SHOW_STR
7315 BGP_STR
7316 "Display routes conforming to the prefix-list\n"
7317 "IPv6 prefix-list name\n")
7318{
7319 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7320 bgp_show_type_prefix_list);
7321}
7322
7323ALIAS (show_bgp_prefix_list,
7324 show_bgp_ipv6_prefix_list_cmd,
7325 "show bgp ipv6 prefix-list WORD",
7326 SHOW_STR
7327 BGP_STR
7328 "Address family\n"
7329 "Display routes conforming to the prefix-list\n"
7330 "IPv6 prefix-list name\n")
7331
7332/* old command */
7333DEFUN (show_ipv6_bgp_prefix_list,
7334 show_ipv6_bgp_prefix_list_cmd,
7335 "show ipv6 bgp prefix-list WORD",
7336 SHOW_STR
7337 IPV6_STR
7338 BGP_STR
7339 "Display routes matching the prefix-list\n"
7340 "IPv6 prefix-list name\n")
7341{
7342 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7343 bgp_show_type_prefix_list);
7344}
7345
7346/* old command */
7347DEFUN (show_ipv6_mbgp_prefix_list,
7348 show_ipv6_mbgp_prefix_list_cmd,
7349 "show ipv6 mbgp prefix-list WORD",
7350 SHOW_STR
7351 IPV6_STR
7352 MBGP_STR
7353 "Display routes matching the prefix-list\n"
7354 "IPv6 prefix-list name\n")
7355{
7356 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7357 bgp_show_type_prefix_list);
7358}
7359#endif /* HAVE_IPV6 */
7360
paul94f2b392005-06-28 12:44:16 +00007361static int
paulfd79ac92004-10-13 05:06:08 +00007362bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007363 safi_t safi, enum bgp_show_type type)
7364{
7365 struct as_list *as_list;
7366
7367 as_list = as_list_lookup (filter);
7368 if (as_list == NULL)
7369 {
7370 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7371 return CMD_WARNING;
7372 }
7373
ajs5a646652004-11-05 01:25:55 +00007374 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007375}
7376
7377DEFUN (show_ip_bgp_filter_list,
7378 show_ip_bgp_filter_list_cmd,
7379 "show ip bgp filter-list WORD",
7380 SHOW_STR
7381 IP_STR
7382 BGP_STR
7383 "Display routes conforming to the filter-list\n"
7384 "Regular expression access list name\n")
7385{
7386 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7387 bgp_show_type_filter_list);
7388}
7389
7390DEFUN (show_ip_bgp_flap_filter_list,
7391 show_ip_bgp_flap_filter_list_cmd,
7392 "show ip bgp flap-statistics filter-list WORD",
7393 SHOW_STR
7394 IP_STR
7395 BGP_STR
7396 "Display flap statistics of routes\n"
7397 "Display routes conforming to the filter-list\n"
7398 "Regular expression access list name\n")
7399{
7400 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7401 bgp_show_type_flap_filter_list);
7402}
7403
7404DEFUN (show_ip_bgp_ipv4_filter_list,
7405 show_ip_bgp_ipv4_filter_list_cmd,
7406 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7407 SHOW_STR
7408 IP_STR
7409 BGP_STR
7410 "Address family\n"
7411 "Address Family modifier\n"
7412 "Address Family modifier\n"
7413 "Display routes conforming to the filter-list\n"
7414 "Regular expression access list name\n")
7415{
7416 if (strncmp (argv[0], "m", 1) == 0)
7417 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7418 bgp_show_type_filter_list);
7419
7420 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7421 bgp_show_type_filter_list);
7422}
7423
7424#ifdef HAVE_IPV6
7425DEFUN (show_bgp_filter_list,
7426 show_bgp_filter_list_cmd,
7427 "show bgp filter-list WORD",
7428 SHOW_STR
7429 BGP_STR
7430 "Display routes conforming to the filter-list\n"
7431 "Regular expression access list name\n")
7432{
7433 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7434 bgp_show_type_filter_list);
7435}
7436
7437ALIAS (show_bgp_filter_list,
7438 show_bgp_ipv6_filter_list_cmd,
7439 "show bgp ipv6 filter-list WORD",
7440 SHOW_STR
7441 BGP_STR
7442 "Address family\n"
7443 "Display routes conforming to the filter-list\n"
7444 "Regular expression access list name\n")
7445
7446/* old command */
7447DEFUN (show_ipv6_bgp_filter_list,
7448 show_ipv6_bgp_filter_list_cmd,
7449 "show ipv6 bgp filter-list WORD",
7450 SHOW_STR
7451 IPV6_STR
7452 BGP_STR
7453 "Display routes conforming to the filter-list\n"
7454 "Regular expression access list name\n")
7455{
7456 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7457 bgp_show_type_filter_list);
7458}
7459
7460/* old command */
7461DEFUN (show_ipv6_mbgp_filter_list,
7462 show_ipv6_mbgp_filter_list_cmd,
7463 "show ipv6 mbgp filter-list WORD",
7464 SHOW_STR
7465 IPV6_STR
7466 MBGP_STR
7467 "Display routes conforming to the filter-list\n"
7468 "Regular expression access list name\n")
7469{
7470 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7471 bgp_show_type_filter_list);
7472}
7473#endif /* HAVE_IPV6 */
7474
paul94f2b392005-06-28 12:44:16 +00007475static int
paulfd79ac92004-10-13 05:06:08 +00007476bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007477 safi_t safi, enum bgp_show_type type)
7478{
7479 struct route_map *rmap;
7480
7481 rmap = route_map_lookup_by_name (rmap_str);
7482 if (! rmap)
7483 {
7484 vty_out (vty, "%% %s is not a valid route-map name%s",
7485 rmap_str, VTY_NEWLINE);
7486 return CMD_WARNING;
7487 }
7488
ajs5a646652004-11-05 01:25:55 +00007489 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007490}
7491
7492DEFUN (show_ip_bgp_route_map,
7493 show_ip_bgp_route_map_cmd,
7494 "show ip bgp route-map WORD",
7495 SHOW_STR
7496 IP_STR
7497 BGP_STR
7498 "Display routes matching the route-map\n"
7499 "A route-map to match on\n")
7500{
7501 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7502 bgp_show_type_route_map);
7503}
7504
7505DEFUN (show_ip_bgp_flap_route_map,
7506 show_ip_bgp_flap_route_map_cmd,
7507 "show ip bgp flap-statistics route-map WORD",
7508 SHOW_STR
7509 IP_STR
7510 BGP_STR
7511 "Display flap statistics of routes\n"
7512 "Display routes matching the route-map\n"
7513 "A route-map to match on\n")
7514{
7515 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7516 bgp_show_type_flap_route_map);
7517}
7518
7519DEFUN (show_ip_bgp_ipv4_route_map,
7520 show_ip_bgp_ipv4_route_map_cmd,
7521 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7522 SHOW_STR
7523 IP_STR
7524 BGP_STR
7525 "Address family\n"
7526 "Address Family modifier\n"
7527 "Address Family modifier\n"
7528 "Display routes matching the route-map\n"
7529 "A route-map to match on\n")
7530{
7531 if (strncmp (argv[0], "m", 1) == 0)
7532 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7533 bgp_show_type_route_map);
7534
7535 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7536 bgp_show_type_route_map);
7537}
7538
7539DEFUN (show_bgp_route_map,
7540 show_bgp_route_map_cmd,
7541 "show bgp route-map WORD",
7542 SHOW_STR
7543 BGP_STR
7544 "Display routes matching the route-map\n"
7545 "A route-map to match on\n")
7546{
7547 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7548 bgp_show_type_route_map);
7549}
7550
7551ALIAS (show_bgp_route_map,
7552 show_bgp_ipv6_route_map_cmd,
7553 "show bgp ipv6 route-map WORD",
7554 SHOW_STR
7555 BGP_STR
7556 "Address family\n"
7557 "Display routes matching the route-map\n"
7558 "A route-map to match on\n")
7559
7560DEFUN (show_ip_bgp_cidr_only,
7561 show_ip_bgp_cidr_only_cmd,
7562 "show ip bgp cidr-only",
7563 SHOW_STR
7564 IP_STR
7565 BGP_STR
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_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007570}
7571
7572DEFUN (show_ip_bgp_flap_cidr_only,
7573 show_ip_bgp_flap_cidr_only_cmd,
7574 "show ip bgp flap-statistics cidr-only",
7575 SHOW_STR
7576 IP_STR
7577 BGP_STR
7578 "Display flap statistics of routes\n"
7579 "Display only routes with non-natural netmasks\n")
7580{
7581 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007582 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007583}
7584
7585DEFUN (show_ip_bgp_ipv4_cidr_only,
7586 show_ip_bgp_ipv4_cidr_only_cmd,
7587 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7588 SHOW_STR
7589 IP_STR
7590 BGP_STR
7591 "Address family\n"
7592 "Address Family modifier\n"
7593 "Address Family modifier\n"
7594 "Display only routes with non-natural netmasks\n")
7595{
7596 if (strncmp (argv[0], "m", 1) == 0)
7597 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007598 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007599
7600 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007601 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007602}
7603
7604DEFUN (show_ip_bgp_community_all,
7605 show_ip_bgp_community_all_cmd,
7606 "show ip bgp community",
7607 SHOW_STR
7608 IP_STR
7609 BGP_STR
7610 "Display routes matching the communities\n")
7611{
7612 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007613 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007614}
7615
7616DEFUN (show_ip_bgp_ipv4_community_all,
7617 show_ip_bgp_ipv4_community_all_cmd,
7618 "show ip bgp ipv4 (unicast|multicast) community",
7619 SHOW_STR
7620 IP_STR
7621 BGP_STR
7622 "Address family\n"
7623 "Address Family modifier\n"
7624 "Address Family modifier\n"
7625 "Display routes matching the communities\n")
7626{
7627 if (strncmp (argv[0], "m", 1) == 0)
7628 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007629 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007630
7631 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007632 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007633}
7634
7635#ifdef HAVE_IPV6
7636DEFUN (show_bgp_community_all,
7637 show_bgp_community_all_cmd,
7638 "show bgp community",
7639 SHOW_STR
7640 BGP_STR
7641 "Display routes matching the communities\n")
7642{
7643 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007644 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007645}
7646
7647ALIAS (show_bgp_community_all,
7648 show_bgp_ipv6_community_all_cmd,
7649 "show bgp ipv6 community",
7650 SHOW_STR
7651 BGP_STR
7652 "Address family\n"
7653 "Display routes matching the communities\n")
7654
7655/* old command */
7656DEFUN (show_ipv6_bgp_community_all,
7657 show_ipv6_bgp_community_all_cmd,
7658 "show ipv6 bgp community",
7659 SHOW_STR
7660 IPV6_STR
7661 BGP_STR
7662 "Display routes matching the communities\n")
7663{
7664 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007665 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007666}
7667
7668/* old command */
7669DEFUN (show_ipv6_mbgp_community_all,
7670 show_ipv6_mbgp_community_all_cmd,
7671 "show ipv6 mbgp community",
7672 SHOW_STR
7673 IPV6_STR
7674 MBGP_STR
7675 "Display routes matching the communities\n")
7676{
7677 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007678 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007679}
7680#endif /* HAVE_IPV6 */
7681
paul94f2b392005-06-28 12:44:16 +00007682static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007683bgp_show_community (struct vty *vty, const char *view_name, int argc,
7684 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007685{
7686 struct community *com;
7687 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007688 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007689 int i;
7690 char *str;
7691 int first = 0;
7692
Michael Lambert95cbbd22010-07-23 14:43:04 -04007693 /* BGP structure lookup */
7694 if (view_name)
7695 {
7696 bgp = bgp_lookup_by_name (view_name);
7697 if (bgp == NULL)
7698 {
7699 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7700 return CMD_WARNING;
7701 }
7702 }
7703 else
7704 {
7705 bgp = bgp_get_default ();
7706 if (bgp == NULL)
7707 {
7708 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7709 return CMD_WARNING;
7710 }
7711 }
7712
paul718e3742002-12-13 20:15:29 +00007713 b = buffer_new (1024);
7714 for (i = 0; i < argc; i++)
7715 {
7716 if (first)
7717 buffer_putc (b, ' ');
7718 else
7719 {
7720 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7721 continue;
7722 first = 1;
7723 }
7724
7725 buffer_putstr (b, argv[i]);
7726 }
7727 buffer_putc (b, '\0');
7728
7729 str = buffer_getstr (b);
7730 buffer_free (b);
7731
7732 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007733 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007734 if (! com)
7735 {
7736 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7737 return CMD_WARNING;
7738 }
7739
Michael Lambert95cbbd22010-07-23 14:43:04 -04007740 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007741 (exact ? bgp_show_type_community_exact :
7742 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007743}
7744
7745DEFUN (show_ip_bgp_community,
7746 show_ip_bgp_community_cmd,
7747 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7748 SHOW_STR
7749 IP_STR
7750 BGP_STR
7751 "Display routes matching the communities\n"
7752 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n")
7756{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007757 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007758}
7759
7760ALIAS (show_ip_bgp_community,
7761 show_ip_bgp_community2_cmd,
7762 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7763 SHOW_STR
7764 IP_STR
7765 BGP_STR
7766 "Display routes matching the communities\n"
7767 "community number\n"
7768 "Do not send outside local AS (well-known community)\n"
7769 "Do not advertise to any peer (well-known community)\n"
7770 "Do not export to next AS (well-known community)\n"
7771 "community number\n"
7772 "Do not send outside local AS (well-known community)\n"
7773 "Do not advertise to any peer (well-known community)\n"
7774 "Do not export to next AS (well-known community)\n")
7775
7776ALIAS (show_ip_bgp_community,
7777 show_ip_bgp_community3_cmd,
7778 "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)",
7779 SHOW_STR
7780 IP_STR
7781 BGP_STR
7782 "Display routes matching the communities\n"
7783 "community number\n"
7784 "Do not send outside local AS (well-known community)\n"
7785 "Do not advertise to any peer (well-known community)\n"
7786 "Do not export to next AS (well-known community)\n"
7787 "community number\n"
7788 "Do not send outside local AS (well-known community)\n"
7789 "Do not advertise to any peer (well-known community)\n"
7790 "Do not export to next AS (well-known community)\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n")
7795
7796ALIAS (show_ip_bgp_community,
7797 show_ip_bgp_community4_cmd,
7798 "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)",
7799 SHOW_STR
7800 IP_STR
7801 BGP_STR
7802 "Display routes matching the communities\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n"
7807 "community number\n"
7808 "Do not send outside local AS (well-known community)\n"
7809 "Do not advertise to any peer (well-known community)\n"
7810 "Do not export to next AS (well-known community)\n"
7811 "community number\n"
7812 "Do not send outside local AS (well-known community)\n"
7813 "Do not advertise to any peer (well-known community)\n"
7814 "Do not export to next AS (well-known community)\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n")
7819
7820DEFUN (show_ip_bgp_ipv4_community,
7821 show_ip_bgp_ipv4_community_cmd,
7822 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7823 SHOW_STR
7824 IP_STR
7825 BGP_STR
7826 "Address family\n"
7827 "Address Family modifier\n"
7828 "Address Family modifier\n"
7829 "Display routes matching the communities\n"
7830 "community number\n"
7831 "Do not send outside local AS (well-known community)\n"
7832 "Do not advertise to any peer (well-known community)\n"
7833 "Do not export to next AS (well-known community)\n")
7834{
7835 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007836 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007837
Michael Lambert95cbbd22010-07-23 14:43:04 -04007838 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007839}
7840
7841ALIAS (show_ip_bgp_ipv4_community,
7842 show_ip_bgp_ipv4_community2_cmd,
7843 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "Address family\n"
7848 "Address Family modifier\n"
7849 "Address Family modifier\n"
7850 "Display routes matching the communities\n"
7851 "community number\n"
7852 "Do not send outside local AS (well-known community)\n"
7853 "Do not advertise to any peer (well-known community)\n"
7854 "Do not export to next AS (well-known community)\n"
7855 "community number\n"
7856 "Do not send outside local AS (well-known community)\n"
7857 "Do not advertise to any peer (well-known community)\n"
7858 "Do not export to next AS (well-known community)\n")
7859
7860ALIAS (show_ip_bgp_ipv4_community,
7861 show_ip_bgp_ipv4_community3_cmd,
7862 "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)",
7863 SHOW_STR
7864 IP_STR
7865 BGP_STR
7866 "Address family\n"
7867 "Address Family modifier\n"
7868 "Address Family modifier\n"
7869 "Display routes matching the communities\n"
7870 "community number\n"
7871 "Do not send outside local AS (well-known community)\n"
7872 "Do not advertise to any peer (well-known community)\n"
7873 "Do not export to next AS (well-known community)\n"
7874 "community number\n"
7875 "Do not send outside local AS (well-known community)\n"
7876 "Do not advertise to any peer (well-known community)\n"
7877 "Do not export to next AS (well-known community)\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n")
7882
7883ALIAS (show_ip_bgp_ipv4_community,
7884 show_ip_bgp_ipv4_community4_cmd,
7885 "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)",
7886 SHOW_STR
7887 IP_STR
7888 BGP_STR
7889 "Address family\n"
7890 "Address Family modifier\n"
7891 "Address Family modifier\n"
7892 "Display routes matching the communities\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n"
7897 "community number\n"
7898 "Do not send outside local AS (well-known community)\n"
7899 "Do not advertise to any peer (well-known community)\n"
7900 "Do not export to next AS (well-known community)\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n")
7909
Michael Lambert95cbbd22010-07-23 14:43:04 -04007910DEFUN (show_bgp_view_afi_safi_community_all,
7911 show_bgp_view_afi_safi_community_all_cmd,
7912#ifdef HAVE_IPV6
7913 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7914#else
7915 "show bgp view WORD ipv4 (unicast|multicast) community",
7916#endif
7917 SHOW_STR
7918 BGP_STR
7919 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007920 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007921 "Address family\n"
7922#ifdef HAVE_IPV6
7923 "Address family\n"
7924#endif
7925 "Address Family modifier\n"
7926 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007927 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007928{
7929 int afi;
7930 int safi;
7931 struct bgp *bgp;
7932
7933 /* BGP structure lookup. */
7934 bgp = bgp_lookup_by_name (argv[0]);
7935 if (bgp == NULL)
7936 {
7937 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7938 return CMD_WARNING;
7939 }
7940
7941#ifdef HAVE_IPV6
7942 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7943 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7944#else
7945 afi = AFI_IP;
7946 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7947#endif
7948 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7949}
7950
7951DEFUN (show_bgp_view_afi_safi_community,
7952 show_bgp_view_afi_safi_community_cmd,
7953#ifdef HAVE_IPV6
7954 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7955#else
7956 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7957#endif
7958 SHOW_STR
7959 BGP_STR
7960 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007961 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007962 "Address family\n"
7963#ifdef HAVE_IPV6
7964 "Address family\n"
7965#endif
7966 "Address family modifier\n"
7967 "Address family modifier\n"
7968 "Display routes matching the communities\n"
7969 "community number\n"
7970 "Do not send outside local AS (well-known community)\n"
7971 "Do not advertise to any peer (well-known community)\n"
7972 "Do not export to next AS (well-known community)\n")
7973{
7974 int afi;
7975 int safi;
7976
7977#ifdef HAVE_IPV6
7978 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7979 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7980 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7981#else
7982 afi = AFI_IP;
7983 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7984 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7985#endif
7986}
7987
7988ALIAS (show_bgp_view_afi_safi_community,
7989 show_bgp_view_afi_safi_community2_cmd,
7990#ifdef HAVE_IPV6
7991 "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)",
7992#else
7993 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7994#endif
7995 SHOW_STR
7996 BGP_STR
7997 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007998 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007999 "Address family\n"
8000#ifdef HAVE_IPV6
8001 "Address family\n"
8002#endif
8003 "Address family modifier\n"
8004 "Address family modifier\n"
8005 "Display routes matching the communities\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n")
8014
8015ALIAS (show_bgp_view_afi_safi_community,
8016 show_bgp_view_afi_safi_community3_cmd,
8017#ifdef HAVE_IPV6
8018 "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)",
8019#else
8020 "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)",
8021#endif
8022 SHOW_STR
8023 BGP_STR
8024 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008025 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008026 "Address family\n"
8027#ifdef HAVE_IPV6
8028 "Address family\n"
8029#endif
8030 "Address family modifier\n"
8031 "Address family modifier\n"
8032 "Display routes matching the communities\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
8046ALIAS (show_bgp_view_afi_safi_community,
8047 show_bgp_view_afi_safi_community4_cmd,
8048#ifdef HAVE_IPV6
8049 "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)",
8050#else
8051 "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)",
8052#endif
8053 SHOW_STR
8054 BGP_STR
8055 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008056 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008057 "Address family\n"
8058#ifdef HAVE_IPV6
8059 "Address family\n"
8060#endif
8061 "Address family modifier\n"
8062 "Address family modifier\n"
8063 "Display routes matching the communities\n"
8064 "community number\n"
8065 "Do not send outside local AS (well-known community)\n"
8066 "Do not advertise to any peer (well-known community)\n"
8067 "Do not export to next AS (well-known community)\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n")
8080
paul718e3742002-12-13 20:15:29 +00008081DEFUN (show_ip_bgp_community_exact,
8082 show_ip_bgp_community_exact_cmd,
8083 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8084 SHOW_STR
8085 IP_STR
8086 BGP_STR
8087 "Display routes matching the communities\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n"
8092 "Exact match of the communities")
8093{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008094 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008095}
8096
8097ALIAS (show_ip_bgp_community_exact,
8098 show_ip_bgp_community2_exact_cmd,
8099 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8100 SHOW_STR
8101 IP_STR
8102 BGP_STR
8103 "Display routes matching the communities\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "Exact match of the communities")
8113
8114ALIAS (show_ip_bgp_community_exact,
8115 show_ip_bgp_community3_exact_cmd,
8116 "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",
8117 SHOW_STR
8118 IP_STR
8119 BGP_STR
8120 "Display routes matching the communities\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n"
8125 "community number\n"
8126 "Do not send outside local AS (well-known community)\n"
8127 "Do not advertise to any peer (well-known community)\n"
8128 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8134
8135ALIAS (show_ip_bgp_community_exact,
8136 show_ip_bgp_community4_exact_cmd,
8137 "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",
8138 SHOW_STR
8139 IP_STR
8140 BGP_STR
8141 "Display routes matching the communities\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n"
8146 "community number\n"
8147 "Do not send outside local AS (well-known community)\n"
8148 "Do not advertise to any peer (well-known community)\n"
8149 "Do not export to next AS (well-known community)\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "community number\n"
8155 "Do not send outside local AS (well-known community)\n"
8156 "Do not advertise to any peer (well-known community)\n"
8157 "Do not export to next AS (well-known community)\n"
8158 "Exact match of the communities")
8159
8160DEFUN (show_ip_bgp_ipv4_community_exact,
8161 show_ip_bgp_ipv4_community_exact_cmd,
8162 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8163 SHOW_STR
8164 IP_STR
8165 BGP_STR
8166 "Address family\n"
8167 "Address Family modifier\n"
8168 "Address Family modifier\n"
8169 "Display routes matching the communities\n"
8170 "community number\n"
8171 "Do not send outside local AS (well-known community)\n"
8172 "Do not advertise to any peer (well-known community)\n"
8173 "Do not export to next AS (well-known community)\n"
8174 "Exact match of the communities")
8175{
8176 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008177 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008178
Michael Lambert95cbbd22010-07-23 14:43:04 -04008179 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008180}
8181
8182ALIAS (show_ip_bgp_ipv4_community_exact,
8183 show_ip_bgp_ipv4_community2_exact_cmd,
8184 "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",
8185 SHOW_STR
8186 IP_STR
8187 BGP_STR
8188 "Address family\n"
8189 "Address Family modifier\n"
8190 "Address Family modifier\n"
8191 "Display routes matching the communities\n"
8192 "community number\n"
8193 "Do not send outside local AS (well-known community)\n"
8194 "Do not advertise to any peer (well-known community)\n"
8195 "Do not export to next AS (well-known community)\n"
8196 "community number\n"
8197 "Do not send outside local AS (well-known community)\n"
8198 "Do not advertise to any peer (well-known community)\n"
8199 "Do not export to next AS (well-known community)\n"
8200 "Exact match of the communities")
8201
8202ALIAS (show_ip_bgp_ipv4_community_exact,
8203 show_ip_bgp_ipv4_community3_exact_cmd,
8204 "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",
8205 SHOW_STR
8206 IP_STR
8207 BGP_STR
8208 "Address family\n"
8209 "Address Family modifier\n"
8210 "Address Family modifier\n"
8211 "Display routes matching the communities\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "community number\n"
8221 "Do not send outside local AS (well-known community)\n"
8222 "Do not advertise to any peer (well-known community)\n"
8223 "Do not export to next AS (well-known community)\n"
8224 "Exact match of the communities")
8225
8226ALIAS (show_ip_bgp_ipv4_community_exact,
8227 show_ip_bgp_ipv4_community4_exact_cmd,
8228 "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",
8229 SHOW_STR
8230 IP_STR
8231 BGP_STR
8232 "Address family\n"
8233 "Address Family modifier\n"
8234 "Address Family modifier\n"
8235 "Display routes matching the communities\n"
8236 "community number\n"
8237 "Do not send outside local AS (well-known community)\n"
8238 "Do not advertise to any peer (well-known community)\n"
8239 "Do not export to next AS (well-known community)\n"
8240 "community number\n"
8241 "Do not send outside local AS (well-known community)\n"
8242 "Do not advertise to any peer (well-known community)\n"
8243 "Do not export to next AS (well-known community)\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8253
8254#ifdef HAVE_IPV6
8255DEFUN (show_bgp_community,
8256 show_bgp_community_cmd,
8257 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8258 SHOW_STR
8259 BGP_STR
8260 "Display routes matching the communities\n"
8261 "community number\n"
8262 "Do not send outside local AS (well-known community)\n"
8263 "Do not advertise to any peer (well-known community)\n"
8264 "Do not export to next AS (well-known community)\n")
8265{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008266 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008267}
8268
8269ALIAS (show_bgp_community,
8270 show_bgp_ipv6_community_cmd,
8271 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8272 SHOW_STR
8273 BGP_STR
8274 "Address family\n"
8275 "Display routes matching the communities\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\n")
8280
8281ALIAS (show_bgp_community,
8282 show_bgp_community2_cmd,
8283 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8284 SHOW_STR
8285 BGP_STR
8286 "Display routes matching the communities\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n")
8295
8296ALIAS (show_bgp_community,
8297 show_bgp_ipv6_community2_cmd,
8298 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8299 SHOW_STR
8300 BGP_STR
8301 "Address family\n"
8302 "Display routes matching the communities\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n"
8307 "community number\n"
8308 "Do not send outside local AS (well-known community)\n"
8309 "Do not advertise to any peer (well-known community)\n"
8310 "Do not export to next AS (well-known community)\n")
8311
8312ALIAS (show_bgp_community,
8313 show_bgp_community3_cmd,
8314 "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)",
8315 SHOW_STR
8316 BGP_STR
8317 "Display routes matching the communities\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n")
8330
8331ALIAS (show_bgp_community,
8332 show_bgp_ipv6_community3_cmd,
8333 "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)",
8334 SHOW_STR
8335 BGP_STR
8336 "Address family\n"
8337 "Display routes matching the communities\n"
8338 "community number\n"
8339 "Do not send outside local AS (well-known community)\n"
8340 "Do not advertise to any peer (well-known community)\n"
8341 "Do not export to next AS (well-known community)\n"
8342 "community number\n"
8343 "Do not send outside local AS (well-known community)\n"
8344 "Do not advertise to any peer (well-known community)\n"
8345 "Do not export to next AS (well-known community)\n"
8346 "community number\n"
8347 "Do not send outside local AS (well-known community)\n"
8348 "Do not advertise to any peer (well-known community)\n"
8349 "Do not export to next AS (well-known community)\n")
8350
8351ALIAS (show_bgp_community,
8352 show_bgp_community4_cmd,
8353 "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)",
8354 SHOW_STR
8355 BGP_STR
8356 "Display routes matching the communities\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\n"
8365 "community number\n"
8366 "Do not send outside local AS (well-known community)\n"
8367 "Do not advertise to any peer (well-known community)\n"
8368 "Do not export to next AS (well-known community)\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n")
8373
8374ALIAS (show_bgp_community,
8375 show_bgp_ipv6_community4_cmd,
8376 "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)",
8377 SHOW_STR
8378 BGP_STR
8379 "Address family\n"
8380 "Display routes matching the communities\n"
8381 "community number\n"
8382 "Do not send outside local AS (well-known community)\n"
8383 "Do not advertise to any peer (well-known community)\n"
8384 "Do not export to next AS (well-known community)\n"
8385 "community number\n"
8386 "Do not send outside local AS (well-known community)\n"
8387 "Do not advertise to any peer (well-known community)\n"
8388 "Do not export to next AS (well-known community)\n"
8389 "community number\n"
8390 "Do not send outside local AS (well-known community)\n"
8391 "Do not advertise to any peer (well-known community)\n"
8392 "Do not export to next AS (well-known community)\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
8398/* old command */
8399DEFUN (show_ipv6_bgp_community,
8400 show_ipv6_bgp_community_cmd,
8401 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8402 SHOW_STR
8403 IPV6_STR
8404 BGP_STR
8405 "Display routes matching the communities\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n")
8410{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008411 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008412}
8413
8414/* old command */
8415ALIAS (show_ipv6_bgp_community,
8416 show_ipv6_bgp_community2_cmd,
8417 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8418 SHOW_STR
8419 IPV6_STR
8420 BGP_STR
8421 "Display routes matching the communities\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n")
8430
8431/* old command */
8432ALIAS (show_ipv6_bgp_community,
8433 show_ipv6_bgp_community3_cmd,
8434 "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)",
8435 SHOW_STR
8436 IPV6_STR
8437 BGP_STR
8438 "Display routes matching the communities\n"
8439 "community number\n"
8440 "Do not send outside local AS (well-known community)\n"
8441 "Do not advertise to any peer (well-known community)\n"
8442 "Do not export to next AS (well-known community)\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n")
8451
8452/* old command */
8453ALIAS (show_ipv6_bgp_community,
8454 show_ipv6_bgp_community4_cmd,
8455 "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)",
8456 SHOW_STR
8457 IPV6_STR
8458 BGP_STR
8459 "Display routes matching the communities\n"
8460 "community number\n"
8461 "Do not send outside local AS (well-known community)\n"
8462 "Do not advertise to any peer (well-known community)\n"
8463 "Do not export to next AS (well-known community)\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n")
8476
8477DEFUN (show_bgp_community_exact,
8478 show_bgp_community_exact_cmd,
8479 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8480 SHOW_STR
8481 BGP_STR
8482 "Display routes matching the communities\n"
8483 "community number\n"
8484 "Do not send outside local AS (well-known community)\n"
8485 "Do not advertise to any peer (well-known community)\n"
8486 "Do not export to next AS (well-known community)\n"
8487 "Exact match of the communities")
8488{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008489 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008490}
8491
8492ALIAS (show_bgp_community_exact,
8493 show_bgp_ipv6_community_exact_cmd,
8494 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8495 SHOW_STR
8496 BGP_STR
8497 "Address family\n"
8498 "Display routes matching the communities\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "Exact match of the communities")
8504
8505ALIAS (show_bgp_community_exact,
8506 show_bgp_community2_exact_cmd,
8507 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8508 SHOW_STR
8509 BGP_STR
8510 "Display routes matching the communities\n"
8511 "community number\n"
8512 "Do not send outside local AS (well-known community)\n"
8513 "Do not advertise to any peer (well-known community)\n"
8514 "Do not export to next AS (well-known community)\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "Exact match of the communities")
8520
8521ALIAS (show_bgp_community_exact,
8522 show_bgp_ipv6_community2_exact_cmd,
8523 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8524 SHOW_STR
8525 BGP_STR
8526 "Address family\n"
8527 "Display routes matching the communities\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n"
8536 "Exact match of the communities")
8537
8538ALIAS (show_bgp_community_exact,
8539 show_bgp_community3_exact_cmd,
8540 "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",
8541 SHOW_STR
8542 BGP_STR
8543 "Display routes matching the communities\n"
8544 "community number\n"
8545 "Do not send outside local AS (well-known community)\n"
8546 "Do not advertise to any peer (well-known community)\n"
8547 "Do not export to next AS (well-known community)\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "Exact match of the communities")
8557
8558ALIAS (show_bgp_community_exact,
8559 show_bgp_ipv6_community3_exact_cmd,
8560 "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",
8561 SHOW_STR
8562 BGP_STR
8563 "Address family\n"
8564 "Display routes matching the communities\n"
8565 "community number\n"
8566 "Do not send outside local AS (well-known community)\n"
8567 "Do not advertise to any peer (well-known community)\n"
8568 "Do not export to next AS (well-known community)\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "Exact match of the communities")
8578
8579ALIAS (show_bgp_community_exact,
8580 show_bgp_community4_exact_cmd,
8581 "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",
8582 SHOW_STR
8583 BGP_STR
8584 "Display routes matching the communities\n"
8585 "community number\n"
8586 "Do not send outside local AS (well-known community)\n"
8587 "Do not advertise to any peer (well-known community)\n"
8588 "Do not export to next AS (well-known community)\n"
8589 "community number\n"
8590 "Do not send outside local AS (well-known community)\n"
8591 "Do not advertise to any peer (well-known community)\n"
8592 "Do not export to next AS (well-known community)\n"
8593 "community number\n"
8594 "Do not send outside local AS (well-known community)\n"
8595 "Do not advertise to any peer (well-known community)\n"
8596 "Do not export to next AS (well-known community)\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "Exact match of the communities")
8602
8603ALIAS (show_bgp_community_exact,
8604 show_bgp_ipv6_community4_exact_cmd,
8605 "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",
8606 SHOW_STR
8607 BGP_STR
8608 "Address family\n"
8609 "Display routes matching the communities\n"
8610 "community number\n"
8611 "Do not send outside local AS (well-known community)\n"
8612 "Do not advertise to any peer (well-known community)\n"
8613 "Do not export to next AS (well-known community)\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n"
8626 "Exact match of the communities")
8627
8628/* old command */
8629DEFUN (show_ipv6_bgp_community_exact,
8630 show_ipv6_bgp_community_exact_cmd,
8631 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8632 SHOW_STR
8633 IPV6_STR
8634 BGP_STR
8635 "Display routes matching the communities\n"
8636 "community number\n"
8637 "Do not send outside local AS (well-known community)\n"
8638 "Do not advertise to any peer (well-known community)\n"
8639 "Do not export to next AS (well-known community)\n"
8640 "Exact match of the communities")
8641{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008642 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008643}
8644
8645/* old command */
8646ALIAS (show_ipv6_bgp_community_exact,
8647 show_ipv6_bgp_community2_exact_cmd,
8648 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8649 SHOW_STR
8650 IPV6_STR
8651 BGP_STR
8652 "Display routes matching the communities\n"
8653 "community number\n"
8654 "Do not send outside local AS (well-known community)\n"
8655 "Do not advertise to any peer (well-known community)\n"
8656 "Do not export to next AS (well-known community)\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\n"
8661 "Exact match of the communities")
8662
8663/* old command */
8664ALIAS (show_ipv6_bgp_community_exact,
8665 show_ipv6_bgp_community3_exact_cmd,
8666 "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",
8667 SHOW_STR
8668 IPV6_STR
8669 BGP_STR
8670 "Display routes matching the communities\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "Exact match of the communities")
8684
8685/* old command */
8686ALIAS (show_ipv6_bgp_community_exact,
8687 show_ipv6_bgp_community4_exact_cmd,
8688 "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",
8689 SHOW_STR
8690 IPV6_STR
8691 BGP_STR
8692 "Display routes matching the communities\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n"
8709 "Exact match of the communities")
8710
8711/* old command */
8712DEFUN (show_ipv6_mbgp_community,
8713 show_ipv6_mbgp_community_cmd,
8714 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8715 SHOW_STR
8716 IPV6_STR
8717 MBGP_STR
8718 "Display routes matching the communities\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n")
8723{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008724 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008725}
8726
8727/* old command */
8728ALIAS (show_ipv6_mbgp_community,
8729 show_ipv6_mbgp_community2_cmd,
8730 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8731 SHOW_STR
8732 IPV6_STR
8733 MBGP_STR
8734 "Display routes matching the communities\n"
8735 "community number\n"
8736 "Do not send outside local AS (well-known community)\n"
8737 "Do not advertise to any peer (well-known community)\n"
8738 "Do not export to next AS (well-known community)\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
8744/* old command */
8745ALIAS (show_ipv6_mbgp_community,
8746 show_ipv6_mbgp_community3_cmd,
8747 "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)",
8748 SHOW_STR
8749 IPV6_STR
8750 MBGP_STR
8751 "Display routes matching the communities\n"
8752 "community number\n"
8753 "Do not send outside local AS (well-known community)\n"
8754 "Do not advertise to any peer (well-known community)\n"
8755 "Do not export to next AS (well-known community)\n"
8756 "community number\n"
8757 "Do not send outside local AS (well-known community)\n"
8758 "Do not advertise to any peer (well-known community)\n"
8759 "Do not export to next AS (well-known community)\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
8765/* old command */
8766ALIAS (show_ipv6_mbgp_community,
8767 show_ipv6_mbgp_community4_cmd,
8768 "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)",
8769 SHOW_STR
8770 IPV6_STR
8771 MBGP_STR
8772 "Display routes matching the communities\n"
8773 "community number\n"
8774 "Do not send outside local AS (well-known community)\n"
8775 "Do not advertise to any peer (well-known community)\n"
8776 "Do not export to next AS (well-known community)\n"
8777 "community number\n"
8778 "Do not send outside local AS (well-known community)\n"
8779 "Do not advertise to any peer (well-known community)\n"
8780 "Do not export to next AS (well-known community)\n"
8781 "community number\n"
8782 "Do not send outside local AS (well-known community)\n"
8783 "Do not advertise to any peer (well-known community)\n"
8784 "Do not export to next AS (well-known community)\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
8790/* old command */
8791DEFUN (show_ipv6_mbgp_community_exact,
8792 show_ipv6_mbgp_community_exact_cmd,
8793 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8794 SHOW_STR
8795 IPV6_STR
8796 MBGP_STR
8797 "Display routes matching the communities\n"
8798 "community number\n"
8799 "Do not send outside local AS (well-known community)\n"
8800 "Do not advertise to any peer (well-known community)\n"
8801 "Do not export to next AS (well-known community)\n"
8802 "Exact match of the communities")
8803{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008804 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008805}
8806
8807/* old command */
8808ALIAS (show_ipv6_mbgp_community_exact,
8809 show_ipv6_mbgp_community2_exact_cmd,
8810 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8811 SHOW_STR
8812 IPV6_STR
8813 MBGP_STR
8814 "Display routes matching the communities\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "Exact match of the communities")
8824
8825/* old command */
8826ALIAS (show_ipv6_mbgp_community_exact,
8827 show_ipv6_mbgp_community3_exact_cmd,
8828 "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",
8829 SHOW_STR
8830 IPV6_STR
8831 MBGP_STR
8832 "Display routes matching the communities\n"
8833 "community number\n"
8834 "Do not send outside local AS (well-known community)\n"
8835 "Do not advertise to any peer (well-known community)\n"
8836 "Do not export to next AS (well-known community)\n"
8837 "community number\n"
8838 "Do not send outside local AS (well-known community)\n"
8839 "Do not advertise to any peer (well-known community)\n"
8840 "Do not export to next AS (well-known community)\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "Exact match of the communities")
8846
8847/* old command */
8848ALIAS (show_ipv6_mbgp_community_exact,
8849 show_ipv6_mbgp_community4_exact_cmd,
8850 "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",
8851 SHOW_STR
8852 IPV6_STR
8853 MBGP_STR
8854 "Display routes matching the communities\n"
8855 "community number\n"
8856 "Do not send outside local AS (well-known community)\n"
8857 "Do not advertise to any peer (well-known community)\n"
8858 "Do not export to next AS (well-known community)\n"
8859 "community number\n"
8860 "Do not send outside local AS (well-known community)\n"
8861 "Do not advertise to any peer (well-known community)\n"
8862 "Do not export to next AS (well-known community)\n"
8863 "community number\n"
8864 "Do not send outside local AS (well-known community)\n"
8865 "Do not advertise to any peer (well-known community)\n"
8866 "Do not export to next AS (well-known community)\n"
8867 "community number\n"
8868 "Do not send outside local AS (well-known community)\n"
8869 "Do not advertise to any peer (well-known community)\n"
8870 "Do not export to next AS (well-known community)\n"
8871 "Exact match of the communities")
8872#endif /* HAVE_IPV6 */
8873
paul94f2b392005-06-28 12:44:16 +00008874static int
paulfd79ac92004-10-13 05:06:08 +00008875bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008876 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008877{
8878 struct community_list *list;
8879
hassofee6e4e2005-02-02 16:29:31 +00008880 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008881 if (list == NULL)
8882 {
8883 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8884 VTY_NEWLINE);
8885 return CMD_WARNING;
8886 }
8887
ajs5a646652004-11-05 01:25:55 +00008888 return bgp_show (vty, NULL, afi, safi,
8889 (exact ? bgp_show_type_community_list_exact :
8890 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008891}
8892
8893DEFUN (show_ip_bgp_community_list,
8894 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008895 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008896 SHOW_STR
8897 IP_STR
8898 BGP_STR
8899 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008900 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008901 "community-list name\n")
8902{
8903 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8904}
8905
8906DEFUN (show_ip_bgp_ipv4_community_list,
8907 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008908 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008909 SHOW_STR
8910 IP_STR
8911 BGP_STR
8912 "Address family\n"
8913 "Address Family modifier\n"
8914 "Address Family modifier\n"
8915 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008916 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008917 "community-list name\n")
8918{
8919 if (strncmp (argv[0], "m", 1) == 0)
8920 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8921
8922 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8923}
8924
8925DEFUN (show_ip_bgp_community_list_exact,
8926 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008927 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008928 SHOW_STR
8929 IP_STR
8930 BGP_STR
8931 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008932 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008933 "community-list name\n"
8934 "Exact match of the communities\n")
8935{
8936 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8937}
8938
8939DEFUN (show_ip_bgp_ipv4_community_list_exact,
8940 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008941 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008942 SHOW_STR
8943 IP_STR
8944 BGP_STR
8945 "Address family\n"
8946 "Address Family modifier\n"
8947 "Address Family modifier\n"
8948 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008949 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008950 "community-list name\n"
8951 "Exact match of the communities\n")
8952{
8953 if (strncmp (argv[0], "m", 1) == 0)
8954 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8955
8956 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8957}
8958
8959#ifdef HAVE_IPV6
8960DEFUN (show_bgp_community_list,
8961 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008962 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008963 SHOW_STR
8964 BGP_STR
8965 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008966 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008967 "community-list name\n")
8968{
8969 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8970}
8971
8972ALIAS (show_bgp_community_list,
8973 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008974 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008975 SHOW_STR
8976 BGP_STR
8977 "Address family\n"
8978 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008979 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008980 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008981
8982/* old command */
8983DEFUN (show_ipv6_bgp_community_list,
8984 show_ipv6_bgp_community_list_cmd,
8985 "show ipv6 bgp community-list WORD",
8986 SHOW_STR
8987 IPV6_STR
8988 BGP_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_UNICAST);
8993}
8994
8995/* old command */
8996DEFUN (show_ipv6_mbgp_community_list,
8997 show_ipv6_mbgp_community_list_cmd,
8998 "show ipv6 mbgp community-list WORD",
8999 SHOW_STR
9000 IPV6_STR
9001 MBGP_STR
9002 "Display routes matching the community-list\n"
9003 "community-list name\n")
9004{
9005 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9006}
9007
9008DEFUN (show_bgp_community_list_exact,
9009 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009010 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009011 SHOW_STR
9012 BGP_STR
9013 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009014 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009015 "community-list name\n"
9016 "Exact match of the communities\n")
9017{
9018 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9019}
9020
9021ALIAS (show_bgp_community_list_exact,
9022 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009023 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009024 SHOW_STR
9025 BGP_STR
9026 "Address family\n"
9027 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009028 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009029 "community-list name\n"
9030 "Exact match of the communities\n")
9031
9032/* old command */
9033DEFUN (show_ipv6_bgp_community_list_exact,
9034 show_ipv6_bgp_community_list_exact_cmd,
9035 "show ipv6 bgp community-list WORD exact-match",
9036 SHOW_STR
9037 IPV6_STR
9038 BGP_STR
9039 "Display routes matching the community-list\n"
9040 "community-list name\n"
9041 "Exact match of the communities\n")
9042{
9043 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9044}
9045
9046/* old command */
9047DEFUN (show_ipv6_mbgp_community_list_exact,
9048 show_ipv6_mbgp_community_list_exact_cmd,
9049 "show ipv6 mbgp community-list WORD exact-match",
9050 SHOW_STR
9051 IPV6_STR
9052 MBGP_STR
9053 "Display routes matching the community-list\n"
9054 "community-list name\n"
9055 "Exact match of the communities\n")
9056{
9057 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9058}
9059#endif /* HAVE_IPV6 */
9060
paul94f2b392005-06-28 12:44:16 +00009061static int
paulfd79ac92004-10-13 05:06:08 +00009062bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009063 safi_t safi, enum bgp_show_type type)
9064{
9065 int ret;
9066 struct prefix *p;
9067
9068 p = prefix_new();
9069
9070 ret = str2prefix (prefix, p);
9071 if (! ret)
9072 {
9073 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9074 return CMD_WARNING;
9075 }
9076
ajs5a646652004-11-05 01:25:55 +00009077 ret = bgp_show (vty, NULL, afi, safi, type, p);
9078 prefix_free(p);
9079 return ret;
paul718e3742002-12-13 20:15:29 +00009080}
9081
9082DEFUN (show_ip_bgp_prefix_longer,
9083 show_ip_bgp_prefix_longer_cmd,
9084 "show ip bgp A.B.C.D/M longer-prefixes",
9085 SHOW_STR
9086 IP_STR
9087 BGP_STR
9088 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9089 "Display route and more specific routes\n")
9090{
9091 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9092 bgp_show_type_prefix_longer);
9093}
9094
9095DEFUN (show_ip_bgp_flap_prefix_longer,
9096 show_ip_bgp_flap_prefix_longer_cmd,
9097 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9098 SHOW_STR
9099 IP_STR
9100 BGP_STR
9101 "Display flap statistics of routes\n"
9102 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9103 "Display route and more specific routes\n")
9104{
9105 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9106 bgp_show_type_flap_prefix_longer);
9107}
9108
9109DEFUN (show_ip_bgp_ipv4_prefix_longer,
9110 show_ip_bgp_ipv4_prefix_longer_cmd,
9111 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9112 SHOW_STR
9113 IP_STR
9114 BGP_STR
9115 "Address family\n"
9116 "Address Family modifier\n"
9117 "Address Family modifier\n"
9118 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9119 "Display route and more specific routes\n")
9120{
9121 if (strncmp (argv[0], "m", 1) == 0)
9122 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9123 bgp_show_type_prefix_longer);
9124
9125 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9126 bgp_show_type_prefix_longer);
9127}
9128
9129DEFUN (show_ip_bgp_flap_address,
9130 show_ip_bgp_flap_address_cmd,
9131 "show ip bgp flap-statistics A.B.C.D",
9132 SHOW_STR
9133 IP_STR
9134 BGP_STR
9135 "Display flap statistics of routes\n"
9136 "Network in the BGP routing table to display\n")
9137{
9138 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9139 bgp_show_type_flap_address);
9140}
9141
9142DEFUN (show_ip_bgp_flap_prefix,
9143 show_ip_bgp_flap_prefix_cmd,
9144 "show ip bgp flap-statistics A.B.C.D/M",
9145 SHOW_STR
9146 IP_STR
9147 BGP_STR
9148 "Display flap statistics of routes\n"
9149 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9150{
9151 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9152 bgp_show_type_flap_prefix);
9153}
9154#ifdef HAVE_IPV6
9155DEFUN (show_bgp_prefix_longer,
9156 show_bgp_prefix_longer_cmd,
9157 "show bgp X:X::X:X/M longer-prefixes",
9158 SHOW_STR
9159 BGP_STR
9160 "IPv6 prefix <network>/<length>\n"
9161 "Display route and more specific routes\n")
9162{
9163 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9164 bgp_show_type_prefix_longer);
9165}
9166
9167ALIAS (show_bgp_prefix_longer,
9168 show_bgp_ipv6_prefix_longer_cmd,
9169 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9170 SHOW_STR
9171 BGP_STR
9172 "Address family\n"
9173 "IPv6 prefix <network>/<length>\n"
9174 "Display route and more specific routes\n")
9175
9176/* old command */
9177DEFUN (show_ipv6_bgp_prefix_longer,
9178 show_ipv6_bgp_prefix_longer_cmd,
9179 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9180 SHOW_STR
9181 IPV6_STR
9182 BGP_STR
9183 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9184 "Display route and more specific routes\n")
9185{
9186 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9187 bgp_show_type_prefix_longer);
9188}
9189
9190/* old command */
9191DEFUN (show_ipv6_mbgp_prefix_longer,
9192 show_ipv6_mbgp_prefix_longer_cmd,
9193 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9194 SHOW_STR
9195 IPV6_STR
9196 MBGP_STR
9197 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9198 "Display route and more specific routes\n")
9199{
9200 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9201 bgp_show_type_prefix_longer);
9202}
9203#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009204
paul94f2b392005-06-28 12:44:16 +00009205static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009206peer_lookup_in_view (struct vty *vty, const char *view_name,
9207 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009208{
9209 int ret;
9210 struct bgp *bgp;
9211 struct peer *peer;
9212 union sockunion su;
9213
9214 /* BGP structure lookup. */
9215 if (view_name)
9216 {
9217 bgp = bgp_lookup_by_name (view_name);
9218 if (! bgp)
9219 {
9220 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9221 return NULL;
9222 }
9223 }
paul5228ad22004-06-04 17:58:18 +00009224 else
paulbb46e942003-10-24 19:02:03 +00009225 {
9226 bgp = bgp_get_default ();
9227 if (! bgp)
9228 {
9229 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9230 return NULL;
9231 }
9232 }
9233
9234 /* Get peer sockunion. */
9235 ret = str2sockunion (ip_str, &su);
9236 if (ret < 0)
9237 {
9238 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9239 return NULL;
9240 }
9241
9242 /* Peer structure lookup. */
9243 peer = peer_lookup (bgp, &su);
9244 if (! peer)
9245 {
9246 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9247 return NULL;
9248 }
9249
9250 return peer;
9251}
Paul Jakma2815e612006-09-14 02:56:07 +00009252
9253enum bgp_stats
9254{
9255 BGP_STATS_MAXBITLEN = 0,
9256 BGP_STATS_RIB,
9257 BGP_STATS_PREFIXES,
9258 BGP_STATS_TOTPLEN,
9259 BGP_STATS_UNAGGREGATEABLE,
9260 BGP_STATS_MAX_AGGREGATEABLE,
9261 BGP_STATS_AGGREGATES,
9262 BGP_STATS_SPACE,
9263 BGP_STATS_ASPATH_COUNT,
9264 BGP_STATS_ASPATH_MAXHOPS,
9265 BGP_STATS_ASPATH_TOTHOPS,
9266 BGP_STATS_ASPATH_MAXSIZE,
9267 BGP_STATS_ASPATH_TOTSIZE,
9268 BGP_STATS_ASN_HIGHEST,
9269 BGP_STATS_MAX,
9270};
paulbb46e942003-10-24 19:02:03 +00009271
Paul Jakma2815e612006-09-14 02:56:07 +00009272static const char *table_stats_strs[] =
9273{
9274 [BGP_STATS_PREFIXES] = "Total Prefixes",
9275 [BGP_STATS_TOTPLEN] = "Average prefix length",
9276 [BGP_STATS_RIB] = "Total Advertisements",
9277 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9278 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9279 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9280 [BGP_STATS_SPACE] = "Address space advertised",
9281 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9282 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9283 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9284 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9285 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9286 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9287 [BGP_STATS_MAX] = NULL,
9288};
9289
9290struct bgp_table_stats
9291{
9292 struct bgp_table *table;
9293 unsigned long long counts[BGP_STATS_MAX];
9294};
9295
9296#if 0
9297#define TALLY_SIGFIG 100000
9298static unsigned long
9299ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9300{
9301 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9302 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9303 unsigned long ret = newtot / count;
9304
9305 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9306 return ret + 1;
9307 else
9308 return ret;
9309}
9310#endif
9311
9312static int
9313bgp_table_stats_walker (struct thread *t)
9314{
9315 struct bgp_node *rn;
9316 struct bgp_node *top;
9317 struct bgp_table_stats *ts = THREAD_ARG (t);
9318 unsigned int space = 0;
9319
Paul Jakma53d9f672006-10-15 23:41:16 +00009320 if (!(top = bgp_table_top (ts->table)))
9321 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009322
9323 switch (top->p.family)
9324 {
9325 case AF_INET:
9326 space = IPV4_MAX_BITLEN;
9327 break;
9328 case AF_INET6:
9329 space = IPV6_MAX_BITLEN;
9330 break;
9331 }
9332
9333 ts->counts[BGP_STATS_MAXBITLEN] = space;
9334
9335 for (rn = top; rn; rn = bgp_route_next (rn))
9336 {
9337 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009338 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009339 unsigned int rinum = 0;
9340
9341 if (rn == top)
9342 continue;
9343
9344 if (!rn->info)
9345 continue;
9346
9347 ts->counts[BGP_STATS_PREFIXES]++;
9348 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9349
9350#if 0
9351 ts->counts[BGP_STATS_AVGPLEN]
9352 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9353 ts->counts[BGP_STATS_AVGPLEN],
9354 rn->p.prefixlen);
9355#endif
9356
9357 /* check if the prefix is included by any other announcements */
9358 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009359 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009360
9361 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009362 {
9363 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9364 /* announced address space */
9365 if (space)
9366 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9367 }
Paul Jakma2815e612006-09-14 02:56:07 +00009368 else if (prn->info)
9369 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9370
Paul Jakma2815e612006-09-14 02:56:07 +00009371 for (ri = rn->info; ri; ri = ri->next)
9372 {
9373 rinum++;
9374 ts->counts[BGP_STATS_RIB]++;
9375
9376 if (ri->attr &&
9377 (CHECK_FLAG (ri->attr->flag,
9378 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9379 ts->counts[BGP_STATS_AGGREGATES]++;
9380
9381 /* as-path stats */
9382 if (ri->attr && ri->attr->aspath)
9383 {
9384 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9385 unsigned int size = aspath_size (ri->attr->aspath);
9386 as_t highest = aspath_highest (ri->attr->aspath);
9387
9388 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9389
9390 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9391 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9392
9393 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9394 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9395
9396 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9397 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9398#if 0
9399 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9400 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9401 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9402 hops);
9403 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9404 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9405 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9406 size);
9407#endif
9408 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9409 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9410 }
9411 }
9412 }
9413 return 0;
9414}
9415
9416static int
9417bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9418{
9419 struct bgp_table_stats ts;
9420 unsigned int i;
9421
9422 if (!bgp->rib[afi][safi])
9423 {
9424 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9425 return CMD_WARNING;
9426 }
9427
9428 memset (&ts, 0, sizeof (ts));
9429 ts.table = bgp->rib[afi][safi];
9430 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9431
9432 vty_out (vty, "BGP %s RIB statistics%s%s",
9433 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9434
9435 for (i = 0; i < BGP_STATS_MAX; i++)
9436 {
9437 if (!table_stats_strs[i])
9438 continue;
9439
9440 switch (i)
9441 {
9442#if 0
9443 case BGP_STATS_ASPATH_AVGHOPS:
9444 case BGP_STATS_ASPATH_AVGSIZE:
9445 case BGP_STATS_AVGPLEN:
9446 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9447 vty_out (vty, "%12.2f",
9448 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9449 break;
9450#endif
9451 case BGP_STATS_ASPATH_TOTHOPS:
9452 case BGP_STATS_ASPATH_TOTSIZE:
9453 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9454 vty_out (vty, "%12.2f",
9455 ts.counts[i] ?
9456 (float)ts.counts[i] /
9457 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9458 : 0);
9459 break;
9460 case BGP_STATS_TOTPLEN:
9461 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9462 vty_out (vty, "%12.2f",
9463 ts.counts[i] ?
9464 (float)ts.counts[i] /
9465 (float)ts.counts[BGP_STATS_PREFIXES]
9466 : 0);
9467 break;
9468 case BGP_STATS_SPACE:
9469 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9470 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9471 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9472 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009473 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009474 vty_out (vty, "%12.2f%s",
9475 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009476 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009477 VTY_NEWLINE);
9478 vty_out (vty, "%30s: ", "/8 equivalent ");
9479 vty_out (vty, "%12.2f%s",
9480 (float)ts.counts[BGP_STATS_SPACE] /
9481 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9482 VTY_NEWLINE);
9483 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9484 break;
9485 vty_out (vty, "%30s: ", "/24 equivalent ");
9486 vty_out (vty, "%12.2f",
9487 (float)ts.counts[BGP_STATS_SPACE] /
9488 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9489 break;
9490 default:
9491 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9492 vty_out (vty, "%12llu", ts.counts[i]);
9493 }
9494
9495 vty_out (vty, "%s", VTY_NEWLINE);
9496 }
9497 return CMD_SUCCESS;
9498}
9499
9500static int
9501bgp_table_stats_vty (struct vty *vty, const char *name,
9502 const char *afi_str, const char *safi_str)
9503{
9504 struct bgp *bgp;
9505 afi_t afi;
9506 safi_t safi;
9507
9508 if (name)
9509 bgp = bgp_lookup_by_name (name);
9510 else
9511 bgp = bgp_get_default ();
9512
9513 if (!bgp)
9514 {
9515 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9516 return CMD_WARNING;
9517 }
9518 if (strncmp (afi_str, "ipv", 3) == 0)
9519 {
9520 if (strncmp (afi_str, "ipv4", 4) == 0)
9521 afi = AFI_IP;
9522 else if (strncmp (afi_str, "ipv6", 4) == 0)
9523 afi = AFI_IP6;
9524 else
9525 {
9526 vty_out (vty, "%% Invalid address family %s%s",
9527 afi_str, VTY_NEWLINE);
9528 return CMD_WARNING;
9529 }
9530 if (strncmp (safi_str, "m", 1) == 0)
9531 safi = SAFI_MULTICAST;
9532 else if (strncmp (safi_str, "u", 1) == 0)
9533 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009534 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9535 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009536 else
9537 {
9538 vty_out (vty, "%% Invalid subsequent address family %s%s",
9539 safi_str, VTY_NEWLINE);
9540 return CMD_WARNING;
9541 }
9542 }
9543 else
9544 {
9545 vty_out (vty, "%% Invalid address family %s%s",
9546 afi_str, VTY_NEWLINE);
9547 return CMD_WARNING;
9548 }
9549
Paul Jakma2815e612006-09-14 02:56:07 +00009550 return bgp_table_stats (vty, bgp, afi, safi);
9551}
9552
9553DEFUN (show_bgp_statistics,
9554 show_bgp_statistics_cmd,
9555 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9556 SHOW_STR
9557 BGP_STR
9558 "Address family\n"
9559 "Address family\n"
9560 "Address Family modifier\n"
9561 "Address Family modifier\n"
9562 "BGP RIB advertisement statistics\n")
9563{
9564 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9565}
9566
9567ALIAS (show_bgp_statistics,
9568 show_bgp_statistics_vpnv4_cmd,
9569 "show bgp (ipv4) (vpnv4) statistics",
9570 SHOW_STR
9571 BGP_STR
9572 "Address family\n"
9573 "Address Family modifier\n"
9574 "BGP RIB advertisement statistics\n")
9575
9576DEFUN (show_bgp_statistics_view,
9577 show_bgp_statistics_view_cmd,
9578 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9579 SHOW_STR
9580 BGP_STR
9581 "BGP view\n"
9582 "Address family\n"
9583 "Address family\n"
9584 "Address Family modifier\n"
9585 "Address Family modifier\n"
9586 "BGP RIB advertisement statistics\n")
9587{
9588 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9589}
9590
9591ALIAS (show_bgp_statistics_view,
9592 show_bgp_statistics_view_vpnv4_cmd,
9593 "show bgp view WORD (ipv4) (vpnv4) statistics",
9594 SHOW_STR
9595 BGP_STR
9596 "BGP view\n"
9597 "Address family\n"
9598 "Address Family modifier\n"
9599 "BGP RIB advertisement statistics\n")
9600
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601enum bgp_pcounts
9602{
9603 PCOUNT_ADJ_IN = 0,
9604 PCOUNT_DAMPED,
9605 PCOUNT_REMOVED,
9606 PCOUNT_HISTORY,
9607 PCOUNT_STALE,
9608 PCOUNT_VALID,
9609 PCOUNT_ALL,
9610 PCOUNT_COUNTED,
9611 PCOUNT_PFCNT, /* the figure we display to users */
9612 PCOUNT_MAX,
9613};
9614
9615static const char *pcount_strs[] =
9616{
9617 [PCOUNT_ADJ_IN] = "Adj-in",
9618 [PCOUNT_DAMPED] = "Damped",
9619 [PCOUNT_REMOVED] = "Removed",
9620 [PCOUNT_HISTORY] = "History",
9621 [PCOUNT_STALE] = "Stale",
9622 [PCOUNT_VALID] = "Valid",
9623 [PCOUNT_ALL] = "All RIB",
9624 [PCOUNT_COUNTED] = "PfxCt counted",
9625 [PCOUNT_PFCNT] = "Useable",
9626 [PCOUNT_MAX] = NULL,
9627};
9628
Paul Jakma2815e612006-09-14 02:56:07 +00009629struct peer_pcounts
9630{
9631 unsigned int count[PCOUNT_MAX];
9632 const struct peer *peer;
9633 const struct bgp_table *table;
9634};
9635
Paul Jakmaff7924f2006-09-04 01:10:36 +00009636static int
Paul Jakma2815e612006-09-14 02:56:07 +00009637bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638{
9639 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009640 struct peer_pcounts *pc = THREAD_ARG (t);
9641 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009642
Paul Jakma2815e612006-09-14 02:56:07 +00009643 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009644 {
9645 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009646 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647
9648 for (ain = rn->adj_in; ain; ain = ain->next)
9649 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009650 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009651
Paul Jakmaff7924f2006-09-04 01:10:36 +00009652 for (ri = rn->info; ri; ri = ri->next)
9653 {
9654 char buf[SU_ADDRSTRLEN];
9655
9656 if (ri->peer != peer)
9657 continue;
9658
Paul Jakma2815e612006-09-14 02:56:07 +00009659 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660
9661 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009662 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009663 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009664 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009665 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009666 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009667 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009668 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009669 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009670 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009671 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009672 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009673
9674 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9675 {
Paul Jakma2815e612006-09-14 02:56:07 +00009676 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009677 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009678 plog_warn (peer->log,
9679 "%s [pcount] %s/%d is counted but flags 0x%x",
9680 peer->host,
9681 inet_ntop(rn->p.family, &rn->p.u.prefix,
9682 buf, SU_ADDRSTRLEN),
9683 rn->p.prefixlen,
9684 ri->flags);
9685 }
9686 else
9687 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009688 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009689 plog_warn (peer->log,
9690 "%s [pcount] %s/%d not counted but flags 0x%x",
9691 peer->host,
9692 inet_ntop(rn->p.family, &rn->p.u.prefix,
9693 buf, SU_ADDRSTRLEN),
9694 rn->p.prefixlen,
9695 ri->flags);
9696 }
9697 }
9698 }
Paul Jakma2815e612006-09-14 02:56:07 +00009699 return 0;
9700}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009701
Paul Jakma2815e612006-09-14 02:56:07 +00009702static int
9703bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9704{
9705 struct peer_pcounts pcounts = { .peer = peer };
9706 unsigned int i;
9707
9708 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9709 || !peer->bgp->rib[afi][safi])
9710 {
9711 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9712 return CMD_WARNING;
9713 }
9714
9715 memset (&pcounts, 0, sizeof(pcounts));
9716 pcounts.peer = peer;
9717 pcounts.table = peer->bgp->rib[afi][safi];
9718
9719 /* in-place call via thread subsystem so as to record execution time
9720 * stats for the thread-walk (i.e. ensure this can't be blamed on
9721 * on just vty_read()).
9722 */
9723 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9724
Paul Jakmaff7924f2006-09-04 01:10:36 +00009725 vty_out (vty, "Prefix counts for %s, %s%s",
9726 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9727 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9728 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9729 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9730
9731 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009732 vty_out (vty, "%20s: %-10d%s",
9733 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009734
Paul Jakma2815e612006-09-14 02:56:07 +00009735 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009736 {
9737 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9738 peer->host, VTY_NEWLINE);
9739 vty_out (vty, "Please report this bug, with the above command output%s",
9740 VTY_NEWLINE);
9741 }
9742
9743 return CMD_SUCCESS;
9744}
9745
9746DEFUN (show_ip_bgp_neighbor_prefix_counts,
9747 show_ip_bgp_neighbor_prefix_counts_cmd,
9748 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9749 SHOW_STR
9750 IP_STR
9751 BGP_STR
9752 "Detailed information on TCP and BGP neighbor connections\n"
9753 "Neighbor to display information about\n"
9754 "Neighbor to display information about\n"
9755 "Display detailed prefix count information\n")
9756{
9757 struct peer *peer;
9758
9759 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9760 if (! peer)
9761 return CMD_WARNING;
9762
9763 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9764}
9765
9766DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9767 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9768 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9769 SHOW_STR
9770 BGP_STR
9771 "Address family\n"
9772 "Detailed information on TCP and BGP neighbor connections\n"
9773 "Neighbor to display information about\n"
9774 "Neighbor to display information about\n"
9775 "Display detailed prefix count information\n")
9776{
9777 struct peer *peer;
9778
9779 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9780 if (! peer)
9781 return CMD_WARNING;
9782
9783 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9784}
9785
9786DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9787 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9788 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9789 SHOW_STR
9790 IP_STR
9791 BGP_STR
9792 "Address family\n"
9793 "Address Family modifier\n"
9794 "Address Family modifier\n"
9795 "Detailed information on TCP and BGP neighbor connections\n"
9796 "Neighbor to display information about\n"
9797 "Neighbor to display information about\n"
9798 "Display detailed prefix count information\n")
9799{
9800 struct peer *peer;
9801
9802 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9803 if (! peer)
9804 return CMD_WARNING;
9805
9806 if (strncmp (argv[0], "m", 1) == 0)
9807 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9808
9809 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9810}
9811
9812DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9813 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9814 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9815 SHOW_STR
9816 IP_STR
9817 BGP_STR
9818 "Address family\n"
9819 "Address Family modifier\n"
9820 "Address Family modifier\n"
9821 "Detailed information on TCP and BGP neighbor connections\n"
9822 "Neighbor to display information about\n"
9823 "Neighbor to display information about\n"
9824 "Display detailed prefix count information\n")
9825{
9826 struct peer *peer;
9827
9828 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9829 if (! peer)
9830 return CMD_WARNING;
9831
9832 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9833}
9834
9835
paul94f2b392005-06-28 12:44:16 +00009836static void
paul718e3742002-12-13 20:15:29 +00009837show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9838 int in)
9839{
9840 struct bgp_table *table;
9841 struct bgp_adj_in *ain;
9842 struct bgp_adj_out *adj;
9843 unsigned long output_count;
9844 struct bgp_node *rn;
9845 int header1 = 1;
9846 struct bgp *bgp;
9847 int header2 = 1;
9848
paulbb46e942003-10-24 19:02:03 +00009849 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009850
9851 if (! bgp)
9852 return;
9853
9854 table = bgp->rib[afi][safi];
9855
9856 output_count = 0;
9857
9858 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9859 PEER_STATUS_DEFAULT_ORIGINATE))
9860 {
9861 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 +00009862 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9863 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009864
9865 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9866 VTY_NEWLINE, VTY_NEWLINE);
9867 header1 = 0;
9868 }
9869
9870 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9871 if (in)
9872 {
9873 for (ain = rn->adj_in; ain; ain = ain->next)
9874 if (ain->peer == peer)
9875 {
9876 if (header1)
9877 {
9878 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 +00009879 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9880 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009881 header1 = 0;
9882 }
9883 if (header2)
9884 {
9885 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9886 header2 = 0;
9887 }
9888 if (ain->attr)
9889 {
9890 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9891 output_count++;
9892 }
9893 }
9894 }
9895 else
9896 {
9897 for (adj = rn->adj_out; adj; adj = adj->next)
9898 if (adj->peer == peer)
9899 {
9900 if (header1)
9901 {
9902 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 +00009903 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9904 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009905 header1 = 0;
9906 }
9907 if (header2)
9908 {
9909 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9910 header2 = 0;
9911 }
9912 if (adj->attr)
9913 {
9914 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9915 output_count++;
9916 }
9917 }
9918 }
9919
9920 if (output_count != 0)
9921 vty_out (vty, "%sTotal number of prefixes %ld%s",
9922 VTY_NEWLINE, output_count, VTY_NEWLINE);
9923}
9924
paul94f2b392005-06-28 12:44:16 +00009925static int
paulbb46e942003-10-24 19:02:03 +00009926peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9927{
paul718e3742002-12-13 20:15:29 +00009928 if (! peer || ! peer->afc[afi][safi])
9929 {
9930 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9931 return CMD_WARNING;
9932 }
9933
9934 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9935 {
9936 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9937 VTY_NEWLINE);
9938 return CMD_WARNING;
9939 }
9940
9941 show_adj_route (vty, peer, afi, safi, in);
9942
9943 return CMD_SUCCESS;
9944}
9945
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009946DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9947 show_ip_bgp_view_neighbor_advertised_route_cmd,
9948 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9949 SHOW_STR
9950 IP_STR
9951 BGP_STR
9952 "BGP view\n"
9953 "View name\n"
9954 "Detailed information on TCP and BGP neighbor connections\n"
9955 "Neighbor to display information about\n"
9956 "Neighbor to display information about\n"
9957 "Display the routes advertised to a BGP neighbor\n")
9958{
9959 struct peer *peer;
9960
9961 if (argc == 2)
9962 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9963 else
9964 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9965
9966 if (! peer)
9967 return CMD_WARNING;
9968
9969 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9970}
9971
9972ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009973 show_ip_bgp_neighbor_advertised_route_cmd,
9974 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9975 SHOW_STR
9976 IP_STR
9977 BGP_STR
9978 "Detailed information on TCP and BGP neighbor connections\n"
9979 "Neighbor to display information about\n"
9980 "Neighbor to display information about\n"
9981 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009982
9983DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9984 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9985 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9986 SHOW_STR
9987 IP_STR
9988 BGP_STR
9989 "Address family\n"
9990 "Address Family modifier\n"
9991 "Address Family modifier\n"
9992 "Detailed information on TCP and BGP neighbor connections\n"
9993 "Neighbor to display information about\n"
9994 "Neighbor to display information about\n"
9995 "Display the routes advertised to a BGP neighbor\n")
9996{
paulbb46e942003-10-24 19:02:03 +00009997 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009998
paulbb46e942003-10-24 19:02:03 +00009999 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10000 if (! peer)
10001 return CMD_WARNING;
10002
10003 if (strncmp (argv[0], "m", 1) == 0)
10004 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10005
10006 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010007}
10008
10009#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010010DEFUN (show_bgp_view_neighbor_advertised_route,
10011 show_bgp_view_neighbor_advertised_route_cmd,
10012 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10013 SHOW_STR
10014 BGP_STR
10015 "BGP view\n"
10016 "View name\n"
10017 "Detailed information on TCP and BGP neighbor connections\n"
10018 "Neighbor to display information about\n"
10019 "Neighbor to display information about\n"
10020 "Display the routes advertised to a BGP neighbor\n")
10021{
10022 struct peer *peer;
10023
10024 if (argc == 2)
10025 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10026 else
10027 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10028
10029 if (! peer)
10030 return CMD_WARNING;
10031
10032 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10033}
10034
10035ALIAS (show_bgp_view_neighbor_advertised_route,
10036 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10037 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10038 SHOW_STR
10039 BGP_STR
10040 "BGP view\n"
10041 "View name\n"
10042 "Address family\n"
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display the routes advertised to a BGP neighbor\n")
10047
10048DEFUN (show_bgp_view_neighbor_received_routes,
10049 show_bgp_view_neighbor_received_routes_cmd,
10050 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10051 SHOW_STR
10052 BGP_STR
10053 "BGP view\n"
10054 "View name\n"
10055 "Detailed information on TCP and BGP neighbor connections\n"
10056 "Neighbor to display information about\n"
10057 "Neighbor to display information about\n"
10058 "Display the received routes from neighbor\n")
10059{
10060 struct peer *peer;
10061
10062 if (argc == 2)
10063 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10064 else
10065 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10066
10067 if (! peer)
10068 return CMD_WARNING;
10069
10070 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10071}
10072
10073ALIAS (show_bgp_view_neighbor_received_routes,
10074 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10075 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10076 SHOW_STR
10077 BGP_STR
10078 "BGP view\n"
10079 "View name\n"
10080 "Address family\n"
10081 "Detailed information on TCP and BGP neighbor connections\n"
10082 "Neighbor to display information about\n"
10083 "Neighbor to display information about\n"
10084 "Display the received routes from neighbor\n")
10085
10086ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010087 show_bgp_neighbor_advertised_route_cmd,
10088 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10089 SHOW_STR
10090 BGP_STR
10091 "Detailed information on TCP and BGP neighbor connections\n"
10092 "Neighbor to display information about\n"
10093 "Neighbor to display information about\n"
10094 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010095
10096ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010097 show_bgp_ipv6_neighbor_advertised_route_cmd,
10098 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10099 SHOW_STR
10100 BGP_STR
10101 "Address family\n"
10102 "Detailed information on TCP and BGP neighbor connections\n"
10103 "Neighbor to display information about\n"
10104 "Neighbor to display information about\n"
10105 "Display the routes advertised to a BGP neighbor\n")
10106
10107/* old command */
paulbb46e942003-10-24 19:02:03 +000010108ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010109 ipv6_bgp_neighbor_advertised_route_cmd,
10110 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10111 SHOW_STR
10112 IPV6_STR
10113 BGP_STR
10114 "Detailed information on TCP and BGP neighbor connections\n"
10115 "Neighbor to display information about\n"
10116 "Neighbor to display information about\n"
10117 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010118
paul718e3742002-12-13 20:15:29 +000010119/* old command */
10120DEFUN (ipv6_mbgp_neighbor_advertised_route,
10121 ipv6_mbgp_neighbor_advertised_route_cmd,
10122 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10123 SHOW_STR
10124 IPV6_STR
10125 MBGP_STR
10126 "Detailed information on TCP and BGP neighbor connections\n"
10127 "Neighbor to display information about\n"
10128 "Neighbor to display information about\n"
10129 "Display the routes advertised to a BGP neighbor\n")
10130{
paulbb46e942003-10-24 19:02:03 +000010131 struct peer *peer;
10132
10133 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10134 if (! peer)
10135 return CMD_WARNING;
10136
10137 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010138}
10139#endif /* HAVE_IPV6 */
10140
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010141DEFUN (show_ip_bgp_view_neighbor_received_routes,
10142 show_ip_bgp_view_neighbor_received_routes_cmd,
10143 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10144 SHOW_STR
10145 IP_STR
10146 BGP_STR
10147 "BGP view\n"
10148 "View name\n"
10149 "Detailed information on TCP and BGP neighbor connections\n"
10150 "Neighbor to display information about\n"
10151 "Neighbor to display information about\n"
10152 "Display the received routes from neighbor\n")
10153{
10154 struct peer *peer;
10155
10156 if (argc == 2)
10157 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10158 else
10159 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10160
10161 if (! peer)
10162 return CMD_WARNING;
10163
10164 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10165}
10166
10167ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010168 show_ip_bgp_neighbor_received_routes_cmd,
10169 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10170 SHOW_STR
10171 IP_STR
10172 BGP_STR
10173 "Detailed information on TCP and BGP neighbor connections\n"
10174 "Neighbor to display information about\n"
10175 "Neighbor to display information about\n"
10176 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010177
10178DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10179 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10180 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10181 SHOW_STR
10182 IP_STR
10183 BGP_STR
10184 "Address family\n"
10185 "Address Family modifier\n"
10186 "Address Family modifier\n"
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display the received routes from neighbor\n")
10191{
paulbb46e942003-10-24 19:02:03 +000010192 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010193
paulbb46e942003-10-24 19:02:03 +000010194 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10195 if (! peer)
10196 return CMD_WARNING;
10197
10198 if (strncmp (argv[0], "m", 1) == 0)
10199 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10200
10201 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010202}
10203
Michael Lambert95cbbd22010-07-23 14:43:04 -040010204DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10205 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10206#ifdef HAVE_IPV6
10207 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10208#else
10209 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10210#endif
10211 SHOW_STR
10212 BGP_STR
10213 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010214 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010215 "Address family\n"
10216#ifdef HAVE_IPV6
10217 "Address family\n"
10218#endif
10219 "Address family modifier\n"
10220 "Address family modifier\n"
10221 "Detailed information on TCP and BGP neighbor connections\n"
10222 "Neighbor to display information about\n"
10223 "Neighbor to display information about\n"
10224 "Display the advertised routes to neighbor\n"
10225 "Display the received routes from neighbor\n")
10226{
10227 int afi;
10228 int safi;
10229 int in;
10230 struct peer *peer;
10231
10232#ifdef HAVE_IPV6
10233 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10234#else
10235 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10236#endif
10237
10238 if (! peer)
10239 return CMD_WARNING;
10240
10241#ifdef HAVE_IPV6
10242 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10243 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10244 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10245#else
10246 afi = AFI_IP;
10247 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10248 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10249#endif
10250
10251 return peer_adj_routes (vty, peer, afi, safi, in);
10252}
10253
paul718e3742002-12-13 20:15:29 +000010254DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10255 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10256 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10257 SHOW_STR
10258 IP_STR
10259 BGP_STR
10260 "Detailed information on TCP and BGP neighbor connections\n"
10261 "Neighbor to display information about\n"
10262 "Neighbor to display information about\n"
10263 "Display information received from a BGP neighbor\n"
10264 "Display the prefixlist filter\n")
10265{
10266 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010267 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010268 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010269 int count, ret;
paul718e3742002-12-13 20:15:29 +000010270
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010271 ret = str2sockunion (argv[0], &su);
10272 if (ret < 0)
10273 {
10274 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10275 return CMD_WARNING;
10276 }
paul718e3742002-12-13 20:15:29 +000010277
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010278 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010279 if (! peer)
10280 return CMD_WARNING;
10281
10282 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10283 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10284 if (count)
10285 {
10286 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10287 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10288 }
10289
10290 return CMD_SUCCESS;
10291}
10292
10293DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10294 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10295 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10296 SHOW_STR
10297 IP_STR
10298 BGP_STR
10299 "Address family\n"
10300 "Address Family modifier\n"
10301 "Address Family modifier\n"
10302 "Detailed information on TCP and BGP neighbor connections\n"
10303 "Neighbor to display information about\n"
10304 "Neighbor to display information about\n"
10305 "Display information received from a BGP neighbor\n"
10306 "Display the prefixlist filter\n")
10307{
10308 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010309 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010310 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010311 int count, ret;
paul718e3742002-12-13 20:15:29 +000010312
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010313 ret = str2sockunion (argv[1], &su);
10314 if (ret < 0)
10315 {
10316 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10317 return CMD_WARNING;
10318 }
paul718e3742002-12-13 20:15:29 +000010319
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010320 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010321 if (! peer)
10322 return CMD_WARNING;
10323
10324 if (strncmp (argv[0], "m", 1) == 0)
10325 {
10326 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10327 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10328 if (count)
10329 {
10330 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10331 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10332 }
10333 }
10334 else
10335 {
10336 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10337 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10338 if (count)
10339 {
10340 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10341 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10342 }
10343 }
10344
10345 return CMD_SUCCESS;
10346}
10347
10348
10349#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010350ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010351 show_bgp_neighbor_received_routes_cmd,
10352 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10353 SHOW_STR
10354 BGP_STR
10355 "Detailed information on TCP and BGP neighbor connections\n"
10356 "Neighbor to display information about\n"
10357 "Neighbor to display information about\n"
10358 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010359
paulbb46e942003-10-24 19:02:03 +000010360ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010361 show_bgp_ipv6_neighbor_received_routes_cmd,
10362 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10363 SHOW_STR
10364 BGP_STR
10365 "Address family\n"
10366 "Detailed information on TCP and BGP neighbor connections\n"
10367 "Neighbor to display information about\n"
10368 "Neighbor to display information about\n"
10369 "Display the received routes from neighbor\n")
10370
10371DEFUN (show_bgp_neighbor_received_prefix_filter,
10372 show_bgp_neighbor_received_prefix_filter_cmd,
10373 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10374 SHOW_STR
10375 BGP_STR
10376 "Detailed information on TCP and BGP neighbor connections\n"
10377 "Neighbor to display information about\n"
10378 "Neighbor to display information about\n"
10379 "Display information received from a BGP neighbor\n"
10380 "Display the prefixlist filter\n")
10381{
10382 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010383 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010384 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010385 int count, ret;
paul718e3742002-12-13 20:15:29 +000010386
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010387 ret = str2sockunion (argv[0], &su);
10388 if (ret < 0)
10389 {
10390 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10391 return CMD_WARNING;
10392 }
paul718e3742002-12-13 20:15:29 +000010393
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010394 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010395 if (! peer)
10396 return CMD_WARNING;
10397
10398 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10399 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10400 if (count)
10401 {
10402 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10403 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10404 }
10405
10406 return CMD_SUCCESS;
10407}
10408
10409ALIAS (show_bgp_neighbor_received_prefix_filter,
10410 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10411 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10412 SHOW_STR
10413 BGP_STR
10414 "Address family\n"
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 information received from a BGP neighbor\n"
10419 "Display the prefixlist filter\n")
10420
10421/* old command */
paulbb46e942003-10-24 19:02:03 +000010422ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010423 ipv6_bgp_neighbor_received_routes_cmd,
10424 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10425 SHOW_STR
10426 IPV6_STR
10427 BGP_STR
10428 "Detailed information on TCP and BGP neighbor connections\n"
10429 "Neighbor to display information about\n"
10430 "Neighbor to display information about\n"
10431 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010432
10433/* old command */
10434DEFUN (ipv6_mbgp_neighbor_received_routes,
10435 ipv6_mbgp_neighbor_received_routes_cmd,
10436 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10437 SHOW_STR
10438 IPV6_STR
10439 MBGP_STR
10440 "Detailed information on TCP and BGP neighbor connections\n"
10441 "Neighbor to display information about\n"
10442 "Neighbor to display information about\n"
10443 "Display the received routes from neighbor\n")
10444{
paulbb46e942003-10-24 19:02:03 +000010445 struct peer *peer;
10446
10447 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10448 if (! peer)
10449 return CMD_WARNING;
10450
10451 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010452}
paulbb46e942003-10-24 19:02:03 +000010453
10454DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10455 show_bgp_view_neighbor_received_prefix_filter_cmd,
10456 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10457 SHOW_STR
10458 BGP_STR
10459 "BGP view\n"
10460 "View name\n"
10461 "Detailed information on TCP and BGP neighbor connections\n"
10462 "Neighbor to display information about\n"
10463 "Neighbor to display information about\n"
10464 "Display information received from a BGP neighbor\n"
10465 "Display the prefixlist filter\n")
10466{
10467 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010468 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010469 struct peer *peer;
10470 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010471 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010472
10473 /* BGP structure lookup. */
10474 bgp = bgp_lookup_by_name (argv[0]);
10475 if (bgp == NULL)
10476 {
10477 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10478 return CMD_WARNING;
10479 }
10480
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010481 ret = str2sockunion (argv[1], &su);
10482 if (ret < 0)
10483 {
10484 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10485 return CMD_WARNING;
10486 }
paulbb46e942003-10-24 19:02:03 +000010487
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010488 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010489 if (! peer)
10490 return CMD_WARNING;
10491
10492 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10493 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10494 if (count)
10495 {
10496 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10497 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10498 }
10499
10500 return CMD_SUCCESS;
10501}
10502
10503ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10504 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10505 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10506 SHOW_STR
10507 BGP_STR
10508 "BGP view\n"
10509 "View name\n"
10510 "Address family\n"
10511 "Detailed information on TCP and BGP neighbor connections\n"
10512 "Neighbor to display information about\n"
10513 "Neighbor to display information about\n"
10514 "Display information received from a BGP neighbor\n"
10515 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010516#endif /* HAVE_IPV6 */
10517
paul94f2b392005-06-28 12:44:16 +000010518static int
paulbb46e942003-10-24 19:02:03 +000010519bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010520 safi_t safi, enum bgp_show_type type)
10521{
paul718e3742002-12-13 20:15:29 +000010522 if (! peer || ! peer->afc[afi][safi])
10523 {
10524 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010525 return CMD_WARNING;
10526 }
10527
ajs5a646652004-11-05 01:25:55 +000010528 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010529}
10530
10531DEFUN (show_ip_bgp_neighbor_routes,
10532 show_ip_bgp_neighbor_routes_cmd,
10533 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10534 SHOW_STR
10535 IP_STR
10536 BGP_STR
10537 "Detailed information on TCP and BGP neighbor connections\n"
10538 "Neighbor to display information about\n"
10539 "Neighbor to display information about\n"
10540 "Display routes learned from neighbor\n")
10541{
paulbb46e942003-10-24 19:02:03 +000010542 struct peer *peer;
10543
10544 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10545 if (! peer)
10546 return CMD_WARNING;
10547
10548 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010549 bgp_show_type_neighbor);
10550}
10551
10552DEFUN (show_ip_bgp_neighbor_flap,
10553 show_ip_bgp_neighbor_flap_cmd,
10554 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10555 SHOW_STR
10556 IP_STR
10557 BGP_STR
10558 "Detailed information on TCP and BGP neighbor connections\n"
10559 "Neighbor to display information about\n"
10560 "Neighbor to display information about\n"
10561 "Display flap statistics of the routes learned from neighbor\n")
10562{
paulbb46e942003-10-24 19:02:03 +000010563 struct peer *peer;
10564
10565 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10566 if (! peer)
10567 return CMD_WARNING;
10568
10569 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010570 bgp_show_type_flap_neighbor);
10571}
10572
10573DEFUN (show_ip_bgp_neighbor_damp,
10574 show_ip_bgp_neighbor_damp_cmd,
10575 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10576 SHOW_STR
10577 IP_STR
10578 BGP_STR
10579 "Detailed information on TCP and BGP neighbor connections\n"
10580 "Neighbor to display information about\n"
10581 "Neighbor to display information about\n"
10582 "Display the dampened routes received from neighbor\n")
10583{
paulbb46e942003-10-24 19:02:03 +000010584 struct peer *peer;
10585
10586 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10587 if (! peer)
10588 return CMD_WARNING;
10589
10590 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010591 bgp_show_type_damp_neighbor);
10592}
10593
10594DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10595 show_ip_bgp_ipv4_neighbor_routes_cmd,
10596 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10597 SHOW_STR
10598 IP_STR
10599 BGP_STR
10600 "Address family\n"
10601 "Address Family modifier\n"
10602 "Address Family modifier\n"
10603 "Detailed information on TCP and BGP neighbor connections\n"
10604 "Neighbor to display information about\n"
10605 "Neighbor to display information about\n"
10606 "Display routes learned from neighbor\n")
10607{
paulbb46e942003-10-24 19:02:03 +000010608 struct peer *peer;
10609
10610 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10611 if (! peer)
10612 return CMD_WARNING;
10613
paul718e3742002-12-13 20:15:29 +000010614 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010615 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010616 bgp_show_type_neighbor);
10617
paulbb46e942003-10-24 19:02:03 +000010618 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010619 bgp_show_type_neighbor);
10620}
paulbb46e942003-10-24 19:02:03 +000010621
paulfee0f4c2004-09-13 05:12:46 +000010622DEFUN (show_ip_bgp_view_rsclient,
10623 show_ip_bgp_view_rsclient_cmd,
10624 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10625 SHOW_STR
10626 IP_STR
10627 BGP_STR
10628 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010629 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010630 "Information about Route Server Client\n"
10631 NEIGHBOR_ADDR_STR)
10632{
10633 struct bgp_table *table;
10634 struct peer *peer;
10635
10636 if (argc == 2)
10637 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10638 else
10639 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10640
10641 if (! peer)
10642 return CMD_WARNING;
10643
10644 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10645 {
10646 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10647 VTY_NEWLINE);
10648 return CMD_WARNING;
10649 }
10650
10651 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10652 PEER_FLAG_RSERVER_CLIENT))
10653 {
10654 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10655 VTY_NEWLINE);
10656 return CMD_WARNING;
10657 }
10658
10659 table = peer->rib[AFI_IP][SAFI_UNICAST];
10660
ajs5a646652004-11-05 01:25:55 +000010661 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010662}
10663
10664ALIAS (show_ip_bgp_view_rsclient,
10665 show_ip_bgp_rsclient_cmd,
10666 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10667 SHOW_STR
10668 IP_STR
10669 BGP_STR
10670 "Information about Route Server Client\n"
10671 NEIGHBOR_ADDR_STR)
10672
Michael Lambert95cbbd22010-07-23 14:43:04 -040010673DEFUN (show_bgp_view_ipv4_safi_rsclient,
10674 show_bgp_view_ipv4_safi_rsclient_cmd,
10675 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10676 SHOW_STR
10677 BGP_STR
10678 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010679 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010680 "Address family\n"
10681 "Address Family modifier\n"
10682 "Address Family modifier\n"
10683 "Information about Route Server Client\n"
10684 NEIGHBOR_ADDR_STR)
10685{
10686 struct bgp_table *table;
10687 struct peer *peer;
10688 safi_t safi;
10689
10690 if (argc == 3) {
10691 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10692 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10693 } else {
10694 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10695 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10696 }
10697
10698 if (! peer)
10699 return CMD_WARNING;
10700
10701 if (! peer->afc[AFI_IP][safi])
10702 {
10703 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10704 VTY_NEWLINE);
10705 return CMD_WARNING;
10706 }
10707
10708 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10709 PEER_FLAG_RSERVER_CLIENT))
10710 {
10711 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10712 VTY_NEWLINE);
10713 return CMD_WARNING;
10714 }
10715
10716 table = peer->rib[AFI_IP][safi];
10717
10718 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10719}
10720
10721ALIAS (show_bgp_view_ipv4_safi_rsclient,
10722 show_bgp_ipv4_safi_rsclient_cmd,
10723 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10724 SHOW_STR
10725 BGP_STR
10726 "Address family\n"
10727 "Address Family modifier\n"
10728 "Address Family modifier\n"
10729 "Information about Route Server Client\n"
10730 NEIGHBOR_ADDR_STR)
10731
paulfee0f4c2004-09-13 05:12:46 +000010732DEFUN (show_ip_bgp_view_rsclient_route,
10733 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010734 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010735 SHOW_STR
10736 IP_STR
10737 BGP_STR
10738 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010739 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010740 "Information about Route Server Client\n"
10741 NEIGHBOR_ADDR_STR
10742 "Network in the BGP routing table to display\n")
10743{
10744 struct bgp *bgp;
10745 struct peer *peer;
10746
10747 /* BGP structure lookup. */
10748 if (argc == 3)
10749 {
10750 bgp = bgp_lookup_by_name (argv[0]);
10751 if (bgp == NULL)
10752 {
10753 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10754 return CMD_WARNING;
10755 }
10756 }
10757 else
10758 {
10759 bgp = bgp_get_default ();
10760 if (bgp == NULL)
10761 {
10762 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10763 return CMD_WARNING;
10764 }
10765 }
10766
10767 if (argc == 3)
10768 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10769 else
10770 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10771
10772 if (! peer)
10773 return CMD_WARNING;
10774
10775 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10776 {
10777 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10778 VTY_NEWLINE);
10779 return CMD_WARNING;
10780}
10781
10782 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10783 PEER_FLAG_RSERVER_CLIENT))
10784 {
10785 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10786 VTY_NEWLINE);
10787 return CMD_WARNING;
10788 }
10789
10790 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10791 (argc == 3) ? argv[2] : argv[1],
10792 AFI_IP, SAFI_UNICAST, NULL, 0);
10793}
10794
10795ALIAS (show_ip_bgp_view_rsclient_route,
10796 show_ip_bgp_rsclient_route_cmd,
10797 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10798 SHOW_STR
10799 IP_STR
10800 BGP_STR
10801 "Information about Route Server Client\n"
10802 NEIGHBOR_ADDR_STR
10803 "Network in the BGP routing table to display\n")
10804
Michael Lambert95cbbd22010-07-23 14:43:04 -040010805DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10806 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10807 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10808 SHOW_STR
10809 BGP_STR
10810 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010811 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010812 "Address family\n"
10813 "Address Family modifier\n"
10814 "Address Family modifier\n"
10815 "Information about Route Server Client\n"
10816 NEIGHBOR_ADDR_STR
10817 "Network in the BGP routing table to display\n")
10818{
10819 struct bgp *bgp;
10820 struct peer *peer;
10821 safi_t safi;
10822
10823 /* BGP structure lookup. */
10824 if (argc == 4)
10825 {
10826 bgp = bgp_lookup_by_name (argv[0]);
10827 if (bgp == NULL)
10828 {
10829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832 }
10833 else
10834 {
10835 bgp = bgp_get_default ();
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842
10843 if (argc == 4) {
10844 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10845 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10846 } else {
10847 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10848 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10849 }
10850
10851 if (! peer)
10852 return CMD_WARNING;
10853
10854 if (! peer->afc[AFI_IP][safi])
10855 {
10856 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10857 VTY_NEWLINE);
10858 return CMD_WARNING;
10859}
10860
10861 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10862 PEER_FLAG_RSERVER_CLIENT))
10863 {
10864 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10865 VTY_NEWLINE);
10866 return CMD_WARNING;
10867 }
10868
10869 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10870 (argc == 4) ? argv[3] : argv[2],
10871 AFI_IP, safi, NULL, 0);
10872}
10873
10874ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10875 show_bgp_ipv4_safi_rsclient_route_cmd,
10876 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10877 SHOW_STR
10878 BGP_STR
10879 "Address family\n"
10880 "Address Family modifier\n"
10881 "Address Family modifier\n"
10882 "Information about Route Server Client\n"
10883 NEIGHBOR_ADDR_STR
10884 "Network in the BGP routing table to display\n")
10885
paulfee0f4c2004-09-13 05:12:46 +000010886DEFUN (show_ip_bgp_view_rsclient_prefix,
10887 show_ip_bgp_view_rsclient_prefix_cmd,
10888 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10889 SHOW_STR
10890 IP_STR
10891 BGP_STR
10892 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010893 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010894 "Information about Route Server Client\n"
10895 NEIGHBOR_ADDR_STR
10896 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10897{
10898 struct bgp *bgp;
10899 struct peer *peer;
10900
10901 /* BGP structure lookup. */
10902 if (argc == 3)
10903 {
10904 bgp = bgp_lookup_by_name (argv[0]);
10905 if (bgp == NULL)
10906 {
10907 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10908 return CMD_WARNING;
10909 }
10910 }
10911 else
10912 {
10913 bgp = bgp_get_default ();
10914 if (bgp == NULL)
10915 {
10916 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10917 return CMD_WARNING;
10918 }
10919 }
10920
10921 if (argc == 3)
10922 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10923 else
10924 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10925
10926 if (! peer)
10927 return CMD_WARNING;
10928
10929 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10930 {
10931 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10932 VTY_NEWLINE);
10933 return CMD_WARNING;
10934}
10935
10936 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10937 PEER_FLAG_RSERVER_CLIENT))
10938{
10939 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10940 VTY_NEWLINE);
10941 return CMD_WARNING;
10942 }
10943
10944 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10945 (argc == 3) ? argv[2] : argv[1],
10946 AFI_IP, SAFI_UNICAST, NULL, 1);
10947}
10948
10949ALIAS (show_ip_bgp_view_rsclient_prefix,
10950 show_ip_bgp_rsclient_prefix_cmd,
10951 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10952 SHOW_STR
10953 IP_STR
10954 BGP_STR
10955 "Information about Route Server Client\n"
10956 NEIGHBOR_ADDR_STR
10957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10958
Michael Lambert95cbbd22010-07-23 14:43:04 -040010959DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10960 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10961 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10962 SHOW_STR
10963 BGP_STR
10964 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010965 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010966 "Address family\n"
10967 "Address Family modifier\n"
10968 "Address Family modifier\n"
10969 "Information about Route Server Client\n"
10970 NEIGHBOR_ADDR_STR
10971 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10972{
10973 struct bgp *bgp;
10974 struct peer *peer;
10975 safi_t safi;
10976
10977 /* BGP structure lookup. */
10978 if (argc == 4)
10979 {
10980 bgp = bgp_lookup_by_name (argv[0]);
10981 if (bgp == NULL)
10982 {
10983 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10984 return CMD_WARNING;
10985 }
10986 }
10987 else
10988 {
10989 bgp = bgp_get_default ();
10990 if (bgp == NULL)
10991 {
10992 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10993 return CMD_WARNING;
10994 }
10995 }
10996
10997 if (argc == 4) {
10998 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10999 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11000 } else {
11001 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11002 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11003 }
11004
11005 if (! peer)
11006 return CMD_WARNING;
11007
11008 if (! peer->afc[AFI_IP][safi])
11009 {
11010 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11011 VTY_NEWLINE);
11012 return CMD_WARNING;
11013}
11014
11015 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11016 PEER_FLAG_RSERVER_CLIENT))
11017{
11018 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11019 VTY_NEWLINE);
11020 return CMD_WARNING;
11021 }
11022
11023 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11024 (argc == 4) ? argv[3] : argv[2],
11025 AFI_IP, safi, NULL, 1);
11026}
11027
11028ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11029 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11030 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11031 SHOW_STR
11032 BGP_STR
11033 "Address family\n"
11034 "Address Family modifier\n"
11035 "Address Family modifier\n"
11036 "Information about Route Server Client\n"
11037 NEIGHBOR_ADDR_STR
11038 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011039
paul718e3742002-12-13 20:15:29 +000011040#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011041DEFUN (show_bgp_view_neighbor_routes,
11042 show_bgp_view_neighbor_routes_cmd,
11043 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11044 SHOW_STR
11045 BGP_STR
11046 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011047 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011048 "Detailed information on TCP and BGP neighbor connections\n"
11049 "Neighbor to display information about\n"
11050 "Neighbor to display information about\n"
11051 "Display routes learned from neighbor\n")
11052{
11053 struct peer *peer;
11054
11055 if (argc == 2)
11056 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11057 else
11058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11059
11060 if (! peer)
11061 return CMD_WARNING;
11062
11063 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11064 bgp_show_type_neighbor);
11065}
11066
11067ALIAS (show_bgp_view_neighbor_routes,
11068 show_bgp_view_ipv6_neighbor_routes_cmd,
11069 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) 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 "Address family\n"
11075 "Detailed information on TCP and BGP neighbor connections\n"
11076 "Neighbor to display information about\n"
11077 "Neighbor to display information about\n"
11078 "Display routes learned from neighbor\n")
11079
11080DEFUN (show_bgp_view_neighbor_damp,
11081 show_bgp_view_neighbor_damp_cmd,
11082 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11083 SHOW_STR
11084 BGP_STR
11085 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011086 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011087 "Detailed information on TCP and BGP neighbor connections\n"
11088 "Neighbor to display information about\n"
11089 "Neighbor to display information about\n"
11090 "Display the dampened routes received from neighbor\n")
11091{
11092 struct peer *peer;
11093
11094 if (argc == 2)
11095 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11096 else
11097 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11098
11099 if (! peer)
11100 return CMD_WARNING;
11101
11102 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11103 bgp_show_type_damp_neighbor);
11104}
11105
11106ALIAS (show_bgp_view_neighbor_damp,
11107 show_bgp_view_ipv6_neighbor_damp_cmd,
11108 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
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 "Address family\n"
11114 "Detailed information on TCP and BGP neighbor connections\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor to display information about\n"
11117 "Display the dampened routes received from neighbor\n")
11118
11119DEFUN (show_bgp_view_neighbor_flap,
11120 show_bgp_view_neighbor_flap_cmd,
11121 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11122 SHOW_STR
11123 BGP_STR
11124 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011125 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011126 "Detailed information on TCP and BGP neighbor connections\n"
11127 "Neighbor to display information about\n"
11128 "Neighbor to display information about\n"
11129 "Display flap statistics of the routes learned from neighbor\n")
11130{
11131 struct peer *peer;
11132
11133 if (argc == 2)
11134 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11135 else
11136 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11137
11138 if (! peer)
11139 return CMD_WARNING;
11140
11141 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11142 bgp_show_type_flap_neighbor);
11143}
11144
11145ALIAS (show_bgp_view_neighbor_flap,
11146 show_bgp_view_ipv6_neighbor_flap_cmd,
11147 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11148 SHOW_STR
11149 BGP_STR
11150 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011151 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011152 "Address family\n"
11153 "Detailed information on TCP and BGP neighbor connections\n"
11154 "Neighbor to display information about\n"
11155 "Neighbor to display information about\n"
11156 "Display flap statistics of the routes learned from neighbor\n")
11157
11158ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011159 show_bgp_neighbor_routes_cmd,
11160 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11161 SHOW_STR
11162 BGP_STR
11163 "Detailed information on TCP and BGP neighbor connections\n"
11164 "Neighbor to display information about\n"
11165 "Neighbor to display information about\n"
11166 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011167
paulbb46e942003-10-24 19:02:03 +000011168
11169ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011170 show_bgp_ipv6_neighbor_routes_cmd,
11171 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11172 SHOW_STR
11173 BGP_STR
11174 "Address family\n"
11175 "Detailed information on TCP and BGP neighbor connections\n"
11176 "Neighbor to display information about\n"
11177 "Neighbor to display information about\n"
11178 "Display routes learned from neighbor\n")
11179
11180/* old command */
paulbb46e942003-10-24 19:02:03 +000011181ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011182 ipv6_bgp_neighbor_routes_cmd,
11183 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11184 SHOW_STR
11185 IPV6_STR
11186 BGP_STR
11187 "Detailed information on TCP and BGP neighbor connections\n"
11188 "Neighbor to display information about\n"
11189 "Neighbor to display information about\n"
11190 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011191
11192/* old command */
11193DEFUN (ipv6_mbgp_neighbor_routes,
11194 ipv6_mbgp_neighbor_routes_cmd,
11195 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11196 SHOW_STR
11197 IPV6_STR
11198 MBGP_STR
11199 "Detailed information on TCP and BGP neighbor connections\n"
11200 "Neighbor to display information about\n"
11201 "Neighbor to display information about\n"
11202 "Display routes learned from neighbor\n")
11203{
paulbb46e942003-10-24 19:02:03 +000011204 struct peer *peer;
11205
11206 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11207 if (! peer)
11208 return CMD_WARNING;
11209
11210 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011211 bgp_show_type_neighbor);
11212}
paulbb46e942003-10-24 19:02:03 +000011213
11214ALIAS (show_bgp_view_neighbor_flap,
11215 show_bgp_neighbor_flap_cmd,
11216 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11217 SHOW_STR
11218 BGP_STR
11219 "Detailed information on TCP and BGP neighbor connections\n"
11220 "Neighbor to display information about\n"
11221 "Neighbor to display information about\n"
11222 "Display flap statistics of the routes learned from neighbor\n")
11223
11224ALIAS (show_bgp_view_neighbor_flap,
11225 show_bgp_ipv6_neighbor_flap_cmd,
11226 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11227 SHOW_STR
11228 BGP_STR
11229 "Address family\n"
11230 "Detailed information on TCP and BGP neighbor connections\n"
11231 "Neighbor to display information about\n"
11232 "Neighbor to display information about\n"
11233 "Display flap statistics of the routes learned from neighbor\n")
11234
11235ALIAS (show_bgp_view_neighbor_damp,
11236 show_bgp_neighbor_damp_cmd,
11237 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11238 SHOW_STR
11239 BGP_STR
11240 "Detailed information on TCP and BGP neighbor connections\n"
11241 "Neighbor to display information about\n"
11242 "Neighbor to display information about\n"
11243 "Display the dampened routes received from neighbor\n")
11244
11245ALIAS (show_bgp_view_neighbor_damp,
11246 show_bgp_ipv6_neighbor_damp_cmd,
11247 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11248 SHOW_STR
11249 BGP_STR
11250 "Address family\n"
11251 "Detailed information on TCP and BGP neighbor connections\n"
11252 "Neighbor to display information about\n"
11253 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011254 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011255
11256DEFUN (show_bgp_view_rsclient,
11257 show_bgp_view_rsclient_cmd,
11258 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11259 SHOW_STR
11260 BGP_STR
11261 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011262 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011263 "Information about Route Server Client\n"
11264 NEIGHBOR_ADDR_STR)
11265{
11266 struct bgp_table *table;
11267 struct peer *peer;
11268
11269 if (argc == 2)
11270 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11271 else
11272 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11273
11274 if (! peer)
11275 return CMD_WARNING;
11276
11277 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11278 {
11279 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11280 VTY_NEWLINE);
11281 return CMD_WARNING;
11282 }
11283
11284 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11285 PEER_FLAG_RSERVER_CLIENT))
11286 {
11287 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11288 VTY_NEWLINE);
11289 return CMD_WARNING;
11290 }
11291
11292 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11293
ajs5a646652004-11-05 01:25:55 +000011294 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011295}
11296
11297ALIAS (show_bgp_view_rsclient,
11298 show_bgp_rsclient_cmd,
11299 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11300 SHOW_STR
11301 BGP_STR
11302 "Information about Route Server Client\n"
11303 NEIGHBOR_ADDR_STR)
11304
Michael Lambert95cbbd22010-07-23 14:43:04 -040011305DEFUN (show_bgp_view_ipv6_safi_rsclient,
11306 show_bgp_view_ipv6_safi_rsclient_cmd,
11307 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11308 SHOW_STR
11309 BGP_STR
11310 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011311 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011312 "Address family\n"
11313 "Address Family modifier\n"
11314 "Address Family modifier\n"
11315 "Information about Route Server Client\n"
11316 NEIGHBOR_ADDR_STR)
11317{
11318 struct bgp_table *table;
11319 struct peer *peer;
11320 safi_t safi;
11321
11322 if (argc == 3) {
11323 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11324 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11325 } else {
11326 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11327 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11328 }
11329
11330 if (! peer)
11331 return CMD_WARNING;
11332
11333 if (! peer->afc[AFI_IP6][safi])
11334 {
11335 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11336 VTY_NEWLINE);
11337 return CMD_WARNING;
11338 }
11339
11340 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11341 PEER_FLAG_RSERVER_CLIENT))
11342 {
11343 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11344 VTY_NEWLINE);
11345 return CMD_WARNING;
11346 }
11347
11348 table = peer->rib[AFI_IP6][safi];
11349
11350 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11351}
11352
11353ALIAS (show_bgp_view_ipv6_safi_rsclient,
11354 show_bgp_ipv6_safi_rsclient_cmd,
11355 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11356 SHOW_STR
11357 BGP_STR
11358 "Address family\n"
11359 "Address Family modifier\n"
11360 "Address Family modifier\n"
11361 "Information about Route Server Client\n"
11362 NEIGHBOR_ADDR_STR)
11363
paulfee0f4c2004-09-13 05:12:46 +000011364DEFUN (show_bgp_view_rsclient_route,
11365 show_bgp_view_rsclient_route_cmd,
11366 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11367 SHOW_STR
11368 BGP_STR
11369 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011370 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011371 "Information about Route Server Client\n"
11372 NEIGHBOR_ADDR_STR
11373 "Network in the BGP routing table to display\n")
11374{
11375 struct bgp *bgp;
11376 struct peer *peer;
11377
11378 /* BGP structure lookup. */
11379 if (argc == 3)
11380 {
11381 bgp = bgp_lookup_by_name (argv[0]);
11382 if (bgp == NULL)
11383 {
11384 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11385 return CMD_WARNING;
11386 }
11387 }
11388 else
11389 {
11390 bgp = bgp_get_default ();
11391 if (bgp == NULL)
11392 {
11393 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11394 return CMD_WARNING;
11395 }
11396 }
11397
11398 if (argc == 3)
11399 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11400 else
11401 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11402
11403 if (! peer)
11404 return CMD_WARNING;
11405
11406 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11407 {
11408 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11409 VTY_NEWLINE);
11410 return CMD_WARNING;
11411 }
11412
11413 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11414 PEER_FLAG_RSERVER_CLIENT))
11415 {
11416 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11417 VTY_NEWLINE);
11418 return CMD_WARNING;
11419 }
11420
11421 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11422 (argc == 3) ? argv[2] : argv[1],
11423 AFI_IP6, SAFI_UNICAST, NULL, 0);
11424}
11425
11426ALIAS (show_bgp_view_rsclient_route,
11427 show_bgp_rsclient_route_cmd,
11428 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11429 SHOW_STR
11430 BGP_STR
11431 "Information about Route Server Client\n"
11432 NEIGHBOR_ADDR_STR
11433 "Network in the BGP routing table to display\n")
11434
Michael Lambert95cbbd22010-07-23 14:43:04 -040011435DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11436 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11437 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11438 SHOW_STR
11439 BGP_STR
11440 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011441 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011442 "Address family\n"
11443 "Address Family modifier\n"
11444 "Address Family modifier\n"
11445 "Information about Route Server Client\n"
11446 NEIGHBOR_ADDR_STR
11447 "Network in the BGP routing table to display\n")
11448{
11449 struct bgp *bgp;
11450 struct peer *peer;
11451 safi_t safi;
11452
11453 /* BGP structure lookup. */
11454 if (argc == 4)
11455 {
11456 bgp = bgp_lookup_by_name (argv[0]);
11457 if (bgp == NULL)
11458 {
11459 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11460 return CMD_WARNING;
11461 }
11462 }
11463 else
11464 {
11465 bgp = bgp_get_default ();
11466 if (bgp == NULL)
11467 {
11468 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11469 return CMD_WARNING;
11470 }
11471 }
11472
11473 if (argc == 4) {
11474 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11475 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11476 } else {
11477 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11478 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11479 }
11480
11481 if (! peer)
11482 return CMD_WARNING;
11483
11484 if (! peer->afc[AFI_IP6][safi])
11485 {
11486 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11487 VTY_NEWLINE);
11488 return CMD_WARNING;
11489}
11490
11491 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11492 PEER_FLAG_RSERVER_CLIENT))
11493 {
11494 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11495 VTY_NEWLINE);
11496 return CMD_WARNING;
11497 }
11498
11499 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11500 (argc == 4) ? argv[3] : argv[2],
11501 AFI_IP6, safi, NULL, 0);
11502}
11503
11504ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11505 show_bgp_ipv6_safi_rsclient_route_cmd,
11506 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11507 SHOW_STR
11508 BGP_STR
11509 "Address family\n"
11510 "Address Family modifier\n"
11511 "Address Family modifier\n"
11512 "Information about Route Server Client\n"
11513 NEIGHBOR_ADDR_STR
11514 "Network in the BGP routing table to display\n")
11515
paulfee0f4c2004-09-13 05:12:46 +000011516DEFUN (show_bgp_view_rsclient_prefix,
11517 show_bgp_view_rsclient_prefix_cmd,
11518 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11519 SHOW_STR
11520 BGP_STR
11521 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011522 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011523 "Information about Route Server Client\n"
11524 NEIGHBOR_ADDR_STR
11525 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11526{
11527 struct bgp *bgp;
11528 struct peer *peer;
11529
11530 /* BGP structure lookup. */
11531 if (argc == 3)
11532 {
11533 bgp = bgp_lookup_by_name (argv[0]);
11534 if (bgp == NULL)
11535 {
11536 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11537 return CMD_WARNING;
11538 }
11539 }
11540 else
11541 {
11542 bgp = bgp_get_default ();
11543 if (bgp == NULL)
11544 {
11545 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11546 return CMD_WARNING;
11547 }
11548 }
11549
11550 if (argc == 3)
11551 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11552 else
11553 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11554
11555 if (! peer)
11556 return CMD_WARNING;
11557
11558 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11559 {
11560 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11561 VTY_NEWLINE);
11562 return CMD_WARNING;
11563 }
11564
11565 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11566 PEER_FLAG_RSERVER_CLIENT))
11567 {
11568 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11569 VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572
11573 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11574 (argc == 3) ? argv[2] : argv[1],
11575 AFI_IP6, SAFI_UNICAST, NULL, 1);
11576}
11577
11578ALIAS (show_bgp_view_rsclient_prefix,
11579 show_bgp_rsclient_prefix_cmd,
11580 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11581 SHOW_STR
11582 BGP_STR
11583 "Information about Route Server Client\n"
11584 NEIGHBOR_ADDR_STR
11585 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11586
Michael Lambert95cbbd22010-07-23 14:43:04 -040011587DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11588 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11589 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11590 SHOW_STR
11591 BGP_STR
11592 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011593 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011594 "Address family\n"
11595 "Address Family modifier\n"
11596 "Address Family modifier\n"
11597 "Information about Route Server Client\n"
11598 NEIGHBOR_ADDR_STR
11599 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11600{
11601 struct bgp *bgp;
11602 struct peer *peer;
11603 safi_t safi;
11604
11605 /* BGP structure lookup. */
11606 if (argc == 4)
11607 {
11608 bgp = bgp_lookup_by_name (argv[0]);
11609 if (bgp == NULL)
11610 {
11611 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11612 return CMD_WARNING;
11613 }
11614 }
11615 else
11616 {
11617 bgp = bgp_get_default ();
11618 if (bgp == NULL)
11619 {
11620 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11621 return CMD_WARNING;
11622 }
11623 }
11624
11625 if (argc == 4) {
11626 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11627 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11628 } else {
11629 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11630 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11631 }
11632
11633 if (! peer)
11634 return CMD_WARNING;
11635
11636 if (! peer->afc[AFI_IP6][safi])
11637 {
11638 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11639 VTY_NEWLINE);
11640 return CMD_WARNING;
11641}
11642
11643 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11644 PEER_FLAG_RSERVER_CLIENT))
11645{
11646 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11647 VTY_NEWLINE);
11648 return CMD_WARNING;
11649 }
11650
11651 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11652 (argc == 4) ? argv[3] : argv[2],
11653 AFI_IP6, safi, NULL, 1);
11654}
11655
11656ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11657 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11658 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11659 SHOW_STR
11660 BGP_STR
11661 "Address family\n"
11662 "Address Family modifier\n"
11663 "Address Family modifier\n"
11664 "Information about Route Server Client\n"
11665 NEIGHBOR_ADDR_STR
11666 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11667
paul718e3742002-12-13 20:15:29 +000011668#endif /* HAVE_IPV6 */
11669
11670struct bgp_table *bgp_distance_table;
11671
11672struct bgp_distance
11673{
11674 /* Distance value for the IP source prefix. */
11675 u_char distance;
11676
11677 /* Name of the access-list to be matched. */
11678 char *access_list;
11679};
11680
paul94f2b392005-06-28 12:44:16 +000011681static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011682bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011683{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011684 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011685}
11686
paul94f2b392005-06-28 12:44:16 +000011687static void
paul718e3742002-12-13 20:15:29 +000011688bgp_distance_free (struct bgp_distance *bdistance)
11689{
11690 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11691}
11692
paul94f2b392005-06-28 12:44:16 +000011693static int
paulfd79ac92004-10-13 05:06:08 +000011694bgp_distance_set (struct vty *vty, const char *distance_str,
11695 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011696{
11697 int ret;
11698 struct prefix_ipv4 p;
11699 u_char distance;
11700 struct bgp_node *rn;
11701 struct bgp_distance *bdistance;
11702
11703 ret = str2prefix_ipv4 (ip_str, &p);
11704 if (ret == 0)
11705 {
11706 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11707 return CMD_WARNING;
11708 }
11709
11710 distance = atoi (distance_str);
11711
11712 /* Get BGP distance node. */
11713 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11714 if (rn->info)
11715 {
11716 bdistance = rn->info;
11717 bgp_unlock_node (rn);
11718 }
11719 else
11720 {
11721 bdistance = bgp_distance_new ();
11722 rn->info = bdistance;
11723 }
11724
11725 /* Set distance value. */
11726 bdistance->distance = distance;
11727
11728 /* Reset access-list configuration. */
11729 if (bdistance->access_list)
11730 {
11731 free (bdistance->access_list);
11732 bdistance->access_list = NULL;
11733 }
11734 if (access_list_str)
11735 bdistance->access_list = strdup (access_list_str);
11736
11737 return CMD_SUCCESS;
11738}
11739
paul94f2b392005-06-28 12:44:16 +000011740static int
paulfd79ac92004-10-13 05:06:08 +000011741bgp_distance_unset (struct vty *vty, const char *distance_str,
11742 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011743{
11744 int ret;
11745 struct prefix_ipv4 p;
11746 u_char distance;
11747 struct bgp_node *rn;
11748 struct bgp_distance *bdistance;
11749
11750 ret = str2prefix_ipv4 (ip_str, &p);
11751 if (ret == 0)
11752 {
11753 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11754 return CMD_WARNING;
11755 }
11756
11757 distance = atoi (distance_str);
11758
11759 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11760 if (! rn)
11761 {
11762 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11763 return CMD_WARNING;
11764 }
11765
11766 bdistance = rn->info;
11767
11768 if (bdistance->access_list)
11769 free (bdistance->access_list);
11770 bgp_distance_free (bdistance);
11771
11772 rn->info = NULL;
11773 bgp_unlock_node (rn);
11774 bgp_unlock_node (rn);
11775
11776 return CMD_SUCCESS;
11777}
11778
paul718e3742002-12-13 20:15:29 +000011779/* Apply BGP information to distance method. */
11780u_char
11781bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11782{
11783 struct bgp_node *rn;
11784 struct prefix_ipv4 q;
11785 struct peer *peer;
11786 struct bgp_distance *bdistance;
11787 struct access_list *alist;
11788 struct bgp_static *bgp_static;
11789
11790 if (! bgp)
11791 return 0;
11792
11793 if (p->family != AF_INET)
11794 return 0;
11795
11796 peer = rinfo->peer;
11797
11798 if (peer->su.sa.sa_family != AF_INET)
11799 return 0;
11800
11801 memset (&q, 0, sizeof (struct prefix_ipv4));
11802 q.family = AF_INET;
11803 q.prefix = peer->su.sin.sin_addr;
11804 q.prefixlen = IPV4_MAX_BITLEN;
11805
11806 /* Check source address. */
11807 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11808 if (rn)
11809 {
11810 bdistance = rn->info;
11811 bgp_unlock_node (rn);
11812
11813 if (bdistance->access_list)
11814 {
11815 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11816 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11817 return bdistance->distance;
11818 }
11819 else
11820 return bdistance->distance;
11821 }
11822
11823 /* Backdoor check. */
11824 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11825 if (rn)
11826 {
11827 bgp_static = rn->info;
11828 bgp_unlock_node (rn);
11829
11830 if (bgp_static->backdoor)
11831 {
11832 if (bgp->distance_local)
11833 return bgp->distance_local;
11834 else
11835 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11836 }
11837 }
11838
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011839 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011840 {
11841 if (bgp->distance_ebgp)
11842 return bgp->distance_ebgp;
11843 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11844 }
11845 else
11846 {
11847 if (bgp->distance_ibgp)
11848 return bgp->distance_ibgp;
11849 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11850 }
11851}
11852
11853DEFUN (bgp_distance,
11854 bgp_distance_cmd,
11855 "distance bgp <1-255> <1-255> <1-255>",
11856 "Define an administrative distance\n"
11857 "BGP distance\n"
11858 "Distance for routes external to the AS\n"
11859 "Distance for routes internal to the AS\n"
11860 "Distance for local routes\n")
11861{
11862 struct bgp *bgp;
11863
11864 bgp = vty->index;
11865
11866 bgp->distance_ebgp = atoi (argv[0]);
11867 bgp->distance_ibgp = atoi (argv[1]);
11868 bgp->distance_local = atoi (argv[2]);
11869 return CMD_SUCCESS;
11870}
11871
11872DEFUN (no_bgp_distance,
11873 no_bgp_distance_cmd,
11874 "no distance bgp <1-255> <1-255> <1-255>",
11875 NO_STR
11876 "Define an administrative distance\n"
11877 "BGP distance\n"
11878 "Distance for routes external to the AS\n"
11879 "Distance for routes internal to the AS\n"
11880 "Distance for local routes\n")
11881{
11882 struct bgp *bgp;
11883
11884 bgp = vty->index;
11885
11886 bgp->distance_ebgp= 0;
11887 bgp->distance_ibgp = 0;
11888 bgp->distance_local = 0;
11889 return CMD_SUCCESS;
11890}
11891
11892ALIAS (no_bgp_distance,
11893 no_bgp_distance2_cmd,
11894 "no distance bgp",
11895 NO_STR
11896 "Define an administrative distance\n"
11897 "BGP distance\n")
11898
11899DEFUN (bgp_distance_source,
11900 bgp_distance_source_cmd,
11901 "distance <1-255> A.B.C.D/M",
11902 "Define an administrative distance\n"
11903 "Administrative distance\n"
11904 "IP source prefix\n")
11905{
11906 bgp_distance_set (vty, argv[0], argv[1], NULL);
11907 return CMD_SUCCESS;
11908}
11909
11910DEFUN (no_bgp_distance_source,
11911 no_bgp_distance_source_cmd,
11912 "no distance <1-255> A.B.C.D/M",
11913 NO_STR
11914 "Define an administrative distance\n"
11915 "Administrative distance\n"
11916 "IP source prefix\n")
11917{
11918 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11919 return CMD_SUCCESS;
11920}
11921
11922DEFUN (bgp_distance_source_access_list,
11923 bgp_distance_source_access_list_cmd,
11924 "distance <1-255> A.B.C.D/M WORD",
11925 "Define an administrative distance\n"
11926 "Administrative distance\n"
11927 "IP source prefix\n"
11928 "Access list name\n")
11929{
11930 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11931 return CMD_SUCCESS;
11932}
11933
11934DEFUN (no_bgp_distance_source_access_list,
11935 no_bgp_distance_source_access_list_cmd,
11936 "no distance <1-255> A.B.C.D/M WORD",
11937 NO_STR
11938 "Define an administrative distance\n"
11939 "Administrative distance\n"
11940 "IP source prefix\n"
11941 "Access list name\n")
11942{
11943 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11944 return CMD_SUCCESS;
11945}
11946
11947DEFUN (bgp_damp_set,
11948 bgp_damp_set_cmd,
11949 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11950 "BGP Specific commands\n"
11951 "Enable route-flap dampening\n"
11952 "Half-life time for the penalty\n"
11953 "Value to start reusing a route\n"
11954 "Value to start suppressing a route\n"
11955 "Maximum duration to suppress a stable route\n")
11956{
11957 struct bgp *bgp;
11958 int half = DEFAULT_HALF_LIFE * 60;
11959 int reuse = DEFAULT_REUSE;
11960 int suppress = DEFAULT_SUPPRESS;
11961 int max = 4 * half;
11962
11963 if (argc == 4)
11964 {
11965 half = atoi (argv[0]) * 60;
11966 reuse = atoi (argv[1]);
11967 suppress = atoi (argv[2]);
11968 max = atoi (argv[3]) * 60;
11969 }
11970 else if (argc == 1)
11971 {
11972 half = atoi (argv[0]) * 60;
11973 max = 4 * half;
11974 }
11975
11976 bgp = vty->index;
11977 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11978 half, reuse, suppress, max);
11979}
11980
11981ALIAS (bgp_damp_set,
11982 bgp_damp_set2_cmd,
11983 "bgp dampening <1-45>",
11984 "BGP Specific commands\n"
11985 "Enable route-flap dampening\n"
11986 "Half-life time for the penalty\n")
11987
11988ALIAS (bgp_damp_set,
11989 bgp_damp_set3_cmd,
11990 "bgp dampening",
11991 "BGP Specific commands\n"
11992 "Enable route-flap dampening\n")
11993
11994DEFUN (bgp_damp_unset,
11995 bgp_damp_unset_cmd,
11996 "no bgp dampening",
11997 NO_STR
11998 "BGP Specific commands\n"
11999 "Enable route-flap dampening\n")
12000{
12001 struct bgp *bgp;
12002
12003 bgp = vty->index;
12004 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12005}
12006
12007ALIAS (bgp_damp_unset,
12008 bgp_damp_unset2_cmd,
12009 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12010 NO_STR
12011 "BGP Specific commands\n"
12012 "Enable route-flap dampening\n"
12013 "Half-life time for the penalty\n"
12014 "Value to start reusing a route\n"
12015 "Value to start suppressing a route\n"
12016 "Maximum duration to suppress a stable route\n")
12017
12018DEFUN (show_ip_bgp_dampened_paths,
12019 show_ip_bgp_dampened_paths_cmd,
12020 "show ip bgp dampened-paths",
12021 SHOW_STR
12022 IP_STR
12023 BGP_STR
12024 "Display paths suppressed due to dampening\n")
12025{
ajs5a646652004-11-05 01:25:55 +000012026 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12027 NULL);
paul718e3742002-12-13 20:15:29 +000012028}
12029
12030DEFUN (show_ip_bgp_flap_statistics,
12031 show_ip_bgp_flap_statistics_cmd,
12032 "show ip bgp flap-statistics",
12033 SHOW_STR
12034 IP_STR
12035 BGP_STR
12036 "Display flap statistics of routes\n")
12037{
ajs5a646652004-11-05 01:25:55 +000012038 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12039 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012040}
12041
12042/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012043static int
paulfd79ac92004-10-13 05:06:08 +000012044bgp_clear_damp_route (struct vty *vty, const char *view_name,
12045 const char *ip_str, afi_t afi, safi_t safi,
12046 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012047{
12048 int ret;
12049 struct prefix match;
12050 struct bgp_node *rn;
12051 struct bgp_node *rm;
12052 struct bgp_info *ri;
12053 struct bgp_info *ri_temp;
12054 struct bgp *bgp;
12055 struct bgp_table *table;
12056
12057 /* BGP structure lookup. */
12058 if (view_name)
12059 {
12060 bgp = bgp_lookup_by_name (view_name);
12061 if (bgp == NULL)
12062 {
12063 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12064 return CMD_WARNING;
12065 }
12066 }
12067 else
12068 {
12069 bgp = bgp_get_default ();
12070 if (bgp == NULL)
12071 {
12072 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12073 return CMD_WARNING;
12074 }
12075 }
12076
12077 /* Check IP address argument. */
12078 ret = str2prefix (ip_str, &match);
12079 if (! ret)
12080 {
12081 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12082 return CMD_WARNING;
12083 }
12084
12085 match.family = afi2family (afi);
12086
12087 if (safi == SAFI_MPLS_VPN)
12088 {
12089 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12090 {
12091 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12092 continue;
12093
12094 if ((table = rn->info) != NULL)
12095 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012096 {
12097 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12098 {
12099 ri = rm->info;
12100 while (ri)
12101 {
12102 if (ri->extra && ri->extra->damp_info)
12103 {
12104 ri_temp = ri->next;
12105 bgp_damp_info_free (ri->extra->damp_info, 1);
12106 ri = ri_temp;
12107 }
12108 else
12109 ri = ri->next;
12110 }
12111 }
12112
12113 bgp_unlock_node (rm);
12114 }
paul718e3742002-12-13 20:15:29 +000012115 }
12116 }
12117 else
12118 {
12119 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012120 {
12121 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12122 {
12123 ri = rn->info;
12124 while (ri)
12125 {
12126 if (ri->extra && ri->extra->damp_info)
12127 {
12128 ri_temp = ri->next;
12129 bgp_damp_info_free (ri->extra->damp_info, 1);
12130 ri = ri_temp;
12131 }
12132 else
12133 ri = ri->next;
12134 }
12135 }
12136
12137 bgp_unlock_node (rn);
12138 }
paul718e3742002-12-13 20:15:29 +000012139 }
12140
12141 return CMD_SUCCESS;
12142}
12143
12144DEFUN (clear_ip_bgp_dampening,
12145 clear_ip_bgp_dampening_cmd,
12146 "clear ip bgp dampening",
12147 CLEAR_STR
12148 IP_STR
12149 BGP_STR
12150 "Clear route flap dampening information\n")
12151{
12152 bgp_damp_info_clean ();
12153 return CMD_SUCCESS;
12154}
12155
12156DEFUN (clear_ip_bgp_dampening_prefix,
12157 clear_ip_bgp_dampening_prefix_cmd,
12158 "clear ip bgp dampening A.B.C.D/M",
12159 CLEAR_STR
12160 IP_STR
12161 BGP_STR
12162 "Clear route flap dampening information\n"
12163 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12164{
12165 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12166 SAFI_UNICAST, NULL, 1);
12167}
12168
12169DEFUN (clear_ip_bgp_dampening_address,
12170 clear_ip_bgp_dampening_address_cmd,
12171 "clear ip bgp dampening 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{
12178 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12179 SAFI_UNICAST, NULL, 0);
12180}
12181
12182DEFUN (clear_ip_bgp_dampening_address_mask,
12183 clear_ip_bgp_dampening_address_mask_cmd,
12184 "clear ip bgp dampening A.B.C.D A.B.C.D",
12185 CLEAR_STR
12186 IP_STR
12187 BGP_STR
12188 "Clear route flap dampening information\n"
12189 "Network to clear damping information\n"
12190 "Network mask\n")
12191{
12192 int ret;
12193 char prefix_str[BUFSIZ];
12194
12195 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12196 if (! ret)
12197 {
12198 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12199 return CMD_WARNING;
12200 }
12201
12202 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12203 SAFI_UNICAST, NULL, 0);
12204}
12205
paul94f2b392005-06-28 12:44:16 +000012206static int
paul718e3742002-12-13 20:15:29 +000012207bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12208 afi_t afi, safi_t safi, int *write)
12209{
12210 struct bgp_node *prn;
12211 struct bgp_node *rn;
12212 struct bgp_table *table;
12213 struct prefix *p;
12214 struct prefix_rd *prd;
12215 struct bgp_static *bgp_static;
12216 u_int32_t label;
12217 char buf[SU_ADDRSTRLEN];
12218 char rdbuf[RD_ADDRSTRLEN];
12219
12220 /* Network configuration. */
12221 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12222 if ((table = prn->info) != NULL)
12223 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12224 if ((bgp_static = rn->info) != NULL)
12225 {
12226 p = &rn->p;
12227 prd = (struct prefix_rd *) &prn->p;
12228
12229 /* "address-family" display. */
12230 bgp_config_write_family_header (vty, afi, safi, write);
12231
12232 /* "network" configuration display. */
12233 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12234 label = decode_label (bgp_static->tag);
12235
12236 vty_out (vty, " network %s/%d rd %s tag %d",
12237 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12238 p->prefixlen,
12239 rdbuf, label);
12240 vty_out (vty, "%s", VTY_NEWLINE);
12241 }
12242 return 0;
12243}
12244
12245/* Configuration of static route announcement and aggregate
12246 information. */
12247int
12248bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12249 afi_t afi, safi_t safi, int *write)
12250{
12251 struct bgp_node *rn;
12252 struct prefix *p;
12253 struct bgp_static *bgp_static;
12254 struct bgp_aggregate *bgp_aggregate;
12255 char buf[SU_ADDRSTRLEN];
12256
12257 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12258 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12259
12260 /* Network configuration. */
12261 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12262 if ((bgp_static = rn->info) != NULL)
12263 {
12264 p = &rn->p;
12265
12266 /* "address-family" display. */
12267 bgp_config_write_family_header (vty, afi, safi, write);
12268
12269 /* "network" configuration display. */
12270 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12271 {
12272 u_int32_t destination;
12273 struct in_addr netmask;
12274
12275 destination = ntohl (p->u.prefix4.s_addr);
12276 masklen2ip (p->prefixlen, &netmask);
12277 vty_out (vty, " network %s",
12278 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12279
12280 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12281 || (IN_CLASSB (destination) && p->prefixlen == 16)
12282 || (IN_CLASSA (destination) && p->prefixlen == 8)
12283 || p->u.prefix4.s_addr == 0)
12284 {
12285 /* Natural mask is not display. */
12286 }
12287 else
12288 vty_out (vty, " mask %s", inet_ntoa (netmask));
12289 }
12290 else
12291 {
12292 vty_out (vty, " network %s/%d",
12293 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12294 p->prefixlen);
12295 }
12296
12297 if (bgp_static->rmap.name)
12298 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012299 else
12300 {
12301 if (bgp_static->backdoor)
12302 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012303 }
paul718e3742002-12-13 20:15:29 +000012304
12305 vty_out (vty, "%s", VTY_NEWLINE);
12306 }
12307
12308 /* Aggregate-address configuration. */
12309 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12310 if ((bgp_aggregate = rn->info) != NULL)
12311 {
12312 p = &rn->p;
12313
12314 /* "address-family" display. */
12315 bgp_config_write_family_header (vty, afi, safi, write);
12316
12317 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12318 {
12319 struct in_addr netmask;
12320
12321 masklen2ip (p->prefixlen, &netmask);
12322 vty_out (vty, " aggregate-address %s %s",
12323 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12324 inet_ntoa (netmask));
12325 }
12326 else
12327 {
12328 vty_out (vty, " aggregate-address %s/%d",
12329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12330 p->prefixlen);
12331 }
12332
12333 if (bgp_aggregate->as_set)
12334 vty_out (vty, " as-set");
12335
12336 if (bgp_aggregate->summary_only)
12337 vty_out (vty, " summary-only");
12338
12339 vty_out (vty, "%s", VTY_NEWLINE);
12340 }
12341
12342 return 0;
12343}
12344
12345int
12346bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12347{
12348 struct bgp_node *rn;
12349 struct bgp_distance *bdistance;
12350
12351 /* Distance configuration. */
12352 if (bgp->distance_ebgp
12353 && bgp->distance_ibgp
12354 && bgp->distance_local
12355 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12356 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12357 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12358 vty_out (vty, " distance bgp %d %d %d%s",
12359 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12360 VTY_NEWLINE);
12361
12362 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12363 if ((bdistance = rn->info) != NULL)
12364 {
12365 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12366 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12367 bdistance->access_list ? bdistance->access_list : "",
12368 VTY_NEWLINE);
12369 }
12370
12371 return 0;
12372}
12373
12374/* Allocate routing table structure and install commands. */
12375void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012376bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012377{
12378 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012379 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012380
12381 /* IPv4 BGP commands. */
12382 install_element (BGP_NODE, &bgp_network_cmd);
12383 install_element (BGP_NODE, &bgp_network_mask_cmd);
12384 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12385 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12386 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12387 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12388 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12389 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12390 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12391 install_element (BGP_NODE, &no_bgp_network_cmd);
12392 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12393 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12394 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12395 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12396 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12397 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12398 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12400
12401 install_element (BGP_NODE, &aggregate_address_cmd);
12402 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12403 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12404 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12405 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12406 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12407 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12408 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12409 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12410 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12411 install_element (BGP_NODE, &no_aggregate_address_cmd);
12412 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12413 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12414 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12415 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12416 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12417 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12418 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12421
12422 /* IPv4 unicast configuration. */
12423 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12424 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12425 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12426 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12427 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12428 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012429 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012430 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12431 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12432 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12433 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12434 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012435
paul718e3742002-12-13 20:15:29 +000012436 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12437 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12438 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12439 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12440 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12441 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12442 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12443 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12444 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12446 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12447 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12448 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12449 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12450 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12451 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12452 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12453 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12456
12457 /* IPv4 multicast configuration. */
12458 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12459 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12460 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12461 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12462 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12463 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12464 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12465 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12466 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12470 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12471 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12472 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12473 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12474 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12475 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12476 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12477 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12480 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12481 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12482 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12483 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12484 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12485 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12486 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12487 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12490
12491 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012493 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012494 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012496 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012497 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012501 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012502 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012527 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12528 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12529 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12530 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12531 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012532 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012567 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012568 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012569 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012570 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012571 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012572 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012573 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12574 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012575 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012577 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012578 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012579 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012581
12582 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12583 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12584 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012585 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012586 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012589 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012590 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012602 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12603 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12604 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12605 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12606 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012607 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12608 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12609 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12610 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12611 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12612 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12613 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012616 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012617 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012618 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012619 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012620 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012621 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012622 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012623
12624 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012627 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012630 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012634 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012635 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012660 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12661 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12662 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12663 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12664 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012665 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012683 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012700 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012701 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012702 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012703 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012704 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012705 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012706 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12707 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012708 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012709 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012710 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012711 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012712 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012713 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012714
12715 /* BGP dampening clear commands */
12716 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12717 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12718 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12719 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12720
Paul Jakmaff7924f2006-09-04 01:10:36 +000012721 /* prefix count */
12722 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12723 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12724 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012725#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012726 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12727
paul718e3742002-12-13 20:15:29 +000012728 /* New config IPv6 BGP commands. */
12729 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12730 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12731 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12732 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12733
12734 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12735 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12736 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12737 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12738
G.Balaji73bfe0b2011-09-23 22:36:20 +053012739 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12740 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12741
paul718e3742002-12-13 20:15:29 +000012742 /* Old config IPv6 BGP commands. */
12743 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12744 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12745
12746 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12747 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12748 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12749 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12750
12751 install_element (VIEW_NODE, &show_bgp_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012754 install_element (VIEW_NODE, &show_bgp_route_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012756 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012757 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012759 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012760 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12762 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12764 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12766 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12768 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12770 install_element (VIEW_NODE, &show_bgp_community_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12772 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12774 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12776 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12778 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12780 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12782 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12784 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12786 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12788 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12792 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12794 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12796 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12797 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12798 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12799 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012800 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12801 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12802 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12803 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012804 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012805 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012806 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012808 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012810 install_element (VIEW_NODE, &show_bgp_view_cmd);
12811 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12812 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12813 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12814 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12815 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12816 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012828 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012830 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012831 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012832 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012833 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012834
12835 /* Restricted:
12836 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12837 */
12838 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012840 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012841 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012844 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012861 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012862 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012863 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012864 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012871 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012872 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012873 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012874
12875 install_element (ENABLE_NODE, &show_bgp_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012878 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012880 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012881 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012883 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012884 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012924 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012928 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012929 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012930 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012931 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012932 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012934 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012952 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012953 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012954 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012955 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012956 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012957 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012958
12959 /* Statistics */
12960 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12963 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12964
paul718e3742002-12-13 20:15:29 +000012965 /* old command */
12966 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013002
paul718e3742002-12-13 20:15:29 +000013003 /* old command */
13004 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13040
13041 /* old command */
13042 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13043 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13044 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13045 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13046
13047 /* old command */
13048 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13049 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13050 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13051 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13052
13053 /* old command */
13054 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13055 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13056 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13057 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13058#endif /* HAVE_IPV6 */
13059
13060 install_element (BGP_NODE, &bgp_distance_cmd);
13061 install_element (BGP_NODE, &no_bgp_distance_cmd);
13062 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13063 install_element (BGP_NODE, &bgp_distance_source_cmd);
13064 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13065 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13066 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13067
13068 install_element (BGP_NODE, &bgp_damp_set_cmd);
13069 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13070 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13071 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13072 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13073 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13074 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13075 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13076 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13077 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013078
13079 /* Deprecated AS-Pathlimit commands */
13080 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13081 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13082 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13083 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13084 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13085 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13086
13087 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13088 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13089 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13090 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13091 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13092 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13093
13094 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13095 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13096 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13097 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13098 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13099 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13100
13101 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13102 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13103 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13105 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13106 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13107
13108 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13109 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13110 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13111 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13112 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13113 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13114
13115 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13116 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13117 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13119 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13120 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013121
13122#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013123 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13124 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013125#endif
paul718e3742002-12-13 20:15:29 +000013126}
Chris Caputo228da422009-07-18 05:44:03 +000013127
13128void
13129bgp_route_finish (void)
13130{
13131 bgp_table_unlock (bgp_distance_table);
13132 bgp_distance_table = NULL;
13133}