blob: 46c0c85f66ae12463af6ca2050d2af08bddbce8b [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
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000968 /* If originator-id is not set and the route is to be reflected,
969 set the originator id */
970 if (peer && from && peer->sort == BGP_PEER_IBGP &&
971 from->sort == BGP_PEER_IBGP &&
972 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
973 {
974 attr->extra = bgp_attr_extra_get(attr);
975 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
976 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
977 }
978
paul718e3742002-12-13 20:15:29 +0000979 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000980 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000981 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
982 {
983 if (ri->peer != bgp->peer_self && ! transparent
984 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
985 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
986 }
987
988 /* next-hop-set */
989 if (transparent || reflect
990 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
991 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000992#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000993 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000995#endif /* HAVE_IPV6 */
996 )))
paul718e3742002-12-13 20:15:29 +0000997 {
998 /* NEXT-HOP Unchanged. */
999 }
1000 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1001 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1002#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001003 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001004 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001005#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001006 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001007 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1008 {
1009 /* Set IPv4 nexthop. */
1010 if (p->family == AF_INET)
1011 {
1012 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1014 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001015 else
1016 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1017 }
1018#ifdef HAVE_IPV6
1019 /* Set IPv6 nexthop. */
1020 if (p->family == AF_INET6)
1021 {
1022 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001024 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001026 }
1027#endif /* HAVE_IPV6 */
1028 }
1029
1030#ifdef HAVE_IPV6
1031 if (p->family == AF_INET6)
1032 {
paulfee0f4c2004-09-13 05:12:46 +00001033 /* Left nexthop_local unchanged if so configured. */
1034 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1035 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1036 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1038 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001039 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001040 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001041 }
1042
1043 /* Default nexthop_local treatment for non-RS-Clients */
1044 else
1045 {
paul718e3742002-12-13 20:15:29 +00001046 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001048
1049 /* Set link-local address for shared network peer. */
1050 if (peer->shared_network
1051 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1052 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001053 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001054 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001056 }
1057
1058 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1059 address.*/
1060 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001062
1063 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1064 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001065 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001066 }
paulfee0f4c2004-09-13 05:12:46 +00001067
1068 }
paul718e3742002-12-13 20:15:29 +00001069#endif /* HAVE_IPV6 */
1070
1071 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001072 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001073 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1074 && aspath_private_as_check (attr->aspath))
1075 attr->aspath = aspath_empty_get ();
1076
1077 /* Route map & unsuppress-map apply. */
1078 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001079 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001080 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001081 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001082 struct attr dummy_attr;
1083 struct attr_extra dummy_extra;
1084
1085 dummy_attr.extra = &dummy_extra;
1086
paul718e3742002-12-13 20:15:29 +00001087 info.peer = peer;
1088 info.attr = attr;
1089
1090 /* The route reflector is not allowed to modify the attributes
1091 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001092 if (from->sort == BGP_PEER_IBGP
1093 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001094 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001095 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001096 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001097 }
paulac41b2a2003-08-12 05:32:27 +00001098
1099 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1100
Paul Jakmafb982c22007-05-04 20:15:47 +00001101 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001102 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1103 else
1104 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1105
paulac41b2a2003-08-12 05:32:27 +00001106 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001107
paul718e3742002-12-13 20:15:29 +00001108 if (ret == RMAP_DENYMATCH)
1109 {
1110 bgp_attr_flush (attr);
1111 return 0;
1112 }
1113 }
1114 return 1;
1115}
1116
paul94f2b392005-06-28 12:44:16 +00001117static int
paulfee0f4c2004-09-13 05:12:46 +00001118bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1119 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001120{
paulfee0f4c2004-09-13 05:12:46 +00001121 int ret;
1122 char buf[SU_ADDRSTRLEN];
1123 struct bgp_filter *filter;
1124 struct bgp_info info;
1125 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001126 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001127
1128 from = ri->peer;
1129 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001130 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001131
Paul Jakma750e8142008-07-22 21:11:48 +00001132 if (DISABLE_BGP_ANNOUNCE)
1133 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 /* Do not send back route to sender. */
1136 if (from == rsclient)
1137 return 0;
1138
1139 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001140 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001141 if (! UNSUPPRESS_MAP_NAME (filter))
1142 return 0;
1143
1144 /* Default route check. */
1145 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1146 PEER_STATUS_DEFAULT_ORIGINATE))
1147 {
1148 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1149 return 0;
1150#ifdef HAVE_IPV6
1151 else if (p->family == AF_INET6 && p->prefixlen == 0)
1152 return 0;
1153#endif /* HAVE_IPV6 */
1154 }
1155
1156 /* If the attribute has originator-id and it is same as remote
1157 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001158 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001159 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001160 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001161 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001162 {
1163 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001164 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001165 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1166 rsclient->host,
1167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1168 p->prefixlen);
1169 return 0;
1170 }
1171 }
1172
1173 /* ORF prefix-list filter check */
1174 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1175 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1176 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1177 if (rsclient->orf_plist[afi][safi])
1178 {
1179 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1180 return 0;
1181 }
1182
1183 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001185 {
1186 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001187 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001188 "%s [Update:SEND] %s/%d is filtered",
1189 rsclient->host,
1190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1191 p->prefixlen);
1192 return 0;
1193 }
1194
1195#ifdef BGP_SEND_ASPATH_CHECK
1196 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001197 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001198 {
1199 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001200 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001201 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001202 rsclient->host, rsclient->as);
1203 return 0;
1204 }
1205#endif /* BGP_SEND_ASPATH_CHECK */
1206
1207 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001208 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001209
1210 /* next-hop-set */
1211 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1212#ifdef HAVE_IPV6
1213 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001215#endif /* HAVE_IPV6 */
1216 )
1217 {
1218 /* Set IPv4 nexthop. */
1219 if (p->family == AF_INET)
1220 {
1221 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001223 IPV4_MAX_BYTELEN);
1224 else
1225 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1226 }
1227#ifdef HAVE_IPV6
1228 /* Set IPv6 nexthop. */
1229 if (p->family == AF_INET6)
1230 {
1231 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001232 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001233 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236#endif /* HAVE_IPV6 */
1237 }
1238
1239#ifdef HAVE_IPV6
1240 if (p->family == AF_INET6)
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001243
paulfee0f4c2004-09-13 05:12:46 +00001244 /* Left nexthop_local unchanged if so configured. */
1245 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1246 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1247 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001248 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1249 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001250 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001252 }
1253
1254 /* Default nexthop_local treatment for RS-Clients */
1255 else
1256 {
1257 /* Announcer and RS-Client are both in the same network */
1258 if (rsclient->shared_network && from->shared_network &&
1259 (rsclient->ifindex == from->ifindex))
1260 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1262 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001263 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001265 }
1266
1267 /* Set link-local address for shared network peer. */
1268 else if (rsclient->shared_network
1269 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1270 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001272 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001273 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001274 }
1275
1276 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001277 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001278 }
1279
1280 }
1281#endif /* HAVE_IPV6 */
1282
1283
1284 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001285 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001286 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1287 && aspath_private_as_check (attr->aspath))
1288 attr->aspath = aspath_empty_get ();
1289
1290 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001291 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001292 {
1293 info.peer = rsclient;
1294 info.attr = attr;
1295
1296 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1297
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001299 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1300 else
1301 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1302
1303 rsclient->rmap_type = 0;
1304
1305 if (ret == RMAP_DENYMATCH)
1306 {
1307 bgp_attr_flush (attr);
1308 return 0;
1309 }
1310 }
1311
1312 return 1;
1313}
1314
1315struct bgp_info_pair
1316{
1317 struct bgp_info *old;
1318 struct bgp_info *new;
1319};
1320
paul94f2b392005-06-28 12:44:16 +00001321static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001322bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1323 struct bgp_maxpaths_cfg *mpath_cfg,
1324 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001325{
paul718e3742002-12-13 20:15:29 +00001326 struct bgp_info *new_select;
1327 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001328 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001329 struct bgp_info *ri1;
1330 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001331 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001332 int paths_eq, do_mpath;
1333 struct list mp_list;
1334
1335 bgp_mp_list_init (&mp_list);
1336 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1337 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1338
paul718e3742002-12-13 20:15:29 +00001339 /* bgp deterministic-med */
1340 new_select = NULL;
1341 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1342 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1343 {
1344 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri1))
1347 continue;
1348
1349 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001350 if (do_mpath)
1351 bgp_mp_list_add (&mp_list, ri1);
1352 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001353 if (ri1->next)
1354 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1355 {
1356 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1357 continue;
1358 if (BGP_INFO_HOLDDOWN (ri2))
1359 continue;
1360
1361 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1362 || aspath_cmp_left_confed (ri1->attr->aspath,
1363 ri2->attr->aspath))
1364 {
Josh Bailey6918e742011-07-20 20:48:20 -07001365 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1366 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001367 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001371 if (do_mpath && !paths_eq)
1372 {
1373 bgp_mp_list_clear (&mp_list);
1374 bgp_mp_list_add (&mp_list, ri2);
1375 }
paul718e3742002-12-13 20:15:29 +00001376 }
1377
Josh Bailey6918e742011-07-20 20:48:20 -07001378 if (do_mpath && paths_eq)
1379 bgp_mp_list_add (&mp_list, ri2);
1380
Paul Jakma1a392d42006-09-07 00:24:49 +00001381 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001382 }
1383 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001386
1387 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1388 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001389 }
1390
1391 /* Check old selected route and new selected route. */
1392 old_select = NULL;
1393 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001394 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001395 {
1396 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1397 old_select = ri;
1398
1399 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001400 {
1401 /* reap REMOVED routes, if needs be
1402 * selected route must stay for a while longer though
1403 */
1404 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1405 && (ri != old_select))
1406 bgp_info_reap (rn, ri);
1407
1408 continue;
1409 }
paul718e3742002-12-13 20:15:29 +00001410
1411 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1412 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1413 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001414 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001415 continue;
1416 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001417 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1418 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001419
Josh Bailey96450fa2011-07-20 20:45:12 -07001420 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1421 {
Josh Bailey6918e742011-07-20 20:48:20 -07001422 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1423 bgp_mp_dmed_deselect (new_select);
1424
Josh Bailey96450fa2011-07-20 20:45:12 -07001425 new_select = ri;
1426
1427 if (do_mpath && !paths_eq)
1428 {
1429 bgp_mp_list_clear (&mp_list);
1430 bgp_mp_list_add (&mp_list, ri);
1431 }
1432 }
Josh Bailey6918e742011-07-20 20:48:20 -07001433 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1434 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001435
1436 if (do_mpath && paths_eq)
1437 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001438 }
paulb40d9392005-08-22 22:34:41 +00001439
paulfee0f4c2004-09-13 05:12:46 +00001440
Josh Bailey6918e742011-07-20 20:48:20 -07001441 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1442 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001443
Josh Bailey0b597ef2011-07-20 20:49:11 -07001444 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001445 bgp_mp_list_clear (&mp_list);
1446
1447 result->old = old_select;
1448 result->new = new_select;
1449
1450 return;
paulfee0f4c2004-09-13 05:12:46 +00001451}
1452
paul94f2b392005-06-28 12:44:16 +00001453static int
paulfee0f4c2004-09-13 05:12:46 +00001454bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001455 struct bgp_node *rn, afi_t afi, safi_t safi)
1456{
paulfee0f4c2004-09-13 05:12:46 +00001457 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001458 struct attr attr;
1459 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001460
1461 p = &rn->p;
1462
Paul Jakma9eda90c2007-08-30 13:36:17 +00001463 /* Announce route to Established peer. */
1464 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001465 return 0;
1466
Paul Jakma9eda90c2007-08-30 13:36:17 +00001467 /* Address family configuration check. */
1468 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001469 return 0;
1470
Paul Jakma9eda90c2007-08-30 13:36:17 +00001471 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001472 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1473 PEER_STATUS_ORF_WAIT_REFRESH))
1474 return 0;
1475
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001476 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1477 attr.extra = &extra;
1478
Avneesh Sachdev67174042012-08-17 08:19:49 -07001479 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001480 {
1481 case BGP_TABLE_MAIN:
1482 /* Announcement to peer->conf. If the route is filtered,
1483 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001484 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1485 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001486 else
1487 bgp_adj_out_unset (rn, peer, p, afi, safi);
1488 break;
1489 case BGP_TABLE_RSCLIENT:
1490 /* Announcement to peer->conf. If the route is filtered,
1491 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001492 if (selected &&
1493 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1494 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1495 else
1496 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001497 break;
1498 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001499
paulfee0f4c2004-09-13 05:12:46 +00001500 return 0;
paul200df112005-06-01 11:17:05 +00001501}
paulfee0f4c2004-09-13 05:12:46 +00001502
paul200df112005-06-01 11:17:05 +00001503struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001504{
paul200df112005-06-01 11:17:05 +00001505 struct bgp *bgp;
1506 struct bgp_node *rn;
1507 afi_t afi;
1508 safi_t safi;
1509};
1510
1511static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001512bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001513{
paul0fb58d52005-11-14 14:31:49 +00001514 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001515 struct bgp *bgp = pq->bgp;
1516 struct bgp_node *rn = pq->rn;
1517 afi_t afi = pq->afi;
1518 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001519 struct bgp_info *new_select;
1520 struct bgp_info *old_select;
1521 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001522 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001523 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001524
paulfee0f4c2004-09-13 05:12:46 +00001525 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001526 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001527 new_select = old_and_new.new;
1528 old_select = old_and_new.old;
1529
paul200df112005-06-01 11:17:05 +00001530 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1531 {
Chris Caputo228da422009-07-18 05:44:03 +00001532 if (rsclient->group)
1533 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1534 {
1535 /* Nothing to do. */
1536 if (old_select && old_select == new_select)
1537 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1538 continue;
paulfee0f4c2004-09-13 05:12:46 +00001539
Chris Caputo228da422009-07-18 05:44:03 +00001540 if (old_select)
1541 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1542 if (new_select)
1543 {
1544 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1545 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001546 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1547 }
paulfee0f4c2004-09-13 05:12:46 +00001548
Chris Caputo228da422009-07-18 05:44:03 +00001549 bgp_process_announce_selected (rsclient, new_select, rn,
1550 afi, safi);
1551 }
paul200df112005-06-01 11:17:05 +00001552 }
1553 else
1554 {
hassob7395792005-08-26 12:58:38 +00001555 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001556 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001557 if (new_select)
1558 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001559 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1560 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001561 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001562 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001563 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001564 }
paulfee0f4c2004-09-13 05:12:46 +00001565
paulb40d9392005-08-22 22:34:41 +00001566 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1567 bgp_info_reap (rn, old_select);
1568
paul200df112005-06-01 11:17:05 +00001569 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1570 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001571}
1572
paul200df112005-06-01 11:17:05 +00001573static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001574bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001575{
paul0fb58d52005-11-14 14:31:49 +00001576 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001577 struct bgp *bgp = pq->bgp;
1578 struct bgp_node *rn = pq->rn;
1579 afi_t afi = pq->afi;
1580 safi_t safi = pq->safi;
1581 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001582 struct bgp_info *new_select;
1583 struct bgp_info *old_select;
1584 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001585 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001586 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001587
paulfee0f4c2004-09-13 05:12:46 +00001588 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001589 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001590 old_select = old_and_new.old;
1591 new_select = old_and_new.new;
1592
1593 /* Nothing to do. */
1594 if (old_select && old_select == new_select)
1595 {
1596 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001597 {
Josh Bailey8196f132011-07-20 20:47:07 -07001598 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1599 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001600 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001601
Josh Bailey8196f132011-07-20 20:47:07 -07001602 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001603 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1604 return WQ_SUCCESS;
1605 }
paulfee0f4c2004-09-13 05:12:46 +00001606 }
paul718e3742002-12-13 20:15:29 +00001607
hasso338b3422005-02-23 14:27:24 +00001608 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001609 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001610 if (new_select)
1611 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001612 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1613 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001615 }
1616
1617
paul718e3742002-12-13 20:15:29 +00001618 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001619 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001620 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001621 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001622 }
1623
1624 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001625 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1626 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001627 {
1628 if (new_select
1629 && new_select->type == ZEBRA_ROUTE_BGP
1630 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001631 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001632 else
1633 {
1634 /* Withdraw the route from the kernel. */
1635 if (old_select
1636 && old_select->type == ZEBRA_ROUTE_BGP
1637 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001638 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001639 }
1640 }
paulb40d9392005-08-22 22:34:41 +00001641
1642 /* Reap old select bgp_info, it it has been removed */
1643 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1644 bgp_info_reap (rn, old_select);
1645
paul200df112005-06-01 11:17:05 +00001646 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1647 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001648}
1649
paul200df112005-06-01 11:17:05 +00001650static void
paul0fb58d52005-11-14 14:31:49 +00001651bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001652{
paul0fb58d52005-11-14 14:31:49 +00001653 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001654 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001655
Chris Caputo228da422009-07-18 05:44:03 +00001656 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001657 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001658 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001659 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1660}
1661
1662static void
1663bgp_process_queue_init (void)
1664{
1665 bm->process_main_queue
1666 = work_queue_new (bm->master, "process_main_queue");
1667 bm->process_rsclient_queue
1668 = work_queue_new (bm->master, "process_rsclient_queue");
1669
1670 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1671 {
1672 zlog_err ("%s: Failed to allocate work queue", __func__);
1673 exit (1);
1674 }
1675
1676 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001677 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001678 bm->process_main_queue->spec.max_retries = 0;
1679 bm->process_main_queue->spec.hold = 50;
1680
1681 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1682 sizeof (struct work_queue *));
1683 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001684}
1685
1686void
paulfee0f4c2004-09-13 05:12:46 +00001687bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1688{
paul200df112005-06-01 11:17:05 +00001689 struct bgp_process_queue *pqnode;
1690
1691 /* already scheduled for processing? */
1692 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1693 return;
1694
1695 if ( (bm->process_main_queue == NULL) ||
1696 (bm->process_rsclient_queue == NULL) )
1697 bgp_process_queue_init ();
1698
1699 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1700 sizeof (struct bgp_process_queue));
1701 if (!pqnode)
1702 return;
Chris Caputo228da422009-07-18 05:44:03 +00001703
1704 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001705 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001706 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001707 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001708 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001709 pqnode->afi = afi;
1710 pqnode->safi = safi;
1711
Avneesh Sachdev67174042012-08-17 08:19:49 -07001712 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001713 {
paul200df112005-06-01 11:17:05 +00001714 case BGP_TABLE_MAIN:
1715 work_queue_add (bm->process_main_queue, pqnode);
1716 break;
1717 case BGP_TABLE_RSCLIENT:
1718 work_queue_add (bm->process_rsclient_queue, pqnode);
1719 break;
paulfee0f4c2004-09-13 05:12:46 +00001720 }
paul200df112005-06-01 11:17:05 +00001721
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001722 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001723 return;
paulfee0f4c2004-09-13 05:12:46 +00001724}
hasso0a486e52005-02-01 20:57:17 +00001725
paul94f2b392005-06-28 12:44:16 +00001726static int
hasso0a486e52005-02-01 20:57:17 +00001727bgp_maximum_prefix_restart_timer (struct thread *thread)
1728{
1729 struct peer *peer;
1730
1731 peer = THREAD_ARG (thread);
1732 peer->t_pmax_restart = NULL;
1733
1734 if (BGP_DEBUG (events, EVENTS))
1735 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1736 peer->host);
1737
1738 peer_clear (peer);
1739
1740 return 0;
1741}
1742
paulfee0f4c2004-09-13 05:12:46 +00001743int
paul5228ad22004-06-04 17:58:18 +00001744bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1745 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001746{
hassoe0701b72004-05-20 09:19:34 +00001747 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1748 return 0;
1749
1750 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001751 {
hassoe0701b72004-05-20 09:19:34 +00001752 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1753 && ! always)
1754 return 0;
paul718e3742002-12-13 20:15:29 +00001755
hassoe0701b72004-05-20 09:19:34 +00001756 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001757 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1758 "limit %ld", afi_safi_print (afi, safi), peer->host,
1759 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001760 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001761
hassoe0701b72004-05-20 09:19:34 +00001762 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1763 return 0;
paul718e3742002-12-13 20:15:29 +00001764
hassoe0701b72004-05-20 09:19:34 +00001765 {
paul5228ad22004-06-04 17:58:18 +00001766 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001767
1768 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001769 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001770
1771 ndata[0] = (afi >> 8);
1772 ndata[1] = afi;
1773 ndata[2] = safi;
1774 ndata[3] = (peer->pmax[afi][safi] >> 24);
1775 ndata[4] = (peer->pmax[afi][safi] >> 16);
1776 ndata[5] = (peer->pmax[afi][safi] >> 8);
1777 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001778
1779 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1780 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1781 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1782 }
hasso0a486e52005-02-01 20:57:17 +00001783
1784 /* restart timer start */
1785 if (peer->pmax_restart[afi][safi])
1786 {
1787 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1788
1789 if (BGP_DEBUG (events, EVENTS))
1790 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1791 peer->host, peer->v_pmax_restart);
1792
1793 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1794 peer->v_pmax_restart);
1795 }
1796
hassoe0701b72004-05-20 09:19:34 +00001797 return 1;
paul718e3742002-12-13 20:15:29 +00001798 }
hassoe0701b72004-05-20 09:19:34 +00001799 else
1800 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1801
1802 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1803 {
1804 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1805 && ! always)
1806 return 0;
1807
1808 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001809 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1810 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1811 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001812 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1813 }
1814 else
1815 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001816 return 0;
1817}
1818
paulb40d9392005-08-22 22:34:41 +00001819/* Unconditionally remove the route from the RIB, without taking
1820 * damping into consideration (eg, because the session went down)
1821 */
paul94f2b392005-06-28 12:44:16 +00001822static void
paul718e3742002-12-13 20:15:29 +00001823bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1824 afi_t afi, safi_t safi)
1825{
paul902212c2006-02-05 17:51:19 +00001826 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1827
1828 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1829 bgp_info_delete (rn, ri); /* keep historical info */
1830
paulb40d9392005-08-22 22:34:41 +00001831 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001832}
1833
paul94f2b392005-06-28 12:44:16 +00001834static void
paul718e3742002-12-13 20:15:29 +00001835bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001836 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001837{
paul718e3742002-12-13 20:15:29 +00001838 int status = BGP_DAMP_NONE;
1839
paulb40d9392005-08-22 22:34:41 +00001840 /* apply dampening, if result is suppressed, we'll be retaining
1841 * the bgp_info in the RIB for historical reference.
1842 */
1843 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001844 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001845 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1846 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001847 {
paul902212c2006-02-05 17:51:19 +00001848 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1849 return;
1850 }
1851
1852 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001853}
1854
paul94f2b392005-06-28 12:44:16 +00001855static void
paulfee0f4c2004-09-13 05:12:46 +00001856bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1857 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1858 int sub_type, struct prefix_rd *prd, u_char *tag)
1859{
1860 struct bgp_node *rn;
1861 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001862 struct attr new_attr;
1863 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001864 struct attr *attr_new;
1865 struct attr *attr_new2;
1866 struct bgp_info *ri;
1867 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001868 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001869 char buf[SU_ADDRSTRLEN];
1870
1871 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1872 if (peer == rsclient)
1873 return;
1874
1875 bgp = peer->bgp;
1876 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1877
1878 /* Check previously received route. */
1879 for (ri = rn->info; ri; ri = ri->next)
1880 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1881 break;
1882
1883 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001884 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001885 {
1886 reason = "as-path contains our own AS;";
1887 goto filtered;
1888 }
1889
1890 /* Route reflector originator ID check. */
1891 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001892 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001893 {
1894 reason = "originator is us;";
1895 goto filtered;
1896 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001897
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001898 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001899 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001900
1901 /* Apply export policy. */
1902 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1903 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1904 {
1905 reason = "export-policy;";
1906 goto filtered;
1907 }
1908
1909 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001910
paulfee0f4c2004-09-13 05:12:46 +00001911 /* Apply import policy. */
1912 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1913 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001914 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001915
1916 reason = "import-policy;";
1917 goto filtered;
1918 }
1919
1920 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001921 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001922
1923 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001924 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001925 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001926 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001927 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001928 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001929 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001930 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001931
1932 reason = "martian next-hop;";
1933 goto filtered;
1934 }
1935 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001936
paulfee0f4c2004-09-13 05:12:46 +00001937 /* If the update is implicit withdraw. */
1938 if (ri)
1939 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001940 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001941
1942 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001943 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1944 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001945 {
1946
Paul Jakma1a392d42006-09-07 00:24:49 +00001947 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001948
1949 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001950 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001951 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1952 peer->host,
1953 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1954 p->prefixlen, rsclient->host);
1955
Chris Caputo228da422009-07-18 05:44:03 +00001956 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001957 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001958
Chris Caputo228da422009-07-18 05:44:03 +00001959 return;
paulfee0f4c2004-09-13 05:12:46 +00001960 }
1961
Paul Jakma16d2e242007-04-10 19:32:10 +00001962 /* Withdraw/Announce before we fully processed the withdraw */
1963 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1964 bgp_info_restore (rn, ri);
1965
paulfee0f4c2004-09-13 05:12:46 +00001966 /* Received Logging. */
1967 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001968 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001969 peer->host,
1970 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1971 p->prefixlen, rsclient->host);
1972
1973 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001974 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001975
1976 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001977 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001978 ri->attr = attr_new;
1979
1980 /* Update MPLS tag. */
1981 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001982 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001983
Paul Jakma1a392d42006-09-07 00:24:49 +00001984 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001985
1986 /* Process change. */
1987 bgp_process (bgp, rn, afi, safi);
1988 bgp_unlock_node (rn);
1989
1990 return;
1991 }
1992
1993 /* Received Logging. */
1994 if (BGP_DEBUG (update, UPDATE_IN))
1995 {
ajsd2c1f162004-12-08 21:10:20 +00001996 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001997 peer->host,
1998 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1999 p->prefixlen, rsclient->host);
2000 }
2001
2002 /* Make new BGP info. */
2003 new = bgp_info_new ();
2004 new->type = type;
2005 new->sub_type = sub_type;
2006 new->peer = peer;
2007 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002008 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002009
2010 /* Update MPLS tag. */
2011 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002012 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002013
Paul Jakma1a392d42006-09-07 00:24:49 +00002014 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002015
2016 /* Register new BGP information. */
2017 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002018
2019 /* route_node_get lock */
2020 bgp_unlock_node (rn);
2021
paulfee0f4c2004-09-13 05:12:46 +00002022 /* Process change. */
2023 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002024
paulfee0f4c2004-09-13 05:12:46 +00002025 return;
2026
2027 filtered:
2028
2029 /* This BGP update is filtered. Log the reason then update BGP entry. */
2030 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002031 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002032 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2033 peer->host,
2034 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2035 p->prefixlen, rsclient->host, reason);
2036
2037 if (ri)
paulb40d9392005-08-22 22:34:41 +00002038 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002039
2040 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002041
paulfee0f4c2004-09-13 05:12:46 +00002042 return;
2043}
2044
paul94f2b392005-06-28 12:44:16 +00002045static void
paulfee0f4c2004-09-13 05:12:46 +00002046bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2047 struct peer *peer, struct prefix *p, int type, int sub_type,
2048 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002049{
paulfee0f4c2004-09-13 05:12:46 +00002050 struct bgp_node *rn;
2051 struct bgp_info *ri;
2052 char buf[SU_ADDRSTRLEN];
2053
2054 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002055 return;
paulfee0f4c2004-09-13 05:12:46 +00002056
2057 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2058
2059 /* Lookup withdrawn route. */
2060 for (ri = rn->info; ri; ri = ri->next)
2061 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2062 break;
2063
2064 /* Withdraw specified route from routing table. */
2065 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002066 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002067 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002068 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002069 "%s Can't find the route %s/%d", peer->host,
2070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2071 p->prefixlen);
2072
2073 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002074 bgp_unlock_node (rn);
2075}
paulfee0f4c2004-09-13 05:12:46 +00002076
paul94f2b392005-06-28 12:44:16 +00002077static int
paulfee0f4c2004-09-13 05:12:46 +00002078bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002079 afi_t afi, safi_t safi, int type, int sub_type,
2080 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2081{
2082 int ret;
2083 int aspath_loop_count = 0;
2084 struct bgp_node *rn;
2085 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002086 struct attr new_attr;
2087 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002088 struct attr *attr_new;
2089 struct bgp_info *ri;
2090 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002091 const char *reason;
paul718e3742002-12-13 20:15:29 +00002092 char buf[SU_ADDRSTRLEN];
2093
2094 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002095 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002096
paul718e3742002-12-13 20:15:29 +00002097 /* When peer's soft reconfiguration enabled. Record input packet in
2098 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002099 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2100 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002101 bgp_adj_in_set (rn, peer, attr);
2102
2103 /* Check previously received route. */
2104 for (ri = rn->info; ri; ri = ri->next)
2105 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2106 break;
2107
2108 /* AS path local-as loop check. */
2109 if (peer->change_local_as)
2110 {
2111 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2112 aspath_loop_count = 1;
2113
2114 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2115 {
2116 reason = "as-path contains our own AS;";
2117 goto filtered;
2118 }
2119 }
2120
2121 /* AS path loop check. */
2122 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2123 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2124 && aspath_loop_check(attr->aspath, bgp->confed_id)
2125 > peer->allowas_in[afi][safi]))
2126 {
2127 reason = "as-path contains our own AS;";
2128 goto filtered;
2129 }
2130
2131 /* Route reflector originator ID check. */
2132 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002133 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002134 {
2135 reason = "originator is us;";
2136 goto filtered;
2137 }
2138
2139 /* Route reflector cluster ID check. */
2140 if (bgp_cluster_filter (peer, attr))
2141 {
2142 reason = "reflected from the same cluster;";
2143 goto filtered;
2144 }
2145
2146 /* Apply incoming filter. */
2147 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2148 {
2149 reason = "filter;";
2150 goto filtered;
2151 }
2152
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002153 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002154 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002155
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002156 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002157 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2158 {
2159 reason = "route-map;";
2160 goto filtered;
2161 }
2162
2163 /* IPv4 unicast next hop check. */
2164 if (afi == AFI_IP && safi == SAFI_UNICAST)
2165 {
2166 /* If the peer is EBGP and nexthop is not on connected route,
2167 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002168 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002169 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002170 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002171 {
2172 reason = "non-connected next-hop;";
2173 goto filtered;
2174 }
2175
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002176 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002177 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002178 if (new_attr.nexthop.s_addr == 0
2179 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2180 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002181 {
2182 reason = "martian next-hop;";
2183 goto filtered;
2184 }
2185 }
2186
2187 attr_new = bgp_attr_intern (&new_attr);
2188
2189 /* If the update is implicit withdraw. */
2190 if (ri)
2191 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002192 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002193
2194 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002195 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2196 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002197 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002198 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002199
2200 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002201 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002202 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2203 {
2204 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002205 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002206 peer->host,
2207 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2208 p->prefixlen);
2209
paul902212c2006-02-05 17:51:19 +00002210 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2211 {
2212 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2213 bgp_process (bgp, rn, afi, safi);
2214 }
paul718e3742002-12-13 20:15:29 +00002215 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002216 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002217 {
2218 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002219 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002220 "%s rcvd %s/%d...duplicate ignored",
2221 peer->host,
2222 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2223 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002224
2225 /* graceful restart STALE flag unset. */
2226 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2227 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002228 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002229 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002230 }
paul718e3742002-12-13 20:15:29 +00002231 }
2232
2233 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002234 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002235
paul718e3742002-12-13 20:15:29 +00002236 return 0;
2237 }
2238
Paul Jakma16d2e242007-04-10 19:32:10 +00002239 /* Withdraw/Announce before we fully processed the withdraw */
2240 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2241 {
2242 if (BGP_DEBUG (update, UPDATE_IN))
2243 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2244 peer->host,
2245 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2246 p->prefixlen);
2247 bgp_info_restore (rn, ri);
2248 }
2249
paul718e3742002-12-13 20:15:29 +00002250 /* Received Logging. */
2251 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002252 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002253 peer->host,
2254 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2255 p->prefixlen);
2256
hasso93406d82005-02-02 14:40:33 +00002257 /* graceful restart STALE flag unset. */
2258 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002259 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002260
paul718e3742002-12-13 20:15:29 +00002261 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002262 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002263
2264 /* implicit withdraw, decrement aggregate and pcount here.
2265 * only if update is accepted, they'll increment below.
2266 */
paul902212c2006-02-05 17:51:19 +00002267 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2268
paul718e3742002-12-13 20:15:29 +00002269 /* Update bgp route dampening information. */
2270 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002271 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002272 {
2273 /* This is implicit withdraw so we should update dampening
2274 information. */
2275 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2276 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002277 }
2278
paul718e3742002-12-13 20:15:29 +00002279 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002280 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002281 ri->attr = attr_new;
2282
2283 /* Update MPLS tag. */
2284 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002285 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002286
2287 /* Update bgp route dampening information. */
2288 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002289 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002290 {
2291 /* Now we do normal update dampening. */
2292 ret = bgp_damp_update (ri, rn, afi, safi);
2293 if (ret == BGP_DAMP_SUPPRESSED)
2294 {
2295 bgp_unlock_node (rn);
2296 return 0;
2297 }
2298 }
2299
2300 /* Nexthop reachability check. */
2301 if ((afi == AFI_IP || afi == AFI_IP6)
2302 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002303 && (peer->sort == BGP_PEER_IBGP
2304 || peer->sort == BGP_PEER_CONFED
2305 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002306 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002307 {
2308 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002310 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002311 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002312 }
2313 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002314 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002315
2316 /* Process change. */
2317 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2318
2319 bgp_process (bgp, rn, afi, safi);
2320 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002321
paul718e3742002-12-13 20:15:29 +00002322 return 0;
2323 }
2324
2325 /* Received Logging. */
2326 if (BGP_DEBUG (update, UPDATE_IN))
2327 {
ajsd2c1f162004-12-08 21:10:20 +00002328 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002329 peer->host,
2330 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2331 p->prefixlen);
2332 }
2333
paul718e3742002-12-13 20:15:29 +00002334 /* Make new BGP info. */
2335 new = bgp_info_new ();
2336 new->type = type;
2337 new->sub_type = sub_type;
2338 new->peer = peer;
2339 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002340 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002341
2342 /* Update MPLS tag. */
2343 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002344 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002345
2346 /* Nexthop reachability check. */
2347 if ((afi == AFI_IP || afi == AFI_IP6)
2348 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002349 && (peer->sort == BGP_PEER_IBGP
2350 || peer->sort == BGP_PEER_CONFED
2351 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002352 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002353 {
2354 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002355 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002356 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002357 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002358 }
2359 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002360 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002361
paul902212c2006-02-05 17:51:19 +00002362 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002363 bgp_aggregate_increment (bgp, p, new, afi, safi);
2364
2365 /* Register new BGP information. */
2366 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002367
2368 /* route_node_get lock */
2369 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002370
paul718e3742002-12-13 20:15:29 +00002371 /* If maximum prefix count is configured and current prefix
2372 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002373 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2374 return -1;
paul718e3742002-12-13 20:15:29 +00002375
2376 /* Process change. */
2377 bgp_process (bgp, rn, afi, safi);
2378
2379 return 0;
2380
2381 /* This BGP update is filtered. Log the reason then update BGP
2382 entry. */
2383 filtered:
2384 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002385 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002386 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2387 peer->host,
2388 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2389 p->prefixlen, reason);
2390
2391 if (ri)
paulb40d9392005-08-22 22:34:41 +00002392 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002393
2394 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002395
paul718e3742002-12-13 20:15:29 +00002396 return 0;
2397}
2398
2399int
paulfee0f4c2004-09-13 05:12:46 +00002400bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2401 afi_t afi, safi_t safi, int type, int sub_type,
2402 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2403{
2404 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002405 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002406 struct bgp *bgp;
2407 int ret;
2408
2409 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2410 soft_reconfig);
2411
2412 bgp = peer->bgp;
2413
2414 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002415 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002416 {
2417 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2418 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2419 sub_type, prd, tag);
2420 }
2421
2422 return ret;
2423}
2424
2425int
paul718e3742002-12-13 20:15:29 +00002426bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002427 afi_t afi, safi_t safi, int type, int sub_type,
2428 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002429{
2430 struct bgp *bgp;
2431 char buf[SU_ADDRSTRLEN];
2432 struct bgp_node *rn;
2433 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002434 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002435 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002436
2437 bgp = peer->bgp;
2438
paulfee0f4c2004-09-13 05:12:46 +00002439 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002440 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002441 {
2442 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2443 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2444 }
2445
paul718e3742002-12-13 20:15:29 +00002446 /* Logging. */
2447 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002448 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002449 peer->host,
2450 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2451 p->prefixlen);
2452
2453 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002454 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002455
2456 /* If peer is soft reconfiguration enabled. Record input packet for
2457 further calculation. */
2458 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2459 && peer != bgp->peer_self)
2460 bgp_adj_in_unset (rn, peer);
2461
2462 /* Lookup withdrawn route. */
2463 for (ri = rn->info; ri; ri = ri->next)
2464 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2465 break;
2466
2467 /* Withdraw specified route from routing table. */
2468 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002469 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002470 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002471 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002472 "%s Can't find the route %s/%d", peer->host,
2473 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2474 p->prefixlen);
2475
2476 /* Unlock bgp_node_get() lock. */
2477 bgp_unlock_node (rn);
2478
2479 return 0;
2480}
2481
2482void
2483bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2484{
2485 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002486 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002487 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002488 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002489 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002490 struct bgp_node *rn;
2491 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002492 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002493
Paul Jakmab2497022007-06-14 11:17:58 +00002494 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002495 return;
2496
paul718e3742002-12-13 20:15:29 +00002497 bgp = peer->bgp;
2498 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002499
paul718e3742002-12-13 20:15:29 +00002500 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2501 aspath = attr.aspath;
2502 attr.local_pref = bgp->default_local_pref;
2503 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2504
2505 if (afi == AFI_IP)
2506 str2prefix ("0.0.0.0/0", &p);
2507#ifdef HAVE_IPV6
2508 else if (afi == AFI_IP6)
2509 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002510 struct attr_extra *ae = attr.extra;
2511
paul718e3742002-12-13 20:15:29 +00002512 str2prefix ("::/0", &p);
2513
2514 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002515 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002516 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002517 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002518
2519 /* If the peer is on shared nextwork and we have link-local
2520 nexthop set it. */
2521 if (peer->shared_network
2522 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2523 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002524 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002525 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002526 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002527 }
2528 }
2529#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002530
2531 if (peer->default_rmap[afi][safi].name)
2532 {
paulfee0f4c2004-09-13 05:12:46 +00002533 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002534 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2535 {
2536 for (ri = rn->info; ri; ri = ri->next)
2537 {
2538 struct attr dummy_attr;
2539 struct attr_extra dummy_extra;
2540 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002541
Christian Frankedcab1bb2012-12-07 16:45:52 +00002542 /* Provide dummy so the route-map can't modify the attributes */
2543 dummy_attr.extra = &dummy_extra;
2544 bgp_attr_dup(&dummy_attr, ri->attr);
2545 info.peer = ri->peer;
2546 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002547
Christian Frankedcab1bb2012-12-07 16:45:52 +00002548 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2549 RMAP_BGP, &info);
2550
2551 /* The route map might have set attributes. If we don't flush them
2552 * here, they will be leaked. */
2553 bgp_attr_flush(&dummy_attr);
2554 if (ret != RMAP_DENYMATCH)
2555 break;
2556 }
2557 if (ret != RMAP_DENYMATCH)
2558 break;
2559 }
paulfee0f4c2004-09-13 05:12:46 +00002560 bgp->peer_self->rmap_type = 0;
2561
paul718e3742002-12-13 20:15:29 +00002562 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002563 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002564 }
2565
2566 if (withdraw)
2567 {
2568 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2569 bgp_default_withdraw_send (peer, afi, safi);
2570 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2571 }
2572 else
2573 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002574 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2575 {
2576 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2577 bgp_default_update_send (peer, &attr, afi, safi, from);
2578 }
paul718e3742002-12-13 20:15:29 +00002579 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002580
2581 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002582 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002583}
2584
2585static void
2586bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002587 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002588{
2589 struct bgp_node *rn;
2590 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002591 struct attr attr;
2592 struct attr_extra extra;
2593
paul718e3742002-12-13 20:15:29 +00002594 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002595 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002596
2597 if (safi != SAFI_MPLS_VPN
2598 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2599 bgp_default_originate (peer, afi, safi, 0);
2600
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002601 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2602 attr.extra = &extra;
2603
paul718e3742002-12-13 20:15:29 +00002604 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2605 for (ri = rn->info; ri; ri = ri->next)
2606 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2607 {
paulfee0f4c2004-09-13 05:12:46 +00002608 if ( (rsclient) ?
2609 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2610 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002611 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2612 else
2613 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2614 }
2615}
2616
2617void
2618bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2619{
2620 struct bgp_node *rn;
2621 struct bgp_table *table;
2622
2623 if (peer->status != Established)
2624 return;
2625
2626 if (! peer->afc_nego[afi][safi])
2627 return;
2628
2629 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2630 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2631 return;
2632
2633 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002634 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002635 else
2636 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2637 rn = bgp_route_next(rn))
2638 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002639 bgp_announce_table (peer, afi, safi, table, 0);
2640
2641 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2642 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002643}
2644
2645void
2646bgp_announce_route_all (struct peer *peer)
2647{
2648 afi_t afi;
2649 safi_t safi;
2650
2651 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2652 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2653 bgp_announce_route (peer, afi, safi);
2654}
2655
2656static void
paulfee0f4c2004-09-13 05:12:46 +00002657bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002658 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002659{
2660 struct bgp_node *rn;
2661 struct bgp_adj_in *ain;
2662
2663 if (! table)
2664 table = rsclient->bgp->rib[afi][safi];
2665
2666 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2667 for (ain = rn->adj_in; ain; ain = ain->next)
2668 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002669 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002670 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002671
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002673 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002674 }
2675}
2676
2677void
2678bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2679{
2680 struct bgp_table *table;
2681 struct bgp_node *rn;
2682
2683 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002684 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002685
2686 else
2687 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2688 rn = bgp_route_next (rn))
2689 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002690 {
2691 struct prefix_rd prd;
2692 prd.family = AF_UNSPEC;
2693 prd.prefixlen = 64;
2694 memcpy(&prd.val, rn->p.u.val, 8);
2695
2696 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2697 }
paulfee0f4c2004-09-13 05:12:46 +00002698}
2699
2700static void
paul718e3742002-12-13 20:15:29 +00002701bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002702 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002703{
2704 int ret;
2705 struct bgp_node *rn;
2706 struct bgp_adj_in *ain;
2707
2708 if (! table)
2709 table = peer->bgp->rib[afi][safi];
2710
2711 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2712 for (ain = rn->adj_in; ain; ain = ain->next)
2713 {
2714 if (ain->peer == peer)
2715 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002716 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002717 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002718
paul718e3742002-12-13 20:15:29 +00002719 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2720 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002721 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002722
paul718e3742002-12-13 20:15:29 +00002723 if (ret < 0)
2724 {
2725 bgp_unlock_node (rn);
2726 return;
2727 }
2728 continue;
2729 }
2730 }
2731}
2732
2733void
2734bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2735{
2736 struct bgp_node *rn;
2737 struct bgp_table *table;
2738
2739 if (peer->status != Established)
2740 return;
2741
2742 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002743 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002744 else
2745 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2746 rn = bgp_route_next (rn))
2747 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002748 {
2749 struct prefix_rd prd;
2750 prd.family = AF_UNSPEC;
2751 prd.prefixlen = 64;
2752 memcpy(&prd.val, rn->p.u.val, 8);
2753
2754 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2755 }
paul718e3742002-12-13 20:15:29 +00002756}
2757
Chris Caputo228da422009-07-18 05:44:03 +00002758
2759struct bgp_clear_node_queue
2760{
2761 struct bgp_node *rn;
2762 enum bgp_clear_route_type purpose;
2763};
2764
paul200df112005-06-01 11:17:05 +00002765static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002766bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002767{
Chris Caputo228da422009-07-18 05:44:03 +00002768 struct bgp_clear_node_queue *cnq = data;
2769 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002770 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002771 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002772 afi_t afi = bgp_node_table (rn)->afi;
2773 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002774
Paul Jakma64e580a2006-02-21 01:09:01 +00002775 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002776
Paul Jakma64e580a2006-02-21 01:09:01 +00002777 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002778 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002779 {
2780 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002781 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2782 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002783 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002784 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2785 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002786 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002787 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002788 break;
2789 }
paul200df112005-06-01 11:17:05 +00002790 return WQ_SUCCESS;
2791}
2792
2793static void
paul0fb58d52005-11-14 14:31:49 +00002794bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002795{
Chris Caputo228da422009-07-18 05:44:03 +00002796 struct bgp_clear_node_queue *cnq = data;
2797 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002798 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002799
2800 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002801 bgp_table_unlock (table);
2802 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002803}
2804
2805static void
paul94f2b392005-06-28 12:44:16 +00002806bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002807{
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 struct peer *peer = wq->spec.data;
2809
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002810 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002811 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002812
2813 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002814}
2815
2816static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002817bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002818{
Paul Jakmaa2943652009-07-21 14:02:04 +01002819 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002820
Paul Jakmaa2943652009-07-21 14:02:04 +01002821 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002822#undef CLEAR_QUEUE_NAME_LEN
2823
2824 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002825 {
2826 zlog_err ("%s: Failed to allocate work queue", __func__);
2827 exit (1);
2828 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002829 peer->clear_node_queue->spec.hold = 10;
2830 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2831 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2832 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2833 peer->clear_node_queue->spec.max_retries = 0;
2834
2835 /* we only 'lock' this peer reference when the queue is actually active */
2836 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002837}
2838
paul718e3742002-12-13 20:15:29 +00002839static void
2840bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002841 struct bgp_table *table, struct peer *rsclient,
2842 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002843{
2844 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002845
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002846
paul718e3742002-12-13 20:15:29 +00002847 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002848 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002849
hasso6cf159b2005-03-21 10:28:14 +00002850 /* If still no table => afi/safi isn't configured at all or smth. */
2851 if (! table)
2852 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002853
2854 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2855 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002856 struct bgp_info *ri;
2857 struct bgp_adj_in *ain;
2858 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002859
2860 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2861 * queued for every clearing peer, regardless of whether it is
2862 * relevant to the peer at hand.
2863 *
2864 * Overview: There are 3 different indices which need to be
2865 * scrubbed, potentially, when a peer is removed:
2866 *
2867 * 1 peer's routes visible via the RIB (ie accepted routes)
2868 * 2 peer's routes visible by the (optional) peer's adj-in index
2869 * 3 other routes visible by the peer's adj-out index
2870 *
2871 * 3 there is no hurry in scrubbing, once the struct peer is
2872 * removed from bgp->peer, we could just GC such deleted peer's
2873 * adj-outs at our leisure.
2874 *
2875 * 1 and 2 must be 'scrubbed' in some way, at least made
2876 * invisible via RIB index before peer session is allowed to be
2877 * brought back up. So one needs to know when such a 'search' is
2878 * complete.
2879 *
2880 * Ideally:
2881 *
2882 * - there'd be a single global queue or a single RIB walker
2883 * - rather than tracking which route_nodes still need to be
2884 * examined on a peer basis, we'd track which peers still
2885 * aren't cleared
2886 *
2887 * Given that our per-peer prefix-counts now should be reliable,
2888 * this may actually be achievable. It doesn't seem to be a huge
2889 * problem at this time,
2890 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002891 for (ain = rn->adj_in; ain; ain = ain->next)
2892 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2893 {
2894 bgp_adj_in_remove (rn, ain);
2895 bgp_unlock_node (rn);
2896 break;
2897 }
2898 for (aout = rn->adj_out; aout; aout = aout->next)
2899 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2900 {
2901 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2902 bgp_unlock_node (rn);
2903 break;
2904 }
2905
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002906 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002907 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002908 {
Chris Caputo228da422009-07-18 05:44:03 +00002909 struct bgp_clear_node_queue *cnq;
2910
2911 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002912 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002913 bgp_lock_node (rn);
2914 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2915 sizeof (struct bgp_clear_node_queue));
2916 cnq->rn = rn;
2917 cnq->purpose = purpose;
2918 work_queue_add (peer->clear_node_queue, cnq);
2919 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002920 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002921 }
2922 return;
2923}
2924
2925void
Chris Caputo228da422009-07-18 05:44:03 +00002926bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2927 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002928{
2929 struct bgp_node *rn;
2930 struct bgp_table *table;
2931 struct peer *rsclient;
2932 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002933
Paul Jakma64e580a2006-02-21 01:09:01 +00002934 if (peer->clear_node_queue == NULL)
2935 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002936
Paul Jakmaca058a32006-09-14 02:58:49 +00002937 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2938 * Idle until it receives a Clearing_Completed event. This protects
2939 * against peers which flap faster than we can we clear, which could
2940 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002941 *
2942 * a) race with routes from the new session being installed before
2943 * clear_route_node visits the node (to delete the route of that
2944 * peer)
2945 * b) resource exhaustion, clear_route_node likely leads to an entry
2946 * on the process_main queue. Fast-flapping could cause that queue
2947 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002948 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002949 if (!peer->clear_node_queue->thread)
2950 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002951
Chris Caputo228da422009-07-18 05:44:03 +00002952 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002953 {
Chris Caputo228da422009-07-18 05:44:03 +00002954 case BGP_CLEAR_ROUTE_NORMAL:
2955 if (safi != SAFI_MPLS_VPN)
2956 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2957 else
2958 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2959 rn = bgp_route_next (rn))
2960 if ((table = rn->info) != NULL)
2961 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2962
2963 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2964 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2965 PEER_FLAG_RSERVER_CLIENT))
2966 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2967 break;
2968
2969 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2970 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2971 break;
2972
2973 default:
2974 assert (0);
2975 break;
paulfee0f4c2004-09-13 05:12:46 +00002976 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002977
Paul Jakmaca058a32006-09-14 02:58:49 +00002978 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002979 * completion function won't be run by workqueue code - call it here.
2980 * XXX: Actually, this assumption doesn't hold, see
2981 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002982 *
2983 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002984 * really needed if peer state is Established - peers in
2985 * pre-Established states shouldn't have any route-update state
2986 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002987 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002988 * We still can get here in pre-Established though, through
2989 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2990 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002991 *
2992 * At some future point, this check could be move to the top of the
2993 * function, and do a quick early-return when state is
2994 * pre-Established, avoiding above list and table scans. Once we're
2995 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002996 */
2997 if (!peer->clear_node_queue->thread)
2998 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002999}
3000
3001void
3002bgp_clear_route_all (struct peer *peer)
3003{
3004 afi_t afi;
3005 safi_t safi;
3006
3007 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3008 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003009 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003010}
3011
3012void
3013bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3014{
3015 struct bgp_table *table;
3016 struct bgp_node *rn;
3017 struct bgp_adj_in *ain;
3018
3019 table = peer->bgp->rib[afi][safi];
3020
3021 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3022 for (ain = rn->adj_in; ain ; ain = ain->next)
3023 if (ain->peer == peer)
3024 {
3025 bgp_adj_in_remove (rn, ain);
3026 bgp_unlock_node (rn);
3027 break;
3028 }
3029}
hasso93406d82005-02-02 14:40:33 +00003030
3031void
3032bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3033{
3034 struct bgp_node *rn;
3035 struct bgp_info *ri;
3036 struct bgp_table *table;
3037
3038 table = peer->bgp->rib[afi][safi];
3039
3040 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3041 {
3042 for (ri = rn->info; ri; ri = ri->next)
3043 if (ri->peer == peer)
3044 {
3045 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3046 bgp_rib_remove (rn, ri, peer, afi, safi);
3047 break;
3048 }
3049 }
3050}
paul718e3742002-12-13 20:15:29 +00003051
3052/* Delete all kernel routes. */
3053void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003054bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003055{
3056 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003057 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003058 struct bgp_node *rn;
3059 struct bgp_table *table;
3060 struct bgp_info *ri;
3061
paul1eb8ef22005-04-07 07:30:20 +00003062 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003063 {
3064 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3065
3066 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3067 for (ri = rn->info; ri; ri = ri->next)
3068 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3069 && ri->type == ZEBRA_ROUTE_BGP
3070 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003071 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003072
3073 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3074
3075 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3076 for (ri = rn->info; ri; ri = ri->next)
3077 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3078 && ri->type == ZEBRA_ROUTE_BGP
3079 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003080 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003081 }
3082}
3083
3084void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003085bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003086{
3087 vty_reset ();
3088 bgp_zclient_reset ();
3089 access_list_reset ();
3090 prefix_list_reset ();
3091}
3092
3093/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3094 value. */
3095int
3096bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3097{
3098 u_char *pnt;
3099 u_char *lim;
3100 struct prefix p;
3101 int psize;
3102 int ret;
3103
3104 /* Check peer status. */
3105 if (peer->status != Established)
3106 return 0;
3107
3108 pnt = packet->nlri;
3109 lim = pnt + packet->length;
3110
3111 for (; pnt < lim; pnt += psize)
3112 {
3113 /* Clear prefix structure. */
3114 memset (&p, 0, sizeof (struct prefix));
3115
3116 /* Fetch prefix length. */
3117 p.prefixlen = *pnt++;
3118 p.family = afi2family (packet->afi);
3119
3120 /* Already checked in nlri_sanity_check(). We do double check
3121 here. */
3122 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3123 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3124 return -1;
3125
3126 /* Packet size overflow check. */
3127 psize = PSIZE (p.prefixlen);
3128
3129 /* When packet overflow occur return immediately. */
3130 if (pnt + psize > lim)
3131 return -1;
3132
3133 /* Fetch prefix from NLRI packet. */
3134 memcpy (&p.u.prefix, pnt, psize);
3135
3136 /* Check address. */
3137 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3138 {
3139 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3140 {
paulf5ba3872004-07-09 12:11:31 +00003141 /*
3142 * From draft-ietf-idr-bgp4-22, Section 6.3:
3143 * If a BGP router receives an UPDATE message with a
3144 * semantically incorrect NLRI field, in which a prefix is
3145 * semantically incorrect (eg. an unexpected multicast IP
3146 * address), it should ignore the prefix.
3147 */
paul718e3742002-12-13 20:15:29 +00003148 zlog (peer->log, LOG_ERR,
3149 "IPv4 unicast NLRI is multicast address %s",
3150 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003151
paul718e3742002-12-13 20:15:29 +00003152 return -1;
3153 }
3154 }
3155
3156#ifdef HAVE_IPV6
3157 /* Check address. */
3158 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3159 {
3160 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3161 {
3162 char buf[BUFSIZ];
3163
3164 zlog (peer->log, LOG_WARNING,
3165 "IPv6 link-local NLRI received %s ignore this NLRI",
3166 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3167
3168 continue;
3169 }
3170 }
3171#endif /* HAVE_IPV6 */
3172
3173 /* Normal process. */
3174 if (attr)
3175 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3176 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3177 else
3178 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3179 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3180
3181 /* Address family configuration mismatch or maximum-prefix count
3182 overflow. */
3183 if (ret < 0)
3184 return -1;
3185 }
3186
3187 /* Packet length consistency check. */
3188 if (pnt != lim)
3189 return -1;
3190
3191 return 0;
3192}
3193
3194/* NLRI encode syntax check routine. */
3195int
3196bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3197 bgp_size_t length)
3198{
3199 u_char *end;
3200 u_char prefixlen;
3201 int psize;
3202
3203 end = pnt + length;
3204
3205 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3206 syntactic validity. If the field is syntactically incorrect,
3207 then the Error Subcode is set to Invalid Network Field. */
3208
3209 while (pnt < end)
3210 {
3211 prefixlen = *pnt++;
3212
3213 /* Prefix length check. */
3214 if ((afi == AFI_IP && prefixlen > 32)
3215 || (afi == AFI_IP6 && prefixlen > 128))
3216 {
3217 plog_err (peer->log,
3218 "%s [Error] Update packet error (wrong prefix length %d)",
3219 peer->host, prefixlen);
3220 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3221 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3222 return -1;
3223 }
3224
3225 /* Packet size overflow check. */
3226 psize = PSIZE (prefixlen);
3227
3228 if (pnt + psize > end)
3229 {
3230 plog_err (peer->log,
3231 "%s [Error] Update packet error"
3232 " (prefix data overflow prefix size is %d)",
3233 peer->host, psize);
3234 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3235 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3236 return -1;
3237 }
3238
3239 pnt += psize;
3240 }
3241
3242 /* Packet length consistency check. */
3243 if (pnt != end)
3244 {
3245 plog_err (peer->log,
3246 "%s [Error] Update packet error"
3247 " (prefix length mismatch with total length)",
3248 peer->host);
3249 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3250 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3251 return -1;
3252 }
3253 return 0;
3254}
3255
paul94f2b392005-06-28 12:44:16 +00003256static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003257bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003258{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003259 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003260}
3261
paul94f2b392005-06-28 12:44:16 +00003262static void
paul718e3742002-12-13 20:15:29 +00003263bgp_static_free (struct bgp_static *bgp_static)
3264{
3265 if (bgp_static->rmap.name)
3266 free (bgp_static->rmap.name);
3267 XFREE (MTYPE_BGP_STATIC, bgp_static);
3268}
3269
paul94f2b392005-06-28 12:44:16 +00003270static void
paulfee0f4c2004-09-13 05:12:46 +00003271bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3272 struct prefix *p, afi_t afi, safi_t safi)
3273{
3274 struct bgp_node *rn;
3275 struct bgp_info *ri;
3276
3277 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3278
3279 /* Check selected route and self inserted route. */
3280 for (ri = rn->info; ri; ri = ri->next)
3281 if (ri->peer == bgp->peer_self
3282 && ri->type == ZEBRA_ROUTE_BGP
3283 && ri->sub_type == BGP_ROUTE_STATIC)
3284 break;
3285
3286 /* Withdraw static BGP route from routing table. */
3287 if (ri)
3288 {
paulfee0f4c2004-09-13 05:12:46 +00003289 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003290 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003291 }
3292
3293 /* Unlock bgp_node_lookup. */
3294 bgp_unlock_node (rn);
3295}
3296
paul94f2b392005-06-28 12:44:16 +00003297static void
paulfee0f4c2004-09-13 05:12:46 +00003298bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003299 struct bgp_static *bgp_static,
3300 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003301{
3302 struct bgp_node *rn;
3303 struct bgp_info *ri;
3304 struct bgp_info *new;
3305 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003306 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003307 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003308 struct attr new_attr;
3309 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003310 struct bgp *bgp;
3311 int ret;
3312 char buf[SU_ADDRSTRLEN];
3313
3314 bgp = rsclient->bgp;
3315
Paul Jakma06e110f2006-05-12 23:29:22 +00003316 assert (bgp_static);
3317 if (!bgp_static)
3318 return;
3319
paulfee0f4c2004-09-13 05:12:46 +00003320 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3321
3322 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003323
3324 attr.nexthop = bgp_static->igpnexthop;
3325 attr.med = bgp_static->igpmetric;
3326 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003327
Paul Jakma41367172007-08-06 15:24:51 +00003328 if (bgp_static->atomic)
3329 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3330
paulfee0f4c2004-09-13 05:12:46 +00003331 /* Apply network route-map for export to this rsclient. */
3332 if (bgp_static->rmap.name)
3333 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003334 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003335 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003336 info.attr = &attr_tmp;
3337
paulfee0f4c2004-09-13 05:12:46 +00003338 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3339 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3340
3341 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3342
3343 rsclient->rmap_type = 0;
3344
3345 if (ret == RMAP_DENYMATCH)
3346 {
3347 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003348 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003349
3350 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003351 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003352 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003353 bgp_attr_extra_free (&attr);
3354
paulfee0f4c2004-09-13 05:12:46 +00003355 return;
3356 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003357 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003358 }
3359 else
3360 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003361
3362 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003363 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003364
paulfee0f4c2004-09-13 05:12:46 +00003365 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3366
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3368 == RMAP_DENY)
3369 {
paulfee0f4c2004-09-13 05:12:46 +00003370 /* This BGP update is filtered. Log the reason then update BGP entry. */
3371 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003372 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003373 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3374 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3375 p->prefixlen, rsclient->host);
3376
3377 bgp->peer_self->rmap_type = 0;
3378
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003379 bgp_attr_unintern (&attr_new);
3380 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003382
3383 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3384
3385 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003386 }
paulfee0f4c2004-09-13 05:12:46 +00003387
3388 bgp->peer_self->rmap_type = 0;
3389
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003390 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003391 attr_new = bgp_attr_intern (&new_attr);
3392
3393 for (ri = rn->info; ri; ri = ri->next)
3394 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3395 && ri->sub_type == BGP_ROUTE_STATIC)
3396 break;
3397
3398 if (ri)
3399 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003400 if (attrhash_cmp (ri->attr, attr_new) &&
3401 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003402 {
3403 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003404 bgp_attr_unintern (&attr_new);
3405 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003406 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003407 return;
3408 }
3409 else
3410 {
3411 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003412 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003415 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3416 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003417 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003418 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003419 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003420
3421 /* Process change. */
3422 bgp_process (bgp, rn, afi, safi);
3423 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003424 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003425 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003426 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003427 }
paulfee0f4c2004-09-13 05:12:46 +00003428 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003429
paulfee0f4c2004-09-13 05:12:46 +00003430 /* Make new BGP info. */
3431 new = bgp_info_new ();
3432 new->type = ZEBRA_ROUTE_BGP;
3433 new->sub_type = BGP_ROUTE_STATIC;
3434 new->peer = bgp->peer_self;
3435 SET_FLAG (new->flags, BGP_INFO_VALID);
3436 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003437 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003438
3439 /* Register new BGP information. */
3440 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003441
3442 /* route_node_get lock */
3443 bgp_unlock_node (rn);
3444
paulfee0f4c2004-09-13 05:12:46 +00003445 /* Process change. */
3446 bgp_process (bgp, rn, afi, safi);
3447
3448 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003449 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003450 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003451}
3452
paul94f2b392005-06-28 12:44:16 +00003453static void
paulfee0f4c2004-09-13 05:12:46 +00003454bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003455 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3456{
3457 struct bgp_node *rn;
3458 struct bgp_info *ri;
3459 struct bgp_info *new;
3460 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003461 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003462 struct attr *attr_new;
3463 int ret;
3464
Paul Jakmadd8103a2006-05-12 23:27:30 +00003465 assert (bgp_static);
3466 if (!bgp_static)
3467 return;
3468
paulfee0f4c2004-09-13 05:12:46 +00003469 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003470
3471 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003472
3473 attr.nexthop = bgp_static->igpnexthop;
3474 attr.med = bgp_static->igpmetric;
3475 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003476
Paul Jakma41367172007-08-06 15:24:51 +00003477 if (bgp_static->atomic)
3478 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3479
paul718e3742002-12-13 20:15:29 +00003480 /* Apply route-map. */
3481 if (bgp_static->rmap.name)
3482 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003483 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003484 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003485 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003486
paulfee0f4c2004-09-13 05:12:46 +00003487 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3488
paul718e3742002-12-13 20:15:29 +00003489 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003490
paulfee0f4c2004-09-13 05:12:46 +00003491 bgp->peer_self->rmap_type = 0;
3492
paul718e3742002-12-13 20:15:29 +00003493 if (ret == RMAP_DENYMATCH)
3494 {
3495 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003496 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003497
3498 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003499 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003500 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003501 bgp_static_withdraw (bgp, p, afi, safi);
3502 return;
3503 }
paul286e1e72003-08-08 00:24:31 +00003504 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003505 }
paul286e1e72003-08-08 00:24:31 +00003506 else
3507 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003508
3509 for (ri = rn->info; ri; ri = ri->next)
3510 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3511 && ri->sub_type == BGP_ROUTE_STATIC)
3512 break;
3513
3514 if (ri)
3515 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003516 if (attrhash_cmp (ri->attr, attr_new) &&
3517 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003518 {
3519 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003520 bgp_attr_unintern (&attr_new);
3521 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003522 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003523 return;
3524 }
3525 else
3526 {
3527 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003528 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003529
3530 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003531 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3532 bgp_info_restore(rn, ri);
3533 else
3534 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003535 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003536 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003537 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003538
3539 /* Process change. */
3540 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3541 bgp_process (bgp, rn, afi, safi);
3542 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003543 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003544 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003545 return;
3546 }
3547 }
3548
3549 /* Make new BGP info. */
3550 new = bgp_info_new ();
3551 new->type = ZEBRA_ROUTE_BGP;
3552 new->sub_type = BGP_ROUTE_STATIC;
3553 new->peer = bgp->peer_self;
3554 SET_FLAG (new->flags, BGP_INFO_VALID);
3555 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003556 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003557
3558 /* Aggregate address increment. */
3559 bgp_aggregate_increment (bgp, p, new, afi, safi);
3560
3561 /* Register new BGP information. */
3562 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003563
3564 /* route_node_get lock */
3565 bgp_unlock_node (rn);
3566
paul718e3742002-12-13 20:15:29 +00003567 /* Process change. */
3568 bgp_process (bgp, rn, afi, safi);
3569
3570 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003571 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003572 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003573}
3574
3575void
paulfee0f4c2004-09-13 05:12:46 +00003576bgp_static_update (struct bgp *bgp, struct prefix *p,
3577 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3578{
3579 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003580 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003581
3582 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3583
paul1eb8ef22005-04-07 07:30:20 +00003584 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003585 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003586 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3587 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003588 }
3589}
3590
paul94f2b392005-06-28 12:44:16 +00003591static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003592bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3593 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003594{
3595 struct bgp_node *rn;
3596 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003597
paulfee0f4c2004-09-13 05:12:46 +00003598 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003599
3600 /* Make new BGP info. */
3601 new = bgp_info_new ();
3602 new->type = ZEBRA_ROUTE_BGP;
3603 new->sub_type = BGP_ROUTE_STATIC;
3604 new->peer = bgp->peer_self;
3605 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3606 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003607 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003608 new->extra = bgp_info_extra_new();
3609 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003610
3611 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003612 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003613
3614 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003615 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003616
paul200df112005-06-01 11:17:05 +00003617 /* route_node_get lock */
3618 bgp_unlock_node (rn);
3619
paul718e3742002-12-13 20:15:29 +00003620 /* Process change. */
3621 bgp_process (bgp, rn, afi, safi);
3622}
3623
3624void
3625bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3626 safi_t safi)
3627{
3628 struct bgp_node *rn;
3629 struct bgp_info *ri;
3630
paulfee0f4c2004-09-13 05:12:46 +00003631 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003632
3633 /* Check selected route and self inserted route. */
3634 for (ri = rn->info; ri; ri = ri->next)
3635 if (ri->peer == bgp->peer_self
3636 && ri->type == ZEBRA_ROUTE_BGP
3637 && ri->sub_type == BGP_ROUTE_STATIC)
3638 break;
3639
3640 /* Withdraw static BGP route from routing table. */
3641 if (ri)
3642 {
3643 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003644 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003645 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003646 }
3647
3648 /* Unlock bgp_node_lookup. */
3649 bgp_unlock_node (rn);
3650}
3651
3652void
paulfee0f4c2004-09-13 05:12:46 +00003653bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3654{
3655 struct bgp_static *bgp_static;
3656 struct bgp *bgp;
3657 struct bgp_node *rn;
3658 struct prefix *p;
3659
3660 bgp = rsclient->bgp;
3661
3662 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3663 if ((bgp_static = rn->info) != NULL)
3664 {
3665 p = &rn->p;
3666
3667 bgp_static_update_rsclient (rsclient, p, bgp_static,
3668 afi, safi);
3669 }
3670}
3671
paul94f2b392005-06-28 12:44:16 +00003672static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003673bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3674 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003675{
3676 struct bgp_node *rn;
3677 struct bgp_info *ri;
3678
paulfee0f4c2004-09-13 05:12:46 +00003679 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003680
3681 /* Check selected route and self inserted route. */
3682 for (ri = rn->info; ri; ri = ri->next)
3683 if (ri->peer == bgp->peer_self
3684 && ri->type == ZEBRA_ROUTE_BGP
3685 && ri->sub_type == BGP_ROUTE_STATIC)
3686 break;
3687
3688 /* Withdraw static BGP route from routing table. */
3689 if (ri)
3690 {
3691 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003692 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003693 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003694 }
3695
3696 /* Unlock bgp_node_lookup. */
3697 bgp_unlock_node (rn);
3698}
3699
3700/* Configure static BGP network. When user don't run zebra, static
3701 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003702static int
paulfd79ac92004-10-13 05:06:08 +00003703bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003704 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003705{
3706 int ret;
3707 struct prefix p;
3708 struct bgp_static *bgp_static;
3709 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003710 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003711
3712 /* Convert IP prefix string to struct prefix. */
3713 ret = str2prefix (ip_str, &p);
3714 if (! ret)
3715 {
3716 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3717 return CMD_WARNING;
3718 }
3719#ifdef HAVE_IPV6
3720 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3721 {
3722 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3723 VTY_NEWLINE);
3724 return CMD_WARNING;
3725 }
3726#endif /* HAVE_IPV6 */
3727
3728 apply_mask (&p);
3729
3730 /* Set BGP static route configuration. */
3731 rn = bgp_node_get (bgp->route[afi][safi], &p);
3732
3733 if (rn->info)
3734 {
3735 /* Configuration change. */
3736 bgp_static = rn->info;
3737
3738 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003739 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3740 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003741
paul718e3742002-12-13 20:15:29 +00003742 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003743
paul718e3742002-12-13 20:15:29 +00003744 if (rmap)
3745 {
3746 if (bgp_static->rmap.name)
3747 free (bgp_static->rmap.name);
3748 bgp_static->rmap.name = strdup (rmap);
3749 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3750 }
3751 else
3752 {
3753 if (bgp_static->rmap.name)
3754 free (bgp_static->rmap.name);
3755 bgp_static->rmap.name = NULL;
3756 bgp_static->rmap.map = NULL;
3757 bgp_static->valid = 0;
3758 }
3759 bgp_unlock_node (rn);
3760 }
3761 else
3762 {
3763 /* New configuration. */
3764 bgp_static = bgp_static_new ();
3765 bgp_static->backdoor = backdoor;
3766 bgp_static->valid = 0;
3767 bgp_static->igpmetric = 0;
3768 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003769
paul718e3742002-12-13 20:15:29 +00003770 if (rmap)
3771 {
3772 if (bgp_static->rmap.name)
3773 free (bgp_static->rmap.name);
3774 bgp_static->rmap.name = strdup (rmap);
3775 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3776 }
3777 rn->info = bgp_static;
3778 }
3779
3780 /* If BGP scan is not enabled, we should install this route here. */
3781 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3782 {
3783 bgp_static->valid = 1;
3784
3785 if (need_update)
3786 bgp_static_withdraw (bgp, &p, afi, safi);
3787
3788 if (! bgp_static->backdoor)
3789 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3790 }
3791
3792 return CMD_SUCCESS;
3793}
3794
3795/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003796static int
paulfd79ac92004-10-13 05:06:08 +00003797bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003798 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003799{
3800 int ret;
3801 struct prefix p;
3802 struct bgp_static *bgp_static;
3803 struct bgp_node *rn;
3804
3805 /* Convert IP prefix string to struct prefix. */
3806 ret = str2prefix (ip_str, &p);
3807 if (! ret)
3808 {
3809 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3810 return CMD_WARNING;
3811 }
3812#ifdef HAVE_IPV6
3813 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3814 {
3815 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3816 VTY_NEWLINE);
3817 return CMD_WARNING;
3818 }
3819#endif /* HAVE_IPV6 */
3820
3821 apply_mask (&p);
3822
3823 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3824 if (! rn)
3825 {
3826 vty_out (vty, "%% Can't find specified static route configuration.%s",
3827 VTY_NEWLINE);
3828 return CMD_WARNING;
3829 }
3830
3831 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003832
paul718e3742002-12-13 20:15:29 +00003833 /* Update BGP RIB. */
3834 if (! bgp_static->backdoor)
3835 bgp_static_withdraw (bgp, &p, afi, safi);
3836
3837 /* Clear configuration. */
3838 bgp_static_free (bgp_static);
3839 rn->info = NULL;
3840 bgp_unlock_node (rn);
3841 bgp_unlock_node (rn);
3842
3843 return CMD_SUCCESS;
3844}
3845
3846/* Called from bgp_delete(). Delete all static routes from the BGP
3847 instance. */
3848void
3849bgp_static_delete (struct bgp *bgp)
3850{
3851 afi_t afi;
3852 safi_t safi;
3853 struct bgp_node *rn;
3854 struct bgp_node *rm;
3855 struct bgp_table *table;
3856 struct bgp_static *bgp_static;
3857
3858 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3859 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3860 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3861 if (rn->info != NULL)
3862 {
3863 if (safi == SAFI_MPLS_VPN)
3864 {
3865 table = rn->info;
3866
3867 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3868 {
3869 bgp_static = rn->info;
3870 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3871 AFI_IP, SAFI_MPLS_VPN,
3872 (struct prefix_rd *)&rn->p,
3873 bgp_static->tag);
3874 bgp_static_free (bgp_static);
3875 rn->info = NULL;
3876 bgp_unlock_node (rn);
3877 }
3878 }
3879 else
3880 {
3881 bgp_static = rn->info;
3882 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3883 bgp_static_free (bgp_static);
3884 rn->info = NULL;
3885 bgp_unlock_node (rn);
3886 }
3887 }
3888}
3889
3890int
paulfd79ac92004-10-13 05:06:08 +00003891bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3892 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003893{
3894 int ret;
3895 struct prefix p;
3896 struct prefix_rd prd;
3897 struct bgp *bgp;
3898 struct bgp_node *prn;
3899 struct bgp_node *rn;
3900 struct bgp_table *table;
3901 struct bgp_static *bgp_static;
3902 u_char tag[3];
3903
3904 bgp = vty->index;
3905
3906 ret = str2prefix (ip_str, &p);
3907 if (! ret)
3908 {
3909 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3910 return CMD_WARNING;
3911 }
3912 apply_mask (&p);
3913
3914 ret = str2prefix_rd (rd_str, &prd);
3915 if (! ret)
3916 {
3917 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3918 return CMD_WARNING;
3919 }
3920
3921 ret = str2tag (tag_str, tag);
3922 if (! ret)
3923 {
3924 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
3927
3928 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3929 (struct prefix *)&prd);
3930 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003931 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003932 else
3933 bgp_unlock_node (prn);
3934 table = prn->info;
3935
3936 rn = bgp_node_get (table, &p);
3937
3938 if (rn->info)
3939 {
3940 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3941 bgp_unlock_node (rn);
3942 }
3943 else
3944 {
3945 /* New configuration. */
3946 bgp_static = bgp_static_new ();
3947 bgp_static->valid = 1;
3948 memcpy (bgp_static->tag, tag, 3);
3949 rn->info = bgp_static;
3950
3951 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3952 }
3953
3954 return CMD_SUCCESS;
3955}
3956
3957/* Configure static BGP network. */
3958int
paulfd79ac92004-10-13 05:06:08 +00003959bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3960 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003961{
3962 int ret;
3963 struct bgp *bgp;
3964 struct prefix p;
3965 struct prefix_rd prd;
3966 struct bgp_node *prn;
3967 struct bgp_node *rn;
3968 struct bgp_table *table;
3969 struct bgp_static *bgp_static;
3970 u_char tag[3];
3971
3972 bgp = vty->index;
3973
3974 /* Convert IP prefix string to struct prefix. */
3975 ret = str2prefix (ip_str, &p);
3976 if (! ret)
3977 {
3978 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3979 return CMD_WARNING;
3980 }
3981 apply_mask (&p);
3982
3983 ret = str2prefix_rd (rd_str, &prd);
3984 if (! ret)
3985 {
3986 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3987 return CMD_WARNING;
3988 }
3989
3990 ret = str2tag (tag_str, tag);
3991 if (! ret)
3992 {
3993 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3994 return CMD_WARNING;
3995 }
3996
3997 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3998 (struct prefix *)&prd);
3999 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004000 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004001 else
4002 bgp_unlock_node (prn);
4003 table = prn->info;
4004
4005 rn = bgp_node_lookup (table, &p);
4006
4007 if (rn)
4008 {
4009 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4010
4011 bgp_static = rn->info;
4012 bgp_static_free (bgp_static);
4013 rn->info = NULL;
4014 bgp_unlock_node (rn);
4015 bgp_unlock_node (rn);
4016 }
4017 else
4018 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4019
4020 return CMD_SUCCESS;
4021}
4022
4023DEFUN (bgp_network,
4024 bgp_network_cmd,
4025 "network A.B.C.D/M",
4026 "Specify a network to announce via BGP\n"
4027 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4028{
4029 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004030 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004031}
4032
4033DEFUN (bgp_network_route_map,
4034 bgp_network_route_map_cmd,
4035 "network A.B.C.D/M route-map WORD",
4036 "Specify a network to announce via BGP\n"
4037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4038 "Route-map to modify the attributes\n"
4039 "Name of the route map\n")
4040{
4041 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004042 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004043}
4044
4045DEFUN (bgp_network_backdoor,
4046 bgp_network_backdoor_cmd,
4047 "network A.B.C.D/M backdoor",
4048 "Specify a network to announce via BGP\n"
4049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4050 "Specify a BGP backdoor route\n")
4051{
Paul Jakma41367172007-08-06 15:24:51 +00004052 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004053 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004054}
4055
4056DEFUN (bgp_network_mask,
4057 bgp_network_mask_cmd,
4058 "network A.B.C.D mask A.B.C.D",
4059 "Specify a network to announce via BGP\n"
4060 "Network number\n"
4061 "Network mask\n"
4062 "Network mask\n")
4063{
4064 int ret;
4065 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004066
paul718e3742002-12-13 20:15:29 +00004067 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4068 if (! ret)
4069 {
4070 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4071 return CMD_WARNING;
4072 }
4073
4074 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004075 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004076}
4077
4078DEFUN (bgp_network_mask_route_map,
4079 bgp_network_mask_route_map_cmd,
4080 "network A.B.C.D mask A.B.C.D route-map WORD",
4081 "Specify a network to announce via BGP\n"
4082 "Network number\n"
4083 "Network mask\n"
4084 "Network mask\n"
4085 "Route-map to modify the attributes\n"
4086 "Name of the route map\n")
4087{
4088 int ret;
4089 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004090
paul718e3742002-12-13 20:15:29 +00004091 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4092 if (! ret)
4093 {
4094 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4095 return CMD_WARNING;
4096 }
4097
4098 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004099 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004100}
4101
4102DEFUN (bgp_network_mask_backdoor,
4103 bgp_network_mask_backdoor_cmd,
4104 "network A.B.C.D mask A.B.C.D backdoor",
4105 "Specify a network to announce via BGP\n"
4106 "Network number\n"
4107 "Network mask\n"
4108 "Network mask\n"
4109 "Specify a BGP backdoor route\n")
4110{
4111 int ret;
4112 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004113
paul718e3742002-12-13 20:15:29 +00004114 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4115 if (! ret)
4116 {
4117 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4118 return CMD_WARNING;
4119 }
4120
Paul Jakma41367172007-08-06 15:24:51 +00004121 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004122 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004123}
4124
4125DEFUN (bgp_network_mask_natural,
4126 bgp_network_mask_natural_cmd,
4127 "network A.B.C.D",
4128 "Specify a network to announce via BGP\n"
4129 "Network number\n")
4130{
4131 int ret;
4132 char prefix_str[BUFSIZ];
4133
4134 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4135 if (! ret)
4136 {
4137 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4138 return CMD_WARNING;
4139 }
4140
4141 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004142 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004143}
4144
4145DEFUN (bgp_network_mask_natural_route_map,
4146 bgp_network_mask_natural_route_map_cmd,
4147 "network A.B.C.D route-map WORD",
4148 "Specify a network to announce via BGP\n"
4149 "Network number\n"
4150 "Route-map to modify the attributes\n"
4151 "Name of the route map\n")
4152{
4153 int ret;
4154 char prefix_str[BUFSIZ];
4155
4156 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4157 if (! ret)
4158 {
4159 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4160 return CMD_WARNING;
4161 }
4162
4163 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004164 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004165}
4166
4167DEFUN (bgp_network_mask_natural_backdoor,
4168 bgp_network_mask_natural_backdoor_cmd,
4169 "network A.B.C.D backdoor",
4170 "Specify a network to announce via BGP\n"
4171 "Network number\n"
4172 "Specify a BGP backdoor route\n")
4173{
4174 int ret;
4175 char prefix_str[BUFSIZ];
4176
4177 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4178 if (! ret)
4179 {
4180 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4181 return CMD_WARNING;
4182 }
4183
Paul Jakma41367172007-08-06 15:24:51 +00004184 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004185 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004186}
4187
4188DEFUN (no_bgp_network,
4189 no_bgp_network_cmd,
4190 "no network A.B.C.D/M",
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{
4195 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4196 bgp_node_safi (vty));
4197}
4198
4199ALIAS (no_bgp_network,
4200 no_bgp_network_route_map_cmd,
4201 "no network A.B.C.D/M route-map WORD",
4202 NO_STR
4203 "Specify a network to announce via BGP\n"
4204 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4205 "Route-map to modify the attributes\n"
4206 "Name of the route map\n")
4207
4208ALIAS (no_bgp_network,
4209 no_bgp_network_backdoor_cmd,
4210 "no network A.B.C.D/M backdoor",
4211 NO_STR
4212 "Specify a network to announce via BGP\n"
4213 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4214 "Specify a BGP backdoor route\n")
4215
4216DEFUN (no_bgp_network_mask,
4217 no_bgp_network_mask_cmd,
4218 "no network A.B.C.D mask A.B.C.D",
4219 NO_STR
4220 "Specify a network to announce via BGP\n"
4221 "Network number\n"
4222 "Network mask\n"
4223 "Network mask\n")
4224{
4225 int ret;
4226 char prefix_str[BUFSIZ];
4227
4228 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4229 if (! ret)
4230 {
4231 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4232 return CMD_WARNING;
4233 }
4234
4235 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4236 bgp_node_safi (vty));
4237}
4238
4239ALIAS (no_bgp_network_mask,
4240 no_bgp_network_mask_route_map_cmd,
4241 "no network A.B.C.D mask A.B.C.D route-map WORD",
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 "Route-map to modify the attributes\n"
4248 "Name of the route map\n")
4249
4250ALIAS (no_bgp_network_mask,
4251 no_bgp_network_mask_backdoor_cmd,
4252 "no network A.B.C.D mask A.B.C.D backdoor",
4253 NO_STR
4254 "Specify a network to announce via BGP\n"
4255 "Network number\n"
4256 "Network mask\n"
4257 "Network mask\n"
4258 "Specify a BGP backdoor route\n")
4259
4260DEFUN (no_bgp_network_mask_natural,
4261 no_bgp_network_mask_natural_cmd,
4262 "no network A.B.C.D",
4263 NO_STR
4264 "Specify a network to announce via BGP\n"
4265 "Network number\n")
4266{
4267 int ret;
4268 char prefix_str[BUFSIZ];
4269
4270 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4271 if (! ret)
4272 {
4273 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4274 return CMD_WARNING;
4275 }
4276
4277 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4278 bgp_node_safi (vty));
4279}
4280
4281ALIAS (no_bgp_network_mask_natural,
4282 no_bgp_network_mask_natural_route_map_cmd,
4283 "no network A.B.C.D route-map WORD",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "Network number\n"
4287 "Route-map to modify the attributes\n"
4288 "Name of the route map\n")
4289
4290ALIAS (no_bgp_network_mask_natural,
4291 no_bgp_network_mask_natural_backdoor_cmd,
4292 "no network A.B.C.D backdoor",
4293 NO_STR
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Specify a BGP backdoor route\n")
4297
4298#ifdef HAVE_IPV6
4299DEFUN (ipv6_bgp_network,
4300 ipv6_bgp_network_cmd,
4301 "network X:X::X:X/M",
4302 "Specify a network to announce via BGP\n"
4303 "IPv6 prefix <network>/<length>\n")
4304{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304305 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004306 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004307}
4308
4309DEFUN (ipv6_bgp_network_route_map,
4310 ipv6_bgp_network_route_map_cmd,
4311 "network X:X::X:X/M route-map WORD",
4312 "Specify a network to announce via BGP\n"
4313 "IPv6 prefix <network>/<length>\n"
4314 "Route-map to modify the attributes\n"
4315 "Name of the route map\n")
4316{
4317 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004318 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004319}
4320
4321DEFUN (no_ipv6_bgp_network,
4322 no_ipv6_bgp_network_cmd,
4323 "no network X:X::X:X/M",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "IPv6 prefix <network>/<length>\n")
4327{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304328 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004329}
4330
4331ALIAS (no_ipv6_bgp_network,
4332 no_ipv6_bgp_network_route_map_cmd,
4333 "no network X:X::X:X/M route-map WORD",
4334 NO_STR
4335 "Specify a network to announce via BGP\n"
4336 "IPv6 prefix <network>/<length>\n"
4337 "Route-map to modify the attributes\n"
4338 "Name of the route map\n")
4339
4340ALIAS (ipv6_bgp_network,
4341 old_ipv6_bgp_network_cmd,
4342 "ipv6 bgp network X:X::X:X/M",
4343 IPV6_STR
4344 BGP_STR
4345 "Specify a network to announce via BGP\n"
4346 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4347
4348ALIAS (no_ipv6_bgp_network,
4349 old_no_ipv6_bgp_network_cmd,
4350 "no ipv6 bgp network X:X::X:X/M",
4351 NO_STR
4352 IPV6_STR
4353 BGP_STR
4354 "Specify a network to announce via BGP\n"
4355 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4356#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004357
4358/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4359ALIAS_DEPRECATED (bgp_network,
4360 bgp_network_ttl_cmd,
4361 "network A.B.C.D/M pathlimit <0-255>",
4362 "Specify a network to announce via BGP\n"
4363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4364 "AS-Path hopcount limit attribute\n"
4365 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4366ALIAS_DEPRECATED (bgp_network_backdoor,
4367 bgp_network_backdoor_ttl_cmd,
4368 "network A.B.C.D/M backdoor pathlimit <0-255>",
4369 "Specify a network to announce via BGP\n"
4370 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4371 "Specify a BGP backdoor route\n"
4372 "AS-Path hopcount limit attribute\n"
4373 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4374ALIAS_DEPRECATED (bgp_network_mask,
4375 bgp_network_mask_ttl_cmd,
4376 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4377 "Specify a network to announce via BGP\n"
4378 "Network number\n"
4379 "Network mask\n"
4380 "Network mask\n"
4381 "AS-Path hopcount limit attribute\n"
4382 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4383ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4384 bgp_network_mask_backdoor_ttl_cmd,
4385 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "Network mask\n"
4389 "Network mask\n"
4390 "Specify a BGP backdoor route\n"
4391 "AS-Path hopcount limit attribute\n"
4392 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4393ALIAS_DEPRECATED (bgp_network_mask_natural,
4394 bgp_network_mask_natural_ttl_cmd,
4395 "network A.B.C.D pathlimit <0-255>",
4396 "Specify a network to announce via BGP\n"
4397 "Network number\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4401 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004402 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "Specify a BGP backdoor route\n"
4406 "AS-Path hopcount limit attribute\n"
4407 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4408ALIAS_DEPRECATED (no_bgp_network,
4409 no_bgp_network_ttl_cmd,
4410 "no network A.B.C.D/M pathlimit <0-255>",
4411 NO_STR
4412 "Specify a network to announce via BGP\n"
4413 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4416ALIAS_DEPRECATED (no_bgp_network,
4417 no_bgp_network_backdoor_ttl_cmd,
4418 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4422 "Specify a BGP backdoor route\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4425ALIAS_DEPRECATED (no_bgp_network,
4426 no_bgp_network_mask_ttl_cmd,
4427 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Network mask\n"
4432 "Network mask\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,
4436 no_bgp_network_mask_backdoor_ttl_cmd,
4437 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "Network number\n"
4441 "Network mask\n"
4442 "Network mask\n"
4443 "Specify a BGP backdoor route\n"
4444 "AS-Path hopcount limit attribute\n"
4445 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4446ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4447 no_bgp_network_mask_natural_ttl_cmd,
4448 "no network A.B.C.D pathlimit <0-255>",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "Network number\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4454ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4455 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4456 "no network A.B.C.D backdoor pathlimit <0-255>",
4457 NO_STR
4458 "Specify a network to announce via BGP\n"
4459 "Network number\n"
4460 "Specify a BGP backdoor route\n"
4461 "AS-Path hopcount limit attribute\n"
4462 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004463#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004464ALIAS_DEPRECATED (ipv6_bgp_network,
4465 ipv6_bgp_network_ttl_cmd,
4466 "network X:X::X:X/M pathlimit <0-255>",
4467 "Specify a network to announce via BGP\n"
4468 "IPv6 prefix <network>/<length>\n"
4469 "AS-Path hopcount limit attribute\n"
4470 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4471ALIAS_DEPRECATED (no_ipv6_bgp_network,
4472 no_ipv6_bgp_network_ttl_cmd,
4473 "no network X:X::X:X/M pathlimit <0-255>",
4474 NO_STR
4475 "Specify a network to announce via BGP\n"
4476 "IPv6 prefix <network>/<length>\n"
4477 "AS-Path hopcount limit attribute\n"
4478 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004479#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004480
4481/* Aggreagete address:
4482
4483 advertise-map Set condition to advertise attribute
4484 as-set Generate AS set path information
4485 attribute-map Set attributes of aggregate
4486 route-map Set parameters of aggregate
4487 summary-only Filter more specific routes from updates
4488 suppress-map Conditionally filter more specific routes from updates
4489 <cr>
4490 */
4491struct bgp_aggregate
4492{
4493 /* Summary-only flag. */
4494 u_char summary_only;
4495
4496 /* AS set generation. */
4497 u_char as_set;
4498
4499 /* Route-map for aggregated route. */
4500 struct route_map *map;
4501
4502 /* Suppress-count. */
4503 unsigned long count;
4504
4505 /* SAFI configuration. */
4506 safi_t safi;
4507};
4508
paul94f2b392005-06-28 12:44:16 +00004509static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004510bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004511{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004512 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004513}
4514
paul94f2b392005-06-28 12:44:16 +00004515static void
paul718e3742002-12-13 20:15:29 +00004516bgp_aggregate_free (struct bgp_aggregate *aggregate)
4517{
4518 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4519}
4520
paul94f2b392005-06-28 12:44:16 +00004521static void
paul718e3742002-12-13 20:15:29 +00004522bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4523 afi_t afi, safi_t safi, struct bgp_info *del,
4524 struct bgp_aggregate *aggregate)
4525{
4526 struct bgp_table *table;
4527 struct bgp_node *top;
4528 struct bgp_node *rn;
4529 u_char origin;
4530 struct aspath *aspath = NULL;
4531 struct aspath *asmerge = NULL;
4532 struct community *community = NULL;
4533 struct community *commerge = NULL;
4534 struct in_addr nexthop;
4535 u_int32_t med = 0;
4536 struct bgp_info *ri;
4537 struct bgp_info *new;
4538 int first = 1;
4539 unsigned long match = 0;
4540
4541 /* Record adding route's nexthop and med. */
4542 if (rinew)
4543 {
4544 nexthop = rinew->attr->nexthop;
4545 med = rinew->attr->med;
4546 }
4547
4548 /* ORIGIN attribute: If at least one route among routes that are
4549 aggregated has ORIGIN with the value INCOMPLETE, then the
4550 aggregated route must have the ORIGIN attribute with the value
4551 INCOMPLETE. Otherwise, if at least one route among routes that
4552 are aggregated has ORIGIN with the value EGP, then the aggregated
4553 route must have the origin attribute with the value EGP. In all
4554 other case the value of the ORIGIN attribute of the aggregated
4555 route is INTERNAL. */
4556 origin = BGP_ORIGIN_IGP;
4557
4558 table = bgp->rib[afi][safi];
4559
4560 top = bgp_node_get (table, p);
4561 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4562 if (rn->p.prefixlen > p->prefixlen)
4563 {
4564 match = 0;
4565
4566 for (ri = rn->info; ri; ri = ri->next)
4567 {
4568 if (BGP_INFO_HOLDDOWN (ri))
4569 continue;
4570
4571 if (del && ri == del)
4572 continue;
4573
4574 if (! rinew && first)
4575 {
4576 nexthop = ri->attr->nexthop;
4577 med = ri->attr->med;
4578 first = 0;
4579 }
4580
4581#ifdef AGGREGATE_NEXTHOP_CHECK
4582 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4583 || ri->attr->med != med)
4584 {
4585 if (aspath)
4586 aspath_free (aspath);
4587 if (community)
4588 community_free (community);
4589 bgp_unlock_node (rn);
4590 bgp_unlock_node (top);
4591 return;
4592 }
4593#endif /* AGGREGATE_NEXTHOP_CHECK */
4594
4595 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4596 {
4597 if (aggregate->summary_only)
4598 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004599 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004600 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004601 match++;
4602 }
4603
4604 aggregate->count++;
4605
4606 if (aggregate->as_set)
4607 {
4608 if (origin < ri->attr->origin)
4609 origin = ri->attr->origin;
4610
4611 if (aspath)
4612 {
4613 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4614 aspath_free (aspath);
4615 aspath = asmerge;
4616 }
4617 else
4618 aspath = aspath_dup (ri->attr->aspath);
4619
4620 if (ri->attr->community)
4621 {
4622 if (community)
4623 {
4624 commerge = community_merge (community,
4625 ri->attr->community);
4626 community = community_uniq_sort (commerge);
4627 community_free (commerge);
4628 }
4629 else
4630 community = community_dup (ri->attr->community);
4631 }
4632 }
4633 }
4634 }
4635 if (match)
4636 bgp_process (bgp, rn, afi, safi);
4637 }
4638 bgp_unlock_node (top);
4639
4640 if (rinew)
4641 {
4642 aggregate->count++;
4643
4644 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004645 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004646
4647 if (aggregate->as_set)
4648 {
4649 if (origin < rinew->attr->origin)
4650 origin = rinew->attr->origin;
4651
4652 if (aspath)
4653 {
4654 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4655 aspath_free (aspath);
4656 aspath = asmerge;
4657 }
4658 else
4659 aspath = aspath_dup (rinew->attr->aspath);
4660
4661 if (rinew->attr->community)
4662 {
4663 if (community)
4664 {
4665 commerge = community_merge (community,
4666 rinew->attr->community);
4667 community = community_uniq_sort (commerge);
4668 community_free (commerge);
4669 }
4670 else
4671 community = community_dup (rinew->attr->community);
4672 }
4673 }
4674 }
4675
4676 if (aggregate->count > 0)
4677 {
4678 rn = bgp_node_get (table, p);
4679 new = bgp_info_new ();
4680 new->type = ZEBRA_ROUTE_BGP;
4681 new->sub_type = BGP_ROUTE_AGGREGATE;
4682 new->peer = bgp->peer_self;
4683 SET_FLAG (new->flags, BGP_INFO_VALID);
4684 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004685 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004686
4687 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004688 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004689 bgp_process (bgp, rn, afi, safi);
4690 }
4691 else
4692 {
4693 if (aspath)
4694 aspath_free (aspath);
4695 if (community)
4696 community_free (community);
4697 }
4698}
4699
4700void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4701 struct bgp_aggregate *);
4702
4703void
4704bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4705 struct bgp_info *ri, afi_t afi, safi_t safi)
4706{
4707 struct bgp_node *child;
4708 struct bgp_node *rn;
4709 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004710 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004711
4712 /* MPLS-VPN aggregation is not yet supported. */
4713 if (safi == SAFI_MPLS_VPN)
4714 return;
4715
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004716 table = bgp->aggregate[afi][safi];
4717
4718 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004719 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004720 return;
4721
paul718e3742002-12-13 20:15:29 +00004722 if (p->prefixlen == 0)
4723 return;
4724
4725 if (BGP_INFO_HOLDDOWN (ri))
4726 return;
4727
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004728 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004729
4730 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004731 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004732 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4733 {
4734 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004735 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004736 }
4737 bgp_unlock_node (child);
4738}
4739
4740void
4741bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4742 struct bgp_info *del, afi_t afi, safi_t safi)
4743{
4744 struct bgp_node *child;
4745 struct bgp_node *rn;
4746 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004747 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004748
4749 /* MPLS-VPN aggregation is not yet supported. */
4750 if (safi == SAFI_MPLS_VPN)
4751 return;
4752
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004753 table = bgp->aggregate[afi][safi];
4754
4755 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004756 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004757 return;
4758
paul718e3742002-12-13 20:15:29 +00004759 if (p->prefixlen == 0)
4760 return;
4761
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004762 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004763
4764 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004765 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004766 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4767 {
4768 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004769 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004770 }
4771 bgp_unlock_node (child);
4772}
4773
paul94f2b392005-06-28 12:44:16 +00004774static void
paul718e3742002-12-13 20:15:29 +00004775bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4776 struct bgp_aggregate *aggregate)
4777{
4778 struct bgp_table *table;
4779 struct bgp_node *top;
4780 struct bgp_node *rn;
4781 struct bgp_info *new;
4782 struct bgp_info *ri;
4783 unsigned long match;
4784 u_char origin = BGP_ORIGIN_IGP;
4785 struct aspath *aspath = NULL;
4786 struct aspath *asmerge = NULL;
4787 struct community *community = NULL;
4788 struct community *commerge = NULL;
4789
4790 table = bgp->rib[afi][safi];
4791
4792 /* Sanity check. */
4793 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4794 return;
4795 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4796 return;
4797
4798 /* If routes exists below this node, generate aggregate routes. */
4799 top = bgp_node_get (table, p);
4800 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4801 if (rn->p.prefixlen > p->prefixlen)
4802 {
4803 match = 0;
4804
4805 for (ri = rn->info; ri; ri = ri->next)
4806 {
4807 if (BGP_INFO_HOLDDOWN (ri))
4808 continue;
4809
4810 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4811 {
4812 /* summary-only aggregate route suppress aggregated
4813 route announcement. */
4814 if (aggregate->summary_only)
4815 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004816 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004817 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004818 match++;
4819 }
4820 /* as-set aggregate route generate origin, as path,
4821 community aggregation. */
4822 if (aggregate->as_set)
4823 {
4824 if (origin < ri->attr->origin)
4825 origin = ri->attr->origin;
4826
4827 if (aspath)
4828 {
4829 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4830 aspath_free (aspath);
4831 aspath = asmerge;
4832 }
4833 else
4834 aspath = aspath_dup (ri->attr->aspath);
4835
4836 if (ri->attr->community)
4837 {
4838 if (community)
4839 {
4840 commerge = community_merge (community,
4841 ri->attr->community);
4842 community = community_uniq_sort (commerge);
4843 community_free (commerge);
4844 }
4845 else
4846 community = community_dup (ri->attr->community);
4847 }
4848 }
4849 aggregate->count++;
4850 }
4851 }
4852
4853 /* If this node is suppressed, process the change. */
4854 if (match)
4855 bgp_process (bgp, rn, afi, safi);
4856 }
4857 bgp_unlock_node (top);
4858
4859 /* Add aggregate route to BGP table. */
4860 if (aggregate->count)
4861 {
4862 rn = bgp_node_get (table, p);
4863
4864 new = bgp_info_new ();
4865 new->type = ZEBRA_ROUTE_BGP;
4866 new->sub_type = BGP_ROUTE_AGGREGATE;
4867 new->peer = bgp->peer_self;
4868 SET_FLAG (new->flags, BGP_INFO_VALID);
4869 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004870 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004871
4872 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004873 bgp_unlock_node (rn);
4874
paul718e3742002-12-13 20:15:29 +00004875 /* Process change. */
4876 bgp_process (bgp, rn, afi, safi);
4877 }
4878}
4879
4880void
4881bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4882 safi_t safi, struct bgp_aggregate *aggregate)
4883{
4884 struct bgp_table *table;
4885 struct bgp_node *top;
4886 struct bgp_node *rn;
4887 struct bgp_info *ri;
4888 unsigned long match;
4889
4890 table = bgp->rib[afi][safi];
4891
4892 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4893 return;
4894 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4895 return;
4896
4897 /* If routes exists below this node, generate aggregate routes. */
4898 top = bgp_node_get (table, p);
4899 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4900 if (rn->p.prefixlen > p->prefixlen)
4901 {
4902 match = 0;
4903
4904 for (ri = rn->info; ri; ri = ri->next)
4905 {
4906 if (BGP_INFO_HOLDDOWN (ri))
4907 continue;
4908
4909 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4910 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004911 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004912 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004913 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004914
Paul Jakmafb982c22007-05-04 20:15:47 +00004915 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004916 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004917 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004918 match++;
4919 }
4920 }
4921 aggregate->count--;
4922 }
4923 }
4924
Paul Jakmafb982c22007-05-04 20:15:47 +00004925 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004926 if (match)
4927 bgp_process (bgp, rn, afi, safi);
4928 }
4929 bgp_unlock_node (top);
4930
4931 /* Delete aggregate route from BGP table. */
4932 rn = bgp_node_get (table, p);
4933
4934 for (ri = rn->info; ri; ri = ri->next)
4935 if (ri->peer == bgp->peer_self
4936 && ri->type == ZEBRA_ROUTE_BGP
4937 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4938 break;
4939
4940 /* Withdraw static BGP route from routing table. */
4941 if (ri)
4942 {
paul718e3742002-12-13 20:15:29 +00004943 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004944 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004945 }
4946
4947 /* Unlock bgp_node_lookup. */
4948 bgp_unlock_node (rn);
4949}
4950
4951/* Aggregate route attribute. */
4952#define AGGREGATE_SUMMARY_ONLY 1
4953#define AGGREGATE_AS_SET 1
4954
paul94f2b392005-06-28 12:44:16 +00004955static int
Robert Baysf6269b42010-08-05 10:26:28 -07004956bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4957 afi_t afi, safi_t safi)
4958{
4959 int ret;
4960 struct prefix p;
4961 struct bgp_node *rn;
4962 struct bgp *bgp;
4963 struct bgp_aggregate *aggregate;
4964
4965 /* Convert string to prefix structure. */
4966 ret = str2prefix (prefix_str, &p);
4967 if (!ret)
4968 {
4969 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4970 return CMD_WARNING;
4971 }
4972 apply_mask (&p);
4973
4974 /* Get BGP structure. */
4975 bgp = vty->index;
4976
4977 /* Old configuration check. */
4978 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4979 if (! rn)
4980 {
4981 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4982 VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985
4986 aggregate = rn->info;
4987 if (aggregate->safi & SAFI_UNICAST)
4988 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4989 if (aggregate->safi & SAFI_MULTICAST)
4990 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4991
4992 /* Unlock aggregate address configuration. */
4993 rn->info = NULL;
4994 bgp_aggregate_free (aggregate);
4995 bgp_unlock_node (rn);
4996 bgp_unlock_node (rn);
4997
4998 return CMD_SUCCESS;
4999}
5000
5001static int
5002bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005003 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005004 u_char summary_only, u_char as_set)
5005{
5006 int ret;
5007 struct prefix p;
5008 struct bgp_node *rn;
5009 struct bgp *bgp;
5010 struct bgp_aggregate *aggregate;
5011
5012 /* Convert string to prefix structure. */
5013 ret = str2prefix (prefix_str, &p);
5014 if (!ret)
5015 {
5016 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5017 return CMD_WARNING;
5018 }
5019 apply_mask (&p);
5020
5021 /* Get BGP structure. */
5022 bgp = vty->index;
5023
5024 /* Old configuration check. */
5025 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5026
5027 if (rn->info)
5028 {
5029 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005030 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005031 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5032 if (ret)
5033 {
Robert Bays368473f2010-08-05 10:26:29 -07005034 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5035 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005036 return CMD_WARNING;
5037 }
paul718e3742002-12-13 20:15:29 +00005038 }
5039
5040 /* Make aggregate address structure. */
5041 aggregate = bgp_aggregate_new ();
5042 aggregate->summary_only = summary_only;
5043 aggregate->as_set = as_set;
5044 aggregate->safi = safi;
5045 rn->info = aggregate;
5046
5047 /* Aggregate address insert into BGP routing table. */
5048 if (safi & SAFI_UNICAST)
5049 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5050 if (safi & SAFI_MULTICAST)
5051 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5052
5053 return CMD_SUCCESS;
5054}
5055
paul718e3742002-12-13 20:15:29 +00005056DEFUN (aggregate_address,
5057 aggregate_address_cmd,
5058 "aggregate-address A.B.C.D/M",
5059 "Configure BGP aggregate entries\n"
5060 "Aggregate prefix\n")
5061{
5062 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5063}
5064
5065DEFUN (aggregate_address_mask,
5066 aggregate_address_mask_cmd,
5067 "aggregate-address A.B.C.D A.B.C.D",
5068 "Configure BGP aggregate entries\n"
5069 "Aggregate address\n"
5070 "Aggregate mask\n")
5071{
5072 int ret;
5073 char prefix_str[BUFSIZ];
5074
5075 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5076
5077 if (! ret)
5078 {
5079 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5080 return CMD_WARNING;
5081 }
5082
5083 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5084 0, 0);
5085}
5086
5087DEFUN (aggregate_address_summary_only,
5088 aggregate_address_summary_only_cmd,
5089 "aggregate-address A.B.C.D/M summary-only",
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate prefix\n"
5092 "Filter more specific routes from updates\n")
5093{
5094 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5095 AGGREGATE_SUMMARY_ONLY, 0);
5096}
5097
5098DEFUN (aggregate_address_mask_summary_only,
5099 aggregate_address_mask_summary_only_cmd,
5100 "aggregate-address A.B.C.D A.B.C.D summary-only",
5101 "Configure BGP aggregate entries\n"
5102 "Aggregate address\n"
5103 "Aggregate mask\n"
5104 "Filter more specific routes from updates\n")
5105{
5106 int ret;
5107 char prefix_str[BUFSIZ];
5108
5109 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5110
5111 if (! ret)
5112 {
5113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5114 return CMD_WARNING;
5115 }
5116
5117 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5118 AGGREGATE_SUMMARY_ONLY, 0);
5119}
5120
5121DEFUN (aggregate_address_as_set,
5122 aggregate_address_as_set_cmd,
5123 "aggregate-address A.B.C.D/M as-set",
5124 "Configure BGP aggregate entries\n"
5125 "Aggregate prefix\n"
5126 "Generate AS set path information\n")
5127{
5128 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5129 0, AGGREGATE_AS_SET);
5130}
5131
5132DEFUN (aggregate_address_mask_as_set,
5133 aggregate_address_mask_as_set_cmd,
5134 "aggregate-address A.B.C.D A.B.C.D as-set",
5135 "Configure BGP aggregate entries\n"
5136 "Aggregate address\n"
5137 "Aggregate mask\n"
5138 "Generate AS set path information\n")
5139{
5140 int ret;
5141 char prefix_str[BUFSIZ];
5142
5143 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5144
5145 if (! ret)
5146 {
5147 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5148 return CMD_WARNING;
5149 }
5150
5151 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5152 0, AGGREGATE_AS_SET);
5153}
5154
5155
5156DEFUN (aggregate_address_as_set_summary,
5157 aggregate_address_as_set_summary_cmd,
5158 "aggregate-address A.B.C.D/M as-set summary-only",
5159 "Configure BGP aggregate entries\n"
5160 "Aggregate prefix\n"
5161 "Generate AS set path information\n"
5162 "Filter more specific routes from updates\n")
5163{
5164 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5165 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5166}
5167
5168ALIAS (aggregate_address_as_set_summary,
5169 aggregate_address_summary_as_set_cmd,
5170 "aggregate-address A.B.C.D/M summary-only as-set",
5171 "Configure BGP aggregate entries\n"
5172 "Aggregate prefix\n"
5173 "Filter more specific routes from updates\n"
5174 "Generate AS set path information\n")
5175
5176DEFUN (aggregate_address_mask_as_set_summary,
5177 aggregate_address_mask_as_set_summary_cmd,
5178 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate address\n"
5181 "Aggregate mask\n"
5182 "Generate AS set path information\n"
5183 "Filter more specific routes from updates\n")
5184{
5185 int ret;
5186 char prefix_str[BUFSIZ];
5187
5188 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5189
5190 if (! ret)
5191 {
5192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5193 return CMD_WARNING;
5194 }
5195
5196 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5197 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5198}
5199
5200ALIAS (aggregate_address_mask_as_set_summary,
5201 aggregate_address_mask_summary_as_set_cmd,
5202 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate address\n"
5205 "Aggregate mask\n"
5206 "Filter more specific routes from updates\n"
5207 "Generate AS set path information\n")
5208
5209DEFUN (no_aggregate_address,
5210 no_aggregate_address_cmd,
5211 "no aggregate-address A.B.C.D/M",
5212 NO_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate prefix\n")
5215{
5216 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5217}
5218
5219ALIAS (no_aggregate_address,
5220 no_aggregate_address_summary_only_cmd,
5221 "no aggregate-address A.B.C.D/M summary-only",
5222 NO_STR
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate prefix\n"
5225 "Filter more specific routes from updates\n")
5226
5227ALIAS (no_aggregate_address,
5228 no_aggregate_address_as_set_cmd,
5229 "no aggregate-address A.B.C.D/M as-set",
5230 NO_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate prefix\n"
5233 "Generate AS set path information\n")
5234
5235ALIAS (no_aggregate_address,
5236 no_aggregate_address_as_set_summary_cmd,
5237 "no aggregate-address A.B.C.D/M as-set summary-only",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate prefix\n"
5241 "Generate AS set path information\n"
5242 "Filter more specific routes from updates\n")
5243
5244ALIAS (no_aggregate_address,
5245 no_aggregate_address_summary_as_set_cmd,
5246 "no aggregate-address A.B.C.D/M summary-only as-set",
5247 NO_STR
5248 "Configure BGP aggregate entries\n"
5249 "Aggregate prefix\n"
5250 "Filter more specific routes from updates\n"
5251 "Generate AS set path information\n")
5252
5253DEFUN (no_aggregate_address_mask,
5254 no_aggregate_address_mask_cmd,
5255 "no aggregate-address A.B.C.D A.B.C.D",
5256 NO_STR
5257 "Configure BGP aggregate entries\n"
5258 "Aggregate address\n"
5259 "Aggregate mask\n")
5260{
5261 int ret;
5262 char prefix_str[BUFSIZ];
5263
5264 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5265
5266 if (! ret)
5267 {
5268 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5269 return CMD_WARNING;
5270 }
5271
5272 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5273}
5274
5275ALIAS (no_aggregate_address_mask,
5276 no_aggregate_address_mask_summary_only_cmd,
5277 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5278 NO_STR
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate address\n"
5281 "Aggregate mask\n"
5282 "Filter more specific routes from updates\n")
5283
5284ALIAS (no_aggregate_address_mask,
5285 no_aggregate_address_mask_as_set_cmd,
5286 "no aggregate-address A.B.C.D A.B.C.D as-set",
5287 NO_STR
5288 "Configure BGP aggregate entries\n"
5289 "Aggregate address\n"
5290 "Aggregate mask\n"
5291 "Generate AS set path information\n")
5292
5293ALIAS (no_aggregate_address_mask,
5294 no_aggregate_address_mask_as_set_summary_cmd,
5295 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5296 NO_STR
5297 "Configure BGP aggregate entries\n"
5298 "Aggregate address\n"
5299 "Aggregate mask\n"
5300 "Generate AS set path information\n"
5301 "Filter more specific routes from updates\n")
5302
5303ALIAS (no_aggregate_address_mask,
5304 no_aggregate_address_mask_summary_as_set_cmd,
5305 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5306 NO_STR
5307 "Configure BGP aggregate entries\n"
5308 "Aggregate address\n"
5309 "Aggregate mask\n"
5310 "Filter more specific routes from updates\n"
5311 "Generate AS set path information\n")
5312
5313#ifdef HAVE_IPV6
5314DEFUN (ipv6_aggregate_address,
5315 ipv6_aggregate_address_cmd,
5316 "aggregate-address X:X::X:X/M",
5317 "Configure BGP aggregate entries\n"
5318 "Aggregate prefix\n")
5319{
5320 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5321}
5322
5323DEFUN (ipv6_aggregate_address_summary_only,
5324 ipv6_aggregate_address_summary_only_cmd,
5325 "aggregate-address X:X::X:X/M summary-only",
5326 "Configure BGP aggregate entries\n"
5327 "Aggregate prefix\n"
5328 "Filter more specific routes from updates\n")
5329{
5330 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5331 AGGREGATE_SUMMARY_ONLY, 0);
5332}
5333
5334DEFUN (no_ipv6_aggregate_address,
5335 no_ipv6_aggregate_address_cmd,
5336 "no aggregate-address X:X::X:X/M",
5337 NO_STR
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n")
5340{
5341 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5342}
5343
5344DEFUN (no_ipv6_aggregate_address_summary_only,
5345 no_ipv6_aggregate_address_summary_only_cmd,
5346 "no aggregate-address X:X::X:X/M summary-only",
5347 NO_STR
5348 "Configure BGP aggregate entries\n"
5349 "Aggregate prefix\n"
5350 "Filter more specific routes from updates\n")
5351{
5352 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5353}
5354
5355ALIAS (ipv6_aggregate_address,
5356 old_ipv6_aggregate_address_cmd,
5357 "ipv6 bgp aggregate-address X:X::X:X/M",
5358 IPV6_STR
5359 BGP_STR
5360 "Configure BGP aggregate entries\n"
5361 "Aggregate prefix\n")
5362
5363ALIAS (ipv6_aggregate_address_summary_only,
5364 old_ipv6_aggregate_address_summary_only_cmd,
5365 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5366 IPV6_STR
5367 BGP_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n"
5370 "Filter more specific routes from updates\n")
5371
5372ALIAS (no_ipv6_aggregate_address,
5373 old_no_ipv6_aggregate_address_cmd,
5374 "no ipv6 bgp aggregate-address X:X::X:X/M",
5375 NO_STR
5376 IPV6_STR
5377 BGP_STR
5378 "Configure BGP aggregate entries\n"
5379 "Aggregate prefix\n")
5380
5381ALIAS (no_ipv6_aggregate_address_summary_only,
5382 old_no_ipv6_aggregate_address_summary_only_cmd,
5383 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5384 NO_STR
5385 IPV6_STR
5386 BGP_STR
5387 "Configure BGP aggregate entries\n"
5388 "Aggregate prefix\n"
5389 "Filter more specific routes from updates\n")
5390#endif /* HAVE_IPV6 */
5391
5392/* Redistribute route treatment. */
5393void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005394bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5395 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005396 u_int32_t metric, u_char type)
5397{
5398 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005399 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005400 struct bgp_info *new;
5401 struct bgp_info *bi;
5402 struct bgp_info info;
5403 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005404 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005405 struct attr *new_attr;
5406 afi_t afi;
5407 int ret;
5408
5409 /* Make default attribute. */
5410 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5411 if (nexthop)
5412 attr.nexthop = *nexthop;
5413
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005414#ifdef HAVE_IPV6
5415 if (nexthop6)
5416 {
5417 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5418 extra->mp_nexthop_global = *nexthop6;
5419 extra->mp_nexthop_len = 16;
5420 }
5421#endif
5422
paul718e3742002-12-13 20:15:29 +00005423 attr.med = metric;
5424 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5425
paul1eb8ef22005-04-07 07:30:20 +00005426 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005427 {
5428 afi = family2afi (p->family);
5429
5430 if (bgp->redist[afi][type])
5431 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005432 struct attr attr_new;
5433 struct attr_extra extra_new;
5434
paul718e3742002-12-13 20:15:29 +00005435 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005436 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005437 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005438
5439 if (bgp->redist_metric_flag[afi][type])
5440 attr_new.med = bgp->redist_metric[afi][type];
5441
5442 /* Apply route-map. */
5443 if (bgp->rmap[afi][type].map)
5444 {
5445 info.peer = bgp->peer_self;
5446 info.attr = &attr_new;
5447
paulfee0f4c2004-09-13 05:12:46 +00005448 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5449
paul718e3742002-12-13 20:15:29 +00005450 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5451 &info);
paulfee0f4c2004-09-13 05:12:46 +00005452
5453 bgp->peer_self->rmap_type = 0;
5454
paul718e3742002-12-13 20:15:29 +00005455 if (ret == RMAP_DENYMATCH)
5456 {
5457 /* Free uninterned attribute. */
5458 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005459
paul718e3742002-12-13 20:15:29 +00005460 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005461 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005462 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005463 bgp_redistribute_delete (p, type);
5464 return;
5465 }
5466 }
5467
Paul Jakmafb982c22007-05-04 20:15:47 +00005468 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5469 afi, SAFI_UNICAST, p, NULL);
5470
paul718e3742002-12-13 20:15:29 +00005471 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005472
paul718e3742002-12-13 20:15:29 +00005473 for (bi = bn->info; bi; bi = bi->next)
5474 if (bi->peer == bgp->peer_self
5475 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5476 break;
5477
5478 if (bi)
5479 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005480 if (attrhash_cmp (bi->attr, new_attr) &&
5481 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005482 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005483 bgp_attr_unintern (&new_attr);
5484 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005485 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005486 bgp_unlock_node (bn);
5487 return;
5488 }
5489 else
5490 {
5491 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005492 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005493
5494 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005495 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5496 bgp_info_restore(bn, bi);
5497 else
5498 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005499 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005500 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005501 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005502
5503 /* Process change. */
5504 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5505 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5506 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005507 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005508 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005509 return;
5510 }
5511 }
5512
5513 new = bgp_info_new ();
5514 new->type = type;
5515 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5516 new->peer = bgp->peer_self;
5517 SET_FLAG (new->flags, BGP_INFO_VALID);
5518 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005519 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005520
5521 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5522 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005523 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005524 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5525 }
5526 }
5527
5528 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005529 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005530 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005531}
5532
5533void
5534bgp_redistribute_delete (struct prefix *p, u_char type)
5535{
5536 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005537 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005538 afi_t afi;
5539 struct bgp_node *rn;
5540 struct bgp_info *ri;
5541
paul1eb8ef22005-04-07 07:30:20 +00005542 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005543 {
5544 afi = family2afi (p->family);
5545
5546 if (bgp->redist[afi][type])
5547 {
paulfee0f4c2004-09-13 05:12:46 +00005548 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005549
5550 for (ri = rn->info; ri; ri = ri->next)
5551 if (ri->peer == bgp->peer_self
5552 && ri->type == type)
5553 break;
5554
5555 if (ri)
5556 {
5557 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005558 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005559 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005560 }
5561 bgp_unlock_node (rn);
5562 }
5563 }
5564}
5565
5566/* Withdraw specified route type's route. */
5567void
5568bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5569{
5570 struct bgp_node *rn;
5571 struct bgp_info *ri;
5572 struct bgp_table *table;
5573
5574 table = bgp->rib[afi][SAFI_UNICAST];
5575
5576 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5577 {
5578 for (ri = rn->info; ri; ri = ri->next)
5579 if (ri->peer == bgp->peer_self
5580 && ri->type == type)
5581 break;
5582
5583 if (ri)
5584 {
5585 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005586 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005587 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005588 }
5589 }
5590}
5591
5592/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005593static void
paul718e3742002-12-13 20:15:29 +00005594route_vty_out_route (struct prefix *p, struct vty *vty)
5595{
5596 int len;
5597 u_int32_t destination;
5598 char buf[BUFSIZ];
5599
5600 if (p->family == AF_INET)
5601 {
5602 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5603 destination = ntohl (p->u.prefix4.s_addr);
5604
5605 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5606 || (IN_CLASSB (destination) && p->prefixlen == 16)
5607 || (IN_CLASSA (destination) && p->prefixlen == 8)
5608 || p->u.prefix4.s_addr == 0)
5609 {
5610 /* When mask is natural, mask is not displayed. */
5611 }
5612 else
5613 len += vty_out (vty, "/%d", p->prefixlen);
5614 }
5615 else
5616 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5617 p->prefixlen);
5618
5619 len = 17 - len;
5620 if (len < 1)
5621 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5622 else
5623 vty_out (vty, "%*s", len, " ");
5624}
5625
paul718e3742002-12-13 20:15:29 +00005626enum bgp_display_type
5627{
5628 normal_list,
5629};
5630
paulb40d9392005-08-22 22:34:41 +00005631/* Print the short form route status for a bgp_info */
5632static void
5633route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005634{
paulb40d9392005-08-22 22:34:41 +00005635 /* Route status display. */
5636 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5637 vty_out (vty, "R");
5638 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005639 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005640 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005641 vty_out (vty, "s");
5642 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5643 vty_out (vty, "*");
5644 else
5645 vty_out (vty, " ");
5646
5647 /* Selected */
5648 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5649 vty_out (vty, "h");
5650 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5651 vty_out (vty, "d");
5652 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5653 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005654 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5655 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005656 else
5657 vty_out (vty, " ");
5658
5659 /* Internal route. */
5660 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5661 vty_out (vty, "i");
5662 else
paulb40d9392005-08-22 22:34:41 +00005663 vty_out (vty, " ");
5664}
5665
5666/* called from terminal list command */
5667void
5668route_vty_out (struct vty *vty, struct prefix *p,
5669 struct bgp_info *binfo, int display, safi_t safi)
5670{
5671 struct attr *attr;
5672
5673 /* short status lead text */
5674 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005675
5676 /* print prefix and mask */
5677 if (! display)
5678 route_vty_out_route (p, vty);
5679 else
5680 vty_out (vty, "%*s", 17, " ");
5681
5682 /* Print attribute */
5683 attr = binfo->attr;
5684 if (attr)
5685 {
5686 if (p->family == AF_INET)
5687 {
5688 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005689 vty_out (vty, "%-16s",
5690 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005691 else
5692 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5693 }
5694#ifdef HAVE_IPV6
5695 else if (p->family == AF_INET6)
5696 {
5697 int len;
5698 char buf[BUFSIZ];
5699
5700 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005701 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5702 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005703 len = 16 - len;
5704 if (len < 1)
5705 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5706 else
5707 vty_out (vty, "%*s", len, " ");
5708 }
5709#endif /* HAVE_IPV6 */
5710
5711 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005712 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005713 else
5714 vty_out (vty, " ");
5715
5716 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005717 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005718 else
5719 vty_out (vty, " ");
5720
Paul Jakmafb982c22007-05-04 20:15:47 +00005721 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005722
Paul Jakmab2518c12006-05-12 23:48:40 +00005723 /* Print aspath */
5724 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005725 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005726
Paul Jakmab2518c12006-05-12 23:48:40 +00005727 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005728 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005729 }
paul718e3742002-12-13 20:15:29 +00005730 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005731}
5732
5733/* called from terminal list command */
5734void
5735route_vty_out_tmp (struct vty *vty, struct prefix *p,
5736 struct attr *attr, safi_t safi)
5737{
5738 /* Route status display. */
5739 vty_out (vty, "*");
5740 vty_out (vty, ">");
5741 vty_out (vty, " ");
5742
5743 /* print prefix and mask */
5744 route_vty_out_route (p, vty);
5745
5746 /* Print attribute */
5747 if (attr)
5748 {
5749 if (p->family == AF_INET)
5750 {
5751 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005752 vty_out (vty, "%-16s",
5753 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005754 else
5755 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5756 }
5757#ifdef HAVE_IPV6
5758 else if (p->family == AF_INET6)
5759 {
5760 int len;
5761 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005762
5763 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005764
5765 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005766 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5767 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005768 len = 16 - len;
5769 if (len < 1)
5770 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5771 else
5772 vty_out (vty, "%*s", len, " ");
5773 }
5774#endif /* HAVE_IPV6 */
5775
5776 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005777 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005778 else
5779 vty_out (vty, " ");
5780
5781 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005782 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005783 else
5784 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005785
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005786 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005787
Paul Jakmab2518c12006-05-12 23:48:40 +00005788 /* Print aspath */
5789 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005790 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005791
Paul Jakmab2518c12006-05-12 23:48:40 +00005792 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005793 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005794 }
paul718e3742002-12-13 20:15:29 +00005795
5796 vty_out (vty, "%s", VTY_NEWLINE);
5797}
5798
ajs5a646652004-11-05 01:25:55 +00005799void
paul718e3742002-12-13 20:15:29 +00005800route_vty_out_tag (struct vty *vty, struct prefix *p,
5801 struct bgp_info *binfo, int display, safi_t safi)
5802{
5803 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005804 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005805
5806 if (!binfo->extra)
5807 return;
5808
paulb40d9392005-08-22 22:34:41 +00005809 /* short status lead text */
5810 route_vty_short_status_out (vty, binfo);
5811
paul718e3742002-12-13 20:15:29 +00005812 /* print prefix and mask */
5813 if (! display)
5814 route_vty_out_route (p, vty);
5815 else
5816 vty_out (vty, "%*s", 17, " ");
5817
5818 /* Print attribute */
5819 attr = binfo->attr;
5820 if (attr)
5821 {
5822 if (p->family == AF_INET)
5823 {
5824 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005825 vty_out (vty, "%-16s",
5826 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005827 else
5828 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5829 }
5830#ifdef HAVE_IPV6
5831 else if (p->family == AF_INET6)
5832 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005833 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005834 char buf[BUFSIZ];
5835 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005836 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005837 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005838 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5839 buf, BUFSIZ));
5840 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005841 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5843 buf, BUFSIZ),
5844 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5845 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005846
5847 }
5848#endif /* HAVE_IPV6 */
5849 }
5850
Paul Jakmafb982c22007-05-04 20:15:47 +00005851 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005852
5853 vty_out (vty, "notag/%d", label);
5854
5855 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005856}
5857
5858/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005859static void
paul718e3742002-12-13 20:15:29 +00005860damp_route_vty_out (struct vty *vty, struct prefix *p,
5861 struct bgp_info *binfo, int display, safi_t safi)
5862{
5863 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005864 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005865 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005866
paulb40d9392005-08-22 22:34:41 +00005867 /* short status lead text */
5868 route_vty_short_status_out (vty, binfo);
5869
paul718e3742002-12-13 20:15:29 +00005870 /* print prefix and mask */
5871 if (! display)
5872 route_vty_out_route (p, vty);
5873 else
5874 vty_out (vty, "%*s", 17, " ");
5875
5876 len = vty_out (vty, "%s", binfo->peer->host);
5877 len = 17 - len;
5878 if (len < 1)
5879 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5880 else
5881 vty_out (vty, "%*s", len, " ");
5882
Chris Caputo50aef6f2009-06-23 06:06:49 +00005883 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005884
5885 /* Print attribute */
5886 attr = binfo->attr;
5887 if (attr)
5888 {
5889 /* Print aspath */
5890 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005891 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005892
5893 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005894 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005895 }
5896 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005897}
5898
paul718e3742002-12-13 20:15:29 +00005899/* flap route */
ajs5a646652004-11-05 01:25:55 +00005900static void
paul718e3742002-12-13 20:15:29 +00005901flap_route_vty_out (struct vty *vty, struct prefix *p,
5902 struct bgp_info *binfo, int display, safi_t safi)
5903{
5904 struct attr *attr;
5905 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005906 char timebuf[BGP_UPTIME_LEN];
5907 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005908
5909 if (!binfo->extra)
5910 return;
5911
5912 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005913
paulb40d9392005-08-22 22:34:41 +00005914 /* short status lead text */
5915 route_vty_short_status_out (vty, binfo);
5916
paul718e3742002-12-13 20:15:29 +00005917 /* print prefix and mask */
5918 if (! display)
5919 route_vty_out_route (p, vty);
5920 else
5921 vty_out (vty, "%*s", 17, " ");
5922
5923 len = vty_out (vty, "%s", binfo->peer->host);
5924 len = 16 - len;
5925 if (len < 1)
5926 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5927 else
5928 vty_out (vty, "%*s", len, " ");
5929
5930 len = vty_out (vty, "%d", bdi->flap);
5931 len = 5 - len;
5932 if (len < 1)
5933 vty_out (vty, " ");
5934 else
5935 vty_out (vty, "%*s ", len, " ");
5936
5937 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5938 timebuf, BGP_UPTIME_LEN));
5939
5940 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5941 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005942 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005943 else
5944 vty_out (vty, "%*s ", 8, " ");
5945
5946 /* Print attribute */
5947 attr = binfo->attr;
5948 if (attr)
5949 {
5950 /* Print aspath */
5951 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005952 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005953
5954 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005955 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005956 }
5957 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005958}
5959
paul94f2b392005-06-28 12:44:16 +00005960static void
paul718e3742002-12-13 20:15:29 +00005961route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5962 struct bgp_info *binfo, afi_t afi, safi_t safi)
5963{
5964 char buf[INET6_ADDRSTRLEN];
5965 char buf1[BUFSIZ];
5966 struct attr *attr;
5967 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005968#ifdef HAVE_CLOCK_MONOTONIC
5969 time_t tbuf;
5970#endif
paul718e3742002-12-13 20:15:29 +00005971
5972 attr = binfo->attr;
5973
5974 if (attr)
5975 {
5976 /* Line1 display AS-path, Aggregator */
5977 if (attr->aspath)
5978 {
5979 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005980 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005981 vty_out (vty, "Local");
5982 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005983 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005984 }
5985
paulb40d9392005-08-22 22:34:41 +00005986 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5987 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005988 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5989 vty_out (vty, ", (stale)");
5990 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005991 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005992 attr->extra->aggregator_as,
5993 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005994 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5995 vty_out (vty, ", (Received from a RR-client)");
5996 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5997 vty_out (vty, ", (Received from a RS-client)");
5998 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5999 vty_out (vty, ", (history entry)");
6000 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6001 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006002 vty_out (vty, "%s", VTY_NEWLINE);
6003
6004 /* Line2 display Next-hop, Neighbor, Router-id */
6005 if (p->family == AF_INET)
6006 {
6007 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006009 inet_ntoa (attr->nexthop));
6010 }
6011#ifdef HAVE_IPV6
6012 else
6013 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006014 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006015 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006017 buf, INET6_ADDRSTRLEN));
6018 }
6019#endif /* HAVE_IPV6 */
6020
6021 if (binfo->peer == bgp->peer_self)
6022 {
6023 vty_out (vty, " from %s ",
6024 p->family == AF_INET ? "0.0.0.0" : "::");
6025 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6026 }
6027 else
6028 {
6029 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6030 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006031 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006032 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006033 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006034 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006035 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006036 else
6037 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6038 }
6039 vty_out (vty, "%s", VTY_NEWLINE);
6040
6041#ifdef HAVE_IPV6
6042 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006043 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006044 {
6045 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006046 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006047 buf, INET6_ADDRSTRLEN),
6048 VTY_NEWLINE);
6049 }
6050#endif /* HAVE_IPV6 */
6051
6052 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6053 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6054
6055 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006056 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006057
6058 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006059 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006060 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006061 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006062
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006064 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006065
6066 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6067 vty_out (vty, ", valid");
6068
6069 if (binfo->peer != bgp->peer_self)
6070 {
6071 if (binfo->peer->as == binfo->peer->local_as)
6072 vty_out (vty, ", internal");
6073 else
6074 vty_out (vty, ", %s",
6075 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6076 }
6077 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6078 vty_out (vty, ", aggregated, local");
6079 else if (binfo->type != ZEBRA_ROUTE_BGP)
6080 vty_out (vty, ", sourced");
6081 else
6082 vty_out (vty, ", sourced, local");
6083
6084 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6085 vty_out (vty, ", atomic-aggregate");
6086
Josh Baileyde8d5df2011-07-20 20:46:01 -07006087 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6088 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6089 bgp_info_mpath_count (binfo)))
6090 vty_out (vty, ", multipath");
6091
paul718e3742002-12-13 20:15:29 +00006092 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6093 vty_out (vty, ", best");
6094
6095 vty_out (vty, "%s", VTY_NEWLINE);
6096
6097 /* Line 4 display Community */
6098 if (attr->community)
6099 vty_out (vty, " Community: %s%s", attr->community->str,
6100 VTY_NEWLINE);
6101
6102 /* Line 5 display Extended-community */
6103 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006104 vty_out (vty, " Extended Community: %s%s",
6105 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006106
6107 /* Line 6 display Originator, Cluster-id */
6108 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6109 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6110 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006111 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006112 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006113 vty_out (vty, " Originator: %s",
6114 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006115
6116 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6117 {
6118 int i;
6119 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006120 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6121 vty_out (vty, "%s ",
6122 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006123 }
6124 vty_out (vty, "%s", VTY_NEWLINE);
6125 }
Paul Jakma41367172007-08-06 15:24:51 +00006126
Paul Jakmafb982c22007-05-04 20:15:47 +00006127 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006128 bgp_damp_info_vty (vty, binfo);
6129
6130 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006131#ifdef HAVE_CLOCK_MONOTONIC
6132 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006133 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006134#else
6135 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6136#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006137 }
6138 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006139}
6140
6141#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6142 "h history, * valid, > best, = multipath,%s"\
6143 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006144#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006145#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6146#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6147#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6148
6149enum bgp_show_type
6150{
6151 bgp_show_type_normal,
6152 bgp_show_type_regexp,
6153 bgp_show_type_prefix_list,
6154 bgp_show_type_filter_list,
6155 bgp_show_type_route_map,
6156 bgp_show_type_neighbor,
6157 bgp_show_type_cidr_only,
6158 bgp_show_type_prefix_longer,
6159 bgp_show_type_community_all,
6160 bgp_show_type_community,
6161 bgp_show_type_community_exact,
6162 bgp_show_type_community_list,
6163 bgp_show_type_community_list_exact,
6164 bgp_show_type_flap_statistics,
6165 bgp_show_type_flap_address,
6166 bgp_show_type_flap_prefix,
6167 bgp_show_type_flap_cidr_only,
6168 bgp_show_type_flap_regexp,
6169 bgp_show_type_flap_filter_list,
6170 bgp_show_type_flap_prefix_list,
6171 bgp_show_type_flap_prefix_longer,
6172 bgp_show_type_flap_route_map,
6173 bgp_show_type_flap_neighbor,
6174 bgp_show_type_dampend_paths,
6175 bgp_show_type_damp_neighbor
6176};
6177
ajs5a646652004-11-05 01:25:55 +00006178static int
paulfee0f4c2004-09-13 05:12:46 +00006179bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006180 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006181{
paul718e3742002-12-13 20:15:29 +00006182 struct bgp_info *ri;
6183 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006184 int header = 1;
paul718e3742002-12-13 20:15:29 +00006185 int display;
ajs5a646652004-11-05 01:25:55 +00006186 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006187
6188 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006189 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006190
paul718e3742002-12-13 20:15:29 +00006191 /* Start processing of routes. */
6192 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6193 if (rn->info != NULL)
6194 {
6195 display = 0;
6196
6197 for (ri = rn->info; ri; ri = ri->next)
6198 {
ajs5a646652004-11-05 01:25:55 +00006199 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006200 || type == bgp_show_type_flap_address
6201 || type == bgp_show_type_flap_prefix
6202 || type == bgp_show_type_flap_cidr_only
6203 || type == bgp_show_type_flap_regexp
6204 || type == bgp_show_type_flap_filter_list
6205 || type == bgp_show_type_flap_prefix_list
6206 || type == bgp_show_type_flap_prefix_longer
6207 || type == bgp_show_type_flap_route_map
6208 || type == bgp_show_type_flap_neighbor
6209 || type == bgp_show_type_dampend_paths
6210 || type == bgp_show_type_damp_neighbor)
6211 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006212 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006213 continue;
6214 }
6215 if (type == bgp_show_type_regexp
6216 || type == bgp_show_type_flap_regexp)
6217 {
ajs5a646652004-11-05 01:25:55 +00006218 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006219
6220 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6221 continue;
6222 }
6223 if (type == bgp_show_type_prefix_list
6224 || type == bgp_show_type_flap_prefix_list)
6225 {
ajs5a646652004-11-05 01:25:55 +00006226 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006227
6228 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6229 continue;
6230 }
6231 if (type == bgp_show_type_filter_list
6232 || type == bgp_show_type_flap_filter_list)
6233 {
ajs5a646652004-11-05 01:25:55 +00006234 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006235
6236 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6237 continue;
6238 }
6239 if (type == bgp_show_type_route_map
6240 || type == bgp_show_type_flap_route_map)
6241 {
ajs5a646652004-11-05 01:25:55 +00006242 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006243 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006244 struct attr dummy_attr;
6245 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006246 int ret;
6247
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006248 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006249 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006250
paul718e3742002-12-13 20:15:29 +00006251 binfo.peer = ri->peer;
6252 binfo.attr = &dummy_attr;
6253
6254 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006255 if (ret == RMAP_DENYMATCH)
6256 continue;
6257 }
6258 if (type == bgp_show_type_neighbor
6259 || type == bgp_show_type_flap_neighbor
6260 || type == bgp_show_type_damp_neighbor)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006263
6264 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6265 continue;
6266 }
6267 if (type == bgp_show_type_cidr_only
6268 || type == bgp_show_type_flap_cidr_only)
6269 {
6270 u_int32_t destination;
6271
6272 destination = ntohl (rn->p.u.prefix4.s_addr);
6273 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6274 continue;
6275 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6276 continue;
6277 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6278 continue;
6279 }
6280 if (type == bgp_show_type_prefix_longer
6281 || type == bgp_show_type_flap_prefix_longer)
6282 {
ajs5a646652004-11-05 01:25:55 +00006283 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006284
6285 if (! prefix_match (p, &rn->p))
6286 continue;
6287 }
6288 if (type == bgp_show_type_community_all)
6289 {
6290 if (! ri->attr->community)
6291 continue;
6292 }
6293 if (type == bgp_show_type_community)
6294 {
ajs5a646652004-11-05 01:25:55 +00006295 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006296
6297 if (! ri->attr->community ||
6298 ! community_match (ri->attr->community, com))
6299 continue;
6300 }
6301 if (type == bgp_show_type_community_exact)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! ri->attr->community ||
6306 ! community_cmp (ri->attr->community, com))
6307 continue;
6308 }
6309 if (type == bgp_show_type_community_list)
6310 {
ajs5a646652004-11-05 01:25:55 +00006311 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006312
6313 if (! community_list_match (ri->attr->community, list))
6314 continue;
6315 }
6316 if (type == bgp_show_type_community_list_exact)
6317 {
ajs5a646652004-11-05 01:25:55 +00006318 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006319
6320 if (! community_list_exact_match (ri->attr->community, list))
6321 continue;
6322 }
6323 if (type == bgp_show_type_flap_address
6324 || type == bgp_show_type_flap_prefix)
6325 {
ajs5a646652004-11-05 01:25:55 +00006326 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006327
6328 if (! prefix_match (&rn->p, p))
6329 continue;
6330
6331 if (type == bgp_show_type_flap_prefix)
6332 if (p->prefixlen != rn->p.prefixlen)
6333 continue;
6334 }
6335 if (type == bgp_show_type_dampend_paths
6336 || type == bgp_show_type_damp_neighbor)
6337 {
6338 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6339 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6340 continue;
6341 }
6342
6343 if (header)
6344 {
hasso93406d82005-02-02 14:40:33 +00006345 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6346 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6347 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006348 if (type == bgp_show_type_dampend_paths
6349 || type == bgp_show_type_damp_neighbor)
6350 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6351 else if (type == bgp_show_type_flap_statistics
6352 || type == bgp_show_type_flap_address
6353 || type == bgp_show_type_flap_prefix
6354 || type == bgp_show_type_flap_cidr_only
6355 || type == bgp_show_type_flap_regexp
6356 || type == bgp_show_type_flap_filter_list
6357 || type == bgp_show_type_flap_prefix_list
6358 || type == bgp_show_type_flap_prefix_longer
6359 || type == bgp_show_type_flap_route_map
6360 || type == bgp_show_type_flap_neighbor)
6361 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6362 else
6363 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006364 header = 0;
6365 }
6366
6367 if (type == bgp_show_type_dampend_paths
6368 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006369 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006370 else if (type == bgp_show_type_flap_statistics
6371 || type == bgp_show_type_flap_address
6372 || type == bgp_show_type_flap_prefix
6373 || type == bgp_show_type_flap_cidr_only
6374 || type == bgp_show_type_flap_regexp
6375 || type == bgp_show_type_flap_filter_list
6376 || type == bgp_show_type_flap_prefix_list
6377 || type == bgp_show_type_flap_prefix_longer
6378 || type == bgp_show_type_flap_route_map
6379 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006380 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006381 else
ajs5a646652004-11-05 01:25:55 +00006382 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006383 display++;
6384 }
6385 if (display)
ajs5a646652004-11-05 01:25:55 +00006386 output_count++;
paul718e3742002-12-13 20:15:29 +00006387 }
6388
6389 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006390 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006391 {
6392 if (type == bgp_show_type_normal)
6393 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6394 }
6395 else
6396 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006397 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006398
6399 return CMD_SUCCESS;
6400}
6401
ajs5a646652004-11-05 01:25:55 +00006402static int
paulfee0f4c2004-09-13 05:12:46 +00006403bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006404 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006405{
6406 struct bgp_table *table;
6407
6408 if (bgp == NULL) {
6409 bgp = bgp_get_default ();
6410 }
6411
6412 if (bgp == NULL)
6413 {
6414 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6415 return CMD_WARNING;
6416 }
6417
6418
6419 table = bgp->rib[afi][safi];
6420
ajs5a646652004-11-05 01:25:55 +00006421 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006422}
6423
paul718e3742002-12-13 20:15:29 +00006424/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006425static void
paul718e3742002-12-13 20:15:29 +00006426route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6427 struct bgp_node *rn,
6428 struct prefix_rd *prd, afi_t afi, safi_t safi)
6429{
6430 struct bgp_info *ri;
6431 struct prefix *p;
6432 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006433 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006434 char buf1[INET6_ADDRSTRLEN];
6435 char buf2[INET6_ADDRSTRLEN];
6436 int count = 0;
6437 int best = 0;
6438 int suppress = 0;
6439 int no_export = 0;
6440 int no_advertise = 0;
6441 int local_as = 0;
6442 int first = 0;
6443
6444 p = &rn->p;
6445 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6446 (safi == SAFI_MPLS_VPN ?
6447 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6448 safi == SAFI_MPLS_VPN ? ":" : "",
6449 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6450 p->prefixlen, VTY_NEWLINE);
6451
6452 for (ri = rn->info; ri; ri = ri->next)
6453 {
6454 count++;
6455 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6456 {
6457 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006458 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006459 suppress = 1;
6460 if (ri->attr->community != NULL)
6461 {
6462 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6463 no_advertise = 1;
6464 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6465 no_export = 1;
6466 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6467 local_as = 1;
6468 }
6469 }
6470 }
6471
6472 vty_out (vty, "Paths: (%d available", count);
6473 if (best)
6474 {
6475 vty_out (vty, ", best #%d", best);
6476 if (safi == SAFI_UNICAST)
6477 vty_out (vty, ", table Default-IP-Routing-Table");
6478 }
6479 else
6480 vty_out (vty, ", no best path");
6481 if (no_advertise)
6482 vty_out (vty, ", not advertised to any peer");
6483 else if (no_export)
6484 vty_out (vty, ", not advertised to EBGP peer");
6485 else if (local_as)
6486 vty_out (vty, ", not advertised outside local AS");
6487 if (suppress)
6488 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6489 vty_out (vty, ")%s", VTY_NEWLINE);
6490
6491 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006492 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006493 {
6494 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6495 {
6496 if (! first)
6497 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6498 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6499 first = 1;
6500 }
6501 }
6502 if (! first)
6503 vty_out (vty, " Not advertised to any peer");
6504 vty_out (vty, "%s", VTY_NEWLINE);
6505}
6506
6507/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006508static int
paulfee0f4c2004-09-13 05:12:46 +00006509bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006510 struct bgp_table *rib, const char *ip_str,
6511 afi_t afi, safi_t safi, struct prefix_rd *prd,
6512 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006513{
6514 int ret;
6515 int header;
6516 int display = 0;
6517 struct prefix match;
6518 struct bgp_node *rn;
6519 struct bgp_node *rm;
6520 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006521 struct bgp_table *table;
6522
paul718e3742002-12-13 20:15:29 +00006523 /* Check IP address argument. */
6524 ret = str2prefix (ip_str, &match);
6525 if (! ret)
6526 {
6527 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6528 return CMD_WARNING;
6529 }
6530
6531 match.family = afi2family (afi);
6532
6533 if (safi == SAFI_MPLS_VPN)
6534 {
paulfee0f4c2004-09-13 05:12:46 +00006535 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006536 {
6537 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6538 continue;
6539
6540 if ((table = rn->info) != NULL)
6541 {
6542 header = 1;
6543
6544 if ((rm = bgp_node_match (table, &match)) != NULL)
6545 {
6546 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006547 {
6548 bgp_unlock_node (rm);
6549 continue;
6550 }
paul718e3742002-12-13 20:15:29 +00006551
6552 for (ri = rm->info; ri; ri = ri->next)
6553 {
6554 if (header)
6555 {
6556 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6557 AFI_IP, SAFI_MPLS_VPN);
6558
6559 header = 0;
6560 }
6561 display++;
6562 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6563 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006564
6565 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006566 }
6567 }
6568 }
6569 }
6570 else
6571 {
6572 header = 1;
6573
paulfee0f4c2004-09-13 05:12:46 +00006574 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006575 {
6576 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6577 {
6578 for (ri = rn->info; ri; ri = ri->next)
6579 {
6580 if (header)
6581 {
6582 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6583 header = 0;
6584 }
6585 display++;
6586 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6587 }
6588 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006589
6590 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006591 }
6592 }
6593
6594 if (! display)
6595 {
6596 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6597 return CMD_WARNING;
6598 }
6599
6600 return CMD_SUCCESS;
6601}
6602
paulfee0f4c2004-09-13 05:12:46 +00006603/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006604static int
paulfd79ac92004-10-13 05:06:08 +00006605bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006606 afi_t afi, safi_t safi, struct prefix_rd *prd,
6607 int prefix_check)
6608{
6609 struct bgp *bgp;
6610
6611 /* BGP structure lookup. */
6612 if (view_name)
6613 {
6614 bgp = bgp_lookup_by_name (view_name);
6615 if (bgp == NULL)
6616 {
6617 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6618 return CMD_WARNING;
6619 }
6620 }
6621 else
6622 {
6623 bgp = bgp_get_default ();
6624 if (bgp == NULL)
6625 {
6626 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6627 return CMD_WARNING;
6628 }
6629 }
6630
6631 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6632 afi, safi, prd, prefix_check);
6633}
6634
paul718e3742002-12-13 20:15:29 +00006635/* BGP route print out function. */
6636DEFUN (show_ip_bgp,
6637 show_ip_bgp_cmd,
6638 "show ip bgp",
6639 SHOW_STR
6640 IP_STR
6641 BGP_STR)
6642{
ajs5a646652004-11-05 01:25:55 +00006643 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006644}
6645
6646DEFUN (show_ip_bgp_ipv4,
6647 show_ip_bgp_ipv4_cmd,
6648 "show ip bgp ipv4 (unicast|multicast)",
6649 SHOW_STR
6650 IP_STR
6651 BGP_STR
6652 "Address family\n"
6653 "Address Family modifier\n"
6654 "Address Family modifier\n")
6655{
6656 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006657 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6658 NULL);
paul718e3742002-12-13 20:15:29 +00006659
ajs5a646652004-11-05 01:25:55 +00006660 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006661}
6662
Michael Lambert95cbbd22010-07-23 14:43:04 -04006663ALIAS (show_ip_bgp_ipv4,
6664 show_bgp_ipv4_safi_cmd,
6665 "show bgp ipv4 (unicast|multicast)",
6666 SHOW_STR
6667 BGP_STR
6668 "Address family\n"
6669 "Address Family modifier\n"
6670 "Address Family modifier\n")
6671
paul718e3742002-12-13 20:15:29 +00006672DEFUN (show_ip_bgp_route,
6673 show_ip_bgp_route_cmd,
6674 "show ip bgp A.B.C.D",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR
6678 "Network in the BGP routing table to display\n")
6679{
6680 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6681}
6682
6683DEFUN (show_ip_bgp_ipv4_route,
6684 show_ip_bgp_ipv4_route_cmd,
6685 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6686 SHOW_STR
6687 IP_STR
6688 BGP_STR
6689 "Address family\n"
6690 "Address Family modifier\n"
6691 "Address Family modifier\n"
6692 "Network in the BGP routing table to display\n")
6693{
6694 if (strncmp (argv[0], "m", 1) == 0)
6695 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6696
6697 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6698}
6699
Michael Lambert95cbbd22010-07-23 14:43:04 -04006700ALIAS (show_ip_bgp_ipv4_route,
6701 show_bgp_ipv4_safi_route_cmd,
6702 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6703 SHOW_STR
6704 BGP_STR
6705 "Address family\n"
6706 "Address Family modifier\n"
6707 "Address Family modifier\n"
6708 "Network in the BGP routing table to display\n")
6709
paul718e3742002-12-13 20:15:29 +00006710DEFUN (show_ip_bgp_vpnv4_all_route,
6711 show_ip_bgp_vpnv4_all_route_cmd,
6712 "show ip bgp vpnv4 all A.B.C.D",
6713 SHOW_STR
6714 IP_STR
6715 BGP_STR
6716 "Display VPNv4 NLRI specific information\n"
6717 "Display information about all VPNv4 NLRIs\n"
6718 "Network in the BGP routing table to display\n")
6719{
6720 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6721}
6722
6723DEFUN (show_ip_bgp_vpnv4_rd_route,
6724 show_ip_bgp_vpnv4_rd_route_cmd,
6725 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6726 SHOW_STR
6727 IP_STR
6728 BGP_STR
6729 "Display VPNv4 NLRI specific information\n"
6730 "Display information for a route distinguisher\n"
6731 "VPN Route Distinguisher\n"
6732 "Network in the BGP routing table to display\n")
6733{
6734 int ret;
6735 struct prefix_rd prd;
6736
6737 ret = str2prefix_rd (argv[0], &prd);
6738 if (! ret)
6739 {
6740 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6741 return CMD_WARNING;
6742 }
6743 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6744}
6745
6746DEFUN (show_ip_bgp_prefix,
6747 show_ip_bgp_prefix_cmd,
6748 "show ip bgp A.B.C.D/M",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR
6752 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6753{
6754 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6755}
6756
6757DEFUN (show_ip_bgp_ipv4_prefix,
6758 show_ip_bgp_ipv4_prefix_cmd,
6759 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6760 SHOW_STR
6761 IP_STR
6762 BGP_STR
6763 "Address family\n"
6764 "Address Family modifier\n"
6765 "Address Family modifier\n"
6766 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6767{
6768 if (strncmp (argv[0], "m", 1) == 0)
6769 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6770
6771 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6772}
6773
Michael Lambert95cbbd22010-07-23 14:43:04 -04006774ALIAS (show_ip_bgp_ipv4_prefix,
6775 show_bgp_ipv4_safi_prefix_cmd,
6776 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6777 SHOW_STR
6778 BGP_STR
6779 "Address family\n"
6780 "Address Family modifier\n"
6781 "Address Family modifier\n"
6782 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6783
paul718e3742002-12-13 20:15:29 +00006784DEFUN (show_ip_bgp_vpnv4_all_prefix,
6785 show_ip_bgp_vpnv4_all_prefix_cmd,
6786 "show ip bgp vpnv4 all A.B.C.D/M",
6787 SHOW_STR
6788 IP_STR
6789 BGP_STR
6790 "Display VPNv4 NLRI specific information\n"
6791 "Display information about all VPNv4 NLRIs\n"
6792 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6793{
6794 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6795}
6796
6797DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6798 show_ip_bgp_vpnv4_rd_prefix_cmd,
6799 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6800 SHOW_STR
6801 IP_STR
6802 BGP_STR
6803 "Display VPNv4 NLRI specific information\n"
6804 "Display information for a route distinguisher\n"
6805 "VPN Route Distinguisher\n"
6806 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6807{
6808 int ret;
6809 struct prefix_rd prd;
6810
6811 ret = str2prefix_rd (argv[0], &prd);
6812 if (! ret)
6813 {
6814 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6815 return CMD_WARNING;
6816 }
6817 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6818}
6819
6820DEFUN (show_ip_bgp_view,
6821 show_ip_bgp_view_cmd,
6822 "show ip bgp view WORD",
6823 SHOW_STR
6824 IP_STR
6825 BGP_STR
6826 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006827 "View name\n")
paul718e3742002-12-13 20:15:29 +00006828{
paulbb46e942003-10-24 19:02:03 +00006829 struct bgp *bgp;
6830
6831 /* BGP structure lookup. */
6832 bgp = bgp_lookup_by_name (argv[0]);
6833 if (bgp == NULL)
6834 {
6835 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6836 return CMD_WARNING;
6837 }
6838
ajs5a646652004-11-05 01:25:55 +00006839 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006840}
6841
6842DEFUN (show_ip_bgp_view_route,
6843 show_ip_bgp_view_route_cmd,
6844 "show ip bgp view WORD A.B.C.D",
6845 SHOW_STR
6846 IP_STR
6847 BGP_STR
6848 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006849 "View name\n"
paul718e3742002-12-13 20:15:29 +00006850 "Network in the BGP routing table to display\n")
6851{
6852 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6853}
6854
6855DEFUN (show_ip_bgp_view_prefix,
6856 show_ip_bgp_view_prefix_cmd,
6857 "show ip bgp view WORD A.B.C.D/M",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR
6861 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006862 "View name\n"
paul718e3742002-12-13 20:15:29 +00006863 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6864{
6865 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6866}
6867
6868#ifdef HAVE_IPV6
6869DEFUN (show_bgp,
6870 show_bgp_cmd,
6871 "show bgp",
6872 SHOW_STR
6873 BGP_STR)
6874{
ajs5a646652004-11-05 01:25:55 +00006875 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6876 NULL);
paul718e3742002-12-13 20:15:29 +00006877}
6878
6879ALIAS (show_bgp,
6880 show_bgp_ipv6_cmd,
6881 "show bgp ipv6",
6882 SHOW_STR
6883 BGP_STR
6884 "Address family\n")
6885
Michael Lambert95cbbd22010-07-23 14:43:04 -04006886DEFUN (show_bgp_ipv6_safi,
6887 show_bgp_ipv6_safi_cmd,
6888 "show bgp ipv6 (unicast|multicast)",
6889 SHOW_STR
6890 BGP_STR
6891 "Address family\n"
6892 "Address Family modifier\n"
6893 "Address Family modifier\n")
6894{
6895 if (strncmp (argv[0], "m", 1) == 0)
6896 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6897 NULL);
6898
6899 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6900}
6901
paul718e3742002-12-13 20:15:29 +00006902/* old command */
6903DEFUN (show_ipv6_bgp,
6904 show_ipv6_bgp_cmd,
6905 "show ipv6 bgp",
6906 SHOW_STR
6907 IP_STR
6908 BGP_STR)
6909{
ajs5a646652004-11-05 01:25:55 +00006910 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6911 NULL);
paul718e3742002-12-13 20:15:29 +00006912}
6913
6914DEFUN (show_bgp_route,
6915 show_bgp_route_cmd,
6916 "show bgp X:X::X:X",
6917 SHOW_STR
6918 BGP_STR
6919 "Network in the BGP routing table to display\n")
6920{
6921 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6922}
6923
6924ALIAS (show_bgp_route,
6925 show_bgp_ipv6_route_cmd,
6926 "show bgp ipv6 X:X::X:X",
6927 SHOW_STR
6928 BGP_STR
6929 "Address family\n"
6930 "Network in the BGP routing table to display\n")
6931
Michael Lambert95cbbd22010-07-23 14:43:04 -04006932DEFUN (show_bgp_ipv6_safi_route,
6933 show_bgp_ipv6_safi_route_cmd,
6934 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6935 SHOW_STR
6936 BGP_STR
6937 "Address family\n"
6938 "Address Family modifier\n"
6939 "Address Family modifier\n"
6940 "Network in the BGP routing table to display\n")
6941{
6942 if (strncmp (argv[0], "m", 1) == 0)
6943 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6944
6945 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6946}
6947
paul718e3742002-12-13 20:15:29 +00006948/* old command */
6949DEFUN (show_ipv6_bgp_route,
6950 show_ipv6_bgp_route_cmd,
6951 "show ipv6 bgp X:X::X:X",
6952 SHOW_STR
6953 IP_STR
6954 BGP_STR
6955 "Network in the BGP routing table to display\n")
6956{
6957 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6958}
6959
6960DEFUN (show_bgp_prefix,
6961 show_bgp_prefix_cmd,
6962 "show bgp X:X::X:X/M",
6963 SHOW_STR
6964 BGP_STR
6965 "IPv6 prefix <network>/<length>\n")
6966{
6967 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6968}
6969
6970ALIAS (show_bgp_prefix,
6971 show_bgp_ipv6_prefix_cmd,
6972 "show bgp ipv6 X:X::X:X/M",
6973 SHOW_STR
6974 BGP_STR
6975 "Address family\n"
6976 "IPv6 prefix <network>/<length>\n")
6977
Michael Lambert95cbbd22010-07-23 14:43:04 -04006978DEFUN (show_bgp_ipv6_safi_prefix,
6979 show_bgp_ipv6_safi_prefix_cmd,
6980 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6981 SHOW_STR
6982 BGP_STR
6983 "Address family\n"
6984 "Address Family modifier\n"
6985 "Address Family modifier\n"
6986 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6987{
6988 if (strncmp (argv[0], "m", 1) == 0)
6989 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6990
6991 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6992}
6993
paul718e3742002-12-13 20:15:29 +00006994/* old command */
6995DEFUN (show_ipv6_bgp_prefix,
6996 show_ipv6_bgp_prefix_cmd,
6997 "show ipv6 bgp X:X::X:X/M",
6998 SHOW_STR
6999 IP_STR
7000 BGP_STR
7001 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7002{
7003 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7004}
7005
paulbb46e942003-10-24 19:02:03 +00007006DEFUN (show_bgp_view,
7007 show_bgp_view_cmd,
7008 "show bgp view WORD",
7009 SHOW_STR
7010 BGP_STR
7011 "BGP view\n"
7012 "View name\n")
7013{
7014 struct bgp *bgp;
7015
7016 /* BGP structure lookup. */
7017 bgp = bgp_lookup_by_name (argv[0]);
7018 if (bgp == NULL)
7019 {
7020 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7021 return CMD_WARNING;
7022 }
7023
ajs5a646652004-11-05 01:25:55 +00007024 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007025}
7026
7027ALIAS (show_bgp_view,
7028 show_bgp_view_ipv6_cmd,
7029 "show bgp view WORD ipv6",
7030 SHOW_STR
7031 BGP_STR
7032 "BGP view\n"
7033 "View name\n"
7034 "Address family\n")
7035
7036DEFUN (show_bgp_view_route,
7037 show_bgp_view_route_cmd,
7038 "show bgp view WORD X:X::X:X",
7039 SHOW_STR
7040 BGP_STR
7041 "BGP view\n"
7042 "View name\n"
7043 "Network in the BGP routing table to display\n")
7044{
7045 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7046}
7047
7048ALIAS (show_bgp_view_route,
7049 show_bgp_view_ipv6_route_cmd,
7050 "show bgp view WORD ipv6 X:X::X:X",
7051 SHOW_STR
7052 BGP_STR
7053 "BGP view\n"
7054 "View name\n"
7055 "Address family\n"
7056 "Network in the BGP routing table to display\n")
7057
7058DEFUN (show_bgp_view_prefix,
7059 show_bgp_view_prefix_cmd,
7060 "show bgp view WORD X:X::X:X/M",
7061 SHOW_STR
7062 BGP_STR
7063 "BGP view\n"
7064 "View name\n"
7065 "IPv6 prefix <network>/<length>\n")
7066{
7067 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7068}
7069
7070ALIAS (show_bgp_view_prefix,
7071 show_bgp_view_ipv6_prefix_cmd,
7072 "show bgp view WORD ipv6 X:X::X:X/M",
7073 SHOW_STR
7074 BGP_STR
7075 "BGP view\n"
7076 "View name\n"
7077 "Address family\n"
7078 "IPv6 prefix <network>/<length>\n")
7079
paul718e3742002-12-13 20:15:29 +00007080/* old command */
7081DEFUN (show_ipv6_mbgp,
7082 show_ipv6_mbgp_cmd,
7083 "show ipv6 mbgp",
7084 SHOW_STR
7085 IP_STR
7086 MBGP_STR)
7087{
ajs5a646652004-11-05 01:25:55 +00007088 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7089 NULL);
paul718e3742002-12-13 20:15:29 +00007090}
7091
7092/* old command */
7093DEFUN (show_ipv6_mbgp_route,
7094 show_ipv6_mbgp_route_cmd,
7095 "show ipv6 mbgp X:X::X:X",
7096 SHOW_STR
7097 IP_STR
7098 MBGP_STR
7099 "Network in the MBGP routing table to display\n")
7100{
7101 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7102}
7103
7104/* old command */
7105DEFUN (show_ipv6_mbgp_prefix,
7106 show_ipv6_mbgp_prefix_cmd,
7107 "show ipv6 mbgp X:X::X:X/M",
7108 SHOW_STR
7109 IP_STR
7110 MBGP_STR
7111 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7112{
7113 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7114}
7115#endif
7116
paul718e3742002-12-13 20:15:29 +00007117
paul94f2b392005-06-28 12:44:16 +00007118static int
paulfd79ac92004-10-13 05:06:08 +00007119bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007120 safi_t safi, enum bgp_show_type type)
7121{
7122 int i;
7123 struct buffer *b;
7124 char *regstr;
7125 int first;
7126 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007127 int rc;
paul718e3742002-12-13 20:15:29 +00007128
7129 first = 0;
7130 b = buffer_new (1024);
7131 for (i = 0; i < argc; i++)
7132 {
7133 if (first)
7134 buffer_putc (b, ' ');
7135 else
7136 {
7137 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7138 continue;
7139 first = 1;
7140 }
7141
7142 buffer_putstr (b, argv[i]);
7143 }
7144 buffer_putc (b, '\0');
7145
7146 regstr = buffer_getstr (b);
7147 buffer_free (b);
7148
7149 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007150 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007151 if (! regex)
7152 {
7153 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7154 VTY_NEWLINE);
7155 return CMD_WARNING;
7156 }
7157
ajs5a646652004-11-05 01:25:55 +00007158 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7159 bgp_regex_free (regex);
7160 return rc;
paul718e3742002-12-13 20:15:29 +00007161}
7162
7163DEFUN (show_ip_bgp_regexp,
7164 show_ip_bgp_regexp_cmd,
7165 "show ip bgp regexp .LINE",
7166 SHOW_STR
7167 IP_STR
7168 BGP_STR
7169 "Display routes matching the AS path regular expression\n"
7170 "A regular-expression to match the BGP AS paths\n")
7171{
7172 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7173 bgp_show_type_regexp);
7174}
7175
7176DEFUN (show_ip_bgp_flap_regexp,
7177 show_ip_bgp_flap_regexp_cmd,
7178 "show ip bgp flap-statistics regexp .LINE",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Display flap statistics of routes\n"
7183 "Display routes matching the AS path regular expression\n"
7184 "A regular-expression to match the BGP AS paths\n")
7185{
7186 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7187 bgp_show_type_flap_regexp);
7188}
7189
7190DEFUN (show_ip_bgp_ipv4_regexp,
7191 show_ip_bgp_ipv4_regexp_cmd,
7192 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7193 SHOW_STR
7194 IP_STR
7195 BGP_STR
7196 "Address family\n"
7197 "Address Family modifier\n"
7198 "Address Family modifier\n"
7199 "Display routes matching the AS path regular expression\n"
7200 "A regular-expression to match the BGP AS paths\n")
7201{
7202 if (strncmp (argv[0], "m", 1) == 0)
7203 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7204 bgp_show_type_regexp);
7205
7206 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7207 bgp_show_type_regexp);
7208}
7209
7210#ifdef HAVE_IPV6
7211DEFUN (show_bgp_regexp,
7212 show_bgp_regexp_cmd,
7213 "show bgp regexp .LINE",
7214 SHOW_STR
7215 BGP_STR
7216 "Display routes matching the AS path regular expression\n"
7217 "A regular-expression to match the BGP AS paths\n")
7218{
7219 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7220 bgp_show_type_regexp);
7221}
7222
7223ALIAS (show_bgp_regexp,
7224 show_bgp_ipv6_regexp_cmd,
7225 "show bgp ipv6 regexp .LINE",
7226 SHOW_STR
7227 BGP_STR
7228 "Address family\n"
7229 "Display routes matching the AS path regular expression\n"
7230 "A regular-expression to match the BGP AS paths\n")
7231
7232/* old command */
7233DEFUN (show_ipv6_bgp_regexp,
7234 show_ipv6_bgp_regexp_cmd,
7235 "show ipv6 bgp regexp .LINE",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display routes matching the AS path regular expression\n"
7240 "A regular-expression to match the BGP AS paths\n")
7241{
7242 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7243 bgp_show_type_regexp);
7244}
7245
7246/* old command */
7247DEFUN (show_ipv6_mbgp_regexp,
7248 show_ipv6_mbgp_regexp_cmd,
7249 "show ipv6 mbgp regexp .LINE",
7250 SHOW_STR
7251 IP_STR
7252 BGP_STR
7253 "Display routes matching the AS path regular expression\n"
7254 "A regular-expression to match the MBGP AS paths\n")
7255{
7256 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7257 bgp_show_type_regexp);
7258}
7259#endif /* HAVE_IPV6 */
7260
paul94f2b392005-06-28 12:44:16 +00007261static int
paulfd79ac92004-10-13 05:06:08 +00007262bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007263 safi_t safi, enum bgp_show_type type)
7264{
7265 struct prefix_list *plist;
7266
7267 plist = prefix_list_lookup (afi, prefix_list_str);
7268 if (plist == NULL)
7269 {
7270 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7271 prefix_list_str, VTY_NEWLINE);
7272 return CMD_WARNING;
7273 }
7274
ajs5a646652004-11-05 01:25:55 +00007275 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007276}
7277
7278DEFUN (show_ip_bgp_prefix_list,
7279 show_ip_bgp_prefix_list_cmd,
7280 "show ip bgp prefix-list WORD",
7281 SHOW_STR
7282 IP_STR
7283 BGP_STR
7284 "Display routes conforming to the prefix-list\n"
7285 "IP prefix-list name\n")
7286{
7287 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7288 bgp_show_type_prefix_list);
7289}
7290
7291DEFUN (show_ip_bgp_flap_prefix_list,
7292 show_ip_bgp_flap_prefix_list_cmd,
7293 "show ip bgp flap-statistics prefix-list WORD",
7294 SHOW_STR
7295 IP_STR
7296 BGP_STR
7297 "Display flap statistics of routes\n"
7298 "Display routes conforming to the prefix-list\n"
7299 "IP prefix-list name\n")
7300{
7301 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7302 bgp_show_type_flap_prefix_list);
7303}
7304
7305DEFUN (show_ip_bgp_ipv4_prefix_list,
7306 show_ip_bgp_ipv4_prefix_list_cmd,
7307 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7308 SHOW_STR
7309 IP_STR
7310 BGP_STR
7311 "Address family\n"
7312 "Address Family modifier\n"
7313 "Address Family modifier\n"
7314 "Display routes conforming to the prefix-list\n"
7315 "IP prefix-list name\n")
7316{
7317 if (strncmp (argv[0], "m", 1) == 0)
7318 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7319 bgp_show_type_prefix_list);
7320
7321 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7322 bgp_show_type_prefix_list);
7323}
7324
7325#ifdef HAVE_IPV6
7326DEFUN (show_bgp_prefix_list,
7327 show_bgp_prefix_list_cmd,
7328 "show bgp prefix-list WORD",
7329 SHOW_STR
7330 BGP_STR
7331 "Display routes conforming to the prefix-list\n"
7332 "IPv6 prefix-list name\n")
7333{
7334 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7335 bgp_show_type_prefix_list);
7336}
7337
7338ALIAS (show_bgp_prefix_list,
7339 show_bgp_ipv6_prefix_list_cmd,
7340 "show bgp ipv6 prefix-list WORD",
7341 SHOW_STR
7342 BGP_STR
7343 "Address family\n"
7344 "Display routes conforming to the prefix-list\n"
7345 "IPv6 prefix-list name\n")
7346
7347/* old command */
7348DEFUN (show_ipv6_bgp_prefix_list,
7349 show_ipv6_bgp_prefix_list_cmd,
7350 "show ipv6 bgp prefix-list WORD",
7351 SHOW_STR
7352 IPV6_STR
7353 BGP_STR
7354 "Display routes matching the prefix-list\n"
7355 "IPv6 prefix-list name\n")
7356{
7357 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7358 bgp_show_type_prefix_list);
7359}
7360
7361/* old command */
7362DEFUN (show_ipv6_mbgp_prefix_list,
7363 show_ipv6_mbgp_prefix_list_cmd,
7364 "show ipv6 mbgp prefix-list WORD",
7365 SHOW_STR
7366 IPV6_STR
7367 MBGP_STR
7368 "Display routes matching the prefix-list\n"
7369 "IPv6 prefix-list name\n")
7370{
7371 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7372 bgp_show_type_prefix_list);
7373}
7374#endif /* HAVE_IPV6 */
7375
paul94f2b392005-06-28 12:44:16 +00007376static int
paulfd79ac92004-10-13 05:06:08 +00007377bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007378 safi_t safi, enum bgp_show_type type)
7379{
7380 struct as_list *as_list;
7381
7382 as_list = as_list_lookup (filter);
7383 if (as_list == NULL)
7384 {
7385 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7386 return CMD_WARNING;
7387 }
7388
ajs5a646652004-11-05 01:25:55 +00007389 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007390}
7391
7392DEFUN (show_ip_bgp_filter_list,
7393 show_ip_bgp_filter_list_cmd,
7394 "show ip bgp filter-list WORD",
7395 SHOW_STR
7396 IP_STR
7397 BGP_STR
7398 "Display routes conforming to the filter-list\n"
7399 "Regular expression access list name\n")
7400{
7401 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7402 bgp_show_type_filter_list);
7403}
7404
7405DEFUN (show_ip_bgp_flap_filter_list,
7406 show_ip_bgp_flap_filter_list_cmd,
7407 "show ip bgp flap-statistics filter-list WORD",
7408 SHOW_STR
7409 IP_STR
7410 BGP_STR
7411 "Display flap statistics of routes\n"
7412 "Display routes conforming to the filter-list\n"
7413 "Regular expression access list name\n")
7414{
7415 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7416 bgp_show_type_flap_filter_list);
7417}
7418
7419DEFUN (show_ip_bgp_ipv4_filter_list,
7420 show_ip_bgp_ipv4_filter_list_cmd,
7421 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7422 SHOW_STR
7423 IP_STR
7424 BGP_STR
7425 "Address family\n"
7426 "Address Family modifier\n"
7427 "Address Family modifier\n"
7428 "Display routes conforming to the filter-list\n"
7429 "Regular expression access list name\n")
7430{
7431 if (strncmp (argv[0], "m", 1) == 0)
7432 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7433 bgp_show_type_filter_list);
7434
7435 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7436 bgp_show_type_filter_list);
7437}
7438
7439#ifdef HAVE_IPV6
7440DEFUN (show_bgp_filter_list,
7441 show_bgp_filter_list_cmd,
7442 "show bgp filter-list WORD",
7443 SHOW_STR
7444 BGP_STR
7445 "Display routes conforming to the filter-list\n"
7446 "Regular expression access list name\n")
7447{
7448 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7449 bgp_show_type_filter_list);
7450}
7451
7452ALIAS (show_bgp_filter_list,
7453 show_bgp_ipv6_filter_list_cmd,
7454 "show bgp ipv6 filter-list WORD",
7455 SHOW_STR
7456 BGP_STR
7457 "Address family\n"
7458 "Display routes conforming to the filter-list\n"
7459 "Regular expression access list name\n")
7460
7461/* old command */
7462DEFUN (show_ipv6_bgp_filter_list,
7463 show_ipv6_bgp_filter_list_cmd,
7464 "show ipv6 bgp filter-list WORD",
7465 SHOW_STR
7466 IPV6_STR
7467 BGP_STR
7468 "Display routes conforming to the filter-list\n"
7469 "Regular expression access list name\n")
7470{
7471 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7472 bgp_show_type_filter_list);
7473}
7474
7475/* old command */
7476DEFUN (show_ipv6_mbgp_filter_list,
7477 show_ipv6_mbgp_filter_list_cmd,
7478 "show ipv6 mbgp filter-list WORD",
7479 SHOW_STR
7480 IPV6_STR
7481 MBGP_STR
7482 "Display routes conforming to the filter-list\n"
7483 "Regular expression access list name\n")
7484{
7485 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7486 bgp_show_type_filter_list);
7487}
7488#endif /* HAVE_IPV6 */
7489
paul94f2b392005-06-28 12:44:16 +00007490static int
paulfd79ac92004-10-13 05:06:08 +00007491bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007492 safi_t safi, enum bgp_show_type type)
7493{
7494 struct route_map *rmap;
7495
7496 rmap = route_map_lookup_by_name (rmap_str);
7497 if (! rmap)
7498 {
7499 vty_out (vty, "%% %s is not a valid route-map name%s",
7500 rmap_str, VTY_NEWLINE);
7501 return CMD_WARNING;
7502 }
7503
ajs5a646652004-11-05 01:25:55 +00007504 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007505}
7506
7507DEFUN (show_ip_bgp_route_map,
7508 show_ip_bgp_route_map_cmd,
7509 "show ip bgp route-map WORD",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Display routes matching the route-map\n"
7514 "A route-map to match on\n")
7515{
7516 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7517 bgp_show_type_route_map);
7518}
7519
7520DEFUN (show_ip_bgp_flap_route_map,
7521 show_ip_bgp_flap_route_map_cmd,
7522 "show ip bgp flap-statistics route-map WORD",
7523 SHOW_STR
7524 IP_STR
7525 BGP_STR
7526 "Display flap statistics of routes\n"
7527 "Display routes matching the route-map\n"
7528 "A route-map to match on\n")
7529{
7530 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7531 bgp_show_type_flap_route_map);
7532}
7533
7534DEFUN (show_ip_bgp_ipv4_route_map,
7535 show_ip_bgp_ipv4_route_map_cmd,
7536 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7537 SHOW_STR
7538 IP_STR
7539 BGP_STR
7540 "Address family\n"
7541 "Address Family modifier\n"
7542 "Address Family modifier\n"
7543 "Display routes matching the route-map\n"
7544 "A route-map to match on\n")
7545{
7546 if (strncmp (argv[0], "m", 1) == 0)
7547 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7548 bgp_show_type_route_map);
7549
7550 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7551 bgp_show_type_route_map);
7552}
7553
7554DEFUN (show_bgp_route_map,
7555 show_bgp_route_map_cmd,
7556 "show bgp route-map WORD",
7557 SHOW_STR
7558 BGP_STR
7559 "Display routes matching the route-map\n"
7560 "A route-map to match on\n")
7561{
7562 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7563 bgp_show_type_route_map);
7564}
7565
7566ALIAS (show_bgp_route_map,
7567 show_bgp_ipv6_route_map_cmd,
7568 "show bgp ipv6 route-map WORD",
7569 SHOW_STR
7570 BGP_STR
7571 "Address family\n"
7572 "Display routes matching the route-map\n"
7573 "A route-map to match on\n")
7574
7575DEFUN (show_ip_bgp_cidr_only,
7576 show_ip_bgp_cidr_only_cmd,
7577 "show ip bgp cidr-only",
7578 SHOW_STR
7579 IP_STR
7580 BGP_STR
7581 "Display only routes with non-natural netmasks\n")
7582{
7583 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007584 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007585}
7586
7587DEFUN (show_ip_bgp_flap_cidr_only,
7588 show_ip_bgp_flap_cidr_only_cmd,
7589 "show ip bgp flap-statistics cidr-only",
7590 SHOW_STR
7591 IP_STR
7592 BGP_STR
7593 "Display flap statistics of routes\n"
7594 "Display only routes with non-natural netmasks\n")
7595{
7596 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007597 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007598}
7599
7600DEFUN (show_ip_bgp_ipv4_cidr_only,
7601 show_ip_bgp_ipv4_cidr_only_cmd,
7602 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7603 SHOW_STR
7604 IP_STR
7605 BGP_STR
7606 "Address family\n"
7607 "Address Family modifier\n"
7608 "Address Family modifier\n"
7609 "Display only routes with non-natural netmasks\n")
7610{
7611 if (strncmp (argv[0], "m", 1) == 0)
7612 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007613 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007614
7615 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007616 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007617}
7618
7619DEFUN (show_ip_bgp_community_all,
7620 show_ip_bgp_community_all_cmd,
7621 "show ip bgp community",
7622 SHOW_STR
7623 IP_STR
7624 BGP_STR
7625 "Display routes matching the communities\n")
7626{
7627 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007628 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007629}
7630
7631DEFUN (show_ip_bgp_ipv4_community_all,
7632 show_ip_bgp_ipv4_community_all_cmd,
7633 "show ip bgp ipv4 (unicast|multicast) community",
7634 SHOW_STR
7635 IP_STR
7636 BGP_STR
7637 "Address family\n"
7638 "Address Family modifier\n"
7639 "Address Family modifier\n"
7640 "Display routes matching the communities\n")
7641{
7642 if (strncmp (argv[0], "m", 1) == 0)
7643 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007644 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007645
7646 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007647 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007648}
7649
7650#ifdef HAVE_IPV6
7651DEFUN (show_bgp_community_all,
7652 show_bgp_community_all_cmd,
7653 "show bgp community",
7654 SHOW_STR
7655 BGP_STR
7656 "Display routes matching the communities\n")
7657{
7658 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007659 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007660}
7661
7662ALIAS (show_bgp_community_all,
7663 show_bgp_ipv6_community_all_cmd,
7664 "show bgp ipv6 community",
7665 SHOW_STR
7666 BGP_STR
7667 "Address family\n"
7668 "Display routes matching the communities\n")
7669
7670/* old command */
7671DEFUN (show_ipv6_bgp_community_all,
7672 show_ipv6_bgp_community_all_cmd,
7673 "show ipv6 bgp community",
7674 SHOW_STR
7675 IPV6_STR
7676 BGP_STR
7677 "Display routes matching the communities\n")
7678{
7679 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007680 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007681}
7682
7683/* old command */
7684DEFUN (show_ipv6_mbgp_community_all,
7685 show_ipv6_mbgp_community_all_cmd,
7686 "show ipv6 mbgp community",
7687 SHOW_STR
7688 IPV6_STR
7689 MBGP_STR
7690 "Display routes matching the communities\n")
7691{
7692 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007693 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007694}
7695#endif /* HAVE_IPV6 */
7696
paul94f2b392005-06-28 12:44:16 +00007697static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007698bgp_show_community (struct vty *vty, const char *view_name, int argc,
7699 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007700{
7701 struct community *com;
7702 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007703 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007704 int i;
7705 char *str;
7706 int first = 0;
7707
Michael Lambert95cbbd22010-07-23 14:43:04 -04007708 /* BGP structure lookup */
7709 if (view_name)
7710 {
7711 bgp = bgp_lookup_by_name (view_name);
7712 if (bgp == NULL)
7713 {
7714 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7715 return CMD_WARNING;
7716 }
7717 }
7718 else
7719 {
7720 bgp = bgp_get_default ();
7721 if (bgp == NULL)
7722 {
7723 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7724 return CMD_WARNING;
7725 }
7726 }
7727
paul718e3742002-12-13 20:15:29 +00007728 b = buffer_new (1024);
7729 for (i = 0; i < argc; i++)
7730 {
7731 if (first)
7732 buffer_putc (b, ' ');
7733 else
7734 {
7735 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7736 continue;
7737 first = 1;
7738 }
7739
7740 buffer_putstr (b, argv[i]);
7741 }
7742 buffer_putc (b, '\0');
7743
7744 str = buffer_getstr (b);
7745 buffer_free (b);
7746
7747 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007748 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007749 if (! com)
7750 {
7751 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7752 return CMD_WARNING;
7753 }
7754
Michael Lambert95cbbd22010-07-23 14:43:04 -04007755 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007756 (exact ? bgp_show_type_community_exact :
7757 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007758}
7759
7760DEFUN (show_ip_bgp_community,
7761 show_ip_bgp_community_cmd,
7762 "show ip bgp community (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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007772 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007773}
7774
7775ALIAS (show_ip_bgp_community,
7776 show_ip_bgp_community2_cmd,
7777 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7778 SHOW_STR
7779 IP_STR
7780 BGP_STR
7781 "Display routes matching the communities\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n")
7790
7791ALIAS (show_ip_bgp_community,
7792 show_ip_bgp_community3_cmd,
7793 "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)",
7794 SHOW_STR
7795 IP_STR
7796 BGP_STR
7797 "Display routes matching the communities\n"
7798 "community number\n"
7799 "Do not send outside local AS (well-known community)\n"
7800 "Do not advertise to any peer (well-known community)\n"
7801 "Do not export to next AS (well-known community)\n"
7802 "community number\n"
7803 "Do not send outside local AS (well-known community)\n"
7804 "Do not advertise to any peer (well-known community)\n"
7805 "Do not export to next AS (well-known community)\n"
7806 "community number\n"
7807 "Do not send outside local AS (well-known community)\n"
7808 "Do not advertise to any peer (well-known community)\n"
7809 "Do not export to next AS (well-known community)\n")
7810
7811ALIAS (show_ip_bgp_community,
7812 show_ip_bgp_community4_cmd,
7813 "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)",
7814 SHOW_STR
7815 IP_STR
7816 BGP_STR
7817 "Display routes matching the communities\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\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
7835DEFUN (show_ip_bgp_ipv4_community,
7836 show_ip_bgp_ipv4_community_cmd,
7837 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7838 SHOW_STR
7839 IP_STR
7840 BGP_STR
7841 "Address family\n"
7842 "Address Family modifier\n"
7843 "Address Family modifier\n"
7844 "Display routes matching the communities\n"
7845 "community number\n"
7846 "Do not send outside local AS (well-known community)\n"
7847 "Do not advertise to any peer (well-known community)\n"
7848 "Do not export to next AS (well-known community)\n")
7849{
7850 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007851 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007852
Michael Lambert95cbbd22010-07-23 14:43:04 -04007853 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007854}
7855
7856ALIAS (show_ip_bgp_ipv4_community,
7857 show_ip_bgp_ipv4_community2_cmd,
7858 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7859 SHOW_STR
7860 IP_STR
7861 BGP_STR
7862 "Address family\n"
7863 "Address Family modifier\n"
7864 "Address Family modifier\n"
7865 "Display routes matching the communities\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n"
7870 "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
7875ALIAS (show_ip_bgp_ipv4_community,
7876 show_ip_bgp_ipv4_community3_cmd,
7877 "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)",
7878 SHOW_STR
7879 IP_STR
7880 BGP_STR
7881 "Address family\n"
7882 "Address Family modifier\n"
7883 "Address Family modifier\n"
7884 "Display routes matching the communities\n"
7885 "community number\n"
7886 "Do not send outside local AS (well-known community)\n"
7887 "Do not advertise to any peer (well-known community)\n"
7888 "Do not export to next AS (well-known community)\n"
7889 "community number\n"
7890 "Do not send outside local AS (well-known community)\n"
7891 "Do not advertise to any peer (well-known community)\n"
7892 "Do not export to next AS (well-known community)\n"
7893 "community number\n"
7894 "Do not send outside local AS (well-known community)\n"
7895 "Do not advertise to any peer (well-known community)\n"
7896 "Do not export to next AS (well-known community)\n")
7897
7898ALIAS (show_ip_bgp_ipv4_community,
7899 show_ip_bgp_ipv4_community4_cmd,
7900 "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)",
7901 SHOW_STR
7902 IP_STR
7903 BGP_STR
7904 "Address family\n"
7905 "Address Family modifier\n"
7906 "Address Family modifier\n"
7907 "Display routes matching the communities\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n"
7912 "community number\n"
7913 "Do not send outside local AS (well-known community)\n"
7914 "Do not advertise to any peer (well-known community)\n"
7915 "Do not export to next AS (well-known community)\n"
7916 "community number\n"
7917 "Do not send outside local AS (well-known community)\n"
7918 "Do not advertise to any peer (well-known community)\n"
7919 "Do not export to next AS (well-known community)\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n")
7924
Michael Lambert95cbbd22010-07-23 14:43:04 -04007925DEFUN (show_bgp_view_afi_safi_community_all,
7926 show_bgp_view_afi_safi_community_all_cmd,
7927#ifdef HAVE_IPV6
7928 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7929#else
7930 "show bgp view WORD ipv4 (unicast|multicast) community",
7931#endif
7932 SHOW_STR
7933 BGP_STR
7934 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007935 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007936 "Address family\n"
7937#ifdef HAVE_IPV6
7938 "Address family\n"
7939#endif
7940 "Address Family modifier\n"
7941 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007942 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007943{
7944 int afi;
7945 int safi;
7946 struct bgp *bgp;
7947
7948 /* BGP structure lookup. */
7949 bgp = bgp_lookup_by_name (argv[0]);
7950 if (bgp == NULL)
7951 {
7952 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7953 return CMD_WARNING;
7954 }
7955
7956#ifdef HAVE_IPV6
7957 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7958 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7959#else
7960 afi = AFI_IP;
7961 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7962#endif
7963 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7964}
7965
7966DEFUN (show_bgp_view_afi_safi_community,
7967 show_bgp_view_afi_safi_community_cmd,
7968#ifdef HAVE_IPV6
7969 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7970#else
7971 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7972#endif
7973 SHOW_STR
7974 BGP_STR
7975 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007976 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007977 "Address family\n"
7978#ifdef HAVE_IPV6
7979 "Address family\n"
7980#endif
7981 "Address family modifier\n"
7982 "Address family modifier\n"
7983 "Display routes matching the communities\n"
7984 "community number\n"
7985 "Do not send outside local AS (well-known community)\n"
7986 "Do not advertise to any peer (well-known community)\n"
7987 "Do not export to next AS (well-known community)\n")
7988{
7989 int afi;
7990 int safi;
7991
7992#ifdef HAVE_IPV6
7993 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7994 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7995 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7996#else
7997 afi = AFI_IP;
7998 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7999 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
8000#endif
8001}
8002
8003ALIAS (show_bgp_view_afi_safi_community,
8004 show_bgp_view_afi_safi_community2_cmd,
8005#ifdef HAVE_IPV6
8006 "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)",
8007#else
8008 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8009#endif
8010 SHOW_STR
8011 BGP_STR
8012 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008013 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008014 "Address family\n"
8015#ifdef HAVE_IPV6
8016 "Address family\n"
8017#endif
8018 "Address family modifier\n"
8019 "Address family modifier\n"
8020 "Display routes matching the communities\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n"
8025 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\n")
8029
8030ALIAS (show_bgp_view_afi_safi_community,
8031 show_bgp_view_afi_safi_community3_cmd,
8032#ifdef HAVE_IPV6
8033 "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)",
8034#else
8035 "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)",
8036#endif
8037 SHOW_STR
8038 BGP_STR
8039 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008040 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "Address family\n"
8042#ifdef HAVE_IPV6
8043 "Address family\n"
8044#endif
8045 "Address family modifier\n"
8046 "Address family modifier\n"
8047 "Display routes matching the communities\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n")
8060
8061ALIAS (show_bgp_view_afi_safi_community,
8062 show_bgp_view_afi_safi_community4_cmd,
8063#ifdef HAVE_IPV6
8064 "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)",
8065#else
8066 "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)",
8067#endif
8068 SHOW_STR
8069 BGP_STR
8070 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008071 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008072 "Address family\n"
8073#ifdef HAVE_IPV6
8074 "Address family\n"
8075#endif
8076 "Address family modifier\n"
8077 "Address family modifier\n"
8078 "Display routes matching the communities\n"
8079 "community number\n"
8080 "Do not send outside local AS (well-known community)\n"
8081 "Do not advertise to any peer (well-known community)\n"
8082 "Do not export to next AS (well-known community)\n"
8083 "community number\n"
8084 "Do not send outside local AS (well-known community)\n"
8085 "Do not advertise to any peer (well-known community)\n"
8086 "Do not export to next AS (well-known community)\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n")
8095
paul718e3742002-12-13 20:15:29 +00008096DEFUN (show_ip_bgp_community_exact,
8097 show_ip_bgp_community_exact_cmd,
8098 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8099 SHOW_STR
8100 IP_STR
8101 BGP_STR
8102 "Display routes matching the communities\n"
8103 "community number\n"
8104 "Do not send outside local AS (well-known community)\n"
8105 "Do not advertise to any peer (well-known community)\n"
8106 "Do not export to next AS (well-known community)\n"
8107 "Exact match of the communities")
8108{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008109 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008110}
8111
8112ALIAS (show_ip_bgp_community_exact,
8113 show_ip_bgp_community2_exact_cmd,
8114 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8115 SHOW_STR
8116 IP_STR
8117 BGP_STR
8118 "Display routes matching the communities\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n"
8123 "community number\n"
8124 "Do not send outside local AS (well-known community)\n"
8125 "Do not advertise to any peer (well-known community)\n"
8126 "Do not export to next AS (well-known community)\n"
8127 "Exact match of the communities")
8128
8129ALIAS (show_ip_bgp_community_exact,
8130 show_ip_bgp_community3_exact_cmd,
8131 "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",
8132 SHOW_STR
8133 IP_STR
8134 BGP_STR
8135 "Display routes matching the communities\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "community number\n"
8141 "Do not send outside local AS (well-known community)\n"
8142 "Do not advertise to any peer (well-known community)\n"
8143 "Do not export to next AS (well-known community)\n"
8144 "community number\n"
8145 "Do not send outside local AS (well-known community)\n"
8146 "Do not advertise to any peer (well-known community)\n"
8147 "Do not export to next AS (well-known community)\n"
8148 "Exact match of the communities")
8149
8150ALIAS (show_ip_bgp_community_exact,
8151 show_ip_bgp_community4_exact_cmd,
8152 "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",
8153 SHOW_STR
8154 IP_STR
8155 BGP_STR
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\n"
8165 "community number\n"
8166 "Do not send outside local AS (well-known community)\n"
8167 "Do not advertise to any peer (well-known community)\n"
8168 "Do not export to next AS (well-known community)\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n"
8173 "Exact match of the communities")
8174
8175DEFUN (show_ip_bgp_ipv4_community_exact,
8176 show_ip_bgp_ipv4_community_exact_cmd,
8177 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8178 SHOW_STR
8179 IP_STR
8180 BGP_STR
8181 "Address family\n"
8182 "Address Family modifier\n"
8183 "Address Family modifier\n"
8184 "Display routes matching the communities\n"
8185 "community number\n"
8186 "Do not send outside local AS (well-known community)\n"
8187 "Do not advertise to any peer (well-known community)\n"
8188 "Do not export to next AS (well-known community)\n"
8189 "Exact match of the communities")
8190{
8191 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008192 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008193
Michael Lambert95cbbd22010-07-23 14:43:04 -04008194 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008195}
8196
8197ALIAS (show_ip_bgp_ipv4_community_exact,
8198 show_ip_bgp_ipv4_community2_exact_cmd,
8199 "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",
8200 SHOW_STR
8201 IP_STR
8202 BGP_STR
8203 "Address family\n"
8204 "Address Family modifier\n"
8205 "Address Family modifier\n"
8206 "Display routes matching the communities\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "community number\n"
8212 "Do not send outside local AS (well-known community)\n"
8213 "Do not advertise to any peer (well-known community)\n"
8214 "Do not export to next AS (well-known community)\n"
8215 "Exact match of the communities")
8216
8217ALIAS (show_ip_bgp_ipv4_community_exact,
8218 show_ip_bgp_ipv4_community3_exact_cmd,
8219 "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",
8220 SHOW_STR
8221 IP_STR
8222 BGP_STR
8223 "Address family\n"
8224 "Address Family modifier\n"
8225 "Address Family modifier\n"
8226 "Display routes matching the communities\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "community number\n"
8232 "Do not send outside local AS (well-known community)\n"
8233 "Do not advertise to any peer (well-known community)\n"
8234 "Do not export to next AS (well-known community)\n"
8235 "community number\n"
8236 "Do not send outside local AS (well-known community)\n"
8237 "Do not advertise to any peer (well-known community)\n"
8238 "Do not export to next AS (well-known community)\n"
8239 "Exact match of the communities")
8240
8241ALIAS (show_ip_bgp_ipv4_community_exact,
8242 show_ip_bgp_ipv4_community4_exact_cmd,
8243 "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",
8244 SHOW_STR
8245 IP_STR
8246 BGP_STR
8247 "Address family\n"
8248 "Address Family modifier\n"
8249 "Address Family modifier\n"
8250 "Display routes matching the communities\n"
8251 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n"
8267 "Exact match of the communities")
8268
8269#ifdef HAVE_IPV6
8270DEFUN (show_bgp_community,
8271 show_bgp_community_cmd,
8272 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8273 SHOW_STR
8274 BGP_STR
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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008281 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008282}
8283
8284ALIAS (show_bgp_community,
8285 show_bgp_ipv6_community_cmd,
8286 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8287 SHOW_STR
8288 BGP_STR
8289 "Address family\n"
8290 "Display routes matching the communities\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_community2_cmd,
8298 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8299 SHOW_STR
8300 BGP_STR
8301 "Display routes matching the communities\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n")
8310
8311ALIAS (show_bgp_community,
8312 show_bgp_ipv6_community2_cmd,
8313 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8314 SHOW_STR
8315 BGP_STR
8316 "Address family\n"
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
8327ALIAS (show_bgp_community,
8328 show_bgp_community3_cmd,
8329 "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)",
8330 SHOW_STR
8331 BGP_STR
8332 "Display routes matching the communities\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n")
8345
8346ALIAS (show_bgp_community,
8347 show_bgp_ipv6_community3_cmd,
8348 "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)",
8349 SHOW_STR
8350 BGP_STR
8351 "Address family\n"
8352 "Display routes matching the communities\n"
8353 "community number\n"
8354 "Do not send outside local AS (well-known community)\n"
8355 "Do not advertise to any peer (well-known community)\n"
8356 "Do not export to next AS (well-known community)\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
8366ALIAS (show_bgp_community,
8367 show_bgp_community4_cmd,
8368 "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)",
8369 SHOW_STR
8370 BGP_STR
8371 "Display routes matching the communities\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "community number\n"
8377 "Do not send outside local AS (well-known community)\n"
8378 "Do not advertise to any peer (well-known community)\n"
8379 "Do not export to next AS (well-known community)\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n")
8388
8389ALIAS (show_bgp_community,
8390 show_bgp_ipv6_community4_cmd,
8391 "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)",
8392 SHOW_STR
8393 BGP_STR
8394 "Address family\n"
8395 "Display routes matching the communities\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n")
8412
8413/* old command */
8414DEFUN (show_ipv6_bgp_community,
8415 show_ipv6_bgp_community_cmd,
8416 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8417 SHOW_STR
8418 IPV6_STR
8419 BGP_STR
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n")
8425{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008426 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008427}
8428
8429/* old command */
8430ALIAS (show_ipv6_bgp_community,
8431 show_ipv6_bgp_community2_cmd,
8432 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8433 SHOW_STR
8434 IPV6_STR
8435 BGP_STR
8436 "Display routes matching the communities\n"
8437 "community number\n"
8438 "Do not send outside local AS (well-known community)\n"
8439 "Do not advertise to any peer (well-known community)\n"
8440 "Do not export to next AS (well-known community)\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n")
8445
8446/* old command */
8447ALIAS (show_ipv6_bgp_community,
8448 show_ipv6_bgp_community3_cmd,
8449 "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)",
8450 SHOW_STR
8451 IPV6_STR
8452 BGP_STR
8453 "Display routes matching the communities\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n")
8466
8467/* old command */
8468ALIAS (show_ipv6_bgp_community,
8469 show_ipv6_bgp_community4_cmd,
8470 "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)",
8471 SHOW_STR
8472 IPV6_STR
8473 BGP_STR
8474 "Display routes matching the communities\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\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 "community number\n"
8488 "Do not send outside local AS (well-known community)\n"
8489 "Do not advertise to any peer (well-known community)\n"
8490 "Do not export to next AS (well-known community)\n")
8491
8492DEFUN (show_bgp_community_exact,
8493 show_bgp_community_exact_cmd,
8494 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8495 SHOW_STR
8496 BGP_STR
8497 "Display routes matching the communities\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "Exact match of the communities")
8503{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008504 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008505}
8506
8507ALIAS (show_bgp_community_exact,
8508 show_bgp_ipv6_community_exact_cmd,
8509 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8510 SHOW_STR
8511 BGP_STR
8512 "Address family\n"
8513 "Display routes matching the communities\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "Exact match of the communities")
8519
8520ALIAS (show_bgp_community_exact,
8521 show_bgp_community2_exact_cmd,
8522 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8523 SHOW_STR
8524 BGP_STR
8525 "Display routes matching the communities\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n"
8534 "Exact match of the communities")
8535
8536ALIAS (show_bgp_community_exact,
8537 show_bgp_ipv6_community2_exact_cmd,
8538 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8539 SHOW_STR
8540 BGP_STR
8541 "Address family\n"
8542 "Display routes matching the communities\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "Exact match of the communities")
8552
8553ALIAS (show_bgp_community_exact,
8554 show_bgp_community3_exact_cmd,
8555 "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",
8556 SHOW_STR
8557 BGP_STR
8558 "Display routes matching the communities\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n"
8571 "Exact match of the communities")
8572
8573ALIAS (show_bgp_community_exact,
8574 show_bgp_ipv6_community3_exact_cmd,
8575 "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",
8576 SHOW_STR
8577 BGP_STR
8578 "Address family\n"
8579 "Display routes matching the communities\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\n"
8592 "Exact match of the communities")
8593
8594ALIAS (show_bgp_community_exact,
8595 show_bgp_community4_exact_cmd,
8596 "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",
8597 SHOW_STR
8598 BGP_STR
8599 "Display routes matching the communities\n"
8600 "community number\n"
8601 "Do not send outside local AS (well-known community)\n"
8602 "Do not advertise to any peer (well-known community)\n"
8603 "Do not export to next AS (well-known community)\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "Exact match of the communities")
8617
8618ALIAS (show_bgp_community_exact,
8619 show_bgp_ipv6_community4_exact_cmd,
8620 "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",
8621 SHOW_STR
8622 BGP_STR
8623 "Address family\n"
8624 "Display routes matching the communities\n"
8625 "community number\n"
8626 "Do not send outside local AS (well-known community)\n"
8627 "Do not advertise to any peer (well-known community)\n"
8628 "Do not export to next AS (well-known community)\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "Exact match of the communities")
8642
8643/* old command */
8644DEFUN (show_ipv6_bgp_community_exact,
8645 show_ipv6_bgp_community_exact_cmd,
8646 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8647 SHOW_STR
8648 IPV6_STR
8649 BGP_STR
8650 "Display routes matching the communities\n"
8651 "community number\n"
8652 "Do not send outside local AS (well-known community)\n"
8653 "Do not advertise to any peer (well-known community)\n"
8654 "Do not export to next AS (well-known community)\n"
8655 "Exact match of the communities")
8656{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008657 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008658}
8659
8660/* old command */
8661ALIAS (show_ipv6_bgp_community_exact,
8662 show_ipv6_bgp_community2_exact_cmd,
8663 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8664 SHOW_STR
8665 IPV6_STR
8666 BGP_STR
8667 "Display routes matching the communities\n"
8668 "community number\n"
8669 "Do not send outside local AS (well-known community)\n"
8670 "Do not advertise to any peer (well-known community)\n"
8671 "Do not export to next AS (well-known community)\n"
8672 "community number\n"
8673 "Do not send outside local AS (well-known community)\n"
8674 "Do not advertise to any peer (well-known community)\n"
8675 "Do not export to next AS (well-known community)\n"
8676 "Exact match of the communities")
8677
8678/* old command */
8679ALIAS (show_ipv6_bgp_community_exact,
8680 show_ipv6_bgp_community3_exact_cmd,
8681 "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",
8682 SHOW_STR
8683 IPV6_STR
8684 BGP_STR
8685 "Display routes matching the communities\n"
8686 "community number\n"
8687 "Do not send outside local AS (well-known community)\n"
8688 "Do not advertise to any peer (well-known community)\n"
8689 "Do not export to next AS (well-known community)\n"
8690 "community number\n"
8691 "Do not send outside local AS (well-known community)\n"
8692 "Do not advertise to any peer (well-known community)\n"
8693 "Do not export to next AS (well-known community)\n"
8694 "community number\n"
8695 "Do not send outside local AS (well-known community)\n"
8696 "Do not advertise to any peer (well-known community)\n"
8697 "Do not export to next AS (well-known community)\n"
8698 "Exact match of the communities")
8699
8700/* old command */
8701ALIAS (show_ipv6_bgp_community_exact,
8702 show_ipv6_bgp_community4_exact_cmd,
8703 "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",
8704 SHOW_STR
8705 IPV6_STR
8706 BGP_STR
8707 "Display routes matching the communities\n"
8708 "community number\n"
8709 "Do not send outside local AS (well-known community)\n"
8710 "Do not advertise to any peer (well-known community)\n"
8711 "Do not export to next AS (well-known community)\n"
8712 "community number\n"
8713 "Do not send outside local AS (well-known community)\n"
8714 "Do not advertise to any peer (well-known community)\n"
8715 "Do not export to next AS (well-known community)\n"
8716 "community number\n"
8717 "Do not send outside local AS (well-known community)\n"
8718 "Do not advertise to any peer (well-known community)\n"
8719 "Do not export to next AS (well-known community)\n"
8720 "community number\n"
8721 "Do not send outside local AS (well-known community)\n"
8722 "Do not advertise to any peer (well-known community)\n"
8723 "Do not export to next AS (well-known community)\n"
8724 "Exact match of the communities")
8725
8726/* old command */
8727DEFUN (show_ipv6_mbgp_community,
8728 show_ipv6_mbgp_community_cmd,
8729 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8730 SHOW_STR
8731 IPV6_STR
8732 MBGP_STR
8733 "Display routes matching the communities\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n")
8738{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008739 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008740}
8741
8742/* old command */
8743ALIAS (show_ipv6_mbgp_community,
8744 show_ipv6_mbgp_community2_cmd,
8745 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8746 SHOW_STR
8747 IPV6_STR
8748 MBGP_STR
8749 "Display routes matching the communities\n"
8750 "community number\n"
8751 "Do not send outside local AS (well-known community)\n"
8752 "Do not advertise to any peer (well-known community)\n"
8753 "Do not export to next AS (well-known community)\n"
8754 "community number\n"
8755 "Do not send outside local AS (well-known community)\n"
8756 "Do not advertise to any peer (well-known community)\n"
8757 "Do not export to next AS (well-known community)\n")
8758
8759/* old command */
8760ALIAS (show_ipv6_mbgp_community,
8761 show_ipv6_mbgp_community3_cmd,
8762 "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)",
8763 SHOW_STR
8764 IPV6_STR
8765 MBGP_STR
8766 "Display routes matching the communities\n"
8767 "community number\n"
8768 "Do not send outside local AS (well-known community)\n"
8769 "Do not advertise to any peer (well-known community)\n"
8770 "Do not export to next AS (well-known community)\n"
8771 "community number\n"
8772 "Do not send outside local AS (well-known community)\n"
8773 "Do not advertise to any peer (well-known community)\n"
8774 "Do not export to next AS (well-known community)\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n")
8779
8780/* old command */
8781ALIAS (show_ipv6_mbgp_community,
8782 show_ipv6_mbgp_community4_cmd,
8783 "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)",
8784 SHOW_STR
8785 IPV6_STR
8786 MBGP_STR
8787 "Display routes matching the communities\n"
8788 "community number\n"
8789 "Do not send outside local AS (well-known community)\n"
8790 "Do not advertise to any peer (well-known community)\n"
8791 "Do not export to next AS (well-known community)\n"
8792 "community number\n"
8793 "Do not send outside local AS (well-known community)\n"
8794 "Do not advertise to any peer (well-known community)\n"
8795 "Do not export to next AS (well-known community)\n"
8796 "community number\n"
8797 "Do not send outside local AS (well-known community)\n"
8798 "Do not advertise to any peer (well-known community)\n"
8799 "Do not export to next AS (well-known community)\n"
8800 "community number\n"
8801 "Do not send outside local AS (well-known community)\n"
8802 "Do not advertise to any peer (well-known community)\n"
8803 "Do not export to next AS (well-known community)\n")
8804
8805/* old command */
8806DEFUN (show_ipv6_mbgp_community_exact,
8807 show_ipv6_mbgp_community_exact_cmd,
8808 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8809 SHOW_STR
8810 IPV6_STR
8811 MBGP_STR
8812 "Display routes matching the communities\n"
8813 "community number\n"
8814 "Do not send outside local AS (well-known community)\n"
8815 "Do not advertise to any peer (well-known community)\n"
8816 "Do not export to next AS (well-known community)\n"
8817 "Exact match of the communities")
8818{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008819 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008820}
8821
8822/* old command */
8823ALIAS (show_ipv6_mbgp_community_exact,
8824 show_ipv6_mbgp_community2_exact_cmd,
8825 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8826 SHOW_STR
8827 IPV6_STR
8828 MBGP_STR
8829 "Display routes matching the communities\n"
8830 "community number\n"
8831 "Do not send outside local AS (well-known community)\n"
8832 "Do not advertise to any peer (well-known community)\n"
8833 "Do not export to next AS (well-known community)\n"
8834 "community number\n"
8835 "Do not send outside local AS (well-known community)\n"
8836 "Do not advertise to any peer (well-known community)\n"
8837 "Do not export to next AS (well-known community)\n"
8838 "Exact match of the communities")
8839
8840/* old command */
8841ALIAS (show_ipv6_mbgp_community_exact,
8842 show_ipv6_mbgp_community3_exact_cmd,
8843 "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",
8844 SHOW_STR
8845 IPV6_STR
8846 MBGP_STR
8847 "Display routes matching the communities\n"
8848 "community number\n"
8849 "Do not send outside local AS (well-known community)\n"
8850 "Do not advertise to any peer (well-known community)\n"
8851 "Do not export to next AS (well-known community)\n"
8852 "community number\n"
8853 "Do not send outside local AS (well-known community)\n"
8854 "Do not advertise to any peer (well-known community)\n"
8855 "Do not export to next AS (well-known community)\n"
8856 "community number\n"
8857 "Do not send outside local AS (well-known community)\n"
8858 "Do not advertise to any peer (well-known community)\n"
8859 "Do not export to next AS (well-known community)\n"
8860 "Exact match of the communities")
8861
8862/* old command */
8863ALIAS (show_ipv6_mbgp_community_exact,
8864 show_ipv6_mbgp_community4_exact_cmd,
8865 "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",
8866 SHOW_STR
8867 IPV6_STR
8868 MBGP_STR
8869 "Display routes matching the communities\n"
8870 "community number\n"
8871 "Do not send outside local AS (well-known community)\n"
8872 "Do not advertise to any peer (well-known community)\n"
8873 "Do not export to next AS (well-known community)\n"
8874 "community number\n"
8875 "Do not send outside local AS (well-known community)\n"
8876 "Do not advertise to any peer (well-known community)\n"
8877 "Do not export to next AS (well-known community)\n"
8878 "community number\n"
8879 "Do not send outside local AS (well-known community)\n"
8880 "Do not advertise to any peer (well-known community)\n"
8881 "Do not export to next AS (well-known community)\n"
8882 "community number\n"
8883 "Do not send outside local AS (well-known community)\n"
8884 "Do not advertise to any peer (well-known community)\n"
8885 "Do not export to next AS (well-known community)\n"
8886 "Exact match of the communities")
8887#endif /* HAVE_IPV6 */
8888
paul94f2b392005-06-28 12:44:16 +00008889static int
paulfd79ac92004-10-13 05:06:08 +00008890bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008891 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008892{
8893 struct community_list *list;
8894
hassofee6e4e2005-02-02 16:29:31 +00008895 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008896 if (list == NULL)
8897 {
8898 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8899 VTY_NEWLINE);
8900 return CMD_WARNING;
8901 }
8902
ajs5a646652004-11-05 01:25:55 +00008903 return bgp_show (vty, NULL, afi, safi,
8904 (exact ? bgp_show_type_community_list_exact :
8905 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008906}
8907
8908DEFUN (show_ip_bgp_community_list,
8909 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008910 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008911 SHOW_STR
8912 IP_STR
8913 BGP_STR
8914 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008915 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008916 "community-list name\n")
8917{
8918 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8919}
8920
8921DEFUN (show_ip_bgp_ipv4_community_list,
8922 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008923 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008924 SHOW_STR
8925 IP_STR
8926 BGP_STR
8927 "Address family\n"
8928 "Address Family modifier\n"
8929 "Address Family modifier\n"
8930 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008931 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008932 "community-list name\n")
8933{
8934 if (strncmp (argv[0], "m", 1) == 0)
8935 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8936
8937 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8938}
8939
8940DEFUN (show_ip_bgp_community_list_exact,
8941 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008942 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008943 SHOW_STR
8944 IP_STR
8945 BGP_STR
8946 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008947 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008948 "community-list name\n"
8949 "Exact match of the communities\n")
8950{
8951 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8952}
8953
8954DEFUN (show_ip_bgp_ipv4_community_list_exact,
8955 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008956 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008957 SHOW_STR
8958 IP_STR
8959 BGP_STR
8960 "Address family\n"
8961 "Address Family modifier\n"
8962 "Address Family modifier\n"
8963 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008964 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008965 "community-list name\n"
8966 "Exact match of the communities\n")
8967{
8968 if (strncmp (argv[0], "m", 1) == 0)
8969 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8970
8971 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8972}
8973
8974#ifdef HAVE_IPV6
8975DEFUN (show_bgp_community_list,
8976 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008977 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008978 SHOW_STR
8979 BGP_STR
8980 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008981 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008982 "community-list name\n")
8983{
8984 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8985}
8986
8987ALIAS (show_bgp_community_list,
8988 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008989 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008990 SHOW_STR
8991 BGP_STR
8992 "Address family\n"
8993 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008994 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008995 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008996
8997/* old command */
8998DEFUN (show_ipv6_bgp_community_list,
8999 show_ipv6_bgp_community_list_cmd,
9000 "show ipv6 bgp community-list WORD",
9001 SHOW_STR
9002 IPV6_STR
9003 BGP_STR
9004 "Display routes matching the community-list\n"
9005 "community-list name\n")
9006{
9007 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9008}
9009
9010/* old command */
9011DEFUN (show_ipv6_mbgp_community_list,
9012 show_ipv6_mbgp_community_list_cmd,
9013 "show ipv6 mbgp community-list WORD",
9014 SHOW_STR
9015 IPV6_STR
9016 MBGP_STR
9017 "Display routes matching the community-list\n"
9018 "community-list name\n")
9019{
9020 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9021}
9022
9023DEFUN (show_bgp_community_list_exact,
9024 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009025 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009026 SHOW_STR
9027 BGP_STR
9028 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009029 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009030 "community-list name\n"
9031 "Exact match of the communities\n")
9032{
9033 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9034}
9035
9036ALIAS (show_bgp_community_list_exact,
9037 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009038 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009039 SHOW_STR
9040 BGP_STR
9041 "Address family\n"
9042 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009043 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009044 "community-list name\n"
9045 "Exact match of the communities\n")
9046
9047/* old command */
9048DEFUN (show_ipv6_bgp_community_list_exact,
9049 show_ipv6_bgp_community_list_exact_cmd,
9050 "show ipv6 bgp community-list WORD exact-match",
9051 SHOW_STR
9052 IPV6_STR
9053 BGP_STR
9054 "Display routes matching the community-list\n"
9055 "community-list name\n"
9056 "Exact match of the communities\n")
9057{
9058 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9059}
9060
9061/* old command */
9062DEFUN (show_ipv6_mbgp_community_list_exact,
9063 show_ipv6_mbgp_community_list_exact_cmd,
9064 "show ipv6 mbgp community-list WORD exact-match",
9065 SHOW_STR
9066 IPV6_STR
9067 MBGP_STR
9068 "Display routes matching the community-list\n"
9069 "community-list name\n"
9070 "Exact match of the communities\n")
9071{
9072 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9073}
9074#endif /* HAVE_IPV6 */
9075
paul94f2b392005-06-28 12:44:16 +00009076static int
paulfd79ac92004-10-13 05:06:08 +00009077bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009078 safi_t safi, enum bgp_show_type type)
9079{
9080 int ret;
9081 struct prefix *p;
9082
9083 p = prefix_new();
9084
9085 ret = str2prefix (prefix, p);
9086 if (! ret)
9087 {
9088 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9089 return CMD_WARNING;
9090 }
9091
ajs5a646652004-11-05 01:25:55 +00009092 ret = bgp_show (vty, NULL, afi, safi, type, p);
9093 prefix_free(p);
9094 return ret;
paul718e3742002-12-13 20:15:29 +00009095}
9096
9097DEFUN (show_ip_bgp_prefix_longer,
9098 show_ip_bgp_prefix_longer_cmd,
9099 "show ip bgp A.B.C.D/M longer-prefixes",
9100 SHOW_STR
9101 IP_STR
9102 BGP_STR
9103 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9104 "Display route and more specific routes\n")
9105{
9106 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9107 bgp_show_type_prefix_longer);
9108}
9109
9110DEFUN (show_ip_bgp_flap_prefix_longer,
9111 show_ip_bgp_flap_prefix_longer_cmd,
9112 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9113 SHOW_STR
9114 IP_STR
9115 BGP_STR
9116 "Display flap statistics of routes\n"
9117 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9118 "Display route and more specific routes\n")
9119{
9120 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9121 bgp_show_type_flap_prefix_longer);
9122}
9123
9124DEFUN (show_ip_bgp_ipv4_prefix_longer,
9125 show_ip_bgp_ipv4_prefix_longer_cmd,
9126 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9127 SHOW_STR
9128 IP_STR
9129 BGP_STR
9130 "Address family\n"
9131 "Address Family modifier\n"
9132 "Address Family modifier\n"
9133 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9134 "Display route and more specific routes\n")
9135{
9136 if (strncmp (argv[0], "m", 1) == 0)
9137 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9138 bgp_show_type_prefix_longer);
9139
9140 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9141 bgp_show_type_prefix_longer);
9142}
9143
9144DEFUN (show_ip_bgp_flap_address,
9145 show_ip_bgp_flap_address_cmd,
9146 "show ip bgp flap-statistics A.B.C.D",
9147 SHOW_STR
9148 IP_STR
9149 BGP_STR
9150 "Display flap statistics of routes\n"
9151 "Network in the BGP routing table to display\n")
9152{
9153 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9154 bgp_show_type_flap_address);
9155}
9156
9157DEFUN (show_ip_bgp_flap_prefix,
9158 show_ip_bgp_flap_prefix_cmd,
9159 "show ip bgp flap-statistics A.B.C.D/M",
9160 SHOW_STR
9161 IP_STR
9162 BGP_STR
9163 "Display flap statistics of routes\n"
9164 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9165{
9166 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9167 bgp_show_type_flap_prefix);
9168}
9169#ifdef HAVE_IPV6
9170DEFUN (show_bgp_prefix_longer,
9171 show_bgp_prefix_longer_cmd,
9172 "show bgp X:X::X:X/M longer-prefixes",
9173 SHOW_STR
9174 BGP_STR
9175 "IPv6 prefix <network>/<length>\n"
9176 "Display route and more specific routes\n")
9177{
9178 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9179 bgp_show_type_prefix_longer);
9180}
9181
9182ALIAS (show_bgp_prefix_longer,
9183 show_bgp_ipv6_prefix_longer_cmd,
9184 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9185 SHOW_STR
9186 BGP_STR
9187 "Address family\n"
9188 "IPv6 prefix <network>/<length>\n"
9189 "Display route and more specific routes\n")
9190
9191/* old command */
9192DEFUN (show_ipv6_bgp_prefix_longer,
9193 show_ipv6_bgp_prefix_longer_cmd,
9194 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9195 SHOW_STR
9196 IPV6_STR
9197 BGP_STR
9198 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9199 "Display route and more specific routes\n")
9200{
9201 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9202 bgp_show_type_prefix_longer);
9203}
9204
9205/* old command */
9206DEFUN (show_ipv6_mbgp_prefix_longer,
9207 show_ipv6_mbgp_prefix_longer_cmd,
9208 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9209 SHOW_STR
9210 IPV6_STR
9211 MBGP_STR
9212 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9213 "Display route and more specific routes\n")
9214{
9215 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9216 bgp_show_type_prefix_longer);
9217}
9218#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009219
paul94f2b392005-06-28 12:44:16 +00009220static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009221peer_lookup_in_view (struct vty *vty, const char *view_name,
9222 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009223{
9224 int ret;
9225 struct bgp *bgp;
9226 struct peer *peer;
9227 union sockunion su;
9228
9229 /* BGP structure lookup. */
9230 if (view_name)
9231 {
9232 bgp = bgp_lookup_by_name (view_name);
9233 if (! bgp)
9234 {
9235 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9236 return NULL;
9237 }
9238 }
paul5228ad22004-06-04 17:58:18 +00009239 else
paulbb46e942003-10-24 19:02:03 +00009240 {
9241 bgp = bgp_get_default ();
9242 if (! bgp)
9243 {
9244 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9245 return NULL;
9246 }
9247 }
9248
9249 /* Get peer sockunion. */
9250 ret = str2sockunion (ip_str, &su);
9251 if (ret < 0)
9252 {
9253 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9254 return NULL;
9255 }
9256
9257 /* Peer structure lookup. */
9258 peer = peer_lookup (bgp, &su);
9259 if (! peer)
9260 {
9261 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9262 return NULL;
9263 }
9264
9265 return peer;
9266}
Paul Jakma2815e612006-09-14 02:56:07 +00009267
9268enum bgp_stats
9269{
9270 BGP_STATS_MAXBITLEN = 0,
9271 BGP_STATS_RIB,
9272 BGP_STATS_PREFIXES,
9273 BGP_STATS_TOTPLEN,
9274 BGP_STATS_UNAGGREGATEABLE,
9275 BGP_STATS_MAX_AGGREGATEABLE,
9276 BGP_STATS_AGGREGATES,
9277 BGP_STATS_SPACE,
9278 BGP_STATS_ASPATH_COUNT,
9279 BGP_STATS_ASPATH_MAXHOPS,
9280 BGP_STATS_ASPATH_TOTHOPS,
9281 BGP_STATS_ASPATH_MAXSIZE,
9282 BGP_STATS_ASPATH_TOTSIZE,
9283 BGP_STATS_ASN_HIGHEST,
9284 BGP_STATS_MAX,
9285};
paulbb46e942003-10-24 19:02:03 +00009286
Paul Jakma2815e612006-09-14 02:56:07 +00009287static const char *table_stats_strs[] =
9288{
9289 [BGP_STATS_PREFIXES] = "Total Prefixes",
9290 [BGP_STATS_TOTPLEN] = "Average prefix length",
9291 [BGP_STATS_RIB] = "Total Advertisements",
9292 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9293 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9294 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9295 [BGP_STATS_SPACE] = "Address space advertised",
9296 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9297 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9298 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9299 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9300 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9301 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9302 [BGP_STATS_MAX] = NULL,
9303};
9304
9305struct bgp_table_stats
9306{
9307 struct bgp_table *table;
9308 unsigned long long counts[BGP_STATS_MAX];
9309};
9310
9311#if 0
9312#define TALLY_SIGFIG 100000
9313static unsigned long
9314ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9315{
9316 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9317 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9318 unsigned long ret = newtot / count;
9319
9320 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9321 return ret + 1;
9322 else
9323 return ret;
9324}
9325#endif
9326
9327static int
9328bgp_table_stats_walker (struct thread *t)
9329{
9330 struct bgp_node *rn;
9331 struct bgp_node *top;
9332 struct bgp_table_stats *ts = THREAD_ARG (t);
9333 unsigned int space = 0;
9334
Paul Jakma53d9f672006-10-15 23:41:16 +00009335 if (!(top = bgp_table_top (ts->table)))
9336 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009337
9338 switch (top->p.family)
9339 {
9340 case AF_INET:
9341 space = IPV4_MAX_BITLEN;
9342 break;
9343 case AF_INET6:
9344 space = IPV6_MAX_BITLEN;
9345 break;
9346 }
9347
9348 ts->counts[BGP_STATS_MAXBITLEN] = space;
9349
9350 for (rn = top; rn; rn = bgp_route_next (rn))
9351 {
9352 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009353 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009354 unsigned int rinum = 0;
9355
9356 if (rn == top)
9357 continue;
9358
9359 if (!rn->info)
9360 continue;
9361
9362 ts->counts[BGP_STATS_PREFIXES]++;
9363 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9364
9365#if 0
9366 ts->counts[BGP_STATS_AVGPLEN]
9367 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9368 ts->counts[BGP_STATS_AVGPLEN],
9369 rn->p.prefixlen);
9370#endif
9371
9372 /* check if the prefix is included by any other announcements */
9373 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009374 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009375
9376 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009377 {
9378 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9379 /* announced address space */
9380 if (space)
9381 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9382 }
Paul Jakma2815e612006-09-14 02:56:07 +00009383 else if (prn->info)
9384 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9385
Paul Jakma2815e612006-09-14 02:56:07 +00009386 for (ri = rn->info; ri; ri = ri->next)
9387 {
9388 rinum++;
9389 ts->counts[BGP_STATS_RIB]++;
9390
9391 if (ri->attr &&
9392 (CHECK_FLAG (ri->attr->flag,
9393 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9394 ts->counts[BGP_STATS_AGGREGATES]++;
9395
9396 /* as-path stats */
9397 if (ri->attr && ri->attr->aspath)
9398 {
9399 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9400 unsigned int size = aspath_size (ri->attr->aspath);
9401 as_t highest = aspath_highest (ri->attr->aspath);
9402
9403 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9404
9405 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9406 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9407
9408 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9409 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9410
9411 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9412 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9413#if 0
9414 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9415 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9416 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9417 hops);
9418 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9419 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9420 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9421 size);
9422#endif
9423 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9424 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9425 }
9426 }
9427 }
9428 return 0;
9429}
9430
9431static int
9432bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9433{
9434 struct bgp_table_stats ts;
9435 unsigned int i;
9436
9437 if (!bgp->rib[afi][safi])
9438 {
9439 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9440 return CMD_WARNING;
9441 }
9442
9443 memset (&ts, 0, sizeof (ts));
9444 ts.table = bgp->rib[afi][safi];
9445 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9446
9447 vty_out (vty, "BGP %s RIB statistics%s%s",
9448 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9449
9450 for (i = 0; i < BGP_STATS_MAX; i++)
9451 {
9452 if (!table_stats_strs[i])
9453 continue;
9454
9455 switch (i)
9456 {
9457#if 0
9458 case BGP_STATS_ASPATH_AVGHOPS:
9459 case BGP_STATS_ASPATH_AVGSIZE:
9460 case BGP_STATS_AVGPLEN:
9461 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9462 vty_out (vty, "%12.2f",
9463 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9464 break;
9465#endif
9466 case BGP_STATS_ASPATH_TOTHOPS:
9467 case BGP_STATS_ASPATH_TOTSIZE:
9468 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9469 vty_out (vty, "%12.2f",
9470 ts.counts[i] ?
9471 (float)ts.counts[i] /
9472 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9473 : 0);
9474 break;
9475 case BGP_STATS_TOTPLEN:
9476 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9477 vty_out (vty, "%12.2f",
9478 ts.counts[i] ?
9479 (float)ts.counts[i] /
9480 (float)ts.counts[BGP_STATS_PREFIXES]
9481 : 0);
9482 break;
9483 case BGP_STATS_SPACE:
9484 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9485 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9486 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9487 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009488 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009489 vty_out (vty, "%12.2f%s",
9490 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009491 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009492 VTY_NEWLINE);
9493 vty_out (vty, "%30s: ", "/8 equivalent ");
9494 vty_out (vty, "%12.2f%s",
9495 (float)ts.counts[BGP_STATS_SPACE] /
9496 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9497 VTY_NEWLINE);
9498 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9499 break;
9500 vty_out (vty, "%30s: ", "/24 equivalent ");
9501 vty_out (vty, "%12.2f",
9502 (float)ts.counts[BGP_STATS_SPACE] /
9503 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9504 break;
9505 default:
9506 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9507 vty_out (vty, "%12llu", ts.counts[i]);
9508 }
9509
9510 vty_out (vty, "%s", VTY_NEWLINE);
9511 }
9512 return CMD_SUCCESS;
9513}
9514
9515static int
9516bgp_table_stats_vty (struct vty *vty, const char *name,
9517 const char *afi_str, const char *safi_str)
9518{
9519 struct bgp *bgp;
9520 afi_t afi;
9521 safi_t safi;
9522
9523 if (name)
9524 bgp = bgp_lookup_by_name (name);
9525 else
9526 bgp = bgp_get_default ();
9527
9528 if (!bgp)
9529 {
9530 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9531 return CMD_WARNING;
9532 }
9533 if (strncmp (afi_str, "ipv", 3) == 0)
9534 {
9535 if (strncmp (afi_str, "ipv4", 4) == 0)
9536 afi = AFI_IP;
9537 else if (strncmp (afi_str, "ipv6", 4) == 0)
9538 afi = AFI_IP6;
9539 else
9540 {
9541 vty_out (vty, "%% Invalid address family %s%s",
9542 afi_str, VTY_NEWLINE);
9543 return CMD_WARNING;
9544 }
9545 if (strncmp (safi_str, "m", 1) == 0)
9546 safi = SAFI_MULTICAST;
9547 else if (strncmp (safi_str, "u", 1) == 0)
9548 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009549 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9550 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009551 else
9552 {
9553 vty_out (vty, "%% Invalid subsequent address family %s%s",
9554 safi_str, VTY_NEWLINE);
9555 return CMD_WARNING;
9556 }
9557 }
9558 else
9559 {
9560 vty_out (vty, "%% Invalid address family %s%s",
9561 afi_str, VTY_NEWLINE);
9562 return CMD_WARNING;
9563 }
9564
Paul Jakma2815e612006-09-14 02:56:07 +00009565 return bgp_table_stats (vty, bgp, afi, safi);
9566}
9567
9568DEFUN (show_bgp_statistics,
9569 show_bgp_statistics_cmd,
9570 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9571 SHOW_STR
9572 BGP_STR
9573 "Address family\n"
9574 "Address family\n"
9575 "Address Family modifier\n"
9576 "Address Family modifier\n"
9577 "BGP RIB advertisement statistics\n")
9578{
9579 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9580}
9581
9582ALIAS (show_bgp_statistics,
9583 show_bgp_statistics_vpnv4_cmd,
9584 "show bgp (ipv4) (vpnv4) statistics",
9585 SHOW_STR
9586 BGP_STR
9587 "Address family\n"
9588 "Address Family modifier\n"
9589 "BGP RIB advertisement statistics\n")
9590
9591DEFUN (show_bgp_statistics_view,
9592 show_bgp_statistics_view_cmd,
9593 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9594 SHOW_STR
9595 BGP_STR
9596 "BGP view\n"
9597 "Address family\n"
9598 "Address family\n"
9599 "Address Family modifier\n"
9600 "Address Family modifier\n"
9601 "BGP RIB advertisement statistics\n")
9602{
9603 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9604}
9605
9606ALIAS (show_bgp_statistics_view,
9607 show_bgp_statistics_view_vpnv4_cmd,
9608 "show bgp view WORD (ipv4) (vpnv4) statistics",
9609 SHOW_STR
9610 BGP_STR
9611 "BGP view\n"
9612 "Address family\n"
9613 "Address Family modifier\n"
9614 "BGP RIB advertisement statistics\n")
9615
Paul Jakmaff7924f2006-09-04 01:10:36 +00009616enum bgp_pcounts
9617{
9618 PCOUNT_ADJ_IN = 0,
9619 PCOUNT_DAMPED,
9620 PCOUNT_REMOVED,
9621 PCOUNT_HISTORY,
9622 PCOUNT_STALE,
9623 PCOUNT_VALID,
9624 PCOUNT_ALL,
9625 PCOUNT_COUNTED,
9626 PCOUNT_PFCNT, /* the figure we display to users */
9627 PCOUNT_MAX,
9628};
9629
9630static const char *pcount_strs[] =
9631{
9632 [PCOUNT_ADJ_IN] = "Adj-in",
9633 [PCOUNT_DAMPED] = "Damped",
9634 [PCOUNT_REMOVED] = "Removed",
9635 [PCOUNT_HISTORY] = "History",
9636 [PCOUNT_STALE] = "Stale",
9637 [PCOUNT_VALID] = "Valid",
9638 [PCOUNT_ALL] = "All RIB",
9639 [PCOUNT_COUNTED] = "PfxCt counted",
9640 [PCOUNT_PFCNT] = "Useable",
9641 [PCOUNT_MAX] = NULL,
9642};
9643
Paul Jakma2815e612006-09-14 02:56:07 +00009644struct peer_pcounts
9645{
9646 unsigned int count[PCOUNT_MAX];
9647 const struct peer *peer;
9648 const struct bgp_table *table;
9649};
9650
Paul Jakmaff7924f2006-09-04 01:10:36 +00009651static int
Paul Jakma2815e612006-09-14 02:56:07 +00009652bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653{
9654 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009655 struct peer_pcounts *pc = THREAD_ARG (t);
9656 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657
Paul Jakma2815e612006-09-14 02:56:07 +00009658 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659 {
9660 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009661 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009662
9663 for (ain = rn->adj_in; ain; ain = ain->next)
9664 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009665 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009666
Paul Jakmaff7924f2006-09-04 01:10:36 +00009667 for (ri = rn->info; ri; ri = ri->next)
9668 {
9669 char buf[SU_ADDRSTRLEN];
9670
9671 if (ri->peer != peer)
9672 continue;
9673
Paul Jakma2815e612006-09-14 02:56:07 +00009674 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675
9676 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009677 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009678 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009679 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009680 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009681 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009682 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009683 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009684 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009685 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009686 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009687 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009688
9689 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9690 {
Paul Jakma2815e612006-09-14 02:56:07 +00009691 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009692 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009693 plog_warn (peer->log,
9694 "%s [pcount] %s/%d is counted but flags 0x%x",
9695 peer->host,
9696 inet_ntop(rn->p.family, &rn->p.u.prefix,
9697 buf, SU_ADDRSTRLEN),
9698 rn->p.prefixlen,
9699 ri->flags);
9700 }
9701 else
9702 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009703 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009704 plog_warn (peer->log,
9705 "%s [pcount] %s/%d not counted but flags 0x%x",
9706 peer->host,
9707 inet_ntop(rn->p.family, &rn->p.u.prefix,
9708 buf, SU_ADDRSTRLEN),
9709 rn->p.prefixlen,
9710 ri->flags);
9711 }
9712 }
9713 }
Paul Jakma2815e612006-09-14 02:56:07 +00009714 return 0;
9715}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009716
Paul Jakma2815e612006-09-14 02:56:07 +00009717static int
9718bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9719{
9720 struct peer_pcounts pcounts = { .peer = peer };
9721 unsigned int i;
9722
9723 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9724 || !peer->bgp->rib[afi][safi])
9725 {
9726 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9727 return CMD_WARNING;
9728 }
9729
9730 memset (&pcounts, 0, sizeof(pcounts));
9731 pcounts.peer = peer;
9732 pcounts.table = peer->bgp->rib[afi][safi];
9733
9734 /* in-place call via thread subsystem so as to record execution time
9735 * stats for the thread-walk (i.e. ensure this can't be blamed on
9736 * on just vty_read()).
9737 */
9738 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9739
Paul Jakmaff7924f2006-09-04 01:10:36 +00009740 vty_out (vty, "Prefix counts for %s, %s%s",
9741 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9742 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9743 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9744 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9745
9746 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009747 vty_out (vty, "%20s: %-10d%s",
9748 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009749
Paul Jakma2815e612006-09-14 02:56:07 +00009750 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009751 {
9752 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9753 peer->host, VTY_NEWLINE);
9754 vty_out (vty, "Please report this bug, with the above command output%s",
9755 VTY_NEWLINE);
9756 }
9757
9758 return CMD_SUCCESS;
9759}
9760
9761DEFUN (show_ip_bgp_neighbor_prefix_counts,
9762 show_ip_bgp_neighbor_prefix_counts_cmd,
9763 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9764 SHOW_STR
9765 IP_STR
9766 BGP_STR
9767 "Detailed information on TCP and BGP neighbor connections\n"
9768 "Neighbor to display information about\n"
9769 "Neighbor to display information about\n"
9770 "Display detailed prefix count information\n")
9771{
9772 struct peer *peer;
9773
9774 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9775 if (! peer)
9776 return CMD_WARNING;
9777
9778 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9779}
9780
9781DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9782 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9783 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9784 SHOW_STR
9785 BGP_STR
9786 "Address family\n"
9787 "Detailed information on TCP and BGP neighbor connections\n"
9788 "Neighbor to display information about\n"
9789 "Neighbor to display information about\n"
9790 "Display detailed prefix count information\n")
9791{
9792 struct peer *peer;
9793
9794 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9795 if (! peer)
9796 return CMD_WARNING;
9797
9798 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9799}
9800
9801DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9802 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9803 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9804 SHOW_STR
9805 IP_STR
9806 BGP_STR
9807 "Address family\n"
9808 "Address Family modifier\n"
9809 "Address Family modifier\n"
9810 "Detailed information on TCP and BGP neighbor connections\n"
9811 "Neighbor to display information about\n"
9812 "Neighbor to display information about\n"
9813 "Display detailed prefix count information\n")
9814{
9815 struct peer *peer;
9816
9817 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9818 if (! peer)
9819 return CMD_WARNING;
9820
9821 if (strncmp (argv[0], "m", 1) == 0)
9822 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9823
9824 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9825}
9826
9827DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9828 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9829 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9830 SHOW_STR
9831 IP_STR
9832 BGP_STR
9833 "Address family\n"
9834 "Address Family modifier\n"
9835 "Address Family modifier\n"
9836 "Detailed information on TCP and BGP neighbor connections\n"
9837 "Neighbor to display information about\n"
9838 "Neighbor to display information about\n"
9839 "Display detailed prefix count information\n")
9840{
9841 struct peer *peer;
9842
9843 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9844 if (! peer)
9845 return CMD_WARNING;
9846
9847 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9848}
9849
9850
paul94f2b392005-06-28 12:44:16 +00009851static void
paul718e3742002-12-13 20:15:29 +00009852show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9853 int in)
9854{
9855 struct bgp_table *table;
9856 struct bgp_adj_in *ain;
9857 struct bgp_adj_out *adj;
9858 unsigned long output_count;
9859 struct bgp_node *rn;
9860 int header1 = 1;
9861 struct bgp *bgp;
9862 int header2 = 1;
9863
paulbb46e942003-10-24 19:02:03 +00009864 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009865
9866 if (! bgp)
9867 return;
9868
9869 table = bgp->rib[afi][safi];
9870
9871 output_count = 0;
9872
9873 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9874 PEER_STATUS_DEFAULT_ORIGINATE))
9875 {
9876 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 +00009877 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9878 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009879
9880 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9881 VTY_NEWLINE, VTY_NEWLINE);
9882 header1 = 0;
9883 }
9884
9885 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9886 if (in)
9887 {
9888 for (ain = rn->adj_in; ain; ain = ain->next)
9889 if (ain->peer == peer)
9890 {
9891 if (header1)
9892 {
9893 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 +00009894 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9895 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009896 header1 = 0;
9897 }
9898 if (header2)
9899 {
9900 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9901 header2 = 0;
9902 }
9903 if (ain->attr)
9904 {
9905 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9906 output_count++;
9907 }
9908 }
9909 }
9910 else
9911 {
9912 for (adj = rn->adj_out; adj; adj = adj->next)
9913 if (adj->peer == peer)
9914 {
9915 if (header1)
9916 {
9917 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 +00009918 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9919 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009920 header1 = 0;
9921 }
9922 if (header2)
9923 {
9924 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9925 header2 = 0;
9926 }
9927 if (adj->attr)
9928 {
9929 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9930 output_count++;
9931 }
9932 }
9933 }
9934
9935 if (output_count != 0)
9936 vty_out (vty, "%sTotal number of prefixes %ld%s",
9937 VTY_NEWLINE, output_count, VTY_NEWLINE);
9938}
9939
paul94f2b392005-06-28 12:44:16 +00009940static int
paulbb46e942003-10-24 19:02:03 +00009941peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9942{
paul718e3742002-12-13 20:15:29 +00009943 if (! peer || ! peer->afc[afi][safi])
9944 {
9945 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9946 return CMD_WARNING;
9947 }
9948
9949 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9950 {
9951 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9952 VTY_NEWLINE);
9953 return CMD_WARNING;
9954 }
9955
9956 show_adj_route (vty, peer, afi, safi, in);
9957
9958 return CMD_SUCCESS;
9959}
9960
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009961DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9962 show_ip_bgp_view_neighbor_advertised_route_cmd,
9963 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9964 SHOW_STR
9965 IP_STR
9966 BGP_STR
9967 "BGP view\n"
9968 "View name\n"
9969 "Detailed information on TCP and BGP neighbor connections\n"
9970 "Neighbor to display information about\n"
9971 "Neighbor to display information about\n"
9972 "Display the routes advertised to a BGP neighbor\n")
9973{
9974 struct peer *peer;
9975
9976 if (argc == 2)
9977 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9978 else
9979 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9980
9981 if (! peer)
9982 return CMD_WARNING;
9983
9984 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9985}
9986
9987ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009988 show_ip_bgp_neighbor_advertised_route_cmd,
9989 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9990 SHOW_STR
9991 IP_STR
9992 BGP_STR
9993 "Detailed information on TCP and BGP neighbor connections\n"
9994 "Neighbor to display information about\n"
9995 "Neighbor to display information about\n"
9996 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009997
9998DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9999 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10000 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10001 SHOW_STR
10002 IP_STR
10003 BGP_STR
10004 "Address family\n"
10005 "Address Family modifier\n"
10006 "Address Family modifier\n"
10007 "Detailed information on TCP and BGP neighbor connections\n"
10008 "Neighbor to display information about\n"
10009 "Neighbor to display information about\n"
10010 "Display the routes advertised to a BGP neighbor\n")
10011{
paulbb46e942003-10-24 19:02:03 +000010012 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010013
paulbb46e942003-10-24 19:02:03 +000010014 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10015 if (! peer)
10016 return CMD_WARNING;
10017
10018 if (strncmp (argv[0], "m", 1) == 0)
10019 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10020
10021 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010022}
10023
10024#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010025DEFUN (show_bgp_view_neighbor_advertised_route,
10026 show_bgp_view_neighbor_advertised_route_cmd,
10027 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10028 SHOW_STR
10029 BGP_STR
10030 "BGP view\n"
10031 "View name\n"
10032 "Detailed information on TCP and BGP neighbor connections\n"
10033 "Neighbor to display information about\n"
10034 "Neighbor to display information about\n"
10035 "Display the routes advertised to a BGP neighbor\n")
10036{
10037 struct peer *peer;
10038
10039 if (argc == 2)
10040 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10041 else
10042 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10043
10044 if (! peer)
10045 return CMD_WARNING;
10046
10047 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10048}
10049
10050ALIAS (show_bgp_view_neighbor_advertised_route,
10051 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10052 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10053 SHOW_STR
10054 BGP_STR
10055 "BGP view\n"
10056 "View name\n"
10057 "Address family\n"
10058 "Detailed information on TCP and BGP neighbor connections\n"
10059 "Neighbor to display information about\n"
10060 "Neighbor to display information about\n"
10061 "Display the routes advertised to a BGP neighbor\n")
10062
10063DEFUN (show_bgp_view_neighbor_received_routes,
10064 show_bgp_view_neighbor_received_routes_cmd,
10065 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10066 SHOW_STR
10067 BGP_STR
10068 "BGP view\n"
10069 "View name\n"
10070 "Detailed information on TCP and BGP neighbor connections\n"
10071 "Neighbor to display information about\n"
10072 "Neighbor to display information about\n"
10073 "Display the received routes from neighbor\n")
10074{
10075 struct peer *peer;
10076
10077 if (argc == 2)
10078 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10079 else
10080 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10081
10082 if (! peer)
10083 return CMD_WARNING;
10084
10085 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10086}
10087
10088ALIAS (show_bgp_view_neighbor_received_routes,
10089 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10090 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10091 SHOW_STR
10092 BGP_STR
10093 "BGP view\n"
10094 "View name\n"
10095 "Address family\n"
10096 "Detailed information on TCP and BGP neighbor connections\n"
10097 "Neighbor to display information about\n"
10098 "Neighbor to display information about\n"
10099 "Display the received routes from neighbor\n")
10100
10101ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010102 show_bgp_neighbor_advertised_route_cmd,
10103 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10104 SHOW_STR
10105 BGP_STR
10106 "Detailed information on TCP and BGP neighbor connections\n"
10107 "Neighbor to display information about\n"
10108 "Neighbor to display information about\n"
10109 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010110
10111ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010112 show_bgp_ipv6_neighbor_advertised_route_cmd,
10113 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10114 SHOW_STR
10115 BGP_STR
10116 "Address family\n"
10117 "Detailed information on TCP and BGP neighbor connections\n"
10118 "Neighbor to display information about\n"
10119 "Neighbor to display information about\n"
10120 "Display the routes advertised to a BGP neighbor\n")
10121
10122/* old command */
paulbb46e942003-10-24 19:02:03 +000010123ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010124 ipv6_bgp_neighbor_advertised_route_cmd,
10125 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10126 SHOW_STR
10127 IPV6_STR
10128 BGP_STR
10129 "Detailed information on TCP and BGP neighbor connections\n"
10130 "Neighbor to display information about\n"
10131 "Neighbor to display information about\n"
10132 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010133
paul718e3742002-12-13 20:15:29 +000010134/* old command */
10135DEFUN (ipv6_mbgp_neighbor_advertised_route,
10136 ipv6_mbgp_neighbor_advertised_route_cmd,
10137 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10138 SHOW_STR
10139 IPV6_STR
10140 MBGP_STR
10141 "Detailed information on TCP and BGP neighbor connections\n"
10142 "Neighbor to display information about\n"
10143 "Neighbor to display information about\n"
10144 "Display the routes advertised to a BGP neighbor\n")
10145{
paulbb46e942003-10-24 19:02:03 +000010146 struct peer *peer;
10147
10148 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10149 if (! peer)
10150 return CMD_WARNING;
10151
10152 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010153}
10154#endif /* HAVE_IPV6 */
10155
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010156DEFUN (show_ip_bgp_view_neighbor_received_routes,
10157 show_ip_bgp_view_neighbor_received_routes_cmd,
10158 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10159 SHOW_STR
10160 IP_STR
10161 BGP_STR
10162 "BGP view\n"
10163 "View name\n"
10164 "Detailed information on TCP and BGP neighbor connections\n"
10165 "Neighbor to display information about\n"
10166 "Neighbor to display information about\n"
10167 "Display the received routes from neighbor\n")
10168{
10169 struct peer *peer;
10170
10171 if (argc == 2)
10172 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10173 else
10174 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10175
10176 if (! peer)
10177 return CMD_WARNING;
10178
10179 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10180}
10181
10182ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010183 show_ip_bgp_neighbor_received_routes_cmd,
10184 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10185 SHOW_STR
10186 IP_STR
10187 BGP_STR
10188 "Detailed information on TCP and BGP neighbor connections\n"
10189 "Neighbor to display information about\n"
10190 "Neighbor to display information about\n"
10191 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010192
10193DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10194 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10195 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10196 SHOW_STR
10197 IP_STR
10198 BGP_STR
10199 "Address family\n"
10200 "Address Family modifier\n"
10201 "Address Family modifier\n"
10202 "Detailed information on TCP and BGP neighbor connections\n"
10203 "Neighbor to display information about\n"
10204 "Neighbor to display information about\n"
10205 "Display the received routes from neighbor\n")
10206{
paulbb46e942003-10-24 19:02:03 +000010207 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010208
paulbb46e942003-10-24 19:02:03 +000010209 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10210 if (! peer)
10211 return CMD_WARNING;
10212
10213 if (strncmp (argv[0], "m", 1) == 0)
10214 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10215
10216 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010217}
10218
Michael Lambert95cbbd22010-07-23 14:43:04 -040010219DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10220 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10221#ifdef HAVE_IPV6
10222 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10223#else
10224 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10225#endif
10226 SHOW_STR
10227 BGP_STR
10228 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010229 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010230 "Address family\n"
10231#ifdef HAVE_IPV6
10232 "Address family\n"
10233#endif
10234 "Address family modifier\n"
10235 "Address family modifier\n"
10236 "Detailed information on TCP and BGP neighbor connections\n"
10237 "Neighbor to display information about\n"
10238 "Neighbor to display information about\n"
10239 "Display the advertised routes to neighbor\n"
10240 "Display the received routes from neighbor\n")
10241{
10242 int afi;
10243 int safi;
10244 int in;
10245 struct peer *peer;
10246
10247#ifdef HAVE_IPV6
10248 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10249#else
10250 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10251#endif
10252
10253 if (! peer)
10254 return CMD_WARNING;
10255
10256#ifdef HAVE_IPV6
10257 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10258 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10259 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10260#else
10261 afi = AFI_IP;
10262 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10263 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10264#endif
10265
10266 return peer_adj_routes (vty, peer, afi, safi, in);
10267}
10268
paul718e3742002-12-13 20:15:29 +000010269DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10270 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10271 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10272 SHOW_STR
10273 IP_STR
10274 BGP_STR
10275 "Detailed information on TCP and BGP neighbor connections\n"
10276 "Neighbor to display information about\n"
10277 "Neighbor to display information about\n"
10278 "Display information received from a BGP neighbor\n"
10279 "Display the prefixlist filter\n")
10280{
10281 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010282 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010283 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010284 int count, ret;
paul718e3742002-12-13 20:15:29 +000010285
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010286 ret = str2sockunion (argv[0], &su);
10287 if (ret < 0)
10288 {
10289 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10290 return CMD_WARNING;
10291 }
paul718e3742002-12-13 20:15:29 +000010292
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010293 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010294 if (! peer)
10295 return CMD_WARNING;
10296
10297 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10298 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10299 if (count)
10300 {
10301 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10302 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10303 }
10304
10305 return CMD_SUCCESS;
10306}
10307
10308DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10309 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10310 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10311 SHOW_STR
10312 IP_STR
10313 BGP_STR
10314 "Address family\n"
10315 "Address Family modifier\n"
10316 "Address Family modifier\n"
10317 "Detailed information on TCP and BGP neighbor connections\n"
10318 "Neighbor to display information about\n"
10319 "Neighbor to display information about\n"
10320 "Display information received from a BGP neighbor\n"
10321 "Display the prefixlist filter\n")
10322{
10323 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010324 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010325 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010326 int count, ret;
paul718e3742002-12-13 20:15:29 +000010327
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010328 ret = str2sockunion (argv[1], &su);
10329 if (ret < 0)
10330 {
10331 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10332 return CMD_WARNING;
10333 }
paul718e3742002-12-13 20:15:29 +000010334
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010335 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010336 if (! peer)
10337 return CMD_WARNING;
10338
10339 if (strncmp (argv[0], "m", 1) == 0)
10340 {
10341 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10342 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10343 if (count)
10344 {
10345 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10346 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10347 }
10348 }
10349 else
10350 {
10351 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10352 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10353 if (count)
10354 {
10355 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10356 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10357 }
10358 }
10359
10360 return CMD_SUCCESS;
10361}
10362
10363
10364#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010365ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010366 show_bgp_neighbor_received_routes_cmd,
10367 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10368 SHOW_STR
10369 BGP_STR
10370 "Detailed information on TCP and BGP neighbor connections\n"
10371 "Neighbor to display information about\n"
10372 "Neighbor to display information about\n"
10373 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010374
paulbb46e942003-10-24 19:02:03 +000010375ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010376 show_bgp_ipv6_neighbor_received_routes_cmd,
10377 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10378 SHOW_STR
10379 BGP_STR
10380 "Address family\n"
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display the received routes from neighbor\n")
10385
10386DEFUN (show_bgp_neighbor_received_prefix_filter,
10387 show_bgp_neighbor_received_prefix_filter_cmd,
10388 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10389 SHOW_STR
10390 BGP_STR
10391 "Detailed information on TCP and BGP neighbor connections\n"
10392 "Neighbor to display information about\n"
10393 "Neighbor to display information about\n"
10394 "Display information received from a BGP neighbor\n"
10395 "Display the prefixlist filter\n")
10396{
10397 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010398 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010399 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010400 int count, ret;
paul718e3742002-12-13 20:15:29 +000010401
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010402 ret = str2sockunion (argv[0], &su);
10403 if (ret < 0)
10404 {
10405 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10406 return CMD_WARNING;
10407 }
paul718e3742002-12-13 20:15:29 +000010408
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010409 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010410 if (! peer)
10411 return CMD_WARNING;
10412
10413 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10414 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10415 if (count)
10416 {
10417 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10418 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10419 }
10420
10421 return CMD_SUCCESS;
10422}
10423
10424ALIAS (show_bgp_neighbor_received_prefix_filter,
10425 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10426 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10427 SHOW_STR
10428 BGP_STR
10429 "Address family\n"
10430 "Detailed information on TCP and BGP neighbor connections\n"
10431 "Neighbor to display information about\n"
10432 "Neighbor to display information about\n"
10433 "Display information received from a BGP neighbor\n"
10434 "Display the prefixlist filter\n")
10435
10436/* old command */
paulbb46e942003-10-24 19:02:03 +000010437ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010438 ipv6_bgp_neighbor_received_routes_cmd,
10439 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10440 SHOW_STR
10441 IPV6_STR
10442 BGP_STR
10443 "Detailed information on TCP and BGP neighbor connections\n"
10444 "Neighbor to display information about\n"
10445 "Neighbor to display information about\n"
10446 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010447
10448/* old command */
10449DEFUN (ipv6_mbgp_neighbor_received_routes,
10450 ipv6_mbgp_neighbor_received_routes_cmd,
10451 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10452 SHOW_STR
10453 IPV6_STR
10454 MBGP_STR
10455 "Detailed information on TCP and BGP neighbor connections\n"
10456 "Neighbor to display information about\n"
10457 "Neighbor to display information about\n"
10458 "Display the received routes from neighbor\n")
10459{
paulbb46e942003-10-24 19:02:03 +000010460 struct peer *peer;
10461
10462 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10463 if (! peer)
10464 return CMD_WARNING;
10465
10466 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010467}
paulbb46e942003-10-24 19:02:03 +000010468
10469DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10470 show_bgp_view_neighbor_received_prefix_filter_cmd,
10471 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10472 SHOW_STR
10473 BGP_STR
10474 "BGP view\n"
10475 "View name\n"
10476 "Detailed information on TCP and BGP neighbor connections\n"
10477 "Neighbor to display information about\n"
10478 "Neighbor to display information about\n"
10479 "Display information received from a BGP neighbor\n"
10480 "Display the prefixlist filter\n")
10481{
10482 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010483 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010484 struct peer *peer;
10485 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010486 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010487
10488 /* BGP structure lookup. */
10489 bgp = bgp_lookup_by_name (argv[0]);
10490 if (bgp == NULL)
10491 {
10492 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10493 return CMD_WARNING;
10494 }
10495
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010496 ret = str2sockunion (argv[1], &su);
10497 if (ret < 0)
10498 {
10499 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10500 return CMD_WARNING;
10501 }
paulbb46e942003-10-24 19:02:03 +000010502
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010503 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010504 if (! peer)
10505 return CMD_WARNING;
10506
10507 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10508 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10509 if (count)
10510 {
10511 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10512 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10513 }
10514
10515 return CMD_SUCCESS;
10516}
10517
10518ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10519 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10520 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10521 SHOW_STR
10522 BGP_STR
10523 "BGP view\n"
10524 "View name\n"
10525 "Address family\n"
10526 "Detailed information on TCP and BGP neighbor connections\n"
10527 "Neighbor to display information about\n"
10528 "Neighbor to display information about\n"
10529 "Display information received from a BGP neighbor\n"
10530 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010531#endif /* HAVE_IPV6 */
10532
paul94f2b392005-06-28 12:44:16 +000010533static int
paulbb46e942003-10-24 19:02:03 +000010534bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010535 safi_t safi, enum bgp_show_type type)
10536{
paul718e3742002-12-13 20:15:29 +000010537 if (! peer || ! peer->afc[afi][safi])
10538 {
10539 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010540 return CMD_WARNING;
10541 }
10542
ajs5a646652004-11-05 01:25:55 +000010543 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010544}
10545
10546DEFUN (show_ip_bgp_neighbor_routes,
10547 show_ip_bgp_neighbor_routes_cmd,
10548 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10549 SHOW_STR
10550 IP_STR
10551 BGP_STR
10552 "Detailed information on TCP and BGP neighbor connections\n"
10553 "Neighbor to display information about\n"
10554 "Neighbor to display information about\n"
10555 "Display routes learned from neighbor\n")
10556{
paulbb46e942003-10-24 19:02:03 +000010557 struct peer *peer;
10558
10559 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10560 if (! peer)
10561 return CMD_WARNING;
10562
10563 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010564 bgp_show_type_neighbor);
10565}
10566
10567DEFUN (show_ip_bgp_neighbor_flap,
10568 show_ip_bgp_neighbor_flap_cmd,
10569 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10570 SHOW_STR
10571 IP_STR
10572 BGP_STR
10573 "Detailed information on TCP and BGP neighbor connections\n"
10574 "Neighbor to display information about\n"
10575 "Neighbor to display information about\n"
10576 "Display flap statistics of the routes learned from neighbor\n")
10577{
paulbb46e942003-10-24 19:02:03 +000010578 struct peer *peer;
10579
10580 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10581 if (! peer)
10582 return CMD_WARNING;
10583
10584 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010585 bgp_show_type_flap_neighbor);
10586}
10587
10588DEFUN (show_ip_bgp_neighbor_damp,
10589 show_ip_bgp_neighbor_damp_cmd,
10590 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10591 SHOW_STR
10592 IP_STR
10593 BGP_STR
10594 "Detailed information on TCP and BGP neighbor connections\n"
10595 "Neighbor to display information about\n"
10596 "Neighbor to display information about\n"
10597 "Display the dampened routes received from neighbor\n")
10598{
paulbb46e942003-10-24 19:02:03 +000010599 struct peer *peer;
10600
10601 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10602 if (! peer)
10603 return CMD_WARNING;
10604
10605 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010606 bgp_show_type_damp_neighbor);
10607}
10608
10609DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10610 show_ip_bgp_ipv4_neighbor_routes_cmd,
10611 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10612 SHOW_STR
10613 IP_STR
10614 BGP_STR
10615 "Address family\n"
10616 "Address Family modifier\n"
10617 "Address Family modifier\n"
10618 "Detailed information on TCP and BGP neighbor connections\n"
10619 "Neighbor to display information about\n"
10620 "Neighbor to display information about\n"
10621 "Display routes learned from neighbor\n")
10622{
paulbb46e942003-10-24 19:02:03 +000010623 struct peer *peer;
10624
10625 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10626 if (! peer)
10627 return CMD_WARNING;
10628
paul718e3742002-12-13 20:15:29 +000010629 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010630 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010631 bgp_show_type_neighbor);
10632
paulbb46e942003-10-24 19:02:03 +000010633 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010634 bgp_show_type_neighbor);
10635}
paulbb46e942003-10-24 19:02:03 +000010636
paulfee0f4c2004-09-13 05:12:46 +000010637DEFUN (show_ip_bgp_view_rsclient,
10638 show_ip_bgp_view_rsclient_cmd,
10639 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10640 SHOW_STR
10641 IP_STR
10642 BGP_STR
10643 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010644 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010645 "Information about Route Server Client\n"
10646 NEIGHBOR_ADDR_STR)
10647{
10648 struct bgp_table *table;
10649 struct peer *peer;
10650
10651 if (argc == 2)
10652 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10653 else
10654 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10655
10656 if (! peer)
10657 return CMD_WARNING;
10658
10659 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10660 {
10661 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10662 VTY_NEWLINE);
10663 return CMD_WARNING;
10664 }
10665
10666 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10667 PEER_FLAG_RSERVER_CLIENT))
10668 {
10669 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10670 VTY_NEWLINE);
10671 return CMD_WARNING;
10672 }
10673
10674 table = peer->rib[AFI_IP][SAFI_UNICAST];
10675
ajs5a646652004-11-05 01:25:55 +000010676 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010677}
10678
10679ALIAS (show_ip_bgp_view_rsclient,
10680 show_ip_bgp_rsclient_cmd,
10681 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10682 SHOW_STR
10683 IP_STR
10684 BGP_STR
10685 "Information about Route Server Client\n"
10686 NEIGHBOR_ADDR_STR)
10687
Michael Lambert95cbbd22010-07-23 14:43:04 -040010688DEFUN (show_bgp_view_ipv4_safi_rsclient,
10689 show_bgp_view_ipv4_safi_rsclient_cmd,
10690 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10691 SHOW_STR
10692 BGP_STR
10693 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010694 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010695 "Address family\n"
10696 "Address Family modifier\n"
10697 "Address Family modifier\n"
10698 "Information about Route Server Client\n"
10699 NEIGHBOR_ADDR_STR)
10700{
10701 struct bgp_table *table;
10702 struct peer *peer;
10703 safi_t safi;
10704
10705 if (argc == 3) {
10706 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10707 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10708 } else {
10709 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10710 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10711 }
10712
10713 if (! peer)
10714 return CMD_WARNING;
10715
10716 if (! peer->afc[AFI_IP][safi])
10717 {
10718 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10719 VTY_NEWLINE);
10720 return CMD_WARNING;
10721 }
10722
10723 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10724 PEER_FLAG_RSERVER_CLIENT))
10725 {
10726 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10727 VTY_NEWLINE);
10728 return CMD_WARNING;
10729 }
10730
10731 table = peer->rib[AFI_IP][safi];
10732
10733 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10734}
10735
10736ALIAS (show_bgp_view_ipv4_safi_rsclient,
10737 show_bgp_ipv4_safi_rsclient_cmd,
10738 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10739 SHOW_STR
10740 BGP_STR
10741 "Address family\n"
10742 "Address Family modifier\n"
10743 "Address Family modifier\n"
10744 "Information about Route Server Client\n"
10745 NEIGHBOR_ADDR_STR)
10746
paulfee0f4c2004-09-13 05:12:46 +000010747DEFUN (show_ip_bgp_view_rsclient_route,
10748 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010749 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010750 SHOW_STR
10751 IP_STR
10752 BGP_STR
10753 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010754 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010755 "Information about Route Server Client\n"
10756 NEIGHBOR_ADDR_STR
10757 "Network in the BGP routing table to display\n")
10758{
10759 struct bgp *bgp;
10760 struct peer *peer;
10761
10762 /* BGP structure lookup. */
10763 if (argc == 3)
10764 {
10765 bgp = bgp_lookup_by_name (argv[0]);
10766 if (bgp == NULL)
10767 {
10768 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10769 return CMD_WARNING;
10770 }
10771 }
10772 else
10773 {
10774 bgp = bgp_get_default ();
10775 if (bgp == NULL)
10776 {
10777 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10778 return CMD_WARNING;
10779 }
10780 }
10781
10782 if (argc == 3)
10783 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10784 else
10785 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10786
10787 if (! peer)
10788 return CMD_WARNING;
10789
10790 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10791 {
10792 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10793 VTY_NEWLINE);
10794 return CMD_WARNING;
10795}
10796
10797 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10798 PEER_FLAG_RSERVER_CLIENT))
10799 {
10800 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10801 VTY_NEWLINE);
10802 return CMD_WARNING;
10803 }
10804
10805 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10806 (argc == 3) ? argv[2] : argv[1],
10807 AFI_IP, SAFI_UNICAST, NULL, 0);
10808}
10809
10810ALIAS (show_ip_bgp_view_rsclient_route,
10811 show_ip_bgp_rsclient_route_cmd,
10812 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10813 SHOW_STR
10814 IP_STR
10815 BGP_STR
10816 "Information about Route Server Client\n"
10817 NEIGHBOR_ADDR_STR
10818 "Network in the BGP routing table to display\n")
10819
Michael Lambert95cbbd22010-07-23 14:43:04 -040010820DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10821 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10822 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10823 SHOW_STR
10824 BGP_STR
10825 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010826 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010827 "Address family\n"
10828 "Address Family modifier\n"
10829 "Address Family modifier\n"
10830 "Information about Route Server Client\n"
10831 NEIGHBOR_ADDR_STR
10832 "Network in the BGP routing table to display\n")
10833{
10834 struct bgp *bgp;
10835 struct peer *peer;
10836 safi_t safi;
10837
10838 /* BGP structure lookup. */
10839 if (argc == 4)
10840 {
10841 bgp = bgp_lookup_by_name (argv[0]);
10842 if (bgp == NULL)
10843 {
10844 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10845 return CMD_WARNING;
10846 }
10847 }
10848 else
10849 {
10850 bgp = bgp_get_default ();
10851 if (bgp == NULL)
10852 {
10853 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10854 return CMD_WARNING;
10855 }
10856 }
10857
10858 if (argc == 4) {
10859 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10860 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10861 } else {
10862 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10863 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10864 }
10865
10866 if (! peer)
10867 return CMD_WARNING;
10868
10869 if (! peer->afc[AFI_IP][safi])
10870 {
10871 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10872 VTY_NEWLINE);
10873 return CMD_WARNING;
10874}
10875
10876 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10877 PEER_FLAG_RSERVER_CLIENT))
10878 {
10879 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10880 VTY_NEWLINE);
10881 return CMD_WARNING;
10882 }
10883
10884 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10885 (argc == 4) ? argv[3] : argv[2],
10886 AFI_IP, safi, NULL, 0);
10887}
10888
10889ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10890 show_bgp_ipv4_safi_rsclient_route_cmd,
10891 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10892 SHOW_STR
10893 BGP_STR
10894 "Address family\n"
10895 "Address Family modifier\n"
10896 "Address Family modifier\n"
10897 "Information about Route Server Client\n"
10898 NEIGHBOR_ADDR_STR
10899 "Network in the BGP routing table to display\n")
10900
paulfee0f4c2004-09-13 05:12:46 +000010901DEFUN (show_ip_bgp_view_rsclient_prefix,
10902 show_ip_bgp_view_rsclient_prefix_cmd,
10903 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10904 SHOW_STR
10905 IP_STR
10906 BGP_STR
10907 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010908 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010909 "Information about Route Server Client\n"
10910 NEIGHBOR_ADDR_STR
10911 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10912{
10913 struct bgp *bgp;
10914 struct peer *peer;
10915
10916 /* BGP structure lookup. */
10917 if (argc == 3)
10918 {
10919 bgp = bgp_lookup_by_name (argv[0]);
10920 if (bgp == NULL)
10921 {
10922 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10923 return CMD_WARNING;
10924 }
10925 }
10926 else
10927 {
10928 bgp = bgp_get_default ();
10929 if (bgp == NULL)
10930 {
10931 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10932 return CMD_WARNING;
10933 }
10934 }
10935
10936 if (argc == 3)
10937 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10938 else
10939 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10940
10941 if (! peer)
10942 return CMD_WARNING;
10943
10944 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10945 {
10946 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10947 VTY_NEWLINE);
10948 return CMD_WARNING;
10949}
10950
10951 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10952 PEER_FLAG_RSERVER_CLIENT))
10953{
10954 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10955 VTY_NEWLINE);
10956 return CMD_WARNING;
10957 }
10958
10959 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10960 (argc == 3) ? argv[2] : argv[1],
10961 AFI_IP, SAFI_UNICAST, NULL, 1);
10962}
10963
10964ALIAS (show_ip_bgp_view_rsclient_prefix,
10965 show_ip_bgp_rsclient_prefix_cmd,
10966 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10967 SHOW_STR
10968 IP_STR
10969 BGP_STR
10970 "Information about Route Server Client\n"
10971 NEIGHBOR_ADDR_STR
10972 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10973
Michael Lambert95cbbd22010-07-23 14:43:04 -040010974DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10975 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10976 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10977 SHOW_STR
10978 BGP_STR
10979 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010980 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010981 "Address family\n"
10982 "Address Family modifier\n"
10983 "Address Family modifier\n"
10984 "Information about Route Server Client\n"
10985 NEIGHBOR_ADDR_STR
10986 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10987{
10988 struct bgp *bgp;
10989 struct peer *peer;
10990 safi_t safi;
10991
10992 /* BGP structure lookup. */
10993 if (argc == 4)
10994 {
10995 bgp = bgp_lookup_by_name (argv[0]);
10996 if (bgp == NULL)
10997 {
10998 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10999 return CMD_WARNING;
11000 }
11001 }
11002 else
11003 {
11004 bgp = bgp_get_default ();
11005 if (bgp == NULL)
11006 {
11007 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11008 return CMD_WARNING;
11009 }
11010 }
11011
11012 if (argc == 4) {
11013 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11014 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11015 } else {
11016 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11017 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11018 }
11019
11020 if (! peer)
11021 return CMD_WARNING;
11022
11023 if (! peer->afc[AFI_IP][safi])
11024 {
11025 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11026 VTY_NEWLINE);
11027 return CMD_WARNING;
11028}
11029
11030 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11031 PEER_FLAG_RSERVER_CLIENT))
11032{
11033 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11034 VTY_NEWLINE);
11035 return CMD_WARNING;
11036 }
11037
11038 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11039 (argc == 4) ? argv[3] : argv[2],
11040 AFI_IP, safi, NULL, 1);
11041}
11042
11043ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11044 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11045 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11046 SHOW_STR
11047 BGP_STR
11048 "Address family\n"
11049 "Address Family modifier\n"
11050 "Address Family modifier\n"
11051 "Information about Route Server Client\n"
11052 NEIGHBOR_ADDR_STR
11053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011054
paul718e3742002-12-13 20:15:29 +000011055#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011056DEFUN (show_bgp_view_neighbor_routes,
11057 show_bgp_view_neighbor_routes_cmd,
11058 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11059 SHOW_STR
11060 BGP_STR
11061 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011062 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011063 "Detailed information on TCP and BGP neighbor connections\n"
11064 "Neighbor to display information about\n"
11065 "Neighbor to display information about\n"
11066 "Display routes learned from neighbor\n")
11067{
11068 struct peer *peer;
11069
11070 if (argc == 2)
11071 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11072 else
11073 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11074
11075 if (! peer)
11076 return CMD_WARNING;
11077
11078 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11079 bgp_show_type_neighbor);
11080}
11081
11082ALIAS (show_bgp_view_neighbor_routes,
11083 show_bgp_view_ipv6_neighbor_routes_cmd,
11084 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11085 SHOW_STR
11086 BGP_STR
11087 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011088 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011089 "Address family\n"
11090 "Detailed information on TCP and BGP neighbor connections\n"
11091 "Neighbor to display information about\n"
11092 "Neighbor to display information about\n"
11093 "Display routes learned from neighbor\n")
11094
11095DEFUN (show_bgp_view_neighbor_damp,
11096 show_bgp_view_neighbor_damp_cmd,
11097 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11098 SHOW_STR
11099 BGP_STR
11100 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011101 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011102 "Detailed information on TCP and BGP neighbor connections\n"
11103 "Neighbor to display information about\n"
11104 "Neighbor to display information about\n"
11105 "Display the dampened routes received from neighbor\n")
11106{
11107 struct peer *peer;
11108
11109 if (argc == 2)
11110 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11111 else
11112 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11113
11114 if (! peer)
11115 return CMD_WARNING;
11116
11117 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11118 bgp_show_type_damp_neighbor);
11119}
11120
11121ALIAS (show_bgp_view_neighbor_damp,
11122 show_bgp_view_ipv6_neighbor_damp_cmd,
11123 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11124 SHOW_STR
11125 BGP_STR
11126 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011127 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011128 "Address family\n"
11129 "Detailed information on TCP and BGP neighbor connections\n"
11130 "Neighbor to display information about\n"
11131 "Neighbor to display information about\n"
11132 "Display the dampened routes received from neighbor\n")
11133
11134DEFUN (show_bgp_view_neighbor_flap,
11135 show_bgp_view_neighbor_flap_cmd,
11136 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11137 SHOW_STR
11138 BGP_STR
11139 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011140 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Display flap statistics of the routes learned from neighbor\n")
11145{
11146 struct peer *peer;
11147
11148 if (argc == 2)
11149 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11150 else
11151 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11152
11153 if (! peer)
11154 return CMD_WARNING;
11155
11156 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11157 bgp_show_type_flap_neighbor);
11158}
11159
11160ALIAS (show_bgp_view_neighbor_flap,
11161 show_bgp_view_ipv6_neighbor_flap_cmd,
11162 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11163 SHOW_STR
11164 BGP_STR
11165 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011166 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011167 "Address family\n"
11168 "Detailed information on TCP and BGP neighbor connections\n"
11169 "Neighbor to display information about\n"
11170 "Neighbor to display information about\n"
11171 "Display flap statistics of the routes learned from neighbor\n")
11172
11173ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011174 show_bgp_neighbor_routes_cmd,
11175 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11176 SHOW_STR
11177 BGP_STR
11178 "Detailed information on TCP and BGP neighbor connections\n"
11179 "Neighbor to display information about\n"
11180 "Neighbor to display information about\n"
11181 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011182
paulbb46e942003-10-24 19:02:03 +000011183
11184ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011185 show_bgp_ipv6_neighbor_routes_cmd,
11186 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11187 SHOW_STR
11188 BGP_STR
11189 "Address family\n"
11190 "Detailed information on TCP and BGP neighbor connections\n"
11191 "Neighbor to display information about\n"
11192 "Neighbor to display information about\n"
11193 "Display routes learned from neighbor\n")
11194
11195/* old command */
paulbb46e942003-10-24 19:02:03 +000011196ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011197 ipv6_bgp_neighbor_routes_cmd,
11198 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11199 SHOW_STR
11200 IPV6_STR
11201 BGP_STR
11202 "Detailed information on TCP and BGP neighbor connections\n"
11203 "Neighbor to display information about\n"
11204 "Neighbor to display information about\n"
11205 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011206
11207/* old command */
11208DEFUN (ipv6_mbgp_neighbor_routes,
11209 ipv6_mbgp_neighbor_routes_cmd,
11210 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11211 SHOW_STR
11212 IPV6_STR
11213 MBGP_STR
11214 "Detailed information on TCP and BGP neighbor connections\n"
11215 "Neighbor to display information about\n"
11216 "Neighbor to display information about\n"
11217 "Display routes learned from neighbor\n")
11218{
paulbb46e942003-10-24 19:02:03 +000011219 struct peer *peer;
11220
11221 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11222 if (! peer)
11223 return CMD_WARNING;
11224
11225 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011226 bgp_show_type_neighbor);
11227}
paulbb46e942003-10-24 19:02:03 +000011228
11229ALIAS (show_bgp_view_neighbor_flap,
11230 show_bgp_neighbor_flap_cmd,
11231 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11232 SHOW_STR
11233 BGP_STR
11234 "Detailed information on TCP and BGP neighbor connections\n"
11235 "Neighbor to display information about\n"
11236 "Neighbor to display information about\n"
11237 "Display flap statistics of the routes learned from neighbor\n")
11238
11239ALIAS (show_bgp_view_neighbor_flap,
11240 show_bgp_ipv6_neighbor_flap_cmd,
11241 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11242 SHOW_STR
11243 BGP_STR
11244 "Address family\n"
11245 "Detailed information on TCP and BGP neighbor connections\n"
11246 "Neighbor to display information about\n"
11247 "Neighbor to display information about\n"
11248 "Display flap statistics of the routes learned from neighbor\n")
11249
11250ALIAS (show_bgp_view_neighbor_damp,
11251 show_bgp_neighbor_damp_cmd,
11252 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11253 SHOW_STR
11254 BGP_STR
11255 "Detailed information on TCP and BGP neighbor connections\n"
11256 "Neighbor to display information about\n"
11257 "Neighbor to display information about\n"
11258 "Display the dampened routes received from neighbor\n")
11259
11260ALIAS (show_bgp_view_neighbor_damp,
11261 show_bgp_ipv6_neighbor_damp_cmd,
11262 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11263 SHOW_STR
11264 BGP_STR
11265 "Address family\n"
11266 "Detailed information on TCP and BGP neighbor connections\n"
11267 "Neighbor to display information about\n"
11268 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011269 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011270
11271DEFUN (show_bgp_view_rsclient,
11272 show_bgp_view_rsclient_cmd,
11273 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11274 SHOW_STR
11275 BGP_STR
11276 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011277 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011278 "Information about Route Server Client\n"
11279 NEIGHBOR_ADDR_STR)
11280{
11281 struct bgp_table *table;
11282 struct peer *peer;
11283
11284 if (argc == 2)
11285 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11286 else
11287 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11288
11289 if (! peer)
11290 return CMD_WARNING;
11291
11292 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11293 {
11294 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11295 VTY_NEWLINE);
11296 return CMD_WARNING;
11297 }
11298
11299 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11300 PEER_FLAG_RSERVER_CLIENT))
11301 {
11302 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11303 VTY_NEWLINE);
11304 return CMD_WARNING;
11305 }
11306
11307 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11308
ajs5a646652004-11-05 01:25:55 +000011309 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011310}
11311
11312ALIAS (show_bgp_view_rsclient,
11313 show_bgp_rsclient_cmd,
11314 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11315 SHOW_STR
11316 BGP_STR
11317 "Information about Route Server Client\n"
11318 NEIGHBOR_ADDR_STR)
11319
Michael Lambert95cbbd22010-07-23 14:43:04 -040011320DEFUN (show_bgp_view_ipv6_safi_rsclient,
11321 show_bgp_view_ipv6_safi_rsclient_cmd,
11322 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11323 SHOW_STR
11324 BGP_STR
11325 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011326 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011327 "Address family\n"
11328 "Address Family modifier\n"
11329 "Address Family modifier\n"
11330 "Information about Route Server Client\n"
11331 NEIGHBOR_ADDR_STR)
11332{
11333 struct bgp_table *table;
11334 struct peer *peer;
11335 safi_t safi;
11336
11337 if (argc == 3) {
11338 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11339 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11340 } else {
11341 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11342 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11343 }
11344
11345 if (! peer)
11346 return CMD_WARNING;
11347
11348 if (! peer->afc[AFI_IP6][safi])
11349 {
11350 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11351 VTY_NEWLINE);
11352 return CMD_WARNING;
11353 }
11354
11355 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11356 PEER_FLAG_RSERVER_CLIENT))
11357 {
11358 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11359 VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362
11363 table = peer->rib[AFI_IP6][safi];
11364
11365 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11366}
11367
11368ALIAS (show_bgp_view_ipv6_safi_rsclient,
11369 show_bgp_ipv6_safi_rsclient_cmd,
11370 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11371 SHOW_STR
11372 BGP_STR
11373 "Address family\n"
11374 "Address Family modifier\n"
11375 "Address Family modifier\n"
11376 "Information about Route Server Client\n"
11377 NEIGHBOR_ADDR_STR)
11378
paulfee0f4c2004-09-13 05:12:46 +000011379DEFUN (show_bgp_view_rsclient_route,
11380 show_bgp_view_rsclient_route_cmd,
11381 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11382 SHOW_STR
11383 BGP_STR
11384 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011385 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011386 "Information about Route Server Client\n"
11387 NEIGHBOR_ADDR_STR
11388 "Network in the BGP routing table to display\n")
11389{
11390 struct bgp *bgp;
11391 struct peer *peer;
11392
11393 /* BGP structure lookup. */
11394 if (argc == 3)
11395 {
11396 bgp = bgp_lookup_by_name (argv[0]);
11397 if (bgp == NULL)
11398 {
11399 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11400 return CMD_WARNING;
11401 }
11402 }
11403 else
11404 {
11405 bgp = bgp_get_default ();
11406 if (bgp == NULL)
11407 {
11408 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11409 return CMD_WARNING;
11410 }
11411 }
11412
11413 if (argc == 3)
11414 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11415 else
11416 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11417
11418 if (! peer)
11419 return CMD_WARNING;
11420
11421 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11422 {
11423 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11424 VTY_NEWLINE);
11425 return CMD_WARNING;
11426 }
11427
11428 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11429 PEER_FLAG_RSERVER_CLIENT))
11430 {
11431 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11432 VTY_NEWLINE);
11433 return CMD_WARNING;
11434 }
11435
11436 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11437 (argc == 3) ? argv[2] : argv[1],
11438 AFI_IP6, SAFI_UNICAST, NULL, 0);
11439}
11440
11441ALIAS (show_bgp_view_rsclient_route,
11442 show_bgp_rsclient_route_cmd,
11443 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11444 SHOW_STR
11445 BGP_STR
11446 "Information about Route Server Client\n"
11447 NEIGHBOR_ADDR_STR
11448 "Network in the BGP routing table to display\n")
11449
Michael Lambert95cbbd22010-07-23 14:43:04 -040011450DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11451 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11452 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11453 SHOW_STR
11454 BGP_STR
11455 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011456 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011457 "Address family\n"
11458 "Address Family modifier\n"
11459 "Address Family modifier\n"
11460 "Information about Route Server Client\n"
11461 NEIGHBOR_ADDR_STR
11462 "Network in the BGP routing table to display\n")
11463{
11464 struct bgp *bgp;
11465 struct peer *peer;
11466 safi_t safi;
11467
11468 /* BGP structure lookup. */
11469 if (argc == 4)
11470 {
11471 bgp = bgp_lookup_by_name (argv[0]);
11472 if (bgp == NULL)
11473 {
11474 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11475 return CMD_WARNING;
11476 }
11477 }
11478 else
11479 {
11480 bgp = bgp_get_default ();
11481 if (bgp == NULL)
11482 {
11483 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11484 return CMD_WARNING;
11485 }
11486 }
11487
11488 if (argc == 4) {
11489 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11490 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11491 } else {
11492 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11493 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11494 }
11495
11496 if (! peer)
11497 return CMD_WARNING;
11498
11499 if (! peer->afc[AFI_IP6][safi])
11500 {
11501 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11502 VTY_NEWLINE);
11503 return CMD_WARNING;
11504}
11505
11506 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11507 PEER_FLAG_RSERVER_CLIENT))
11508 {
11509 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11510 VTY_NEWLINE);
11511 return CMD_WARNING;
11512 }
11513
11514 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11515 (argc == 4) ? argv[3] : argv[2],
11516 AFI_IP6, safi, NULL, 0);
11517}
11518
11519ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11520 show_bgp_ipv6_safi_rsclient_route_cmd,
11521 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11522 SHOW_STR
11523 BGP_STR
11524 "Address family\n"
11525 "Address Family modifier\n"
11526 "Address Family modifier\n"
11527 "Information about Route Server Client\n"
11528 NEIGHBOR_ADDR_STR
11529 "Network in the BGP routing table to display\n")
11530
paulfee0f4c2004-09-13 05:12:46 +000011531DEFUN (show_bgp_view_rsclient_prefix,
11532 show_bgp_view_rsclient_prefix_cmd,
11533 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11534 SHOW_STR
11535 BGP_STR
11536 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011537 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011538 "Information about Route Server Client\n"
11539 NEIGHBOR_ADDR_STR
11540 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11541{
11542 struct bgp *bgp;
11543 struct peer *peer;
11544
11545 /* BGP structure lookup. */
11546 if (argc == 3)
11547 {
11548 bgp = bgp_lookup_by_name (argv[0]);
11549 if (bgp == NULL)
11550 {
11551 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11552 return CMD_WARNING;
11553 }
11554 }
11555 else
11556 {
11557 bgp = bgp_get_default ();
11558 if (bgp == NULL)
11559 {
11560 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11561 return CMD_WARNING;
11562 }
11563 }
11564
11565 if (argc == 3)
11566 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11567 else
11568 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11569
11570 if (! peer)
11571 return CMD_WARNING;
11572
11573 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11574 {
11575 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11576 VTY_NEWLINE);
11577 return CMD_WARNING;
11578 }
11579
11580 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11581 PEER_FLAG_RSERVER_CLIENT))
11582 {
11583 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11584 VTY_NEWLINE);
11585 return CMD_WARNING;
11586 }
11587
11588 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11589 (argc == 3) ? argv[2] : argv[1],
11590 AFI_IP6, SAFI_UNICAST, NULL, 1);
11591}
11592
11593ALIAS (show_bgp_view_rsclient_prefix,
11594 show_bgp_rsclient_prefix_cmd,
11595 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11596 SHOW_STR
11597 BGP_STR
11598 "Information about Route Server Client\n"
11599 NEIGHBOR_ADDR_STR
11600 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11601
Michael Lambert95cbbd22010-07-23 14:43:04 -040011602DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11603 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11604 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11605 SHOW_STR
11606 BGP_STR
11607 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011608 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011609 "Address family\n"
11610 "Address Family modifier\n"
11611 "Address Family modifier\n"
11612 "Information about Route Server Client\n"
11613 NEIGHBOR_ADDR_STR
11614 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11615{
11616 struct bgp *bgp;
11617 struct peer *peer;
11618 safi_t safi;
11619
11620 /* BGP structure lookup. */
11621 if (argc == 4)
11622 {
11623 bgp = bgp_lookup_by_name (argv[0]);
11624 if (bgp == NULL)
11625 {
11626 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11627 return CMD_WARNING;
11628 }
11629 }
11630 else
11631 {
11632 bgp = bgp_get_default ();
11633 if (bgp == NULL)
11634 {
11635 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11636 return CMD_WARNING;
11637 }
11638 }
11639
11640 if (argc == 4) {
11641 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11642 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11643 } else {
11644 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11645 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11646 }
11647
11648 if (! peer)
11649 return CMD_WARNING;
11650
11651 if (! peer->afc[AFI_IP6][safi])
11652 {
11653 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11654 VTY_NEWLINE);
11655 return CMD_WARNING;
11656}
11657
11658 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11659 PEER_FLAG_RSERVER_CLIENT))
11660{
11661 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11662 VTY_NEWLINE);
11663 return CMD_WARNING;
11664 }
11665
11666 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11667 (argc == 4) ? argv[3] : argv[2],
11668 AFI_IP6, safi, NULL, 1);
11669}
11670
11671ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11672 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11673 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11674 SHOW_STR
11675 BGP_STR
11676 "Address family\n"
11677 "Address Family modifier\n"
11678 "Address Family modifier\n"
11679 "Information about Route Server Client\n"
11680 NEIGHBOR_ADDR_STR
11681 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11682
paul718e3742002-12-13 20:15:29 +000011683#endif /* HAVE_IPV6 */
11684
11685struct bgp_table *bgp_distance_table;
11686
11687struct bgp_distance
11688{
11689 /* Distance value for the IP source prefix. */
11690 u_char distance;
11691
11692 /* Name of the access-list to be matched. */
11693 char *access_list;
11694};
11695
paul94f2b392005-06-28 12:44:16 +000011696static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011697bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011698{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011699 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011700}
11701
paul94f2b392005-06-28 12:44:16 +000011702static void
paul718e3742002-12-13 20:15:29 +000011703bgp_distance_free (struct bgp_distance *bdistance)
11704{
11705 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11706}
11707
paul94f2b392005-06-28 12:44:16 +000011708static int
paulfd79ac92004-10-13 05:06:08 +000011709bgp_distance_set (struct vty *vty, const char *distance_str,
11710 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011711{
11712 int ret;
11713 struct prefix_ipv4 p;
11714 u_char distance;
11715 struct bgp_node *rn;
11716 struct bgp_distance *bdistance;
11717
11718 ret = str2prefix_ipv4 (ip_str, &p);
11719 if (ret == 0)
11720 {
11721 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11722 return CMD_WARNING;
11723 }
11724
11725 distance = atoi (distance_str);
11726
11727 /* Get BGP distance node. */
11728 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11729 if (rn->info)
11730 {
11731 bdistance = rn->info;
11732 bgp_unlock_node (rn);
11733 }
11734 else
11735 {
11736 bdistance = bgp_distance_new ();
11737 rn->info = bdistance;
11738 }
11739
11740 /* Set distance value. */
11741 bdistance->distance = distance;
11742
11743 /* Reset access-list configuration. */
11744 if (bdistance->access_list)
11745 {
11746 free (bdistance->access_list);
11747 bdistance->access_list = NULL;
11748 }
11749 if (access_list_str)
11750 bdistance->access_list = strdup (access_list_str);
11751
11752 return CMD_SUCCESS;
11753}
11754
paul94f2b392005-06-28 12:44:16 +000011755static int
paulfd79ac92004-10-13 05:06:08 +000011756bgp_distance_unset (struct vty *vty, const char *distance_str,
11757 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011758{
11759 int ret;
11760 struct prefix_ipv4 p;
11761 u_char distance;
11762 struct bgp_node *rn;
11763 struct bgp_distance *bdistance;
11764
11765 ret = str2prefix_ipv4 (ip_str, &p);
11766 if (ret == 0)
11767 {
11768 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11769 return CMD_WARNING;
11770 }
11771
11772 distance = atoi (distance_str);
11773
11774 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11775 if (! rn)
11776 {
11777 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11778 return CMD_WARNING;
11779 }
11780
11781 bdistance = rn->info;
11782
11783 if (bdistance->access_list)
11784 free (bdistance->access_list);
11785 bgp_distance_free (bdistance);
11786
11787 rn->info = NULL;
11788 bgp_unlock_node (rn);
11789 bgp_unlock_node (rn);
11790
11791 return CMD_SUCCESS;
11792}
11793
paul718e3742002-12-13 20:15:29 +000011794/* Apply BGP information to distance method. */
11795u_char
11796bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11797{
11798 struct bgp_node *rn;
11799 struct prefix_ipv4 q;
11800 struct peer *peer;
11801 struct bgp_distance *bdistance;
11802 struct access_list *alist;
11803 struct bgp_static *bgp_static;
11804
11805 if (! bgp)
11806 return 0;
11807
11808 if (p->family != AF_INET)
11809 return 0;
11810
11811 peer = rinfo->peer;
11812
11813 if (peer->su.sa.sa_family != AF_INET)
11814 return 0;
11815
11816 memset (&q, 0, sizeof (struct prefix_ipv4));
11817 q.family = AF_INET;
11818 q.prefix = peer->su.sin.sin_addr;
11819 q.prefixlen = IPV4_MAX_BITLEN;
11820
11821 /* Check source address. */
11822 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11823 if (rn)
11824 {
11825 bdistance = rn->info;
11826 bgp_unlock_node (rn);
11827
11828 if (bdistance->access_list)
11829 {
11830 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11831 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11832 return bdistance->distance;
11833 }
11834 else
11835 return bdistance->distance;
11836 }
11837
11838 /* Backdoor check. */
11839 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11840 if (rn)
11841 {
11842 bgp_static = rn->info;
11843 bgp_unlock_node (rn);
11844
11845 if (bgp_static->backdoor)
11846 {
11847 if (bgp->distance_local)
11848 return bgp->distance_local;
11849 else
11850 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11851 }
11852 }
11853
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011854 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011855 {
11856 if (bgp->distance_ebgp)
11857 return bgp->distance_ebgp;
11858 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11859 }
11860 else
11861 {
11862 if (bgp->distance_ibgp)
11863 return bgp->distance_ibgp;
11864 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11865 }
11866}
11867
11868DEFUN (bgp_distance,
11869 bgp_distance_cmd,
11870 "distance bgp <1-255> <1-255> <1-255>",
11871 "Define an administrative distance\n"
11872 "BGP distance\n"
11873 "Distance for routes external to the AS\n"
11874 "Distance for routes internal to the AS\n"
11875 "Distance for local routes\n")
11876{
11877 struct bgp *bgp;
11878
11879 bgp = vty->index;
11880
11881 bgp->distance_ebgp = atoi (argv[0]);
11882 bgp->distance_ibgp = atoi (argv[1]);
11883 bgp->distance_local = atoi (argv[2]);
11884 return CMD_SUCCESS;
11885}
11886
11887DEFUN (no_bgp_distance,
11888 no_bgp_distance_cmd,
11889 "no distance bgp <1-255> <1-255> <1-255>",
11890 NO_STR
11891 "Define an administrative distance\n"
11892 "BGP distance\n"
11893 "Distance for routes external to the AS\n"
11894 "Distance for routes internal to the AS\n"
11895 "Distance for local routes\n")
11896{
11897 struct bgp *bgp;
11898
11899 bgp = vty->index;
11900
11901 bgp->distance_ebgp= 0;
11902 bgp->distance_ibgp = 0;
11903 bgp->distance_local = 0;
11904 return CMD_SUCCESS;
11905}
11906
11907ALIAS (no_bgp_distance,
11908 no_bgp_distance2_cmd,
11909 "no distance bgp",
11910 NO_STR
11911 "Define an administrative distance\n"
11912 "BGP distance\n")
11913
11914DEFUN (bgp_distance_source,
11915 bgp_distance_source_cmd,
11916 "distance <1-255> A.B.C.D/M",
11917 "Define an administrative distance\n"
11918 "Administrative distance\n"
11919 "IP source prefix\n")
11920{
11921 bgp_distance_set (vty, argv[0], argv[1], NULL);
11922 return CMD_SUCCESS;
11923}
11924
11925DEFUN (no_bgp_distance_source,
11926 no_bgp_distance_source_cmd,
11927 "no distance <1-255> A.B.C.D/M",
11928 NO_STR
11929 "Define an administrative distance\n"
11930 "Administrative distance\n"
11931 "IP source prefix\n")
11932{
11933 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11934 return CMD_SUCCESS;
11935}
11936
11937DEFUN (bgp_distance_source_access_list,
11938 bgp_distance_source_access_list_cmd,
11939 "distance <1-255> A.B.C.D/M WORD",
11940 "Define an administrative distance\n"
11941 "Administrative distance\n"
11942 "IP source prefix\n"
11943 "Access list name\n")
11944{
11945 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11946 return CMD_SUCCESS;
11947}
11948
11949DEFUN (no_bgp_distance_source_access_list,
11950 no_bgp_distance_source_access_list_cmd,
11951 "no distance <1-255> A.B.C.D/M WORD",
11952 NO_STR
11953 "Define an administrative distance\n"
11954 "Administrative distance\n"
11955 "IP source prefix\n"
11956 "Access list name\n")
11957{
11958 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11959 return CMD_SUCCESS;
11960}
11961
11962DEFUN (bgp_damp_set,
11963 bgp_damp_set_cmd,
11964 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11965 "BGP Specific commands\n"
11966 "Enable route-flap dampening\n"
11967 "Half-life time for the penalty\n"
11968 "Value to start reusing a route\n"
11969 "Value to start suppressing a route\n"
11970 "Maximum duration to suppress a stable route\n")
11971{
11972 struct bgp *bgp;
11973 int half = DEFAULT_HALF_LIFE * 60;
11974 int reuse = DEFAULT_REUSE;
11975 int suppress = DEFAULT_SUPPRESS;
11976 int max = 4 * half;
11977
11978 if (argc == 4)
11979 {
11980 half = atoi (argv[0]) * 60;
11981 reuse = atoi (argv[1]);
11982 suppress = atoi (argv[2]);
11983 max = atoi (argv[3]) * 60;
11984 }
11985 else if (argc == 1)
11986 {
11987 half = atoi (argv[0]) * 60;
11988 max = 4 * half;
11989 }
11990
11991 bgp = vty->index;
11992 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11993 half, reuse, suppress, max);
11994}
11995
11996ALIAS (bgp_damp_set,
11997 bgp_damp_set2_cmd,
11998 "bgp dampening <1-45>",
11999 "BGP Specific commands\n"
12000 "Enable route-flap dampening\n"
12001 "Half-life time for the penalty\n")
12002
12003ALIAS (bgp_damp_set,
12004 bgp_damp_set3_cmd,
12005 "bgp dampening",
12006 "BGP Specific commands\n"
12007 "Enable route-flap dampening\n")
12008
12009DEFUN (bgp_damp_unset,
12010 bgp_damp_unset_cmd,
12011 "no bgp dampening",
12012 NO_STR
12013 "BGP Specific commands\n"
12014 "Enable route-flap dampening\n")
12015{
12016 struct bgp *bgp;
12017
12018 bgp = vty->index;
12019 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12020}
12021
12022ALIAS (bgp_damp_unset,
12023 bgp_damp_unset2_cmd,
12024 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12025 NO_STR
12026 "BGP Specific commands\n"
12027 "Enable route-flap dampening\n"
12028 "Half-life time for the penalty\n"
12029 "Value to start reusing a route\n"
12030 "Value to start suppressing a route\n"
12031 "Maximum duration to suppress a stable route\n")
12032
12033DEFUN (show_ip_bgp_dampened_paths,
12034 show_ip_bgp_dampened_paths_cmd,
12035 "show ip bgp dampened-paths",
12036 SHOW_STR
12037 IP_STR
12038 BGP_STR
12039 "Display paths suppressed due to dampening\n")
12040{
ajs5a646652004-11-05 01:25:55 +000012041 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12042 NULL);
paul718e3742002-12-13 20:15:29 +000012043}
12044
12045DEFUN (show_ip_bgp_flap_statistics,
12046 show_ip_bgp_flap_statistics_cmd,
12047 "show ip bgp flap-statistics",
12048 SHOW_STR
12049 IP_STR
12050 BGP_STR
12051 "Display flap statistics of routes\n")
12052{
ajs5a646652004-11-05 01:25:55 +000012053 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12054 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012055}
12056
12057/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012058static int
paulfd79ac92004-10-13 05:06:08 +000012059bgp_clear_damp_route (struct vty *vty, const char *view_name,
12060 const char *ip_str, afi_t afi, safi_t safi,
12061 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012062{
12063 int ret;
12064 struct prefix match;
12065 struct bgp_node *rn;
12066 struct bgp_node *rm;
12067 struct bgp_info *ri;
12068 struct bgp_info *ri_temp;
12069 struct bgp *bgp;
12070 struct bgp_table *table;
12071
12072 /* BGP structure lookup. */
12073 if (view_name)
12074 {
12075 bgp = bgp_lookup_by_name (view_name);
12076 if (bgp == NULL)
12077 {
12078 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12079 return CMD_WARNING;
12080 }
12081 }
12082 else
12083 {
12084 bgp = bgp_get_default ();
12085 if (bgp == NULL)
12086 {
12087 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12088 return CMD_WARNING;
12089 }
12090 }
12091
12092 /* Check IP address argument. */
12093 ret = str2prefix (ip_str, &match);
12094 if (! ret)
12095 {
12096 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12097 return CMD_WARNING;
12098 }
12099
12100 match.family = afi2family (afi);
12101
12102 if (safi == SAFI_MPLS_VPN)
12103 {
12104 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12105 {
12106 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12107 continue;
12108
12109 if ((table = rn->info) != NULL)
12110 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012111 {
12112 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12113 {
12114 ri = rm->info;
12115 while (ri)
12116 {
12117 if (ri->extra && ri->extra->damp_info)
12118 {
12119 ri_temp = ri->next;
12120 bgp_damp_info_free (ri->extra->damp_info, 1);
12121 ri = ri_temp;
12122 }
12123 else
12124 ri = ri->next;
12125 }
12126 }
12127
12128 bgp_unlock_node (rm);
12129 }
paul718e3742002-12-13 20:15:29 +000012130 }
12131 }
12132 else
12133 {
12134 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012135 {
12136 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12137 {
12138 ri = rn->info;
12139 while (ri)
12140 {
12141 if (ri->extra && ri->extra->damp_info)
12142 {
12143 ri_temp = ri->next;
12144 bgp_damp_info_free (ri->extra->damp_info, 1);
12145 ri = ri_temp;
12146 }
12147 else
12148 ri = ri->next;
12149 }
12150 }
12151
12152 bgp_unlock_node (rn);
12153 }
paul718e3742002-12-13 20:15:29 +000012154 }
12155
12156 return CMD_SUCCESS;
12157}
12158
12159DEFUN (clear_ip_bgp_dampening,
12160 clear_ip_bgp_dampening_cmd,
12161 "clear ip bgp dampening",
12162 CLEAR_STR
12163 IP_STR
12164 BGP_STR
12165 "Clear route flap dampening information\n")
12166{
12167 bgp_damp_info_clean ();
12168 return CMD_SUCCESS;
12169}
12170
12171DEFUN (clear_ip_bgp_dampening_prefix,
12172 clear_ip_bgp_dampening_prefix_cmd,
12173 "clear ip bgp dampening A.B.C.D/M",
12174 CLEAR_STR
12175 IP_STR
12176 BGP_STR
12177 "Clear route flap dampening information\n"
12178 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12179{
12180 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12181 SAFI_UNICAST, NULL, 1);
12182}
12183
12184DEFUN (clear_ip_bgp_dampening_address,
12185 clear_ip_bgp_dampening_address_cmd,
12186 "clear ip bgp dampening A.B.C.D",
12187 CLEAR_STR
12188 IP_STR
12189 BGP_STR
12190 "Clear route flap dampening information\n"
12191 "Network to clear damping information\n")
12192{
12193 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12194 SAFI_UNICAST, NULL, 0);
12195}
12196
12197DEFUN (clear_ip_bgp_dampening_address_mask,
12198 clear_ip_bgp_dampening_address_mask_cmd,
12199 "clear ip bgp dampening A.B.C.D A.B.C.D",
12200 CLEAR_STR
12201 IP_STR
12202 BGP_STR
12203 "Clear route flap dampening information\n"
12204 "Network to clear damping information\n"
12205 "Network mask\n")
12206{
12207 int ret;
12208 char prefix_str[BUFSIZ];
12209
12210 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12211 if (! ret)
12212 {
12213 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12214 return CMD_WARNING;
12215 }
12216
12217 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12218 SAFI_UNICAST, NULL, 0);
12219}
12220
paul94f2b392005-06-28 12:44:16 +000012221static int
paul718e3742002-12-13 20:15:29 +000012222bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12223 afi_t afi, safi_t safi, int *write)
12224{
12225 struct bgp_node *prn;
12226 struct bgp_node *rn;
12227 struct bgp_table *table;
12228 struct prefix *p;
12229 struct prefix_rd *prd;
12230 struct bgp_static *bgp_static;
12231 u_int32_t label;
12232 char buf[SU_ADDRSTRLEN];
12233 char rdbuf[RD_ADDRSTRLEN];
12234
12235 /* Network configuration. */
12236 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12237 if ((table = prn->info) != NULL)
12238 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12239 if ((bgp_static = rn->info) != NULL)
12240 {
12241 p = &rn->p;
12242 prd = (struct prefix_rd *) &prn->p;
12243
12244 /* "address-family" display. */
12245 bgp_config_write_family_header (vty, afi, safi, write);
12246
12247 /* "network" configuration display. */
12248 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12249 label = decode_label (bgp_static->tag);
12250
12251 vty_out (vty, " network %s/%d rd %s tag %d",
12252 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12253 p->prefixlen,
12254 rdbuf, label);
12255 vty_out (vty, "%s", VTY_NEWLINE);
12256 }
12257 return 0;
12258}
12259
12260/* Configuration of static route announcement and aggregate
12261 information. */
12262int
12263bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12264 afi_t afi, safi_t safi, int *write)
12265{
12266 struct bgp_node *rn;
12267 struct prefix *p;
12268 struct bgp_static *bgp_static;
12269 struct bgp_aggregate *bgp_aggregate;
12270 char buf[SU_ADDRSTRLEN];
12271
12272 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12273 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12274
12275 /* Network configuration. */
12276 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12277 if ((bgp_static = rn->info) != NULL)
12278 {
12279 p = &rn->p;
12280
12281 /* "address-family" display. */
12282 bgp_config_write_family_header (vty, afi, safi, write);
12283
12284 /* "network" configuration display. */
12285 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12286 {
12287 u_int32_t destination;
12288 struct in_addr netmask;
12289
12290 destination = ntohl (p->u.prefix4.s_addr);
12291 masklen2ip (p->prefixlen, &netmask);
12292 vty_out (vty, " network %s",
12293 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12294
12295 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12296 || (IN_CLASSB (destination) && p->prefixlen == 16)
12297 || (IN_CLASSA (destination) && p->prefixlen == 8)
12298 || p->u.prefix4.s_addr == 0)
12299 {
12300 /* Natural mask is not display. */
12301 }
12302 else
12303 vty_out (vty, " mask %s", inet_ntoa (netmask));
12304 }
12305 else
12306 {
12307 vty_out (vty, " network %s/%d",
12308 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12309 p->prefixlen);
12310 }
12311
12312 if (bgp_static->rmap.name)
12313 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012314 else
12315 {
12316 if (bgp_static->backdoor)
12317 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012318 }
paul718e3742002-12-13 20:15:29 +000012319
12320 vty_out (vty, "%s", VTY_NEWLINE);
12321 }
12322
12323 /* Aggregate-address configuration. */
12324 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12325 if ((bgp_aggregate = rn->info) != NULL)
12326 {
12327 p = &rn->p;
12328
12329 /* "address-family" display. */
12330 bgp_config_write_family_header (vty, afi, safi, write);
12331
12332 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12333 {
12334 struct in_addr netmask;
12335
12336 masklen2ip (p->prefixlen, &netmask);
12337 vty_out (vty, " aggregate-address %s %s",
12338 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12339 inet_ntoa (netmask));
12340 }
12341 else
12342 {
12343 vty_out (vty, " aggregate-address %s/%d",
12344 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12345 p->prefixlen);
12346 }
12347
12348 if (bgp_aggregate->as_set)
12349 vty_out (vty, " as-set");
12350
12351 if (bgp_aggregate->summary_only)
12352 vty_out (vty, " summary-only");
12353
12354 vty_out (vty, "%s", VTY_NEWLINE);
12355 }
12356
12357 return 0;
12358}
12359
12360int
12361bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12362{
12363 struct bgp_node *rn;
12364 struct bgp_distance *bdistance;
12365
12366 /* Distance configuration. */
12367 if (bgp->distance_ebgp
12368 && bgp->distance_ibgp
12369 && bgp->distance_local
12370 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12371 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12372 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12373 vty_out (vty, " distance bgp %d %d %d%s",
12374 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12375 VTY_NEWLINE);
12376
12377 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12378 if ((bdistance = rn->info) != NULL)
12379 {
12380 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12381 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12382 bdistance->access_list ? bdistance->access_list : "",
12383 VTY_NEWLINE);
12384 }
12385
12386 return 0;
12387}
12388
12389/* Allocate routing table structure and install commands. */
12390void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012391bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012392{
12393 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012394 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012395
12396 /* IPv4 BGP commands. */
12397 install_element (BGP_NODE, &bgp_network_cmd);
12398 install_element (BGP_NODE, &bgp_network_mask_cmd);
12399 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12400 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12401 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12402 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12403 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12404 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12405 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12406 install_element (BGP_NODE, &no_bgp_network_cmd);
12407 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12408 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12409 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12410 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12411 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12412 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12413 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12414 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12415
12416 install_element (BGP_NODE, &aggregate_address_cmd);
12417 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12418 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12419 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12420 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12421 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12422 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12423 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12424 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12425 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12426 install_element (BGP_NODE, &no_aggregate_address_cmd);
12427 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12428 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12429 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12430 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12431 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12432 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12433 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12434 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12435 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12436
12437 /* IPv4 unicast configuration. */
12438 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12439 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12440 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12441 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12442 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12443 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012444 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012445 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12446 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12447 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12448 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12449 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012450
paul718e3742002-12-13 20:15:29 +000012451 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12452 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12453 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12454 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12455 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12456 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12457 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12458 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12459 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12460 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12461 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12462 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12463 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12464 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12465 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12466 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12467 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12468 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12469 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12470 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12471
12472 /* IPv4 multicast configuration. */
12473 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12474 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12475 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12476 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12477 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12478 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12479 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12480 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12481 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12482 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12483 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12484 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12485 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12486 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12487 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12488 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12489 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12490 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12491 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12492 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12493 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12494 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12498 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12499 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12500 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12501 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12502 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12503 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12504 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12505
12506 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012508 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012509 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012511 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012512 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012517 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12543 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12544 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12545 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12546 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012547 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012565 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012566 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12572 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12573 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12574 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12575 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12576 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12577 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12578 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12579 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12580 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12581 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012582 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012584 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012585 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012586 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012588 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12589 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012590 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012591 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012592 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012593 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012594 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012595 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012596
12597 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012601 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012604 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012605 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12608 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12609 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12610 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12611 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12612 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12613 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12614 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12615 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012617 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12618 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12619 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12620 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12621 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012622 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12623 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12624 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12625 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12626 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12627 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12628 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12629 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12630 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012631 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012632 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012633 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012634 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012635 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012636 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012637 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012638
12639 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012641 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012642 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012644 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012645 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012649 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012650 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12676 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12677 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12678 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12679 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012680 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012698 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012699 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12705 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12706 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12707 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12708 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12709 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12710 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12711 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12712 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12713 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12714 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012715 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012717 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012719 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012721 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12722 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012723 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012724 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012725 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012726 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012727 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012728 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012729
12730 /* BGP dampening clear commands */
12731 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12732 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12733 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12734 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12735
Paul Jakmaff7924f2006-09-04 01:10:36 +000012736 /* prefix count */
12737 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12738 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12739 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012740#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012741 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12742
paul718e3742002-12-13 20:15:29 +000012743 /* New config IPv6 BGP commands. */
12744 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12745 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12746 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12747 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12748
12749 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12750 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12751 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12752 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12753
G.Balaji73bfe0b2011-09-23 22:36:20 +053012754 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12755 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12756
paul718e3742002-12-13 20:15:29 +000012757 /* Old config IPv6 BGP commands. */
12758 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12759 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12760
12761 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12762 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12763 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12764 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12765
12766 install_element (VIEW_NODE, &show_bgp_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012768 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012769 install_element (VIEW_NODE, &show_bgp_route_cmd);
12770 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012771 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012772 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012775 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12777 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12779 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12781 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12793 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12797 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12799 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12801 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12803 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12805 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12807 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12809 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12810 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12811 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12812 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12813 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12814 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012815 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12816 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12817 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12818 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012819 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012821 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012822 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012823 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012824 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012825 install_element (VIEW_NODE, &show_bgp_view_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12833 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12834 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12835 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12836 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12837 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12838 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12839 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12840 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12841 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12842 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012843 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012845 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012847 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012849
12850 /* Restricted:
12851 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12852 */
12853 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012856 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012859 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12872 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012876 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012877 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012878 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012879 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12880 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12881 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12882 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12883 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12884 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12885 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012887 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012889
12890 install_element (ENABLE_NODE, &show_bgp_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012893 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012895 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012896 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012898 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012899 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012939 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012943 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012944 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012945 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012946 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012947 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012948 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012949 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12963 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12964 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12965 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12966 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012967 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012968 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012969 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012970 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012971 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012972 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012973
12974 /* Statistics */
12975 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12976 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12977 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12978 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12979
paul718e3742002-12-13 20:15:29 +000012980 /* old command */
12981 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13007 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13008 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13009 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13010 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13011 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13012 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13013 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13014 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13015 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13016 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013017
paul718e3742002-12-13 20:15:29 +000013018 /* old command */
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13045 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13046 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13047 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13048 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13049 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13050 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13051 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13052 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13053 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13054 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13055
13056 /* old command */
13057 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13058 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13060 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13061
13062 /* old command */
13063 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13064 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13065 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13066 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13067
13068 /* old command */
13069 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13070 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13071 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13072 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13073#endif /* HAVE_IPV6 */
13074
13075 install_element (BGP_NODE, &bgp_distance_cmd);
13076 install_element (BGP_NODE, &no_bgp_distance_cmd);
13077 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13078 install_element (BGP_NODE, &bgp_distance_source_cmd);
13079 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13080 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13081 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13082
13083 install_element (BGP_NODE, &bgp_damp_set_cmd);
13084 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13085 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13086 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13087 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13088 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13089 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13090 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13091 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13092 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013093
13094 /* Deprecated AS-Pathlimit commands */
13095 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13096 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13097 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13098 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13099 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13100 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13101
13102 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13103 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13104 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13105 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13106 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13107 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13108
13109 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13112 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13113 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13114 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13115
13116 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13117 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13118 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13119 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13120 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13121 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13122
13123 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13126 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13127 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13128 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13129
13130 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13131 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13132 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13133 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13134 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13135 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013136
13137#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013138 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13139 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013140#endif
paul718e3742002-12-13 20:15:29 +000013141}
Chris Caputo228da422009-07-18 05:44:03 +000013142
13143void
13144bgp_route_finish (void)
13145{
13146 bgp_table_unlock (bgp_distance_table);
13147 bgp_distance_table = NULL;
13148}