blob: 0428531f77c79321e60557a182a7345578be756a [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. */
1884 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1885 {
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, ">");
5654 else
5655 vty_out (vty, " ");
5656
5657 /* Internal route. */
5658 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5659 vty_out (vty, "i");
5660 else
paulb40d9392005-08-22 22:34:41 +00005661 vty_out (vty, " ");
5662}
5663
5664/* called from terminal list command */
5665void
5666route_vty_out (struct vty *vty, struct prefix *p,
5667 struct bgp_info *binfo, int display, safi_t safi)
5668{
5669 struct attr *attr;
5670
5671 /* short status lead text */
5672 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005673
5674 /* print prefix and mask */
5675 if (! display)
5676 route_vty_out_route (p, vty);
5677 else
5678 vty_out (vty, "%*s", 17, " ");
5679
5680 /* Print attribute */
5681 attr = binfo->attr;
5682 if (attr)
5683 {
5684 if (p->family == AF_INET)
5685 {
5686 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005687 vty_out (vty, "%-16s",
5688 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005689 else
5690 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5691 }
5692#ifdef HAVE_IPV6
5693 else if (p->family == AF_INET6)
5694 {
5695 int len;
5696 char buf[BUFSIZ];
5697
5698 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005699 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5700 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005701 len = 16 - len;
5702 if (len < 1)
5703 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5704 else
5705 vty_out (vty, "%*s", len, " ");
5706 }
5707#endif /* HAVE_IPV6 */
5708
5709 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005710 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005711 else
5712 vty_out (vty, " ");
5713
5714 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005715 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005716 else
5717 vty_out (vty, " ");
5718
Paul Jakmafb982c22007-05-04 20:15:47 +00005719 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005720
Paul Jakmab2518c12006-05-12 23:48:40 +00005721 /* Print aspath */
5722 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005723 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005724
Paul Jakmab2518c12006-05-12 23:48:40 +00005725 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005726 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005727 }
paul718e3742002-12-13 20:15:29 +00005728 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005729}
5730
5731/* called from terminal list command */
5732void
5733route_vty_out_tmp (struct vty *vty, struct prefix *p,
5734 struct attr *attr, safi_t safi)
5735{
5736 /* Route status display. */
5737 vty_out (vty, "*");
5738 vty_out (vty, ">");
5739 vty_out (vty, " ");
5740
5741 /* print prefix and mask */
5742 route_vty_out_route (p, vty);
5743
5744 /* Print attribute */
5745 if (attr)
5746 {
5747 if (p->family == AF_INET)
5748 {
5749 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005750 vty_out (vty, "%-16s",
5751 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005752 else
5753 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5754 }
5755#ifdef HAVE_IPV6
5756 else if (p->family == AF_INET6)
5757 {
5758 int len;
5759 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005760
5761 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005762
5763 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005764 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5765 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005766 len = 16 - len;
5767 if (len < 1)
5768 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5769 else
5770 vty_out (vty, "%*s", len, " ");
5771 }
5772#endif /* HAVE_IPV6 */
5773
5774 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005775 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005776 else
5777 vty_out (vty, " ");
5778
5779 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005780 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005781 else
5782 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005783
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005784 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005785
Paul Jakmab2518c12006-05-12 23:48:40 +00005786 /* Print aspath */
5787 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005788 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005789
Paul Jakmab2518c12006-05-12 23:48:40 +00005790 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005791 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005792 }
paul718e3742002-12-13 20:15:29 +00005793
5794 vty_out (vty, "%s", VTY_NEWLINE);
5795}
5796
ajs5a646652004-11-05 01:25:55 +00005797void
paul718e3742002-12-13 20:15:29 +00005798route_vty_out_tag (struct vty *vty, struct prefix *p,
5799 struct bgp_info *binfo, int display, safi_t safi)
5800{
5801 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005802 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005803
5804 if (!binfo->extra)
5805 return;
5806
paulb40d9392005-08-22 22:34:41 +00005807 /* short status lead text */
5808 route_vty_short_status_out (vty, binfo);
5809
paul718e3742002-12-13 20:15:29 +00005810 /* print prefix and mask */
5811 if (! display)
5812 route_vty_out_route (p, vty);
5813 else
5814 vty_out (vty, "%*s", 17, " ");
5815
5816 /* Print attribute */
5817 attr = binfo->attr;
5818 if (attr)
5819 {
5820 if (p->family == AF_INET)
5821 {
5822 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005823 vty_out (vty, "%-16s",
5824 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005825 else
5826 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5827 }
5828#ifdef HAVE_IPV6
5829 else if (p->family == AF_INET6)
5830 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005831 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005832 char buf[BUFSIZ];
5833 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005834 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005835 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005836 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5837 buf, BUFSIZ));
5838 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005839 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005840 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5841 buf, BUFSIZ),
5842 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5843 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005844
5845 }
5846#endif /* HAVE_IPV6 */
5847 }
5848
Paul Jakmafb982c22007-05-04 20:15:47 +00005849 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005850
5851 vty_out (vty, "notag/%d", label);
5852
5853 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005854}
5855
5856/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005857static void
paul718e3742002-12-13 20:15:29 +00005858damp_route_vty_out (struct vty *vty, struct prefix *p,
5859 struct bgp_info *binfo, int display, safi_t safi)
5860{
5861 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005862 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005863 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005864
paulb40d9392005-08-22 22:34:41 +00005865 /* short status lead text */
5866 route_vty_short_status_out (vty, binfo);
5867
paul718e3742002-12-13 20:15:29 +00005868 /* print prefix and mask */
5869 if (! display)
5870 route_vty_out_route (p, vty);
5871 else
5872 vty_out (vty, "%*s", 17, " ");
5873
5874 len = vty_out (vty, "%s", binfo->peer->host);
5875 len = 17 - len;
5876 if (len < 1)
5877 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5878 else
5879 vty_out (vty, "%*s", len, " ");
5880
Chris Caputo50aef6f2009-06-23 06:06:49 +00005881 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005882
5883 /* Print attribute */
5884 attr = binfo->attr;
5885 if (attr)
5886 {
5887 /* Print aspath */
5888 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005889 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005890
5891 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005892 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005893 }
5894 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005895}
5896
paul718e3742002-12-13 20:15:29 +00005897/* flap route */
ajs5a646652004-11-05 01:25:55 +00005898static void
paul718e3742002-12-13 20:15:29 +00005899flap_route_vty_out (struct vty *vty, struct prefix *p,
5900 struct bgp_info *binfo, int display, safi_t safi)
5901{
5902 struct attr *attr;
5903 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005904 char timebuf[BGP_UPTIME_LEN];
5905 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005906
5907 if (!binfo->extra)
5908 return;
5909
5910 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005911
paulb40d9392005-08-22 22:34:41 +00005912 /* short status lead text */
5913 route_vty_short_status_out (vty, binfo);
5914
paul718e3742002-12-13 20:15:29 +00005915 /* print prefix and mask */
5916 if (! display)
5917 route_vty_out_route (p, vty);
5918 else
5919 vty_out (vty, "%*s", 17, " ");
5920
5921 len = vty_out (vty, "%s", binfo->peer->host);
5922 len = 16 - len;
5923 if (len < 1)
5924 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5925 else
5926 vty_out (vty, "%*s", len, " ");
5927
5928 len = vty_out (vty, "%d", bdi->flap);
5929 len = 5 - len;
5930 if (len < 1)
5931 vty_out (vty, " ");
5932 else
5933 vty_out (vty, "%*s ", len, " ");
5934
5935 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5936 timebuf, BGP_UPTIME_LEN));
5937
5938 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5939 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005940 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005941 else
5942 vty_out (vty, "%*s ", 8, " ");
5943
5944 /* Print attribute */
5945 attr = binfo->attr;
5946 if (attr)
5947 {
5948 /* Print aspath */
5949 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005950 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005951
5952 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005953 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005954 }
5955 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005956}
5957
paul94f2b392005-06-28 12:44:16 +00005958static void
paul718e3742002-12-13 20:15:29 +00005959route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5960 struct bgp_info *binfo, afi_t afi, safi_t safi)
5961{
5962 char buf[INET6_ADDRSTRLEN];
5963 char buf1[BUFSIZ];
5964 struct attr *attr;
5965 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005966#ifdef HAVE_CLOCK_MONOTONIC
5967 time_t tbuf;
5968#endif
paul718e3742002-12-13 20:15:29 +00005969
5970 attr = binfo->attr;
5971
5972 if (attr)
5973 {
5974 /* Line1 display AS-path, Aggregator */
5975 if (attr->aspath)
5976 {
5977 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005978 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005979 vty_out (vty, "Local");
5980 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005981 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005982 }
5983
paulb40d9392005-08-22 22:34:41 +00005984 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5985 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005986 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5987 vty_out (vty, ", (stale)");
5988 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005989 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005990 attr->extra->aggregator_as,
5991 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005992 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5993 vty_out (vty, ", (Received from a RR-client)");
5994 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5995 vty_out (vty, ", (Received from a RS-client)");
5996 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5997 vty_out (vty, ", (history entry)");
5998 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5999 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006000 vty_out (vty, "%s", VTY_NEWLINE);
6001
6002 /* Line2 display Next-hop, Neighbor, Router-id */
6003 if (p->family == AF_INET)
6004 {
6005 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006006 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006007 inet_ntoa (attr->nexthop));
6008 }
6009#ifdef HAVE_IPV6
6010 else
6011 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006013 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006014 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006015 buf, INET6_ADDRSTRLEN));
6016 }
6017#endif /* HAVE_IPV6 */
6018
6019 if (binfo->peer == bgp->peer_self)
6020 {
6021 vty_out (vty, " from %s ",
6022 p->family == AF_INET ? "0.0.0.0" : "::");
6023 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6024 }
6025 else
6026 {
6027 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6028 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006029 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006030 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006031 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006032 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006034 else
6035 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6036 }
6037 vty_out (vty, "%s", VTY_NEWLINE);
6038
6039#ifdef HAVE_IPV6
6040 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006041 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006042 {
6043 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006045 buf, INET6_ADDRSTRLEN),
6046 VTY_NEWLINE);
6047 }
6048#endif /* HAVE_IPV6 */
6049
6050 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6051 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6052
6053 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006054 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006055
6056 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006057 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006058 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006059 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006060
Paul Jakmafb982c22007-05-04 20:15:47 +00006061 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006062 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006063
6064 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6065 vty_out (vty, ", valid");
6066
6067 if (binfo->peer != bgp->peer_self)
6068 {
6069 if (binfo->peer->as == binfo->peer->local_as)
6070 vty_out (vty, ", internal");
6071 else
6072 vty_out (vty, ", %s",
6073 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6074 }
6075 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6076 vty_out (vty, ", aggregated, local");
6077 else if (binfo->type != ZEBRA_ROUTE_BGP)
6078 vty_out (vty, ", sourced");
6079 else
6080 vty_out (vty, ", sourced, local");
6081
6082 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6083 vty_out (vty, ", atomic-aggregate");
6084
Josh Baileyde8d5df2011-07-20 20:46:01 -07006085 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6086 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6087 bgp_info_mpath_count (binfo)))
6088 vty_out (vty, ", multipath");
6089
paul718e3742002-12-13 20:15:29 +00006090 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6091 vty_out (vty, ", best");
6092
6093 vty_out (vty, "%s", VTY_NEWLINE);
6094
6095 /* Line 4 display Community */
6096 if (attr->community)
6097 vty_out (vty, " Community: %s%s", attr->community->str,
6098 VTY_NEWLINE);
6099
6100 /* Line 5 display Extended-community */
6101 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006102 vty_out (vty, " Extended Community: %s%s",
6103 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006104
6105 /* Line 6 display Originator, Cluster-id */
6106 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6107 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6108 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006109 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006110 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006111 vty_out (vty, " Originator: %s",
6112 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006113
6114 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6115 {
6116 int i;
6117 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006118 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6119 vty_out (vty, "%s ",
6120 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006121 }
6122 vty_out (vty, "%s", VTY_NEWLINE);
6123 }
Paul Jakma41367172007-08-06 15:24:51 +00006124
Paul Jakmafb982c22007-05-04 20:15:47 +00006125 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006126 bgp_damp_info_vty (vty, binfo);
6127
6128 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006129#ifdef HAVE_CLOCK_MONOTONIC
6130 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006131 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006132#else
6133 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6134#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006135 }
6136 vty_out (vty, "%s", VTY_NEWLINE);
6137}
6138
paulb40d9392005-08-22 22:34:41 +00006139#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006140#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006141#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6142#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6143#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6144
6145enum bgp_show_type
6146{
6147 bgp_show_type_normal,
6148 bgp_show_type_regexp,
6149 bgp_show_type_prefix_list,
6150 bgp_show_type_filter_list,
6151 bgp_show_type_route_map,
6152 bgp_show_type_neighbor,
6153 bgp_show_type_cidr_only,
6154 bgp_show_type_prefix_longer,
6155 bgp_show_type_community_all,
6156 bgp_show_type_community,
6157 bgp_show_type_community_exact,
6158 bgp_show_type_community_list,
6159 bgp_show_type_community_list_exact,
6160 bgp_show_type_flap_statistics,
6161 bgp_show_type_flap_address,
6162 bgp_show_type_flap_prefix,
6163 bgp_show_type_flap_cidr_only,
6164 bgp_show_type_flap_regexp,
6165 bgp_show_type_flap_filter_list,
6166 bgp_show_type_flap_prefix_list,
6167 bgp_show_type_flap_prefix_longer,
6168 bgp_show_type_flap_route_map,
6169 bgp_show_type_flap_neighbor,
6170 bgp_show_type_dampend_paths,
6171 bgp_show_type_damp_neighbor
6172};
6173
ajs5a646652004-11-05 01:25:55 +00006174static int
paulfee0f4c2004-09-13 05:12:46 +00006175bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006176 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006177{
paul718e3742002-12-13 20:15:29 +00006178 struct bgp_info *ri;
6179 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006180 int header = 1;
paul718e3742002-12-13 20:15:29 +00006181 int display;
ajs5a646652004-11-05 01:25:55 +00006182 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006183
6184 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006185 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006186
paul718e3742002-12-13 20:15:29 +00006187 /* Start processing of routes. */
6188 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6189 if (rn->info != NULL)
6190 {
6191 display = 0;
6192
6193 for (ri = rn->info; ri; ri = ri->next)
6194 {
ajs5a646652004-11-05 01:25:55 +00006195 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006196 || type == bgp_show_type_flap_address
6197 || type == bgp_show_type_flap_prefix
6198 || type == bgp_show_type_flap_cidr_only
6199 || type == bgp_show_type_flap_regexp
6200 || type == bgp_show_type_flap_filter_list
6201 || type == bgp_show_type_flap_prefix_list
6202 || type == bgp_show_type_flap_prefix_longer
6203 || type == bgp_show_type_flap_route_map
6204 || type == bgp_show_type_flap_neighbor
6205 || type == bgp_show_type_dampend_paths
6206 || type == bgp_show_type_damp_neighbor)
6207 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006208 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006209 continue;
6210 }
6211 if (type == bgp_show_type_regexp
6212 || type == bgp_show_type_flap_regexp)
6213 {
ajs5a646652004-11-05 01:25:55 +00006214 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006215
6216 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6217 continue;
6218 }
6219 if (type == bgp_show_type_prefix_list
6220 || type == bgp_show_type_flap_prefix_list)
6221 {
ajs5a646652004-11-05 01:25:55 +00006222 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006223
6224 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6225 continue;
6226 }
6227 if (type == bgp_show_type_filter_list
6228 || type == bgp_show_type_flap_filter_list)
6229 {
ajs5a646652004-11-05 01:25:55 +00006230 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006231
6232 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6233 continue;
6234 }
6235 if (type == bgp_show_type_route_map
6236 || type == bgp_show_type_flap_route_map)
6237 {
ajs5a646652004-11-05 01:25:55 +00006238 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006239 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006240 struct attr dummy_attr;
6241 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006242 int ret;
6243
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006244 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006245 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006246
paul718e3742002-12-13 20:15:29 +00006247 binfo.peer = ri->peer;
6248 binfo.attr = &dummy_attr;
6249
6250 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006251 if (ret == RMAP_DENYMATCH)
6252 continue;
6253 }
6254 if (type == bgp_show_type_neighbor
6255 || type == bgp_show_type_flap_neighbor
6256 || type == bgp_show_type_damp_neighbor)
6257 {
ajs5a646652004-11-05 01:25:55 +00006258 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006259
6260 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6261 continue;
6262 }
6263 if (type == bgp_show_type_cidr_only
6264 || type == bgp_show_type_flap_cidr_only)
6265 {
6266 u_int32_t destination;
6267
6268 destination = ntohl (rn->p.u.prefix4.s_addr);
6269 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6270 continue;
6271 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6272 continue;
6273 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6274 continue;
6275 }
6276 if (type == bgp_show_type_prefix_longer
6277 || type == bgp_show_type_flap_prefix_longer)
6278 {
ajs5a646652004-11-05 01:25:55 +00006279 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006280
6281 if (! prefix_match (p, &rn->p))
6282 continue;
6283 }
6284 if (type == bgp_show_type_community_all)
6285 {
6286 if (! ri->attr->community)
6287 continue;
6288 }
6289 if (type == bgp_show_type_community)
6290 {
ajs5a646652004-11-05 01:25:55 +00006291 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006292
6293 if (! ri->attr->community ||
6294 ! community_match (ri->attr->community, com))
6295 continue;
6296 }
6297 if (type == bgp_show_type_community_exact)
6298 {
ajs5a646652004-11-05 01:25:55 +00006299 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006300
6301 if (! ri->attr->community ||
6302 ! community_cmp (ri->attr->community, com))
6303 continue;
6304 }
6305 if (type == bgp_show_type_community_list)
6306 {
ajs5a646652004-11-05 01:25:55 +00006307 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006308
6309 if (! community_list_match (ri->attr->community, list))
6310 continue;
6311 }
6312 if (type == bgp_show_type_community_list_exact)
6313 {
ajs5a646652004-11-05 01:25:55 +00006314 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006315
6316 if (! community_list_exact_match (ri->attr->community, list))
6317 continue;
6318 }
6319 if (type == bgp_show_type_flap_address
6320 || type == bgp_show_type_flap_prefix)
6321 {
ajs5a646652004-11-05 01:25:55 +00006322 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006323
6324 if (! prefix_match (&rn->p, p))
6325 continue;
6326
6327 if (type == bgp_show_type_flap_prefix)
6328 if (p->prefixlen != rn->p.prefixlen)
6329 continue;
6330 }
6331 if (type == bgp_show_type_dampend_paths
6332 || type == bgp_show_type_damp_neighbor)
6333 {
6334 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6335 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6336 continue;
6337 }
6338
6339 if (header)
6340 {
hasso93406d82005-02-02 14:40:33 +00006341 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6342 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6343 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006344 if (type == bgp_show_type_dampend_paths
6345 || type == bgp_show_type_damp_neighbor)
6346 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6347 else if (type == bgp_show_type_flap_statistics
6348 || type == bgp_show_type_flap_address
6349 || type == bgp_show_type_flap_prefix
6350 || type == bgp_show_type_flap_cidr_only
6351 || type == bgp_show_type_flap_regexp
6352 || type == bgp_show_type_flap_filter_list
6353 || type == bgp_show_type_flap_prefix_list
6354 || type == bgp_show_type_flap_prefix_longer
6355 || type == bgp_show_type_flap_route_map
6356 || type == bgp_show_type_flap_neighbor)
6357 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6358 else
6359 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006360 header = 0;
6361 }
6362
6363 if (type == bgp_show_type_dampend_paths
6364 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006365 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006366 else if (type == bgp_show_type_flap_statistics
6367 || type == bgp_show_type_flap_address
6368 || type == bgp_show_type_flap_prefix
6369 || type == bgp_show_type_flap_cidr_only
6370 || type == bgp_show_type_flap_regexp
6371 || type == bgp_show_type_flap_filter_list
6372 || type == bgp_show_type_flap_prefix_list
6373 || type == bgp_show_type_flap_prefix_longer
6374 || type == bgp_show_type_flap_route_map
6375 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006376 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006377 else
ajs5a646652004-11-05 01:25:55 +00006378 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006379 display++;
6380 }
6381 if (display)
ajs5a646652004-11-05 01:25:55 +00006382 output_count++;
paul718e3742002-12-13 20:15:29 +00006383 }
6384
6385 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006386 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006387 {
6388 if (type == bgp_show_type_normal)
6389 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6390 }
6391 else
6392 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006393 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006394
6395 return CMD_SUCCESS;
6396}
6397
ajs5a646652004-11-05 01:25:55 +00006398static int
paulfee0f4c2004-09-13 05:12:46 +00006399bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006400 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006401{
6402 struct bgp_table *table;
6403
6404 if (bgp == NULL) {
6405 bgp = bgp_get_default ();
6406 }
6407
6408 if (bgp == NULL)
6409 {
6410 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6411 return CMD_WARNING;
6412 }
6413
6414
6415 table = bgp->rib[afi][safi];
6416
ajs5a646652004-11-05 01:25:55 +00006417 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006418}
6419
paul718e3742002-12-13 20:15:29 +00006420/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006421static void
paul718e3742002-12-13 20:15:29 +00006422route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6423 struct bgp_node *rn,
6424 struct prefix_rd *prd, afi_t afi, safi_t safi)
6425{
6426 struct bgp_info *ri;
6427 struct prefix *p;
6428 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006429 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006430 char buf1[INET6_ADDRSTRLEN];
6431 char buf2[INET6_ADDRSTRLEN];
6432 int count = 0;
6433 int best = 0;
6434 int suppress = 0;
6435 int no_export = 0;
6436 int no_advertise = 0;
6437 int local_as = 0;
6438 int first = 0;
6439
6440 p = &rn->p;
6441 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6442 (safi == SAFI_MPLS_VPN ?
6443 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6444 safi == SAFI_MPLS_VPN ? ":" : "",
6445 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6446 p->prefixlen, VTY_NEWLINE);
6447
6448 for (ri = rn->info; ri; ri = ri->next)
6449 {
6450 count++;
6451 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6452 {
6453 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006454 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006455 suppress = 1;
6456 if (ri->attr->community != NULL)
6457 {
6458 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6459 no_advertise = 1;
6460 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6461 no_export = 1;
6462 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6463 local_as = 1;
6464 }
6465 }
6466 }
6467
6468 vty_out (vty, "Paths: (%d available", count);
6469 if (best)
6470 {
6471 vty_out (vty, ", best #%d", best);
6472 if (safi == SAFI_UNICAST)
6473 vty_out (vty, ", table Default-IP-Routing-Table");
6474 }
6475 else
6476 vty_out (vty, ", no best path");
6477 if (no_advertise)
6478 vty_out (vty, ", not advertised to any peer");
6479 else if (no_export)
6480 vty_out (vty, ", not advertised to EBGP peer");
6481 else if (local_as)
6482 vty_out (vty, ", not advertised outside local AS");
6483 if (suppress)
6484 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6485 vty_out (vty, ")%s", VTY_NEWLINE);
6486
6487 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006488 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006489 {
6490 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6491 {
6492 if (! first)
6493 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6494 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6495 first = 1;
6496 }
6497 }
6498 if (! first)
6499 vty_out (vty, " Not advertised to any peer");
6500 vty_out (vty, "%s", VTY_NEWLINE);
6501}
6502
6503/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006504static int
paulfee0f4c2004-09-13 05:12:46 +00006505bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006506 struct bgp_table *rib, const char *ip_str,
6507 afi_t afi, safi_t safi, struct prefix_rd *prd,
6508 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006509{
6510 int ret;
6511 int header;
6512 int display = 0;
6513 struct prefix match;
6514 struct bgp_node *rn;
6515 struct bgp_node *rm;
6516 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006517 struct bgp_table *table;
6518
paul718e3742002-12-13 20:15:29 +00006519 /* Check IP address argument. */
6520 ret = str2prefix (ip_str, &match);
6521 if (! ret)
6522 {
6523 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6524 return CMD_WARNING;
6525 }
6526
6527 match.family = afi2family (afi);
6528
6529 if (safi == SAFI_MPLS_VPN)
6530 {
paulfee0f4c2004-09-13 05:12:46 +00006531 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006532 {
6533 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6534 continue;
6535
6536 if ((table = rn->info) != NULL)
6537 {
6538 header = 1;
6539
6540 if ((rm = bgp_node_match (table, &match)) != NULL)
6541 {
6542 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006543 {
6544 bgp_unlock_node (rm);
6545 continue;
6546 }
paul718e3742002-12-13 20:15:29 +00006547
6548 for (ri = rm->info; ri; ri = ri->next)
6549 {
6550 if (header)
6551 {
6552 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6553 AFI_IP, SAFI_MPLS_VPN);
6554
6555 header = 0;
6556 }
6557 display++;
6558 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6559 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006560
6561 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006562 }
6563 }
6564 }
6565 }
6566 else
6567 {
6568 header = 1;
6569
paulfee0f4c2004-09-13 05:12:46 +00006570 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006571 {
6572 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6573 {
6574 for (ri = rn->info; ri; ri = ri->next)
6575 {
6576 if (header)
6577 {
6578 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6579 header = 0;
6580 }
6581 display++;
6582 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6583 }
6584 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006585
6586 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006587 }
6588 }
6589
6590 if (! display)
6591 {
6592 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6593 return CMD_WARNING;
6594 }
6595
6596 return CMD_SUCCESS;
6597}
6598
paulfee0f4c2004-09-13 05:12:46 +00006599/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006600static int
paulfd79ac92004-10-13 05:06:08 +00006601bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006602 afi_t afi, safi_t safi, struct prefix_rd *prd,
6603 int prefix_check)
6604{
6605 struct bgp *bgp;
6606
6607 /* BGP structure lookup. */
6608 if (view_name)
6609 {
6610 bgp = bgp_lookup_by_name (view_name);
6611 if (bgp == NULL)
6612 {
6613 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6614 return CMD_WARNING;
6615 }
6616 }
6617 else
6618 {
6619 bgp = bgp_get_default ();
6620 if (bgp == NULL)
6621 {
6622 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6623 return CMD_WARNING;
6624 }
6625 }
6626
6627 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6628 afi, safi, prd, prefix_check);
6629}
6630
paul718e3742002-12-13 20:15:29 +00006631/* BGP route print out function. */
6632DEFUN (show_ip_bgp,
6633 show_ip_bgp_cmd,
6634 "show ip bgp",
6635 SHOW_STR
6636 IP_STR
6637 BGP_STR)
6638{
ajs5a646652004-11-05 01:25:55 +00006639 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006640}
6641
6642DEFUN (show_ip_bgp_ipv4,
6643 show_ip_bgp_ipv4_cmd,
6644 "show ip bgp ipv4 (unicast|multicast)",
6645 SHOW_STR
6646 IP_STR
6647 BGP_STR
6648 "Address family\n"
6649 "Address Family modifier\n"
6650 "Address Family modifier\n")
6651{
6652 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006653 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6654 NULL);
paul718e3742002-12-13 20:15:29 +00006655
ajs5a646652004-11-05 01:25:55 +00006656 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006657}
6658
Michael Lambert95cbbd22010-07-23 14:43:04 -04006659ALIAS (show_ip_bgp_ipv4,
6660 show_bgp_ipv4_safi_cmd,
6661 "show bgp ipv4 (unicast|multicast)",
6662 SHOW_STR
6663 BGP_STR
6664 "Address family\n"
6665 "Address Family modifier\n"
6666 "Address Family modifier\n")
6667
paul718e3742002-12-13 20:15:29 +00006668DEFUN (show_ip_bgp_route,
6669 show_ip_bgp_route_cmd,
6670 "show ip bgp A.B.C.D",
6671 SHOW_STR
6672 IP_STR
6673 BGP_STR
6674 "Network in the BGP routing table to display\n")
6675{
6676 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6677}
6678
6679DEFUN (show_ip_bgp_ipv4_route,
6680 show_ip_bgp_ipv4_route_cmd,
6681 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6682 SHOW_STR
6683 IP_STR
6684 BGP_STR
6685 "Address family\n"
6686 "Address Family modifier\n"
6687 "Address Family modifier\n"
6688 "Network in the BGP routing table to display\n")
6689{
6690 if (strncmp (argv[0], "m", 1) == 0)
6691 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6692
6693 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6694}
6695
Michael Lambert95cbbd22010-07-23 14:43:04 -04006696ALIAS (show_ip_bgp_ipv4_route,
6697 show_bgp_ipv4_safi_route_cmd,
6698 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6699 SHOW_STR
6700 BGP_STR
6701 "Address family\n"
6702 "Address Family modifier\n"
6703 "Address Family modifier\n"
6704 "Network in the BGP routing table to display\n")
6705
paul718e3742002-12-13 20:15:29 +00006706DEFUN (show_ip_bgp_vpnv4_all_route,
6707 show_ip_bgp_vpnv4_all_route_cmd,
6708 "show ip bgp vpnv4 all A.B.C.D",
6709 SHOW_STR
6710 IP_STR
6711 BGP_STR
6712 "Display VPNv4 NLRI specific information\n"
6713 "Display information about all VPNv4 NLRIs\n"
6714 "Network in the BGP routing table to display\n")
6715{
6716 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6717}
6718
6719DEFUN (show_ip_bgp_vpnv4_rd_route,
6720 show_ip_bgp_vpnv4_rd_route_cmd,
6721 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6722 SHOW_STR
6723 IP_STR
6724 BGP_STR
6725 "Display VPNv4 NLRI specific information\n"
6726 "Display information for a route distinguisher\n"
6727 "VPN Route Distinguisher\n"
6728 "Network in the BGP routing table to display\n")
6729{
6730 int ret;
6731 struct prefix_rd prd;
6732
6733 ret = str2prefix_rd (argv[0], &prd);
6734 if (! ret)
6735 {
6736 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6737 return CMD_WARNING;
6738 }
6739 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6740}
6741
6742DEFUN (show_ip_bgp_prefix,
6743 show_ip_bgp_prefix_cmd,
6744 "show ip bgp A.B.C.D/M",
6745 SHOW_STR
6746 IP_STR
6747 BGP_STR
6748 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6749{
6750 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6751}
6752
6753DEFUN (show_ip_bgp_ipv4_prefix,
6754 show_ip_bgp_ipv4_prefix_cmd,
6755 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6756 SHOW_STR
6757 IP_STR
6758 BGP_STR
6759 "Address family\n"
6760 "Address Family modifier\n"
6761 "Address Family modifier\n"
6762 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6763{
6764 if (strncmp (argv[0], "m", 1) == 0)
6765 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6766
6767 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6768}
6769
Michael Lambert95cbbd22010-07-23 14:43:04 -04006770ALIAS (show_ip_bgp_ipv4_prefix,
6771 show_bgp_ipv4_safi_prefix_cmd,
6772 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6773 SHOW_STR
6774 BGP_STR
6775 "Address family\n"
6776 "Address Family modifier\n"
6777 "Address Family modifier\n"
6778 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6779
paul718e3742002-12-13 20:15:29 +00006780DEFUN (show_ip_bgp_vpnv4_all_prefix,
6781 show_ip_bgp_vpnv4_all_prefix_cmd,
6782 "show ip bgp vpnv4 all A.B.C.D/M",
6783 SHOW_STR
6784 IP_STR
6785 BGP_STR
6786 "Display VPNv4 NLRI specific information\n"
6787 "Display information about all VPNv4 NLRIs\n"
6788 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6789{
6790 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6791}
6792
6793DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6794 show_ip_bgp_vpnv4_rd_prefix_cmd,
6795 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6796 SHOW_STR
6797 IP_STR
6798 BGP_STR
6799 "Display VPNv4 NLRI specific information\n"
6800 "Display information for a route distinguisher\n"
6801 "VPN Route Distinguisher\n"
6802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6803{
6804 int ret;
6805 struct prefix_rd prd;
6806
6807 ret = str2prefix_rd (argv[0], &prd);
6808 if (! ret)
6809 {
6810 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6811 return CMD_WARNING;
6812 }
6813 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6814}
6815
6816DEFUN (show_ip_bgp_view,
6817 show_ip_bgp_view_cmd,
6818 "show ip bgp view WORD",
6819 SHOW_STR
6820 IP_STR
6821 BGP_STR
6822 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006823 "View name\n")
paul718e3742002-12-13 20:15:29 +00006824{
paulbb46e942003-10-24 19:02:03 +00006825 struct bgp *bgp;
6826
6827 /* BGP structure lookup. */
6828 bgp = bgp_lookup_by_name (argv[0]);
6829 if (bgp == NULL)
6830 {
6831 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6832 return CMD_WARNING;
6833 }
6834
ajs5a646652004-11-05 01:25:55 +00006835 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006836}
6837
6838DEFUN (show_ip_bgp_view_route,
6839 show_ip_bgp_view_route_cmd,
6840 "show ip bgp view WORD A.B.C.D",
6841 SHOW_STR
6842 IP_STR
6843 BGP_STR
6844 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006845 "View name\n"
paul718e3742002-12-13 20:15:29 +00006846 "Network in the BGP routing table to display\n")
6847{
6848 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6849}
6850
6851DEFUN (show_ip_bgp_view_prefix,
6852 show_ip_bgp_view_prefix_cmd,
6853 "show ip bgp view WORD A.B.C.D/M",
6854 SHOW_STR
6855 IP_STR
6856 BGP_STR
6857 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006858 "View name\n"
paul718e3742002-12-13 20:15:29 +00006859 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6860{
6861 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6862}
6863
6864#ifdef HAVE_IPV6
6865DEFUN (show_bgp,
6866 show_bgp_cmd,
6867 "show bgp",
6868 SHOW_STR
6869 BGP_STR)
6870{
ajs5a646652004-11-05 01:25:55 +00006871 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6872 NULL);
paul718e3742002-12-13 20:15:29 +00006873}
6874
6875ALIAS (show_bgp,
6876 show_bgp_ipv6_cmd,
6877 "show bgp ipv6",
6878 SHOW_STR
6879 BGP_STR
6880 "Address family\n")
6881
Michael Lambert95cbbd22010-07-23 14:43:04 -04006882DEFUN (show_bgp_ipv6_safi,
6883 show_bgp_ipv6_safi_cmd,
6884 "show bgp ipv6 (unicast|multicast)",
6885 SHOW_STR
6886 BGP_STR
6887 "Address family\n"
6888 "Address Family modifier\n"
6889 "Address Family modifier\n")
6890{
6891 if (strncmp (argv[0], "m", 1) == 0)
6892 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6893 NULL);
6894
6895 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6896}
6897
paul718e3742002-12-13 20:15:29 +00006898/* old command */
6899DEFUN (show_ipv6_bgp,
6900 show_ipv6_bgp_cmd,
6901 "show ipv6 bgp",
6902 SHOW_STR
6903 IP_STR
6904 BGP_STR)
6905{
ajs5a646652004-11-05 01:25:55 +00006906 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6907 NULL);
paul718e3742002-12-13 20:15:29 +00006908}
6909
6910DEFUN (show_bgp_route,
6911 show_bgp_route_cmd,
6912 "show bgp X:X::X:X",
6913 SHOW_STR
6914 BGP_STR
6915 "Network in the BGP routing table to display\n")
6916{
6917 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6918}
6919
6920ALIAS (show_bgp_route,
6921 show_bgp_ipv6_route_cmd,
6922 "show bgp ipv6 X:X::X:X",
6923 SHOW_STR
6924 BGP_STR
6925 "Address family\n"
6926 "Network in the BGP routing table to display\n")
6927
Michael Lambert95cbbd22010-07-23 14:43:04 -04006928DEFUN (show_bgp_ipv6_safi_route,
6929 show_bgp_ipv6_safi_route_cmd,
6930 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6931 SHOW_STR
6932 BGP_STR
6933 "Address family\n"
6934 "Address Family modifier\n"
6935 "Address Family modifier\n"
6936 "Network in the BGP routing table to display\n")
6937{
6938 if (strncmp (argv[0], "m", 1) == 0)
6939 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6940
6941 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6942}
6943
paul718e3742002-12-13 20:15:29 +00006944/* old command */
6945DEFUN (show_ipv6_bgp_route,
6946 show_ipv6_bgp_route_cmd,
6947 "show ipv6 bgp X:X::X:X",
6948 SHOW_STR
6949 IP_STR
6950 BGP_STR
6951 "Network in the BGP routing table to display\n")
6952{
6953 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6954}
6955
6956DEFUN (show_bgp_prefix,
6957 show_bgp_prefix_cmd,
6958 "show bgp X:X::X:X/M",
6959 SHOW_STR
6960 BGP_STR
6961 "IPv6 prefix <network>/<length>\n")
6962{
6963 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6964}
6965
6966ALIAS (show_bgp_prefix,
6967 show_bgp_ipv6_prefix_cmd,
6968 "show bgp ipv6 X:X::X:X/M",
6969 SHOW_STR
6970 BGP_STR
6971 "Address family\n"
6972 "IPv6 prefix <network>/<length>\n")
6973
Michael Lambert95cbbd22010-07-23 14:43:04 -04006974DEFUN (show_bgp_ipv6_safi_prefix,
6975 show_bgp_ipv6_safi_prefix_cmd,
6976 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6977 SHOW_STR
6978 BGP_STR
6979 "Address family\n"
6980 "Address Family modifier\n"
6981 "Address Family modifier\n"
6982 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6983{
6984 if (strncmp (argv[0], "m", 1) == 0)
6985 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6986
6987 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6988}
6989
paul718e3742002-12-13 20:15:29 +00006990/* old command */
6991DEFUN (show_ipv6_bgp_prefix,
6992 show_ipv6_bgp_prefix_cmd,
6993 "show ipv6 bgp X:X::X:X/M",
6994 SHOW_STR
6995 IP_STR
6996 BGP_STR
6997 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6998{
6999 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7000}
7001
paulbb46e942003-10-24 19:02:03 +00007002DEFUN (show_bgp_view,
7003 show_bgp_view_cmd,
7004 "show bgp view WORD",
7005 SHOW_STR
7006 BGP_STR
7007 "BGP view\n"
7008 "View name\n")
7009{
7010 struct bgp *bgp;
7011
7012 /* BGP structure lookup. */
7013 bgp = bgp_lookup_by_name (argv[0]);
7014 if (bgp == NULL)
7015 {
7016 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7017 return CMD_WARNING;
7018 }
7019
ajs5a646652004-11-05 01:25:55 +00007020 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007021}
7022
7023ALIAS (show_bgp_view,
7024 show_bgp_view_ipv6_cmd,
7025 "show bgp view WORD ipv6",
7026 SHOW_STR
7027 BGP_STR
7028 "BGP view\n"
7029 "View name\n"
7030 "Address family\n")
7031
7032DEFUN (show_bgp_view_route,
7033 show_bgp_view_route_cmd,
7034 "show bgp view WORD X:X::X:X",
7035 SHOW_STR
7036 BGP_STR
7037 "BGP view\n"
7038 "View name\n"
7039 "Network in the BGP routing table to display\n")
7040{
7041 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7042}
7043
7044ALIAS (show_bgp_view_route,
7045 show_bgp_view_ipv6_route_cmd,
7046 "show bgp view WORD ipv6 X:X::X:X",
7047 SHOW_STR
7048 BGP_STR
7049 "BGP view\n"
7050 "View name\n"
7051 "Address family\n"
7052 "Network in the BGP routing table to display\n")
7053
7054DEFUN (show_bgp_view_prefix,
7055 show_bgp_view_prefix_cmd,
7056 "show bgp view WORD X:X::X:X/M",
7057 SHOW_STR
7058 BGP_STR
7059 "BGP view\n"
7060 "View name\n"
7061 "IPv6 prefix <network>/<length>\n")
7062{
7063 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7064}
7065
7066ALIAS (show_bgp_view_prefix,
7067 show_bgp_view_ipv6_prefix_cmd,
7068 "show bgp view WORD ipv6 X:X::X:X/M",
7069 SHOW_STR
7070 BGP_STR
7071 "BGP view\n"
7072 "View name\n"
7073 "Address family\n"
7074 "IPv6 prefix <network>/<length>\n")
7075
paul718e3742002-12-13 20:15:29 +00007076/* old command */
7077DEFUN (show_ipv6_mbgp,
7078 show_ipv6_mbgp_cmd,
7079 "show ipv6 mbgp",
7080 SHOW_STR
7081 IP_STR
7082 MBGP_STR)
7083{
ajs5a646652004-11-05 01:25:55 +00007084 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7085 NULL);
paul718e3742002-12-13 20:15:29 +00007086}
7087
7088/* old command */
7089DEFUN (show_ipv6_mbgp_route,
7090 show_ipv6_mbgp_route_cmd,
7091 "show ipv6 mbgp X:X::X:X",
7092 SHOW_STR
7093 IP_STR
7094 MBGP_STR
7095 "Network in the MBGP routing table to display\n")
7096{
7097 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7098}
7099
7100/* old command */
7101DEFUN (show_ipv6_mbgp_prefix,
7102 show_ipv6_mbgp_prefix_cmd,
7103 "show ipv6 mbgp X:X::X:X/M",
7104 SHOW_STR
7105 IP_STR
7106 MBGP_STR
7107 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7108{
7109 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7110}
7111#endif
7112
paul718e3742002-12-13 20:15:29 +00007113
paul94f2b392005-06-28 12:44:16 +00007114static int
paulfd79ac92004-10-13 05:06:08 +00007115bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007116 safi_t safi, enum bgp_show_type type)
7117{
7118 int i;
7119 struct buffer *b;
7120 char *regstr;
7121 int first;
7122 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007123 int rc;
paul718e3742002-12-13 20:15:29 +00007124
7125 first = 0;
7126 b = buffer_new (1024);
7127 for (i = 0; i < argc; i++)
7128 {
7129 if (first)
7130 buffer_putc (b, ' ');
7131 else
7132 {
7133 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7134 continue;
7135 first = 1;
7136 }
7137
7138 buffer_putstr (b, argv[i]);
7139 }
7140 buffer_putc (b, '\0');
7141
7142 regstr = buffer_getstr (b);
7143 buffer_free (b);
7144
7145 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007146 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007147 if (! regex)
7148 {
7149 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7150 VTY_NEWLINE);
7151 return CMD_WARNING;
7152 }
7153
ajs5a646652004-11-05 01:25:55 +00007154 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7155 bgp_regex_free (regex);
7156 return rc;
paul718e3742002-12-13 20:15:29 +00007157}
7158
7159DEFUN (show_ip_bgp_regexp,
7160 show_ip_bgp_regexp_cmd,
7161 "show ip bgp regexp .LINE",
7162 SHOW_STR
7163 IP_STR
7164 BGP_STR
7165 "Display routes matching the AS path regular expression\n"
7166 "A regular-expression to match the BGP AS paths\n")
7167{
7168 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7169 bgp_show_type_regexp);
7170}
7171
7172DEFUN (show_ip_bgp_flap_regexp,
7173 show_ip_bgp_flap_regexp_cmd,
7174 "show ip bgp flap-statistics regexp .LINE",
7175 SHOW_STR
7176 IP_STR
7177 BGP_STR
7178 "Display flap statistics of routes\n"
7179 "Display routes matching the AS path regular expression\n"
7180 "A regular-expression to match the BGP AS paths\n")
7181{
7182 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7183 bgp_show_type_flap_regexp);
7184}
7185
7186DEFUN (show_ip_bgp_ipv4_regexp,
7187 show_ip_bgp_ipv4_regexp_cmd,
7188 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7189 SHOW_STR
7190 IP_STR
7191 BGP_STR
7192 "Address family\n"
7193 "Address Family modifier\n"
7194 "Address Family modifier\n"
7195 "Display routes matching the AS path regular expression\n"
7196 "A regular-expression to match the BGP AS paths\n")
7197{
7198 if (strncmp (argv[0], "m", 1) == 0)
7199 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7200 bgp_show_type_regexp);
7201
7202 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7203 bgp_show_type_regexp);
7204}
7205
7206#ifdef HAVE_IPV6
7207DEFUN (show_bgp_regexp,
7208 show_bgp_regexp_cmd,
7209 "show bgp regexp .LINE",
7210 SHOW_STR
7211 BGP_STR
7212 "Display routes matching the AS path regular expression\n"
7213 "A regular-expression to match the BGP AS paths\n")
7214{
7215 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7216 bgp_show_type_regexp);
7217}
7218
7219ALIAS (show_bgp_regexp,
7220 show_bgp_ipv6_regexp_cmd,
7221 "show bgp ipv6 regexp .LINE",
7222 SHOW_STR
7223 BGP_STR
7224 "Address family\n"
7225 "Display routes matching the AS path regular expression\n"
7226 "A regular-expression to match the BGP AS paths\n")
7227
7228/* old command */
7229DEFUN (show_ipv6_bgp_regexp,
7230 show_ipv6_bgp_regexp_cmd,
7231 "show ipv6 bgp regexp .LINE",
7232 SHOW_STR
7233 IP_STR
7234 BGP_STR
7235 "Display routes matching the AS path regular expression\n"
7236 "A regular-expression to match the BGP AS paths\n")
7237{
7238 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7239 bgp_show_type_regexp);
7240}
7241
7242/* old command */
7243DEFUN (show_ipv6_mbgp_regexp,
7244 show_ipv6_mbgp_regexp_cmd,
7245 "show ipv6 mbgp regexp .LINE",
7246 SHOW_STR
7247 IP_STR
7248 BGP_STR
7249 "Display routes matching the AS path regular expression\n"
7250 "A regular-expression to match the MBGP AS paths\n")
7251{
7252 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7253 bgp_show_type_regexp);
7254}
7255#endif /* HAVE_IPV6 */
7256
paul94f2b392005-06-28 12:44:16 +00007257static int
paulfd79ac92004-10-13 05:06:08 +00007258bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007259 safi_t safi, enum bgp_show_type type)
7260{
7261 struct prefix_list *plist;
7262
7263 plist = prefix_list_lookup (afi, prefix_list_str);
7264 if (plist == NULL)
7265 {
7266 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7267 prefix_list_str, VTY_NEWLINE);
7268 return CMD_WARNING;
7269 }
7270
ajs5a646652004-11-05 01:25:55 +00007271 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007272}
7273
7274DEFUN (show_ip_bgp_prefix_list,
7275 show_ip_bgp_prefix_list_cmd,
7276 "show ip bgp prefix-list WORD",
7277 SHOW_STR
7278 IP_STR
7279 BGP_STR
7280 "Display routes conforming to the prefix-list\n"
7281 "IP prefix-list name\n")
7282{
7283 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7284 bgp_show_type_prefix_list);
7285}
7286
7287DEFUN (show_ip_bgp_flap_prefix_list,
7288 show_ip_bgp_flap_prefix_list_cmd,
7289 "show ip bgp flap-statistics prefix-list WORD",
7290 SHOW_STR
7291 IP_STR
7292 BGP_STR
7293 "Display flap statistics of routes\n"
7294 "Display routes conforming to the prefix-list\n"
7295 "IP prefix-list name\n")
7296{
7297 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7298 bgp_show_type_flap_prefix_list);
7299}
7300
7301DEFUN (show_ip_bgp_ipv4_prefix_list,
7302 show_ip_bgp_ipv4_prefix_list_cmd,
7303 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7304 SHOW_STR
7305 IP_STR
7306 BGP_STR
7307 "Address family\n"
7308 "Address Family modifier\n"
7309 "Address Family modifier\n"
7310 "Display routes conforming to the prefix-list\n"
7311 "IP prefix-list name\n")
7312{
7313 if (strncmp (argv[0], "m", 1) == 0)
7314 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7315 bgp_show_type_prefix_list);
7316
7317 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7318 bgp_show_type_prefix_list);
7319}
7320
7321#ifdef HAVE_IPV6
7322DEFUN (show_bgp_prefix_list,
7323 show_bgp_prefix_list_cmd,
7324 "show bgp prefix-list WORD",
7325 SHOW_STR
7326 BGP_STR
7327 "Display routes conforming to the prefix-list\n"
7328 "IPv6 prefix-list name\n")
7329{
7330 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7331 bgp_show_type_prefix_list);
7332}
7333
7334ALIAS (show_bgp_prefix_list,
7335 show_bgp_ipv6_prefix_list_cmd,
7336 "show bgp ipv6 prefix-list WORD",
7337 SHOW_STR
7338 BGP_STR
7339 "Address family\n"
7340 "Display routes conforming to the prefix-list\n"
7341 "IPv6 prefix-list name\n")
7342
7343/* old command */
7344DEFUN (show_ipv6_bgp_prefix_list,
7345 show_ipv6_bgp_prefix_list_cmd,
7346 "show ipv6 bgp prefix-list WORD",
7347 SHOW_STR
7348 IPV6_STR
7349 BGP_STR
7350 "Display routes matching the prefix-list\n"
7351 "IPv6 prefix-list name\n")
7352{
7353 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7354 bgp_show_type_prefix_list);
7355}
7356
7357/* old command */
7358DEFUN (show_ipv6_mbgp_prefix_list,
7359 show_ipv6_mbgp_prefix_list_cmd,
7360 "show ipv6 mbgp prefix-list WORD",
7361 SHOW_STR
7362 IPV6_STR
7363 MBGP_STR
7364 "Display routes matching the prefix-list\n"
7365 "IPv6 prefix-list name\n")
7366{
7367 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7368 bgp_show_type_prefix_list);
7369}
7370#endif /* HAVE_IPV6 */
7371
paul94f2b392005-06-28 12:44:16 +00007372static int
paulfd79ac92004-10-13 05:06:08 +00007373bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007374 safi_t safi, enum bgp_show_type type)
7375{
7376 struct as_list *as_list;
7377
7378 as_list = as_list_lookup (filter);
7379 if (as_list == NULL)
7380 {
7381 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7382 return CMD_WARNING;
7383 }
7384
ajs5a646652004-11-05 01:25:55 +00007385 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007386}
7387
7388DEFUN (show_ip_bgp_filter_list,
7389 show_ip_bgp_filter_list_cmd,
7390 "show ip bgp filter-list WORD",
7391 SHOW_STR
7392 IP_STR
7393 BGP_STR
7394 "Display routes conforming to the filter-list\n"
7395 "Regular expression access list name\n")
7396{
7397 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7398 bgp_show_type_filter_list);
7399}
7400
7401DEFUN (show_ip_bgp_flap_filter_list,
7402 show_ip_bgp_flap_filter_list_cmd,
7403 "show ip bgp flap-statistics filter-list WORD",
7404 SHOW_STR
7405 IP_STR
7406 BGP_STR
7407 "Display flap statistics of routes\n"
7408 "Display routes conforming to the filter-list\n"
7409 "Regular expression access list name\n")
7410{
7411 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7412 bgp_show_type_flap_filter_list);
7413}
7414
7415DEFUN (show_ip_bgp_ipv4_filter_list,
7416 show_ip_bgp_ipv4_filter_list_cmd,
7417 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7418 SHOW_STR
7419 IP_STR
7420 BGP_STR
7421 "Address family\n"
7422 "Address Family modifier\n"
7423 "Address Family modifier\n"
7424 "Display routes conforming to the filter-list\n"
7425 "Regular expression access list name\n")
7426{
7427 if (strncmp (argv[0], "m", 1) == 0)
7428 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7429 bgp_show_type_filter_list);
7430
7431 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7432 bgp_show_type_filter_list);
7433}
7434
7435#ifdef HAVE_IPV6
7436DEFUN (show_bgp_filter_list,
7437 show_bgp_filter_list_cmd,
7438 "show bgp filter-list WORD",
7439 SHOW_STR
7440 BGP_STR
7441 "Display routes conforming to the filter-list\n"
7442 "Regular expression access list name\n")
7443{
7444 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7445 bgp_show_type_filter_list);
7446}
7447
7448ALIAS (show_bgp_filter_list,
7449 show_bgp_ipv6_filter_list_cmd,
7450 "show bgp ipv6 filter-list WORD",
7451 SHOW_STR
7452 BGP_STR
7453 "Address family\n"
7454 "Display routes conforming to the filter-list\n"
7455 "Regular expression access list name\n")
7456
7457/* old command */
7458DEFUN (show_ipv6_bgp_filter_list,
7459 show_ipv6_bgp_filter_list_cmd,
7460 "show ipv6 bgp filter-list WORD",
7461 SHOW_STR
7462 IPV6_STR
7463 BGP_STR
7464 "Display routes conforming to the filter-list\n"
7465 "Regular expression access list name\n")
7466{
7467 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7468 bgp_show_type_filter_list);
7469}
7470
7471/* old command */
7472DEFUN (show_ipv6_mbgp_filter_list,
7473 show_ipv6_mbgp_filter_list_cmd,
7474 "show ipv6 mbgp filter-list WORD",
7475 SHOW_STR
7476 IPV6_STR
7477 MBGP_STR
7478 "Display routes conforming to the filter-list\n"
7479 "Regular expression access list name\n")
7480{
7481 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7482 bgp_show_type_filter_list);
7483}
7484#endif /* HAVE_IPV6 */
7485
paul94f2b392005-06-28 12:44:16 +00007486static int
paulfd79ac92004-10-13 05:06:08 +00007487bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007488 safi_t safi, enum bgp_show_type type)
7489{
7490 struct route_map *rmap;
7491
7492 rmap = route_map_lookup_by_name (rmap_str);
7493 if (! rmap)
7494 {
7495 vty_out (vty, "%% %s is not a valid route-map name%s",
7496 rmap_str, VTY_NEWLINE);
7497 return CMD_WARNING;
7498 }
7499
ajs5a646652004-11-05 01:25:55 +00007500 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007501}
7502
7503DEFUN (show_ip_bgp_route_map,
7504 show_ip_bgp_route_map_cmd,
7505 "show ip bgp route-map WORD",
7506 SHOW_STR
7507 IP_STR
7508 BGP_STR
7509 "Display routes matching the route-map\n"
7510 "A route-map to match on\n")
7511{
7512 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7513 bgp_show_type_route_map);
7514}
7515
7516DEFUN (show_ip_bgp_flap_route_map,
7517 show_ip_bgp_flap_route_map_cmd,
7518 "show ip bgp flap-statistics route-map WORD",
7519 SHOW_STR
7520 IP_STR
7521 BGP_STR
7522 "Display flap statistics of routes\n"
7523 "Display routes matching the route-map\n"
7524 "A route-map to match on\n")
7525{
7526 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7527 bgp_show_type_flap_route_map);
7528}
7529
7530DEFUN (show_ip_bgp_ipv4_route_map,
7531 show_ip_bgp_ipv4_route_map_cmd,
7532 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7533 SHOW_STR
7534 IP_STR
7535 BGP_STR
7536 "Address family\n"
7537 "Address Family modifier\n"
7538 "Address Family modifier\n"
7539 "Display routes matching the route-map\n"
7540 "A route-map to match on\n")
7541{
7542 if (strncmp (argv[0], "m", 1) == 0)
7543 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7544 bgp_show_type_route_map);
7545
7546 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7547 bgp_show_type_route_map);
7548}
7549
7550DEFUN (show_bgp_route_map,
7551 show_bgp_route_map_cmd,
7552 "show bgp route-map WORD",
7553 SHOW_STR
7554 BGP_STR
7555 "Display routes matching the route-map\n"
7556 "A route-map to match on\n")
7557{
7558 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7559 bgp_show_type_route_map);
7560}
7561
7562ALIAS (show_bgp_route_map,
7563 show_bgp_ipv6_route_map_cmd,
7564 "show bgp ipv6 route-map WORD",
7565 SHOW_STR
7566 BGP_STR
7567 "Address family\n"
7568 "Display routes matching the route-map\n"
7569 "A route-map to match on\n")
7570
7571DEFUN (show_ip_bgp_cidr_only,
7572 show_ip_bgp_cidr_only_cmd,
7573 "show ip bgp cidr-only",
7574 SHOW_STR
7575 IP_STR
7576 BGP_STR
7577 "Display only routes with non-natural netmasks\n")
7578{
7579 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007580 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007581}
7582
7583DEFUN (show_ip_bgp_flap_cidr_only,
7584 show_ip_bgp_flap_cidr_only_cmd,
7585 "show ip bgp flap-statistics cidr-only",
7586 SHOW_STR
7587 IP_STR
7588 BGP_STR
7589 "Display flap statistics of routes\n"
7590 "Display only routes with non-natural netmasks\n")
7591{
7592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007593 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007594}
7595
7596DEFUN (show_ip_bgp_ipv4_cidr_only,
7597 show_ip_bgp_ipv4_cidr_only_cmd,
7598 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7599 SHOW_STR
7600 IP_STR
7601 BGP_STR
7602 "Address family\n"
7603 "Address Family modifier\n"
7604 "Address Family modifier\n"
7605 "Display only routes with non-natural netmasks\n")
7606{
7607 if (strncmp (argv[0], "m", 1) == 0)
7608 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007609 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007610
7611 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007612 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007613}
7614
7615DEFUN (show_ip_bgp_community_all,
7616 show_ip_bgp_community_all_cmd,
7617 "show ip bgp community",
7618 SHOW_STR
7619 IP_STR
7620 BGP_STR
7621 "Display routes matching the communities\n")
7622{
7623 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007624 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007625}
7626
7627DEFUN (show_ip_bgp_ipv4_community_all,
7628 show_ip_bgp_ipv4_community_all_cmd,
7629 "show ip bgp ipv4 (unicast|multicast) community",
7630 SHOW_STR
7631 IP_STR
7632 BGP_STR
7633 "Address family\n"
7634 "Address Family modifier\n"
7635 "Address Family modifier\n"
7636 "Display routes matching the communities\n")
7637{
7638 if (strncmp (argv[0], "m", 1) == 0)
7639 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007640 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007641
7642 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007643 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007644}
7645
7646#ifdef HAVE_IPV6
7647DEFUN (show_bgp_community_all,
7648 show_bgp_community_all_cmd,
7649 "show bgp community",
7650 SHOW_STR
7651 BGP_STR
7652 "Display routes matching the communities\n")
7653{
7654 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007655 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007656}
7657
7658ALIAS (show_bgp_community_all,
7659 show_bgp_ipv6_community_all_cmd,
7660 "show bgp ipv6 community",
7661 SHOW_STR
7662 BGP_STR
7663 "Address family\n"
7664 "Display routes matching the communities\n")
7665
7666/* old command */
7667DEFUN (show_ipv6_bgp_community_all,
7668 show_ipv6_bgp_community_all_cmd,
7669 "show ipv6 bgp community",
7670 SHOW_STR
7671 IPV6_STR
7672 BGP_STR
7673 "Display routes matching the communities\n")
7674{
7675 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007676 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007677}
7678
7679/* old command */
7680DEFUN (show_ipv6_mbgp_community_all,
7681 show_ipv6_mbgp_community_all_cmd,
7682 "show ipv6 mbgp community",
7683 SHOW_STR
7684 IPV6_STR
7685 MBGP_STR
7686 "Display routes matching the communities\n")
7687{
7688 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007689 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007690}
7691#endif /* HAVE_IPV6 */
7692
paul94f2b392005-06-28 12:44:16 +00007693static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007694bgp_show_community (struct vty *vty, const char *view_name, int argc,
7695 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007696{
7697 struct community *com;
7698 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007699 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007700 int i;
7701 char *str;
7702 int first = 0;
7703
Michael Lambert95cbbd22010-07-23 14:43:04 -04007704 /* BGP structure lookup */
7705 if (view_name)
7706 {
7707 bgp = bgp_lookup_by_name (view_name);
7708 if (bgp == NULL)
7709 {
7710 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7711 return CMD_WARNING;
7712 }
7713 }
7714 else
7715 {
7716 bgp = bgp_get_default ();
7717 if (bgp == NULL)
7718 {
7719 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7720 return CMD_WARNING;
7721 }
7722 }
7723
paul718e3742002-12-13 20:15:29 +00007724 b = buffer_new (1024);
7725 for (i = 0; i < argc; i++)
7726 {
7727 if (first)
7728 buffer_putc (b, ' ');
7729 else
7730 {
7731 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7732 continue;
7733 first = 1;
7734 }
7735
7736 buffer_putstr (b, argv[i]);
7737 }
7738 buffer_putc (b, '\0');
7739
7740 str = buffer_getstr (b);
7741 buffer_free (b);
7742
7743 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007744 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007745 if (! com)
7746 {
7747 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7748 return CMD_WARNING;
7749 }
7750
Michael Lambert95cbbd22010-07-23 14:43:04 -04007751 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007752 (exact ? bgp_show_type_community_exact :
7753 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007754}
7755
7756DEFUN (show_ip_bgp_community,
7757 show_ip_bgp_community_cmd,
7758 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7759 SHOW_STR
7760 IP_STR
7761 BGP_STR
7762 "Display routes matching the communities\n"
7763 "community number\n"
7764 "Do not send outside local AS (well-known community)\n"
7765 "Do not advertise to any peer (well-known community)\n"
7766 "Do not export to next AS (well-known community)\n")
7767{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007768 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007769}
7770
7771ALIAS (show_ip_bgp_community,
7772 show_ip_bgp_community2_cmd,
7773 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7774 SHOW_STR
7775 IP_STR
7776 BGP_STR
7777 "Display routes matching the communities\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "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
7787ALIAS (show_ip_bgp_community,
7788 show_ip_bgp_community3_cmd,
7789 "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)",
7790 SHOW_STR
7791 IP_STR
7792 BGP_STR
7793 "Display routes matching the communities\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n"
7798 "community number\n"
7799 "Do not send outside local AS (well-known community)\n"
7800 "Do not advertise to any peer (well-known community)\n"
7801 "Do not export to next AS (well-known community)\n"
7802 "community number\n"
7803 "Do not send outside local AS (well-known community)\n"
7804 "Do not advertise to any peer (well-known community)\n"
7805 "Do not export to next AS (well-known community)\n")
7806
7807ALIAS (show_ip_bgp_community,
7808 show_ip_bgp_community4_cmd,
7809 "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)",
7810 SHOW_STR
7811 IP_STR
7812 BGP_STR
7813 "Display routes matching the communities\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\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
7831DEFUN (show_ip_bgp_ipv4_community,
7832 show_ip_bgp_ipv4_community_cmd,
7833 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7834 SHOW_STR
7835 IP_STR
7836 BGP_STR
7837 "Address family\n"
7838 "Address Family modifier\n"
7839 "Address Family modifier\n"
7840 "Display routes matching the communities\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n")
7845{
7846 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007847 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007848
Michael Lambert95cbbd22010-07-23 14:43:04 -04007849 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007850}
7851
7852ALIAS (show_ip_bgp_ipv4_community,
7853 show_ip_bgp_ipv4_community2_cmd,
7854 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7855 SHOW_STR
7856 IP_STR
7857 BGP_STR
7858 "Address family\n"
7859 "Address Family modifier\n"
7860 "Address Family modifier\n"
7861 "Display routes matching the communities\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n")
7870
7871ALIAS (show_ip_bgp_ipv4_community,
7872 show_ip_bgp_ipv4_community3_cmd,
7873 "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)",
7874 SHOW_STR
7875 IP_STR
7876 BGP_STR
7877 "Address family\n"
7878 "Address Family modifier\n"
7879 "Address Family modifier\n"
7880 "Display routes matching the communities\n"
7881 "community number\n"
7882 "Do not send outside local AS (well-known community)\n"
7883 "Do not advertise to any peer (well-known community)\n"
7884 "Do not export to next AS (well-known community)\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
7894ALIAS (show_ip_bgp_ipv4_community,
7895 show_ip_bgp_ipv4_community4_cmd,
7896 "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)",
7897 SHOW_STR
7898 IP_STR
7899 BGP_STR
7900 "Address family\n"
7901 "Address Family modifier\n"
7902 "Address Family modifier\n"
7903 "Display routes matching the communities\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\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
Michael Lambert95cbbd22010-07-23 14:43:04 -04007921DEFUN (show_bgp_view_afi_safi_community_all,
7922 show_bgp_view_afi_safi_community_all_cmd,
7923#ifdef HAVE_IPV6
7924 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7925#else
7926 "show bgp view WORD ipv4 (unicast|multicast) community",
7927#endif
7928 SHOW_STR
7929 BGP_STR
7930 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007931 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007932 "Address family\n"
7933#ifdef HAVE_IPV6
7934 "Address family\n"
7935#endif
7936 "Address Family modifier\n"
7937 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007938 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007939{
7940 int afi;
7941 int safi;
7942 struct bgp *bgp;
7943
7944 /* BGP structure lookup. */
7945 bgp = bgp_lookup_by_name (argv[0]);
7946 if (bgp == NULL)
7947 {
7948 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7949 return CMD_WARNING;
7950 }
7951
7952#ifdef HAVE_IPV6
7953 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7954 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7955#else
7956 afi = AFI_IP;
7957 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7958#endif
7959 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7960}
7961
7962DEFUN (show_bgp_view_afi_safi_community,
7963 show_bgp_view_afi_safi_community_cmd,
7964#ifdef HAVE_IPV6
7965 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7966#else
7967 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7968#endif
7969 SHOW_STR
7970 BGP_STR
7971 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007972 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007973 "Address family\n"
7974#ifdef HAVE_IPV6
7975 "Address family\n"
7976#endif
7977 "Address family modifier\n"
7978 "Address family modifier\n"
7979 "Display routes matching the communities\n"
7980 "community number\n"
7981 "Do not send outside local AS (well-known community)\n"
7982 "Do not advertise to any peer (well-known community)\n"
7983 "Do not export to next AS (well-known community)\n")
7984{
7985 int afi;
7986 int safi;
7987
7988#ifdef HAVE_IPV6
7989 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7990 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7991 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7992#else
7993 afi = AFI_IP;
7994 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7995 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7996#endif
7997}
7998
7999ALIAS (show_bgp_view_afi_safi_community,
8000 show_bgp_view_afi_safi_community2_cmd,
8001#ifdef HAVE_IPV6
8002 "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)",
8003#else
8004 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8005#endif
8006 SHOW_STR
8007 BGP_STR
8008 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008009 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008010 "Address family\n"
8011#ifdef HAVE_IPV6
8012 "Address family\n"
8013#endif
8014 "Address family modifier\n"
8015 "Address family modifier\n"
8016 "Display routes matching the communities\n"
8017 "community number\n"
8018 "Do not send outside local AS (well-known community)\n"
8019 "Do not advertise to any peer (well-known community)\n"
8020 "Do not export to next AS (well-known community)\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
8026ALIAS (show_bgp_view_afi_safi_community,
8027 show_bgp_view_afi_safi_community3_cmd,
8028#ifdef HAVE_IPV6
8029 "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)",
8030#else
8031 "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)",
8032#endif
8033 SHOW_STR
8034 BGP_STR
8035 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008036 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008037 "Address family\n"
8038#ifdef HAVE_IPV6
8039 "Address family\n"
8040#endif
8041 "Address family modifier\n"
8042 "Address family modifier\n"
8043 "Display routes matching the communities\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\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
8057ALIAS (show_bgp_view_afi_safi_community,
8058 show_bgp_view_afi_safi_community4_cmd,
8059#ifdef HAVE_IPV6
8060 "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)",
8061#else
8062 "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)",
8063#endif
8064 SHOW_STR
8065 BGP_STR
8066 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008067 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008068 "Address family\n"
8069#ifdef HAVE_IPV6
8070 "Address family\n"
8071#endif
8072 "Address family modifier\n"
8073 "Address family modifier\n"
8074 "Display routes matching the communities\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n"
8079 "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
paul718e3742002-12-13 20:15:29 +00008092DEFUN (show_ip_bgp_community_exact,
8093 show_ip_bgp_community_exact_cmd,
8094 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8095 SHOW_STR
8096 IP_STR
8097 BGP_STR
8098 "Display routes matching the communities\n"
8099 "community number\n"
8100 "Do not send outside local AS (well-known community)\n"
8101 "Do not advertise to any peer (well-known community)\n"
8102 "Do not export to next AS (well-known community)\n"
8103 "Exact match of the communities")
8104{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008105 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008106}
8107
8108ALIAS (show_ip_bgp_community_exact,
8109 show_ip_bgp_community2_exact_cmd,
8110 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8111 SHOW_STR
8112 IP_STR
8113 BGP_STR
8114 "Display routes matching the communities\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8124
8125ALIAS (show_ip_bgp_community_exact,
8126 show_ip_bgp_community3_exact_cmd,
8127 "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",
8128 SHOW_STR
8129 IP_STR
8130 BGP_STR
8131 "Display routes matching the communities\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "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 "Exact match of the communities")
8145
8146ALIAS (show_ip_bgp_community_exact,
8147 show_ip_bgp_community4_exact_cmd,
8148 "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",
8149 SHOW_STR
8150 IP_STR
8151 BGP_STR
8152 "Display routes matching the communities\n"
8153 "community number\n"
8154 "Do not send outside local AS (well-known community)\n"
8155 "Do not advertise to any peer (well-known community)\n"
8156 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8170
8171DEFUN (show_ip_bgp_ipv4_community_exact,
8172 show_ip_bgp_ipv4_community_exact_cmd,
8173 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8174 SHOW_STR
8175 IP_STR
8176 BGP_STR
8177 "Address family\n"
8178 "Address Family modifier\n"
8179 "Address Family modifier\n"
8180 "Display routes matching the communities\n"
8181 "community number\n"
8182 "Do not send outside local AS (well-known community)\n"
8183 "Do not advertise to any peer (well-known community)\n"
8184 "Do not export to next AS (well-known community)\n"
8185 "Exact match of the communities")
8186{
8187 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008188 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008189
Michael Lambert95cbbd22010-07-23 14:43:04 -04008190 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008191}
8192
8193ALIAS (show_ip_bgp_ipv4_community_exact,
8194 show_ip_bgp_ipv4_community2_exact_cmd,
8195 "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",
8196 SHOW_STR
8197 IP_STR
8198 BGP_STR
8199 "Address family\n"
8200 "Address Family modifier\n"
8201 "Address Family modifier\n"
8202 "Display routes matching the communities\n"
8203 "community number\n"
8204 "Do not send outside local AS (well-known community)\n"
8205 "Do not advertise to any peer (well-known community)\n"
8206 "Do not export to next AS (well-known community)\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "Exact match of the communities")
8212
8213ALIAS (show_ip_bgp_ipv4_community_exact,
8214 show_ip_bgp_ipv4_community3_exact_cmd,
8215 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8216 SHOW_STR
8217 IP_STR
8218 BGP_STR
8219 "Address family\n"
8220 "Address Family modifier\n"
8221 "Address Family modifier\n"
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "community number\n"
8232 "Do not send outside local AS (well-known community)\n"
8233 "Do not advertise to any peer (well-known community)\n"
8234 "Do not export to next AS (well-known community)\n"
8235 "Exact match of the communities")
8236
8237ALIAS (show_ip_bgp_ipv4_community_exact,
8238 show_ip_bgp_ipv4_community4_exact_cmd,
8239 "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",
8240 SHOW_STR
8241 IP_STR
8242 BGP_STR
8243 "Address family\n"
8244 "Address Family modifier\n"
8245 "Address Family modifier\n"
8246 "Display routes matching the communities\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n"
8255 "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 "Exact match of the communities")
8264
8265#ifdef HAVE_IPV6
8266DEFUN (show_bgp_community,
8267 show_bgp_community_cmd,
8268 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8269 SHOW_STR
8270 BGP_STR
8271 "Display routes matching the communities\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n")
8276{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008277 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008278}
8279
8280ALIAS (show_bgp_community,
8281 show_bgp_ipv6_community_cmd,
8282 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8283 SHOW_STR
8284 BGP_STR
8285 "Address family\n"
8286 "Display routes matching the communities\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n")
8291
8292ALIAS (show_bgp_community,
8293 show_bgp_community2_cmd,
8294 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8295 SHOW_STR
8296 BGP_STR
8297 "Display routes matching the communities\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\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
8307ALIAS (show_bgp_community,
8308 show_bgp_ipv6_community2_cmd,
8309 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8310 SHOW_STR
8311 BGP_STR
8312 "Address family\n"
8313 "Display routes matching the communities\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\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
8323ALIAS (show_bgp_community,
8324 show_bgp_community3_cmd,
8325 "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)",
8326 SHOW_STR
8327 BGP_STR
8328 "Display routes matching the communities\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n"
8337 "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
8342ALIAS (show_bgp_community,
8343 show_bgp_ipv6_community3_cmd,
8344 "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)",
8345 SHOW_STR
8346 BGP_STR
8347 "Address family\n"
8348 "Display routes matching the communities\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\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
8362ALIAS (show_bgp_community,
8363 show_bgp_community4_cmd,
8364 "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)",
8365 SHOW_STR
8366 BGP_STR
8367 "Display routes matching the communities\n"
8368 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n"
8376 "community number\n"
8377 "Do not send outside local AS (well-known community)\n"
8378 "Do not advertise to any peer (well-known community)\n"
8379 "Do not export to next AS (well-known community)\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n")
8384
8385ALIAS (show_bgp_community,
8386 show_bgp_ipv6_community4_cmd,
8387 "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)",
8388 SHOW_STR
8389 BGP_STR
8390 "Address family\n"
8391 "Display routes matching the communities\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\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
8409/* old command */
8410DEFUN (show_ipv6_bgp_community,
8411 show_ipv6_bgp_community_cmd,
8412 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8413 SHOW_STR
8414 IPV6_STR
8415 BGP_STR
8416 "Display routes matching the communities\n"
8417 "community number\n"
8418 "Do not send outside local AS (well-known community)\n"
8419 "Do not advertise to any peer (well-known community)\n"
8420 "Do not export to next AS (well-known community)\n")
8421{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008422 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008423}
8424
8425/* old command */
8426ALIAS (show_ipv6_bgp_community,
8427 show_ipv6_bgp_community2_cmd,
8428 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8429 SHOW_STR
8430 IPV6_STR
8431 BGP_STR
8432 "Display routes matching the communities\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\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
8442/* old command */
8443ALIAS (show_ipv6_bgp_community,
8444 show_ipv6_bgp_community3_cmd,
8445 "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)",
8446 SHOW_STR
8447 IPV6_STR
8448 BGP_STR
8449 "Display routes matching the communities\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\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
8463/* old command */
8464ALIAS (show_ipv6_bgp_community,
8465 show_ipv6_bgp_community4_cmd,
8466 "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)",
8467 SHOW_STR
8468 IPV6_STR
8469 BGP_STR
8470 "Display routes matching the communities\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\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
8488DEFUN (show_bgp_community_exact,
8489 show_bgp_community_exact_cmd,
8490 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8491 SHOW_STR
8492 BGP_STR
8493 "Display routes matching the communities\n"
8494 "community number\n"
8495 "Do not send outside local AS (well-known community)\n"
8496 "Do not advertise to any peer (well-known community)\n"
8497 "Do not export to next AS (well-known community)\n"
8498 "Exact match of the communities")
8499{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008500 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008501}
8502
8503ALIAS (show_bgp_community_exact,
8504 show_bgp_ipv6_community_exact_cmd,
8505 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8506 SHOW_STR
8507 BGP_STR
8508 "Address family\n"
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "Exact match of the communities")
8515
8516ALIAS (show_bgp_community_exact,
8517 show_bgp_community2_exact_cmd,
8518 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8519 SHOW_STR
8520 BGP_STR
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8531
8532ALIAS (show_bgp_community_exact,
8533 show_bgp_ipv6_community2_exact_cmd,
8534 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8535 SHOW_STR
8536 BGP_STR
8537 "Address family\n"
8538 "Display routes matching the communities\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "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 "Exact match of the communities")
8548
8549ALIAS (show_bgp_community_exact,
8550 show_bgp_community3_exact_cmd,
8551 "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",
8552 SHOW_STR
8553 BGP_STR
8554 "Display routes matching the communities\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "Exact match of the communities")
8568
8569ALIAS (show_bgp_community_exact,
8570 show_bgp_ipv6_community3_exact_cmd,
8571 "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",
8572 SHOW_STR
8573 BGP_STR
8574 "Address family\n"
8575 "Display routes matching the communities\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "Exact match of the communities")
8589
8590ALIAS (show_bgp_community_exact,
8591 show_bgp_community4_exact_cmd,
8592 "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",
8593 SHOW_STR
8594 BGP_STR
8595 "Display routes matching the communities\n"
8596 "community number\n"
8597 "Do not send outside local AS (well-known community)\n"
8598 "Do not advertise to any peer (well-known community)\n"
8599 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8613
8614ALIAS (show_bgp_community_exact,
8615 show_bgp_ipv6_community4_exact_cmd,
8616 "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",
8617 SHOW_STR
8618 BGP_STR
8619 "Address family\n"
8620 "Display routes matching the communities\n"
8621 "community number\n"
8622 "Do not send outside local AS (well-known community)\n"
8623 "Do not advertise to any peer (well-known community)\n"
8624 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8638
8639/* old command */
8640DEFUN (show_ipv6_bgp_community_exact,
8641 show_ipv6_bgp_community_exact_cmd,
8642 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8643 SHOW_STR
8644 IPV6_STR
8645 BGP_STR
8646 "Display routes matching the communities\n"
8647 "community number\n"
8648 "Do not send outside local AS (well-known community)\n"
8649 "Do not advertise to any peer (well-known community)\n"
8650 "Do not export to next AS (well-known community)\n"
8651 "Exact match of the communities")
8652{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008653 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008654}
8655
8656/* old command */
8657ALIAS (show_ipv6_bgp_community_exact,
8658 show_ipv6_bgp_community2_exact_cmd,
8659 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8660 SHOW_STR
8661 IPV6_STR
8662 BGP_STR
8663 "Display routes matching the communities\n"
8664 "community number\n"
8665 "Do not send outside local AS (well-known community)\n"
8666 "Do not advertise to any peer (well-known community)\n"
8667 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8673
8674/* old command */
8675ALIAS (show_ipv6_bgp_community_exact,
8676 show_ipv6_bgp_community3_exact_cmd,
8677 "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",
8678 SHOW_STR
8679 IPV6_STR
8680 BGP_STR
8681 "Display routes matching the communities\n"
8682 "community number\n"
8683 "Do not send outside local AS (well-known community)\n"
8684 "Do not advertise to any peer (well-known community)\n"
8685 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8695
8696/* old command */
8697ALIAS (show_ipv6_bgp_community_exact,
8698 show_ipv6_bgp_community4_exact_cmd,
8699 "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",
8700 SHOW_STR
8701 IPV6_STR
8702 BGP_STR
8703 "Display routes matching the communities\n"
8704 "community number\n"
8705 "Do not send outside local AS (well-known community)\n"
8706 "Do not advertise to any peer (well-known community)\n"
8707 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8721
8722/* old command */
8723DEFUN (show_ipv6_mbgp_community,
8724 show_ipv6_mbgp_community_cmd,
8725 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8726 SHOW_STR
8727 IPV6_STR
8728 MBGP_STR
8729 "Display routes matching the communities\n"
8730 "community number\n"
8731 "Do not send outside local AS (well-known community)\n"
8732 "Do not advertise to any peer (well-known community)\n"
8733 "Do not export to next AS (well-known community)\n")
8734{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008735 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008736}
8737
8738/* old command */
8739ALIAS (show_ipv6_mbgp_community,
8740 show_ipv6_mbgp_community2_cmd,
8741 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8742 SHOW_STR
8743 IPV6_STR
8744 MBGP_STR
8745 "Display routes matching the communities\n"
8746 "community number\n"
8747 "Do not send outside local AS (well-known community)\n"
8748 "Do not advertise to any peer (well-known community)\n"
8749 "Do not export to next AS (well-known community)\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
8755/* old command */
8756ALIAS (show_ipv6_mbgp_community,
8757 show_ipv6_mbgp_community3_cmd,
8758 "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)",
8759 SHOW_STR
8760 IPV6_STR
8761 MBGP_STR
8762 "Display routes matching the communities\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\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
8776/* old command */
8777ALIAS (show_ipv6_mbgp_community,
8778 show_ipv6_mbgp_community4_cmd,
8779 "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)",
8780 SHOW_STR
8781 IPV6_STR
8782 MBGP_STR
8783 "Display routes matching the communities\n"
8784 "community number\n"
8785 "Do not send outside local AS (well-known community)\n"
8786 "Do not advertise to any peer (well-known community)\n"
8787 "Do not export to next AS (well-known community)\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
8801/* old command */
8802DEFUN (show_ipv6_mbgp_community_exact,
8803 show_ipv6_mbgp_community_exact_cmd,
8804 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8805 SHOW_STR
8806 IPV6_STR
8807 MBGP_STR
8808 "Display routes matching the communities\n"
8809 "community number\n"
8810 "Do not send outside local AS (well-known community)\n"
8811 "Do not advertise to any peer (well-known community)\n"
8812 "Do not export to next AS (well-known community)\n"
8813 "Exact match of the communities")
8814{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008815 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008816}
8817
8818/* old command */
8819ALIAS (show_ipv6_mbgp_community_exact,
8820 show_ipv6_mbgp_community2_exact_cmd,
8821 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8822 SHOW_STR
8823 IPV6_STR
8824 MBGP_STR
8825 "Display routes matching the communities\n"
8826 "community number\n"
8827 "Do not send outside local AS (well-known community)\n"
8828 "Do not advertise to any peer (well-known community)\n"
8829 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8835
8836/* old command */
8837ALIAS (show_ipv6_mbgp_community_exact,
8838 show_ipv6_mbgp_community3_exact_cmd,
8839 "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",
8840 SHOW_STR
8841 IPV6_STR
8842 MBGP_STR
8843 "Display routes matching the communities\n"
8844 "community number\n"
8845 "Do not send outside local AS (well-known community)\n"
8846 "Do not advertise to any peer (well-known community)\n"
8847 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8857
8858/* old command */
8859ALIAS (show_ipv6_mbgp_community_exact,
8860 show_ipv6_mbgp_community4_exact_cmd,
8861 "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",
8862 SHOW_STR
8863 IPV6_STR
8864 MBGP_STR
8865 "Display routes matching the communities\n"
8866 "community number\n"
8867 "Do not send outside local AS (well-known community)\n"
8868 "Do not advertise to any peer (well-known community)\n"
8869 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8883#endif /* HAVE_IPV6 */
8884
paul94f2b392005-06-28 12:44:16 +00008885static int
paulfd79ac92004-10-13 05:06:08 +00008886bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008887 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008888{
8889 struct community_list *list;
8890
hassofee6e4e2005-02-02 16:29:31 +00008891 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008892 if (list == NULL)
8893 {
8894 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8895 VTY_NEWLINE);
8896 return CMD_WARNING;
8897 }
8898
ajs5a646652004-11-05 01:25:55 +00008899 return bgp_show (vty, NULL, afi, safi,
8900 (exact ? bgp_show_type_community_list_exact :
8901 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008902}
8903
8904DEFUN (show_ip_bgp_community_list,
8905 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008906 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008907 SHOW_STR
8908 IP_STR
8909 BGP_STR
8910 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008911 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008912 "community-list name\n")
8913{
8914 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8915}
8916
8917DEFUN (show_ip_bgp_ipv4_community_list,
8918 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008919 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008920 SHOW_STR
8921 IP_STR
8922 BGP_STR
8923 "Address family\n"
8924 "Address Family modifier\n"
8925 "Address Family modifier\n"
8926 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008927 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008928 "community-list name\n")
8929{
8930 if (strncmp (argv[0], "m", 1) == 0)
8931 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8932
8933 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8934}
8935
8936DEFUN (show_ip_bgp_community_list_exact,
8937 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008938 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008939 SHOW_STR
8940 IP_STR
8941 BGP_STR
8942 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008943 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008944 "community-list name\n"
8945 "Exact match of the communities\n")
8946{
8947 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8948}
8949
8950DEFUN (show_ip_bgp_ipv4_community_list_exact,
8951 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008952 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008953 SHOW_STR
8954 IP_STR
8955 BGP_STR
8956 "Address family\n"
8957 "Address Family modifier\n"
8958 "Address Family modifier\n"
8959 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008960 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008961 "community-list name\n"
8962 "Exact match of the communities\n")
8963{
8964 if (strncmp (argv[0], "m", 1) == 0)
8965 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8966
8967 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8968}
8969
8970#ifdef HAVE_IPV6
8971DEFUN (show_bgp_community_list,
8972 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008973 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008974 SHOW_STR
8975 BGP_STR
8976 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008977 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008978 "community-list name\n")
8979{
8980 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8981}
8982
8983ALIAS (show_bgp_community_list,
8984 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008985 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008986 SHOW_STR
8987 BGP_STR
8988 "Address family\n"
8989 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008990 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008991 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008992
8993/* old command */
8994DEFUN (show_ipv6_bgp_community_list,
8995 show_ipv6_bgp_community_list_cmd,
8996 "show ipv6 bgp community-list WORD",
8997 SHOW_STR
8998 IPV6_STR
8999 BGP_STR
9000 "Display routes matching the community-list\n"
9001 "community-list name\n")
9002{
9003 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9004}
9005
9006/* old command */
9007DEFUN (show_ipv6_mbgp_community_list,
9008 show_ipv6_mbgp_community_list_cmd,
9009 "show ipv6 mbgp community-list WORD",
9010 SHOW_STR
9011 IPV6_STR
9012 MBGP_STR
9013 "Display routes matching the community-list\n"
9014 "community-list name\n")
9015{
9016 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9017}
9018
9019DEFUN (show_bgp_community_list_exact,
9020 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009021 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009022 SHOW_STR
9023 BGP_STR
9024 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009025 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009026 "community-list name\n"
9027 "Exact match of the communities\n")
9028{
9029 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9030}
9031
9032ALIAS (show_bgp_community_list_exact,
9033 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009034 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009035 SHOW_STR
9036 BGP_STR
9037 "Address family\n"
9038 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009039 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009040 "community-list name\n"
9041 "Exact match of the communities\n")
9042
9043/* old command */
9044DEFUN (show_ipv6_bgp_community_list_exact,
9045 show_ipv6_bgp_community_list_exact_cmd,
9046 "show ipv6 bgp community-list WORD exact-match",
9047 SHOW_STR
9048 IPV6_STR
9049 BGP_STR
9050 "Display routes matching the community-list\n"
9051 "community-list name\n"
9052 "Exact match of the communities\n")
9053{
9054 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9055}
9056
9057/* old command */
9058DEFUN (show_ipv6_mbgp_community_list_exact,
9059 show_ipv6_mbgp_community_list_exact_cmd,
9060 "show ipv6 mbgp community-list WORD exact-match",
9061 SHOW_STR
9062 IPV6_STR
9063 MBGP_STR
9064 "Display routes matching the community-list\n"
9065 "community-list name\n"
9066 "Exact match of the communities\n")
9067{
9068 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9069}
9070#endif /* HAVE_IPV6 */
9071
paul94f2b392005-06-28 12:44:16 +00009072static int
paulfd79ac92004-10-13 05:06:08 +00009073bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009074 safi_t safi, enum bgp_show_type type)
9075{
9076 int ret;
9077 struct prefix *p;
9078
9079 p = prefix_new();
9080
9081 ret = str2prefix (prefix, p);
9082 if (! ret)
9083 {
9084 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9085 return CMD_WARNING;
9086 }
9087
ajs5a646652004-11-05 01:25:55 +00009088 ret = bgp_show (vty, NULL, afi, safi, type, p);
9089 prefix_free(p);
9090 return ret;
paul718e3742002-12-13 20:15:29 +00009091}
9092
9093DEFUN (show_ip_bgp_prefix_longer,
9094 show_ip_bgp_prefix_longer_cmd,
9095 "show ip bgp A.B.C.D/M longer-prefixes",
9096 SHOW_STR
9097 IP_STR
9098 BGP_STR
9099 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9100 "Display route and more specific routes\n")
9101{
9102 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9103 bgp_show_type_prefix_longer);
9104}
9105
9106DEFUN (show_ip_bgp_flap_prefix_longer,
9107 show_ip_bgp_flap_prefix_longer_cmd,
9108 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9109 SHOW_STR
9110 IP_STR
9111 BGP_STR
9112 "Display flap statistics of routes\n"
9113 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9114 "Display route and more specific routes\n")
9115{
9116 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9117 bgp_show_type_flap_prefix_longer);
9118}
9119
9120DEFUN (show_ip_bgp_ipv4_prefix_longer,
9121 show_ip_bgp_ipv4_prefix_longer_cmd,
9122 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9123 SHOW_STR
9124 IP_STR
9125 BGP_STR
9126 "Address family\n"
9127 "Address Family modifier\n"
9128 "Address Family modifier\n"
9129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9130 "Display route and more specific routes\n")
9131{
9132 if (strncmp (argv[0], "m", 1) == 0)
9133 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9134 bgp_show_type_prefix_longer);
9135
9136 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9137 bgp_show_type_prefix_longer);
9138}
9139
9140DEFUN (show_ip_bgp_flap_address,
9141 show_ip_bgp_flap_address_cmd,
9142 "show ip bgp flap-statistics A.B.C.D",
9143 SHOW_STR
9144 IP_STR
9145 BGP_STR
9146 "Display flap statistics of routes\n"
9147 "Network in the BGP routing table to display\n")
9148{
9149 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9150 bgp_show_type_flap_address);
9151}
9152
9153DEFUN (show_ip_bgp_flap_prefix,
9154 show_ip_bgp_flap_prefix_cmd,
9155 "show ip bgp flap-statistics A.B.C.D/M",
9156 SHOW_STR
9157 IP_STR
9158 BGP_STR
9159 "Display flap statistics of routes\n"
9160 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9161{
9162 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9163 bgp_show_type_flap_prefix);
9164}
9165#ifdef HAVE_IPV6
9166DEFUN (show_bgp_prefix_longer,
9167 show_bgp_prefix_longer_cmd,
9168 "show bgp X:X::X:X/M longer-prefixes",
9169 SHOW_STR
9170 BGP_STR
9171 "IPv6 prefix <network>/<length>\n"
9172 "Display route and more specific routes\n")
9173{
9174 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9175 bgp_show_type_prefix_longer);
9176}
9177
9178ALIAS (show_bgp_prefix_longer,
9179 show_bgp_ipv6_prefix_longer_cmd,
9180 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9181 SHOW_STR
9182 BGP_STR
9183 "Address family\n"
9184 "IPv6 prefix <network>/<length>\n"
9185 "Display route and more specific routes\n")
9186
9187/* old command */
9188DEFUN (show_ipv6_bgp_prefix_longer,
9189 show_ipv6_bgp_prefix_longer_cmd,
9190 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9191 SHOW_STR
9192 IPV6_STR
9193 BGP_STR
9194 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9195 "Display route and more specific routes\n")
9196{
9197 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9198 bgp_show_type_prefix_longer);
9199}
9200
9201/* old command */
9202DEFUN (show_ipv6_mbgp_prefix_longer,
9203 show_ipv6_mbgp_prefix_longer_cmd,
9204 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9205 SHOW_STR
9206 IPV6_STR
9207 MBGP_STR
9208 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9209 "Display route and more specific routes\n")
9210{
9211 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9212 bgp_show_type_prefix_longer);
9213}
9214#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009215
paul94f2b392005-06-28 12:44:16 +00009216static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009217peer_lookup_in_view (struct vty *vty, const char *view_name,
9218 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009219{
9220 int ret;
9221 struct bgp *bgp;
9222 struct peer *peer;
9223 union sockunion su;
9224
9225 /* BGP structure lookup. */
9226 if (view_name)
9227 {
9228 bgp = bgp_lookup_by_name (view_name);
9229 if (! bgp)
9230 {
9231 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9232 return NULL;
9233 }
9234 }
paul5228ad22004-06-04 17:58:18 +00009235 else
paulbb46e942003-10-24 19:02:03 +00009236 {
9237 bgp = bgp_get_default ();
9238 if (! bgp)
9239 {
9240 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9241 return NULL;
9242 }
9243 }
9244
9245 /* Get peer sockunion. */
9246 ret = str2sockunion (ip_str, &su);
9247 if (ret < 0)
9248 {
9249 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9250 return NULL;
9251 }
9252
9253 /* Peer structure lookup. */
9254 peer = peer_lookup (bgp, &su);
9255 if (! peer)
9256 {
9257 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9258 return NULL;
9259 }
9260
9261 return peer;
9262}
Paul Jakma2815e612006-09-14 02:56:07 +00009263
9264enum bgp_stats
9265{
9266 BGP_STATS_MAXBITLEN = 0,
9267 BGP_STATS_RIB,
9268 BGP_STATS_PREFIXES,
9269 BGP_STATS_TOTPLEN,
9270 BGP_STATS_UNAGGREGATEABLE,
9271 BGP_STATS_MAX_AGGREGATEABLE,
9272 BGP_STATS_AGGREGATES,
9273 BGP_STATS_SPACE,
9274 BGP_STATS_ASPATH_COUNT,
9275 BGP_STATS_ASPATH_MAXHOPS,
9276 BGP_STATS_ASPATH_TOTHOPS,
9277 BGP_STATS_ASPATH_MAXSIZE,
9278 BGP_STATS_ASPATH_TOTSIZE,
9279 BGP_STATS_ASN_HIGHEST,
9280 BGP_STATS_MAX,
9281};
paulbb46e942003-10-24 19:02:03 +00009282
Paul Jakma2815e612006-09-14 02:56:07 +00009283static const char *table_stats_strs[] =
9284{
9285 [BGP_STATS_PREFIXES] = "Total Prefixes",
9286 [BGP_STATS_TOTPLEN] = "Average prefix length",
9287 [BGP_STATS_RIB] = "Total Advertisements",
9288 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9289 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9290 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9291 [BGP_STATS_SPACE] = "Address space advertised",
9292 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9293 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9294 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9295 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9296 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9297 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9298 [BGP_STATS_MAX] = NULL,
9299};
9300
9301struct bgp_table_stats
9302{
9303 struct bgp_table *table;
9304 unsigned long long counts[BGP_STATS_MAX];
9305};
9306
9307#if 0
9308#define TALLY_SIGFIG 100000
9309static unsigned long
9310ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9311{
9312 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9313 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9314 unsigned long ret = newtot / count;
9315
9316 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9317 return ret + 1;
9318 else
9319 return ret;
9320}
9321#endif
9322
9323static int
9324bgp_table_stats_walker (struct thread *t)
9325{
9326 struct bgp_node *rn;
9327 struct bgp_node *top;
9328 struct bgp_table_stats *ts = THREAD_ARG (t);
9329 unsigned int space = 0;
9330
Paul Jakma53d9f672006-10-15 23:41:16 +00009331 if (!(top = bgp_table_top (ts->table)))
9332 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009333
9334 switch (top->p.family)
9335 {
9336 case AF_INET:
9337 space = IPV4_MAX_BITLEN;
9338 break;
9339 case AF_INET6:
9340 space = IPV6_MAX_BITLEN;
9341 break;
9342 }
9343
9344 ts->counts[BGP_STATS_MAXBITLEN] = space;
9345
9346 for (rn = top; rn; rn = bgp_route_next (rn))
9347 {
9348 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009349 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009350 unsigned int rinum = 0;
9351
9352 if (rn == top)
9353 continue;
9354
9355 if (!rn->info)
9356 continue;
9357
9358 ts->counts[BGP_STATS_PREFIXES]++;
9359 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9360
9361#if 0
9362 ts->counts[BGP_STATS_AVGPLEN]
9363 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9364 ts->counts[BGP_STATS_AVGPLEN],
9365 rn->p.prefixlen);
9366#endif
9367
9368 /* check if the prefix is included by any other announcements */
9369 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009370 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009371
9372 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009373 {
9374 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9375 /* announced address space */
9376 if (space)
9377 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9378 }
Paul Jakma2815e612006-09-14 02:56:07 +00009379 else if (prn->info)
9380 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9381
Paul Jakma2815e612006-09-14 02:56:07 +00009382 for (ri = rn->info; ri; ri = ri->next)
9383 {
9384 rinum++;
9385 ts->counts[BGP_STATS_RIB]++;
9386
9387 if (ri->attr &&
9388 (CHECK_FLAG (ri->attr->flag,
9389 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9390 ts->counts[BGP_STATS_AGGREGATES]++;
9391
9392 /* as-path stats */
9393 if (ri->attr && ri->attr->aspath)
9394 {
9395 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9396 unsigned int size = aspath_size (ri->attr->aspath);
9397 as_t highest = aspath_highest (ri->attr->aspath);
9398
9399 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9400
9401 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9402 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9403
9404 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9405 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9406
9407 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9408 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9409#if 0
9410 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9411 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9412 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9413 hops);
9414 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9415 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9416 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9417 size);
9418#endif
9419 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9420 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9421 }
9422 }
9423 }
9424 return 0;
9425}
9426
9427static int
9428bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9429{
9430 struct bgp_table_stats ts;
9431 unsigned int i;
9432
9433 if (!bgp->rib[afi][safi])
9434 {
9435 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9436 return CMD_WARNING;
9437 }
9438
9439 memset (&ts, 0, sizeof (ts));
9440 ts.table = bgp->rib[afi][safi];
9441 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9442
9443 vty_out (vty, "BGP %s RIB statistics%s%s",
9444 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9445
9446 for (i = 0; i < BGP_STATS_MAX; i++)
9447 {
9448 if (!table_stats_strs[i])
9449 continue;
9450
9451 switch (i)
9452 {
9453#if 0
9454 case BGP_STATS_ASPATH_AVGHOPS:
9455 case BGP_STATS_ASPATH_AVGSIZE:
9456 case BGP_STATS_AVGPLEN:
9457 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9458 vty_out (vty, "%12.2f",
9459 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9460 break;
9461#endif
9462 case BGP_STATS_ASPATH_TOTHOPS:
9463 case BGP_STATS_ASPATH_TOTSIZE:
9464 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9465 vty_out (vty, "%12.2f",
9466 ts.counts[i] ?
9467 (float)ts.counts[i] /
9468 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9469 : 0);
9470 break;
9471 case BGP_STATS_TOTPLEN:
9472 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9473 vty_out (vty, "%12.2f",
9474 ts.counts[i] ?
9475 (float)ts.counts[i] /
9476 (float)ts.counts[BGP_STATS_PREFIXES]
9477 : 0);
9478 break;
9479 case BGP_STATS_SPACE:
9480 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9481 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9482 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9483 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009484 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009485 vty_out (vty, "%12.2f%s",
9486 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009487 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009488 VTY_NEWLINE);
9489 vty_out (vty, "%30s: ", "/8 equivalent ");
9490 vty_out (vty, "%12.2f%s",
9491 (float)ts.counts[BGP_STATS_SPACE] /
9492 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9493 VTY_NEWLINE);
9494 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9495 break;
9496 vty_out (vty, "%30s: ", "/24 equivalent ");
9497 vty_out (vty, "%12.2f",
9498 (float)ts.counts[BGP_STATS_SPACE] /
9499 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9500 break;
9501 default:
9502 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9503 vty_out (vty, "%12llu", ts.counts[i]);
9504 }
9505
9506 vty_out (vty, "%s", VTY_NEWLINE);
9507 }
9508 return CMD_SUCCESS;
9509}
9510
9511static int
9512bgp_table_stats_vty (struct vty *vty, const char *name,
9513 const char *afi_str, const char *safi_str)
9514{
9515 struct bgp *bgp;
9516 afi_t afi;
9517 safi_t safi;
9518
9519 if (name)
9520 bgp = bgp_lookup_by_name (name);
9521 else
9522 bgp = bgp_get_default ();
9523
9524 if (!bgp)
9525 {
9526 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9527 return CMD_WARNING;
9528 }
9529 if (strncmp (afi_str, "ipv", 3) == 0)
9530 {
9531 if (strncmp (afi_str, "ipv4", 4) == 0)
9532 afi = AFI_IP;
9533 else if (strncmp (afi_str, "ipv6", 4) == 0)
9534 afi = AFI_IP6;
9535 else
9536 {
9537 vty_out (vty, "%% Invalid address family %s%s",
9538 afi_str, VTY_NEWLINE);
9539 return CMD_WARNING;
9540 }
9541 if (strncmp (safi_str, "m", 1) == 0)
9542 safi = SAFI_MULTICAST;
9543 else if (strncmp (safi_str, "u", 1) == 0)
9544 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009545 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9546 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009547 else
9548 {
9549 vty_out (vty, "%% Invalid subsequent address family %s%s",
9550 safi_str, VTY_NEWLINE);
9551 return CMD_WARNING;
9552 }
9553 }
9554 else
9555 {
9556 vty_out (vty, "%% Invalid address family %s%s",
9557 afi_str, VTY_NEWLINE);
9558 return CMD_WARNING;
9559 }
9560
Paul Jakma2815e612006-09-14 02:56:07 +00009561 return bgp_table_stats (vty, bgp, afi, safi);
9562}
9563
9564DEFUN (show_bgp_statistics,
9565 show_bgp_statistics_cmd,
9566 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9567 SHOW_STR
9568 BGP_STR
9569 "Address family\n"
9570 "Address family\n"
9571 "Address Family modifier\n"
9572 "Address Family modifier\n"
9573 "BGP RIB advertisement statistics\n")
9574{
9575 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9576}
9577
9578ALIAS (show_bgp_statistics,
9579 show_bgp_statistics_vpnv4_cmd,
9580 "show bgp (ipv4) (vpnv4) statistics",
9581 SHOW_STR
9582 BGP_STR
9583 "Address family\n"
9584 "Address Family modifier\n"
9585 "BGP RIB advertisement statistics\n")
9586
9587DEFUN (show_bgp_statistics_view,
9588 show_bgp_statistics_view_cmd,
9589 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9590 SHOW_STR
9591 BGP_STR
9592 "BGP view\n"
9593 "Address family\n"
9594 "Address family\n"
9595 "Address Family modifier\n"
9596 "Address Family modifier\n"
9597 "BGP RIB advertisement statistics\n")
9598{
9599 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9600}
9601
9602ALIAS (show_bgp_statistics_view,
9603 show_bgp_statistics_view_vpnv4_cmd,
9604 "show bgp view WORD (ipv4) (vpnv4) statistics",
9605 SHOW_STR
9606 BGP_STR
9607 "BGP view\n"
9608 "Address family\n"
9609 "Address Family modifier\n"
9610 "BGP RIB advertisement statistics\n")
9611
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612enum bgp_pcounts
9613{
9614 PCOUNT_ADJ_IN = 0,
9615 PCOUNT_DAMPED,
9616 PCOUNT_REMOVED,
9617 PCOUNT_HISTORY,
9618 PCOUNT_STALE,
9619 PCOUNT_VALID,
9620 PCOUNT_ALL,
9621 PCOUNT_COUNTED,
9622 PCOUNT_PFCNT, /* the figure we display to users */
9623 PCOUNT_MAX,
9624};
9625
9626static const char *pcount_strs[] =
9627{
9628 [PCOUNT_ADJ_IN] = "Adj-in",
9629 [PCOUNT_DAMPED] = "Damped",
9630 [PCOUNT_REMOVED] = "Removed",
9631 [PCOUNT_HISTORY] = "History",
9632 [PCOUNT_STALE] = "Stale",
9633 [PCOUNT_VALID] = "Valid",
9634 [PCOUNT_ALL] = "All RIB",
9635 [PCOUNT_COUNTED] = "PfxCt counted",
9636 [PCOUNT_PFCNT] = "Useable",
9637 [PCOUNT_MAX] = NULL,
9638};
9639
Paul Jakma2815e612006-09-14 02:56:07 +00009640struct peer_pcounts
9641{
9642 unsigned int count[PCOUNT_MAX];
9643 const struct peer *peer;
9644 const struct bgp_table *table;
9645};
9646
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647static int
Paul Jakma2815e612006-09-14 02:56:07 +00009648bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649{
9650 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009651 struct peer_pcounts *pc = THREAD_ARG (t);
9652 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653
Paul Jakma2815e612006-09-14 02:56:07 +00009654 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009655 {
9656 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009657 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009658
9659 for (ain = rn->adj_in; ain; ain = ain->next)
9660 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009661 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009662
Paul Jakmaff7924f2006-09-04 01:10:36 +00009663 for (ri = rn->info; ri; ri = ri->next)
9664 {
9665 char buf[SU_ADDRSTRLEN];
9666
9667 if (ri->peer != peer)
9668 continue;
9669
Paul Jakma2815e612006-09-14 02:56:07 +00009670 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009671
9672 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009673 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009674 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009675 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009676 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009677 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009678 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009679 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009680 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009681 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009682 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009683 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009684
9685 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9686 {
Paul Jakma2815e612006-09-14 02:56:07 +00009687 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009688 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009689 plog_warn (peer->log,
9690 "%s [pcount] %s/%d is counted but flags 0x%x",
9691 peer->host,
9692 inet_ntop(rn->p.family, &rn->p.u.prefix,
9693 buf, SU_ADDRSTRLEN),
9694 rn->p.prefixlen,
9695 ri->flags);
9696 }
9697 else
9698 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009699 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009700 plog_warn (peer->log,
9701 "%s [pcount] %s/%d not counted but flags 0x%x",
9702 peer->host,
9703 inet_ntop(rn->p.family, &rn->p.u.prefix,
9704 buf, SU_ADDRSTRLEN),
9705 rn->p.prefixlen,
9706 ri->flags);
9707 }
9708 }
9709 }
Paul Jakma2815e612006-09-14 02:56:07 +00009710 return 0;
9711}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009712
Paul Jakma2815e612006-09-14 02:56:07 +00009713static int
9714bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9715{
9716 struct peer_pcounts pcounts = { .peer = peer };
9717 unsigned int i;
9718
9719 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9720 || !peer->bgp->rib[afi][safi])
9721 {
9722 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9723 return CMD_WARNING;
9724 }
9725
9726 memset (&pcounts, 0, sizeof(pcounts));
9727 pcounts.peer = peer;
9728 pcounts.table = peer->bgp->rib[afi][safi];
9729
9730 /* in-place call via thread subsystem so as to record execution time
9731 * stats for the thread-walk (i.e. ensure this can't be blamed on
9732 * on just vty_read()).
9733 */
9734 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9735
Paul Jakmaff7924f2006-09-04 01:10:36 +00009736 vty_out (vty, "Prefix counts for %s, %s%s",
9737 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9738 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9739 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9740 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9741
9742 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009743 vty_out (vty, "%20s: %-10d%s",
9744 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009745
Paul Jakma2815e612006-09-14 02:56:07 +00009746 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009747 {
9748 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9749 peer->host, VTY_NEWLINE);
9750 vty_out (vty, "Please report this bug, with the above command output%s",
9751 VTY_NEWLINE);
9752 }
9753
9754 return CMD_SUCCESS;
9755}
9756
9757DEFUN (show_ip_bgp_neighbor_prefix_counts,
9758 show_ip_bgp_neighbor_prefix_counts_cmd,
9759 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9760 SHOW_STR
9761 IP_STR
9762 BGP_STR
9763 "Detailed information on TCP and BGP neighbor connections\n"
9764 "Neighbor to display information about\n"
9765 "Neighbor to display information about\n"
9766 "Display detailed prefix count information\n")
9767{
9768 struct peer *peer;
9769
9770 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9771 if (! peer)
9772 return CMD_WARNING;
9773
9774 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9775}
9776
9777DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9778 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9779 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9780 SHOW_STR
9781 BGP_STR
9782 "Address family\n"
9783 "Detailed information on TCP and BGP neighbor connections\n"
9784 "Neighbor to display information about\n"
9785 "Neighbor to display information about\n"
9786 "Display detailed prefix count information\n")
9787{
9788 struct peer *peer;
9789
9790 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9791 if (! peer)
9792 return CMD_WARNING;
9793
9794 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9795}
9796
9797DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9798 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9799 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9800 SHOW_STR
9801 IP_STR
9802 BGP_STR
9803 "Address family\n"
9804 "Address Family modifier\n"
9805 "Address Family modifier\n"
9806 "Detailed information on TCP and BGP neighbor connections\n"
9807 "Neighbor to display information about\n"
9808 "Neighbor to display information about\n"
9809 "Display detailed prefix count information\n")
9810{
9811 struct peer *peer;
9812
9813 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9814 if (! peer)
9815 return CMD_WARNING;
9816
9817 if (strncmp (argv[0], "m", 1) == 0)
9818 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9819
9820 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9821}
9822
9823DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9824 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9825 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9826 SHOW_STR
9827 IP_STR
9828 BGP_STR
9829 "Address family\n"
9830 "Address Family modifier\n"
9831 "Address Family modifier\n"
9832 "Detailed information on TCP and BGP neighbor connections\n"
9833 "Neighbor to display information about\n"
9834 "Neighbor to display information about\n"
9835 "Display detailed prefix count information\n")
9836{
9837 struct peer *peer;
9838
9839 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9840 if (! peer)
9841 return CMD_WARNING;
9842
9843 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9844}
9845
9846
paul94f2b392005-06-28 12:44:16 +00009847static void
paul718e3742002-12-13 20:15:29 +00009848show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9849 int in)
9850{
9851 struct bgp_table *table;
9852 struct bgp_adj_in *ain;
9853 struct bgp_adj_out *adj;
9854 unsigned long output_count;
9855 struct bgp_node *rn;
9856 int header1 = 1;
9857 struct bgp *bgp;
9858 int header2 = 1;
9859
paulbb46e942003-10-24 19:02:03 +00009860 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009861
9862 if (! bgp)
9863 return;
9864
9865 table = bgp->rib[afi][safi];
9866
9867 output_count = 0;
9868
9869 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9870 PEER_STATUS_DEFAULT_ORIGINATE))
9871 {
9872 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 +00009873 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9874 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009875
9876 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9877 VTY_NEWLINE, VTY_NEWLINE);
9878 header1 = 0;
9879 }
9880
9881 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9882 if (in)
9883 {
9884 for (ain = rn->adj_in; ain; ain = ain->next)
9885 if (ain->peer == peer)
9886 {
9887 if (header1)
9888 {
9889 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
hasso93406d82005-02-02 14:40:33 +00009890 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9891 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009892 header1 = 0;
9893 }
9894 if (header2)
9895 {
9896 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9897 header2 = 0;
9898 }
9899 if (ain->attr)
9900 {
9901 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9902 output_count++;
9903 }
9904 }
9905 }
9906 else
9907 {
9908 for (adj = rn->adj_out; adj; adj = adj->next)
9909 if (adj->peer == peer)
9910 {
9911 if (header1)
9912 {
9913 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 +00009914 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9915 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009916 header1 = 0;
9917 }
9918 if (header2)
9919 {
9920 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9921 header2 = 0;
9922 }
9923 if (adj->attr)
9924 {
9925 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9926 output_count++;
9927 }
9928 }
9929 }
9930
9931 if (output_count != 0)
9932 vty_out (vty, "%sTotal number of prefixes %ld%s",
9933 VTY_NEWLINE, output_count, VTY_NEWLINE);
9934}
9935
paul94f2b392005-06-28 12:44:16 +00009936static int
paulbb46e942003-10-24 19:02:03 +00009937peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9938{
paul718e3742002-12-13 20:15:29 +00009939 if (! peer || ! peer->afc[afi][safi])
9940 {
9941 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9942 return CMD_WARNING;
9943 }
9944
9945 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9946 {
9947 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9948 VTY_NEWLINE);
9949 return CMD_WARNING;
9950 }
9951
9952 show_adj_route (vty, peer, afi, safi, in);
9953
9954 return CMD_SUCCESS;
9955}
9956
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009957DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9958 show_ip_bgp_view_neighbor_advertised_route_cmd,
9959 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9960 SHOW_STR
9961 IP_STR
9962 BGP_STR
9963 "BGP view\n"
9964 "View name\n"
9965 "Detailed information on TCP and BGP neighbor connections\n"
9966 "Neighbor to display information about\n"
9967 "Neighbor to display information about\n"
9968 "Display the routes advertised to a BGP neighbor\n")
9969{
9970 struct peer *peer;
9971
9972 if (argc == 2)
9973 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9974 else
9975 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9976
9977 if (! peer)
9978 return CMD_WARNING;
9979
9980 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9981}
9982
9983ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009984 show_ip_bgp_neighbor_advertised_route_cmd,
9985 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9986 SHOW_STR
9987 IP_STR
9988 BGP_STR
9989 "Detailed information on TCP and BGP neighbor connections\n"
9990 "Neighbor to display information about\n"
9991 "Neighbor to display information about\n"
9992 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009993
9994DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9995 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9996 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9997 SHOW_STR
9998 IP_STR
9999 BGP_STR
10000 "Address family\n"
10001 "Address Family modifier\n"
10002 "Address Family modifier\n"
10003 "Detailed information on TCP and BGP neighbor connections\n"
10004 "Neighbor to display information about\n"
10005 "Neighbor to display information about\n"
10006 "Display the routes advertised to a BGP neighbor\n")
10007{
paulbb46e942003-10-24 19:02:03 +000010008 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010009
paulbb46e942003-10-24 19:02:03 +000010010 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10011 if (! peer)
10012 return CMD_WARNING;
10013
10014 if (strncmp (argv[0], "m", 1) == 0)
10015 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10016
10017 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010018}
10019
10020#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010021DEFUN (show_bgp_view_neighbor_advertised_route,
10022 show_bgp_view_neighbor_advertised_route_cmd,
10023 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10024 SHOW_STR
10025 BGP_STR
10026 "BGP view\n"
10027 "View name\n"
10028 "Detailed information on TCP and BGP neighbor connections\n"
10029 "Neighbor to display information about\n"
10030 "Neighbor to display information about\n"
10031 "Display the routes advertised to a BGP neighbor\n")
10032{
10033 struct peer *peer;
10034
10035 if (argc == 2)
10036 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10037 else
10038 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10039
10040 if (! peer)
10041 return CMD_WARNING;
10042
10043 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10044}
10045
10046ALIAS (show_bgp_view_neighbor_advertised_route,
10047 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10048 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10049 SHOW_STR
10050 BGP_STR
10051 "BGP view\n"
10052 "View name\n"
10053 "Address family\n"
10054 "Detailed information on TCP and BGP neighbor connections\n"
10055 "Neighbor to display information about\n"
10056 "Neighbor to display information about\n"
10057 "Display the routes advertised to a BGP neighbor\n")
10058
10059DEFUN (show_bgp_view_neighbor_received_routes,
10060 show_bgp_view_neighbor_received_routes_cmd,
10061 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10062 SHOW_STR
10063 BGP_STR
10064 "BGP view\n"
10065 "View name\n"
10066 "Detailed information on TCP and BGP neighbor connections\n"
10067 "Neighbor to display information about\n"
10068 "Neighbor to display information about\n"
10069 "Display the received routes from neighbor\n")
10070{
10071 struct peer *peer;
10072
10073 if (argc == 2)
10074 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10075 else
10076 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10077
10078 if (! peer)
10079 return CMD_WARNING;
10080
10081 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10082}
10083
10084ALIAS (show_bgp_view_neighbor_received_routes,
10085 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10086 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10087 SHOW_STR
10088 BGP_STR
10089 "BGP view\n"
10090 "View name\n"
10091 "Address family\n"
10092 "Detailed information on TCP and BGP neighbor connections\n"
10093 "Neighbor to display information about\n"
10094 "Neighbor to display information about\n"
10095 "Display the received routes from neighbor\n")
10096
10097ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010098 show_bgp_neighbor_advertised_route_cmd,
10099 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10100 SHOW_STR
10101 BGP_STR
10102 "Detailed information on TCP and BGP neighbor connections\n"
10103 "Neighbor to display information about\n"
10104 "Neighbor to display information about\n"
10105 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010106
10107ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010108 show_bgp_ipv6_neighbor_advertised_route_cmd,
10109 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10110 SHOW_STR
10111 BGP_STR
10112 "Address family\n"
10113 "Detailed information on TCP and BGP neighbor connections\n"
10114 "Neighbor to display information about\n"
10115 "Neighbor to display information about\n"
10116 "Display the routes advertised to a BGP neighbor\n")
10117
10118/* old command */
paulbb46e942003-10-24 19:02:03 +000010119ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010120 ipv6_bgp_neighbor_advertised_route_cmd,
10121 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10122 SHOW_STR
10123 IPV6_STR
10124 BGP_STR
10125 "Detailed information on TCP and BGP neighbor connections\n"
10126 "Neighbor to display information about\n"
10127 "Neighbor to display information about\n"
10128 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010129
paul718e3742002-12-13 20:15:29 +000010130/* old command */
10131DEFUN (ipv6_mbgp_neighbor_advertised_route,
10132 ipv6_mbgp_neighbor_advertised_route_cmd,
10133 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10134 SHOW_STR
10135 IPV6_STR
10136 MBGP_STR
10137 "Detailed information on TCP and BGP neighbor connections\n"
10138 "Neighbor to display information about\n"
10139 "Neighbor to display information about\n"
10140 "Display the routes advertised to a BGP neighbor\n")
10141{
paulbb46e942003-10-24 19:02:03 +000010142 struct peer *peer;
10143
10144 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10145 if (! peer)
10146 return CMD_WARNING;
10147
10148 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010149}
10150#endif /* HAVE_IPV6 */
10151
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010152DEFUN (show_ip_bgp_view_neighbor_received_routes,
10153 show_ip_bgp_view_neighbor_received_routes_cmd,
10154 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10155 SHOW_STR
10156 IP_STR
10157 BGP_STR
10158 "BGP view\n"
10159 "View name\n"
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display the received routes from neighbor\n")
10164{
10165 struct peer *peer;
10166
10167 if (argc == 2)
10168 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10169 else
10170 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10171
10172 if (! peer)
10173 return CMD_WARNING;
10174
10175 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10176}
10177
10178ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010179 show_ip_bgp_neighbor_received_routes_cmd,
10180 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10181 SHOW_STR
10182 IP_STR
10183 BGP_STR
10184 "Detailed information on TCP and BGP neighbor connections\n"
10185 "Neighbor to display information about\n"
10186 "Neighbor to display information about\n"
10187 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010188
10189DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10190 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10191 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10192 SHOW_STR
10193 IP_STR
10194 BGP_STR
10195 "Address family\n"
10196 "Address Family modifier\n"
10197 "Address Family modifier\n"
10198 "Detailed information on TCP and BGP neighbor connections\n"
10199 "Neighbor to display information about\n"
10200 "Neighbor to display information about\n"
10201 "Display the received routes from neighbor\n")
10202{
paulbb46e942003-10-24 19:02:03 +000010203 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010204
paulbb46e942003-10-24 19:02:03 +000010205 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10206 if (! peer)
10207 return CMD_WARNING;
10208
10209 if (strncmp (argv[0], "m", 1) == 0)
10210 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10211
10212 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010213}
10214
Michael Lambert95cbbd22010-07-23 14:43:04 -040010215DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10216 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10217#ifdef HAVE_IPV6
10218 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10219#else
10220 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10221#endif
10222 SHOW_STR
10223 BGP_STR
10224 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010225 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010226 "Address family\n"
10227#ifdef HAVE_IPV6
10228 "Address family\n"
10229#endif
10230 "Address family modifier\n"
10231 "Address family modifier\n"
10232 "Detailed information on TCP and BGP neighbor connections\n"
10233 "Neighbor to display information about\n"
10234 "Neighbor to display information about\n"
10235 "Display the advertised routes to neighbor\n"
10236 "Display the received routes from neighbor\n")
10237{
10238 int afi;
10239 int safi;
10240 int in;
10241 struct peer *peer;
10242
10243#ifdef HAVE_IPV6
10244 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10245#else
10246 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10247#endif
10248
10249 if (! peer)
10250 return CMD_WARNING;
10251
10252#ifdef HAVE_IPV6
10253 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10254 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10255 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10256#else
10257 afi = AFI_IP;
10258 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10259 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10260#endif
10261
10262 return peer_adj_routes (vty, peer, afi, safi, in);
10263}
10264
paul718e3742002-12-13 20:15:29 +000010265DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10266 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10267 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10268 SHOW_STR
10269 IP_STR
10270 BGP_STR
10271 "Detailed information on TCP and BGP neighbor connections\n"
10272 "Neighbor to display information about\n"
10273 "Neighbor to display information about\n"
10274 "Display information received from a BGP neighbor\n"
10275 "Display the prefixlist filter\n")
10276{
10277 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010278 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010279 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010280 int count, ret;
paul718e3742002-12-13 20:15:29 +000010281
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010282 ret = str2sockunion (argv[0], &su);
10283 if (ret < 0)
10284 {
10285 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10286 return CMD_WARNING;
10287 }
paul718e3742002-12-13 20:15:29 +000010288
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010289 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010290 if (! peer)
10291 return CMD_WARNING;
10292
10293 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10294 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10295 if (count)
10296 {
10297 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10298 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10299 }
10300
10301 return CMD_SUCCESS;
10302}
10303
10304DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10305 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10306 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10307 SHOW_STR
10308 IP_STR
10309 BGP_STR
10310 "Address family\n"
10311 "Address Family modifier\n"
10312 "Address Family modifier\n"
10313 "Detailed information on TCP and BGP neighbor connections\n"
10314 "Neighbor to display information about\n"
10315 "Neighbor to display information about\n"
10316 "Display information received from a BGP neighbor\n"
10317 "Display the prefixlist filter\n")
10318{
10319 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010320 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010321 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010322 int count, ret;
paul718e3742002-12-13 20:15:29 +000010323
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010324 ret = str2sockunion (argv[1], &su);
10325 if (ret < 0)
10326 {
10327 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10328 return CMD_WARNING;
10329 }
paul718e3742002-12-13 20:15:29 +000010330
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010331 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010332 if (! peer)
10333 return CMD_WARNING;
10334
10335 if (strncmp (argv[0], "m", 1) == 0)
10336 {
10337 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10338 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10339 if (count)
10340 {
10341 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10342 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10343 }
10344 }
10345 else
10346 {
10347 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10348 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10349 if (count)
10350 {
10351 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10352 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10353 }
10354 }
10355
10356 return CMD_SUCCESS;
10357}
10358
10359
10360#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010361ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010362 show_bgp_neighbor_received_routes_cmd,
10363 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10364 SHOW_STR
10365 BGP_STR
10366 "Detailed information on TCP and BGP neighbor connections\n"
10367 "Neighbor to display information about\n"
10368 "Neighbor to display information about\n"
10369 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010370
paulbb46e942003-10-24 19:02:03 +000010371ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010372 show_bgp_ipv6_neighbor_received_routes_cmd,
10373 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10374 SHOW_STR
10375 BGP_STR
10376 "Address family\n"
10377 "Detailed information on TCP and BGP neighbor connections\n"
10378 "Neighbor to display information about\n"
10379 "Neighbor to display information about\n"
10380 "Display the received routes from neighbor\n")
10381
10382DEFUN (show_bgp_neighbor_received_prefix_filter,
10383 show_bgp_neighbor_received_prefix_filter_cmd,
10384 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10385 SHOW_STR
10386 BGP_STR
10387 "Detailed information on TCP and BGP neighbor connections\n"
10388 "Neighbor to display information about\n"
10389 "Neighbor to display information about\n"
10390 "Display information received from a BGP neighbor\n"
10391 "Display the prefixlist filter\n")
10392{
10393 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010394 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010395 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010396 int count, ret;
paul718e3742002-12-13 20:15:29 +000010397
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010398 ret = str2sockunion (argv[0], &su);
10399 if (ret < 0)
10400 {
10401 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10402 return CMD_WARNING;
10403 }
paul718e3742002-12-13 20:15:29 +000010404
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010405 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010406 if (! peer)
10407 return CMD_WARNING;
10408
10409 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10410 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10411 if (count)
10412 {
10413 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10414 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10415 }
10416
10417 return CMD_SUCCESS;
10418}
10419
10420ALIAS (show_bgp_neighbor_received_prefix_filter,
10421 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10422 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10423 SHOW_STR
10424 BGP_STR
10425 "Address family\n"
10426 "Detailed information on TCP and BGP neighbor connections\n"
10427 "Neighbor to display information about\n"
10428 "Neighbor to display information about\n"
10429 "Display information received from a BGP neighbor\n"
10430 "Display the prefixlist filter\n")
10431
10432/* old command */
paulbb46e942003-10-24 19:02:03 +000010433ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010434 ipv6_bgp_neighbor_received_routes_cmd,
10435 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10436 SHOW_STR
10437 IPV6_STR
10438 BGP_STR
10439 "Detailed information on TCP and BGP neighbor connections\n"
10440 "Neighbor to display information about\n"
10441 "Neighbor to display information about\n"
10442 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010443
10444/* old command */
10445DEFUN (ipv6_mbgp_neighbor_received_routes,
10446 ipv6_mbgp_neighbor_received_routes_cmd,
10447 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10448 SHOW_STR
10449 IPV6_STR
10450 MBGP_STR
10451 "Detailed information on TCP and BGP neighbor connections\n"
10452 "Neighbor to display information about\n"
10453 "Neighbor to display information about\n"
10454 "Display the received routes from neighbor\n")
10455{
paulbb46e942003-10-24 19:02:03 +000010456 struct peer *peer;
10457
10458 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10459 if (! peer)
10460 return CMD_WARNING;
10461
10462 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010463}
paulbb46e942003-10-24 19:02:03 +000010464
10465DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10466 show_bgp_view_neighbor_received_prefix_filter_cmd,
10467 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10468 SHOW_STR
10469 BGP_STR
10470 "BGP view\n"
10471 "View name\n"
10472 "Detailed information on TCP and BGP neighbor connections\n"
10473 "Neighbor to display information about\n"
10474 "Neighbor to display information about\n"
10475 "Display information received from a BGP neighbor\n"
10476 "Display the prefixlist filter\n")
10477{
10478 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010479 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010480 struct peer *peer;
10481 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010482 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010483
10484 /* BGP structure lookup. */
10485 bgp = bgp_lookup_by_name (argv[0]);
10486 if (bgp == NULL)
10487 {
10488 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10489 return CMD_WARNING;
10490 }
10491
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010492 ret = str2sockunion (argv[1], &su);
10493 if (ret < 0)
10494 {
10495 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10496 return CMD_WARNING;
10497 }
paulbb46e942003-10-24 19:02:03 +000010498
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010499 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010500 if (! peer)
10501 return CMD_WARNING;
10502
10503 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10504 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10505 if (count)
10506 {
10507 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10508 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10509 }
10510
10511 return CMD_SUCCESS;
10512}
10513
10514ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10515 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10516 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10517 SHOW_STR
10518 BGP_STR
10519 "BGP view\n"
10520 "View name\n"
10521 "Address family\n"
10522 "Detailed information on TCP and BGP neighbor connections\n"
10523 "Neighbor to display information about\n"
10524 "Neighbor to display information about\n"
10525 "Display information received from a BGP neighbor\n"
10526 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010527#endif /* HAVE_IPV6 */
10528
paul94f2b392005-06-28 12:44:16 +000010529static int
paulbb46e942003-10-24 19:02:03 +000010530bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010531 safi_t safi, enum bgp_show_type type)
10532{
paul718e3742002-12-13 20:15:29 +000010533 if (! peer || ! peer->afc[afi][safi])
10534 {
10535 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010536 return CMD_WARNING;
10537 }
10538
ajs5a646652004-11-05 01:25:55 +000010539 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010540}
10541
10542DEFUN (show_ip_bgp_neighbor_routes,
10543 show_ip_bgp_neighbor_routes_cmd,
10544 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10545 SHOW_STR
10546 IP_STR
10547 BGP_STR
10548 "Detailed information on TCP and BGP neighbor connections\n"
10549 "Neighbor to display information about\n"
10550 "Neighbor to display information about\n"
10551 "Display routes learned from neighbor\n")
10552{
paulbb46e942003-10-24 19:02:03 +000010553 struct peer *peer;
10554
10555 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10556 if (! peer)
10557 return CMD_WARNING;
10558
10559 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010560 bgp_show_type_neighbor);
10561}
10562
10563DEFUN (show_ip_bgp_neighbor_flap,
10564 show_ip_bgp_neighbor_flap_cmd,
10565 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10566 SHOW_STR
10567 IP_STR
10568 BGP_STR
10569 "Detailed information on TCP and BGP neighbor connections\n"
10570 "Neighbor to display information about\n"
10571 "Neighbor to display information about\n"
10572 "Display flap statistics of the routes learned from neighbor\n")
10573{
paulbb46e942003-10-24 19:02:03 +000010574 struct peer *peer;
10575
10576 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10577 if (! peer)
10578 return CMD_WARNING;
10579
10580 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010581 bgp_show_type_flap_neighbor);
10582}
10583
10584DEFUN (show_ip_bgp_neighbor_damp,
10585 show_ip_bgp_neighbor_damp_cmd,
10586 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10587 SHOW_STR
10588 IP_STR
10589 BGP_STR
10590 "Detailed information on TCP and BGP neighbor connections\n"
10591 "Neighbor to display information about\n"
10592 "Neighbor to display information about\n"
10593 "Display the dampened routes received from neighbor\n")
10594{
paulbb46e942003-10-24 19:02:03 +000010595 struct peer *peer;
10596
10597 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10598 if (! peer)
10599 return CMD_WARNING;
10600
10601 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010602 bgp_show_type_damp_neighbor);
10603}
10604
10605DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10606 show_ip_bgp_ipv4_neighbor_routes_cmd,
10607 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10608 SHOW_STR
10609 IP_STR
10610 BGP_STR
10611 "Address family\n"
10612 "Address Family modifier\n"
10613 "Address Family modifier\n"
10614 "Detailed information on TCP and BGP neighbor connections\n"
10615 "Neighbor to display information about\n"
10616 "Neighbor to display information about\n"
10617 "Display routes learned from neighbor\n")
10618{
paulbb46e942003-10-24 19:02:03 +000010619 struct peer *peer;
10620
10621 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10622 if (! peer)
10623 return CMD_WARNING;
10624
paul718e3742002-12-13 20:15:29 +000010625 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010626 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010627 bgp_show_type_neighbor);
10628
paulbb46e942003-10-24 19:02:03 +000010629 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010630 bgp_show_type_neighbor);
10631}
paulbb46e942003-10-24 19:02:03 +000010632
paulfee0f4c2004-09-13 05:12:46 +000010633DEFUN (show_ip_bgp_view_rsclient,
10634 show_ip_bgp_view_rsclient_cmd,
10635 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10636 SHOW_STR
10637 IP_STR
10638 BGP_STR
10639 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010640 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010641 "Information about Route Server Client\n"
10642 NEIGHBOR_ADDR_STR)
10643{
10644 struct bgp_table *table;
10645 struct peer *peer;
10646
10647 if (argc == 2)
10648 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10649 else
10650 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10651
10652 if (! peer)
10653 return CMD_WARNING;
10654
10655 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10656 {
10657 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10658 VTY_NEWLINE);
10659 return CMD_WARNING;
10660 }
10661
10662 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10663 PEER_FLAG_RSERVER_CLIENT))
10664 {
10665 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10666 VTY_NEWLINE);
10667 return CMD_WARNING;
10668 }
10669
10670 table = peer->rib[AFI_IP][SAFI_UNICAST];
10671
ajs5a646652004-11-05 01:25:55 +000010672 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010673}
10674
10675ALIAS (show_ip_bgp_view_rsclient,
10676 show_ip_bgp_rsclient_cmd,
10677 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10678 SHOW_STR
10679 IP_STR
10680 BGP_STR
10681 "Information about Route Server Client\n"
10682 NEIGHBOR_ADDR_STR)
10683
Michael Lambert95cbbd22010-07-23 14:43:04 -040010684DEFUN (show_bgp_view_ipv4_safi_rsclient,
10685 show_bgp_view_ipv4_safi_rsclient_cmd,
10686 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10687 SHOW_STR
10688 BGP_STR
10689 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010690 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010691 "Address family\n"
10692 "Address Family modifier\n"
10693 "Address Family modifier\n"
10694 "Information about Route Server Client\n"
10695 NEIGHBOR_ADDR_STR)
10696{
10697 struct bgp_table *table;
10698 struct peer *peer;
10699 safi_t safi;
10700
10701 if (argc == 3) {
10702 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10703 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10704 } else {
10705 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10706 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10707 }
10708
10709 if (! peer)
10710 return CMD_WARNING;
10711
10712 if (! peer->afc[AFI_IP][safi])
10713 {
10714 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10715 VTY_NEWLINE);
10716 return CMD_WARNING;
10717 }
10718
10719 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10720 PEER_FLAG_RSERVER_CLIENT))
10721 {
10722 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10723 VTY_NEWLINE);
10724 return CMD_WARNING;
10725 }
10726
10727 table = peer->rib[AFI_IP][safi];
10728
10729 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10730}
10731
10732ALIAS (show_bgp_view_ipv4_safi_rsclient,
10733 show_bgp_ipv4_safi_rsclient_cmd,
10734 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10735 SHOW_STR
10736 BGP_STR
10737 "Address family\n"
10738 "Address Family modifier\n"
10739 "Address Family modifier\n"
10740 "Information about Route Server Client\n"
10741 NEIGHBOR_ADDR_STR)
10742
paulfee0f4c2004-09-13 05:12:46 +000010743DEFUN (show_ip_bgp_view_rsclient_route,
10744 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010745 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010746 SHOW_STR
10747 IP_STR
10748 BGP_STR
10749 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010750 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010751 "Information about Route Server Client\n"
10752 NEIGHBOR_ADDR_STR
10753 "Network in the BGP routing table to display\n")
10754{
10755 struct bgp *bgp;
10756 struct peer *peer;
10757
10758 /* BGP structure lookup. */
10759 if (argc == 3)
10760 {
10761 bgp = bgp_lookup_by_name (argv[0]);
10762 if (bgp == NULL)
10763 {
10764 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10765 return CMD_WARNING;
10766 }
10767 }
10768 else
10769 {
10770 bgp = bgp_get_default ();
10771 if (bgp == NULL)
10772 {
10773 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10774 return CMD_WARNING;
10775 }
10776 }
10777
10778 if (argc == 3)
10779 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10780 else
10781 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10782
10783 if (! peer)
10784 return CMD_WARNING;
10785
10786 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10787 {
10788 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10789 VTY_NEWLINE);
10790 return CMD_WARNING;
10791}
10792
10793 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10794 PEER_FLAG_RSERVER_CLIENT))
10795 {
10796 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10797 VTY_NEWLINE);
10798 return CMD_WARNING;
10799 }
10800
10801 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10802 (argc == 3) ? argv[2] : argv[1],
10803 AFI_IP, SAFI_UNICAST, NULL, 0);
10804}
10805
10806ALIAS (show_ip_bgp_view_rsclient_route,
10807 show_ip_bgp_rsclient_route_cmd,
10808 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10809 SHOW_STR
10810 IP_STR
10811 BGP_STR
10812 "Information about Route Server Client\n"
10813 NEIGHBOR_ADDR_STR
10814 "Network in the BGP routing table to display\n")
10815
Michael Lambert95cbbd22010-07-23 14:43:04 -040010816DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10817 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10818 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10819 SHOW_STR
10820 BGP_STR
10821 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010822 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010823 "Address family\n"
10824 "Address Family modifier\n"
10825 "Address Family modifier\n"
10826 "Information about Route Server Client\n"
10827 NEIGHBOR_ADDR_STR
10828 "Network in the BGP routing table to display\n")
10829{
10830 struct bgp *bgp;
10831 struct peer *peer;
10832 safi_t safi;
10833
10834 /* BGP structure lookup. */
10835 if (argc == 4)
10836 {
10837 bgp = bgp_lookup_by_name (argv[0]);
10838 if (bgp == NULL)
10839 {
10840 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10841 return CMD_WARNING;
10842 }
10843 }
10844 else
10845 {
10846 bgp = bgp_get_default ();
10847 if (bgp == NULL)
10848 {
10849 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10850 return CMD_WARNING;
10851 }
10852 }
10853
10854 if (argc == 4) {
10855 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10856 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10857 } else {
10858 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10859 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10860 }
10861
10862 if (! peer)
10863 return CMD_WARNING;
10864
10865 if (! peer->afc[AFI_IP][safi])
10866 {
10867 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10868 VTY_NEWLINE);
10869 return CMD_WARNING;
10870}
10871
10872 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10873 PEER_FLAG_RSERVER_CLIENT))
10874 {
10875 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10876 VTY_NEWLINE);
10877 return CMD_WARNING;
10878 }
10879
10880 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10881 (argc == 4) ? argv[3] : argv[2],
10882 AFI_IP, safi, NULL, 0);
10883}
10884
10885ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10886 show_bgp_ipv4_safi_rsclient_route_cmd,
10887 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10888 SHOW_STR
10889 BGP_STR
10890 "Address family\n"
10891 "Address Family modifier\n"
10892 "Address Family modifier\n"
10893 "Information about Route Server Client\n"
10894 NEIGHBOR_ADDR_STR
10895 "Network in the BGP routing table to display\n")
10896
paulfee0f4c2004-09-13 05:12:46 +000010897DEFUN (show_ip_bgp_view_rsclient_prefix,
10898 show_ip_bgp_view_rsclient_prefix_cmd,
10899 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10900 SHOW_STR
10901 IP_STR
10902 BGP_STR
10903 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010904 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010905 "Information about Route Server Client\n"
10906 NEIGHBOR_ADDR_STR
10907 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10908{
10909 struct bgp *bgp;
10910 struct peer *peer;
10911
10912 /* BGP structure lookup. */
10913 if (argc == 3)
10914 {
10915 bgp = bgp_lookup_by_name (argv[0]);
10916 if (bgp == NULL)
10917 {
10918 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10919 return CMD_WARNING;
10920 }
10921 }
10922 else
10923 {
10924 bgp = bgp_get_default ();
10925 if (bgp == NULL)
10926 {
10927 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10928 return CMD_WARNING;
10929 }
10930 }
10931
10932 if (argc == 3)
10933 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10934 else
10935 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10936
10937 if (! peer)
10938 return CMD_WARNING;
10939
10940 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10941 {
10942 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10943 VTY_NEWLINE);
10944 return CMD_WARNING;
10945}
10946
10947 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10948 PEER_FLAG_RSERVER_CLIENT))
10949{
10950 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10951 VTY_NEWLINE);
10952 return CMD_WARNING;
10953 }
10954
10955 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10956 (argc == 3) ? argv[2] : argv[1],
10957 AFI_IP, SAFI_UNICAST, NULL, 1);
10958}
10959
10960ALIAS (show_ip_bgp_view_rsclient_prefix,
10961 show_ip_bgp_rsclient_prefix_cmd,
10962 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10963 SHOW_STR
10964 IP_STR
10965 BGP_STR
10966 "Information about Route Server Client\n"
10967 NEIGHBOR_ADDR_STR
10968 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10969
Michael Lambert95cbbd22010-07-23 14:43:04 -040010970DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10971 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10972 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10973 SHOW_STR
10974 BGP_STR
10975 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010976 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010977 "Address family\n"
10978 "Address Family modifier\n"
10979 "Address Family modifier\n"
10980 "Information about Route Server Client\n"
10981 NEIGHBOR_ADDR_STR
10982 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10983{
10984 struct bgp *bgp;
10985 struct peer *peer;
10986 safi_t safi;
10987
10988 /* BGP structure lookup. */
10989 if (argc == 4)
10990 {
10991 bgp = bgp_lookup_by_name (argv[0]);
10992 if (bgp == NULL)
10993 {
10994 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10995 return CMD_WARNING;
10996 }
10997 }
10998 else
10999 {
11000 bgp = bgp_get_default ();
11001 if (bgp == NULL)
11002 {
11003 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11004 return CMD_WARNING;
11005 }
11006 }
11007
11008 if (argc == 4) {
11009 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11010 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11011 } else {
11012 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11013 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11014 }
11015
11016 if (! peer)
11017 return CMD_WARNING;
11018
11019 if (! peer->afc[AFI_IP][safi])
11020 {
11021 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11022 VTY_NEWLINE);
11023 return CMD_WARNING;
11024}
11025
11026 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11027 PEER_FLAG_RSERVER_CLIENT))
11028{
11029 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11030 VTY_NEWLINE);
11031 return CMD_WARNING;
11032 }
11033
11034 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11035 (argc == 4) ? argv[3] : argv[2],
11036 AFI_IP, safi, NULL, 1);
11037}
11038
11039ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11040 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11041 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11042 SHOW_STR
11043 BGP_STR
11044 "Address family\n"
11045 "Address Family modifier\n"
11046 "Address Family modifier\n"
11047 "Information about Route Server Client\n"
11048 NEIGHBOR_ADDR_STR
11049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011050
paul718e3742002-12-13 20:15:29 +000011051#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011052DEFUN (show_bgp_view_neighbor_routes,
11053 show_bgp_view_neighbor_routes_cmd,
11054 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11055 SHOW_STR
11056 BGP_STR
11057 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011058 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011059 "Detailed information on TCP and BGP neighbor connections\n"
11060 "Neighbor to display information about\n"
11061 "Neighbor to display information about\n"
11062 "Display routes learned from neighbor\n")
11063{
11064 struct peer *peer;
11065
11066 if (argc == 2)
11067 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11068 else
11069 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11070
11071 if (! peer)
11072 return CMD_WARNING;
11073
11074 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11075 bgp_show_type_neighbor);
11076}
11077
11078ALIAS (show_bgp_view_neighbor_routes,
11079 show_bgp_view_ipv6_neighbor_routes_cmd,
11080 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11081 SHOW_STR
11082 BGP_STR
11083 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011084 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011085 "Address family\n"
11086 "Detailed information on TCP and BGP neighbor connections\n"
11087 "Neighbor to display information about\n"
11088 "Neighbor to display information about\n"
11089 "Display routes learned from neighbor\n")
11090
11091DEFUN (show_bgp_view_neighbor_damp,
11092 show_bgp_view_neighbor_damp_cmd,
11093 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11094 SHOW_STR
11095 BGP_STR
11096 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011097 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011098 "Detailed information on TCP and BGP neighbor connections\n"
11099 "Neighbor to display information about\n"
11100 "Neighbor to display information about\n"
11101 "Display the dampened routes received from neighbor\n")
11102{
11103 struct peer *peer;
11104
11105 if (argc == 2)
11106 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11107 else
11108 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11109
11110 if (! peer)
11111 return CMD_WARNING;
11112
11113 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11114 bgp_show_type_damp_neighbor);
11115}
11116
11117ALIAS (show_bgp_view_neighbor_damp,
11118 show_bgp_view_ipv6_neighbor_damp_cmd,
11119 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11120 SHOW_STR
11121 BGP_STR
11122 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011123 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011124 "Address family\n"
11125 "Detailed information on TCP and BGP neighbor connections\n"
11126 "Neighbor to display information about\n"
11127 "Neighbor to display information about\n"
11128 "Display the dampened routes received from neighbor\n")
11129
11130DEFUN (show_bgp_view_neighbor_flap,
11131 show_bgp_view_neighbor_flap_cmd,
11132 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11133 SHOW_STR
11134 BGP_STR
11135 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011136 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011137 "Detailed information on TCP and BGP neighbor connections\n"
11138 "Neighbor to display information about\n"
11139 "Neighbor to display information about\n"
11140 "Display flap statistics of the routes learned from neighbor\n")
11141{
11142 struct peer *peer;
11143
11144 if (argc == 2)
11145 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11146 else
11147 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11148
11149 if (! peer)
11150 return CMD_WARNING;
11151
11152 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11153 bgp_show_type_flap_neighbor);
11154}
11155
11156ALIAS (show_bgp_view_neighbor_flap,
11157 show_bgp_view_ipv6_neighbor_flap_cmd,
11158 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11159 SHOW_STR
11160 BGP_STR
11161 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011162 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011163 "Address family\n"
11164 "Detailed information on TCP and BGP neighbor connections\n"
11165 "Neighbor to display information about\n"
11166 "Neighbor to display information about\n"
11167 "Display flap statistics of the routes learned from neighbor\n")
11168
11169ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011170 show_bgp_neighbor_routes_cmd,
11171 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11172 SHOW_STR
11173 BGP_STR
11174 "Detailed information on TCP and BGP neighbor connections\n"
11175 "Neighbor to display information about\n"
11176 "Neighbor to display information about\n"
11177 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011178
paulbb46e942003-10-24 19:02:03 +000011179
11180ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011181 show_bgp_ipv6_neighbor_routes_cmd,
11182 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11183 SHOW_STR
11184 BGP_STR
11185 "Address family\n"
11186 "Detailed information on TCP and BGP neighbor connections\n"
11187 "Neighbor to display information about\n"
11188 "Neighbor to display information about\n"
11189 "Display routes learned from neighbor\n")
11190
11191/* old command */
paulbb46e942003-10-24 19:02:03 +000011192ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011193 ipv6_bgp_neighbor_routes_cmd,
11194 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11195 SHOW_STR
11196 IPV6_STR
11197 BGP_STR
11198 "Detailed information on TCP and BGP neighbor connections\n"
11199 "Neighbor to display information about\n"
11200 "Neighbor to display information about\n"
11201 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011202
11203/* old command */
11204DEFUN (ipv6_mbgp_neighbor_routes,
11205 ipv6_mbgp_neighbor_routes_cmd,
11206 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11207 SHOW_STR
11208 IPV6_STR
11209 MBGP_STR
11210 "Detailed information on TCP and BGP neighbor connections\n"
11211 "Neighbor to display information about\n"
11212 "Neighbor to display information about\n"
11213 "Display routes learned from neighbor\n")
11214{
paulbb46e942003-10-24 19:02:03 +000011215 struct peer *peer;
11216
11217 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11218 if (! peer)
11219 return CMD_WARNING;
11220
11221 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011222 bgp_show_type_neighbor);
11223}
paulbb46e942003-10-24 19:02:03 +000011224
11225ALIAS (show_bgp_view_neighbor_flap,
11226 show_bgp_neighbor_flap_cmd,
11227 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11228 SHOW_STR
11229 BGP_STR
11230 "Detailed information on TCP and BGP neighbor connections\n"
11231 "Neighbor to display information about\n"
11232 "Neighbor to display information about\n"
11233 "Display flap statistics of the routes learned from neighbor\n")
11234
11235ALIAS (show_bgp_view_neighbor_flap,
11236 show_bgp_ipv6_neighbor_flap_cmd,
11237 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11238 SHOW_STR
11239 BGP_STR
11240 "Address family\n"
11241 "Detailed information on TCP and BGP neighbor connections\n"
11242 "Neighbor to display information about\n"
11243 "Neighbor to display information about\n"
11244 "Display flap statistics of the routes learned from neighbor\n")
11245
11246ALIAS (show_bgp_view_neighbor_damp,
11247 show_bgp_neighbor_damp_cmd,
11248 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11249 SHOW_STR
11250 BGP_STR
11251 "Detailed information on TCP and BGP neighbor connections\n"
11252 "Neighbor to display information about\n"
11253 "Neighbor to display information about\n"
11254 "Display the dampened routes received from neighbor\n")
11255
11256ALIAS (show_bgp_view_neighbor_damp,
11257 show_bgp_ipv6_neighbor_damp_cmd,
11258 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11259 SHOW_STR
11260 BGP_STR
11261 "Address family\n"
11262 "Detailed information on TCP and BGP neighbor connections\n"
11263 "Neighbor to display information about\n"
11264 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011265 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011266
11267DEFUN (show_bgp_view_rsclient,
11268 show_bgp_view_rsclient_cmd,
11269 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11270 SHOW_STR
11271 BGP_STR
11272 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011273 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011274 "Information about Route Server Client\n"
11275 NEIGHBOR_ADDR_STR)
11276{
11277 struct bgp_table *table;
11278 struct peer *peer;
11279
11280 if (argc == 2)
11281 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11282 else
11283 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11284
11285 if (! peer)
11286 return CMD_WARNING;
11287
11288 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11289 {
11290 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11291 VTY_NEWLINE);
11292 return CMD_WARNING;
11293 }
11294
11295 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11296 PEER_FLAG_RSERVER_CLIENT))
11297 {
11298 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11299 VTY_NEWLINE);
11300 return CMD_WARNING;
11301 }
11302
11303 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11304
ajs5a646652004-11-05 01:25:55 +000011305 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011306}
11307
11308ALIAS (show_bgp_view_rsclient,
11309 show_bgp_rsclient_cmd,
11310 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11311 SHOW_STR
11312 BGP_STR
11313 "Information about Route Server Client\n"
11314 NEIGHBOR_ADDR_STR)
11315
Michael Lambert95cbbd22010-07-23 14:43:04 -040011316DEFUN (show_bgp_view_ipv6_safi_rsclient,
11317 show_bgp_view_ipv6_safi_rsclient_cmd,
11318 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11319 SHOW_STR
11320 BGP_STR
11321 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011322 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011323 "Address family\n"
11324 "Address Family modifier\n"
11325 "Address Family modifier\n"
11326 "Information about Route Server Client\n"
11327 NEIGHBOR_ADDR_STR)
11328{
11329 struct bgp_table *table;
11330 struct peer *peer;
11331 safi_t safi;
11332
11333 if (argc == 3) {
11334 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11335 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11336 } else {
11337 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11338 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11339 }
11340
11341 if (! peer)
11342 return CMD_WARNING;
11343
11344 if (! peer->afc[AFI_IP6][safi])
11345 {
11346 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11347 VTY_NEWLINE);
11348 return CMD_WARNING;
11349 }
11350
11351 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11352 PEER_FLAG_RSERVER_CLIENT))
11353 {
11354 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11355 VTY_NEWLINE);
11356 return CMD_WARNING;
11357 }
11358
11359 table = peer->rib[AFI_IP6][safi];
11360
11361 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11362}
11363
11364ALIAS (show_bgp_view_ipv6_safi_rsclient,
11365 show_bgp_ipv6_safi_rsclient_cmd,
11366 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11367 SHOW_STR
11368 BGP_STR
11369 "Address family\n"
11370 "Address Family modifier\n"
11371 "Address Family modifier\n"
11372 "Information about Route Server Client\n"
11373 NEIGHBOR_ADDR_STR)
11374
paulfee0f4c2004-09-13 05:12:46 +000011375DEFUN (show_bgp_view_rsclient_route,
11376 show_bgp_view_rsclient_route_cmd,
11377 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11378 SHOW_STR
11379 BGP_STR
11380 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011381 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011382 "Information about Route Server Client\n"
11383 NEIGHBOR_ADDR_STR
11384 "Network in the BGP routing table to display\n")
11385{
11386 struct bgp *bgp;
11387 struct peer *peer;
11388
11389 /* BGP structure lookup. */
11390 if (argc == 3)
11391 {
11392 bgp = bgp_lookup_by_name (argv[0]);
11393 if (bgp == NULL)
11394 {
11395 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398 }
11399 else
11400 {
11401 bgp = bgp_get_default ();
11402 if (bgp == NULL)
11403 {
11404 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11405 return CMD_WARNING;
11406 }
11407 }
11408
11409 if (argc == 3)
11410 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11411 else
11412 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11413
11414 if (! peer)
11415 return CMD_WARNING;
11416
11417 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11418 {
11419 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11420 VTY_NEWLINE);
11421 return CMD_WARNING;
11422 }
11423
11424 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11425 PEER_FLAG_RSERVER_CLIENT))
11426 {
11427 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11428 VTY_NEWLINE);
11429 return CMD_WARNING;
11430 }
11431
11432 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11433 (argc == 3) ? argv[2] : argv[1],
11434 AFI_IP6, SAFI_UNICAST, NULL, 0);
11435}
11436
11437ALIAS (show_bgp_view_rsclient_route,
11438 show_bgp_rsclient_route_cmd,
11439 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11440 SHOW_STR
11441 BGP_STR
11442 "Information about Route Server Client\n"
11443 NEIGHBOR_ADDR_STR
11444 "Network in the BGP routing table to display\n")
11445
Michael Lambert95cbbd22010-07-23 14:43:04 -040011446DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11447 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11448 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11449 SHOW_STR
11450 BGP_STR
11451 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011452 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011453 "Address family\n"
11454 "Address Family modifier\n"
11455 "Address Family modifier\n"
11456 "Information about Route Server Client\n"
11457 NEIGHBOR_ADDR_STR
11458 "Network in the BGP routing table to display\n")
11459{
11460 struct bgp *bgp;
11461 struct peer *peer;
11462 safi_t safi;
11463
11464 /* BGP structure lookup. */
11465 if (argc == 4)
11466 {
11467 bgp = bgp_lookup_by_name (argv[0]);
11468 if (bgp == NULL)
11469 {
11470 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11471 return CMD_WARNING;
11472 }
11473 }
11474 else
11475 {
11476 bgp = bgp_get_default ();
11477 if (bgp == NULL)
11478 {
11479 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11480 return CMD_WARNING;
11481 }
11482 }
11483
11484 if (argc == 4) {
11485 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11486 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11487 } else {
11488 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11489 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11490 }
11491
11492 if (! peer)
11493 return CMD_WARNING;
11494
11495 if (! peer->afc[AFI_IP6][safi])
11496 {
11497 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11498 VTY_NEWLINE);
11499 return CMD_WARNING;
11500}
11501
11502 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11503 PEER_FLAG_RSERVER_CLIENT))
11504 {
11505 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11506 VTY_NEWLINE);
11507 return CMD_WARNING;
11508 }
11509
11510 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11511 (argc == 4) ? argv[3] : argv[2],
11512 AFI_IP6, safi, NULL, 0);
11513}
11514
11515ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11516 show_bgp_ipv6_safi_rsclient_route_cmd,
11517 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11518 SHOW_STR
11519 BGP_STR
11520 "Address family\n"
11521 "Address Family modifier\n"
11522 "Address Family modifier\n"
11523 "Information about Route Server Client\n"
11524 NEIGHBOR_ADDR_STR
11525 "Network in the BGP routing table to display\n")
11526
paulfee0f4c2004-09-13 05:12:46 +000011527DEFUN (show_bgp_view_rsclient_prefix,
11528 show_bgp_view_rsclient_prefix_cmd,
11529 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11530 SHOW_STR
11531 BGP_STR
11532 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011533 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011534 "Information about Route Server Client\n"
11535 NEIGHBOR_ADDR_STR
11536 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11537{
11538 struct bgp *bgp;
11539 struct peer *peer;
11540
11541 /* BGP structure lookup. */
11542 if (argc == 3)
11543 {
11544 bgp = bgp_lookup_by_name (argv[0]);
11545 if (bgp == NULL)
11546 {
11547 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11548 return CMD_WARNING;
11549 }
11550 }
11551 else
11552 {
11553 bgp = bgp_get_default ();
11554 if (bgp == NULL)
11555 {
11556 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11557 return CMD_WARNING;
11558 }
11559 }
11560
11561 if (argc == 3)
11562 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11563 else
11564 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11565
11566 if (! peer)
11567 return CMD_WARNING;
11568
11569 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11570 {
11571 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11572 VTY_NEWLINE);
11573 return CMD_WARNING;
11574 }
11575
11576 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11577 PEER_FLAG_RSERVER_CLIENT))
11578 {
11579 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11580 VTY_NEWLINE);
11581 return CMD_WARNING;
11582 }
11583
11584 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11585 (argc == 3) ? argv[2] : argv[1],
11586 AFI_IP6, SAFI_UNICAST, NULL, 1);
11587}
11588
11589ALIAS (show_bgp_view_rsclient_prefix,
11590 show_bgp_rsclient_prefix_cmd,
11591 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11592 SHOW_STR
11593 BGP_STR
11594 "Information about Route Server Client\n"
11595 NEIGHBOR_ADDR_STR
11596 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11597
Michael Lambert95cbbd22010-07-23 14:43:04 -040011598DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11599 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11600 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11601 SHOW_STR
11602 BGP_STR
11603 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011604 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011605 "Address family\n"
11606 "Address Family modifier\n"
11607 "Address Family modifier\n"
11608 "Information about Route Server Client\n"
11609 NEIGHBOR_ADDR_STR
11610 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11611{
11612 struct bgp *bgp;
11613 struct peer *peer;
11614 safi_t safi;
11615
11616 /* BGP structure lookup. */
11617 if (argc == 4)
11618 {
11619 bgp = bgp_lookup_by_name (argv[0]);
11620 if (bgp == NULL)
11621 {
11622 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11623 return CMD_WARNING;
11624 }
11625 }
11626 else
11627 {
11628 bgp = bgp_get_default ();
11629 if (bgp == NULL)
11630 {
11631 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11632 return CMD_WARNING;
11633 }
11634 }
11635
11636 if (argc == 4) {
11637 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11638 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11639 } else {
11640 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11641 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11642 }
11643
11644 if (! peer)
11645 return CMD_WARNING;
11646
11647 if (! peer->afc[AFI_IP6][safi])
11648 {
11649 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11650 VTY_NEWLINE);
11651 return CMD_WARNING;
11652}
11653
11654 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11655 PEER_FLAG_RSERVER_CLIENT))
11656{
11657 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11658 VTY_NEWLINE);
11659 return CMD_WARNING;
11660 }
11661
11662 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11663 (argc == 4) ? argv[3] : argv[2],
11664 AFI_IP6, safi, NULL, 1);
11665}
11666
11667ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11668 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11669 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11670 SHOW_STR
11671 BGP_STR
11672 "Address family\n"
11673 "Address Family modifier\n"
11674 "Address Family modifier\n"
11675 "Information about Route Server Client\n"
11676 NEIGHBOR_ADDR_STR
11677 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11678
paul718e3742002-12-13 20:15:29 +000011679#endif /* HAVE_IPV6 */
11680
11681struct bgp_table *bgp_distance_table;
11682
11683struct bgp_distance
11684{
11685 /* Distance value for the IP source prefix. */
11686 u_char distance;
11687
11688 /* Name of the access-list to be matched. */
11689 char *access_list;
11690};
11691
paul94f2b392005-06-28 12:44:16 +000011692static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011693bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011694{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011695 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011696}
11697
paul94f2b392005-06-28 12:44:16 +000011698static void
paul718e3742002-12-13 20:15:29 +000011699bgp_distance_free (struct bgp_distance *bdistance)
11700{
11701 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11702}
11703
paul94f2b392005-06-28 12:44:16 +000011704static int
paulfd79ac92004-10-13 05:06:08 +000011705bgp_distance_set (struct vty *vty, const char *distance_str,
11706 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011707{
11708 int ret;
11709 struct prefix_ipv4 p;
11710 u_char distance;
11711 struct bgp_node *rn;
11712 struct bgp_distance *bdistance;
11713
11714 ret = str2prefix_ipv4 (ip_str, &p);
11715 if (ret == 0)
11716 {
11717 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11718 return CMD_WARNING;
11719 }
11720
11721 distance = atoi (distance_str);
11722
11723 /* Get BGP distance node. */
11724 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11725 if (rn->info)
11726 {
11727 bdistance = rn->info;
11728 bgp_unlock_node (rn);
11729 }
11730 else
11731 {
11732 bdistance = bgp_distance_new ();
11733 rn->info = bdistance;
11734 }
11735
11736 /* Set distance value. */
11737 bdistance->distance = distance;
11738
11739 /* Reset access-list configuration. */
11740 if (bdistance->access_list)
11741 {
11742 free (bdistance->access_list);
11743 bdistance->access_list = NULL;
11744 }
11745 if (access_list_str)
11746 bdistance->access_list = strdup (access_list_str);
11747
11748 return CMD_SUCCESS;
11749}
11750
paul94f2b392005-06-28 12:44:16 +000011751static int
paulfd79ac92004-10-13 05:06:08 +000011752bgp_distance_unset (struct vty *vty, const char *distance_str,
11753 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011754{
11755 int ret;
11756 struct prefix_ipv4 p;
11757 u_char distance;
11758 struct bgp_node *rn;
11759 struct bgp_distance *bdistance;
11760
11761 ret = str2prefix_ipv4 (ip_str, &p);
11762 if (ret == 0)
11763 {
11764 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11765 return CMD_WARNING;
11766 }
11767
11768 distance = atoi (distance_str);
11769
11770 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11771 if (! rn)
11772 {
11773 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11774 return CMD_WARNING;
11775 }
11776
11777 bdistance = rn->info;
11778
11779 if (bdistance->access_list)
11780 free (bdistance->access_list);
11781 bgp_distance_free (bdistance);
11782
11783 rn->info = NULL;
11784 bgp_unlock_node (rn);
11785 bgp_unlock_node (rn);
11786
11787 return CMD_SUCCESS;
11788}
11789
paul718e3742002-12-13 20:15:29 +000011790/* Apply BGP information to distance method. */
11791u_char
11792bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11793{
11794 struct bgp_node *rn;
11795 struct prefix_ipv4 q;
11796 struct peer *peer;
11797 struct bgp_distance *bdistance;
11798 struct access_list *alist;
11799 struct bgp_static *bgp_static;
11800
11801 if (! bgp)
11802 return 0;
11803
11804 if (p->family != AF_INET)
11805 return 0;
11806
11807 peer = rinfo->peer;
11808
11809 if (peer->su.sa.sa_family != AF_INET)
11810 return 0;
11811
11812 memset (&q, 0, sizeof (struct prefix_ipv4));
11813 q.family = AF_INET;
11814 q.prefix = peer->su.sin.sin_addr;
11815 q.prefixlen = IPV4_MAX_BITLEN;
11816
11817 /* Check source address. */
11818 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11819 if (rn)
11820 {
11821 bdistance = rn->info;
11822 bgp_unlock_node (rn);
11823
11824 if (bdistance->access_list)
11825 {
11826 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11827 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11828 return bdistance->distance;
11829 }
11830 else
11831 return bdistance->distance;
11832 }
11833
11834 /* Backdoor check. */
11835 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11836 if (rn)
11837 {
11838 bgp_static = rn->info;
11839 bgp_unlock_node (rn);
11840
11841 if (bgp_static->backdoor)
11842 {
11843 if (bgp->distance_local)
11844 return bgp->distance_local;
11845 else
11846 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11847 }
11848 }
11849
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011850 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011851 {
11852 if (bgp->distance_ebgp)
11853 return bgp->distance_ebgp;
11854 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11855 }
11856 else
11857 {
11858 if (bgp->distance_ibgp)
11859 return bgp->distance_ibgp;
11860 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11861 }
11862}
11863
11864DEFUN (bgp_distance,
11865 bgp_distance_cmd,
11866 "distance bgp <1-255> <1-255> <1-255>",
11867 "Define an administrative distance\n"
11868 "BGP distance\n"
11869 "Distance for routes external to the AS\n"
11870 "Distance for routes internal to the AS\n"
11871 "Distance for local routes\n")
11872{
11873 struct bgp *bgp;
11874
11875 bgp = vty->index;
11876
11877 bgp->distance_ebgp = atoi (argv[0]);
11878 bgp->distance_ibgp = atoi (argv[1]);
11879 bgp->distance_local = atoi (argv[2]);
11880 return CMD_SUCCESS;
11881}
11882
11883DEFUN (no_bgp_distance,
11884 no_bgp_distance_cmd,
11885 "no distance bgp <1-255> <1-255> <1-255>",
11886 NO_STR
11887 "Define an administrative distance\n"
11888 "BGP distance\n"
11889 "Distance for routes external to the AS\n"
11890 "Distance for routes internal to the AS\n"
11891 "Distance for local routes\n")
11892{
11893 struct bgp *bgp;
11894
11895 bgp = vty->index;
11896
11897 bgp->distance_ebgp= 0;
11898 bgp->distance_ibgp = 0;
11899 bgp->distance_local = 0;
11900 return CMD_SUCCESS;
11901}
11902
11903ALIAS (no_bgp_distance,
11904 no_bgp_distance2_cmd,
11905 "no distance bgp",
11906 NO_STR
11907 "Define an administrative distance\n"
11908 "BGP distance\n")
11909
11910DEFUN (bgp_distance_source,
11911 bgp_distance_source_cmd,
11912 "distance <1-255> A.B.C.D/M",
11913 "Define an administrative distance\n"
11914 "Administrative distance\n"
11915 "IP source prefix\n")
11916{
11917 bgp_distance_set (vty, argv[0], argv[1], NULL);
11918 return CMD_SUCCESS;
11919}
11920
11921DEFUN (no_bgp_distance_source,
11922 no_bgp_distance_source_cmd,
11923 "no distance <1-255> A.B.C.D/M",
11924 NO_STR
11925 "Define an administrative distance\n"
11926 "Administrative distance\n"
11927 "IP source prefix\n")
11928{
11929 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11930 return CMD_SUCCESS;
11931}
11932
11933DEFUN (bgp_distance_source_access_list,
11934 bgp_distance_source_access_list_cmd,
11935 "distance <1-255> A.B.C.D/M WORD",
11936 "Define an administrative distance\n"
11937 "Administrative distance\n"
11938 "IP source prefix\n"
11939 "Access list name\n")
11940{
11941 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11942 return CMD_SUCCESS;
11943}
11944
11945DEFUN (no_bgp_distance_source_access_list,
11946 no_bgp_distance_source_access_list_cmd,
11947 "no distance <1-255> A.B.C.D/M WORD",
11948 NO_STR
11949 "Define an administrative distance\n"
11950 "Administrative distance\n"
11951 "IP source prefix\n"
11952 "Access list name\n")
11953{
11954 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11955 return CMD_SUCCESS;
11956}
11957
11958DEFUN (bgp_damp_set,
11959 bgp_damp_set_cmd,
11960 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11961 "BGP Specific commands\n"
11962 "Enable route-flap dampening\n"
11963 "Half-life time for the penalty\n"
11964 "Value to start reusing a route\n"
11965 "Value to start suppressing a route\n"
11966 "Maximum duration to suppress a stable route\n")
11967{
11968 struct bgp *bgp;
11969 int half = DEFAULT_HALF_LIFE * 60;
11970 int reuse = DEFAULT_REUSE;
11971 int suppress = DEFAULT_SUPPRESS;
11972 int max = 4 * half;
11973
11974 if (argc == 4)
11975 {
11976 half = atoi (argv[0]) * 60;
11977 reuse = atoi (argv[1]);
11978 suppress = atoi (argv[2]);
11979 max = atoi (argv[3]) * 60;
11980 }
11981 else if (argc == 1)
11982 {
11983 half = atoi (argv[0]) * 60;
11984 max = 4 * half;
11985 }
11986
11987 bgp = vty->index;
11988 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11989 half, reuse, suppress, max);
11990}
11991
11992ALIAS (bgp_damp_set,
11993 bgp_damp_set2_cmd,
11994 "bgp dampening <1-45>",
11995 "BGP Specific commands\n"
11996 "Enable route-flap dampening\n"
11997 "Half-life time for the penalty\n")
11998
11999ALIAS (bgp_damp_set,
12000 bgp_damp_set3_cmd,
12001 "bgp dampening",
12002 "BGP Specific commands\n"
12003 "Enable route-flap dampening\n")
12004
12005DEFUN (bgp_damp_unset,
12006 bgp_damp_unset_cmd,
12007 "no bgp dampening",
12008 NO_STR
12009 "BGP Specific commands\n"
12010 "Enable route-flap dampening\n")
12011{
12012 struct bgp *bgp;
12013
12014 bgp = vty->index;
12015 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12016}
12017
12018ALIAS (bgp_damp_unset,
12019 bgp_damp_unset2_cmd,
12020 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12021 NO_STR
12022 "BGP Specific commands\n"
12023 "Enable route-flap dampening\n"
12024 "Half-life time for the penalty\n"
12025 "Value to start reusing a route\n"
12026 "Value to start suppressing a route\n"
12027 "Maximum duration to suppress a stable route\n")
12028
12029DEFUN (show_ip_bgp_dampened_paths,
12030 show_ip_bgp_dampened_paths_cmd,
12031 "show ip bgp dampened-paths",
12032 SHOW_STR
12033 IP_STR
12034 BGP_STR
12035 "Display paths suppressed due to dampening\n")
12036{
ajs5a646652004-11-05 01:25:55 +000012037 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12038 NULL);
paul718e3742002-12-13 20:15:29 +000012039}
12040
12041DEFUN (show_ip_bgp_flap_statistics,
12042 show_ip_bgp_flap_statistics_cmd,
12043 "show ip bgp flap-statistics",
12044 SHOW_STR
12045 IP_STR
12046 BGP_STR
12047 "Display flap statistics of routes\n")
12048{
ajs5a646652004-11-05 01:25:55 +000012049 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12050 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012051}
12052
12053/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012054static int
paulfd79ac92004-10-13 05:06:08 +000012055bgp_clear_damp_route (struct vty *vty, const char *view_name,
12056 const char *ip_str, afi_t afi, safi_t safi,
12057 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012058{
12059 int ret;
12060 struct prefix match;
12061 struct bgp_node *rn;
12062 struct bgp_node *rm;
12063 struct bgp_info *ri;
12064 struct bgp_info *ri_temp;
12065 struct bgp *bgp;
12066 struct bgp_table *table;
12067
12068 /* BGP structure lookup. */
12069 if (view_name)
12070 {
12071 bgp = bgp_lookup_by_name (view_name);
12072 if (bgp == NULL)
12073 {
12074 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12075 return CMD_WARNING;
12076 }
12077 }
12078 else
12079 {
12080 bgp = bgp_get_default ();
12081 if (bgp == NULL)
12082 {
12083 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12084 return CMD_WARNING;
12085 }
12086 }
12087
12088 /* Check IP address argument. */
12089 ret = str2prefix (ip_str, &match);
12090 if (! ret)
12091 {
12092 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12093 return CMD_WARNING;
12094 }
12095
12096 match.family = afi2family (afi);
12097
12098 if (safi == SAFI_MPLS_VPN)
12099 {
12100 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12101 {
12102 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12103 continue;
12104
12105 if ((table = rn->info) != NULL)
12106 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012107 {
12108 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12109 {
12110 ri = rm->info;
12111 while (ri)
12112 {
12113 if (ri->extra && ri->extra->damp_info)
12114 {
12115 ri_temp = ri->next;
12116 bgp_damp_info_free (ri->extra->damp_info, 1);
12117 ri = ri_temp;
12118 }
12119 else
12120 ri = ri->next;
12121 }
12122 }
12123
12124 bgp_unlock_node (rm);
12125 }
paul718e3742002-12-13 20:15:29 +000012126 }
12127 }
12128 else
12129 {
12130 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012131 {
12132 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12133 {
12134 ri = rn->info;
12135 while (ri)
12136 {
12137 if (ri->extra && ri->extra->damp_info)
12138 {
12139 ri_temp = ri->next;
12140 bgp_damp_info_free (ri->extra->damp_info, 1);
12141 ri = ri_temp;
12142 }
12143 else
12144 ri = ri->next;
12145 }
12146 }
12147
12148 bgp_unlock_node (rn);
12149 }
paul718e3742002-12-13 20:15:29 +000012150 }
12151
12152 return CMD_SUCCESS;
12153}
12154
12155DEFUN (clear_ip_bgp_dampening,
12156 clear_ip_bgp_dampening_cmd,
12157 "clear ip bgp dampening",
12158 CLEAR_STR
12159 IP_STR
12160 BGP_STR
12161 "Clear route flap dampening information\n")
12162{
12163 bgp_damp_info_clean ();
12164 return CMD_SUCCESS;
12165}
12166
12167DEFUN (clear_ip_bgp_dampening_prefix,
12168 clear_ip_bgp_dampening_prefix_cmd,
12169 "clear ip bgp dampening A.B.C.D/M",
12170 CLEAR_STR
12171 IP_STR
12172 BGP_STR
12173 "Clear route flap dampening information\n"
12174 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12175{
12176 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12177 SAFI_UNICAST, NULL, 1);
12178}
12179
12180DEFUN (clear_ip_bgp_dampening_address,
12181 clear_ip_bgp_dampening_address_cmd,
12182 "clear ip bgp dampening A.B.C.D",
12183 CLEAR_STR
12184 IP_STR
12185 BGP_STR
12186 "Clear route flap dampening information\n"
12187 "Network to clear damping information\n")
12188{
12189 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12190 SAFI_UNICAST, NULL, 0);
12191}
12192
12193DEFUN (clear_ip_bgp_dampening_address_mask,
12194 clear_ip_bgp_dampening_address_mask_cmd,
12195 "clear ip bgp dampening A.B.C.D A.B.C.D",
12196 CLEAR_STR
12197 IP_STR
12198 BGP_STR
12199 "Clear route flap dampening information\n"
12200 "Network to clear damping information\n"
12201 "Network mask\n")
12202{
12203 int ret;
12204 char prefix_str[BUFSIZ];
12205
12206 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12207 if (! ret)
12208 {
12209 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12210 return CMD_WARNING;
12211 }
12212
12213 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12214 SAFI_UNICAST, NULL, 0);
12215}
12216
paul94f2b392005-06-28 12:44:16 +000012217static int
paul718e3742002-12-13 20:15:29 +000012218bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12219 afi_t afi, safi_t safi, int *write)
12220{
12221 struct bgp_node *prn;
12222 struct bgp_node *rn;
12223 struct bgp_table *table;
12224 struct prefix *p;
12225 struct prefix_rd *prd;
12226 struct bgp_static *bgp_static;
12227 u_int32_t label;
12228 char buf[SU_ADDRSTRLEN];
12229 char rdbuf[RD_ADDRSTRLEN];
12230
12231 /* Network configuration. */
12232 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12233 if ((table = prn->info) != NULL)
12234 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12235 if ((bgp_static = rn->info) != NULL)
12236 {
12237 p = &rn->p;
12238 prd = (struct prefix_rd *) &prn->p;
12239
12240 /* "address-family" display. */
12241 bgp_config_write_family_header (vty, afi, safi, write);
12242
12243 /* "network" configuration display. */
12244 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12245 label = decode_label (bgp_static->tag);
12246
12247 vty_out (vty, " network %s/%d rd %s tag %d",
12248 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12249 p->prefixlen,
12250 rdbuf, label);
12251 vty_out (vty, "%s", VTY_NEWLINE);
12252 }
12253 return 0;
12254}
12255
12256/* Configuration of static route announcement and aggregate
12257 information. */
12258int
12259bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12260 afi_t afi, safi_t safi, int *write)
12261{
12262 struct bgp_node *rn;
12263 struct prefix *p;
12264 struct bgp_static *bgp_static;
12265 struct bgp_aggregate *bgp_aggregate;
12266 char buf[SU_ADDRSTRLEN];
12267
12268 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12269 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12270
12271 /* Network configuration. */
12272 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12273 if ((bgp_static = rn->info) != NULL)
12274 {
12275 p = &rn->p;
12276
12277 /* "address-family" display. */
12278 bgp_config_write_family_header (vty, afi, safi, write);
12279
12280 /* "network" configuration display. */
12281 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12282 {
12283 u_int32_t destination;
12284 struct in_addr netmask;
12285
12286 destination = ntohl (p->u.prefix4.s_addr);
12287 masklen2ip (p->prefixlen, &netmask);
12288 vty_out (vty, " network %s",
12289 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12290
12291 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12292 || (IN_CLASSB (destination) && p->prefixlen == 16)
12293 || (IN_CLASSA (destination) && p->prefixlen == 8)
12294 || p->u.prefix4.s_addr == 0)
12295 {
12296 /* Natural mask is not display. */
12297 }
12298 else
12299 vty_out (vty, " mask %s", inet_ntoa (netmask));
12300 }
12301 else
12302 {
12303 vty_out (vty, " network %s/%d",
12304 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12305 p->prefixlen);
12306 }
12307
12308 if (bgp_static->rmap.name)
12309 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012310 else
12311 {
12312 if (bgp_static->backdoor)
12313 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012314 }
paul718e3742002-12-13 20:15:29 +000012315
12316 vty_out (vty, "%s", VTY_NEWLINE);
12317 }
12318
12319 /* Aggregate-address configuration. */
12320 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12321 if ((bgp_aggregate = rn->info) != NULL)
12322 {
12323 p = &rn->p;
12324
12325 /* "address-family" display. */
12326 bgp_config_write_family_header (vty, afi, safi, write);
12327
12328 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12329 {
12330 struct in_addr netmask;
12331
12332 masklen2ip (p->prefixlen, &netmask);
12333 vty_out (vty, " aggregate-address %s %s",
12334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12335 inet_ntoa (netmask));
12336 }
12337 else
12338 {
12339 vty_out (vty, " aggregate-address %s/%d",
12340 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12341 p->prefixlen);
12342 }
12343
12344 if (bgp_aggregate->as_set)
12345 vty_out (vty, " as-set");
12346
12347 if (bgp_aggregate->summary_only)
12348 vty_out (vty, " summary-only");
12349
12350 vty_out (vty, "%s", VTY_NEWLINE);
12351 }
12352
12353 return 0;
12354}
12355
12356int
12357bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12358{
12359 struct bgp_node *rn;
12360 struct bgp_distance *bdistance;
12361
12362 /* Distance configuration. */
12363 if (bgp->distance_ebgp
12364 && bgp->distance_ibgp
12365 && bgp->distance_local
12366 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12367 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12368 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12369 vty_out (vty, " distance bgp %d %d %d%s",
12370 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12371 VTY_NEWLINE);
12372
12373 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12374 if ((bdistance = rn->info) != NULL)
12375 {
12376 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12377 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12378 bdistance->access_list ? bdistance->access_list : "",
12379 VTY_NEWLINE);
12380 }
12381
12382 return 0;
12383}
12384
12385/* Allocate routing table structure and install commands. */
12386void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012387bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012388{
12389 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012390 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012391
12392 /* IPv4 BGP commands. */
12393 install_element (BGP_NODE, &bgp_network_cmd);
12394 install_element (BGP_NODE, &bgp_network_mask_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12396 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12397 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12398 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12399 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12400 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12401 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12405 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12406 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12407 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12408 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12409 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12410 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12411
12412 install_element (BGP_NODE, &aggregate_address_cmd);
12413 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12414 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12415 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12416 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12417 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12418 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12419 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12420 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12421 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12426 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12427 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12428 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12429 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12430 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12431 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12432
12433 /* IPv4 unicast configuration. */
12434 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12435 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12436 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12437 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12438 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12439 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012440 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012441 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12443 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12444 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12445 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012446
paul718e3742002-12-13 20:15:29 +000012447 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12451 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12452 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12453 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12454 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12455 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12456 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12461 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12464 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12465 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12466 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12467
12468 /* IPv4 multicast configuration. */
12469 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12470 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12471 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12472 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12473 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12474 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12476 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12477 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12478 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12479 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12480 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12485 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12486 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12487 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12488 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12489 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12490 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12498 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12499 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12500 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12501
12502 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012504 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012505 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012508 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012512 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012513 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12539 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12540 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12541 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12542 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012543 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12559 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012561 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012562 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12572 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12573 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12574 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12575 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12576 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12577 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012578 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012579 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012580 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012582 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012584 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12585 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012586 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012588 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012589 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012590 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012591 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012592
12593 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012596 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012597 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012601 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12608 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12609 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12610 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12611 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12612 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012613 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12614 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12615 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12616 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12617 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012618 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12621 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12622 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12623 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12624 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12625 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12626 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012628 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012630 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012631 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012632 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012633 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012634
12635 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012637 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012638 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012640 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012641 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012645 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012646 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012671 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12672 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12673 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12674 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12675 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012676 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12692 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012694 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012695 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12705 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12706 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12707 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12708 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12709 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12710 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012711 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012712 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012713 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012715 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012717 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12718 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012719 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012721 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012723 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012724 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012725
12726 /* BGP dampening clear commands */
12727 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12728 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12729 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12730 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12731
Paul Jakmaff7924f2006-09-04 01:10:36 +000012732 /* prefix count */
12733 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12734 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12735 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012736#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012737 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12738
paul718e3742002-12-13 20:15:29 +000012739 /* New config IPv6 BGP commands. */
12740 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12741 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12742 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12743 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12744
12745 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12746 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12747 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12748 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12749
G.Balaji73bfe0b2011-09-23 22:36:20 +053012750 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12751 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12752
paul718e3742002-12-13 20:15:29 +000012753 /* Old config IPv6 BGP commands. */
12754 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12755 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12756
12757 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12758 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12759 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12760 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12761
12762 install_element (VIEW_NODE, &show_bgp_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012764 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012765 install_element (VIEW_NODE, &show_bgp_route_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012767 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012768 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012771 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12772 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12773 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12774 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12775 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12776 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12777 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12778 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12779 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12780 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12781 install_element (VIEW_NODE, &show_bgp_community_cmd);
12782 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12783 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12784 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12785 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12786 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12787 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12788 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12789 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12793 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12795 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12796 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12797 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12798 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12799 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12800 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12801 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12802 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12803 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12804 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12805 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12807 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12808 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12809 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12810 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012811 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12812 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12813 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12814 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012815 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012816 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012817 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012819 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012821 install_element (VIEW_NODE, &show_bgp_view_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12833 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12834 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12835 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12836 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12837 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12838 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012839 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012840 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012841 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012842 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012843 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012845
12846 /* Restricted:
12847 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12848 */
12849 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012852 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012854 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012855 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12869 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12870 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12871 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012872 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012873 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012874 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012875 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12877 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12878 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12879 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12880 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12881 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012882 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012883 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012884 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012885
12886 install_element (ENABLE_NODE, &show_bgp_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012889 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012891 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012892 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012894 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012895 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012935 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012939 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012940 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012941 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012943 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012944 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012945 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12960 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12961 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12962 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012963 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012964 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012965 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012966 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012967 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012968 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012969
12970 /* Statistics */
12971 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12972 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12973 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12974 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12975
paul718e3742002-12-13 20:15:29 +000012976 /* old command */
12977 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13007 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13008 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13009 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13010 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13011 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13012 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013013
paul718e3742002-12-13 20:15:29 +000013014 /* old command */
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13045 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13046 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13047 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13048 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13049 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13050 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13051
13052 /* old command */
13053 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13054 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13055 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13056 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13057
13058 /* old command */
13059 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13060 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13061 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13062 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13063
13064 /* old command */
13065 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13066 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13067 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13068 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13069#endif /* HAVE_IPV6 */
13070
13071 install_element (BGP_NODE, &bgp_distance_cmd);
13072 install_element (BGP_NODE, &no_bgp_distance_cmd);
13073 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13074 install_element (BGP_NODE, &bgp_distance_source_cmd);
13075 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13076 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13077 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13078
13079 install_element (BGP_NODE, &bgp_damp_set_cmd);
13080 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13081 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13082 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13083 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13085 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13086 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13087 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13088 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013089
13090 /* Deprecated AS-Pathlimit commands */
13091 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13092 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13093 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13094 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13095 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13096 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13097
13098 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13099 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13100 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13101 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13102 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13103 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13104
13105 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13106 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13108 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13109 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13111
13112 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13113 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13114 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13115 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13116 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13117 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13118
13119 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13120 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13122 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13123 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13125
13126 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13127 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13128 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13129 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13130 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13131 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013132
13133#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013134 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13135 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013136#endif
paul718e3742002-12-13 20:15:29 +000013137}
Chris Caputo228da422009-07-18 05:44:03 +000013138
13139void
13140bgp_route_finish (void)
13141{
13142 bgp_table_unlock (bgp_distance_table);
13143 bgp_distance_table = NULL;
13144}