blob: 9251d2c22fb85be6c11ac2e7c77e71c8c45b39ed [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000483 if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700484 {
485 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
486 *paths_eq = 1;
487 }
488 else if (new->peer->as == exist->peer->as)
489 *paths_eq = 1;
490 }
491 else
492 {
493 /*
494 * TODO: If unequal cost ibgp multipath is enabled we can
495 * mark the paths as equal here instead of returning
496 */
497 return ret;
498 }
paul718e3742002-12-13 20:15:29 +0000499
500 /* 10. If both paths are external, prefer the path that was received
501 first (the oldest one). This step minimizes route-flap, since a
502 newer path won't displace an older one, even if it was the
503 preferred route based on the additional decision criteria below. */
504 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000505 && new_sort == BGP_PEER_EBGP
506 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000507 {
508 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
509 return 1;
510 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
511 return 0;
512 }
513
514 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000515 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
516 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000517 else
518 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000519 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
520 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000521 else
522 exist_id.s_addr = exist->peer->remote_id.s_addr;
523
524 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
525 return 1;
526 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
527 return 0;
528
529 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000530 new_cluster = exist_cluster = 0;
531
532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
533 new_cluster = newattre->cluster->length;
534 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
535 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000536
537 if (new_cluster < exist_cluster)
538 return 1;
539 if (new_cluster > exist_cluster)
540 return 0;
541
542 /* 13. Neighbor address comparision. */
543 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
544
545 if (ret == 1)
546 return 0;
547 if (ret == -1)
548 return 1;
549
550 return 1;
551}
552
paul94f2b392005-06-28 12:44:16 +0000553static enum filter_type
paul718e3742002-12-13 20:15:29 +0000554bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
555 afi_t afi, safi_t safi)
556{
557 struct bgp_filter *filter;
558
559 filter = &peer->filter[afi][safi];
560
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#define FILTER_EXIST_WARN(F,f,filter) \
562 if (BGP_DEBUG (update, UPDATE_IN) \
563 && !(F ## _IN (filter))) \
564 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
565 peer->host, #f, F ## _IN_NAME(filter));
566
567 if (DISTRIBUTE_IN_NAME (filter)) {
568 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
569
paul718e3742002-12-13 20:15:29 +0000570 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
571 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 }
paul718e3742002-12-13 20:15:29 +0000573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574 if (PREFIX_LIST_IN_NAME (filter)) {
575 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
576
paul718e3742002-12-13 20:15:29 +0000577 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
578 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100579 }
paul718e3742002-12-13 20:15:29 +0000580
Paul Jakma650f76c2009-06-25 18:06:31 +0100581 if (FILTER_LIST_IN_NAME (filter)) {
582 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
583
paul718e3742002-12-13 20:15:29 +0000584 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
585 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100586 }
587
paul718e3742002-12-13 20:15:29 +0000588 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100589#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000590}
591
paul94f2b392005-06-28 12:44:16 +0000592static enum filter_type
paul718e3742002-12-13 20:15:29 +0000593bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
594 afi_t afi, safi_t safi)
595{
596 struct bgp_filter *filter;
597
598 filter = &peer->filter[afi][safi];
599
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#define FILTER_EXIST_WARN(F,f,filter) \
601 if (BGP_DEBUG (update, UPDATE_OUT) \
602 && !(F ## _OUT (filter))) \
603 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
604 peer->host, #f, F ## _OUT_NAME(filter));
605
606 if (DISTRIBUTE_OUT_NAME (filter)) {
607 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
paul718e3742002-12-13 20:15:29 +0000612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613 if (PREFIX_LIST_OUT_NAME (filter)) {
614 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
615
paul718e3742002-12-13 20:15:29 +0000616 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
617 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100618 }
paul718e3742002-12-13 20:15:29 +0000619
Paul Jakma650f76c2009-06-25 18:06:31 +0100620 if (FILTER_LIST_OUT_NAME (filter)) {
621 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
622
paul718e3742002-12-13 20:15:29 +0000623 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
624 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100625 }
paul718e3742002-12-13 20:15:29 +0000626
627 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100628#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000629}
630
631/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000632static int
paul718e3742002-12-13 20:15:29 +0000633bgp_community_filter (struct peer *peer, struct attr *attr)
634{
635 if (attr->community)
636 {
637 /* NO_ADVERTISE check. */
638 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
639 return 1;
640
641 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000642 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000643 community_include (attr->community, COMMUNITY_NO_EXPORT))
644 return 1;
645
646 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000647 if (peer->sort == BGP_PEER_EBGP
648 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000649 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
650 return 1;
651 }
652 return 0;
653}
654
655/* Route reflection loop check. */
656static int
657bgp_cluster_filter (struct peer *peer, struct attr *attr)
658{
659 struct in_addr cluster_id;
660
Paul Jakmafb982c22007-05-04 20:15:47 +0000661 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000662 {
663 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
664 cluster_id = peer->bgp->cluster_id;
665 else
666 cluster_id = peer->bgp->router_id;
667
Paul Jakmafb982c22007-05-04 20:15:47 +0000668 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000669 return 1;
670 }
671 return 0;
672}
673
paul94f2b392005-06-28 12:44:16 +0000674static int
paul718e3742002-12-13 20:15:29 +0000675bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
676 afi_t afi, safi_t safi)
677{
678 struct bgp_filter *filter;
679 struct bgp_info info;
680 route_map_result_t ret;
681
682 filter = &peer->filter[afi][safi];
683
684 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000685 if (peer->weight)
686 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000687
688 /* Route map apply. */
689 if (ROUTE_MAP_IN_NAME (filter))
690 {
691 /* Duplicate current value to new strucutre for modification. */
692 info.peer = peer;
693 info.attr = attr;
694
paulac41b2a2003-08-12 05:32:27 +0000695 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
696
paul718e3742002-12-13 20:15:29 +0000697 /* Apply BGP route map to the attribute. */
698 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000699
700 peer->rmap_type = 0;
701
paul718e3742002-12-13 20:15:29 +0000702 if (ret == RMAP_DENYMATCH)
703 {
704 /* Free newly generated AS path and community by route-map. */
705 bgp_attr_flush (attr);
706 return RMAP_DENY;
707 }
708 }
709 return RMAP_PERMIT;
710}
711
paul94f2b392005-06-28 12:44:16 +0000712static int
paulfee0f4c2004-09-13 05:12:46 +0000713bgp_export_modifier (struct peer *rsclient, struct peer *peer,
714 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
715{
716 struct bgp_filter *filter;
717 struct bgp_info info;
718 route_map_result_t ret;
719
720 filter = &peer->filter[afi][safi];
721
722 /* Route map apply. */
723 if (ROUTE_MAP_EXPORT_NAME (filter))
724 {
725 /* Duplicate current value to new strucutre for modification. */
726 info.peer = rsclient;
727 info.attr = attr;
728
729 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
730
731 /* Apply BGP route map to the attribute. */
732 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
733
734 rsclient->rmap_type = 0;
735
736 if (ret == RMAP_DENYMATCH)
737 {
738 /* Free newly generated AS path and community by route-map. */
739 bgp_attr_flush (attr);
740 return RMAP_DENY;
741 }
742 }
743 return RMAP_PERMIT;
744}
745
paul94f2b392005-06-28 12:44:16 +0000746static int
paulfee0f4c2004-09-13 05:12:46 +0000747bgp_import_modifier (struct peer *rsclient, struct peer *peer,
748 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
749{
750 struct bgp_filter *filter;
751 struct bgp_info info;
752 route_map_result_t ret;
753
754 filter = &rsclient->filter[afi][safi];
755
756 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000757 if (peer->weight)
758 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000759
760 /* Route map apply. */
761 if (ROUTE_MAP_IMPORT_NAME (filter))
762 {
763 /* Duplicate current value to new strucutre for modification. */
764 info.peer = peer;
765 info.attr = attr;
766
767 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
768
769 /* Apply BGP route map to the attribute. */
770 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
771
772 peer->rmap_type = 0;
773
774 if (ret == RMAP_DENYMATCH)
775 {
776 /* Free newly generated AS path and community by route-map. */
777 bgp_attr_flush (attr);
778 return RMAP_DENY;
779 }
780 }
781 return RMAP_PERMIT;
782}
783
paul94f2b392005-06-28 12:44:16 +0000784static int
paul718e3742002-12-13 20:15:29 +0000785bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
786 struct attr *attr, afi_t afi, safi_t safi)
787{
788 int ret;
789 char buf[SU_ADDRSTRLEN];
790 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000791 struct peer *from;
792 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000793 int transparent;
794 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700795 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000796
797 from = ri->peer;
798 filter = &peer->filter[afi][safi];
799 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700800 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000801
Paul Jakma750e8142008-07-22 21:11:48 +0000802 if (DISABLE_BGP_ANNOUNCE)
803 return 0;
paul718e3742002-12-13 20:15:29 +0000804
paulfee0f4c2004-09-13 05:12:46 +0000805 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
806 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
807 return 0;
808
paul718e3742002-12-13 20:15:29 +0000809 /* Do not send back route to sender. */
810 if (from == peer)
811 return 0;
812
paul35be31b2004-05-01 18:17:04 +0000813 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
814 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700815 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000816 return 0;
817#ifdef HAVE_IPV6
818 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700819 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000820 return 0;
821#endif
822
paul718e3742002-12-13 20:15:29 +0000823 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000825 if (! UNSUPPRESS_MAP_NAME (filter))
826 return 0;
827
828 /* Default route check. */
829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
830 {
831 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
832 return 0;
833#ifdef HAVE_IPV6
834 else if (p->family == AF_INET6 && p->prefixlen == 0)
835 return 0;
836#endif /* HAVE_IPV6 */
837 }
838
paul286e1e72003-08-08 00:24:31 +0000839 /* Transparency check. */
840 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
841 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
842 transparent = 1;
843 else
844 transparent = 0;
845
paul718e3742002-12-13 20:15:29 +0000846 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000848 return 0;
849
850 /* If the attribute has originator-id and it is same as remote
851 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700852 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000853 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700854 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000857 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000858 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
859 peer->host,
860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
861 p->prefixlen);
862 return 0;
863 }
864 }
865
866 /* ORF prefix-list filter check */
867 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
868 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
869 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
870 if (peer->orf_plist[afi][safi])
871 {
872 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
873 return 0;
874 }
875
876 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700877 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000878 {
879 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000880 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000881 "%s [Update:SEND] %s/%d is filtered",
882 peer->host,
883 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
884 p->prefixlen);
885 return 0;
886 }
887
888#ifdef BGP_SEND_ASPATH_CHECK
889 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000891 {
892 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000893 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400894 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000895 peer->host, peer->as);
896 return 0;
897 }
898#endif /* BGP_SEND_ASPATH_CHECK */
899
900 /* If we're a CONFED we need to loop check the CONFED ID too */
901 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
902 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000904 {
905 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000906 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400907 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000908 peer->host,
909 bgp->confed_id);
910 return 0;
911 }
912 }
913
914 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000915 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000916 reflect = 1;
917 else
918 reflect = 0;
919
920 /* IBGP reflection check. */
921 if (reflect)
922 {
923 /* A route from a Client peer. */
924 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 {
926 /* Reflect to all the Non-Client peers and also to the
927 Client peers other than the originator. Originator check
928 is already done. So there is noting to do. */
929 /* no bgp client-to-client reflection check. */
930 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
931 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 else
935 {
936 /* A route from a Non-client peer. Reflect to all other
937 clients. */
938 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
939 return 0;
940 }
941 }
Paul Jakma41367172007-08-06 15:24:51 +0000942
paul718e3742002-12-13 20:15:29 +0000943 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700944 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000947 if ((peer->sort == BGP_PEER_IBGP
948 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000949 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
950 {
951 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
952 attr->local_pref = bgp->default_local_pref;
953 }
954
paul718e3742002-12-13 20:15:29 +0000955 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000956 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000957 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
958 {
959 if (ri->peer != bgp->peer_self && ! transparent
960 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
961 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
962 }
963
964 /* next-hop-set */
965 if (transparent || reflect
966 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
967 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000968#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000969 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000970 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000971#endif /* HAVE_IPV6 */
972 )))
paul718e3742002-12-13 20:15:29 +0000973 {
974 /* NEXT-HOP Unchanged. */
975 }
976 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
977 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
978#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000979 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000981#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000982 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000983 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
984 {
985 /* Set IPv4 nexthop. */
986 if (p->family == AF_INET)
987 {
988 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000989 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
990 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000991 else
992 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
993 }
994#ifdef HAVE_IPV6
995 /* Set IPv6 nexthop. */
996 if (p->family == AF_INET6)
997 {
998 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001000 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001002 }
1003#endif /* HAVE_IPV6 */
1004 }
1005
1006#ifdef HAVE_IPV6
1007 if (p->family == AF_INET6)
1008 {
paulfee0f4c2004-09-13 05:12:46 +00001009 /* Left nexthop_local unchanged if so configured. */
1010 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1011 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1012 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1014 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001015 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001017 }
1018
1019 /* Default nexthop_local treatment for non-RS-Clients */
1020 else
1021 {
paul718e3742002-12-13 20:15:29 +00001022 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001024
1025 /* Set link-local address for shared network peer. */
1026 if (peer->shared_network
1027 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1028 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001029 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001030 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001032 }
1033
1034 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1035 address.*/
1036 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001038
1039 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1040 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001041 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001042 }
paulfee0f4c2004-09-13 05:12:46 +00001043
1044 }
paul718e3742002-12-13 20:15:29 +00001045#endif /* HAVE_IPV6 */
1046
1047 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001048 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001049 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1050 && aspath_private_as_check (attr->aspath))
1051 attr->aspath = aspath_empty_get ();
1052
1053 /* Route map & unsuppress-map apply. */
1054 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001056 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001057 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001058 struct attr dummy_attr;
1059 struct attr_extra dummy_extra;
1060
1061 dummy_attr.extra = &dummy_extra;
1062
paul718e3742002-12-13 20:15:29 +00001063 info.peer = peer;
1064 info.attr = attr;
1065
1066 /* The route reflector is not allowed to modify the attributes
1067 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001068 if (from->sort == BGP_PEER_IBGP
1069 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001071 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001072 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001073 }
paulac41b2a2003-08-12 05:32:27 +00001074
1075 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1076
Paul Jakmafb982c22007-05-04 20:15:47 +00001077 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001078 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1079 else
1080 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1081
paulac41b2a2003-08-12 05:32:27 +00001082 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001083
paul718e3742002-12-13 20:15:29 +00001084 if (ret == RMAP_DENYMATCH)
1085 {
1086 bgp_attr_flush (attr);
1087 return 0;
1088 }
1089 }
1090 return 1;
1091}
1092
paul94f2b392005-06-28 12:44:16 +00001093static int
paulfee0f4c2004-09-13 05:12:46 +00001094bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1095 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001096{
paulfee0f4c2004-09-13 05:12:46 +00001097 int ret;
1098 char buf[SU_ADDRSTRLEN];
1099 struct bgp_filter *filter;
1100 struct bgp_info info;
1101 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001102 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001103
1104 from = ri->peer;
1105 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001106 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001107
Paul Jakma750e8142008-07-22 21:11:48 +00001108 if (DISABLE_BGP_ANNOUNCE)
1109 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001110
1111 /* Do not send back route to sender. */
1112 if (from == rsclient)
1113 return 0;
1114
1115 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001116 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001117 if (! UNSUPPRESS_MAP_NAME (filter))
1118 return 0;
1119
1120 /* Default route check. */
1121 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1122 PEER_STATUS_DEFAULT_ORIGINATE))
1123 {
1124 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1125 return 0;
1126#ifdef HAVE_IPV6
1127 else if (p->family == AF_INET6 && p->prefixlen == 0)
1128 return 0;
1129#endif /* HAVE_IPV6 */
1130 }
1131
1132 /* If the attribute has originator-id and it is same as remote
1133 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001134 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001135 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001136 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001138 {
1139 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001140 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001141 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1142 rsclient->host,
1143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1144 p->prefixlen);
1145 return 0;
1146 }
1147 }
1148
1149 /* ORF prefix-list filter check */
1150 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1151 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1152 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1153 if (rsclient->orf_plist[afi][safi])
1154 {
1155 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1156 return 0;
1157 }
1158
1159 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001160 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001161 {
1162 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001163 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001164 "%s [Update:SEND] %s/%d is filtered",
1165 rsclient->host,
1166 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1167 p->prefixlen);
1168 return 0;
1169 }
1170
1171#ifdef BGP_SEND_ASPATH_CHECK
1172 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001173 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001174 {
1175 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001176 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001177 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001178 rsclient->host, rsclient->as);
1179 return 0;
1180 }
1181#endif /* BGP_SEND_ASPATH_CHECK */
1182
1183 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001185
1186 /* next-hop-set */
1187 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1188#ifdef HAVE_IPV6
1189 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001190 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001191#endif /* HAVE_IPV6 */
1192 )
1193 {
1194 /* Set IPv4 nexthop. */
1195 if (p->family == AF_INET)
1196 {
1197 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001198 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001199 IPV4_MAX_BYTELEN);
1200 else
1201 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1202 }
1203#ifdef HAVE_IPV6
1204 /* Set IPv6 nexthop. */
1205 if (p->family == AF_INET6)
1206 {
1207 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001211 }
1212#endif /* HAVE_IPV6 */
1213 }
1214
1215#ifdef HAVE_IPV6
1216 if (p->family == AF_INET6)
1217 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001219
paulfee0f4c2004-09-13 05:12:46 +00001220 /* Left nexthop_local unchanged if so configured. */
1221 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1222 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1223 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1225 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001226 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001228 }
1229
1230 /* Default nexthop_local treatment for RS-Clients */
1231 else
1232 {
1233 /* Announcer and RS-Client are both in the same network */
1234 if (rsclient->shared_network && from->shared_network &&
1235 (rsclient->ifindex == from->ifindex))
1236 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1238 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001239 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001241 }
1242
1243 /* Set link-local address for shared network peer. */
1244 else if (rsclient->shared_network
1245 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001248 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001250 }
1251
1252 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001254 }
1255
1256 }
1257#endif /* HAVE_IPV6 */
1258
1259
1260 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001261 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001262 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1263 && aspath_private_as_check (attr->aspath))
1264 attr->aspath = aspath_empty_get ();
1265
1266 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001268 {
1269 info.peer = rsclient;
1270 info.attr = attr;
1271
1272 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1273
Paul Jakmafb982c22007-05-04 20:15:47 +00001274 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001275 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1276 else
1277 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1278
1279 rsclient->rmap_type = 0;
1280
1281 if (ret == RMAP_DENYMATCH)
1282 {
1283 bgp_attr_flush (attr);
1284 return 0;
1285 }
1286 }
1287
1288 return 1;
1289}
1290
1291struct bgp_info_pair
1292{
1293 struct bgp_info *old;
1294 struct bgp_info *new;
1295};
1296
paul94f2b392005-06-28 12:44:16 +00001297static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001298bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1299 struct bgp_maxpaths_cfg *mpath_cfg,
1300 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001301{
paul718e3742002-12-13 20:15:29 +00001302 struct bgp_info *new_select;
1303 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001304 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001305 struct bgp_info *ri1;
1306 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001307 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001308 int paths_eq, do_mpath;
1309 struct list mp_list;
1310
1311 bgp_mp_list_init (&mp_list);
1312 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1313 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1314
paul718e3742002-12-13 20:15:29 +00001315 /* bgp deterministic-med */
1316 new_select = NULL;
1317 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1318 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1319 {
1320 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1321 continue;
1322 if (BGP_INFO_HOLDDOWN (ri1))
1323 continue;
1324
1325 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001326 if (do_mpath)
1327 bgp_mp_list_add (&mp_list, ri1);
1328 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001329 if (ri1->next)
1330 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1331 {
1332 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1333 continue;
1334 if (BGP_INFO_HOLDDOWN (ri2))
1335 continue;
1336
1337 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1338 || aspath_cmp_left_confed (ri1->attr->aspath,
1339 ri2->attr->aspath))
1340 {
Josh Bailey6918e742011-07-20 20:48:20 -07001341 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1342 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001343 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001344 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001345 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001346 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001347 if (do_mpath && !paths_eq)
1348 {
1349 bgp_mp_list_clear (&mp_list);
1350 bgp_mp_list_add (&mp_list, ri2);
1351 }
paul718e3742002-12-13 20:15:29 +00001352 }
1353
Josh Bailey6918e742011-07-20 20:48:20 -07001354 if (do_mpath && paths_eq)
1355 bgp_mp_list_add (&mp_list, ri2);
1356
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001358 }
1359 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1361 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001362
1363 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1364 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001365 }
1366
1367 /* Check old selected route and new selected route. */
1368 old_select = NULL;
1369 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001370 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001371 {
1372 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1373 old_select = ri;
1374
1375 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001376 {
1377 /* reap REMOVED routes, if needs be
1378 * selected route must stay for a while longer though
1379 */
1380 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1381 && (ri != old_select))
1382 bgp_info_reap (rn, ri);
1383
1384 continue;
1385 }
paul718e3742002-12-13 20:15:29 +00001386
1387 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1388 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1389 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001390 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001391 continue;
1392 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001393 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1394 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001395
Josh Bailey96450fa2011-07-20 20:45:12 -07001396 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1397 {
Josh Bailey6918e742011-07-20 20:48:20 -07001398 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1399 bgp_mp_dmed_deselect (new_select);
1400
Josh Bailey96450fa2011-07-20 20:45:12 -07001401 new_select = ri;
1402
1403 if (do_mpath && !paths_eq)
1404 {
1405 bgp_mp_list_clear (&mp_list);
1406 bgp_mp_list_add (&mp_list, ri);
1407 }
1408 }
Josh Bailey6918e742011-07-20 20:48:20 -07001409 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1410 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001411
1412 if (do_mpath && paths_eq)
1413 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001414 }
paulb40d9392005-08-22 22:34:41 +00001415
paulfee0f4c2004-09-13 05:12:46 +00001416
Josh Bailey6918e742011-07-20 20:48:20 -07001417 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1418 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001419
Josh Bailey0b597ef2011-07-20 20:49:11 -07001420 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001421 bgp_mp_list_clear (&mp_list);
1422
1423 result->old = old_select;
1424 result->new = new_select;
1425
1426 return;
paulfee0f4c2004-09-13 05:12:46 +00001427}
1428
paul94f2b392005-06-28 12:44:16 +00001429static int
paulfee0f4c2004-09-13 05:12:46 +00001430bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001431 struct bgp_node *rn, afi_t afi, safi_t safi)
1432{
paulfee0f4c2004-09-13 05:12:46 +00001433 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001434 struct attr attr;
1435 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001436
1437 p = &rn->p;
1438
Paul Jakma9eda90c2007-08-30 13:36:17 +00001439 /* Announce route to Established peer. */
1440 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001441 return 0;
1442
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 /* Address family configuration check. */
1444 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001445 return 0;
1446
Paul Jakma9eda90c2007-08-30 13:36:17 +00001447 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001448 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1449 PEER_STATUS_ORF_WAIT_REFRESH))
1450 return 0;
1451
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001452 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1453 attr.extra = &extra;
1454
Avneesh Sachdev67174042012-08-17 08:19:49 -07001455 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001456 {
1457 case BGP_TABLE_MAIN:
1458 /* Announcement to peer->conf. If the route is filtered,
1459 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1461 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001462 else
1463 bgp_adj_out_unset (rn, peer, p, afi, safi);
1464 break;
1465 case BGP_TABLE_RSCLIENT:
1466 /* Announcement to peer->conf. If the route is filtered,
1467 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001468 if (selected &&
1469 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1470 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1471 else
1472 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001473 break;
1474 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001475
paulfee0f4c2004-09-13 05:12:46 +00001476 return 0;
paul200df112005-06-01 11:17:05 +00001477}
paulfee0f4c2004-09-13 05:12:46 +00001478
paul200df112005-06-01 11:17:05 +00001479struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001480{
paul200df112005-06-01 11:17:05 +00001481 struct bgp *bgp;
1482 struct bgp_node *rn;
1483 afi_t afi;
1484 safi_t safi;
1485};
1486
1487static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001488bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001489{
paul0fb58d52005-11-14 14:31:49 +00001490 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001491 struct bgp *bgp = pq->bgp;
1492 struct bgp_node *rn = pq->rn;
1493 afi_t afi = pq->afi;
1494 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001495 struct bgp_info *new_select;
1496 struct bgp_info *old_select;
1497 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001498 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001499 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001500
paulfee0f4c2004-09-13 05:12:46 +00001501 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001502 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001503 new_select = old_and_new.new;
1504 old_select = old_and_new.old;
1505
paul200df112005-06-01 11:17:05 +00001506 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1507 {
Chris Caputo228da422009-07-18 05:44:03 +00001508 if (rsclient->group)
1509 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1510 {
1511 /* Nothing to do. */
1512 if (old_select && old_select == new_select)
1513 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1514 continue;
paulfee0f4c2004-09-13 05:12:46 +00001515
Chris Caputo228da422009-07-18 05:44:03 +00001516 if (old_select)
1517 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1518 if (new_select)
1519 {
1520 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1521 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001522 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1523 }
paulfee0f4c2004-09-13 05:12:46 +00001524
Chris Caputo228da422009-07-18 05:44:03 +00001525 bgp_process_announce_selected (rsclient, new_select, rn,
1526 afi, safi);
1527 }
paul200df112005-06-01 11:17:05 +00001528 }
1529 else
1530 {
hassob7395792005-08-26 12:58:38 +00001531 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001532 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001533 if (new_select)
1534 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001535 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1536 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001537 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001538 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001539 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001540 }
paulfee0f4c2004-09-13 05:12:46 +00001541
paulb40d9392005-08-22 22:34:41 +00001542 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1543 bgp_info_reap (rn, old_select);
1544
paul200df112005-06-01 11:17:05 +00001545 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1546 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001547}
1548
paul200df112005-06-01 11:17:05 +00001549static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001550bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001551{
paul0fb58d52005-11-14 14:31:49 +00001552 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001553 struct bgp *bgp = pq->bgp;
1554 struct bgp_node *rn = pq->rn;
1555 afi_t afi = pq->afi;
1556 safi_t safi = pq->safi;
1557 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001558 struct bgp_info *new_select;
1559 struct bgp_info *old_select;
1560 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001561 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001562 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001563
paulfee0f4c2004-09-13 05:12:46 +00001564 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001565 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001566 old_select = old_and_new.old;
1567 new_select = old_and_new.new;
1568
1569 /* Nothing to do. */
1570 if (old_select && old_select == new_select)
1571 {
1572 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001573 {
Josh Bailey8196f132011-07-20 20:47:07 -07001574 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1575 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001576 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001577
Josh Bailey8196f132011-07-20 20:47:07 -07001578 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001579 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1580 return WQ_SUCCESS;
1581 }
paulfee0f4c2004-09-13 05:12:46 +00001582 }
paul718e3742002-12-13 20:15:29 +00001583
hasso338b3422005-02-23 14:27:24 +00001584 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001585 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001586 if (new_select)
1587 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001588 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1589 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001591 }
1592
1593
paul718e3742002-12-13 20:15:29 +00001594 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001595 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001596 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001597 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001598 }
1599
1600 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001601 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1602 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001603 {
1604 if (new_select
1605 && new_select->type == ZEBRA_ROUTE_BGP
1606 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001607 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001608 else
1609 {
1610 /* Withdraw the route from the kernel. */
1611 if (old_select
1612 && old_select->type == ZEBRA_ROUTE_BGP
1613 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001614 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001615 }
1616 }
paulb40d9392005-08-22 22:34:41 +00001617
1618 /* Reap old select bgp_info, it it has been removed */
1619 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1620 bgp_info_reap (rn, old_select);
1621
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001624}
1625
paul200df112005-06-01 11:17:05 +00001626static void
paul0fb58d52005-11-14 14:31:49 +00001627bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001628{
paul0fb58d52005-11-14 14:31:49 +00001629 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001630 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001631
Chris Caputo228da422009-07-18 05:44:03 +00001632 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001633 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001634 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001635 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1636}
1637
1638static void
1639bgp_process_queue_init (void)
1640{
1641 bm->process_main_queue
1642 = work_queue_new (bm->master, "process_main_queue");
1643 bm->process_rsclient_queue
1644 = work_queue_new (bm->master, "process_rsclient_queue");
1645
1646 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1647 {
1648 zlog_err ("%s: Failed to allocate work queue", __func__);
1649 exit (1);
1650 }
1651
1652 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001653 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001654 bm->process_main_queue->spec.max_retries = 0;
1655 bm->process_main_queue->spec.hold = 50;
1656
1657 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1658 sizeof (struct work_queue *));
1659 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001660}
1661
1662void
paulfee0f4c2004-09-13 05:12:46 +00001663bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1664{
paul200df112005-06-01 11:17:05 +00001665 struct bgp_process_queue *pqnode;
1666
1667 /* already scheduled for processing? */
1668 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1669 return;
1670
1671 if ( (bm->process_main_queue == NULL) ||
1672 (bm->process_rsclient_queue == NULL) )
1673 bgp_process_queue_init ();
1674
1675 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1676 sizeof (struct bgp_process_queue));
1677 if (!pqnode)
1678 return;
Chris Caputo228da422009-07-18 05:44:03 +00001679
1680 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001681 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001682 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001683 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001684 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001685 pqnode->afi = afi;
1686 pqnode->safi = safi;
1687
Avneesh Sachdev67174042012-08-17 08:19:49 -07001688 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001689 {
paul200df112005-06-01 11:17:05 +00001690 case BGP_TABLE_MAIN:
1691 work_queue_add (bm->process_main_queue, pqnode);
1692 break;
1693 case BGP_TABLE_RSCLIENT:
1694 work_queue_add (bm->process_rsclient_queue, pqnode);
1695 break;
paulfee0f4c2004-09-13 05:12:46 +00001696 }
paul200df112005-06-01 11:17:05 +00001697
1698 return;
paulfee0f4c2004-09-13 05:12:46 +00001699}
hasso0a486e52005-02-01 20:57:17 +00001700
paul94f2b392005-06-28 12:44:16 +00001701static int
hasso0a486e52005-02-01 20:57:17 +00001702bgp_maximum_prefix_restart_timer (struct thread *thread)
1703{
1704 struct peer *peer;
1705
1706 peer = THREAD_ARG (thread);
1707 peer->t_pmax_restart = NULL;
1708
1709 if (BGP_DEBUG (events, EVENTS))
1710 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1711 peer->host);
1712
1713 peer_clear (peer);
1714
1715 return 0;
1716}
1717
paulfee0f4c2004-09-13 05:12:46 +00001718int
paul5228ad22004-06-04 17:58:18 +00001719bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1720 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001721{
hassoe0701b72004-05-20 09:19:34 +00001722 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1723 return 0;
1724
1725 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001726 {
hassoe0701b72004-05-20 09:19:34 +00001727 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1728 && ! always)
1729 return 0;
paul718e3742002-12-13 20:15:29 +00001730
hassoe0701b72004-05-20 09:19:34 +00001731 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001732 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1733 "limit %ld", afi_safi_print (afi, safi), peer->host,
1734 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001735 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001736
hassoe0701b72004-05-20 09:19:34 +00001737 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1738 return 0;
paul718e3742002-12-13 20:15:29 +00001739
hassoe0701b72004-05-20 09:19:34 +00001740 {
paul5228ad22004-06-04 17:58:18 +00001741 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001742
1743 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001744 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001745
1746 ndata[0] = (afi >> 8);
1747 ndata[1] = afi;
1748 ndata[2] = safi;
1749 ndata[3] = (peer->pmax[afi][safi] >> 24);
1750 ndata[4] = (peer->pmax[afi][safi] >> 16);
1751 ndata[5] = (peer->pmax[afi][safi] >> 8);
1752 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001753
1754 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1755 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1756 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1757 }
hasso0a486e52005-02-01 20:57:17 +00001758
1759 /* restart timer start */
1760 if (peer->pmax_restart[afi][safi])
1761 {
1762 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1763
1764 if (BGP_DEBUG (events, EVENTS))
1765 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1766 peer->host, peer->v_pmax_restart);
1767
1768 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1769 peer->v_pmax_restart);
1770 }
1771
hassoe0701b72004-05-20 09:19:34 +00001772 return 1;
paul718e3742002-12-13 20:15:29 +00001773 }
hassoe0701b72004-05-20 09:19:34 +00001774 else
1775 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1776
1777 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1778 {
1779 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1780 && ! always)
1781 return 0;
1782
1783 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001784 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1785 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1786 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001787 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1788 }
1789 else
1790 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001791 return 0;
1792}
1793
paulb40d9392005-08-22 22:34:41 +00001794/* Unconditionally remove the route from the RIB, without taking
1795 * damping into consideration (eg, because the session went down)
1796 */
paul94f2b392005-06-28 12:44:16 +00001797static void
paul718e3742002-12-13 20:15:29 +00001798bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1799 afi_t afi, safi_t safi)
1800{
paul902212c2006-02-05 17:51:19 +00001801 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1802
1803 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1804 bgp_info_delete (rn, ri); /* keep historical info */
1805
paulb40d9392005-08-22 22:34:41 +00001806 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001807}
1808
paul94f2b392005-06-28 12:44:16 +00001809static void
paul718e3742002-12-13 20:15:29 +00001810bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001811 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001812{
paul718e3742002-12-13 20:15:29 +00001813 int status = BGP_DAMP_NONE;
1814
paulb40d9392005-08-22 22:34:41 +00001815 /* apply dampening, if result is suppressed, we'll be retaining
1816 * the bgp_info in the RIB for historical reference.
1817 */
1818 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001819 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001820 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1821 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001822 {
paul902212c2006-02-05 17:51:19 +00001823 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1824 return;
1825 }
1826
1827 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001828}
1829
paul94f2b392005-06-28 12:44:16 +00001830static void
paulfee0f4c2004-09-13 05:12:46 +00001831bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1832 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1833 int sub_type, struct prefix_rd *prd, u_char *tag)
1834{
1835 struct bgp_node *rn;
1836 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001837 struct attr new_attr;
1838 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001839 struct attr *attr_new;
1840 struct attr *attr_new2;
1841 struct bgp_info *ri;
1842 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001843 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001844 char buf[SU_ADDRSTRLEN];
1845
1846 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1847 if (peer == rsclient)
1848 return;
1849
1850 bgp = peer->bgp;
1851 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1852
1853 /* Check previously received route. */
1854 for (ri = rn->info; ri; ri = ri->next)
1855 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1856 break;
1857
1858 /* AS path loop check. */
1859 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1860 {
1861 reason = "as-path contains our own AS;";
1862 goto filtered;
1863 }
1864
1865 /* Route reflector originator ID check. */
1866 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001867 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001868 {
1869 reason = "originator is us;";
1870 goto filtered;
1871 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001872
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001873 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001874 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001875
1876 /* Apply export policy. */
1877 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1878 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1879 {
1880 reason = "export-policy;";
1881 goto filtered;
1882 }
1883
1884 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001885
paulfee0f4c2004-09-13 05:12:46 +00001886 /* Apply import policy. */
1887 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1888 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001889 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001890
1891 reason = "import-policy;";
1892 goto filtered;
1893 }
1894
1895 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001896 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001897
1898 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001899 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001900 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001901 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001902 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001903 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001904 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001905 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001906
1907 reason = "martian next-hop;";
1908 goto filtered;
1909 }
1910 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001911
paulfee0f4c2004-09-13 05:12:46 +00001912 /* If the update is implicit withdraw. */
1913 if (ri)
1914 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001915 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001916
1917 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001918 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1919 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001920 {
1921
Paul Jakma1a392d42006-09-07 00:24:49 +00001922 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001923
1924 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001925 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001926 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1927 peer->host,
1928 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1929 p->prefixlen, rsclient->host);
1930
Chris Caputo228da422009-07-18 05:44:03 +00001931 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001932 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001933
Chris Caputo228da422009-07-18 05:44:03 +00001934 return;
paulfee0f4c2004-09-13 05:12:46 +00001935 }
1936
Paul Jakma16d2e242007-04-10 19:32:10 +00001937 /* Withdraw/Announce before we fully processed the withdraw */
1938 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1939 bgp_info_restore (rn, ri);
1940
paulfee0f4c2004-09-13 05:12:46 +00001941 /* Received Logging. */
1942 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001943 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001944 peer->host,
1945 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1946 p->prefixlen, rsclient->host);
1947
1948 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001949 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001950
1951 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001952 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001953 ri->attr = attr_new;
1954
1955 /* Update MPLS tag. */
1956 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001957 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001958
Paul Jakma1a392d42006-09-07 00:24:49 +00001959 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001960
1961 /* Process change. */
1962 bgp_process (bgp, rn, afi, safi);
1963 bgp_unlock_node (rn);
1964
1965 return;
1966 }
1967
1968 /* Received Logging. */
1969 if (BGP_DEBUG (update, UPDATE_IN))
1970 {
ajsd2c1f162004-12-08 21:10:20 +00001971 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001972 peer->host,
1973 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1974 p->prefixlen, rsclient->host);
1975 }
1976
1977 /* Make new BGP info. */
1978 new = bgp_info_new ();
1979 new->type = type;
1980 new->sub_type = sub_type;
1981 new->peer = peer;
1982 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001983 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001984
1985 /* Update MPLS tag. */
1986 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001987 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001988
Paul Jakma1a392d42006-09-07 00:24:49 +00001989 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001990
1991 /* Register new BGP information. */
1992 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001993
1994 /* route_node_get lock */
1995 bgp_unlock_node (rn);
1996
paulfee0f4c2004-09-13 05:12:46 +00001997 /* Process change. */
1998 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001999
paulfee0f4c2004-09-13 05:12:46 +00002000 return;
2001
2002 filtered:
2003
2004 /* This BGP update is filtered. Log the reason then update BGP entry. */
2005 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002006 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002007 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2008 peer->host,
2009 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2010 p->prefixlen, rsclient->host, reason);
2011
2012 if (ri)
paulb40d9392005-08-22 22:34:41 +00002013 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002014
2015 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002016
paulfee0f4c2004-09-13 05:12:46 +00002017 return;
2018}
2019
paul94f2b392005-06-28 12:44:16 +00002020static void
paulfee0f4c2004-09-13 05:12:46 +00002021bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2022 struct peer *peer, struct prefix *p, int type, int sub_type,
2023 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002024{
paulfee0f4c2004-09-13 05:12:46 +00002025 struct bgp_node *rn;
2026 struct bgp_info *ri;
2027 char buf[SU_ADDRSTRLEN];
2028
2029 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002030 return;
paulfee0f4c2004-09-13 05:12:46 +00002031
2032 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2033
2034 /* Lookup withdrawn route. */
2035 for (ri = rn->info; ri; ri = ri->next)
2036 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2037 break;
2038
2039 /* Withdraw specified route from routing table. */
2040 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002041 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002042 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002043 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002044 "%s Can't find the route %s/%d", peer->host,
2045 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2046 p->prefixlen);
2047
2048 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002049 bgp_unlock_node (rn);
2050}
paulfee0f4c2004-09-13 05:12:46 +00002051
paul94f2b392005-06-28 12:44:16 +00002052static int
paulfee0f4c2004-09-13 05:12:46 +00002053bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002054 afi_t afi, safi_t safi, int type, int sub_type,
2055 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2056{
2057 int ret;
2058 int aspath_loop_count = 0;
2059 struct bgp_node *rn;
2060 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002061 struct attr new_attr;
2062 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002063 struct attr *attr_new;
2064 struct bgp_info *ri;
2065 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002066 const char *reason;
paul718e3742002-12-13 20:15:29 +00002067 char buf[SU_ADDRSTRLEN];
2068
2069 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002070 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002071
paul718e3742002-12-13 20:15:29 +00002072 /* When peer's soft reconfiguration enabled. Record input packet in
2073 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002074 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2075 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002076 bgp_adj_in_set (rn, peer, attr);
2077
2078 /* Check previously received route. */
2079 for (ri = rn->info; ri; ri = ri->next)
2080 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2081 break;
2082
2083 /* AS path local-as loop check. */
2084 if (peer->change_local_as)
2085 {
2086 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2087 aspath_loop_count = 1;
2088
2089 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2090 {
2091 reason = "as-path contains our own AS;";
2092 goto filtered;
2093 }
2094 }
2095
2096 /* AS path loop check. */
2097 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2098 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2099 && aspath_loop_check(attr->aspath, bgp->confed_id)
2100 > peer->allowas_in[afi][safi]))
2101 {
2102 reason = "as-path contains our own AS;";
2103 goto filtered;
2104 }
2105
2106 /* Route reflector originator ID check. */
2107 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002108 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002109 {
2110 reason = "originator is us;";
2111 goto filtered;
2112 }
2113
2114 /* Route reflector cluster ID check. */
2115 if (bgp_cluster_filter (peer, attr))
2116 {
2117 reason = "reflected from the same cluster;";
2118 goto filtered;
2119 }
2120
2121 /* Apply incoming filter. */
2122 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2123 {
2124 reason = "filter;";
2125 goto filtered;
2126 }
2127
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002128 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002129 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002130
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002131 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002132 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2133 {
2134 reason = "route-map;";
2135 goto filtered;
2136 }
2137
2138 /* IPv4 unicast next hop check. */
2139 if (afi == AFI_IP && safi == SAFI_UNICAST)
2140 {
2141 /* If the peer is EBGP and nexthop is not on connected route,
2142 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002143 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002144 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002145 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002146 {
2147 reason = "non-connected next-hop;";
2148 goto filtered;
2149 }
2150
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002151 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002152 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002153 if (new_attr.nexthop.s_addr == 0
2154 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2155 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002156 {
2157 reason = "martian next-hop;";
2158 goto filtered;
2159 }
2160 }
2161
2162 attr_new = bgp_attr_intern (&new_attr);
2163
2164 /* If the update is implicit withdraw. */
2165 if (ri)
2166 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002167 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002168
2169 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002170 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2171 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002172 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002173 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002174
2175 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002176 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002177 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2178 {
2179 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002180 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002181 peer->host,
2182 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2183 p->prefixlen);
2184
paul902212c2006-02-05 17:51:19 +00002185 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2186 {
2187 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2188 bgp_process (bgp, rn, afi, safi);
2189 }
paul718e3742002-12-13 20:15:29 +00002190 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002191 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002192 {
2193 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002194 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002195 "%s rcvd %s/%d...duplicate ignored",
2196 peer->host,
2197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2198 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002199
2200 /* graceful restart STALE flag unset. */
2201 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2202 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002203 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002204 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002205 }
paul718e3742002-12-13 20:15:29 +00002206 }
2207
2208 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002209 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002210
paul718e3742002-12-13 20:15:29 +00002211 return 0;
2212 }
2213
Paul Jakma16d2e242007-04-10 19:32:10 +00002214 /* Withdraw/Announce before we fully processed the withdraw */
2215 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2216 {
2217 if (BGP_DEBUG (update, UPDATE_IN))
2218 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2219 peer->host,
2220 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2221 p->prefixlen);
2222 bgp_info_restore (rn, ri);
2223 }
2224
paul718e3742002-12-13 20:15:29 +00002225 /* Received Logging. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002227 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002228 peer->host,
2229 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2230 p->prefixlen);
2231
hasso93406d82005-02-02 14:40:33 +00002232 /* graceful restart STALE flag unset. */
2233 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002234 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002235
paul718e3742002-12-13 20:15:29 +00002236 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002237 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002238
2239 /* implicit withdraw, decrement aggregate and pcount here.
2240 * only if update is accepted, they'll increment below.
2241 */
paul902212c2006-02-05 17:51:19 +00002242 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2243
paul718e3742002-12-13 20:15:29 +00002244 /* Update bgp route dampening information. */
2245 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002246 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002247 {
2248 /* This is implicit withdraw so we should update dampening
2249 information. */
2250 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2251 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002252 }
2253
paul718e3742002-12-13 20:15:29 +00002254 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002255 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002256 ri->attr = attr_new;
2257
2258 /* Update MPLS tag. */
2259 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002260 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002261
2262 /* Update bgp route dampening information. */
2263 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002264 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002265 {
2266 /* Now we do normal update dampening. */
2267 ret = bgp_damp_update (ri, rn, afi, safi);
2268 if (ret == BGP_DAMP_SUPPRESSED)
2269 {
2270 bgp_unlock_node (rn);
2271 return 0;
2272 }
2273 }
2274
2275 /* Nexthop reachability check. */
2276 if ((afi == AFI_IP || afi == AFI_IP6)
2277 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002278 && (peer->sort == BGP_PEER_IBGP
2279 || peer->sort == BGP_PEER_CONFED
2280 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002281 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002282 {
2283 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002284 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002285 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002286 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002287 }
2288 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002289 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002290
2291 /* Process change. */
2292 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2293
2294 bgp_process (bgp, rn, afi, safi);
2295 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002296
paul718e3742002-12-13 20:15:29 +00002297 return 0;
2298 }
2299
2300 /* Received Logging. */
2301 if (BGP_DEBUG (update, UPDATE_IN))
2302 {
ajsd2c1f162004-12-08 21:10:20 +00002303 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002304 peer->host,
2305 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2306 p->prefixlen);
2307 }
2308
paul718e3742002-12-13 20:15:29 +00002309 /* Make new BGP info. */
2310 new = bgp_info_new ();
2311 new->type = type;
2312 new->sub_type = sub_type;
2313 new->peer = peer;
2314 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002315 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002316
2317 /* Update MPLS tag. */
2318 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002319 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002320
2321 /* Nexthop reachability check. */
2322 if ((afi == AFI_IP || afi == AFI_IP6)
2323 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002324 && (peer->sort == BGP_PEER_IBGP
2325 || peer->sort == BGP_PEER_CONFED
2326 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002327 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002328 {
2329 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002330 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002331 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333 }
2334 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336
paul902212c2006-02-05 17:51:19 +00002337 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002338 bgp_aggregate_increment (bgp, p, new, afi, safi);
2339
2340 /* Register new BGP information. */
2341 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002342
2343 /* route_node_get lock */
2344 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002345
paul718e3742002-12-13 20:15:29 +00002346 /* If maximum prefix count is configured and current prefix
2347 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002348 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2349 return -1;
paul718e3742002-12-13 20:15:29 +00002350
2351 /* Process change. */
2352 bgp_process (bgp, rn, afi, safi);
2353
2354 return 0;
2355
2356 /* This BGP update is filtered. Log the reason then update BGP
2357 entry. */
2358 filtered:
2359 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002360 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002361 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2362 peer->host,
2363 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2364 p->prefixlen, reason);
2365
2366 if (ri)
paulb40d9392005-08-22 22:34:41 +00002367 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002368
2369 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002370
paul718e3742002-12-13 20:15:29 +00002371 return 0;
2372}
2373
2374int
paulfee0f4c2004-09-13 05:12:46 +00002375bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2376 afi_t afi, safi_t safi, int type, int sub_type,
2377 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2378{
2379 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002380 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002381 struct bgp *bgp;
2382 int ret;
2383
2384 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2385 soft_reconfig);
2386
2387 bgp = peer->bgp;
2388
2389 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002390 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002391 {
2392 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2393 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2394 sub_type, prd, tag);
2395 }
2396
2397 return ret;
2398}
2399
2400int
paul718e3742002-12-13 20:15:29 +00002401bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002402 afi_t afi, safi_t safi, int type, int sub_type,
2403 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002404{
2405 struct bgp *bgp;
2406 char buf[SU_ADDRSTRLEN];
2407 struct bgp_node *rn;
2408 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002409 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002410 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002411
2412 bgp = peer->bgp;
2413
paulfee0f4c2004-09-13 05:12:46 +00002414 /* Process the withdraw 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_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2419 }
2420
paul718e3742002-12-13 20:15:29 +00002421 /* Logging. */
2422 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002423 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002424 peer->host,
2425 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2426 p->prefixlen);
2427
2428 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002429 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002430
2431 /* If peer is soft reconfiguration enabled. Record input packet for
2432 further calculation. */
2433 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2434 && peer != bgp->peer_self)
2435 bgp_adj_in_unset (rn, peer);
2436
2437 /* Lookup withdrawn route. */
2438 for (ri = rn->info; ri; ri = ri->next)
2439 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2440 break;
2441
2442 /* Withdraw specified route from routing table. */
2443 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002444 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002445 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002446 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002447 "%s Can't find the route %s/%d", peer->host,
2448 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2449 p->prefixlen);
2450
2451 /* Unlock bgp_node_get() lock. */
2452 bgp_unlock_node (rn);
2453
2454 return 0;
2455}
2456
2457void
2458bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2459{
2460 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002461 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002462 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002463 struct prefix p;
2464 struct bgp_info binfo;
2465 struct peer *from;
2466 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002467
Paul Jakmab2497022007-06-14 11:17:58 +00002468 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 return;
2470
paul718e3742002-12-13 20:15:29 +00002471 bgp = peer->bgp;
2472 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002473
paul718e3742002-12-13 20:15:29 +00002474 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2475 aspath = attr.aspath;
2476 attr.local_pref = bgp->default_local_pref;
2477 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2478
2479 if (afi == AFI_IP)
2480 str2prefix ("0.0.0.0/0", &p);
2481#ifdef HAVE_IPV6
2482 else if (afi == AFI_IP6)
2483 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002484 struct attr_extra *ae = attr.extra;
2485
paul718e3742002-12-13 20:15:29 +00002486 str2prefix ("::/0", &p);
2487
2488 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002489 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002490 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002491 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002492
2493 /* If the peer is on shared nextwork and we have link-local
2494 nexthop set it. */
2495 if (peer->shared_network
2496 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2497 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002498 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002499 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002500 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002501 }
2502 }
2503#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002504
2505 if (peer->default_rmap[afi][safi].name)
2506 {
2507 binfo.peer = bgp->peer_self;
2508 binfo.attr = &attr;
2509
paulfee0f4c2004-09-13 05:12:46 +00002510 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2511
paul718e3742002-12-13 20:15:29 +00002512 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2513 RMAP_BGP, &binfo);
2514
paulfee0f4c2004-09-13 05:12:46 +00002515 bgp->peer_self->rmap_type = 0;
2516
paul718e3742002-12-13 20:15:29 +00002517 if (ret == RMAP_DENYMATCH)
2518 {
2519 bgp_attr_flush (&attr);
2520 withdraw = 1;
2521 }
2522 }
2523
2524 if (withdraw)
2525 {
2526 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2527 bgp_default_withdraw_send (peer, afi, safi);
2528 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2529 }
2530 else
2531 {
2532 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2533 bgp_default_update_send (peer, &attr, afi, safi, from);
2534 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002535
2536 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002537 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002538}
2539
2540static void
2541bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002542 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002543{
2544 struct bgp_node *rn;
2545 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002546 struct attr attr;
2547 struct attr_extra extra;
2548
paul718e3742002-12-13 20:15:29 +00002549 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002550 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002551
2552 if (safi != SAFI_MPLS_VPN
2553 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2554 bgp_default_originate (peer, afi, safi, 0);
2555
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002556 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2557 attr.extra = &extra;
2558
paul718e3742002-12-13 20:15:29 +00002559 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2560 for (ri = rn->info; ri; ri = ri->next)
2561 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2562 {
paulfee0f4c2004-09-13 05:12:46 +00002563 if ( (rsclient) ?
2564 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2565 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002566 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2567 else
2568 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2569 }
2570}
2571
2572void
2573bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2574{
2575 struct bgp_node *rn;
2576 struct bgp_table *table;
2577
2578 if (peer->status != Established)
2579 return;
2580
2581 if (! peer->afc_nego[afi][safi])
2582 return;
2583
2584 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2585 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2586 return;
2587
2588 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002589 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002590 else
2591 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2592 rn = bgp_route_next(rn))
2593 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002594 bgp_announce_table (peer, afi, safi, table, 0);
2595
2596 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2597 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002598}
2599
2600void
2601bgp_announce_route_all (struct peer *peer)
2602{
2603 afi_t afi;
2604 safi_t safi;
2605
2606 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2607 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2608 bgp_announce_route (peer, afi, safi);
2609}
2610
2611static void
paulfee0f4c2004-09-13 05:12:46 +00002612bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002613 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002614{
2615 struct bgp_node *rn;
2616 struct bgp_adj_in *ain;
2617
2618 if (! table)
2619 table = rsclient->bgp->rib[afi][safi];
2620
2621 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2622 for (ain = rn->adj_in; ain; ain = ain->next)
2623 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002624 struct bgp_info *ri = rn->info;
2625
paulfee0f4c2004-09-13 05:12:46 +00002626 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002627 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2628 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002629 }
2630}
2631
2632void
2633bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2634{
2635 struct bgp_table *table;
2636 struct bgp_node *rn;
2637
2638 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002639 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002640
2641 else
2642 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2643 rn = bgp_route_next (rn))
2644 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002645 {
2646 struct prefix_rd prd;
2647 prd.family = AF_UNSPEC;
2648 prd.prefixlen = 64;
2649 memcpy(&prd.val, rn->p.u.val, 8);
2650
2651 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2652 }
paulfee0f4c2004-09-13 05:12:46 +00002653}
2654
2655static void
paul718e3742002-12-13 20:15:29 +00002656bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002657 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002658{
2659 int ret;
2660 struct bgp_node *rn;
2661 struct bgp_adj_in *ain;
2662
2663 if (! table)
2664 table = peer->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 {
2669 if (ain->peer == peer)
2670 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002671 struct bgp_info *ri = rn->info;
2672
paul718e3742002-12-13 20:15:29 +00002673 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2674 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002675 prd, (bgp_info_extra_get (ri))->tag, 1);
2676
paul718e3742002-12-13 20:15:29 +00002677 if (ret < 0)
2678 {
2679 bgp_unlock_node (rn);
2680 return;
2681 }
2682 continue;
2683 }
2684 }
2685}
2686
2687void
2688bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2689{
2690 struct bgp_node *rn;
2691 struct bgp_table *table;
2692
2693 if (peer->status != Established)
2694 return;
2695
2696 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002697 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002698 else
2699 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2700 rn = bgp_route_next (rn))
2701 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002702 {
2703 struct prefix_rd prd;
2704 prd.family = AF_UNSPEC;
2705 prd.prefixlen = 64;
2706 memcpy(&prd.val, rn->p.u.val, 8);
2707
2708 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2709 }
paul718e3742002-12-13 20:15:29 +00002710}
2711
Chris Caputo228da422009-07-18 05:44:03 +00002712
2713struct bgp_clear_node_queue
2714{
2715 struct bgp_node *rn;
2716 enum bgp_clear_route_type purpose;
2717};
2718
paul200df112005-06-01 11:17:05 +00002719static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002720bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002721{
Chris Caputo228da422009-07-18 05:44:03 +00002722 struct bgp_clear_node_queue *cnq = data;
2723 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002724 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002725 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002726 afi_t afi = bgp_node_table (rn)->afi;
2727 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002728
Paul Jakma64e580a2006-02-21 01:09:01 +00002729 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002730
Paul Jakma64e580a2006-02-21 01:09:01 +00002731 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002732 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002733 {
2734 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002735 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2736 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002737 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002738 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2739 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002740 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002741 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002742 break;
2743 }
paul200df112005-06-01 11:17:05 +00002744 return WQ_SUCCESS;
2745}
2746
2747static void
paul0fb58d52005-11-14 14:31:49 +00002748bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002749{
Chris Caputo228da422009-07-18 05:44:03 +00002750 struct bgp_clear_node_queue *cnq = data;
2751 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002752 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002753
2754 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002755 bgp_table_unlock (table);
2756 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002757}
2758
2759static void
paul94f2b392005-06-28 12:44:16 +00002760bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002761{
Paul Jakma64e580a2006-02-21 01:09:01 +00002762 struct peer *peer = wq->spec.data;
2763
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002764 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002765 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002766
2767 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002768}
2769
2770static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002771bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002772{
Paul Jakmaa2943652009-07-21 14:02:04 +01002773 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002774
Paul Jakmaa2943652009-07-21 14:02:04 +01002775 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002776#undef CLEAR_QUEUE_NAME_LEN
2777
2778 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002779 {
2780 zlog_err ("%s: Failed to allocate work queue", __func__);
2781 exit (1);
2782 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002783 peer->clear_node_queue->spec.hold = 10;
2784 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2785 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2786 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2787 peer->clear_node_queue->spec.max_retries = 0;
2788
2789 /* we only 'lock' this peer reference when the queue is actually active */
2790 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002791}
2792
paul718e3742002-12-13 20:15:29 +00002793static void
2794bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002795 struct bgp_table *table, struct peer *rsclient,
2796 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002797{
2798 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002799
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002800
paul718e3742002-12-13 20:15:29 +00002801 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002802 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002803
hasso6cf159b2005-03-21 10:28:14 +00002804 /* If still no table => afi/safi isn't configured at all or smth. */
2805 if (! table)
2806 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002807
2808 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2809 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002810 struct bgp_info *ri;
2811 struct bgp_adj_in *ain;
2812 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002813
2814 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2815 * queued for every clearing peer, regardless of whether it is
2816 * relevant to the peer at hand.
2817 *
2818 * Overview: There are 3 different indices which need to be
2819 * scrubbed, potentially, when a peer is removed:
2820 *
2821 * 1 peer's routes visible via the RIB (ie accepted routes)
2822 * 2 peer's routes visible by the (optional) peer's adj-in index
2823 * 3 other routes visible by the peer's adj-out index
2824 *
2825 * 3 there is no hurry in scrubbing, once the struct peer is
2826 * removed from bgp->peer, we could just GC such deleted peer's
2827 * adj-outs at our leisure.
2828 *
2829 * 1 and 2 must be 'scrubbed' in some way, at least made
2830 * invisible via RIB index before peer session is allowed to be
2831 * brought back up. So one needs to know when such a 'search' is
2832 * complete.
2833 *
2834 * Ideally:
2835 *
2836 * - there'd be a single global queue or a single RIB walker
2837 * - rather than tracking which route_nodes still need to be
2838 * examined on a peer basis, we'd track which peers still
2839 * aren't cleared
2840 *
2841 * Given that our per-peer prefix-counts now should be reliable,
2842 * this may actually be achievable. It doesn't seem to be a huge
2843 * problem at this time,
2844 */
2845 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002846 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002847 {
Chris Caputo228da422009-07-18 05:44:03 +00002848 struct bgp_clear_node_queue *cnq;
2849
2850 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002851 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002852 bgp_lock_node (rn);
2853 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2854 sizeof (struct bgp_clear_node_queue));
2855 cnq->rn = rn;
2856 cnq->purpose = purpose;
2857 work_queue_add (peer->clear_node_queue, cnq);
2858 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002859 }
2860
2861 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002862 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002863 {
2864 bgp_adj_in_remove (rn, ain);
2865 bgp_unlock_node (rn);
2866 break;
2867 }
2868 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002869 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002870 {
2871 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2872 bgp_unlock_node (rn);
2873 break;
2874 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002875 }
2876 return;
2877}
2878
2879void
Chris Caputo228da422009-07-18 05:44:03 +00002880bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2881 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002882{
2883 struct bgp_node *rn;
2884 struct bgp_table *table;
2885 struct peer *rsclient;
2886 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002887
Paul Jakma64e580a2006-02-21 01:09:01 +00002888 if (peer->clear_node_queue == NULL)
2889 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002890
Paul Jakmaca058a32006-09-14 02:58:49 +00002891 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2892 * Idle until it receives a Clearing_Completed event. This protects
2893 * against peers which flap faster than we can we clear, which could
2894 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002895 *
2896 * a) race with routes from the new session being installed before
2897 * clear_route_node visits the node (to delete the route of that
2898 * peer)
2899 * b) resource exhaustion, clear_route_node likely leads to an entry
2900 * on the process_main queue. Fast-flapping could cause that queue
2901 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002902 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002903 if (!peer->clear_node_queue->thread)
2904 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002905
Chris Caputo228da422009-07-18 05:44:03 +00002906 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002907 {
Chris Caputo228da422009-07-18 05:44:03 +00002908 case BGP_CLEAR_ROUTE_NORMAL:
2909 if (safi != SAFI_MPLS_VPN)
2910 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2911 else
2912 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2913 rn = bgp_route_next (rn))
2914 if ((table = rn->info) != NULL)
2915 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2916
2917 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2918 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2919 PEER_FLAG_RSERVER_CLIENT))
2920 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2921 break;
2922
2923 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2924 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2925 break;
2926
2927 default:
2928 assert (0);
2929 break;
paulfee0f4c2004-09-13 05:12:46 +00002930 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002931
Paul Jakmaca058a32006-09-14 02:58:49 +00002932 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002933 * completion function won't be run by workqueue code - call it here.
2934 * XXX: Actually, this assumption doesn't hold, see
2935 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002936 *
2937 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002938 * really needed if peer state is Established - peers in
2939 * pre-Established states shouldn't have any route-update state
2940 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002941 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002942 * We still can get here in pre-Established though, through
2943 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2944 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002945 *
2946 * At some future point, this check could be move to the top of the
2947 * function, and do a quick early-return when state is
2948 * pre-Established, avoiding above list and table scans. Once we're
2949 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002950 */
2951 if (!peer->clear_node_queue->thread)
2952 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002953}
2954
2955void
2956bgp_clear_route_all (struct peer *peer)
2957{
2958 afi_t afi;
2959 safi_t safi;
2960
2961 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2962 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002963 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002964}
2965
2966void
2967bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2968{
2969 struct bgp_table *table;
2970 struct bgp_node *rn;
2971 struct bgp_adj_in *ain;
2972
2973 table = peer->bgp->rib[afi][safi];
2974
2975 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2976 for (ain = rn->adj_in; ain ; ain = ain->next)
2977 if (ain->peer == peer)
2978 {
2979 bgp_adj_in_remove (rn, ain);
2980 bgp_unlock_node (rn);
2981 break;
2982 }
2983}
hasso93406d82005-02-02 14:40:33 +00002984
2985void
2986bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2987{
2988 struct bgp_node *rn;
2989 struct bgp_info *ri;
2990 struct bgp_table *table;
2991
2992 table = peer->bgp->rib[afi][safi];
2993
2994 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2995 {
2996 for (ri = rn->info; ri; ri = ri->next)
2997 if (ri->peer == peer)
2998 {
2999 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3000 bgp_rib_remove (rn, ri, peer, afi, safi);
3001 break;
3002 }
3003 }
3004}
paul718e3742002-12-13 20:15:29 +00003005
3006/* Delete all kernel routes. */
3007void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003008bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003009{
3010 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003011 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003012 struct bgp_node *rn;
3013 struct bgp_table *table;
3014 struct bgp_info *ri;
3015
paul1eb8ef22005-04-07 07:30:20 +00003016 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003017 {
3018 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3019
3020 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3021 for (ri = rn->info; ri; ri = ri->next)
3022 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3023 && ri->type == ZEBRA_ROUTE_BGP
3024 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003025 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003026
3027 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3028
3029 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3030 for (ri = rn->info; ri; ri = ri->next)
3031 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3032 && ri->type == ZEBRA_ROUTE_BGP
3033 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003034 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003035 }
3036}
3037
3038void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003039bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003040{
3041 vty_reset ();
3042 bgp_zclient_reset ();
3043 access_list_reset ();
3044 prefix_list_reset ();
3045}
3046
3047/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3048 value. */
3049int
3050bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3051{
3052 u_char *pnt;
3053 u_char *lim;
3054 struct prefix p;
3055 int psize;
3056 int ret;
3057
3058 /* Check peer status. */
3059 if (peer->status != Established)
3060 return 0;
3061
3062 pnt = packet->nlri;
3063 lim = pnt + packet->length;
3064
3065 for (; pnt < lim; pnt += psize)
3066 {
3067 /* Clear prefix structure. */
3068 memset (&p, 0, sizeof (struct prefix));
3069
3070 /* Fetch prefix length. */
3071 p.prefixlen = *pnt++;
3072 p.family = afi2family (packet->afi);
3073
3074 /* Already checked in nlri_sanity_check(). We do double check
3075 here. */
3076 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3077 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3078 return -1;
3079
3080 /* Packet size overflow check. */
3081 psize = PSIZE (p.prefixlen);
3082
3083 /* When packet overflow occur return immediately. */
3084 if (pnt + psize > lim)
3085 return -1;
3086
3087 /* Fetch prefix from NLRI packet. */
3088 memcpy (&p.u.prefix, pnt, psize);
3089
3090 /* Check address. */
3091 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3092 {
3093 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3094 {
paulf5ba3872004-07-09 12:11:31 +00003095 /*
3096 * From draft-ietf-idr-bgp4-22, Section 6.3:
3097 * If a BGP router receives an UPDATE message with a
3098 * semantically incorrect NLRI field, in which a prefix is
3099 * semantically incorrect (eg. an unexpected multicast IP
3100 * address), it should ignore the prefix.
3101 */
paul718e3742002-12-13 20:15:29 +00003102 zlog (peer->log, LOG_ERR,
3103 "IPv4 unicast NLRI is multicast address %s",
3104 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003105
paul718e3742002-12-13 20:15:29 +00003106 return -1;
3107 }
3108 }
3109
3110#ifdef HAVE_IPV6
3111 /* Check address. */
3112 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3113 {
3114 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3115 {
3116 char buf[BUFSIZ];
3117
3118 zlog (peer->log, LOG_WARNING,
3119 "IPv6 link-local NLRI received %s ignore this NLRI",
3120 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3121
3122 continue;
3123 }
3124 }
3125#endif /* HAVE_IPV6 */
3126
3127 /* Normal process. */
3128 if (attr)
3129 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3130 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3131 else
3132 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3133 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3134
3135 /* Address family configuration mismatch or maximum-prefix count
3136 overflow. */
3137 if (ret < 0)
3138 return -1;
3139 }
3140
3141 /* Packet length consistency check. */
3142 if (pnt != lim)
3143 return -1;
3144
3145 return 0;
3146}
3147
3148/* NLRI encode syntax check routine. */
3149int
3150bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3151 bgp_size_t length)
3152{
3153 u_char *end;
3154 u_char prefixlen;
3155 int psize;
3156
3157 end = pnt + length;
3158
3159 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3160 syntactic validity. If the field is syntactically incorrect,
3161 then the Error Subcode is set to Invalid Network Field. */
3162
3163 while (pnt < end)
3164 {
3165 prefixlen = *pnt++;
3166
3167 /* Prefix length check. */
3168 if ((afi == AFI_IP && prefixlen > 32)
3169 || (afi == AFI_IP6 && prefixlen > 128))
3170 {
3171 plog_err (peer->log,
3172 "%s [Error] Update packet error (wrong prefix length %d)",
3173 peer->host, prefixlen);
3174 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3175 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3176 return -1;
3177 }
3178
3179 /* Packet size overflow check. */
3180 psize = PSIZE (prefixlen);
3181
3182 if (pnt + psize > end)
3183 {
3184 plog_err (peer->log,
3185 "%s [Error] Update packet error"
3186 " (prefix data overflow prefix size is %d)",
3187 peer->host, psize);
3188 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3189 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3190 return -1;
3191 }
3192
3193 pnt += psize;
3194 }
3195
3196 /* Packet length consistency check. */
3197 if (pnt != end)
3198 {
3199 plog_err (peer->log,
3200 "%s [Error] Update packet error"
3201 " (prefix length mismatch with total length)",
3202 peer->host);
3203 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3204 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3205 return -1;
3206 }
3207 return 0;
3208}
3209
paul94f2b392005-06-28 12:44:16 +00003210static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003211bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003212{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003213 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003214}
3215
paul94f2b392005-06-28 12:44:16 +00003216static void
paul718e3742002-12-13 20:15:29 +00003217bgp_static_free (struct bgp_static *bgp_static)
3218{
3219 if (bgp_static->rmap.name)
3220 free (bgp_static->rmap.name);
3221 XFREE (MTYPE_BGP_STATIC, bgp_static);
3222}
3223
paul94f2b392005-06-28 12:44:16 +00003224static void
paulfee0f4c2004-09-13 05:12:46 +00003225bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3226 struct prefix *p, afi_t afi, safi_t safi)
3227{
3228 struct bgp_node *rn;
3229 struct bgp_info *ri;
3230
3231 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3232
3233 /* Check selected route and self inserted route. */
3234 for (ri = rn->info; ri; ri = ri->next)
3235 if (ri->peer == bgp->peer_self
3236 && ri->type == ZEBRA_ROUTE_BGP
3237 && ri->sub_type == BGP_ROUTE_STATIC)
3238 break;
3239
3240 /* Withdraw static BGP route from routing table. */
3241 if (ri)
3242 {
paulfee0f4c2004-09-13 05:12:46 +00003243 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003244 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003245 }
3246
3247 /* Unlock bgp_node_lookup. */
3248 bgp_unlock_node (rn);
3249}
3250
paul94f2b392005-06-28 12:44:16 +00003251static void
paulfee0f4c2004-09-13 05:12:46 +00003252bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003253 struct bgp_static *bgp_static,
3254 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003255{
3256 struct bgp_node *rn;
3257 struct bgp_info *ri;
3258 struct bgp_info *new;
3259 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003260 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003261 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003262 struct attr new_attr;
3263 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003264 struct bgp *bgp;
3265 int ret;
3266 char buf[SU_ADDRSTRLEN];
3267
3268 bgp = rsclient->bgp;
3269
Paul Jakma06e110f2006-05-12 23:29:22 +00003270 assert (bgp_static);
3271 if (!bgp_static)
3272 return;
3273
paulfee0f4c2004-09-13 05:12:46 +00003274 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3275
3276 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003277
3278 attr.nexthop = bgp_static->igpnexthop;
3279 attr.med = bgp_static->igpmetric;
3280 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003281
Paul Jakma41367172007-08-06 15:24:51 +00003282 if (bgp_static->atomic)
3283 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3284
paulfee0f4c2004-09-13 05:12:46 +00003285 /* Apply network route-map for export to this rsclient. */
3286 if (bgp_static->rmap.name)
3287 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003288 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003289 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003290 info.attr = &attr_tmp;
3291
paulfee0f4c2004-09-13 05:12:46 +00003292 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3293 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3294
3295 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3296
3297 rsclient->rmap_type = 0;
3298
3299 if (ret == RMAP_DENYMATCH)
3300 {
3301 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003302 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003303
3304 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003305 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003306 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003307 bgp_attr_extra_free (&attr);
3308
paulfee0f4c2004-09-13 05:12:46 +00003309 return;
3310 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003311 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003312 }
3313 else
3314 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003315
3316 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003317 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003318
paulfee0f4c2004-09-13 05:12:46 +00003319 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3320
Paul Jakmafb982c22007-05-04 20:15:47 +00003321 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3322 == RMAP_DENY)
3323 {
paulfee0f4c2004-09-13 05:12:46 +00003324 /* This BGP update is filtered. Log the reason then update BGP entry. */
3325 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003326 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003327 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3328 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3329 p->prefixlen, rsclient->host);
3330
3331 bgp->peer_self->rmap_type = 0;
3332
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003333 bgp_attr_unintern (&attr_new);
3334 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003335 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003336
3337 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3338
3339 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003340 }
paulfee0f4c2004-09-13 05:12:46 +00003341
3342 bgp->peer_self->rmap_type = 0;
3343
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003344 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003345 attr_new = bgp_attr_intern (&new_attr);
3346
3347 for (ri = rn->info; ri; ri = ri->next)
3348 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3349 && ri->sub_type == BGP_ROUTE_STATIC)
3350 break;
3351
3352 if (ri)
3353 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003354 if (attrhash_cmp (ri->attr, attr_new) &&
3355 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003356 {
3357 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003358 bgp_attr_unintern (&attr_new);
3359 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003361 return;
3362 }
3363 else
3364 {
3365 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003366 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003367
3368 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003369 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3370 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003371 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003372 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003373 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003374
3375 /* Process change. */
3376 bgp_process (bgp, rn, afi, safi);
3377 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003378 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003379 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003380 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 }
paulfee0f4c2004-09-13 05:12:46 +00003382 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003383
paulfee0f4c2004-09-13 05:12:46 +00003384 /* Make new BGP info. */
3385 new = bgp_info_new ();
3386 new->type = ZEBRA_ROUTE_BGP;
3387 new->sub_type = BGP_ROUTE_STATIC;
3388 new->peer = bgp->peer_self;
3389 SET_FLAG (new->flags, BGP_INFO_VALID);
3390 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003391 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003392
3393 /* Register new BGP information. */
3394 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003395
3396 /* route_node_get lock */
3397 bgp_unlock_node (rn);
3398
paulfee0f4c2004-09-13 05:12:46 +00003399 /* Process change. */
3400 bgp_process (bgp, rn, afi, safi);
3401
3402 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003403 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003404 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003405}
3406
paul94f2b392005-06-28 12:44:16 +00003407static void
paulfee0f4c2004-09-13 05:12:46 +00003408bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003409 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3410{
3411 struct bgp_node *rn;
3412 struct bgp_info *ri;
3413 struct bgp_info *new;
3414 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003415 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003416 struct attr *attr_new;
3417 int ret;
3418
Paul Jakmadd8103a2006-05-12 23:27:30 +00003419 assert (bgp_static);
3420 if (!bgp_static)
3421 return;
3422
paulfee0f4c2004-09-13 05:12:46 +00003423 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003424
3425 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003426
3427 attr.nexthop = bgp_static->igpnexthop;
3428 attr.med = bgp_static->igpmetric;
3429 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003430
Paul Jakma41367172007-08-06 15:24:51 +00003431 if (bgp_static->atomic)
3432 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3433
paul718e3742002-12-13 20:15:29 +00003434 /* Apply route-map. */
3435 if (bgp_static->rmap.name)
3436 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003437 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003438 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003439 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003440
paulfee0f4c2004-09-13 05:12:46 +00003441 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3442
paul718e3742002-12-13 20:15:29 +00003443 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003444
paulfee0f4c2004-09-13 05:12:46 +00003445 bgp->peer_self->rmap_type = 0;
3446
paul718e3742002-12-13 20:15:29 +00003447 if (ret == RMAP_DENYMATCH)
3448 {
3449 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003450 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003451
3452 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003453 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003454 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003455 bgp_static_withdraw (bgp, p, afi, safi);
3456 return;
3457 }
paul286e1e72003-08-08 00:24:31 +00003458 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003459 }
paul286e1e72003-08-08 00:24:31 +00003460 else
3461 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003462
3463 for (ri = rn->info; ri; ri = ri->next)
3464 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3465 && ri->sub_type == BGP_ROUTE_STATIC)
3466 break;
3467
3468 if (ri)
3469 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003470 if (attrhash_cmp (ri->attr, attr_new) &&
3471 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003472 {
3473 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003474 bgp_attr_unintern (&attr_new);
3475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003477 return;
3478 }
3479 else
3480 {
3481 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003482 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003483
3484 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003485 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3486 bgp_info_restore(rn, ri);
3487 else
3488 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003489 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003490 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003491 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003492
3493 /* Process change. */
3494 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3495 bgp_process (bgp, rn, afi, safi);
3496 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003499 return;
3500 }
3501 }
3502
3503 /* Make new BGP info. */
3504 new = bgp_info_new ();
3505 new->type = ZEBRA_ROUTE_BGP;
3506 new->sub_type = BGP_ROUTE_STATIC;
3507 new->peer = bgp->peer_self;
3508 SET_FLAG (new->flags, BGP_INFO_VALID);
3509 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003510 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003511
3512 /* Aggregate address increment. */
3513 bgp_aggregate_increment (bgp, p, new, afi, safi);
3514
3515 /* Register new BGP information. */
3516 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003517
3518 /* route_node_get lock */
3519 bgp_unlock_node (rn);
3520
paul718e3742002-12-13 20:15:29 +00003521 /* Process change. */
3522 bgp_process (bgp, rn, afi, safi);
3523
3524 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003525 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003526 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003527}
3528
3529void
paulfee0f4c2004-09-13 05:12:46 +00003530bgp_static_update (struct bgp *bgp, struct prefix *p,
3531 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3532{
3533 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003534 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003535
3536 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3537
paul1eb8ef22005-04-07 07:30:20 +00003538 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003539 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003540 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3541 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003542 }
3543}
3544
paul94f2b392005-06-28 12:44:16 +00003545static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003546bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3547 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003548{
3549 struct bgp_node *rn;
3550 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003551
paulfee0f4c2004-09-13 05:12:46 +00003552 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003553
3554 /* Make new BGP info. */
3555 new = bgp_info_new ();
3556 new->type = ZEBRA_ROUTE_BGP;
3557 new->sub_type = BGP_ROUTE_STATIC;
3558 new->peer = bgp->peer_self;
3559 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3560 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003561 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003562 new->extra = bgp_info_extra_new();
3563 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003566 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003567
3568 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003569 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003570
paul200df112005-06-01 11:17:05 +00003571 /* route_node_get lock */
3572 bgp_unlock_node (rn);
3573
paul718e3742002-12-13 20:15:29 +00003574 /* Process change. */
3575 bgp_process (bgp, rn, afi, safi);
3576}
3577
3578void
3579bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3580 safi_t safi)
3581{
3582 struct bgp_node *rn;
3583 struct bgp_info *ri;
3584
paulfee0f4c2004-09-13 05:12:46 +00003585 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003586
3587 /* Check selected route and self inserted route. */
3588 for (ri = rn->info; ri; ri = ri->next)
3589 if (ri->peer == bgp->peer_self
3590 && ri->type == ZEBRA_ROUTE_BGP
3591 && ri->sub_type == BGP_ROUTE_STATIC)
3592 break;
3593
3594 /* Withdraw static BGP route from routing table. */
3595 if (ri)
3596 {
3597 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003598 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003599 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003600 }
3601
3602 /* Unlock bgp_node_lookup. */
3603 bgp_unlock_node (rn);
3604}
3605
3606void
paulfee0f4c2004-09-13 05:12:46 +00003607bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3608{
3609 struct bgp_static *bgp_static;
3610 struct bgp *bgp;
3611 struct bgp_node *rn;
3612 struct prefix *p;
3613
3614 bgp = rsclient->bgp;
3615
3616 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3617 if ((bgp_static = rn->info) != NULL)
3618 {
3619 p = &rn->p;
3620
3621 bgp_static_update_rsclient (rsclient, p, bgp_static,
3622 afi, safi);
3623 }
3624}
3625
paul94f2b392005-06-28 12:44:16 +00003626static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003627bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3628 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003629{
3630 struct bgp_node *rn;
3631 struct bgp_info *ri;
3632
paulfee0f4c2004-09-13 05:12:46 +00003633 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003634
3635 /* Check selected route and self inserted route. */
3636 for (ri = rn->info; ri; ri = ri->next)
3637 if (ri->peer == bgp->peer_self
3638 && ri->type == ZEBRA_ROUTE_BGP
3639 && ri->sub_type == BGP_ROUTE_STATIC)
3640 break;
3641
3642 /* Withdraw static BGP route from routing table. */
3643 if (ri)
3644 {
3645 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003646 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003647 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003648 }
3649
3650 /* Unlock bgp_node_lookup. */
3651 bgp_unlock_node (rn);
3652}
3653
3654/* Configure static BGP network. When user don't run zebra, static
3655 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003656static int
paulfd79ac92004-10-13 05:06:08 +00003657bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003658 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003659{
3660 int ret;
3661 struct prefix p;
3662 struct bgp_static *bgp_static;
3663 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003664 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003665
3666 /* Convert IP prefix string to struct prefix. */
3667 ret = str2prefix (ip_str, &p);
3668 if (! ret)
3669 {
3670 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3671 return CMD_WARNING;
3672 }
3673#ifdef HAVE_IPV6
3674 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3675 {
3676 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3677 VTY_NEWLINE);
3678 return CMD_WARNING;
3679 }
3680#endif /* HAVE_IPV6 */
3681
3682 apply_mask (&p);
3683
3684 /* Set BGP static route configuration. */
3685 rn = bgp_node_get (bgp->route[afi][safi], &p);
3686
3687 if (rn->info)
3688 {
3689 /* Configuration change. */
3690 bgp_static = rn->info;
3691
3692 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003693 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3694 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003695
paul718e3742002-12-13 20:15:29 +00003696 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003697
paul718e3742002-12-13 20:15:29 +00003698 if (rmap)
3699 {
3700 if (bgp_static->rmap.name)
3701 free (bgp_static->rmap.name);
3702 bgp_static->rmap.name = strdup (rmap);
3703 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3704 }
3705 else
3706 {
3707 if (bgp_static->rmap.name)
3708 free (bgp_static->rmap.name);
3709 bgp_static->rmap.name = NULL;
3710 bgp_static->rmap.map = NULL;
3711 bgp_static->valid = 0;
3712 }
3713 bgp_unlock_node (rn);
3714 }
3715 else
3716 {
3717 /* New configuration. */
3718 bgp_static = bgp_static_new ();
3719 bgp_static->backdoor = backdoor;
3720 bgp_static->valid = 0;
3721 bgp_static->igpmetric = 0;
3722 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003723
paul718e3742002-12-13 20:15:29 +00003724 if (rmap)
3725 {
3726 if (bgp_static->rmap.name)
3727 free (bgp_static->rmap.name);
3728 bgp_static->rmap.name = strdup (rmap);
3729 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3730 }
3731 rn->info = bgp_static;
3732 }
3733
3734 /* If BGP scan is not enabled, we should install this route here. */
3735 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3736 {
3737 bgp_static->valid = 1;
3738
3739 if (need_update)
3740 bgp_static_withdraw (bgp, &p, afi, safi);
3741
3742 if (! bgp_static->backdoor)
3743 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3744 }
3745
3746 return CMD_SUCCESS;
3747}
3748
3749/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003750static int
paulfd79ac92004-10-13 05:06:08 +00003751bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003752 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003753{
3754 int ret;
3755 struct prefix p;
3756 struct bgp_static *bgp_static;
3757 struct bgp_node *rn;
3758
3759 /* Convert IP prefix string to struct prefix. */
3760 ret = str2prefix (ip_str, &p);
3761 if (! ret)
3762 {
3763 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3764 return CMD_WARNING;
3765 }
3766#ifdef HAVE_IPV6
3767 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3768 {
3769 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3770 VTY_NEWLINE);
3771 return CMD_WARNING;
3772 }
3773#endif /* HAVE_IPV6 */
3774
3775 apply_mask (&p);
3776
3777 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3778 if (! rn)
3779 {
3780 vty_out (vty, "%% Can't find specified static route configuration.%s",
3781 VTY_NEWLINE);
3782 return CMD_WARNING;
3783 }
3784
3785 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003786
paul718e3742002-12-13 20:15:29 +00003787 /* Update BGP RIB. */
3788 if (! bgp_static->backdoor)
3789 bgp_static_withdraw (bgp, &p, afi, safi);
3790
3791 /* Clear configuration. */
3792 bgp_static_free (bgp_static);
3793 rn->info = NULL;
3794 bgp_unlock_node (rn);
3795 bgp_unlock_node (rn);
3796
3797 return CMD_SUCCESS;
3798}
3799
3800/* Called from bgp_delete(). Delete all static routes from the BGP
3801 instance. */
3802void
3803bgp_static_delete (struct bgp *bgp)
3804{
3805 afi_t afi;
3806 safi_t safi;
3807 struct bgp_node *rn;
3808 struct bgp_node *rm;
3809 struct bgp_table *table;
3810 struct bgp_static *bgp_static;
3811
3812 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3813 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3814 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3815 if (rn->info != NULL)
3816 {
3817 if (safi == SAFI_MPLS_VPN)
3818 {
3819 table = rn->info;
3820
3821 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3822 {
3823 bgp_static = rn->info;
3824 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3825 AFI_IP, SAFI_MPLS_VPN,
3826 (struct prefix_rd *)&rn->p,
3827 bgp_static->tag);
3828 bgp_static_free (bgp_static);
3829 rn->info = NULL;
3830 bgp_unlock_node (rn);
3831 }
3832 }
3833 else
3834 {
3835 bgp_static = rn->info;
3836 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3837 bgp_static_free (bgp_static);
3838 rn->info = NULL;
3839 bgp_unlock_node (rn);
3840 }
3841 }
3842}
3843
3844int
paulfd79ac92004-10-13 05:06:08 +00003845bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3846 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003847{
3848 int ret;
3849 struct prefix p;
3850 struct prefix_rd prd;
3851 struct bgp *bgp;
3852 struct bgp_node *prn;
3853 struct bgp_node *rn;
3854 struct bgp_table *table;
3855 struct bgp_static *bgp_static;
3856 u_char tag[3];
3857
3858 bgp = vty->index;
3859
3860 ret = str2prefix (ip_str, &p);
3861 if (! ret)
3862 {
3863 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3864 return CMD_WARNING;
3865 }
3866 apply_mask (&p);
3867
3868 ret = str2prefix_rd (rd_str, &prd);
3869 if (! ret)
3870 {
3871 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3872 return CMD_WARNING;
3873 }
3874
3875 ret = str2tag (tag_str, tag);
3876 if (! ret)
3877 {
3878 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3879 return CMD_WARNING;
3880 }
3881
3882 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3883 (struct prefix *)&prd);
3884 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003885 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003886 else
3887 bgp_unlock_node (prn);
3888 table = prn->info;
3889
3890 rn = bgp_node_get (table, &p);
3891
3892 if (rn->info)
3893 {
3894 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3895 bgp_unlock_node (rn);
3896 }
3897 else
3898 {
3899 /* New configuration. */
3900 bgp_static = bgp_static_new ();
3901 bgp_static->valid = 1;
3902 memcpy (bgp_static->tag, tag, 3);
3903 rn->info = bgp_static;
3904
3905 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3906 }
3907
3908 return CMD_SUCCESS;
3909}
3910
3911/* Configure static BGP network. */
3912int
paulfd79ac92004-10-13 05:06:08 +00003913bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3914 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003915{
3916 int ret;
3917 struct bgp *bgp;
3918 struct prefix p;
3919 struct prefix_rd prd;
3920 struct bgp_node *prn;
3921 struct bgp_node *rn;
3922 struct bgp_table *table;
3923 struct bgp_static *bgp_static;
3924 u_char tag[3];
3925
3926 bgp = vty->index;
3927
3928 /* Convert IP prefix string to struct prefix. */
3929 ret = str2prefix (ip_str, &p);
3930 if (! ret)
3931 {
3932 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3933 return CMD_WARNING;
3934 }
3935 apply_mask (&p);
3936
3937 ret = str2prefix_rd (rd_str, &prd);
3938 if (! ret)
3939 {
3940 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3941 return CMD_WARNING;
3942 }
3943
3944 ret = str2tag (tag_str, tag);
3945 if (! ret)
3946 {
3947 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3948 return CMD_WARNING;
3949 }
3950
3951 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3952 (struct prefix *)&prd);
3953 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003954 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003955 else
3956 bgp_unlock_node (prn);
3957 table = prn->info;
3958
3959 rn = bgp_node_lookup (table, &p);
3960
3961 if (rn)
3962 {
3963 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3964
3965 bgp_static = rn->info;
3966 bgp_static_free (bgp_static);
3967 rn->info = NULL;
3968 bgp_unlock_node (rn);
3969 bgp_unlock_node (rn);
3970 }
3971 else
3972 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3973
3974 return CMD_SUCCESS;
3975}
3976
3977DEFUN (bgp_network,
3978 bgp_network_cmd,
3979 "network A.B.C.D/M",
3980 "Specify a network to announce via BGP\n"
3981 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3982{
3983 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003984 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003985}
3986
3987DEFUN (bgp_network_route_map,
3988 bgp_network_route_map_cmd,
3989 "network A.B.C.D/M route-map WORD",
3990 "Specify a network to announce via BGP\n"
3991 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3992 "Route-map to modify the attributes\n"
3993 "Name of the route map\n")
3994{
3995 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003996 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003997}
3998
3999DEFUN (bgp_network_backdoor,
4000 bgp_network_backdoor_cmd,
4001 "network A.B.C.D/M backdoor",
4002 "Specify a network to announce via BGP\n"
4003 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4004 "Specify a BGP backdoor route\n")
4005{
Paul Jakma41367172007-08-06 15:24:51 +00004006 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004007 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004008}
4009
4010DEFUN (bgp_network_mask,
4011 bgp_network_mask_cmd,
4012 "network A.B.C.D mask A.B.C.D",
4013 "Specify a network to announce via BGP\n"
4014 "Network number\n"
4015 "Network mask\n"
4016 "Network mask\n")
4017{
4018 int ret;
4019 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004020
paul718e3742002-12-13 20:15:29 +00004021 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4022 if (! ret)
4023 {
4024 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4025 return CMD_WARNING;
4026 }
4027
4028 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004029 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004030}
4031
4032DEFUN (bgp_network_mask_route_map,
4033 bgp_network_mask_route_map_cmd,
4034 "network A.B.C.D mask A.B.C.D route-map WORD",
4035 "Specify a network to announce via BGP\n"
4036 "Network number\n"
4037 "Network mask\n"
4038 "Network mask\n"
4039 "Route-map to modify the attributes\n"
4040 "Name of the route map\n")
4041{
4042 int ret;
4043 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004044
paul718e3742002-12-13 20:15:29 +00004045 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4046 if (! ret)
4047 {
4048 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4049 return CMD_WARNING;
4050 }
4051
4052 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004053 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004054}
4055
4056DEFUN (bgp_network_mask_backdoor,
4057 bgp_network_mask_backdoor_cmd,
4058 "network A.B.C.D mask A.B.C.D backdoor",
4059 "Specify a network to announce via BGP\n"
4060 "Network number\n"
4061 "Network mask\n"
4062 "Network mask\n"
4063 "Specify a BGP backdoor route\n")
4064{
4065 int ret;
4066 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004067
paul718e3742002-12-13 20:15:29 +00004068 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4069 if (! ret)
4070 {
4071 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4072 return CMD_WARNING;
4073 }
4074
Paul Jakma41367172007-08-06 15:24:51 +00004075 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004076 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004077}
4078
4079DEFUN (bgp_network_mask_natural,
4080 bgp_network_mask_natural_cmd,
4081 "network A.B.C.D",
4082 "Specify a network to announce via BGP\n"
4083 "Network number\n")
4084{
4085 int ret;
4086 char prefix_str[BUFSIZ];
4087
4088 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4089 if (! ret)
4090 {
4091 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4092 return CMD_WARNING;
4093 }
4094
4095 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004096 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004097}
4098
4099DEFUN (bgp_network_mask_natural_route_map,
4100 bgp_network_mask_natural_route_map_cmd,
4101 "network A.B.C.D route-map WORD",
4102 "Specify a network to announce via BGP\n"
4103 "Network number\n"
4104 "Route-map to modify the attributes\n"
4105 "Name of the route map\n")
4106{
4107 int ret;
4108 char prefix_str[BUFSIZ];
4109
4110 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116
4117 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004118 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004119}
4120
4121DEFUN (bgp_network_mask_natural_backdoor,
4122 bgp_network_mask_natural_backdoor_cmd,
4123 "network A.B.C.D backdoor",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n"
4126 "Specify a BGP backdoor route\n")
4127{
4128 int ret;
4129 char prefix_str[BUFSIZ];
4130
4131 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4132 if (! ret)
4133 {
4134 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4135 return CMD_WARNING;
4136 }
4137
Paul Jakma41367172007-08-06 15:24:51 +00004138 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004139 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004140}
4141
4142DEFUN (no_bgp_network,
4143 no_bgp_network_cmd,
4144 "no network A.B.C.D/M",
4145 NO_STR
4146 "Specify a network to announce via BGP\n"
4147 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4148{
4149 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4150 bgp_node_safi (vty));
4151}
4152
4153ALIAS (no_bgp_network,
4154 no_bgp_network_route_map_cmd,
4155 "no network A.B.C.D/M route-map WORD",
4156 NO_STR
4157 "Specify a network to announce via BGP\n"
4158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4159 "Route-map to modify the attributes\n"
4160 "Name of the route map\n")
4161
4162ALIAS (no_bgp_network,
4163 no_bgp_network_backdoor_cmd,
4164 "no network A.B.C.D/M backdoor",
4165 NO_STR
4166 "Specify a network to announce via BGP\n"
4167 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4168 "Specify a BGP backdoor route\n")
4169
4170DEFUN (no_bgp_network_mask,
4171 no_bgp_network_mask_cmd,
4172 "no network A.B.C.D mask A.B.C.D",
4173 NO_STR
4174 "Specify a network to announce via BGP\n"
4175 "Network number\n"
4176 "Network mask\n"
4177 "Network mask\n")
4178{
4179 int ret;
4180 char prefix_str[BUFSIZ];
4181
4182 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4190 bgp_node_safi (vty));
4191}
4192
4193ALIAS (no_bgp_network_mask,
4194 no_bgp_network_mask_route_map_cmd,
4195 "no network A.B.C.D mask A.B.C.D route-map WORD",
4196 NO_STR
4197 "Specify a network to announce via BGP\n"
4198 "Network number\n"
4199 "Network mask\n"
4200 "Network mask\n"
4201 "Route-map to modify the attributes\n"
4202 "Name of the route map\n")
4203
4204ALIAS (no_bgp_network_mask,
4205 no_bgp_network_mask_backdoor_cmd,
4206 "no network A.B.C.D mask A.B.C.D backdoor",
4207 NO_STR
4208 "Specify a network to announce via BGP\n"
4209 "Network number\n"
4210 "Network mask\n"
4211 "Network mask\n"
4212 "Specify a BGP backdoor route\n")
4213
4214DEFUN (no_bgp_network_mask_natural,
4215 no_bgp_network_mask_natural_cmd,
4216 "no network A.B.C.D",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "Network number\n")
4220{
4221 int ret;
4222 char prefix_str[BUFSIZ];
4223
4224 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4225 if (! ret)
4226 {
4227 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4228 return CMD_WARNING;
4229 }
4230
4231 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4232 bgp_node_safi (vty));
4233}
4234
4235ALIAS (no_bgp_network_mask_natural,
4236 no_bgp_network_mask_natural_route_map_cmd,
4237 "no network A.B.C.D route-map WORD",
4238 NO_STR
4239 "Specify a network to announce via BGP\n"
4240 "Network number\n"
4241 "Route-map to modify the attributes\n"
4242 "Name of the route map\n")
4243
4244ALIAS (no_bgp_network_mask_natural,
4245 no_bgp_network_mask_natural_backdoor_cmd,
4246 "no network A.B.C.D backdoor",
4247 NO_STR
4248 "Specify a network to announce via BGP\n"
4249 "Network number\n"
4250 "Specify a BGP backdoor route\n")
4251
4252#ifdef HAVE_IPV6
4253DEFUN (ipv6_bgp_network,
4254 ipv6_bgp_network_cmd,
4255 "network X:X::X:X/M",
4256 "Specify a network to announce via BGP\n"
4257 "IPv6 prefix <network>/<length>\n")
4258{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304259 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004260 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004261}
4262
4263DEFUN (ipv6_bgp_network_route_map,
4264 ipv6_bgp_network_route_map_cmd,
4265 "network X:X::X:X/M route-map WORD",
4266 "Specify a network to announce via BGP\n"
4267 "IPv6 prefix <network>/<length>\n"
4268 "Route-map to modify the attributes\n"
4269 "Name of the route map\n")
4270{
4271 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004272 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004273}
4274
4275DEFUN (no_ipv6_bgp_network,
4276 no_ipv6_bgp_network_cmd,
4277 "no network X:X::X:X/M",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IPv6 prefix <network>/<length>\n")
4281{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304282 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004283}
4284
4285ALIAS (no_ipv6_bgp_network,
4286 no_ipv6_bgp_network_route_map_cmd,
4287 "no network X:X::X:X/M route-map WORD",
4288 NO_STR
4289 "Specify a network to announce via BGP\n"
4290 "IPv6 prefix <network>/<length>\n"
4291 "Route-map to modify the attributes\n"
4292 "Name of the route map\n")
4293
4294ALIAS (ipv6_bgp_network,
4295 old_ipv6_bgp_network_cmd,
4296 "ipv6 bgp network X:X::X:X/M",
4297 IPV6_STR
4298 BGP_STR
4299 "Specify a network to announce via BGP\n"
4300 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4301
4302ALIAS (no_ipv6_bgp_network,
4303 old_no_ipv6_bgp_network_cmd,
4304 "no ipv6 bgp network X:X::X:X/M",
4305 NO_STR
4306 IPV6_STR
4307 BGP_STR
4308 "Specify a network to announce via BGP\n"
4309 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4310#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004311
4312/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4313ALIAS_DEPRECATED (bgp_network,
4314 bgp_network_ttl_cmd,
4315 "network A.B.C.D/M pathlimit <0-255>",
4316 "Specify a network to announce via BGP\n"
4317 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4318 "AS-Path hopcount limit attribute\n"
4319 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4320ALIAS_DEPRECATED (bgp_network_backdoor,
4321 bgp_network_backdoor_ttl_cmd,
4322 "network A.B.C.D/M backdoor pathlimit <0-255>",
4323 "Specify a network to announce via BGP\n"
4324 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4325 "Specify a BGP backdoor route\n"
4326 "AS-Path hopcount limit attribute\n"
4327 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4328ALIAS_DEPRECATED (bgp_network_mask,
4329 bgp_network_mask_ttl_cmd,
4330 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4331 "Specify a network to announce via BGP\n"
4332 "Network number\n"
4333 "Network mask\n"
4334 "Network mask\n"
4335 "AS-Path hopcount limit attribute\n"
4336 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4337ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4338 bgp_network_mask_backdoor_ttl_cmd,
4339 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "Network mask\n"
4343 "Network mask\n"
4344 "Specify a BGP backdoor route\n"
4345 "AS-Path hopcount limit attribute\n"
4346 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4347ALIAS_DEPRECATED (bgp_network_mask_natural,
4348 bgp_network_mask_natural_ttl_cmd,
4349 "network A.B.C.D pathlimit <0-255>",
4350 "Specify a network to announce via BGP\n"
4351 "Network number\n"
4352 "AS-Path hopcount limit attribute\n"
4353 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4354ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4355 bgp_network_mask_natural_backdoor_ttl_cmd,
4356 "network A.B.C.D backdoor pathlimit (1-255>",
4357 "Specify a network to announce via BGP\n"
4358 "Network number\n"
4359 "Specify a BGP backdoor route\n"
4360 "AS-Path hopcount limit attribute\n"
4361 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4362ALIAS_DEPRECATED (no_bgp_network,
4363 no_bgp_network_ttl_cmd,
4364 "no network A.B.C.D/M pathlimit <0-255>",
4365 NO_STR
4366 "Specify a network to announce via BGP\n"
4367 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4368 "AS-Path hopcount limit attribute\n"
4369 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4370ALIAS_DEPRECATED (no_bgp_network,
4371 no_bgp_network_backdoor_ttl_cmd,
4372 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4373 NO_STR
4374 "Specify a network to announce via BGP\n"
4375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4376 "Specify a BGP backdoor route\n"
4377 "AS-Path hopcount limit attribute\n"
4378 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4379ALIAS_DEPRECATED (no_bgp_network,
4380 no_bgp_network_mask_ttl_cmd,
4381 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4382 NO_STR
4383 "Specify a network to announce via BGP\n"
4384 "Network number\n"
4385 "Network mask\n"
4386 "Network mask\n"
4387 "AS-Path hopcount limit attribute\n"
4388 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4389ALIAS_DEPRECATED (no_bgp_network_mask,
4390 no_bgp_network_mask_backdoor_ttl_cmd,
4391 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4392 NO_STR
4393 "Specify a network to announce via BGP\n"
4394 "Network number\n"
4395 "Network mask\n"
4396 "Network mask\n"
4397 "Specify a BGP backdoor route\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4401 no_bgp_network_mask_natural_ttl_cmd,
4402 "no network A.B.C.D pathlimit <0-255>",
4403 NO_STR
4404 "Specify a network to announce via BGP\n"
4405 "Network number\n"
4406 "AS-Path hopcount limit attribute\n"
4407 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4408ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4409 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4410 "no network A.B.C.D backdoor pathlimit <0-255>",
4411 NO_STR
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "Specify a BGP backdoor route\n"
4415 "AS-Path hopcount limit attribute\n"
4416 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004417#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004418ALIAS_DEPRECATED (ipv6_bgp_network,
4419 ipv6_bgp_network_ttl_cmd,
4420 "network X:X::X:X/M pathlimit <0-255>",
4421 "Specify a network to announce via BGP\n"
4422 "IPv6 prefix <network>/<length>\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4425ALIAS_DEPRECATED (no_ipv6_bgp_network,
4426 no_ipv6_bgp_network_ttl_cmd,
4427 "no network X:X::X:X/M pathlimit <0-255>",
4428 NO_STR
4429 "Specify a network to announce via BGP\n"
4430 "IPv6 prefix <network>/<length>\n"
4431 "AS-Path hopcount limit attribute\n"
4432 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004433#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004434
4435/* Aggreagete address:
4436
4437 advertise-map Set condition to advertise attribute
4438 as-set Generate AS set path information
4439 attribute-map Set attributes of aggregate
4440 route-map Set parameters of aggregate
4441 summary-only Filter more specific routes from updates
4442 suppress-map Conditionally filter more specific routes from updates
4443 <cr>
4444 */
4445struct bgp_aggregate
4446{
4447 /* Summary-only flag. */
4448 u_char summary_only;
4449
4450 /* AS set generation. */
4451 u_char as_set;
4452
4453 /* Route-map for aggregated route. */
4454 struct route_map *map;
4455
4456 /* Suppress-count. */
4457 unsigned long count;
4458
4459 /* SAFI configuration. */
4460 safi_t safi;
4461};
4462
paul94f2b392005-06-28 12:44:16 +00004463static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004464bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004465{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004466 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004467}
4468
paul94f2b392005-06-28 12:44:16 +00004469static void
paul718e3742002-12-13 20:15:29 +00004470bgp_aggregate_free (struct bgp_aggregate *aggregate)
4471{
4472 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4473}
4474
paul94f2b392005-06-28 12:44:16 +00004475static void
paul718e3742002-12-13 20:15:29 +00004476bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4477 afi_t afi, safi_t safi, struct bgp_info *del,
4478 struct bgp_aggregate *aggregate)
4479{
4480 struct bgp_table *table;
4481 struct bgp_node *top;
4482 struct bgp_node *rn;
4483 u_char origin;
4484 struct aspath *aspath = NULL;
4485 struct aspath *asmerge = NULL;
4486 struct community *community = NULL;
4487 struct community *commerge = NULL;
4488 struct in_addr nexthop;
4489 u_int32_t med = 0;
4490 struct bgp_info *ri;
4491 struct bgp_info *new;
4492 int first = 1;
4493 unsigned long match = 0;
4494
4495 /* Record adding route's nexthop and med. */
4496 if (rinew)
4497 {
4498 nexthop = rinew->attr->nexthop;
4499 med = rinew->attr->med;
4500 }
4501
4502 /* ORIGIN attribute: If at least one route among routes that are
4503 aggregated has ORIGIN with the value INCOMPLETE, then the
4504 aggregated route must have the ORIGIN attribute with the value
4505 INCOMPLETE. Otherwise, if at least one route among routes that
4506 are aggregated has ORIGIN with the value EGP, then the aggregated
4507 route must have the origin attribute with the value EGP. In all
4508 other case the value of the ORIGIN attribute of the aggregated
4509 route is INTERNAL. */
4510 origin = BGP_ORIGIN_IGP;
4511
4512 table = bgp->rib[afi][safi];
4513
4514 top = bgp_node_get (table, p);
4515 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4516 if (rn->p.prefixlen > p->prefixlen)
4517 {
4518 match = 0;
4519
4520 for (ri = rn->info; ri; ri = ri->next)
4521 {
4522 if (BGP_INFO_HOLDDOWN (ri))
4523 continue;
4524
4525 if (del && ri == del)
4526 continue;
4527
4528 if (! rinew && first)
4529 {
4530 nexthop = ri->attr->nexthop;
4531 med = ri->attr->med;
4532 first = 0;
4533 }
4534
4535#ifdef AGGREGATE_NEXTHOP_CHECK
4536 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4537 || ri->attr->med != med)
4538 {
4539 if (aspath)
4540 aspath_free (aspath);
4541 if (community)
4542 community_free (community);
4543 bgp_unlock_node (rn);
4544 bgp_unlock_node (top);
4545 return;
4546 }
4547#endif /* AGGREGATE_NEXTHOP_CHECK */
4548
4549 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4550 {
4551 if (aggregate->summary_only)
4552 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004553 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004554 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004555 match++;
4556 }
4557
4558 aggregate->count++;
4559
4560 if (aggregate->as_set)
4561 {
4562 if (origin < ri->attr->origin)
4563 origin = ri->attr->origin;
4564
4565 if (aspath)
4566 {
4567 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4568 aspath_free (aspath);
4569 aspath = asmerge;
4570 }
4571 else
4572 aspath = aspath_dup (ri->attr->aspath);
4573
4574 if (ri->attr->community)
4575 {
4576 if (community)
4577 {
4578 commerge = community_merge (community,
4579 ri->attr->community);
4580 community = community_uniq_sort (commerge);
4581 community_free (commerge);
4582 }
4583 else
4584 community = community_dup (ri->attr->community);
4585 }
4586 }
4587 }
4588 }
4589 if (match)
4590 bgp_process (bgp, rn, afi, safi);
4591 }
4592 bgp_unlock_node (top);
4593
4594 if (rinew)
4595 {
4596 aggregate->count++;
4597
4598 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004599 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004600
4601 if (aggregate->as_set)
4602 {
4603 if (origin < rinew->attr->origin)
4604 origin = rinew->attr->origin;
4605
4606 if (aspath)
4607 {
4608 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4609 aspath_free (aspath);
4610 aspath = asmerge;
4611 }
4612 else
4613 aspath = aspath_dup (rinew->attr->aspath);
4614
4615 if (rinew->attr->community)
4616 {
4617 if (community)
4618 {
4619 commerge = community_merge (community,
4620 rinew->attr->community);
4621 community = community_uniq_sort (commerge);
4622 community_free (commerge);
4623 }
4624 else
4625 community = community_dup (rinew->attr->community);
4626 }
4627 }
4628 }
4629
4630 if (aggregate->count > 0)
4631 {
4632 rn = bgp_node_get (table, p);
4633 new = bgp_info_new ();
4634 new->type = ZEBRA_ROUTE_BGP;
4635 new->sub_type = BGP_ROUTE_AGGREGATE;
4636 new->peer = bgp->peer_self;
4637 SET_FLAG (new->flags, BGP_INFO_VALID);
4638 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004639 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004640
4641 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004642 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004643 bgp_process (bgp, rn, afi, safi);
4644 }
4645 else
4646 {
4647 if (aspath)
4648 aspath_free (aspath);
4649 if (community)
4650 community_free (community);
4651 }
4652}
4653
4654void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4655 struct bgp_aggregate *);
4656
4657void
4658bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4659 struct bgp_info *ri, afi_t afi, safi_t safi)
4660{
4661 struct bgp_node *child;
4662 struct bgp_node *rn;
4663 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004664 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004665
4666 /* MPLS-VPN aggregation is not yet supported. */
4667 if (safi == SAFI_MPLS_VPN)
4668 return;
4669
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004670 table = bgp->aggregate[afi][safi];
4671
4672 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004673 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004674 return;
4675
paul718e3742002-12-13 20:15:29 +00004676 if (p->prefixlen == 0)
4677 return;
4678
4679 if (BGP_INFO_HOLDDOWN (ri))
4680 return;
4681
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004682 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004683
4684 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004685 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004686 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4687 {
4688 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004689 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004690 }
4691 bgp_unlock_node (child);
4692}
4693
4694void
4695bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4696 struct bgp_info *del, afi_t afi, safi_t safi)
4697{
4698 struct bgp_node *child;
4699 struct bgp_node *rn;
4700 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004701 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004702
4703 /* MPLS-VPN aggregation is not yet supported. */
4704 if (safi == SAFI_MPLS_VPN)
4705 return;
4706
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004707 table = bgp->aggregate[afi][safi];
4708
4709 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004710 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004711 return;
4712
paul718e3742002-12-13 20:15:29 +00004713 if (p->prefixlen == 0)
4714 return;
4715
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004716 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004717
4718 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004719 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004720 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4721 {
4722 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004723 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004724 }
4725 bgp_unlock_node (child);
4726}
4727
paul94f2b392005-06-28 12:44:16 +00004728static void
paul718e3742002-12-13 20:15:29 +00004729bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4730 struct bgp_aggregate *aggregate)
4731{
4732 struct bgp_table *table;
4733 struct bgp_node *top;
4734 struct bgp_node *rn;
4735 struct bgp_info *new;
4736 struct bgp_info *ri;
4737 unsigned long match;
4738 u_char origin = BGP_ORIGIN_IGP;
4739 struct aspath *aspath = NULL;
4740 struct aspath *asmerge = NULL;
4741 struct community *community = NULL;
4742 struct community *commerge = NULL;
4743
4744 table = bgp->rib[afi][safi];
4745
4746 /* Sanity check. */
4747 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4748 return;
4749 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4750 return;
4751
4752 /* If routes exists below this node, generate aggregate routes. */
4753 top = bgp_node_get (table, p);
4754 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4755 if (rn->p.prefixlen > p->prefixlen)
4756 {
4757 match = 0;
4758
4759 for (ri = rn->info; ri; ri = ri->next)
4760 {
4761 if (BGP_INFO_HOLDDOWN (ri))
4762 continue;
4763
4764 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4765 {
4766 /* summary-only aggregate route suppress aggregated
4767 route announcement. */
4768 if (aggregate->summary_only)
4769 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004770 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004771 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004772 match++;
4773 }
4774 /* as-set aggregate route generate origin, as path,
4775 community aggregation. */
4776 if (aggregate->as_set)
4777 {
4778 if (origin < ri->attr->origin)
4779 origin = ri->attr->origin;
4780
4781 if (aspath)
4782 {
4783 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4784 aspath_free (aspath);
4785 aspath = asmerge;
4786 }
4787 else
4788 aspath = aspath_dup (ri->attr->aspath);
4789
4790 if (ri->attr->community)
4791 {
4792 if (community)
4793 {
4794 commerge = community_merge (community,
4795 ri->attr->community);
4796 community = community_uniq_sort (commerge);
4797 community_free (commerge);
4798 }
4799 else
4800 community = community_dup (ri->attr->community);
4801 }
4802 }
4803 aggregate->count++;
4804 }
4805 }
4806
4807 /* If this node is suppressed, process the change. */
4808 if (match)
4809 bgp_process (bgp, rn, afi, safi);
4810 }
4811 bgp_unlock_node (top);
4812
4813 /* Add aggregate route to BGP table. */
4814 if (aggregate->count)
4815 {
4816 rn = bgp_node_get (table, p);
4817
4818 new = bgp_info_new ();
4819 new->type = ZEBRA_ROUTE_BGP;
4820 new->sub_type = BGP_ROUTE_AGGREGATE;
4821 new->peer = bgp->peer_self;
4822 SET_FLAG (new->flags, BGP_INFO_VALID);
4823 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004824 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004825
4826 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004827 bgp_unlock_node (rn);
4828
paul718e3742002-12-13 20:15:29 +00004829 /* Process change. */
4830 bgp_process (bgp, rn, afi, safi);
4831 }
4832}
4833
4834void
4835bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4836 safi_t safi, struct bgp_aggregate *aggregate)
4837{
4838 struct bgp_table *table;
4839 struct bgp_node *top;
4840 struct bgp_node *rn;
4841 struct bgp_info *ri;
4842 unsigned long match;
4843
4844 table = bgp->rib[afi][safi];
4845
4846 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4847 return;
4848 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4849 return;
4850
4851 /* If routes exists below this node, generate aggregate routes. */
4852 top = bgp_node_get (table, p);
4853 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4854 if (rn->p.prefixlen > p->prefixlen)
4855 {
4856 match = 0;
4857
4858 for (ri = rn->info; ri; ri = ri->next)
4859 {
4860 if (BGP_INFO_HOLDDOWN (ri))
4861 continue;
4862
4863 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4864 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004865 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004866 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004867 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004868
Paul Jakmafb982c22007-05-04 20:15:47 +00004869 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004870 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004871 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004872 match++;
4873 }
4874 }
4875 aggregate->count--;
4876 }
4877 }
4878
Paul Jakmafb982c22007-05-04 20:15:47 +00004879 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004880 if (match)
4881 bgp_process (bgp, rn, afi, safi);
4882 }
4883 bgp_unlock_node (top);
4884
4885 /* Delete aggregate route from BGP table. */
4886 rn = bgp_node_get (table, p);
4887
4888 for (ri = rn->info; ri; ri = ri->next)
4889 if (ri->peer == bgp->peer_self
4890 && ri->type == ZEBRA_ROUTE_BGP
4891 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4892 break;
4893
4894 /* Withdraw static BGP route from routing table. */
4895 if (ri)
4896 {
paul718e3742002-12-13 20:15:29 +00004897 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004898 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004899 }
4900
4901 /* Unlock bgp_node_lookup. */
4902 bgp_unlock_node (rn);
4903}
4904
4905/* Aggregate route attribute. */
4906#define AGGREGATE_SUMMARY_ONLY 1
4907#define AGGREGATE_AS_SET 1
4908
paul94f2b392005-06-28 12:44:16 +00004909static int
Robert Baysf6269b42010-08-05 10:26:28 -07004910bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4911 afi_t afi, safi_t safi)
4912{
4913 int ret;
4914 struct prefix p;
4915 struct bgp_node *rn;
4916 struct bgp *bgp;
4917 struct bgp_aggregate *aggregate;
4918
4919 /* Convert string to prefix structure. */
4920 ret = str2prefix (prefix_str, &p);
4921 if (!ret)
4922 {
4923 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4924 return CMD_WARNING;
4925 }
4926 apply_mask (&p);
4927
4928 /* Get BGP structure. */
4929 bgp = vty->index;
4930
4931 /* Old configuration check. */
4932 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4933 if (! rn)
4934 {
4935 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4936 VTY_NEWLINE);
4937 return CMD_WARNING;
4938 }
4939
4940 aggregate = rn->info;
4941 if (aggregate->safi & SAFI_UNICAST)
4942 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4943 if (aggregate->safi & SAFI_MULTICAST)
4944 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4945
4946 /* Unlock aggregate address configuration. */
4947 rn->info = NULL;
4948 bgp_aggregate_free (aggregate);
4949 bgp_unlock_node (rn);
4950 bgp_unlock_node (rn);
4951
4952 return CMD_SUCCESS;
4953}
4954
4955static int
4956bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004957 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004958 u_char summary_only, u_char as_set)
4959{
4960 int ret;
4961 struct prefix p;
4962 struct bgp_node *rn;
4963 struct bgp *bgp;
4964 struct bgp_aggregate *aggregate;
4965
4966 /* Convert string to prefix structure. */
4967 ret = str2prefix (prefix_str, &p);
4968 if (!ret)
4969 {
4970 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4971 return CMD_WARNING;
4972 }
4973 apply_mask (&p);
4974
4975 /* Get BGP structure. */
4976 bgp = vty->index;
4977
4978 /* Old configuration check. */
4979 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4980
4981 if (rn->info)
4982 {
4983 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004984 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004985 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4986 if (ret)
4987 {
Robert Bays368473f2010-08-05 10:26:29 -07004988 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4989 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004990 return CMD_WARNING;
4991 }
paul718e3742002-12-13 20:15:29 +00004992 }
4993
4994 /* Make aggregate address structure. */
4995 aggregate = bgp_aggregate_new ();
4996 aggregate->summary_only = summary_only;
4997 aggregate->as_set = as_set;
4998 aggregate->safi = safi;
4999 rn->info = aggregate;
5000
5001 /* Aggregate address insert into BGP routing table. */
5002 if (safi & SAFI_UNICAST)
5003 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5004 if (safi & SAFI_MULTICAST)
5005 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5006
5007 return CMD_SUCCESS;
5008}
5009
paul718e3742002-12-13 20:15:29 +00005010DEFUN (aggregate_address,
5011 aggregate_address_cmd,
5012 "aggregate-address A.B.C.D/M",
5013 "Configure BGP aggregate entries\n"
5014 "Aggregate prefix\n")
5015{
5016 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5017}
5018
5019DEFUN (aggregate_address_mask,
5020 aggregate_address_mask_cmd,
5021 "aggregate-address A.B.C.D A.B.C.D",
5022 "Configure BGP aggregate entries\n"
5023 "Aggregate address\n"
5024 "Aggregate mask\n")
5025{
5026 int ret;
5027 char prefix_str[BUFSIZ];
5028
5029 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5030
5031 if (! ret)
5032 {
5033 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5034 return CMD_WARNING;
5035 }
5036
5037 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5038 0, 0);
5039}
5040
5041DEFUN (aggregate_address_summary_only,
5042 aggregate_address_summary_only_cmd,
5043 "aggregate-address A.B.C.D/M summary-only",
5044 "Configure BGP aggregate entries\n"
5045 "Aggregate prefix\n"
5046 "Filter more specific routes from updates\n")
5047{
5048 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5049 AGGREGATE_SUMMARY_ONLY, 0);
5050}
5051
5052DEFUN (aggregate_address_mask_summary_only,
5053 aggregate_address_mask_summary_only_cmd,
5054 "aggregate-address A.B.C.D A.B.C.D summary-only",
5055 "Configure BGP aggregate entries\n"
5056 "Aggregate address\n"
5057 "Aggregate mask\n"
5058 "Filter more specific routes from updates\n")
5059{
5060 int ret;
5061 char prefix_str[BUFSIZ];
5062
5063 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5064
5065 if (! ret)
5066 {
5067 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5068 return CMD_WARNING;
5069 }
5070
5071 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5072 AGGREGATE_SUMMARY_ONLY, 0);
5073}
5074
5075DEFUN (aggregate_address_as_set,
5076 aggregate_address_as_set_cmd,
5077 "aggregate-address A.B.C.D/M as-set",
5078 "Configure BGP aggregate entries\n"
5079 "Aggregate prefix\n"
5080 "Generate AS set path information\n")
5081{
5082 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5083 0, AGGREGATE_AS_SET);
5084}
5085
5086DEFUN (aggregate_address_mask_as_set,
5087 aggregate_address_mask_as_set_cmd,
5088 "aggregate-address A.B.C.D A.B.C.D as-set",
5089 "Configure BGP aggregate entries\n"
5090 "Aggregate address\n"
5091 "Aggregate mask\n"
5092 "Generate AS set path information\n")
5093{
5094 int ret;
5095 char prefix_str[BUFSIZ];
5096
5097 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5098
5099 if (! ret)
5100 {
5101 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5102 return CMD_WARNING;
5103 }
5104
5105 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5106 0, AGGREGATE_AS_SET);
5107}
5108
5109
5110DEFUN (aggregate_address_as_set_summary,
5111 aggregate_address_as_set_summary_cmd,
5112 "aggregate-address A.B.C.D/M as-set summary-only",
5113 "Configure BGP aggregate entries\n"
5114 "Aggregate prefix\n"
5115 "Generate AS set path information\n"
5116 "Filter more specific routes from updates\n")
5117{
5118 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5119 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5120}
5121
5122ALIAS (aggregate_address_as_set_summary,
5123 aggregate_address_summary_as_set_cmd,
5124 "aggregate-address A.B.C.D/M summary-only as-set",
5125 "Configure BGP aggregate entries\n"
5126 "Aggregate prefix\n"
5127 "Filter more specific routes from updates\n"
5128 "Generate AS set path information\n")
5129
5130DEFUN (aggregate_address_mask_as_set_summary,
5131 aggregate_address_mask_as_set_summary_cmd,
5132 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5133 "Configure BGP aggregate entries\n"
5134 "Aggregate address\n"
5135 "Aggregate mask\n"
5136 "Generate AS set path information\n"
5137 "Filter more specific routes from updates\n")
5138{
5139 int ret;
5140 char prefix_str[BUFSIZ];
5141
5142 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5143
5144 if (! ret)
5145 {
5146 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5147 return CMD_WARNING;
5148 }
5149
5150 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5151 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5152}
5153
5154ALIAS (aggregate_address_mask_as_set_summary,
5155 aggregate_address_mask_summary_as_set_cmd,
5156 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5157 "Configure BGP aggregate entries\n"
5158 "Aggregate address\n"
5159 "Aggregate mask\n"
5160 "Filter more specific routes from updates\n"
5161 "Generate AS set path information\n")
5162
5163DEFUN (no_aggregate_address,
5164 no_aggregate_address_cmd,
5165 "no aggregate-address A.B.C.D/M",
5166 NO_STR
5167 "Configure BGP aggregate entries\n"
5168 "Aggregate prefix\n")
5169{
5170 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5171}
5172
5173ALIAS (no_aggregate_address,
5174 no_aggregate_address_summary_only_cmd,
5175 "no aggregate-address A.B.C.D/M summary-only",
5176 NO_STR
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180
5181ALIAS (no_aggregate_address,
5182 no_aggregate_address_as_set_cmd,
5183 "no aggregate-address A.B.C.D/M as-set",
5184 NO_STR
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate prefix\n"
5187 "Generate AS set path information\n")
5188
5189ALIAS (no_aggregate_address,
5190 no_aggregate_address_as_set_summary_cmd,
5191 "no aggregate-address A.B.C.D/M as-set summary-only",
5192 NO_STR
5193 "Configure BGP aggregate entries\n"
5194 "Aggregate prefix\n"
5195 "Generate AS set path information\n"
5196 "Filter more specific routes from updates\n")
5197
5198ALIAS (no_aggregate_address,
5199 no_aggregate_address_summary_as_set_cmd,
5200 "no aggregate-address A.B.C.D/M summary-only as-set",
5201 NO_STR
5202 "Configure BGP aggregate entries\n"
5203 "Aggregate prefix\n"
5204 "Filter more specific routes from updates\n"
5205 "Generate AS set path information\n")
5206
5207DEFUN (no_aggregate_address_mask,
5208 no_aggregate_address_mask_cmd,
5209 "no aggregate-address A.B.C.D A.B.C.D",
5210 NO_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate address\n"
5213 "Aggregate mask\n")
5214{
5215 int ret;
5216 char prefix_str[BUFSIZ];
5217
5218 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5219
5220 if (! ret)
5221 {
5222 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5223 return CMD_WARNING;
5224 }
5225
5226 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5227}
5228
5229ALIAS (no_aggregate_address_mask,
5230 no_aggregate_address_mask_summary_only_cmd,
5231 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate address\n"
5235 "Aggregate mask\n"
5236 "Filter more specific routes from updates\n")
5237
5238ALIAS (no_aggregate_address_mask,
5239 no_aggregate_address_mask_as_set_cmd,
5240 "no aggregate-address A.B.C.D A.B.C.D as-set",
5241 NO_STR
5242 "Configure BGP aggregate entries\n"
5243 "Aggregate address\n"
5244 "Aggregate mask\n"
5245 "Generate AS set path information\n")
5246
5247ALIAS (no_aggregate_address_mask,
5248 no_aggregate_address_mask_as_set_summary_cmd,
5249 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate address\n"
5253 "Aggregate mask\n"
5254 "Generate AS set path information\n"
5255 "Filter more specific routes from updates\n")
5256
5257ALIAS (no_aggregate_address_mask,
5258 no_aggregate_address_mask_summary_as_set_cmd,
5259 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5260 NO_STR
5261 "Configure BGP aggregate entries\n"
5262 "Aggregate address\n"
5263 "Aggregate mask\n"
5264 "Filter more specific routes from updates\n"
5265 "Generate AS set path information\n")
5266
5267#ifdef HAVE_IPV6
5268DEFUN (ipv6_aggregate_address,
5269 ipv6_aggregate_address_cmd,
5270 "aggregate-address X:X::X:X/M",
5271 "Configure BGP aggregate entries\n"
5272 "Aggregate prefix\n")
5273{
5274 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5275}
5276
5277DEFUN (ipv6_aggregate_address_summary_only,
5278 ipv6_aggregate_address_summary_only_cmd,
5279 "aggregate-address X:X::X:X/M summary-only",
5280 "Configure BGP aggregate entries\n"
5281 "Aggregate prefix\n"
5282 "Filter more specific routes from updates\n")
5283{
5284 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5285 AGGREGATE_SUMMARY_ONLY, 0);
5286}
5287
5288DEFUN (no_ipv6_aggregate_address,
5289 no_ipv6_aggregate_address_cmd,
5290 "no aggregate-address X:X::X:X/M",
5291 NO_STR
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate prefix\n")
5294{
5295 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5296}
5297
5298DEFUN (no_ipv6_aggregate_address_summary_only,
5299 no_ipv6_aggregate_address_summary_only_cmd,
5300 "no aggregate-address X:X::X:X/M summary-only",
5301 NO_STR
5302 "Configure BGP aggregate entries\n"
5303 "Aggregate prefix\n"
5304 "Filter more specific routes from updates\n")
5305{
5306 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5307}
5308
5309ALIAS (ipv6_aggregate_address,
5310 old_ipv6_aggregate_address_cmd,
5311 "ipv6 bgp aggregate-address X:X::X:X/M",
5312 IPV6_STR
5313 BGP_STR
5314 "Configure BGP aggregate entries\n"
5315 "Aggregate prefix\n")
5316
5317ALIAS (ipv6_aggregate_address_summary_only,
5318 old_ipv6_aggregate_address_summary_only_cmd,
5319 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5320 IPV6_STR
5321 BGP_STR
5322 "Configure BGP aggregate entries\n"
5323 "Aggregate prefix\n"
5324 "Filter more specific routes from updates\n")
5325
5326ALIAS (no_ipv6_aggregate_address,
5327 old_no_ipv6_aggregate_address_cmd,
5328 "no ipv6 bgp aggregate-address X:X::X:X/M",
5329 NO_STR
5330 IPV6_STR
5331 BGP_STR
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate prefix\n")
5334
5335ALIAS (no_ipv6_aggregate_address_summary_only,
5336 old_no_ipv6_aggregate_address_summary_only_cmd,
5337 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5338 NO_STR
5339 IPV6_STR
5340 BGP_STR
5341 "Configure BGP aggregate entries\n"
5342 "Aggregate prefix\n"
5343 "Filter more specific routes from updates\n")
5344#endif /* HAVE_IPV6 */
5345
5346/* Redistribute route treatment. */
5347void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005348bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5349 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005350 u_int32_t metric, u_char type)
5351{
5352 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005353 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005354 struct bgp_info *new;
5355 struct bgp_info *bi;
5356 struct bgp_info info;
5357 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005358 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005359 struct attr *new_attr;
5360 afi_t afi;
5361 int ret;
5362
5363 /* Make default attribute. */
5364 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5365 if (nexthop)
5366 attr.nexthop = *nexthop;
5367
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005368#ifdef HAVE_IPV6
5369 if (nexthop6)
5370 {
5371 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5372 extra->mp_nexthop_global = *nexthop6;
5373 extra->mp_nexthop_len = 16;
5374 }
5375#endif
5376
paul718e3742002-12-13 20:15:29 +00005377 attr.med = metric;
5378 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5379
paul1eb8ef22005-04-07 07:30:20 +00005380 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005381 {
5382 afi = family2afi (p->family);
5383
5384 if (bgp->redist[afi][type])
5385 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005386 struct attr attr_new;
5387 struct attr_extra extra_new;
5388
paul718e3742002-12-13 20:15:29 +00005389 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005390 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005391 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005392
5393 if (bgp->redist_metric_flag[afi][type])
5394 attr_new.med = bgp->redist_metric[afi][type];
5395
5396 /* Apply route-map. */
5397 if (bgp->rmap[afi][type].map)
5398 {
5399 info.peer = bgp->peer_self;
5400 info.attr = &attr_new;
5401
paulfee0f4c2004-09-13 05:12:46 +00005402 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5403
paul718e3742002-12-13 20:15:29 +00005404 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5405 &info);
paulfee0f4c2004-09-13 05:12:46 +00005406
5407 bgp->peer_self->rmap_type = 0;
5408
paul718e3742002-12-13 20:15:29 +00005409 if (ret == RMAP_DENYMATCH)
5410 {
5411 /* Free uninterned attribute. */
5412 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005413
paul718e3742002-12-13 20:15:29 +00005414 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005415 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005416 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005417 bgp_redistribute_delete (p, type);
5418 return;
5419 }
5420 }
5421
Paul Jakmafb982c22007-05-04 20:15:47 +00005422 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5423 afi, SAFI_UNICAST, p, NULL);
5424
paul718e3742002-12-13 20:15:29 +00005425 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005426
paul718e3742002-12-13 20:15:29 +00005427 for (bi = bn->info; bi; bi = bi->next)
5428 if (bi->peer == bgp->peer_self
5429 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5430 break;
5431
5432 if (bi)
5433 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005434 if (attrhash_cmp (bi->attr, new_attr) &&
5435 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005436 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005437 bgp_attr_unintern (&new_attr);
5438 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005439 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005440 bgp_unlock_node (bn);
5441 return;
5442 }
5443 else
5444 {
5445 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005446 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005447
5448 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005449 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5450 bgp_info_restore(bn, bi);
5451 else
5452 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005453 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005454 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005455 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005456
5457 /* Process change. */
5458 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5459 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5460 bgp_unlock_node (bn);
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 return;
5464 }
5465 }
5466
5467 new = bgp_info_new ();
5468 new->type = type;
5469 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5470 new->peer = bgp->peer_self;
5471 SET_FLAG (new->flags, BGP_INFO_VALID);
5472 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005473 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005474
5475 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5476 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005477 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005478 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5479 }
5480 }
5481
5482 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005483 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005484 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005485}
5486
5487void
5488bgp_redistribute_delete (struct prefix *p, u_char type)
5489{
5490 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005491 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005492 afi_t afi;
5493 struct bgp_node *rn;
5494 struct bgp_info *ri;
5495
paul1eb8ef22005-04-07 07:30:20 +00005496 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005497 {
5498 afi = family2afi (p->family);
5499
5500 if (bgp->redist[afi][type])
5501 {
paulfee0f4c2004-09-13 05:12:46 +00005502 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005503
5504 for (ri = rn->info; ri; ri = ri->next)
5505 if (ri->peer == bgp->peer_self
5506 && ri->type == type)
5507 break;
5508
5509 if (ri)
5510 {
5511 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005512 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005513 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005514 }
5515 bgp_unlock_node (rn);
5516 }
5517 }
5518}
5519
5520/* Withdraw specified route type's route. */
5521void
5522bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5523{
5524 struct bgp_node *rn;
5525 struct bgp_info *ri;
5526 struct bgp_table *table;
5527
5528 table = bgp->rib[afi][SAFI_UNICAST];
5529
5530 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5531 {
5532 for (ri = rn->info; ri; ri = ri->next)
5533 if (ri->peer == bgp->peer_self
5534 && ri->type == type)
5535 break;
5536
5537 if (ri)
5538 {
5539 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005540 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005541 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005542 }
5543 }
5544}
5545
5546/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005547static void
paul718e3742002-12-13 20:15:29 +00005548route_vty_out_route (struct prefix *p, struct vty *vty)
5549{
5550 int len;
5551 u_int32_t destination;
5552 char buf[BUFSIZ];
5553
5554 if (p->family == AF_INET)
5555 {
5556 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5557 destination = ntohl (p->u.prefix4.s_addr);
5558
5559 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5560 || (IN_CLASSB (destination) && p->prefixlen == 16)
5561 || (IN_CLASSA (destination) && p->prefixlen == 8)
5562 || p->u.prefix4.s_addr == 0)
5563 {
5564 /* When mask is natural, mask is not displayed. */
5565 }
5566 else
5567 len += vty_out (vty, "/%d", p->prefixlen);
5568 }
5569 else
5570 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5571 p->prefixlen);
5572
5573 len = 17 - len;
5574 if (len < 1)
5575 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5576 else
5577 vty_out (vty, "%*s", len, " ");
5578}
5579
paul718e3742002-12-13 20:15:29 +00005580enum bgp_display_type
5581{
5582 normal_list,
5583};
5584
paulb40d9392005-08-22 22:34:41 +00005585/* Print the short form route status for a bgp_info */
5586static void
5587route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005588{
paulb40d9392005-08-22 22:34:41 +00005589 /* Route status display. */
5590 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5591 vty_out (vty, "R");
5592 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005593 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005594 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005595 vty_out (vty, "s");
5596 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5597 vty_out (vty, "*");
5598 else
5599 vty_out (vty, " ");
5600
5601 /* Selected */
5602 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5603 vty_out (vty, "h");
5604 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5605 vty_out (vty, "d");
5606 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5607 vty_out (vty, ">");
5608 else
5609 vty_out (vty, " ");
5610
5611 /* Internal route. */
5612 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5613 vty_out (vty, "i");
5614 else
paulb40d9392005-08-22 22:34:41 +00005615 vty_out (vty, " ");
5616}
5617
5618/* called from terminal list command */
5619void
5620route_vty_out (struct vty *vty, struct prefix *p,
5621 struct bgp_info *binfo, int display, safi_t safi)
5622{
5623 struct attr *attr;
5624
5625 /* short status lead text */
5626 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005627
5628 /* print prefix and mask */
5629 if (! display)
5630 route_vty_out_route (p, vty);
5631 else
5632 vty_out (vty, "%*s", 17, " ");
5633
5634 /* Print attribute */
5635 attr = binfo->attr;
5636 if (attr)
5637 {
5638 if (p->family == AF_INET)
5639 {
5640 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005641 vty_out (vty, "%-16s",
5642 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005643 else
5644 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5645 }
5646#ifdef HAVE_IPV6
5647 else if (p->family == AF_INET6)
5648 {
5649 int len;
5650 char buf[BUFSIZ];
5651
5652 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005653 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5654 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005655 len = 16 - len;
5656 if (len < 1)
5657 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5658 else
5659 vty_out (vty, "%*s", len, " ");
5660 }
5661#endif /* HAVE_IPV6 */
5662
5663 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005664 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005665 else
5666 vty_out (vty, " ");
5667
5668 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005669 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005670 else
5671 vty_out (vty, " ");
5672
Paul Jakmafb982c22007-05-04 20:15:47 +00005673 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005674
Paul Jakmab2518c12006-05-12 23:48:40 +00005675 /* Print aspath */
5676 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005677 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005678
Paul Jakmab2518c12006-05-12 23:48:40 +00005679 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005680 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005681 }
paul718e3742002-12-13 20:15:29 +00005682 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005683}
5684
5685/* called from terminal list command */
5686void
5687route_vty_out_tmp (struct vty *vty, struct prefix *p,
5688 struct attr *attr, safi_t safi)
5689{
5690 /* Route status display. */
5691 vty_out (vty, "*");
5692 vty_out (vty, ">");
5693 vty_out (vty, " ");
5694
5695 /* print prefix and mask */
5696 route_vty_out_route (p, vty);
5697
5698 /* Print attribute */
5699 if (attr)
5700 {
5701 if (p->family == AF_INET)
5702 {
5703 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005704 vty_out (vty, "%-16s",
5705 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005706 else
5707 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5708 }
5709#ifdef HAVE_IPV6
5710 else if (p->family == AF_INET6)
5711 {
5712 int len;
5713 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005714
5715 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005716
5717 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005718 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5719 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005720 len = 16 - len;
5721 if (len < 1)
5722 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5723 else
5724 vty_out (vty, "%*s", len, " ");
5725 }
5726#endif /* HAVE_IPV6 */
5727
5728 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005729 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005730 else
5731 vty_out (vty, " ");
5732
5733 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005734 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005735 else
5736 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005737
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005738 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005739
Paul Jakmab2518c12006-05-12 23:48:40 +00005740 /* Print aspath */
5741 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005742 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005743
Paul Jakmab2518c12006-05-12 23:48:40 +00005744 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005745 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005746 }
paul718e3742002-12-13 20:15:29 +00005747
5748 vty_out (vty, "%s", VTY_NEWLINE);
5749}
5750
ajs5a646652004-11-05 01:25:55 +00005751void
paul718e3742002-12-13 20:15:29 +00005752route_vty_out_tag (struct vty *vty, struct prefix *p,
5753 struct bgp_info *binfo, int display, safi_t safi)
5754{
5755 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005756 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005757
5758 if (!binfo->extra)
5759 return;
5760
paulb40d9392005-08-22 22:34:41 +00005761 /* short status lead text */
5762 route_vty_short_status_out (vty, binfo);
5763
paul718e3742002-12-13 20:15:29 +00005764 /* print prefix and mask */
5765 if (! display)
5766 route_vty_out_route (p, vty);
5767 else
5768 vty_out (vty, "%*s", 17, " ");
5769
5770 /* Print attribute */
5771 attr = binfo->attr;
5772 if (attr)
5773 {
5774 if (p->family == AF_INET)
5775 {
5776 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005777 vty_out (vty, "%-16s",
5778 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005779 else
5780 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5781 }
5782#ifdef HAVE_IPV6
5783 else if (p->family == AF_INET6)
5784 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005785 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005786 char buf[BUFSIZ];
5787 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005788 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005789 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005790 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5791 buf, BUFSIZ));
5792 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005793 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005794 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5795 buf, BUFSIZ),
5796 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5797 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005798
5799 }
5800#endif /* HAVE_IPV6 */
5801 }
5802
Paul Jakmafb982c22007-05-04 20:15:47 +00005803 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005804
5805 vty_out (vty, "notag/%d", label);
5806
5807 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005808}
5809
5810/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005811static void
paul718e3742002-12-13 20:15:29 +00005812damp_route_vty_out (struct vty *vty, struct prefix *p,
5813 struct bgp_info *binfo, int display, safi_t safi)
5814{
5815 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005816 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005817 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005818
paulb40d9392005-08-22 22:34:41 +00005819 /* short status lead text */
5820 route_vty_short_status_out (vty, binfo);
5821
paul718e3742002-12-13 20:15:29 +00005822 /* print prefix and mask */
5823 if (! display)
5824 route_vty_out_route (p, vty);
5825 else
5826 vty_out (vty, "%*s", 17, " ");
5827
5828 len = vty_out (vty, "%s", binfo->peer->host);
5829 len = 17 - len;
5830 if (len < 1)
5831 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5832 else
5833 vty_out (vty, "%*s", len, " ");
5834
Chris Caputo50aef6f2009-06-23 06:06:49 +00005835 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005836
5837 /* Print attribute */
5838 attr = binfo->attr;
5839 if (attr)
5840 {
5841 /* Print aspath */
5842 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005843 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005844
5845 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005846 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005847 }
5848 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005849}
5850
paul718e3742002-12-13 20:15:29 +00005851/* flap route */
ajs5a646652004-11-05 01:25:55 +00005852static void
paul718e3742002-12-13 20:15:29 +00005853flap_route_vty_out (struct vty *vty, struct prefix *p,
5854 struct bgp_info *binfo, int display, safi_t safi)
5855{
5856 struct attr *attr;
5857 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005858 char timebuf[BGP_UPTIME_LEN];
5859 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005860
5861 if (!binfo->extra)
5862 return;
5863
5864 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005865
paulb40d9392005-08-22 22:34:41 +00005866 /* short status lead text */
5867 route_vty_short_status_out (vty, binfo);
5868
paul718e3742002-12-13 20:15:29 +00005869 /* print prefix and mask */
5870 if (! display)
5871 route_vty_out_route (p, vty);
5872 else
5873 vty_out (vty, "%*s", 17, " ");
5874
5875 len = vty_out (vty, "%s", binfo->peer->host);
5876 len = 16 - len;
5877 if (len < 1)
5878 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5879 else
5880 vty_out (vty, "%*s", len, " ");
5881
5882 len = vty_out (vty, "%d", bdi->flap);
5883 len = 5 - len;
5884 if (len < 1)
5885 vty_out (vty, " ");
5886 else
5887 vty_out (vty, "%*s ", len, " ");
5888
5889 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5890 timebuf, BGP_UPTIME_LEN));
5891
5892 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5893 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005894 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005895 else
5896 vty_out (vty, "%*s ", 8, " ");
5897
5898 /* Print attribute */
5899 attr = binfo->attr;
5900 if (attr)
5901 {
5902 /* Print aspath */
5903 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005904 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005905
5906 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005907 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005908 }
5909 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005910}
5911
paul94f2b392005-06-28 12:44:16 +00005912static void
paul718e3742002-12-13 20:15:29 +00005913route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5914 struct bgp_info *binfo, afi_t afi, safi_t safi)
5915{
5916 char buf[INET6_ADDRSTRLEN];
5917 char buf1[BUFSIZ];
5918 struct attr *attr;
5919 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005920#ifdef HAVE_CLOCK_MONOTONIC
5921 time_t tbuf;
5922#endif
paul718e3742002-12-13 20:15:29 +00005923
5924 attr = binfo->attr;
5925
5926 if (attr)
5927 {
5928 /* Line1 display AS-path, Aggregator */
5929 if (attr->aspath)
5930 {
5931 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005932 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005933 vty_out (vty, "Local");
5934 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005935 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005936 }
5937
paulb40d9392005-08-22 22:34:41 +00005938 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5939 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005940 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5941 vty_out (vty, ", (stale)");
5942 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005943 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005944 attr->extra->aggregator_as,
5945 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005946 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5947 vty_out (vty, ", (Received from a RR-client)");
5948 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5949 vty_out (vty, ", (Received from a RS-client)");
5950 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5951 vty_out (vty, ", (history entry)");
5952 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5953 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005954 vty_out (vty, "%s", VTY_NEWLINE);
5955
5956 /* Line2 display Next-hop, Neighbor, Router-id */
5957 if (p->family == AF_INET)
5958 {
5959 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005960 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005961 inet_ntoa (attr->nexthop));
5962 }
5963#ifdef HAVE_IPV6
5964 else
5965 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005966 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005967 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005968 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005969 buf, INET6_ADDRSTRLEN));
5970 }
5971#endif /* HAVE_IPV6 */
5972
5973 if (binfo->peer == bgp->peer_self)
5974 {
5975 vty_out (vty, " from %s ",
5976 p->family == AF_INET ? "0.0.0.0" : "::");
5977 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5978 }
5979 else
5980 {
5981 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5982 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005983 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005984 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005985 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005986 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005987 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005988 else
5989 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5990 }
5991 vty_out (vty, "%s", VTY_NEWLINE);
5992
5993#ifdef HAVE_IPV6
5994 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005995 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005996 {
5997 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005999 buf, INET6_ADDRSTRLEN),
6000 VTY_NEWLINE);
6001 }
6002#endif /* HAVE_IPV6 */
6003
6004 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6005 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6006
6007 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006008 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006009
6010 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006011 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006012 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006013 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006014
Paul Jakmafb982c22007-05-04 20:15:47 +00006015 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006016 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006017
6018 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6019 vty_out (vty, ", valid");
6020
6021 if (binfo->peer != bgp->peer_self)
6022 {
6023 if (binfo->peer->as == binfo->peer->local_as)
6024 vty_out (vty, ", internal");
6025 else
6026 vty_out (vty, ", %s",
6027 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6028 }
6029 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6030 vty_out (vty, ", aggregated, local");
6031 else if (binfo->type != ZEBRA_ROUTE_BGP)
6032 vty_out (vty, ", sourced");
6033 else
6034 vty_out (vty, ", sourced, local");
6035
6036 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6037 vty_out (vty, ", atomic-aggregate");
6038
Josh Baileyde8d5df2011-07-20 20:46:01 -07006039 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6040 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6041 bgp_info_mpath_count (binfo)))
6042 vty_out (vty, ", multipath");
6043
paul718e3742002-12-13 20:15:29 +00006044 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6045 vty_out (vty, ", best");
6046
6047 vty_out (vty, "%s", VTY_NEWLINE);
6048
6049 /* Line 4 display Community */
6050 if (attr->community)
6051 vty_out (vty, " Community: %s%s", attr->community->str,
6052 VTY_NEWLINE);
6053
6054 /* Line 5 display Extended-community */
6055 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 vty_out (vty, " Extended Community: %s%s",
6057 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006058
6059 /* Line 6 display Originator, Cluster-id */
6060 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6061 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6062 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 vty_out (vty, " Originator: %s",
6066 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006067
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6069 {
6070 int i;
6071 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6073 vty_out (vty, "%s ",
6074 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006075 }
6076 vty_out (vty, "%s", VTY_NEWLINE);
6077 }
Paul Jakma41367172007-08-06 15:24:51 +00006078
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006080 bgp_damp_info_vty (vty, binfo);
6081
6082 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006083#ifdef HAVE_CLOCK_MONOTONIC
6084 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006085 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006086#else
6087 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6088#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006089 }
6090 vty_out (vty, "%s", VTY_NEWLINE);
6091}
6092
paulb40d9392005-08-22 22:34:41 +00006093#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 +00006094#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006095#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6096#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6097#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6098
6099enum bgp_show_type
6100{
6101 bgp_show_type_normal,
6102 bgp_show_type_regexp,
6103 bgp_show_type_prefix_list,
6104 bgp_show_type_filter_list,
6105 bgp_show_type_route_map,
6106 bgp_show_type_neighbor,
6107 bgp_show_type_cidr_only,
6108 bgp_show_type_prefix_longer,
6109 bgp_show_type_community_all,
6110 bgp_show_type_community,
6111 bgp_show_type_community_exact,
6112 bgp_show_type_community_list,
6113 bgp_show_type_community_list_exact,
6114 bgp_show_type_flap_statistics,
6115 bgp_show_type_flap_address,
6116 bgp_show_type_flap_prefix,
6117 bgp_show_type_flap_cidr_only,
6118 bgp_show_type_flap_regexp,
6119 bgp_show_type_flap_filter_list,
6120 bgp_show_type_flap_prefix_list,
6121 bgp_show_type_flap_prefix_longer,
6122 bgp_show_type_flap_route_map,
6123 bgp_show_type_flap_neighbor,
6124 bgp_show_type_dampend_paths,
6125 bgp_show_type_damp_neighbor
6126};
6127
ajs5a646652004-11-05 01:25:55 +00006128static int
paulfee0f4c2004-09-13 05:12:46 +00006129bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006130 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006131{
paul718e3742002-12-13 20:15:29 +00006132 struct bgp_info *ri;
6133 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006134 int header = 1;
paul718e3742002-12-13 20:15:29 +00006135 int display;
ajs5a646652004-11-05 01:25:55 +00006136 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006137
6138 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006139 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006140
paul718e3742002-12-13 20:15:29 +00006141 /* Start processing of routes. */
6142 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6143 if (rn->info != NULL)
6144 {
6145 display = 0;
6146
6147 for (ri = rn->info; ri; ri = ri->next)
6148 {
ajs5a646652004-11-05 01:25:55 +00006149 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006150 || type == bgp_show_type_flap_address
6151 || type == bgp_show_type_flap_prefix
6152 || type == bgp_show_type_flap_cidr_only
6153 || type == bgp_show_type_flap_regexp
6154 || type == bgp_show_type_flap_filter_list
6155 || type == bgp_show_type_flap_prefix_list
6156 || type == bgp_show_type_flap_prefix_longer
6157 || type == bgp_show_type_flap_route_map
6158 || type == bgp_show_type_flap_neighbor
6159 || type == bgp_show_type_dampend_paths
6160 || type == bgp_show_type_damp_neighbor)
6161 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006162 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006163 continue;
6164 }
6165 if (type == bgp_show_type_regexp
6166 || type == bgp_show_type_flap_regexp)
6167 {
ajs5a646652004-11-05 01:25:55 +00006168 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006169
6170 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6171 continue;
6172 }
6173 if (type == bgp_show_type_prefix_list
6174 || type == bgp_show_type_flap_prefix_list)
6175 {
ajs5a646652004-11-05 01:25:55 +00006176 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006177
6178 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6179 continue;
6180 }
6181 if (type == bgp_show_type_filter_list
6182 || type == bgp_show_type_flap_filter_list)
6183 {
ajs5a646652004-11-05 01:25:55 +00006184 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006185
6186 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6187 continue;
6188 }
6189 if (type == bgp_show_type_route_map
6190 || type == bgp_show_type_flap_route_map)
6191 {
ajs5a646652004-11-05 01:25:55 +00006192 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006193 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006194 struct attr dummy_attr;
6195 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006196 int ret;
6197
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006198 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006199 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006200
paul718e3742002-12-13 20:15:29 +00006201 binfo.peer = ri->peer;
6202 binfo.attr = &dummy_attr;
6203
6204 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006205 if (ret == RMAP_DENYMATCH)
6206 continue;
6207 }
6208 if (type == bgp_show_type_neighbor
6209 || type == bgp_show_type_flap_neighbor
6210 || type == bgp_show_type_damp_neighbor)
6211 {
ajs5a646652004-11-05 01:25:55 +00006212 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006213
6214 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6215 continue;
6216 }
6217 if (type == bgp_show_type_cidr_only
6218 || type == bgp_show_type_flap_cidr_only)
6219 {
6220 u_int32_t destination;
6221
6222 destination = ntohl (rn->p.u.prefix4.s_addr);
6223 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6224 continue;
6225 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6226 continue;
6227 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6228 continue;
6229 }
6230 if (type == bgp_show_type_prefix_longer
6231 || type == bgp_show_type_flap_prefix_longer)
6232 {
ajs5a646652004-11-05 01:25:55 +00006233 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006234
6235 if (! prefix_match (p, &rn->p))
6236 continue;
6237 }
6238 if (type == bgp_show_type_community_all)
6239 {
6240 if (! ri->attr->community)
6241 continue;
6242 }
6243 if (type == bgp_show_type_community)
6244 {
ajs5a646652004-11-05 01:25:55 +00006245 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006246
6247 if (! ri->attr->community ||
6248 ! community_match (ri->attr->community, com))
6249 continue;
6250 }
6251 if (type == bgp_show_type_community_exact)
6252 {
ajs5a646652004-11-05 01:25:55 +00006253 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006254
6255 if (! ri->attr->community ||
6256 ! community_cmp (ri->attr->community, com))
6257 continue;
6258 }
6259 if (type == bgp_show_type_community_list)
6260 {
ajs5a646652004-11-05 01:25:55 +00006261 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006262
6263 if (! community_list_match (ri->attr->community, list))
6264 continue;
6265 }
6266 if (type == bgp_show_type_community_list_exact)
6267 {
ajs5a646652004-11-05 01:25:55 +00006268 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006269
6270 if (! community_list_exact_match (ri->attr->community, list))
6271 continue;
6272 }
6273 if (type == bgp_show_type_flap_address
6274 || type == bgp_show_type_flap_prefix)
6275 {
ajs5a646652004-11-05 01:25:55 +00006276 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006277
6278 if (! prefix_match (&rn->p, p))
6279 continue;
6280
6281 if (type == bgp_show_type_flap_prefix)
6282 if (p->prefixlen != rn->p.prefixlen)
6283 continue;
6284 }
6285 if (type == bgp_show_type_dampend_paths
6286 || type == bgp_show_type_damp_neighbor)
6287 {
6288 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6289 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6290 continue;
6291 }
6292
6293 if (header)
6294 {
hasso93406d82005-02-02 14:40:33 +00006295 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6296 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6297 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006298 if (type == bgp_show_type_dampend_paths
6299 || type == bgp_show_type_damp_neighbor)
6300 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6301 else if (type == bgp_show_type_flap_statistics
6302 || type == bgp_show_type_flap_address
6303 || type == bgp_show_type_flap_prefix
6304 || type == bgp_show_type_flap_cidr_only
6305 || type == bgp_show_type_flap_regexp
6306 || type == bgp_show_type_flap_filter_list
6307 || type == bgp_show_type_flap_prefix_list
6308 || type == bgp_show_type_flap_prefix_longer
6309 || type == bgp_show_type_flap_route_map
6310 || type == bgp_show_type_flap_neighbor)
6311 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6312 else
6313 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006314 header = 0;
6315 }
6316
6317 if (type == bgp_show_type_dampend_paths
6318 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006319 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006320 else if (type == bgp_show_type_flap_statistics
6321 || type == bgp_show_type_flap_address
6322 || type == bgp_show_type_flap_prefix
6323 || type == bgp_show_type_flap_cidr_only
6324 || type == bgp_show_type_flap_regexp
6325 || type == bgp_show_type_flap_filter_list
6326 || type == bgp_show_type_flap_prefix_list
6327 || type == bgp_show_type_flap_prefix_longer
6328 || type == bgp_show_type_flap_route_map
6329 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006330 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006331 else
ajs5a646652004-11-05 01:25:55 +00006332 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006333 display++;
6334 }
6335 if (display)
ajs5a646652004-11-05 01:25:55 +00006336 output_count++;
paul718e3742002-12-13 20:15:29 +00006337 }
6338
6339 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006340 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006341 {
6342 if (type == bgp_show_type_normal)
6343 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6344 }
6345 else
6346 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006347 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006348
6349 return CMD_SUCCESS;
6350}
6351
ajs5a646652004-11-05 01:25:55 +00006352static int
paulfee0f4c2004-09-13 05:12:46 +00006353bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006354 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006355{
6356 struct bgp_table *table;
6357
6358 if (bgp == NULL) {
6359 bgp = bgp_get_default ();
6360 }
6361
6362 if (bgp == NULL)
6363 {
6364 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6365 return CMD_WARNING;
6366 }
6367
6368
6369 table = bgp->rib[afi][safi];
6370
ajs5a646652004-11-05 01:25:55 +00006371 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006372}
6373
paul718e3742002-12-13 20:15:29 +00006374/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006375static void
paul718e3742002-12-13 20:15:29 +00006376route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6377 struct bgp_node *rn,
6378 struct prefix_rd *prd, afi_t afi, safi_t safi)
6379{
6380 struct bgp_info *ri;
6381 struct prefix *p;
6382 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006383 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006384 char buf1[INET6_ADDRSTRLEN];
6385 char buf2[INET6_ADDRSTRLEN];
6386 int count = 0;
6387 int best = 0;
6388 int suppress = 0;
6389 int no_export = 0;
6390 int no_advertise = 0;
6391 int local_as = 0;
6392 int first = 0;
6393
6394 p = &rn->p;
6395 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6396 (safi == SAFI_MPLS_VPN ?
6397 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6398 safi == SAFI_MPLS_VPN ? ":" : "",
6399 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6400 p->prefixlen, VTY_NEWLINE);
6401
6402 for (ri = rn->info; ri; ri = ri->next)
6403 {
6404 count++;
6405 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6406 {
6407 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006408 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006409 suppress = 1;
6410 if (ri->attr->community != NULL)
6411 {
6412 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6413 no_advertise = 1;
6414 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6415 no_export = 1;
6416 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6417 local_as = 1;
6418 }
6419 }
6420 }
6421
6422 vty_out (vty, "Paths: (%d available", count);
6423 if (best)
6424 {
6425 vty_out (vty, ", best #%d", best);
6426 if (safi == SAFI_UNICAST)
6427 vty_out (vty, ", table Default-IP-Routing-Table");
6428 }
6429 else
6430 vty_out (vty, ", no best path");
6431 if (no_advertise)
6432 vty_out (vty, ", not advertised to any peer");
6433 else if (no_export)
6434 vty_out (vty, ", not advertised to EBGP peer");
6435 else if (local_as)
6436 vty_out (vty, ", not advertised outside local AS");
6437 if (suppress)
6438 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6439 vty_out (vty, ")%s", VTY_NEWLINE);
6440
6441 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006442 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006443 {
6444 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6445 {
6446 if (! first)
6447 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6448 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6449 first = 1;
6450 }
6451 }
6452 if (! first)
6453 vty_out (vty, " Not advertised to any peer");
6454 vty_out (vty, "%s", VTY_NEWLINE);
6455}
6456
6457/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006458static int
paulfee0f4c2004-09-13 05:12:46 +00006459bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006460 struct bgp_table *rib, const char *ip_str,
6461 afi_t afi, safi_t safi, struct prefix_rd *prd,
6462 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006463{
6464 int ret;
6465 int header;
6466 int display = 0;
6467 struct prefix match;
6468 struct bgp_node *rn;
6469 struct bgp_node *rm;
6470 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006471 struct bgp_table *table;
6472
paul718e3742002-12-13 20:15:29 +00006473 /* Check IP address argument. */
6474 ret = str2prefix (ip_str, &match);
6475 if (! ret)
6476 {
6477 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6478 return CMD_WARNING;
6479 }
6480
6481 match.family = afi2family (afi);
6482
6483 if (safi == SAFI_MPLS_VPN)
6484 {
paulfee0f4c2004-09-13 05:12:46 +00006485 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006486 {
6487 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6488 continue;
6489
6490 if ((table = rn->info) != NULL)
6491 {
6492 header = 1;
6493
6494 if ((rm = bgp_node_match (table, &match)) != NULL)
6495 {
6496 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006497 {
6498 bgp_unlock_node (rm);
6499 continue;
6500 }
paul718e3742002-12-13 20:15:29 +00006501
6502 for (ri = rm->info; ri; ri = ri->next)
6503 {
6504 if (header)
6505 {
6506 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6507 AFI_IP, SAFI_MPLS_VPN);
6508
6509 header = 0;
6510 }
6511 display++;
6512 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6513 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006514
6515 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006516 }
6517 }
6518 }
6519 }
6520 else
6521 {
6522 header = 1;
6523
paulfee0f4c2004-09-13 05:12:46 +00006524 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006525 {
6526 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6527 {
6528 for (ri = rn->info; ri; ri = ri->next)
6529 {
6530 if (header)
6531 {
6532 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6533 header = 0;
6534 }
6535 display++;
6536 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6537 }
6538 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006539
6540 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006541 }
6542 }
6543
6544 if (! display)
6545 {
6546 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6547 return CMD_WARNING;
6548 }
6549
6550 return CMD_SUCCESS;
6551}
6552
paulfee0f4c2004-09-13 05:12:46 +00006553/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006554static int
paulfd79ac92004-10-13 05:06:08 +00006555bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006556 afi_t afi, safi_t safi, struct prefix_rd *prd,
6557 int prefix_check)
6558{
6559 struct bgp *bgp;
6560
6561 /* BGP structure lookup. */
6562 if (view_name)
6563 {
6564 bgp = bgp_lookup_by_name (view_name);
6565 if (bgp == NULL)
6566 {
6567 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6568 return CMD_WARNING;
6569 }
6570 }
6571 else
6572 {
6573 bgp = bgp_get_default ();
6574 if (bgp == NULL)
6575 {
6576 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6577 return CMD_WARNING;
6578 }
6579 }
6580
6581 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6582 afi, safi, prd, prefix_check);
6583}
6584
paul718e3742002-12-13 20:15:29 +00006585/* BGP route print out function. */
6586DEFUN (show_ip_bgp,
6587 show_ip_bgp_cmd,
6588 "show ip bgp",
6589 SHOW_STR
6590 IP_STR
6591 BGP_STR)
6592{
ajs5a646652004-11-05 01:25:55 +00006593 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006594}
6595
6596DEFUN (show_ip_bgp_ipv4,
6597 show_ip_bgp_ipv4_cmd,
6598 "show ip bgp ipv4 (unicast|multicast)",
6599 SHOW_STR
6600 IP_STR
6601 BGP_STR
6602 "Address family\n"
6603 "Address Family modifier\n"
6604 "Address Family modifier\n")
6605{
6606 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006607 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6608 NULL);
paul718e3742002-12-13 20:15:29 +00006609
ajs5a646652004-11-05 01:25:55 +00006610 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006611}
6612
Michael Lambert95cbbd22010-07-23 14:43:04 -04006613ALIAS (show_ip_bgp_ipv4,
6614 show_bgp_ipv4_safi_cmd,
6615 "show bgp ipv4 (unicast|multicast)",
6616 SHOW_STR
6617 BGP_STR
6618 "Address family\n"
6619 "Address Family modifier\n"
6620 "Address Family modifier\n")
6621
paul718e3742002-12-13 20:15:29 +00006622DEFUN (show_ip_bgp_route,
6623 show_ip_bgp_route_cmd,
6624 "show ip bgp A.B.C.D",
6625 SHOW_STR
6626 IP_STR
6627 BGP_STR
6628 "Network in the BGP routing table to display\n")
6629{
6630 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6631}
6632
6633DEFUN (show_ip_bgp_ipv4_route,
6634 show_ip_bgp_ipv4_route_cmd,
6635 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6636 SHOW_STR
6637 IP_STR
6638 BGP_STR
6639 "Address family\n"
6640 "Address Family modifier\n"
6641 "Address Family modifier\n"
6642 "Network in the BGP routing table to display\n")
6643{
6644 if (strncmp (argv[0], "m", 1) == 0)
6645 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6646
6647 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6648}
6649
Michael Lambert95cbbd22010-07-23 14:43:04 -04006650ALIAS (show_ip_bgp_ipv4_route,
6651 show_bgp_ipv4_safi_route_cmd,
6652 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6653 SHOW_STR
6654 BGP_STR
6655 "Address family\n"
6656 "Address Family modifier\n"
6657 "Address Family modifier\n"
6658 "Network in the BGP routing table to display\n")
6659
paul718e3742002-12-13 20:15:29 +00006660DEFUN (show_ip_bgp_vpnv4_all_route,
6661 show_ip_bgp_vpnv4_all_route_cmd,
6662 "show ip bgp vpnv4 all A.B.C.D",
6663 SHOW_STR
6664 IP_STR
6665 BGP_STR
6666 "Display VPNv4 NLRI specific information\n"
6667 "Display information about all VPNv4 NLRIs\n"
6668 "Network in the BGP routing table to display\n")
6669{
6670 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6671}
6672
6673DEFUN (show_ip_bgp_vpnv4_rd_route,
6674 show_ip_bgp_vpnv4_rd_route_cmd,
6675 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6676 SHOW_STR
6677 IP_STR
6678 BGP_STR
6679 "Display VPNv4 NLRI specific information\n"
6680 "Display information for a route distinguisher\n"
6681 "VPN Route Distinguisher\n"
6682 "Network in the BGP routing table to display\n")
6683{
6684 int ret;
6685 struct prefix_rd prd;
6686
6687 ret = str2prefix_rd (argv[0], &prd);
6688 if (! ret)
6689 {
6690 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6691 return CMD_WARNING;
6692 }
6693 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6694}
6695
6696DEFUN (show_ip_bgp_prefix,
6697 show_ip_bgp_prefix_cmd,
6698 "show ip bgp A.B.C.D/M",
6699 SHOW_STR
6700 IP_STR
6701 BGP_STR
6702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6703{
6704 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6705}
6706
6707DEFUN (show_ip_bgp_ipv4_prefix,
6708 show_ip_bgp_ipv4_prefix_cmd,
6709 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6710 SHOW_STR
6711 IP_STR
6712 BGP_STR
6713 "Address family\n"
6714 "Address Family modifier\n"
6715 "Address Family modifier\n"
6716 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6717{
6718 if (strncmp (argv[0], "m", 1) == 0)
6719 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6720
6721 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6722}
6723
Michael Lambert95cbbd22010-07-23 14:43:04 -04006724ALIAS (show_ip_bgp_ipv4_prefix,
6725 show_bgp_ipv4_safi_prefix_cmd,
6726 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6727 SHOW_STR
6728 BGP_STR
6729 "Address family\n"
6730 "Address Family modifier\n"
6731 "Address Family modifier\n"
6732 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6733
paul718e3742002-12-13 20:15:29 +00006734DEFUN (show_ip_bgp_vpnv4_all_prefix,
6735 show_ip_bgp_vpnv4_all_prefix_cmd,
6736 "show ip bgp vpnv4 all A.B.C.D/M",
6737 SHOW_STR
6738 IP_STR
6739 BGP_STR
6740 "Display VPNv4 NLRI specific information\n"
6741 "Display information about all VPNv4 NLRIs\n"
6742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6743{
6744 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6745}
6746
6747DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6748 show_ip_bgp_vpnv4_rd_prefix_cmd,
6749 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6750 SHOW_STR
6751 IP_STR
6752 BGP_STR
6753 "Display VPNv4 NLRI specific information\n"
6754 "Display information for a route distinguisher\n"
6755 "VPN Route Distinguisher\n"
6756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6757{
6758 int ret;
6759 struct prefix_rd prd;
6760
6761 ret = str2prefix_rd (argv[0], &prd);
6762 if (! ret)
6763 {
6764 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6765 return CMD_WARNING;
6766 }
6767 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6768}
6769
6770DEFUN (show_ip_bgp_view,
6771 show_ip_bgp_view_cmd,
6772 "show ip bgp view WORD",
6773 SHOW_STR
6774 IP_STR
6775 BGP_STR
6776 "BGP view\n"
6777 "BGP view name\n")
6778{
paulbb46e942003-10-24 19:02:03 +00006779 struct bgp *bgp;
6780
6781 /* BGP structure lookup. */
6782 bgp = bgp_lookup_by_name (argv[0]);
6783 if (bgp == NULL)
6784 {
6785 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6786 return CMD_WARNING;
6787 }
6788
ajs5a646652004-11-05 01:25:55 +00006789 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006790}
6791
6792DEFUN (show_ip_bgp_view_route,
6793 show_ip_bgp_view_route_cmd,
6794 "show ip bgp view WORD A.B.C.D",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "BGP view\n"
6799 "BGP view name\n"
6800 "Network in the BGP routing table to display\n")
6801{
6802 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6803}
6804
6805DEFUN (show_ip_bgp_view_prefix,
6806 show_ip_bgp_view_prefix_cmd,
6807 "show ip bgp view WORD A.B.C.D/M",
6808 SHOW_STR
6809 IP_STR
6810 BGP_STR
6811 "BGP view\n"
6812 "BGP view name\n"
6813 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6814{
6815 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6816}
6817
6818#ifdef HAVE_IPV6
6819DEFUN (show_bgp,
6820 show_bgp_cmd,
6821 "show bgp",
6822 SHOW_STR
6823 BGP_STR)
6824{
ajs5a646652004-11-05 01:25:55 +00006825 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6826 NULL);
paul718e3742002-12-13 20:15:29 +00006827}
6828
6829ALIAS (show_bgp,
6830 show_bgp_ipv6_cmd,
6831 "show bgp ipv6",
6832 SHOW_STR
6833 BGP_STR
6834 "Address family\n")
6835
Michael Lambert95cbbd22010-07-23 14:43:04 -04006836DEFUN (show_bgp_ipv6_safi,
6837 show_bgp_ipv6_safi_cmd,
6838 "show bgp ipv6 (unicast|multicast)",
6839 SHOW_STR
6840 BGP_STR
6841 "Address family\n"
6842 "Address Family modifier\n"
6843 "Address Family modifier\n")
6844{
6845 if (strncmp (argv[0], "m", 1) == 0)
6846 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6847 NULL);
6848
6849 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6850}
6851
paul718e3742002-12-13 20:15:29 +00006852/* old command */
6853DEFUN (show_ipv6_bgp,
6854 show_ipv6_bgp_cmd,
6855 "show ipv6 bgp",
6856 SHOW_STR
6857 IP_STR
6858 BGP_STR)
6859{
ajs5a646652004-11-05 01:25:55 +00006860 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6861 NULL);
paul718e3742002-12-13 20:15:29 +00006862}
6863
6864DEFUN (show_bgp_route,
6865 show_bgp_route_cmd,
6866 "show bgp X:X::X:X",
6867 SHOW_STR
6868 BGP_STR
6869 "Network in the BGP routing table to display\n")
6870{
6871 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6872}
6873
6874ALIAS (show_bgp_route,
6875 show_bgp_ipv6_route_cmd,
6876 "show bgp ipv6 X:X::X:X",
6877 SHOW_STR
6878 BGP_STR
6879 "Address family\n"
6880 "Network in the BGP routing table to display\n")
6881
Michael Lambert95cbbd22010-07-23 14:43:04 -04006882DEFUN (show_bgp_ipv6_safi_route,
6883 show_bgp_ipv6_safi_route_cmd,
6884 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6885 SHOW_STR
6886 BGP_STR
6887 "Address family\n"
6888 "Address Family modifier\n"
6889 "Address Family modifier\n"
6890 "Network in the BGP routing table to display\n")
6891{
6892 if (strncmp (argv[0], "m", 1) == 0)
6893 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6894
6895 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6896}
6897
paul718e3742002-12-13 20:15:29 +00006898/* old command */
6899DEFUN (show_ipv6_bgp_route,
6900 show_ipv6_bgp_route_cmd,
6901 "show ipv6 bgp X:X::X:X",
6902 SHOW_STR
6903 IP_STR
6904 BGP_STR
6905 "Network in the BGP routing table to display\n")
6906{
6907 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6908}
6909
6910DEFUN (show_bgp_prefix,
6911 show_bgp_prefix_cmd,
6912 "show bgp X:X::X:X/M",
6913 SHOW_STR
6914 BGP_STR
6915 "IPv6 prefix <network>/<length>\n")
6916{
6917 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6918}
6919
6920ALIAS (show_bgp_prefix,
6921 show_bgp_ipv6_prefix_cmd,
6922 "show bgp ipv6 X:X::X:X/M",
6923 SHOW_STR
6924 BGP_STR
6925 "Address family\n"
6926 "IPv6 prefix <network>/<length>\n")
6927
Michael Lambert95cbbd22010-07-23 14:43:04 -04006928DEFUN (show_bgp_ipv6_safi_prefix,
6929 show_bgp_ipv6_safi_prefix_cmd,
6930 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6931 SHOW_STR
6932 BGP_STR
6933 "Address family\n"
6934 "Address Family modifier\n"
6935 "Address Family modifier\n"
6936 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6937{
6938 if (strncmp (argv[0], "m", 1) == 0)
6939 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6940
6941 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6942}
6943
paul718e3742002-12-13 20:15:29 +00006944/* old command */
6945DEFUN (show_ipv6_bgp_prefix,
6946 show_ipv6_bgp_prefix_cmd,
6947 "show ipv6 bgp X:X::X:X/M",
6948 SHOW_STR
6949 IP_STR
6950 BGP_STR
6951 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6952{
6953 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6954}
6955
paulbb46e942003-10-24 19:02:03 +00006956DEFUN (show_bgp_view,
6957 show_bgp_view_cmd,
6958 "show bgp view WORD",
6959 SHOW_STR
6960 BGP_STR
6961 "BGP view\n"
6962 "View name\n")
6963{
6964 struct bgp *bgp;
6965
6966 /* BGP structure lookup. */
6967 bgp = bgp_lookup_by_name (argv[0]);
6968 if (bgp == NULL)
6969 {
6970 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6971 return CMD_WARNING;
6972 }
6973
ajs5a646652004-11-05 01:25:55 +00006974 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006975}
6976
6977ALIAS (show_bgp_view,
6978 show_bgp_view_ipv6_cmd,
6979 "show bgp view WORD ipv6",
6980 SHOW_STR
6981 BGP_STR
6982 "BGP view\n"
6983 "View name\n"
6984 "Address family\n")
6985
6986DEFUN (show_bgp_view_route,
6987 show_bgp_view_route_cmd,
6988 "show bgp view WORD X:X::X:X",
6989 SHOW_STR
6990 BGP_STR
6991 "BGP view\n"
6992 "View name\n"
6993 "Network in the BGP routing table to display\n")
6994{
6995 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6996}
6997
6998ALIAS (show_bgp_view_route,
6999 show_bgp_view_ipv6_route_cmd,
7000 "show bgp view WORD ipv6 X:X::X:X",
7001 SHOW_STR
7002 BGP_STR
7003 "BGP view\n"
7004 "View name\n"
7005 "Address family\n"
7006 "Network in the BGP routing table to display\n")
7007
7008DEFUN (show_bgp_view_prefix,
7009 show_bgp_view_prefix_cmd,
7010 "show bgp view WORD X:X::X:X/M",
7011 SHOW_STR
7012 BGP_STR
7013 "BGP view\n"
7014 "View name\n"
7015 "IPv6 prefix <network>/<length>\n")
7016{
7017 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7018}
7019
7020ALIAS (show_bgp_view_prefix,
7021 show_bgp_view_ipv6_prefix_cmd,
7022 "show bgp view WORD ipv6 X:X::X:X/M",
7023 SHOW_STR
7024 BGP_STR
7025 "BGP view\n"
7026 "View name\n"
7027 "Address family\n"
7028 "IPv6 prefix <network>/<length>\n")
7029
paul718e3742002-12-13 20:15:29 +00007030/* old command */
7031DEFUN (show_ipv6_mbgp,
7032 show_ipv6_mbgp_cmd,
7033 "show ipv6 mbgp",
7034 SHOW_STR
7035 IP_STR
7036 MBGP_STR)
7037{
ajs5a646652004-11-05 01:25:55 +00007038 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7039 NULL);
paul718e3742002-12-13 20:15:29 +00007040}
7041
7042/* old command */
7043DEFUN (show_ipv6_mbgp_route,
7044 show_ipv6_mbgp_route_cmd,
7045 "show ipv6 mbgp X:X::X:X",
7046 SHOW_STR
7047 IP_STR
7048 MBGP_STR
7049 "Network in the MBGP routing table to display\n")
7050{
7051 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7052}
7053
7054/* old command */
7055DEFUN (show_ipv6_mbgp_prefix,
7056 show_ipv6_mbgp_prefix_cmd,
7057 "show ipv6 mbgp X:X::X:X/M",
7058 SHOW_STR
7059 IP_STR
7060 MBGP_STR
7061 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7062{
7063 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7064}
7065#endif
7066
paul718e3742002-12-13 20:15:29 +00007067
paul94f2b392005-06-28 12:44:16 +00007068static int
paulfd79ac92004-10-13 05:06:08 +00007069bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007070 safi_t safi, enum bgp_show_type type)
7071{
7072 int i;
7073 struct buffer *b;
7074 char *regstr;
7075 int first;
7076 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007077 int rc;
paul718e3742002-12-13 20:15:29 +00007078
7079 first = 0;
7080 b = buffer_new (1024);
7081 for (i = 0; i < argc; i++)
7082 {
7083 if (first)
7084 buffer_putc (b, ' ');
7085 else
7086 {
7087 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7088 continue;
7089 first = 1;
7090 }
7091
7092 buffer_putstr (b, argv[i]);
7093 }
7094 buffer_putc (b, '\0');
7095
7096 regstr = buffer_getstr (b);
7097 buffer_free (b);
7098
7099 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007100 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007101 if (! regex)
7102 {
7103 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7104 VTY_NEWLINE);
7105 return CMD_WARNING;
7106 }
7107
ajs5a646652004-11-05 01:25:55 +00007108 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7109 bgp_regex_free (regex);
7110 return rc;
paul718e3742002-12-13 20:15:29 +00007111}
7112
7113DEFUN (show_ip_bgp_regexp,
7114 show_ip_bgp_regexp_cmd,
7115 "show ip bgp regexp .LINE",
7116 SHOW_STR
7117 IP_STR
7118 BGP_STR
7119 "Display routes matching the AS path regular expression\n"
7120 "A regular-expression to match the BGP AS paths\n")
7121{
7122 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7123 bgp_show_type_regexp);
7124}
7125
7126DEFUN (show_ip_bgp_flap_regexp,
7127 show_ip_bgp_flap_regexp_cmd,
7128 "show ip bgp flap-statistics regexp .LINE",
7129 SHOW_STR
7130 IP_STR
7131 BGP_STR
7132 "Display flap statistics of routes\n"
7133 "Display routes matching the AS path regular expression\n"
7134 "A regular-expression to match the BGP AS paths\n")
7135{
7136 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7137 bgp_show_type_flap_regexp);
7138}
7139
7140DEFUN (show_ip_bgp_ipv4_regexp,
7141 show_ip_bgp_ipv4_regexp_cmd,
7142 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7143 SHOW_STR
7144 IP_STR
7145 BGP_STR
7146 "Address family\n"
7147 "Address Family modifier\n"
7148 "Address Family modifier\n"
7149 "Display routes matching the AS path regular expression\n"
7150 "A regular-expression to match the BGP AS paths\n")
7151{
7152 if (strncmp (argv[0], "m", 1) == 0)
7153 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7154 bgp_show_type_regexp);
7155
7156 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7157 bgp_show_type_regexp);
7158}
7159
7160#ifdef HAVE_IPV6
7161DEFUN (show_bgp_regexp,
7162 show_bgp_regexp_cmd,
7163 "show bgp regexp .LINE",
7164 SHOW_STR
7165 BGP_STR
7166 "Display routes matching the AS path regular expression\n"
7167 "A regular-expression to match the BGP AS paths\n")
7168{
7169 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7170 bgp_show_type_regexp);
7171}
7172
7173ALIAS (show_bgp_regexp,
7174 show_bgp_ipv6_regexp_cmd,
7175 "show bgp ipv6 regexp .LINE",
7176 SHOW_STR
7177 BGP_STR
7178 "Address family\n"
7179 "Display routes matching the AS path regular expression\n"
7180 "A regular-expression to match the BGP AS paths\n")
7181
7182/* old command */
7183DEFUN (show_ipv6_bgp_regexp,
7184 show_ipv6_bgp_regexp_cmd,
7185 "show ipv6 bgp regexp .LINE",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "Display routes matching the AS path regular expression\n"
7190 "A regular-expression to match the BGP AS paths\n")
7191{
7192 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7193 bgp_show_type_regexp);
7194}
7195
7196/* old command */
7197DEFUN (show_ipv6_mbgp_regexp,
7198 show_ipv6_mbgp_regexp_cmd,
7199 "show ipv6 mbgp regexp .LINE",
7200 SHOW_STR
7201 IP_STR
7202 BGP_STR
7203 "Display routes matching the AS path regular expression\n"
7204 "A regular-expression to match the MBGP AS paths\n")
7205{
7206 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7207 bgp_show_type_regexp);
7208}
7209#endif /* HAVE_IPV6 */
7210
paul94f2b392005-06-28 12:44:16 +00007211static int
paulfd79ac92004-10-13 05:06:08 +00007212bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007213 safi_t safi, enum bgp_show_type type)
7214{
7215 struct prefix_list *plist;
7216
7217 plist = prefix_list_lookup (afi, prefix_list_str);
7218 if (plist == NULL)
7219 {
7220 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7221 prefix_list_str, VTY_NEWLINE);
7222 return CMD_WARNING;
7223 }
7224
ajs5a646652004-11-05 01:25:55 +00007225 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007226}
7227
7228DEFUN (show_ip_bgp_prefix_list,
7229 show_ip_bgp_prefix_list_cmd,
7230 "show ip bgp prefix-list WORD",
7231 SHOW_STR
7232 IP_STR
7233 BGP_STR
7234 "Display routes conforming to the prefix-list\n"
7235 "IP prefix-list name\n")
7236{
7237 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7238 bgp_show_type_prefix_list);
7239}
7240
7241DEFUN (show_ip_bgp_flap_prefix_list,
7242 show_ip_bgp_flap_prefix_list_cmd,
7243 "show ip bgp flap-statistics prefix-list WORD",
7244 SHOW_STR
7245 IP_STR
7246 BGP_STR
7247 "Display flap statistics of routes\n"
7248 "Display routes conforming to the prefix-list\n"
7249 "IP prefix-list name\n")
7250{
7251 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7252 bgp_show_type_flap_prefix_list);
7253}
7254
7255DEFUN (show_ip_bgp_ipv4_prefix_list,
7256 show_ip_bgp_ipv4_prefix_list_cmd,
7257 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7258 SHOW_STR
7259 IP_STR
7260 BGP_STR
7261 "Address family\n"
7262 "Address Family modifier\n"
7263 "Address Family modifier\n"
7264 "Display routes conforming to the prefix-list\n"
7265 "IP prefix-list name\n")
7266{
7267 if (strncmp (argv[0], "m", 1) == 0)
7268 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7269 bgp_show_type_prefix_list);
7270
7271 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7272 bgp_show_type_prefix_list);
7273}
7274
7275#ifdef HAVE_IPV6
7276DEFUN (show_bgp_prefix_list,
7277 show_bgp_prefix_list_cmd,
7278 "show bgp prefix-list WORD",
7279 SHOW_STR
7280 BGP_STR
7281 "Display routes conforming to the prefix-list\n"
7282 "IPv6 prefix-list name\n")
7283{
7284 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7285 bgp_show_type_prefix_list);
7286}
7287
7288ALIAS (show_bgp_prefix_list,
7289 show_bgp_ipv6_prefix_list_cmd,
7290 "show bgp ipv6 prefix-list WORD",
7291 SHOW_STR
7292 BGP_STR
7293 "Address family\n"
7294 "Display routes conforming to the prefix-list\n"
7295 "IPv6 prefix-list name\n")
7296
7297/* old command */
7298DEFUN (show_ipv6_bgp_prefix_list,
7299 show_ipv6_bgp_prefix_list_cmd,
7300 "show ipv6 bgp prefix-list WORD",
7301 SHOW_STR
7302 IPV6_STR
7303 BGP_STR
7304 "Display routes matching the prefix-list\n"
7305 "IPv6 prefix-list name\n")
7306{
7307 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7308 bgp_show_type_prefix_list);
7309}
7310
7311/* old command */
7312DEFUN (show_ipv6_mbgp_prefix_list,
7313 show_ipv6_mbgp_prefix_list_cmd,
7314 "show ipv6 mbgp prefix-list WORD",
7315 SHOW_STR
7316 IPV6_STR
7317 MBGP_STR
7318 "Display routes matching the prefix-list\n"
7319 "IPv6 prefix-list name\n")
7320{
7321 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7322 bgp_show_type_prefix_list);
7323}
7324#endif /* HAVE_IPV6 */
7325
paul94f2b392005-06-28 12:44:16 +00007326static int
paulfd79ac92004-10-13 05:06:08 +00007327bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007328 safi_t safi, enum bgp_show_type type)
7329{
7330 struct as_list *as_list;
7331
7332 as_list = as_list_lookup (filter);
7333 if (as_list == NULL)
7334 {
7335 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7336 return CMD_WARNING;
7337 }
7338
ajs5a646652004-11-05 01:25:55 +00007339 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007340}
7341
7342DEFUN (show_ip_bgp_filter_list,
7343 show_ip_bgp_filter_list_cmd,
7344 "show ip bgp filter-list WORD",
7345 SHOW_STR
7346 IP_STR
7347 BGP_STR
7348 "Display routes conforming to the filter-list\n"
7349 "Regular expression access list name\n")
7350{
7351 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7352 bgp_show_type_filter_list);
7353}
7354
7355DEFUN (show_ip_bgp_flap_filter_list,
7356 show_ip_bgp_flap_filter_list_cmd,
7357 "show ip bgp flap-statistics filter-list WORD",
7358 SHOW_STR
7359 IP_STR
7360 BGP_STR
7361 "Display flap statistics of routes\n"
7362 "Display routes conforming to the filter-list\n"
7363 "Regular expression access list name\n")
7364{
7365 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7366 bgp_show_type_flap_filter_list);
7367}
7368
7369DEFUN (show_ip_bgp_ipv4_filter_list,
7370 show_ip_bgp_ipv4_filter_list_cmd,
7371 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7372 SHOW_STR
7373 IP_STR
7374 BGP_STR
7375 "Address family\n"
7376 "Address Family modifier\n"
7377 "Address Family modifier\n"
7378 "Display routes conforming to the filter-list\n"
7379 "Regular expression access list name\n")
7380{
7381 if (strncmp (argv[0], "m", 1) == 0)
7382 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7383 bgp_show_type_filter_list);
7384
7385 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7386 bgp_show_type_filter_list);
7387}
7388
7389#ifdef HAVE_IPV6
7390DEFUN (show_bgp_filter_list,
7391 show_bgp_filter_list_cmd,
7392 "show bgp filter-list WORD",
7393 SHOW_STR
7394 BGP_STR
7395 "Display routes conforming to the filter-list\n"
7396 "Regular expression access list name\n")
7397{
7398 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7399 bgp_show_type_filter_list);
7400}
7401
7402ALIAS (show_bgp_filter_list,
7403 show_bgp_ipv6_filter_list_cmd,
7404 "show bgp ipv6 filter-list WORD",
7405 SHOW_STR
7406 BGP_STR
7407 "Address family\n"
7408 "Display routes conforming to the filter-list\n"
7409 "Regular expression access list name\n")
7410
7411/* old command */
7412DEFUN (show_ipv6_bgp_filter_list,
7413 show_ipv6_bgp_filter_list_cmd,
7414 "show ipv6 bgp filter-list WORD",
7415 SHOW_STR
7416 IPV6_STR
7417 BGP_STR
7418 "Display routes conforming to the filter-list\n"
7419 "Regular expression access list name\n")
7420{
7421 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7422 bgp_show_type_filter_list);
7423}
7424
7425/* old command */
7426DEFUN (show_ipv6_mbgp_filter_list,
7427 show_ipv6_mbgp_filter_list_cmd,
7428 "show ipv6 mbgp filter-list WORD",
7429 SHOW_STR
7430 IPV6_STR
7431 MBGP_STR
7432 "Display routes conforming to the filter-list\n"
7433 "Regular expression access list name\n")
7434{
7435 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7436 bgp_show_type_filter_list);
7437}
7438#endif /* HAVE_IPV6 */
7439
paul94f2b392005-06-28 12:44:16 +00007440static int
paulfd79ac92004-10-13 05:06:08 +00007441bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007442 safi_t safi, enum bgp_show_type type)
7443{
7444 struct route_map *rmap;
7445
7446 rmap = route_map_lookup_by_name (rmap_str);
7447 if (! rmap)
7448 {
7449 vty_out (vty, "%% %s is not a valid route-map name%s",
7450 rmap_str, VTY_NEWLINE);
7451 return CMD_WARNING;
7452 }
7453
ajs5a646652004-11-05 01:25:55 +00007454 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007455}
7456
7457DEFUN (show_ip_bgp_route_map,
7458 show_ip_bgp_route_map_cmd,
7459 "show ip bgp route-map WORD",
7460 SHOW_STR
7461 IP_STR
7462 BGP_STR
7463 "Display routes matching the route-map\n"
7464 "A route-map to match on\n")
7465{
7466 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7467 bgp_show_type_route_map);
7468}
7469
7470DEFUN (show_ip_bgp_flap_route_map,
7471 show_ip_bgp_flap_route_map_cmd,
7472 "show ip bgp flap-statistics route-map WORD",
7473 SHOW_STR
7474 IP_STR
7475 BGP_STR
7476 "Display flap statistics of routes\n"
7477 "Display routes matching the route-map\n"
7478 "A route-map to match on\n")
7479{
7480 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7481 bgp_show_type_flap_route_map);
7482}
7483
7484DEFUN (show_ip_bgp_ipv4_route_map,
7485 show_ip_bgp_ipv4_route_map_cmd,
7486 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7487 SHOW_STR
7488 IP_STR
7489 BGP_STR
7490 "Address family\n"
7491 "Address Family modifier\n"
7492 "Address Family modifier\n"
7493 "Display routes matching the route-map\n"
7494 "A route-map to match on\n")
7495{
7496 if (strncmp (argv[0], "m", 1) == 0)
7497 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7498 bgp_show_type_route_map);
7499
7500 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7501 bgp_show_type_route_map);
7502}
7503
7504DEFUN (show_bgp_route_map,
7505 show_bgp_route_map_cmd,
7506 "show bgp route-map WORD",
7507 SHOW_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_IP6, SAFI_UNICAST,
7513 bgp_show_type_route_map);
7514}
7515
7516ALIAS (show_bgp_route_map,
7517 show_bgp_ipv6_route_map_cmd,
7518 "show bgp ipv6 route-map WORD",
7519 SHOW_STR
7520 BGP_STR
7521 "Address family\n"
7522 "Display routes matching the route-map\n"
7523 "A route-map to match on\n")
7524
7525DEFUN (show_ip_bgp_cidr_only,
7526 show_ip_bgp_cidr_only_cmd,
7527 "show ip bgp cidr-only",
7528 SHOW_STR
7529 IP_STR
7530 BGP_STR
7531 "Display only routes with non-natural netmasks\n")
7532{
7533 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007534 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007535}
7536
7537DEFUN (show_ip_bgp_flap_cidr_only,
7538 show_ip_bgp_flap_cidr_only_cmd,
7539 "show ip bgp flap-statistics cidr-only",
7540 SHOW_STR
7541 IP_STR
7542 BGP_STR
7543 "Display flap statistics of routes\n"
7544 "Display only routes with non-natural netmasks\n")
7545{
7546 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007547 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007548}
7549
7550DEFUN (show_ip_bgp_ipv4_cidr_only,
7551 show_ip_bgp_ipv4_cidr_only_cmd,
7552 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7553 SHOW_STR
7554 IP_STR
7555 BGP_STR
7556 "Address family\n"
7557 "Address Family modifier\n"
7558 "Address Family modifier\n"
7559 "Display only routes with non-natural netmasks\n")
7560{
7561 if (strncmp (argv[0], "m", 1) == 0)
7562 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007563 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007564
7565 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007566 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007567}
7568
7569DEFUN (show_ip_bgp_community_all,
7570 show_ip_bgp_community_all_cmd,
7571 "show ip bgp community",
7572 SHOW_STR
7573 IP_STR
7574 BGP_STR
7575 "Display routes matching the communities\n")
7576{
7577 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007578 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007579}
7580
7581DEFUN (show_ip_bgp_ipv4_community_all,
7582 show_ip_bgp_ipv4_community_all_cmd,
7583 "show ip bgp ipv4 (unicast|multicast) community",
7584 SHOW_STR
7585 IP_STR
7586 BGP_STR
7587 "Address family\n"
7588 "Address Family modifier\n"
7589 "Address Family modifier\n"
7590 "Display routes matching the communities\n")
7591{
7592 if (strncmp (argv[0], "m", 1) == 0)
7593 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007594 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007595
7596 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007597 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007598}
7599
7600#ifdef HAVE_IPV6
7601DEFUN (show_bgp_community_all,
7602 show_bgp_community_all_cmd,
7603 "show bgp community",
7604 SHOW_STR
7605 BGP_STR
7606 "Display routes matching the communities\n")
7607{
7608 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007609 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007610}
7611
7612ALIAS (show_bgp_community_all,
7613 show_bgp_ipv6_community_all_cmd,
7614 "show bgp ipv6 community",
7615 SHOW_STR
7616 BGP_STR
7617 "Address family\n"
7618 "Display routes matching the communities\n")
7619
7620/* old command */
7621DEFUN (show_ipv6_bgp_community_all,
7622 show_ipv6_bgp_community_all_cmd,
7623 "show ipv6 bgp community",
7624 SHOW_STR
7625 IPV6_STR
7626 BGP_STR
7627 "Display routes matching the communities\n")
7628{
7629 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007630 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007631}
7632
7633/* old command */
7634DEFUN (show_ipv6_mbgp_community_all,
7635 show_ipv6_mbgp_community_all_cmd,
7636 "show ipv6 mbgp community",
7637 SHOW_STR
7638 IPV6_STR
7639 MBGP_STR
7640 "Display routes matching the communities\n")
7641{
7642 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007643 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007644}
7645#endif /* HAVE_IPV6 */
7646
paul94f2b392005-06-28 12:44:16 +00007647static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007648bgp_show_community (struct vty *vty, const char *view_name, int argc,
7649 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007650{
7651 struct community *com;
7652 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007653 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007654 int i;
7655 char *str;
7656 int first = 0;
7657
Michael Lambert95cbbd22010-07-23 14:43:04 -04007658 /* BGP structure lookup */
7659 if (view_name)
7660 {
7661 bgp = bgp_lookup_by_name (view_name);
7662 if (bgp == NULL)
7663 {
7664 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7665 return CMD_WARNING;
7666 }
7667 }
7668 else
7669 {
7670 bgp = bgp_get_default ();
7671 if (bgp == NULL)
7672 {
7673 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7674 return CMD_WARNING;
7675 }
7676 }
7677
paul718e3742002-12-13 20:15:29 +00007678 b = buffer_new (1024);
7679 for (i = 0; i < argc; i++)
7680 {
7681 if (first)
7682 buffer_putc (b, ' ');
7683 else
7684 {
7685 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7686 continue;
7687 first = 1;
7688 }
7689
7690 buffer_putstr (b, argv[i]);
7691 }
7692 buffer_putc (b, '\0');
7693
7694 str = buffer_getstr (b);
7695 buffer_free (b);
7696
7697 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007698 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007699 if (! com)
7700 {
7701 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7702 return CMD_WARNING;
7703 }
7704
Michael Lambert95cbbd22010-07-23 14:43:04 -04007705 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007706 (exact ? bgp_show_type_community_exact :
7707 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007708}
7709
7710DEFUN (show_ip_bgp_community,
7711 show_ip_bgp_community_cmd,
7712 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7713 SHOW_STR
7714 IP_STR
7715 BGP_STR
7716 "Display routes matching the communities\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n")
7721{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007722 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007723}
7724
7725ALIAS (show_ip_bgp_community,
7726 show_ip_bgp_community2_cmd,
7727 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7728 SHOW_STR
7729 IP_STR
7730 BGP_STR
7731 "Display routes matching the communities\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n")
7740
7741ALIAS (show_ip_bgp_community,
7742 show_ip_bgp_community3_cmd,
7743 "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)",
7744 SHOW_STR
7745 IP_STR
7746 BGP_STR
7747 "Display routes matching the communities\n"
7748 "community number\n"
7749 "Do not send outside local AS (well-known community)\n"
7750 "Do not advertise to any peer (well-known community)\n"
7751 "Do not export to next AS (well-known community)\n"
7752 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n"
7756 "community number\n"
7757 "Do not send outside local AS (well-known community)\n"
7758 "Do not advertise to any peer (well-known community)\n"
7759 "Do not export to next AS (well-known community)\n")
7760
7761ALIAS (show_ip_bgp_community,
7762 show_ip_bgp_community4_cmd,
7763 "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)",
7764 SHOW_STR
7765 IP_STR
7766 BGP_STR
7767 "Display routes matching the communities\n"
7768 "community number\n"
7769 "Do not send outside local AS (well-known community)\n"
7770 "Do not advertise to any peer (well-known community)\n"
7771 "Do not export to next AS (well-known community)\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n")
7784
7785DEFUN (show_ip_bgp_ipv4_community,
7786 show_ip_bgp_ipv4_community_cmd,
7787 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7788 SHOW_STR
7789 IP_STR
7790 BGP_STR
7791 "Address family\n"
7792 "Address Family modifier\n"
7793 "Address Family modifier\n"
7794 "Display routes matching the communities\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n")
7799{
7800 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007801 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007802
Michael Lambert95cbbd22010-07-23 14:43:04 -04007803 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007804}
7805
7806ALIAS (show_ip_bgp_ipv4_community,
7807 show_ip_bgp_ipv4_community2_cmd,
7808 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7809 SHOW_STR
7810 IP_STR
7811 BGP_STR
7812 "Address family\n"
7813 "Address Family modifier\n"
7814 "Address Family modifier\n"
7815 "Display routes matching the communities\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n")
7824
7825ALIAS (show_ip_bgp_ipv4_community,
7826 show_ip_bgp_ipv4_community3_cmd,
7827 "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)",
7828 SHOW_STR
7829 IP_STR
7830 BGP_STR
7831 "Address family\n"
7832 "Address Family modifier\n"
7833 "Address Family modifier\n"
7834 "Display routes matching the communities\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n"
7839 "community number\n"
7840 "Do not send outside local AS (well-known community)\n"
7841 "Do not advertise to any peer (well-known community)\n"
7842 "Do not export to next AS (well-known community)\n"
7843 "community number\n"
7844 "Do not send outside local AS (well-known community)\n"
7845 "Do not advertise to any peer (well-known community)\n"
7846 "Do not export to next AS (well-known community)\n")
7847
7848ALIAS (show_ip_bgp_ipv4_community,
7849 show_ip_bgp_ipv4_community4_cmd,
7850 "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)",
7851 SHOW_STR
7852 IP_STR
7853 BGP_STR
7854 "Address family\n"
7855 "Address Family modifier\n"
7856 "Address Family modifier\n"
7857 "Display routes matching the communities\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\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 "community number\n"
7871 "Do not send outside local AS (well-known community)\n"
7872 "Do not advertise to any peer (well-known community)\n"
7873 "Do not export to next AS (well-known community)\n")
7874
Michael Lambert95cbbd22010-07-23 14:43:04 -04007875DEFUN (show_bgp_view_afi_safi_community_all,
7876 show_bgp_view_afi_safi_community_all_cmd,
7877#ifdef HAVE_IPV6
7878 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7879#else
7880 "show bgp view WORD ipv4 (unicast|multicast) community",
7881#endif
7882 SHOW_STR
7883 BGP_STR
7884 "BGP view\n"
7885 "BGP view name\n"
7886 "Address family\n"
7887#ifdef HAVE_IPV6
7888 "Address family\n"
7889#endif
7890 "Address Family modifier\n"
7891 "Address Family modifier\n"
7892 "Display routes containing communities\n")
7893{
7894 int afi;
7895 int safi;
7896 struct bgp *bgp;
7897
7898 /* BGP structure lookup. */
7899 bgp = bgp_lookup_by_name (argv[0]);
7900 if (bgp == NULL)
7901 {
7902 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7903 return CMD_WARNING;
7904 }
7905
7906#ifdef HAVE_IPV6
7907 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7908 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7909#else
7910 afi = AFI_IP;
7911 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7912#endif
7913 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7914}
7915
7916DEFUN (show_bgp_view_afi_safi_community,
7917 show_bgp_view_afi_safi_community_cmd,
7918#ifdef HAVE_IPV6
7919 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7920#else
7921 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7922#endif
7923 SHOW_STR
7924 BGP_STR
7925 "BGP view\n"
7926 "BGP view name\n"
7927 "Address family\n"
7928#ifdef HAVE_IPV6
7929 "Address family\n"
7930#endif
7931 "Address family modifier\n"
7932 "Address family modifier\n"
7933 "Display routes matching the communities\n"
7934 "community number\n"
7935 "Do not send outside local AS (well-known community)\n"
7936 "Do not advertise to any peer (well-known community)\n"
7937 "Do not export to next AS (well-known community)\n")
7938{
7939 int afi;
7940 int safi;
7941
7942#ifdef HAVE_IPV6
7943 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7944 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7945 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7946#else
7947 afi = AFI_IP;
7948 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7949 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7950#endif
7951}
7952
7953ALIAS (show_bgp_view_afi_safi_community,
7954 show_bgp_view_afi_safi_community2_cmd,
7955#ifdef HAVE_IPV6
7956 "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)",
7957#else
7958 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7959#endif
7960 SHOW_STR
7961 BGP_STR
7962 "BGP view\n"
7963 "BGP view name\n"
7964 "Address family\n"
7965#ifdef HAVE_IPV6
7966 "Address family\n"
7967#endif
7968 "Address family modifier\n"
7969 "Address family modifier\n"
7970 "Display routes matching the communities\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n"
7975 "community number\n"
7976 "Do not send outside local AS (well-known community)\n"
7977 "Do not advertise to any peer (well-known community)\n"
7978 "Do not export to next AS (well-known community)\n")
7979
7980ALIAS (show_bgp_view_afi_safi_community,
7981 show_bgp_view_afi_safi_community3_cmd,
7982#ifdef HAVE_IPV6
7983 "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)",
7984#else
7985 "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)",
7986#endif
7987 SHOW_STR
7988 BGP_STR
7989 "BGP view\n"
7990 "BGP view name\n"
7991 "Address family\n"
7992#ifdef HAVE_IPV6
7993 "Address family\n"
7994#endif
7995 "Address family modifier\n"
7996 "Address family modifier\n"
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n")
8010
8011ALIAS (show_bgp_view_afi_safi_community,
8012 show_bgp_view_afi_safi_community4_cmd,
8013#ifdef HAVE_IPV6
8014 "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)",
8015#else
8016 "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)",
8017#endif
8018 SHOW_STR
8019 BGP_STR
8020 "BGP view\n"
8021 "BGP view name\n"
8022 "Address family\n"
8023#ifdef HAVE_IPV6
8024 "Address family\n"
8025#endif
8026 "Address family modifier\n"
8027 "Address family modifier\n"
8028 "Display routes matching the communities\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
paul718e3742002-12-13 20:15:29 +00008046DEFUN (show_ip_bgp_community_exact,
8047 show_ip_bgp_community_exact_cmd,
8048 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8049 SHOW_STR
8050 IP_STR
8051 BGP_STR
8052 "Display routes matching the communities\n"
8053 "community number\n"
8054 "Do not send outside local AS (well-known community)\n"
8055 "Do not advertise to any peer (well-known community)\n"
8056 "Do not export to next AS (well-known community)\n"
8057 "Exact match of the communities")
8058{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008059 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008060}
8061
8062ALIAS (show_ip_bgp_community_exact,
8063 show_ip_bgp_community2_exact_cmd,
8064 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8065 SHOW_STR
8066 IP_STR
8067 BGP_STR
8068 "Display routes matching the communities\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "Exact match of the communities")
8078
8079ALIAS (show_ip_bgp_community_exact,
8080 show_ip_bgp_community3_exact_cmd,
8081 "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",
8082 SHOW_STR
8083 IP_STR
8084 BGP_STR
8085 "Display routes matching the communities\n"
8086 "community number\n"
8087 "Do not send outside local AS (well-known community)\n"
8088 "Do not advertise to any peer (well-known community)\n"
8089 "Do not export to next AS (well-known community)\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "Exact match of the communities")
8099
8100ALIAS (show_ip_bgp_community_exact,
8101 show_ip_bgp_community4_exact_cmd,
8102 "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",
8103 SHOW_STR
8104 IP_STR
8105 BGP_STR
8106 "Display routes matching the communities\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\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
8125DEFUN (show_ip_bgp_ipv4_community_exact,
8126 show_ip_bgp_ipv4_community_exact_cmd,
8127 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8128 SHOW_STR
8129 IP_STR
8130 BGP_STR
8131 "Address family\n"
8132 "Address Family modifier\n"
8133 "Address Family modifier\n"
8134 "Display routes matching the communities\n"
8135 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "Exact match of the communities")
8140{
8141 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008142 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008143
Michael Lambert95cbbd22010-07-23 14:43:04 -04008144 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008145}
8146
8147ALIAS (show_ip_bgp_ipv4_community_exact,
8148 show_ip_bgp_ipv4_community2_exact_cmd,
8149 "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",
8150 SHOW_STR
8151 IP_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "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 "Exact match of the communities")
8166
8167ALIAS (show_ip_bgp_ipv4_community_exact,
8168 show_ip_bgp_ipv4_community3_exact_cmd,
8169 "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",
8170 SHOW_STR
8171 IP_STR
8172 BGP_STR
8173 "Address family\n"
8174 "Address Family modifier\n"
8175 "Address Family modifier\n"
8176 "Display routes matching the communities\n"
8177 "community number\n"
8178 "Do not send outside local AS (well-known community)\n"
8179 "Do not advertise to any peer (well-known community)\n"
8180 "Do not export to next AS (well-known community)\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 "community number\n"
8186 "Do not send outside local AS (well-known community)\n"
8187 "Do not advertise to any peer (well-known community)\n"
8188 "Do not export to next AS (well-known community)\n"
8189 "Exact match of the communities")
8190
8191ALIAS (show_ip_bgp_ipv4_community_exact,
8192 show_ip_bgp_ipv4_community4_exact_cmd,
8193 "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",
8194 SHOW_STR
8195 IP_STR
8196 BGP_STR
8197 "Address family\n"
8198 "Address Family modifier\n"
8199 "Address Family modifier\n"
8200 "Display routes matching the communities\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n"
8209 "community number\n"
8210 "Do not send outside local AS (well-known community)\n"
8211 "Do not advertise to any peer (well-known community)\n"
8212 "Do not export to next AS (well-known community)\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\n"
8217 "Exact match of the communities")
8218
8219#ifdef HAVE_IPV6
8220DEFUN (show_bgp_community,
8221 show_bgp_community_cmd,
8222 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8223 SHOW_STR
8224 BGP_STR
8225 "Display routes matching the communities\n"
8226 "community number\n"
8227 "Do not send outside local AS (well-known community)\n"
8228 "Do not advertise to any peer (well-known community)\n"
8229 "Do not export to next AS (well-known community)\n")
8230{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008231 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008232}
8233
8234ALIAS (show_bgp_community,
8235 show_bgp_ipv6_community_cmd,
8236 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8237 SHOW_STR
8238 BGP_STR
8239 "Address family\n"
8240 "Display routes matching the communities\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n")
8245
8246ALIAS (show_bgp_community,
8247 show_bgp_community2_cmd,
8248 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8249 SHOW_STR
8250 BGP_STR
8251 "Display routes matching the communities\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n")
8260
8261ALIAS (show_bgp_community,
8262 show_bgp_ipv6_community2_cmd,
8263 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8264 SHOW_STR
8265 BGP_STR
8266 "Address family\n"
8267 "Display routes matching the communities\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\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
8277ALIAS (show_bgp_community,
8278 show_bgp_community3_cmd,
8279 "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)",
8280 SHOW_STR
8281 BGP_STR
8282 "Display routes matching the communities\n"
8283 "community number\n"
8284 "Do not send outside local AS (well-known community)\n"
8285 "Do not advertise to any peer (well-known community)\n"
8286 "Do not export to next AS (well-known community)\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n")
8295
8296ALIAS (show_bgp_community,
8297 show_bgp_ipv6_community3_cmd,
8298 "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)",
8299 SHOW_STR
8300 BGP_STR
8301 "Address family\n"
8302 "Display routes matching the communities\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n"
8307 "community number\n"
8308 "Do not send outside local AS (well-known community)\n"
8309 "Do not advertise to any peer (well-known community)\n"
8310 "Do not export to next AS (well-known community)\n"
8311 "community number\n"
8312 "Do not send outside local AS (well-known community)\n"
8313 "Do not advertise to any peer (well-known community)\n"
8314 "Do not export to next AS (well-known community)\n")
8315
8316ALIAS (show_bgp_community,
8317 show_bgp_community4_cmd,
8318 "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)",
8319 SHOW_STR
8320 BGP_STR
8321 "Display routes matching the communities\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n"
8330 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n"
8334 "community number\n"
8335 "Do not send outside local AS (well-known community)\n"
8336 "Do not advertise to any peer (well-known community)\n"
8337 "Do not export to next AS (well-known community)\n")
8338
8339ALIAS (show_bgp_community,
8340 show_bgp_ipv6_community4_cmd,
8341 "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)",
8342 SHOW_STR
8343 BGP_STR
8344 "Address family\n"
8345 "Display routes matching the communities\n"
8346 "community number\n"
8347 "Do not send outside local AS (well-known community)\n"
8348 "Do not advertise to any peer (well-known community)\n"
8349 "Do not export to next AS (well-known community)\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\n")
8362
8363/* old command */
8364DEFUN (show_ipv6_bgp_community,
8365 show_ipv6_bgp_community_cmd,
8366 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8367 SHOW_STR
8368 IPV6_STR
8369 BGP_STR
8370 "Display routes matching the communities\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n")
8375{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008376 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008377}
8378
8379/* old command */
8380ALIAS (show_ipv6_bgp_community,
8381 show_ipv6_bgp_community2_cmd,
8382 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8383 SHOW_STR
8384 IPV6_STR
8385 BGP_STR
8386 "Display routes matching the communities\n"
8387 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n")
8395
8396/* old command */
8397ALIAS (show_ipv6_bgp_community,
8398 show_ipv6_bgp_community3_cmd,
8399 "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)",
8400 SHOW_STR
8401 IPV6_STR
8402 BGP_STR
8403 "Display routes matching the communities\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n"
8412 "community number\n"
8413 "Do not send outside local AS (well-known community)\n"
8414 "Do not advertise to any peer (well-known community)\n"
8415 "Do not export to next AS (well-known community)\n")
8416
8417/* old command */
8418ALIAS (show_ipv6_bgp_community,
8419 show_ipv6_bgp_community4_cmd,
8420 "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)",
8421 SHOW_STR
8422 IPV6_STR
8423 BGP_STR
8424 "Display routes matching the communities\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "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
8442DEFUN (show_bgp_community_exact,
8443 show_bgp_community_exact_cmd,
8444 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8445 SHOW_STR
8446 BGP_STR
8447 "Display routes matching the communities\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "Exact match of the communities")
8453{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008454 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008455}
8456
8457ALIAS (show_bgp_community_exact,
8458 show_bgp_ipv6_community_exact_cmd,
8459 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8460 SHOW_STR
8461 BGP_STR
8462 "Address family\n"
8463 "Display routes matching the communities\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\n"
8468 "Exact match of the communities")
8469
8470ALIAS (show_bgp_community_exact,
8471 show_bgp_community2_exact_cmd,
8472 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8473 SHOW_STR
8474 BGP_STR
8475 "Display routes matching the communities\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n"
8484 "Exact match of the communities")
8485
8486ALIAS (show_bgp_community_exact,
8487 show_bgp_ipv6_community2_exact_cmd,
8488 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8489 SHOW_STR
8490 BGP_STR
8491 "Address family\n"
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "community number\n"
8498 "Do not send outside local AS (well-known community)\n"
8499 "Do not advertise to any peer (well-known community)\n"
8500 "Do not export to next AS (well-known community)\n"
8501 "Exact match of the communities")
8502
8503ALIAS (show_bgp_community_exact,
8504 show_bgp_community3_exact_cmd,
8505 "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",
8506 SHOW_STR
8507 BGP_STR
8508 "Display routes matching the communities\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "community number\n"
8518 "Do not send outside local AS (well-known community)\n"
8519 "Do not advertise to any peer (well-known community)\n"
8520 "Do not export to next AS (well-known community)\n"
8521 "Exact match of the communities")
8522
8523ALIAS (show_bgp_community_exact,
8524 show_bgp_ipv6_community3_exact_cmd,
8525 "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",
8526 SHOW_STR
8527 BGP_STR
8528 "Address family\n"
8529 "Display routes matching the communities\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "community number\n"
8539 "Do not send outside local AS (well-known community)\n"
8540 "Do not advertise to any peer (well-known community)\n"
8541 "Do not export to next AS (well-known community)\n"
8542 "Exact match of the communities")
8543
8544ALIAS (show_bgp_community_exact,
8545 show_bgp_community4_exact_cmd,
8546 "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",
8547 SHOW_STR
8548 BGP_STR
8549 "Display routes matching the communities\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "Exact match of the communities")
8567
8568ALIAS (show_bgp_community_exact,
8569 show_bgp_ipv6_community4_exact_cmd,
8570 "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",
8571 SHOW_STR
8572 BGP_STR
8573 "Address family\n"
8574 "Display routes matching the communities\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n"
8587 "community number\n"
8588 "Do not send outside local AS (well-known community)\n"
8589 "Do not advertise to any peer (well-known community)\n"
8590 "Do not export to next AS (well-known community)\n"
8591 "Exact match of the communities")
8592
8593/* old command */
8594DEFUN (show_ipv6_bgp_community_exact,
8595 show_ipv6_bgp_community_exact_cmd,
8596 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8597 SHOW_STR
8598 IPV6_STR
8599 BGP_STR
8600 "Display routes matching the communities\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "Exact match of the communities")
8606{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008607 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008608}
8609
8610/* old command */
8611ALIAS (show_ipv6_bgp_community_exact,
8612 show_ipv6_bgp_community2_exact_cmd,
8613 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8614 SHOW_STR
8615 IPV6_STR
8616 BGP_STR
8617 "Display routes matching the communities\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n"
8626 "Exact match of the communities")
8627
8628/* old command */
8629ALIAS (show_ipv6_bgp_community_exact,
8630 show_ipv6_bgp_community3_exact_cmd,
8631 "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",
8632 SHOW_STR
8633 IPV6_STR
8634 BGP_STR
8635 "Display routes matching the communities\n"
8636 "community number\n"
8637 "Do not send outside local AS (well-known community)\n"
8638 "Do not advertise to any peer (well-known community)\n"
8639 "Do not export to next AS (well-known community)\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "Exact match of the communities")
8649
8650/* old command */
8651ALIAS (show_ipv6_bgp_community_exact,
8652 show_ipv6_bgp_community4_exact_cmd,
8653 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8654 SHOW_STR
8655 IPV6_STR
8656 BGP_STR
8657 "Display routes matching the communities\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "community number\n"
8667 "Do not send outside local AS (well-known community)\n"
8668 "Do not advertise to any peer (well-known community)\n"
8669 "Do not export to next AS (well-known community)\n"
8670 "community number\n"
8671 "Do not send outside local AS (well-known community)\n"
8672 "Do not advertise to any peer (well-known community)\n"
8673 "Do not export to next AS (well-known community)\n"
8674 "Exact match of the communities")
8675
8676/* old command */
8677DEFUN (show_ipv6_mbgp_community,
8678 show_ipv6_mbgp_community_cmd,
8679 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8680 SHOW_STR
8681 IPV6_STR
8682 MBGP_STR
8683 "Display routes matching the communities\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n")
8688{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008689 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008690}
8691
8692/* old command */
8693ALIAS (show_ipv6_mbgp_community,
8694 show_ipv6_mbgp_community2_cmd,
8695 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8696 SHOW_STR
8697 IPV6_STR
8698 MBGP_STR
8699 "Display routes matching the communities\n"
8700 "community number\n"
8701 "Do not send outside local AS (well-known community)\n"
8702 "Do not advertise to any peer (well-known community)\n"
8703 "Do not export to next AS (well-known community)\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
8709/* old command */
8710ALIAS (show_ipv6_mbgp_community,
8711 show_ipv6_mbgp_community3_cmd,
8712 "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)",
8713 SHOW_STR
8714 IPV6_STR
8715 MBGP_STR
8716 "Display routes matching the communities\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n"
8721 "community number\n"
8722 "Do not send outside local AS (well-known community)\n"
8723 "Do not advertise to any peer (well-known community)\n"
8724 "Do not export to next AS (well-known community)\n"
8725 "community number\n"
8726 "Do not send outside local AS (well-known community)\n"
8727 "Do not advertise to any peer (well-known community)\n"
8728 "Do not export to next AS (well-known community)\n")
8729
8730/* old command */
8731ALIAS (show_ipv6_mbgp_community,
8732 show_ipv6_mbgp_community4_cmd,
8733 "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)",
8734 SHOW_STR
8735 IPV6_STR
8736 MBGP_STR
8737 "Display routes matching the communities\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\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 */
8756DEFUN (show_ipv6_mbgp_community_exact,
8757 show_ipv6_mbgp_community_exact_cmd,
8758 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
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 "Exact match of the communities")
8768{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008769 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008770}
8771
8772/* old command */
8773ALIAS (show_ipv6_mbgp_community_exact,
8774 show_ipv6_mbgp_community2_exact_cmd,
8775 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8776 SHOW_STR
8777 IPV6_STR
8778 MBGP_STR
8779 "Display routes matching the communities\n"
8780 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8789
8790/* old command */
8791ALIAS (show_ipv6_mbgp_community_exact,
8792 show_ipv6_mbgp_community3_exact_cmd,
8793 "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",
8794 SHOW_STR
8795 IPV6_STR
8796 MBGP_STR
8797 "Display routes matching the communities\n"
8798 "community number\n"
8799 "Do not send outside local AS (well-known community)\n"
8800 "Do not advertise to any peer (well-known community)\n"
8801 "Do not export to next AS (well-known community)\n"
8802 "community number\n"
8803 "Do not send outside local AS (well-known community)\n"
8804 "Do not advertise to any peer (well-known community)\n"
8805 "Do not export to next AS (well-known community)\n"
8806 "community number\n"
8807 "Do not send outside local AS (well-known community)\n"
8808 "Do not advertise to any peer (well-known community)\n"
8809 "Do not export to next AS (well-known community)\n"
8810 "Exact match of the communities")
8811
8812/* old command */
8813ALIAS (show_ipv6_mbgp_community_exact,
8814 show_ipv6_mbgp_community4_exact_cmd,
8815 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8816 SHOW_STR
8817 IPV6_STR
8818 MBGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "community number\n"
8833 "Do not send outside local AS (well-known community)\n"
8834 "Do not advertise to any peer (well-known community)\n"
8835 "Do not export to next AS (well-known community)\n"
8836 "Exact match of the communities")
8837#endif /* HAVE_IPV6 */
8838
paul94f2b392005-06-28 12:44:16 +00008839static int
paulfd79ac92004-10-13 05:06:08 +00008840bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008841 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008842{
8843 struct community_list *list;
8844
hassofee6e4e2005-02-02 16:29:31 +00008845 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008846 if (list == NULL)
8847 {
8848 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8849 VTY_NEWLINE);
8850 return CMD_WARNING;
8851 }
8852
ajs5a646652004-11-05 01:25:55 +00008853 return bgp_show (vty, NULL, afi, safi,
8854 (exact ? bgp_show_type_community_list_exact :
8855 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008856}
8857
8858DEFUN (show_ip_bgp_community_list,
8859 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008860 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008861 SHOW_STR
8862 IP_STR
8863 BGP_STR
8864 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008865 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008866 "community-list name\n")
8867{
8868 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8869}
8870
8871DEFUN (show_ip_bgp_ipv4_community_list,
8872 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008873 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008874 SHOW_STR
8875 IP_STR
8876 BGP_STR
8877 "Address family\n"
8878 "Address Family modifier\n"
8879 "Address Family modifier\n"
8880 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008881 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008882 "community-list name\n")
8883{
8884 if (strncmp (argv[0], "m", 1) == 0)
8885 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8886
8887 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8888}
8889
8890DEFUN (show_ip_bgp_community_list_exact,
8891 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008892 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008897 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008898 "community-list name\n"
8899 "Exact match of the communities\n")
8900{
8901 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8902}
8903
8904DEFUN (show_ip_bgp_ipv4_community_list_exact,
8905 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008906 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008907 SHOW_STR
8908 IP_STR
8909 BGP_STR
8910 "Address family\n"
8911 "Address Family modifier\n"
8912 "Address Family modifier\n"
8913 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008914 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008915 "community-list name\n"
8916 "Exact match of the communities\n")
8917{
8918 if (strncmp (argv[0], "m", 1) == 0)
8919 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8920
8921 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8922}
8923
8924#ifdef HAVE_IPV6
8925DEFUN (show_bgp_community_list,
8926 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008927 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008928 SHOW_STR
8929 BGP_STR
8930 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008931 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008932 "community-list name\n")
8933{
8934 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8935}
8936
8937ALIAS (show_bgp_community_list,
8938 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008939 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008940 SHOW_STR
8941 BGP_STR
8942 "Address family\n"
8943 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008944 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008945 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008946
8947/* old command */
8948DEFUN (show_ipv6_bgp_community_list,
8949 show_ipv6_bgp_community_list_cmd,
8950 "show ipv6 bgp community-list WORD",
8951 SHOW_STR
8952 IPV6_STR
8953 BGP_STR
8954 "Display routes matching the community-list\n"
8955 "community-list name\n")
8956{
8957 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8958}
8959
8960/* old command */
8961DEFUN (show_ipv6_mbgp_community_list,
8962 show_ipv6_mbgp_community_list_cmd,
8963 "show ipv6 mbgp community-list WORD",
8964 SHOW_STR
8965 IPV6_STR
8966 MBGP_STR
8967 "Display routes matching the community-list\n"
8968 "community-list name\n")
8969{
8970 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8971}
8972
8973DEFUN (show_bgp_community_list_exact,
8974 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008975 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008976 SHOW_STR
8977 BGP_STR
8978 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008979 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008980 "community-list name\n"
8981 "Exact match of the communities\n")
8982{
8983 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8984}
8985
8986ALIAS (show_bgp_community_list_exact,
8987 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008988 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008989 SHOW_STR
8990 BGP_STR
8991 "Address family\n"
8992 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008993 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008994 "community-list name\n"
8995 "Exact match of the communities\n")
8996
8997/* old command */
8998DEFUN (show_ipv6_bgp_community_list_exact,
8999 show_ipv6_bgp_community_list_exact_cmd,
9000 "show ipv6 bgp community-list WORD exact-match",
9001 SHOW_STR
9002 IPV6_STR
9003 BGP_STR
9004 "Display routes matching the community-list\n"
9005 "community-list name\n"
9006 "Exact match of the communities\n")
9007{
9008 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9009}
9010
9011/* old command */
9012DEFUN (show_ipv6_mbgp_community_list_exact,
9013 show_ipv6_mbgp_community_list_exact_cmd,
9014 "show ipv6 mbgp community-list WORD exact-match",
9015 SHOW_STR
9016 IPV6_STR
9017 MBGP_STR
9018 "Display routes matching the community-list\n"
9019 "community-list name\n"
9020 "Exact match of the communities\n")
9021{
9022 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9023}
9024#endif /* HAVE_IPV6 */
9025
paul94f2b392005-06-28 12:44:16 +00009026static int
paulfd79ac92004-10-13 05:06:08 +00009027bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009028 safi_t safi, enum bgp_show_type type)
9029{
9030 int ret;
9031 struct prefix *p;
9032
9033 p = prefix_new();
9034
9035 ret = str2prefix (prefix, p);
9036 if (! ret)
9037 {
9038 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9039 return CMD_WARNING;
9040 }
9041
ajs5a646652004-11-05 01:25:55 +00009042 ret = bgp_show (vty, NULL, afi, safi, type, p);
9043 prefix_free(p);
9044 return ret;
paul718e3742002-12-13 20:15:29 +00009045}
9046
9047DEFUN (show_ip_bgp_prefix_longer,
9048 show_ip_bgp_prefix_longer_cmd,
9049 "show ip bgp A.B.C.D/M longer-prefixes",
9050 SHOW_STR
9051 IP_STR
9052 BGP_STR
9053 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9054 "Display route and more specific routes\n")
9055{
9056 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9057 bgp_show_type_prefix_longer);
9058}
9059
9060DEFUN (show_ip_bgp_flap_prefix_longer,
9061 show_ip_bgp_flap_prefix_longer_cmd,
9062 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9063 SHOW_STR
9064 IP_STR
9065 BGP_STR
9066 "Display flap statistics of routes\n"
9067 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9068 "Display route and more specific routes\n")
9069{
9070 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9071 bgp_show_type_flap_prefix_longer);
9072}
9073
9074DEFUN (show_ip_bgp_ipv4_prefix_longer,
9075 show_ip_bgp_ipv4_prefix_longer_cmd,
9076 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9077 SHOW_STR
9078 IP_STR
9079 BGP_STR
9080 "Address family\n"
9081 "Address Family modifier\n"
9082 "Address Family modifier\n"
9083 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9084 "Display route and more specific routes\n")
9085{
9086 if (strncmp (argv[0], "m", 1) == 0)
9087 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9088 bgp_show_type_prefix_longer);
9089
9090 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9091 bgp_show_type_prefix_longer);
9092}
9093
9094DEFUN (show_ip_bgp_flap_address,
9095 show_ip_bgp_flap_address_cmd,
9096 "show ip bgp flap-statistics A.B.C.D",
9097 SHOW_STR
9098 IP_STR
9099 BGP_STR
9100 "Display flap statistics of routes\n"
9101 "Network in the BGP routing table to display\n")
9102{
9103 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9104 bgp_show_type_flap_address);
9105}
9106
9107DEFUN (show_ip_bgp_flap_prefix,
9108 show_ip_bgp_flap_prefix_cmd,
9109 "show ip bgp flap-statistics A.B.C.D/M",
9110 SHOW_STR
9111 IP_STR
9112 BGP_STR
9113 "Display flap statistics of routes\n"
9114 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9115{
9116 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9117 bgp_show_type_flap_prefix);
9118}
9119#ifdef HAVE_IPV6
9120DEFUN (show_bgp_prefix_longer,
9121 show_bgp_prefix_longer_cmd,
9122 "show bgp X:X::X:X/M longer-prefixes",
9123 SHOW_STR
9124 BGP_STR
9125 "IPv6 prefix <network>/<length>\n"
9126 "Display route and more specific routes\n")
9127{
9128 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9129 bgp_show_type_prefix_longer);
9130}
9131
9132ALIAS (show_bgp_prefix_longer,
9133 show_bgp_ipv6_prefix_longer_cmd,
9134 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9135 SHOW_STR
9136 BGP_STR
9137 "Address family\n"
9138 "IPv6 prefix <network>/<length>\n"
9139 "Display route and more specific routes\n")
9140
9141/* old command */
9142DEFUN (show_ipv6_bgp_prefix_longer,
9143 show_ipv6_bgp_prefix_longer_cmd,
9144 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9145 SHOW_STR
9146 IPV6_STR
9147 BGP_STR
9148 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9149 "Display route and more specific routes\n")
9150{
9151 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9152 bgp_show_type_prefix_longer);
9153}
9154
9155/* old command */
9156DEFUN (show_ipv6_mbgp_prefix_longer,
9157 show_ipv6_mbgp_prefix_longer_cmd,
9158 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9159 SHOW_STR
9160 IPV6_STR
9161 MBGP_STR
9162 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9163 "Display route and more specific routes\n")
9164{
9165 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9166 bgp_show_type_prefix_longer);
9167}
9168#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009169
paul94f2b392005-06-28 12:44:16 +00009170static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009171peer_lookup_in_view (struct vty *vty, const char *view_name,
9172 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009173{
9174 int ret;
9175 struct bgp *bgp;
9176 struct peer *peer;
9177 union sockunion su;
9178
9179 /* BGP structure lookup. */
9180 if (view_name)
9181 {
9182 bgp = bgp_lookup_by_name (view_name);
9183 if (! bgp)
9184 {
9185 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9186 return NULL;
9187 }
9188 }
paul5228ad22004-06-04 17:58:18 +00009189 else
paulbb46e942003-10-24 19:02:03 +00009190 {
9191 bgp = bgp_get_default ();
9192 if (! bgp)
9193 {
9194 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9195 return NULL;
9196 }
9197 }
9198
9199 /* Get peer sockunion. */
9200 ret = str2sockunion (ip_str, &su);
9201 if (ret < 0)
9202 {
9203 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9204 return NULL;
9205 }
9206
9207 /* Peer structure lookup. */
9208 peer = peer_lookup (bgp, &su);
9209 if (! peer)
9210 {
9211 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9212 return NULL;
9213 }
9214
9215 return peer;
9216}
Paul Jakma2815e612006-09-14 02:56:07 +00009217
9218enum bgp_stats
9219{
9220 BGP_STATS_MAXBITLEN = 0,
9221 BGP_STATS_RIB,
9222 BGP_STATS_PREFIXES,
9223 BGP_STATS_TOTPLEN,
9224 BGP_STATS_UNAGGREGATEABLE,
9225 BGP_STATS_MAX_AGGREGATEABLE,
9226 BGP_STATS_AGGREGATES,
9227 BGP_STATS_SPACE,
9228 BGP_STATS_ASPATH_COUNT,
9229 BGP_STATS_ASPATH_MAXHOPS,
9230 BGP_STATS_ASPATH_TOTHOPS,
9231 BGP_STATS_ASPATH_MAXSIZE,
9232 BGP_STATS_ASPATH_TOTSIZE,
9233 BGP_STATS_ASN_HIGHEST,
9234 BGP_STATS_MAX,
9235};
paulbb46e942003-10-24 19:02:03 +00009236
Paul Jakma2815e612006-09-14 02:56:07 +00009237static const char *table_stats_strs[] =
9238{
9239 [BGP_STATS_PREFIXES] = "Total Prefixes",
9240 [BGP_STATS_TOTPLEN] = "Average prefix length",
9241 [BGP_STATS_RIB] = "Total Advertisements",
9242 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9243 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9244 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9245 [BGP_STATS_SPACE] = "Address space advertised",
9246 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9247 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9248 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9249 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9250 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9251 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9252 [BGP_STATS_MAX] = NULL,
9253};
9254
9255struct bgp_table_stats
9256{
9257 struct bgp_table *table;
9258 unsigned long long counts[BGP_STATS_MAX];
9259};
9260
9261#if 0
9262#define TALLY_SIGFIG 100000
9263static unsigned long
9264ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9265{
9266 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9267 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9268 unsigned long ret = newtot / count;
9269
9270 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9271 return ret + 1;
9272 else
9273 return ret;
9274}
9275#endif
9276
9277static int
9278bgp_table_stats_walker (struct thread *t)
9279{
9280 struct bgp_node *rn;
9281 struct bgp_node *top;
9282 struct bgp_table_stats *ts = THREAD_ARG (t);
9283 unsigned int space = 0;
9284
Paul Jakma53d9f672006-10-15 23:41:16 +00009285 if (!(top = bgp_table_top (ts->table)))
9286 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009287
9288 switch (top->p.family)
9289 {
9290 case AF_INET:
9291 space = IPV4_MAX_BITLEN;
9292 break;
9293 case AF_INET6:
9294 space = IPV6_MAX_BITLEN;
9295 break;
9296 }
9297
9298 ts->counts[BGP_STATS_MAXBITLEN] = space;
9299
9300 for (rn = top; rn; rn = bgp_route_next (rn))
9301 {
9302 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009303 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009304 unsigned int rinum = 0;
9305
9306 if (rn == top)
9307 continue;
9308
9309 if (!rn->info)
9310 continue;
9311
9312 ts->counts[BGP_STATS_PREFIXES]++;
9313 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9314
9315#if 0
9316 ts->counts[BGP_STATS_AVGPLEN]
9317 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9318 ts->counts[BGP_STATS_AVGPLEN],
9319 rn->p.prefixlen);
9320#endif
9321
9322 /* check if the prefix is included by any other announcements */
9323 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009324 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009325
9326 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009327 {
9328 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9329 /* announced address space */
9330 if (space)
9331 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9332 }
Paul Jakma2815e612006-09-14 02:56:07 +00009333 else if (prn->info)
9334 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9335
Paul Jakma2815e612006-09-14 02:56:07 +00009336 for (ri = rn->info; ri; ri = ri->next)
9337 {
9338 rinum++;
9339 ts->counts[BGP_STATS_RIB]++;
9340
9341 if (ri->attr &&
9342 (CHECK_FLAG (ri->attr->flag,
9343 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9344 ts->counts[BGP_STATS_AGGREGATES]++;
9345
9346 /* as-path stats */
9347 if (ri->attr && ri->attr->aspath)
9348 {
9349 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9350 unsigned int size = aspath_size (ri->attr->aspath);
9351 as_t highest = aspath_highest (ri->attr->aspath);
9352
9353 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9354
9355 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9356 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9357
9358 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9359 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9360
9361 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9362 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9363#if 0
9364 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9365 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9366 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9367 hops);
9368 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9369 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9370 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9371 size);
9372#endif
9373 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9374 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9375 }
9376 }
9377 }
9378 return 0;
9379}
9380
9381static int
9382bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9383{
9384 struct bgp_table_stats ts;
9385 unsigned int i;
9386
9387 if (!bgp->rib[afi][safi])
9388 {
9389 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9390 return CMD_WARNING;
9391 }
9392
9393 memset (&ts, 0, sizeof (ts));
9394 ts.table = bgp->rib[afi][safi];
9395 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9396
9397 vty_out (vty, "BGP %s RIB statistics%s%s",
9398 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9399
9400 for (i = 0; i < BGP_STATS_MAX; i++)
9401 {
9402 if (!table_stats_strs[i])
9403 continue;
9404
9405 switch (i)
9406 {
9407#if 0
9408 case BGP_STATS_ASPATH_AVGHOPS:
9409 case BGP_STATS_ASPATH_AVGSIZE:
9410 case BGP_STATS_AVGPLEN:
9411 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9412 vty_out (vty, "%12.2f",
9413 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9414 break;
9415#endif
9416 case BGP_STATS_ASPATH_TOTHOPS:
9417 case BGP_STATS_ASPATH_TOTSIZE:
9418 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9419 vty_out (vty, "%12.2f",
9420 ts.counts[i] ?
9421 (float)ts.counts[i] /
9422 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9423 : 0);
9424 break;
9425 case BGP_STATS_TOTPLEN:
9426 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9427 vty_out (vty, "%12.2f",
9428 ts.counts[i] ?
9429 (float)ts.counts[i] /
9430 (float)ts.counts[BGP_STATS_PREFIXES]
9431 : 0);
9432 break;
9433 case BGP_STATS_SPACE:
9434 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9435 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9436 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9437 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009438 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009439 vty_out (vty, "%12.2f%s",
9440 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009441 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009442 VTY_NEWLINE);
9443 vty_out (vty, "%30s: ", "/8 equivalent ");
9444 vty_out (vty, "%12.2f%s",
9445 (float)ts.counts[BGP_STATS_SPACE] /
9446 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9447 VTY_NEWLINE);
9448 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9449 break;
9450 vty_out (vty, "%30s: ", "/24 equivalent ");
9451 vty_out (vty, "%12.2f",
9452 (float)ts.counts[BGP_STATS_SPACE] /
9453 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9454 break;
9455 default:
9456 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9457 vty_out (vty, "%12llu", ts.counts[i]);
9458 }
9459
9460 vty_out (vty, "%s", VTY_NEWLINE);
9461 }
9462 return CMD_SUCCESS;
9463}
9464
9465static int
9466bgp_table_stats_vty (struct vty *vty, const char *name,
9467 const char *afi_str, const char *safi_str)
9468{
9469 struct bgp *bgp;
9470 afi_t afi;
9471 safi_t safi;
9472
9473 if (name)
9474 bgp = bgp_lookup_by_name (name);
9475 else
9476 bgp = bgp_get_default ();
9477
9478 if (!bgp)
9479 {
9480 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9481 return CMD_WARNING;
9482 }
9483 if (strncmp (afi_str, "ipv", 3) == 0)
9484 {
9485 if (strncmp (afi_str, "ipv4", 4) == 0)
9486 afi = AFI_IP;
9487 else if (strncmp (afi_str, "ipv6", 4) == 0)
9488 afi = AFI_IP6;
9489 else
9490 {
9491 vty_out (vty, "%% Invalid address family %s%s",
9492 afi_str, VTY_NEWLINE);
9493 return CMD_WARNING;
9494 }
9495 if (strncmp (safi_str, "m", 1) == 0)
9496 safi = SAFI_MULTICAST;
9497 else if (strncmp (safi_str, "u", 1) == 0)
9498 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009499 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9500 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009501 else
9502 {
9503 vty_out (vty, "%% Invalid subsequent address family %s%s",
9504 safi_str, VTY_NEWLINE);
9505 return CMD_WARNING;
9506 }
9507 }
9508 else
9509 {
9510 vty_out (vty, "%% Invalid address family %s%s",
9511 afi_str, VTY_NEWLINE);
9512 return CMD_WARNING;
9513 }
9514
Paul Jakma2815e612006-09-14 02:56:07 +00009515 return bgp_table_stats (vty, bgp, afi, safi);
9516}
9517
9518DEFUN (show_bgp_statistics,
9519 show_bgp_statistics_cmd,
9520 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9521 SHOW_STR
9522 BGP_STR
9523 "Address family\n"
9524 "Address family\n"
9525 "Address Family modifier\n"
9526 "Address Family modifier\n"
9527 "BGP RIB advertisement statistics\n")
9528{
9529 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9530}
9531
9532ALIAS (show_bgp_statistics,
9533 show_bgp_statistics_vpnv4_cmd,
9534 "show bgp (ipv4) (vpnv4) statistics",
9535 SHOW_STR
9536 BGP_STR
9537 "Address family\n"
9538 "Address Family modifier\n"
9539 "BGP RIB advertisement statistics\n")
9540
9541DEFUN (show_bgp_statistics_view,
9542 show_bgp_statistics_view_cmd,
9543 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9544 SHOW_STR
9545 BGP_STR
9546 "BGP view\n"
9547 "Address family\n"
9548 "Address family\n"
9549 "Address Family modifier\n"
9550 "Address Family modifier\n"
9551 "BGP RIB advertisement statistics\n")
9552{
9553 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9554}
9555
9556ALIAS (show_bgp_statistics_view,
9557 show_bgp_statistics_view_vpnv4_cmd,
9558 "show bgp view WORD (ipv4) (vpnv4) statistics",
9559 SHOW_STR
9560 BGP_STR
9561 "BGP view\n"
9562 "Address family\n"
9563 "Address Family modifier\n"
9564 "BGP RIB advertisement statistics\n")
9565
Paul Jakmaff7924f2006-09-04 01:10:36 +00009566enum bgp_pcounts
9567{
9568 PCOUNT_ADJ_IN = 0,
9569 PCOUNT_DAMPED,
9570 PCOUNT_REMOVED,
9571 PCOUNT_HISTORY,
9572 PCOUNT_STALE,
9573 PCOUNT_VALID,
9574 PCOUNT_ALL,
9575 PCOUNT_COUNTED,
9576 PCOUNT_PFCNT, /* the figure we display to users */
9577 PCOUNT_MAX,
9578};
9579
9580static const char *pcount_strs[] =
9581{
9582 [PCOUNT_ADJ_IN] = "Adj-in",
9583 [PCOUNT_DAMPED] = "Damped",
9584 [PCOUNT_REMOVED] = "Removed",
9585 [PCOUNT_HISTORY] = "History",
9586 [PCOUNT_STALE] = "Stale",
9587 [PCOUNT_VALID] = "Valid",
9588 [PCOUNT_ALL] = "All RIB",
9589 [PCOUNT_COUNTED] = "PfxCt counted",
9590 [PCOUNT_PFCNT] = "Useable",
9591 [PCOUNT_MAX] = NULL,
9592};
9593
Paul Jakma2815e612006-09-14 02:56:07 +00009594struct peer_pcounts
9595{
9596 unsigned int count[PCOUNT_MAX];
9597 const struct peer *peer;
9598 const struct bgp_table *table;
9599};
9600
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601static int
Paul Jakma2815e612006-09-14 02:56:07 +00009602bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009603{
9604 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009605 struct peer_pcounts *pc = THREAD_ARG (t);
9606 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009607
Paul Jakma2815e612006-09-14 02:56:07 +00009608 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009609 {
9610 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009611 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612
9613 for (ain = rn->adj_in; ain; ain = ain->next)
9614 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009615 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009616
Paul Jakmaff7924f2006-09-04 01:10:36 +00009617 for (ri = rn->info; ri; ri = ri->next)
9618 {
9619 char buf[SU_ADDRSTRLEN];
9620
9621 if (ri->peer != peer)
9622 continue;
9623
Paul Jakma2815e612006-09-14 02:56:07 +00009624 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009625
9626 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009627 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009628 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009629 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009630 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009631 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009632 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009633 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009635 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009636 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009637 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638
9639 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9640 {
Paul Jakma2815e612006-09-14 02:56:07 +00009641 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009642 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009643 plog_warn (peer->log,
9644 "%s [pcount] %s/%d is counted but flags 0x%x",
9645 peer->host,
9646 inet_ntop(rn->p.family, &rn->p.u.prefix,
9647 buf, SU_ADDRSTRLEN),
9648 rn->p.prefixlen,
9649 ri->flags);
9650 }
9651 else
9652 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009653 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009654 plog_warn (peer->log,
9655 "%s [pcount] %s/%d not counted but flags 0x%x",
9656 peer->host,
9657 inet_ntop(rn->p.family, &rn->p.u.prefix,
9658 buf, SU_ADDRSTRLEN),
9659 rn->p.prefixlen,
9660 ri->flags);
9661 }
9662 }
9663 }
Paul Jakma2815e612006-09-14 02:56:07 +00009664 return 0;
9665}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009666
Paul Jakma2815e612006-09-14 02:56:07 +00009667static int
9668bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9669{
9670 struct peer_pcounts pcounts = { .peer = peer };
9671 unsigned int i;
9672
9673 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9674 || !peer->bgp->rib[afi][safi])
9675 {
9676 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9677 return CMD_WARNING;
9678 }
9679
9680 memset (&pcounts, 0, sizeof(pcounts));
9681 pcounts.peer = peer;
9682 pcounts.table = peer->bgp->rib[afi][safi];
9683
9684 /* in-place call via thread subsystem so as to record execution time
9685 * stats for the thread-walk (i.e. ensure this can't be blamed on
9686 * on just vty_read()).
9687 */
9688 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9689
Paul Jakmaff7924f2006-09-04 01:10:36 +00009690 vty_out (vty, "Prefix counts for %s, %s%s",
9691 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9692 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9693 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9694 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9695
9696 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009697 vty_out (vty, "%20s: %-10d%s",
9698 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009699
Paul Jakma2815e612006-09-14 02:56:07 +00009700 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009701 {
9702 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9703 peer->host, VTY_NEWLINE);
9704 vty_out (vty, "Please report this bug, with the above command output%s",
9705 VTY_NEWLINE);
9706 }
9707
9708 return CMD_SUCCESS;
9709}
9710
9711DEFUN (show_ip_bgp_neighbor_prefix_counts,
9712 show_ip_bgp_neighbor_prefix_counts_cmd,
9713 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9714 SHOW_STR
9715 IP_STR
9716 BGP_STR
9717 "Detailed information on TCP and BGP neighbor connections\n"
9718 "Neighbor to display information about\n"
9719 "Neighbor to display information about\n"
9720 "Display detailed prefix count information\n")
9721{
9722 struct peer *peer;
9723
9724 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9725 if (! peer)
9726 return CMD_WARNING;
9727
9728 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9729}
9730
9731DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9732 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9733 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9734 SHOW_STR
9735 BGP_STR
9736 "Address family\n"
9737 "Detailed information on TCP and BGP neighbor connections\n"
9738 "Neighbor to display information about\n"
9739 "Neighbor to display information about\n"
9740 "Display detailed prefix count information\n")
9741{
9742 struct peer *peer;
9743
9744 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9745 if (! peer)
9746 return CMD_WARNING;
9747
9748 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9749}
9750
9751DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9752 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9753 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Address family\n"
9758 "Address Family modifier\n"
9759 "Address Family modifier\n"
9760 "Detailed information on TCP and BGP neighbor connections\n"
9761 "Neighbor to display information about\n"
9762 "Neighbor to display information about\n"
9763 "Display detailed prefix count information\n")
9764{
9765 struct peer *peer;
9766
9767 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9768 if (! peer)
9769 return CMD_WARNING;
9770
9771 if (strncmp (argv[0], "m", 1) == 0)
9772 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9773
9774 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9775}
9776
9777DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9778 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9779 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9780 SHOW_STR
9781 IP_STR
9782 BGP_STR
9783 "Address family\n"
9784 "Address Family modifier\n"
9785 "Address Family modifier\n"
9786 "Detailed information on TCP and BGP neighbor connections\n"
9787 "Neighbor to display information about\n"
9788 "Neighbor to display information about\n"
9789 "Display detailed prefix count information\n")
9790{
9791 struct peer *peer;
9792
9793 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9794 if (! peer)
9795 return CMD_WARNING;
9796
9797 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9798}
9799
9800
paul94f2b392005-06-28 12:44:16 +00009801static void
paul718e3742002-12-13 20:15:29 +00009802show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9803 int in)
9804{
9805 struct bgp_table *table;
9806 struct bgp_adj_in *ain;
9807 struct bgp_adj_out *adj;
9808 unsigned long output_count;
9809 struct bgp_node *rn;
9810 int header1 = 1;
9811 struct bgp *bgp;
9812 int header2 = 1;
9813
paulbb46e942003-10-24 19:02:03 +00009814 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009815
9816 if (! bgp)
9817 return;
9818
9819 table = bgp->rib[afi][safi];
9820
9821 output_count = 0;
9822
9823 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9824 PEER_STATUS_DEFAULT_ORIGINATE))
9825 {
9826 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 +00009827 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9828 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009829
9830 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9831 VTY_NEWLINE, VTY_NEWLINE);
9832 header1 = 0;
9833 }
9834
9835 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9836 if (in)
9837 {
9838 for (ain = rn->adj_in; ain; ain = ain->next)
9839 if (ain->peer == peer)
9840 {
9841 if (header1)
9842 {
9843 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 +00009844 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9845 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009846 header1 = 0;
9847 }
9848 if (header2)
9849 {
9850 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9851 header2 = 0;
9852 }
9853 if (ain->attr)
9854 {
9855 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9856 output_count++;
9857 }
9858 }
9859 }
9860 else
9861 {
9862 for (adj = rn->adj_out; adj; adj = adj->next)
9863 if (adj->peer == peer)
9864 {
9865 if (header1)
9866 {
9867 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 +00009868 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9869 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009870 header1 = 0;
9871 }
9872 if (header2)
9873 {
9874 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9875 header2 = 0;
9876 }
9877 if (adj->attr)
9878 {
9879 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9880 output_count++;
9881 }
9882 }
9883 }
9884
9885 if (output_count != 0)
9886 vty_out (vty, "%sTotal number of prefixes %ld%s",
9887 VTY_NEWLINE, output_count, VTY_NEWLINE);
9888}
9889
paul94f2b392005-06-28 12:44:16 +00009890static int
paulbb46e942003-10-24 19:02:03 +00009891peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9892{
paul718e3742002-12-13 20:15:29 +00009893 if (! peer || ! peer->afc[afi][safi])
9894 {
9895 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9896 return CMD_WARNING;
9897 }
9898
9899 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9900 {
9901 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9902 VTY_NEWLINE);
9903 return CMD_WARNING;
9904 }
9905
9906 show_adj_route (vty, peer, afi, safi, in);
9907
9908 return CMD_SUCCESS;
9909}
9910
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009911DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9912 show_ip_bgp_view_neighbor_advertised_route_cmd,
9913 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "BGP view\n"
9918 "View name\n"
9919 "Detailed information on TCP and BGP neighbor connections\n"
9920 "Neighbor to display information about\n"
9921 "Neighbor to display information about\n"
9922 "Display the routes advertised to a BGP neighbor\n")
9923{
9924 struct peer *peer;
9925
9926 if (argc == 2)
9927 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9928 else
9929 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9930
9931 if (! peer)
9932 return CMD_WARNING;
9933
9934 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9935}
9936
9937ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009938 show_ip_bgp_neighbor_advertised_route_cmd,
9939 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9940 SHOW_STR
9941 IP_STR
9942 BGP_STR
9943 "Detailed information on TCP and BGP neighbor connections\n"
9944 "Neighbor to display information about\n"
9945 "Neighbor to display information about\n"
9946 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009947
9948DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9949 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9950 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9951 SHOW_STR
9952 IP_STR
9953 BGP_STR
9954 "Address family\n"
9955 "Address Family modifier\n"
9956 "Address Family modifier\n"
9957 "Detailed information on TCP and BGP neighbor connections\n"
9958 "Neighbor to display information about\n"
9959 "Neighbor to display information about\n"
9960 "Display the routes advertised to a BGP neighbor\n")
9961{
paulbb46e942003-10-24 19:02:03 +00009962 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009963
paulbb46e942003-10-24 19:02:03 +00009964 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9965 if (! peer)
9966 return CMD_WARNING;
9967
9968 if (strncmp (argv[0], "m", 1) == 0)
9969 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9970
9971 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009972}
9973
9974#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009975DEFUN (show_bgp_view_neighbor_advertised_route,
9976 show_bgp_view_neighbor_advertised_route_cmd,
9977 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9978 SHOW_STR
9979 BGP_STR
9980 "BGP view\n"
9981 "View name\n"
9982 "Detailed information on TCP and BGP neighbor connections\n"
9983 "Neighbor to display information about\n"
9984 "Neighbor to display information about\n"
9985 "Display the routes advertised to a BGP neighbor\n")
9986{
9987 struct peer *peer;
9988
9989 if (argc == 2)
9990 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9991 else
9992 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9993
9994 if (! peer)
9995 return CMD_WARNING;
9996
9997 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9998}
9999
10000ALIAS (show_bgp_view_neighbor_advertised_route,
10001 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10002 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10003 SHOW_STR
10004 BGP_STR
10005 "BGP view\n"
10006 "View name\n"
10007 "Address family\n"
10008 "Detailed information on TCP and BGP neighbor connections\n"
10009 "Neighbor to display information about\n"
10010 "Neighbor to display information about\n"
10011 "Display the routes advertised to a BGP neighbor\n")
10012
10013DEFUN (show_bgp_view_neighbor_received_routes,
10014 show_bgp_view_neighbor_received_routes_cmd,
10015 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10016 SHOW_STR
10017 BGP_STR
10018 "BGP view\n"
10019 "View name\n"
10020 "Detailed information on TCP and BGP neighbor connections\n"
10021 "Neighbor to display information about\n"
10022 "Neighbor to display information about\n"
10023 "Display the received routes from neighbor\n")
10024{
10025 struct peer *peer;
10026
10027 if (argc == 2)
10028 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10029 else
10030 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10031
10032 if (! peer)
10033 return CMD_WARNING;
10034
10035 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10036}
10037
10038ALIAS (show_bgp_view_neighbor_received_routes,
10039 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10040 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10041 SHOW_STR
10042 BGP_STR
10043 "BGP view\n"
10044 "View name\n"
10045 "Address family\n"
10046 "Detailed information on TCP and BGP neighbor connections\n"
10047 "Neighbor to display information about\n"
10048 "Neighbor to display information about\n"
10049 "Display the received routes from neighbor\n")
10050
10051ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010052 show_bgp_neighbor_advertised_route_cmd,
10053 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10054 SHOW_STR
10055 BGP_STR
10056 "Detailed information on TCP and BGP neighbor connections\n"
10057 "Neighbor to display information about\n"
10058 "Neighbor to display information about\n"
10059 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010060
10061ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010062 show_bgp_ipv6_neighbor_advertised_route_cmd,
10063 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10064 SHOW_STR
10065 BGP_STR
10066 "Address family\n"
10067 "Detailed information on TCP and BGP neighbor connections\n"
10068 "Neighbor to display information about\n"
10069 "Neighbor to display information about\n"
10070 "Display the routes advertised to a BGP neighbor\n")
10071
10072/* old command */
paulbb46e942003-10-24 19:02:03 +000010073ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010074 ipv6_bgp_neighbor_advertised_route_cmd,
10075 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10076 SHOW_STR
10077 IPV6_STR
10078 BGP_STR
10079 "Detailed information on TCP and BGP neighbor connections\n"
10080 "Neighbor to display information about\n"
10081 "Neighbor to display information about\n"
10082 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010083
paul718e3742002-12-13 20:15:29 +000010084/* old command */
10085DEFUN (ipv6_mbgp_neighbor_advertised_route,
10086 ipv6_mbgp_neighbor_advertised_route_cmd,
10087 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10088 SHOW_STR
10089 IPV6_STR
10090 MBGP_STR
10091 "Detailed information on TCP and BGP neighbor connections\n"
10092 "Neighbor to display information about\n"
10093 "Neighbor to display information about\n"
10094 "Display the routes advertised to a BGP neighbor\n")
10095{
paulbb46e942003-10-24 19:02:03 +000010096 struct peer *peer;
10097
10098 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10099 if (! peer)
10100 return CMD_WARNING;
10101
10102 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010103}
10104#endif /* HAVE_IPV6 */
10105
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010106DEFUN (show_ip_bgp_view_neighbor_received_routes,
10107 show_ip_bgp_view_neighbor_received_routes_cmd,
10108 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10109 SHOW_STR
10110 IP_STR
10111 BGP_STR
10112 "BGP view\n"
10113 "View name\n"
10114 "Detailed information on TCP and BGP neighbor connections\n"
10115 "Neighbor to display information about\n"
10116 "Neighbor to display information about\n"
10117 "Display the received routes from neighbor\n")
10118{
10119 struct peer *peer;
10120
10121 if (argc == 2)
10122 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10123 else
10124 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10125
10126 if (! peer)
10127 return CMD_WARNING;
10128
10129 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10130}
10131
10132ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010133 show_ip_bgp_neighbor_received_routes_cmd,
10134 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10135 SHOW_STR
10136 IP_STR
10137 BGP_STR
10138 "Detailed information on TCP and BGP neighbor connections\n"
10139 "Neighbor to display information about\n"
10140 "Neighbor to display information about\n"
10141 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010142
10143DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10144 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10145 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10146 SHOW_STR
10147 IP_STR
10148 BGP_STR
10149 "Address family\n"
10150 "Address Family modifier\n"
10151 "Address Family modifier\n"
10152 "Detailed information on TCP and BGP neighbor connections\n"
10153 "Neighbor to display information about\n"
10154 "Neighbor to display information about\n"
10155 "Display the received routes from neighbor\n")
10156{
paulbb46e942003-10-24 19:02:03 +000010157 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010158
paulbb46e942003-10-24 19:02:03 +000010159 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10160 if (! peer)
10161 return CMD_WARNING;
10162
10163 if (strncmp (argv[0], "m", 1) == 0)
10164 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10165
10166 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010167}
10168
Michael Lambert95cbbd22010-07-23 14:43:04 -040010169DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10170 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10171#ifdef HAVE_IPV6
10172 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10173#else
10174 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10175#endif
10176 SHOW_STR
10177 BGP_STR
10178 "BGP view\n"
10179 "BGP view name\n"
10180 "Address family\n"
10181#ifdef HAVE_IPV6
10182 "Address family\n"
10183#endif
10184 "Address family modifier\n"
10185 "Address family modifier\n"
10186 "Detailed information on TCP and BGP neighbor connections\n"
10187 "Neighbor to display information about\n"
10188 "Neighbor to display information about\n"
10189 "Display the advertised routes to neighbor\n"
10190 "Display the received routes from neighbor\n")
10191{
10192 int afi;
10193 int safi;
10194 int in;
10195 struct peer *peer;
10196
10197#ifdef HAVE_IPV6
10198 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10199#else
10200 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10201#endif
10202
10203 if (! peer)
10204 return CMD_WARNING;
10205
10206#ifdef HAVE_IPV6
10207 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10208 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10209 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10210#else
10211 afi = AFI_IP;
10212 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10213 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10214#endif
10215
10216 return peer_adj_routes (vty, peer, afi, safi, in);
10217}
10218
paul718e3742002-12-13 20:15:29 +000010219DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10220 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10221 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10222 SHOW_STR
10223 IP_STR
10224 BGP_STR
10225 "Detailed information on TCP and BGP neighbor connections\n"
10226 "Neighbor to display information about\n"
10227 "Neighbor to display information about\n"
10228 "Display information received from a BGP neighbor\n"
10229 "Display the prefixlist filter\n")
10230{
10231 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010232 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010233 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010234 int count, ret;
paul718e3742002-12-13 20:15:29 +000010235
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010236 ret = str2sockunion (argv[0], &su);
10237 if (ret < 0)
10238 {
10239 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10240 return CMD_WARNING;
10241 }
paul718e3742002-12-13 20:15:29 +000010242
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010243 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010244 if (! peer)
10245 return CMD_WARNING;
10246
10247 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10248 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10249 if (count)
10250 {
10251 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10252 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10253 }
10254
10255 return CMD_SUCCESS;
10256}
10257
10258DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10259 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10260 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10261 SHOW_STR
10262 IP_STR
10263 BGP_STR
10264 "Address family\n"
10265 "Address Family modifier\n"
10266 "Address Family modifier\n"
10267 "Detailed information on TCP and BGP neighbor connections\n"
10268 "Neighbor to display information about\n"
10269 "Neighbor to display information about\n"
10270 "Display information received from a BGP neighbor\n"
10271 "Display the prefixlist filter\n")
10272{
10273 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010274 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010275 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010276 int count, ret;
paul718e3742002-12-13 20:15:29 +000010277
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010278 ret = str2sockunion (argv[1], &su);
10279 if (ret < 0)
10280 {
10281 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10282 return CMD_WARNING;
10283 }
paul718e3742002-12-13 20:15:29 +000010284
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010285 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010286 if (! peer)
10287 return CMD_WARNING;
10288
10289 if (strncmp (argv[0], "m", 1) == 0)
10290 {
10291 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10292 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10293 if (count)
10294 {
10295 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10296 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10297 }
10298 }
10299 else
10300 {
10301 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10302 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10303 if (count)
10304 {
10305 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10306 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10307 }
10308 }
10309
10310 return CMD_SUCCESS;
10311}
10312
10313
10314#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010315ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010316 show_bgp_neighbor_received_routes_cmd,
10317 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10318 SHOW_STR
10319 BGP_STR
10320 "Detailed information on TCP and BGP neighbor connections\n"
10321 "Neighbor to display information about\n"
10322 "Neighbor to display information about\n"
10323 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010324
paulbb46e942003-10-24 19:02:03 +000010325ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010326 show_bgp_ipv6_neighbor_received_routes_cmd,
10327 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10328 SHOW_STR
10329 BGP_STR
10330 "Address family\n"
10331 "Detailed information on TCP and BGP neighbor connections\n"
10332 "Neighbor to display information about\n"
10333 "Neighbor to display information about\n"
10334 "Display the received routes from neighbor\n")
10335
10336DEFUN (show_bgp_neighbor_received_prefix_filter,
10337 show_bgp_neighbor_received_prefix_filter_cmd,
10338 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10339 SHOW_STR
10340 BGP_STR
10341 "Detailed information on TCP and BGP neighbor connections\n"
10342 "Neighbor to display information about\n"
10343 "Neighbor to display information about\n"
10344 "Display information received from a BGP neighbor\n"
10345 "Display the prefixlist filter\n")
10346{
10347 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010348 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010349 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010350 int count, ret;
paul718e3742002-12-13 20:15:29 +000010351
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010352 ret = str2sockunion (argv[0], &su);
10353 if (ret < 0)
10354 {
10355 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10356 return CMD_WARNING;
10357 }
paul718e3742002-12-13 20:15:29 +000010358
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010359 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010360 if (! peer)
10361 return CMD_WARNING;
10362
10363 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10364 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10365 if (count)
10366 {
10367 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10368 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10369 }
10370
10371 return CMD_SUCCESS;
10372}
10373
10374ALIAS (show_bgp_neighbor_received_prefix_filter,
10375 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10376 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10377 SHOW_STR
10378 BGP_STR
10379 "Address family\n"
10380 "Detailed information on TCP and BGP neighbor connections\n"
10381 "Neighbor to display information about\n"
10382 "Neighbor to display information about\n"
10383 "Display information received from a BGP neighbor\n"
10384 "Display the prefixlist filter\n")
10385
10386/* old command */
paulbb46e942003-10-24 19:02:03 +000010387ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010388 ipv6_bgp_neighbor_received_routes_cmd,
10389 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10390 SHOW_STR
10391 IPV6_STR
10392 BGP_STR
10393 "Detailed information on TCP and BGP neighbor connections\n"
10394 "Neighbor to display information about\n"
10395 "Neighbor to display information about\n"
10396 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010397
10398/* old command */
10399DEFUN (ipv6_mbgp_neighbor_received_routes,
10400 ipv6_mbgp_neighbor_received_routes_cmd,
10401 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10402 SHOW_STR
10403 IPV6_STR
10404 MBGP_STR
10405 "Detailed information on TCP and BGP neighbor connections\n"
10406 "Neighbor to display information about\n"
10407 "Neighbor to display information about\n"
10408 "Display the received routes from neighbor\n")
10409{
paulbb46e942003-10-24 19:02:03 +000010410 struct peer *peer;
10411
10412 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10413 if (! peer)
10414 return CMD_WARNING;
10415
10416 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010417}
paulbb46e942003-10-24 19:02:03 +000010418
10419DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10420 show_bgp_view_neighbor_received_prefix_filter_cmd,
10421 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10422 SHOW_STR
10423 BGP_STR
10424 "BGP view\n"
10425 "View name\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 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010433 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010434 struct peer *peer;
10435 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010436 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010437
10438 /* BGP structure lookup. */
10439 bgp = bgp_lookup_by_name (argv[0]);
10440 if (bgp == NULL)
10441 {
10442 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10443 return CMD_WARNING;
10444 }
10445
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010446 ret = str2sockunion (argv[1], &su);
10447 if (ret < 0)
10448 {
10449 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10450 return CMD_WARNING;
10451 }
paulbb46e942003-10-24 19:02:03 +000010452
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010453 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010454 if (! peer)
10455 return CMD_WARNING;
10456
10457 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10458 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10459 if (count)
10460 {
10461 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10462 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10463 }
10464
10465 return CMD_SUCCESS;
10466}
10467
10468ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10469 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10470 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10471 SHOW_STR
10472 BGP_STR
10473 "BGP view\n"
10474 "View name\n"
10475 "Address family\n"
10476 "Detailed information on TCP and BGP neighbor connections\n"
10477 "Neighbor to display information about\n"
10478 "Neighbor to display information about\n"
10479 "Display information received from a BGP neighbor\n"
10480 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010481#endif /* HAVE_IPV6 */
10482
paul94f2b392005-06-28 12:44:16 +000010483static int
paulbb46e942003-10-24 19:02:03 +000010484bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010485 safi_t safi, enum bgp_show_type type)
10486{
paul718e3742002-12-13 20:15:29 +000010487 if (! peer || ! peer->afc[afi][safi])
10488 {
10489 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010490 return CMD_WARNING;
10491 }
10492
ajs5a646652004-11-05 01:25:55 +000010493 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010494}
10495
10496DEFUN (show_ip_bgp_neighbor_routes,
10497 show_ip_bgp_neighbor_routes_cmd,
10498 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10499 SHOW_STR
10500 IP_STR
10501 BGP_STR
10502 "Detailed information on TCP and BGP neighbor connections\n"
10503 "Neighbor to display information about\n"
10504 "Neighbor to display information about\n"
10505 "Display routes learned from neighbor\n")
10506{
paulbb46e942003-10-24 19:02:03 +000010507 struct peer *peer;
10508
10509 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10510 if (! peer)
10511 return CMD_WARNING;
10512
10513 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010514 bgp_show_type_neighbor);
10515}
10516
10517DEFUN (show_ip_bgp_neighbor_flap,
10518 show_ip_bgp_neighbor_flap_cmd,
10519 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10520 SHOW_STR
10521 IP_STR
10522 BGP_STR
10523 "Detailed information on TCP and BGP neighbor connections\n"
10524 "Neighbor to display information about\n"
10525 "Neighbor to display information about\n"
10526 "Display flap statistics of the routes learned from neighbor\n")
10527{
paulbb46e942003-10-24 19:02:03 +000010528 struct peer *peer;
10529
10530 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10531 if (! peer)
10532 return CMD_WARNING;
10533
10534 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010535 bgp_show_type_flap_neighbor);
10536}
10537
10538DEFUN (show_ip_bgp_neighbor_damp,
10539 show_ip_bgp_neighbor_damp_cmd,
10540 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10541 SHOW_STR
10542 IP_STR
10543 BGP_STR
10544 "Detailed information on TCP and BGP neighbor connections\n"
10545 "Neighbor to display information about\n"
10546 "Neighbor to display information about\n"
10547 "Display the dampened routes received from neighbor\n")
10548{
paulbb46e942003-10-24 19:02:03 +000010549 struct peer *peer;
10550
10551 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10552 if (! peer)
10553 return CMD_WARNING;
10554
10555 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010556 bgp_show_type_damp_neighbor);
10557}
10558
10559DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10560 show_ip_bgp_ipv4_neighbor_routes_cmd,
10561 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10562 SHOW_STR
10563 IP_STR
10564 BGP_STR
10565 "Address family\n"
10566 "Address Family modifier\n"
10567 "Address Family modifier\n"
10568 "Detailed information on TCP and BGP neighbor connections\n"
10569 "Neighbor to display information about\n"
10570 "Neighbor to display information about\n"
10571 "Display routes learned from neighbor\n")
10572{
paulbb46e942003-10-24 19:02:03 +000010573 struct peer *peer;
10574
10575 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10576 if (! peer)
10577 return CMD_WARNING;
10578
paul718e3742002-12-13 20:15:29 +000010579 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010580 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010581 bgp_show_type_neighbor);
10582
paulbb46e942003-10-24 19:02:03 +000010583 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010584 bgp_show_type_neighbor);
10585}
paulbb46e942003-10-24 19:02:03 +000010586
paulfee0f4c2004-09-13 05:12:46 +000010587DEFUN (show_ip_bgp_view_rsclient,
10588 show_ip_bgp_view_rsclient_cmd,
10589 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10590 SHOW_STR
10591 IP_STR
10592 BGP_STR
10593 "BGP view\n"
10594 "BGP view name\n"
10595 "Information about Route Server Client\n"
10596 NEIGHBOR_ADDR_STR)
10597{
10598 struct bgp_table *table;
10599 struct peer *peer;
10600
10601 if (argc == 2)
10602 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10603 else
10604 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10605
10606 if (! peer)
10607 return CMD_WARNING;
10608
10609 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10610 {
10611 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10612 VTY_NEWLINE);
10613 return CMD_WARNING;
10614 }
10615
10616 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10617 PEER_FLAG_RSERVER_CLIENT))
10618 {
10619 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10620 VTY_NEWLINE);
10621 return CMD_WARNING;
10622 }
10623
10624 table = peer->rib[AFI_IP][SAFI_UNICAST];
10625
ajs5a646652004-11-05 01:25:55 +000010626 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010627}
10628
10629ALIAS (show_ip_bgp_view_rsclient,
10630 show_ip_bgp_rsclient_cmd,
10631 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10632 SHOW_STR
10633 IP_STR
10634 BGP_STR
10635 "Information about Route Server Client\n"
10636 NEIGHBOR_ADDR_STR)
10637
Michael Lambert95cbbd22010-07-23 14:43:04 -040010638DEFUN (show_bgp_view_ipv4_safi_rsclient,
10639 show_bgp_view_ipv4_safi_rsclient_cmd,
10640 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10641 SHOW_STR
10642 BGP_STR
10643 "BGP view\n"
10644 "BGP view name\n"
10645 "Address family\n"
10646 "Address Family modifier\n"
10647 "Address Family modifier\n"
10648 "Information about Route Server Client\n"
10649 NEIGHBOR_ADDR_STR)
10650{
10651 struct bgp_table *table;
10652 struct peer *peer;
10653 safi_t safi;
10654
10655 if (argc == 3) {
10656 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10657 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10658 } else {
10659 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10660 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10661 }
10662
10663 if (! peer)
10664 return CMD_WARNING;
10665
10666 if (! peer->afc[AFI_IP][safi])
10667 {
10668 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10669 VTY_NEWLINE);
10670 return CMD_WARNING;
10671 }
10672
10673 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10674 PEER_FLAG_RSERVER_CLIENT))
10675 {
10676 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10677 VTY_NEWLINE);
10678 return CMD_WARNING;
10679 }
10680
10681 table = peer->rib[AFI_IP][safi];
10682
10683 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10684}
10685
10686ALIAS (show_bgp_view_ipv4_safi_rsclient,
10687 show_bgp_ipv4_safi_rsclient_cmd,
10688 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10689 SHOW_STR
10690 BGP_STR
10691 "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
paulfee0f4c2004-09-13 05:12:46 +000010697DEFUN (show_ip_bgp_view_rsclient_route,
10698 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010699 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010700 SHOW_STR
10701 IP_STR
10702 BGP_STR
10703 "BGP view\n"
10704 "BGP view name\n"
10705 "Information about Route Server Client\n"
10706 NEIGHBOR_ADDR_STR
10707 "Network in the BGP routing table to display\n")
10708{
10709 struct bgp *bgp;
10710 struct peer *peer;
10711
10712 /* BGP structure lookup. */
10713 if (argc == 3)
10714 {
10715 bgp = bgp_lookup_by_name (argv[0]);
10716 if (bgp == NULL)
10717 {
10718 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10719 return CMD_WARNING;
10720 }
10721 }
10722 else
10723 {
10724 bgp = bgp_get_default ();
10725 if (bgp == NULL)
10726 {
10727 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10728 return CMD_WARNING;
10729 }
10730 }
10731
10732 if (argc == 3)
10733 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10734 else
10735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10736
10737 if (! peer)
10738 return CMD_WARNING;
10739
10740 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10741 {
10742 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10743 VTY_NEWLINE);
10744 return CMD_WARNING;
10745}
10746
10747 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10748 PEER_FLAG_RSERVER_CLIENT))
10749 {
10750 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10751 VTY_NEWLINE);
10752 return CMD_WARNING;
10753 }
10754
10755 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10756 (argc == 3) ? argv[2] : argv[1],
10757 AFI_IP, SAFI_UNICAST, NULL, 0);
10758}
10759
10760ALIAS (show_ip_bgp_view_rsclient_route,
10761 show_ip_bgp_rsclient_route_cmd,
10762 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10763 SHOW_STR
10764 IP_STR
10765 BGP_STR
10766 "Information about Route Server Client\n"
10767 NEIGHBOR_ADDR_STR
10768 "Network in the BGP routing table to display\n")
10769
Michael Lambert95cbbd22010-07-23 14:43:04 -040010770DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10771 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10772 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10773 SHOW_STR
10774 BGP_STR
10775 "BGP view\n"
10776 "BGP view name\n"
10777 "Address family\n"
10778 "Address Family modifier\n"
10779 "Address Family modifier\n"
10780 "Information about Route Server Client\n"
10781 NEIGHBOR_ADDR_STR
10782 "Network in the BGP routing table to display\n")
10783{
10784 struct bgp *bgp;
10785 struct peer *peer;
10786 safi_t safi;
10787
10788 /* BGP structure lookup. */
10789 if (argc == 4)
10790 {
10791 bgp = bgp_lookup_by_name (argv[0]);
10792 if (bgp == NULL)
10793 {
10794 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10795 return CMD_WARNING;
10796 }
10797 }
10798 else
10799 {
10800 bgp = bgp_get_default ();
10801 if (bgp == NULL)
10802 {
10803 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10804 return CMD_WARNING;
10805 }
10806 }
10807
10808 if (argc == 4) {
10809 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10810 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10811 } else {
10812 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10813 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10814 }
10815
10816 if (! peer)
10817 return CMD_WARNING;
10818
10819 if (! peer->afc[AFI_IP][safi])
10820 {
10821 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10822 VTY_NEWLINE);
10823 return CMD_WARNING;
10824}
10825
10826 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10827 PEER_FLAG_RSERVER_CLIENT))
10828 {
10829 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10830 VTY_NEWLINE);
10831 return CMD_WARNING;
10832 }
10833
10834 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10835 (argc == 4) ? argv[3] : argv[2],
10836 AFI_IP, safi, NULL, 0);
10837}
10838
10839ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10840 show_bgp_ipv4_safi_rsclient_route_cmd,
10841 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10842 SHOW_STR
10843 BGP_STR
10844 "Address family\n"
10845 "Address Family modifier\n"
10846 "Address Family modifier\n"
10847 "Information about Route Server Client\n"
10848 NEIGHBOR_ADDR_STR
10849 "Network in the BGP routing table to display\n")
10850
paulfee0f4c2004-09-13 05:12:46 +000010851DEFUN (show_ip_bgp_view_rsclient_prefix,
10852 show_ip_bgp_view_rsclient_prefix_cmd,
10853 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10854 SHOW_STR
10855 IP_STR
10856 BGP_STR
10857 "BGP view\n"
10858 "BGP view name\n"
10859 "Information about Route Server Client\n"
10860 NEIGHBOR_ADDR_STR
10861 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10862{
10863 struct bgp *bgp;
10864 struct peer *peer;
10865
10866 /* BGP structure lookup. */
10867 if (argc == 3)
10868 {
10869 bgp = bgp_lookup_by_name (argv[0]);
10870 if (bgp == NULL)
10871 {
10872 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10873 return CMD_WARNING;
10874 }
10875 }
10876 else
10877 {
10878 bgp = bgp_get_default ();
10879 if (bgp == NULL)
10880 {
10881 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10882 return CMD_WARNING;
10883 }
10884 }
10885
10886 if (argc == 3)
10887 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10888 else
10889 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10890
10891 if (! peer)
10892 return CMD_WARNING;
10893
10894 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10895 {
10896 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10897 VTY_NEWLINE);
10898 return CMD_WARNING;
10899}
10900
10901 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10902 PEER_FLAG_RSERVER_CLIENT))
10903{
10904 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10905 VTY_NEWLINE);
10906 return CMD_WARNING;
10907 }
10908
10909 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10910 (argc == 3) ? argv[2] : argv[1],
10911 AFI_IP, SAFI_UNICAST, NULL, 1);
10912}
10913
10914ALIAS (show_ip_bgp_view_rsclient_prefix,
10915 show_ip_bgp_rsclient_prefix_cmd,
10916 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10917 SHOW_STR
10918 IP_STR
10919 BGP_STR
10920 "Information about Route Server Client\n"
10921 NEIGHBOR_ADDR_STR
10922 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10923
Michael Lambert95cbbd22010-07-23 14:43:04 -040010924DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10925 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10926 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10927 SHOW_STR
10928 BGP_STR
10929 "BGP view\n"
10930 "BGP view name\n"
10931 "Address family\n"
10932 "Address Family modifier\n"
10933 "Address Family modifier\n"
10934 "Information about Route Server Client\n"
10935 NEIGHBOR_ADDR_STR
10936 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10937{
10938 struct bgp *bgp;
10939 struct peer *peer;
10940 safi_t safi;
10941
10942 /* BGP structure lookup. */
10943 if (argc == 4)
10944 {
10945 bgp = bgp_lookup_by_name (argv[0]);
10946 if (bgp == NULL)
10947 {
10948 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10949 return CMD_WARNING;
10950 }
10951 }
10952 else
10953 {
10954 bgp = bgp_get_default ();
10955 if (bgp == NULL)
10956 {
10957 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10958 return CMD_WARNING;
10959 }
10960 }
10961
10962 if (argc == 4) {
10963 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10964 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10965 } else {
10966 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10967 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10968 }
10969
10970 if (! peer)
10971 return CMD_WARNING;
10972
10973 if (! peer->afc[AFI_IP][safi])
10974 {
10975 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10976 VTY_NEWLINE);
10977 return CMD_WARNING;
10978}
10979
10980 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10981 PEER_FLAG_RSERVER_CLIENT))
10982{
10983 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10984 VTY_NEWLINE);
10985 return CMD_WARNING;
10986 }
10987
10988 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10989 (argc == 4) ? argv[3] : argv[2],
10990 AFI_IP, safi, NULL, 1);
10991}
10992
10993ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10994 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10995 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10996 SHOW_STR
10997 BGP_STR
10998 "Address family\n"
10999 "Address Family modifier\n"
11000 "Address Family modifier\n"
11001 "Information about Route Server Client\n"
11002 NEIGHBOR_ADDR_STR
11003 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011004
paul718e3742002-12-13 20:15:29 +000011005#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011006DEFUN (show_bgp_view_neighbor_routes,
11007 show_bgp_view_neighbor_routes_cmd,
11008 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11009 SHOW_STR
11010 BGP_STR
11011 "BGP view\n"
11012 "BGP view name\n"
11013 "Detailed information on TCP and BGP neighbor connections\n"
11014 "Neighbor to display information about\n"
11015 "Neighbor to display information about\n"
11016 "Display routes learned from neighbor\n")
11017{
11018 struct peer *peer;
11019
11020 if (argc == 2)
11021 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11022 else
11023 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11024
11025 if (! peer)
11026 return CMD_WARNING;
11027
11028 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11029 bgp_show_type_neighbor);
11030}
11031
11032ALIAS (show_bgp_view_neighbor_routes,
11033 show_bgp_view_ipv6_neighbor_routes_cmd,
11034 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11035 SHOW_STR
11036 BGP_STR
11037 "BGP view\n"
11038 "BGP view name\n"
11039 "Address family\n"
11040 "Detailed information on TCP and BGP neighbor connections\n"
11041 "Neighbor to display information about\n"
11042 "Neighbor to display information about\n"
11043 "Display routes learned from neighbor\n")
11044
11045DEFUN (show_bgp_view_neighbor_damp,
11046 show_bgp_view_neighbor_damp_cmd,
11047 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11048 SHOW_STR
11049 BGP_STR
11050 "BGP view\n"
11051 "BGP view name\n"
11052 "Detailed information on TCP and BGP neighbor connections\n"
11053 "Neighbor to display information about\n"
11054 "Neighbor to display information about\n"
11055 "Display the dampened routes received from neighbor\n")
11056{
11057 struct peer *peer;
11058
11059 if (argc == 2)
11060 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11061 else
11062 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11063
11064 if (! peer)
11065 return CMD_WARNING;
11066
11067 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11068 bgp_show_type_damp_neighbor);
11069}
11070
11071ALIAS (show_bgp_view_neighbor_damp,
11072 show_bgp_view_ipv6_neighbor_damp_cmd,
11073 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11074 SHOW_STR
11075 BGP_STR
11076 "BGP view\n"
11077 "BGP view name\n"
11078 "Address family\n"
11079 "Detailed information on TCP and BGP neighbor connections\n"
11080 "Neighbor to display information about\n"
11081 "Neighbor to display information about\n"
11082 "Display the dampened routes received from neighbor\n")
11083
11084DEFUN (show_bgp_view_neighbor_flap,
11085 show_bgp_view_neighbor_flap_cmd,
11086 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11087 SHOW_STR
11088 BGP_STR
11089 "BGP view\n"
11090 "BGP view name\n"
11091 "Detailed information on TCP and BGP neighbor connections\n"
11092 "Neighbor to display information about\n"
11093 "Neighbor to display information about\n"
11094 "Display flap statistics of the routes learned from neighbor\n")
11095{
11096 struct peer *peer;
11097
11098 if (argc == 2)
11099 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11100 else
11101 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11102
11103 if (! peer)
11104 return CMD_WARNING;
11105
11106 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11107 bgp_show_type_flap_neighbor);
11108}
11109
11110ALIAS (show_bgp_view_neighbor_flap,
11111 show_bgp_view_ipv6_neighbor_flap_cmd,
11112 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11113 SHOW_STR
11114 BGP_STR
11115 "BGP view\n"
11116 "BGP view name\n"
11117 "Address family\n"
11118 "Detailed information on TCP and BGP neighbor connections\n"
11119 "Neighbor to display information about\n"
11120 "Neighbor to display information about\n"
11121 "Display flap statistics of the routes learned from neighbor\n")
11122
11123ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011124 show_bgp_neighbor_routes_cmd,
11125 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11126 SHOW_STR
11127 BGP_STR
11128 "Detailed information on TCP and BGP neighbor connections\n"
11129 "Neighbor to display information about\n"
11130 "Neighbor to display information about\n"
11131 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011132
paulbb46e942003-10-24 19:02:03 +000011133
11134ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011135 show_bgp_ipv6_neighbor_routes_cmd,
11136 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11137 SHOW_STR
11138 BGP_STR
11139 "Address family\n"
11140 "Detailed information on TCP and BGP neighbor connections\n"
11141 "Neighbor to display information about\n"
11142 "Neighbor to display information about\n"
11143 "Display routes learned from neighbor\n")
11144
11145/* old command */
paulbb46e942003-10-24 19:02:03 +000011146ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011147 ipv6_bgp_neighbor_routes_cmd,
11148 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11149 SHOW_STR
11150 IPV6_STR
11151 BGP_STR
11152 "Detailed information on TCP and BGP neighbor connections\n"
11153 "Neighbor to display information about\n"
11154 "Neighbor to display information about\n"
11155 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011156
11157/* old command */
11158DEFUN (ipv6_mbgp_neighbor_routes,
11159 ipv6_mbgp_neighbor_routes_cmd,
11160 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11161 SHOW_STR
11162 IPV6_STR
11163 MBGP_STR
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 routes learned from neighbor\n")
11168{
paulbb46e942003-10-24 19:02:03 +000011169 struct peer *peer;
11170
11171 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11172 if (! peer)
11173 return CMD_WARNING;
11174
11175 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011176 bgp_show_type_neighbor);
11177}
paulbb46e942003-10-24 19:02:03 +000011178
11179ALIAS (show_bgp_view_neighbor_flap,
11180 show_bgp_neighbor_flap_cmd,
11181 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11182 SHOW_STR
11183 BGP_STR
11184 "Detailed information on TCP and BGP neighbor connections\n"
11185 "Neighbor to display information about\n"
11186 "Neighbor to display information about\n"
11187 "Display flap statistics of the routes learned from neighbor\n")
11188
11189ALIAS (show_bgp_view_neighbor_flap,
11190 show_bgp_ipv6_neighbor_flap_cmd,
11191 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11192 SHOW_STR
11193 BGP_STR
11194 "Address family\n"
11195 "Detailed information on TCP and BGP neighbor connections\n"
11196 "Neighbor to display information about\n"
11197 "Neighbor to display information about\n"
11198 "Display flap statistics of the routes learned from neighbor\n")
11199
11200ALIAS (show_bgp_view_neighbor_damp,
11201 show_bgp_neighbor_damp_cmd,
11202 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11203 SHOW_STR
11204 BGP_STR
11205 "Detailed information on TCP and BGP neighbor connections\n"
11206 "Neighbor to display information about\n"
11207 "Neighbor to display information about\n"
11208 "Display the dampened routes received from neighbor\n")
11209
11210ALIAS (show_bgp_view_neighbor_damp,
11211 show_bgp_ipv6_neighbor_damp_cmd,
11212 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11213 SHOW_STR
11214 BGP_STR
11215 "Address family\n"
11216 "Detailed information on TCP and BGP neighbor connections\n"
11217 "Neighbor to display information about\n"
11218 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011219 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011220
11221DEFUN (show_bgp_view_rsclient,
11222 show_bgp_view_rsclient_cmd,
11223 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11224 SHOW_STR
11225 BGP_STR
11226 "BGP view\n"
11227 "BGP view name\n"
11228 "Information about Route Server Client\n"
11229 NEIGHBOR_ADDR_STR)
11230{
11231 struct bgp_table *table;
11232 struct peer *peer;
11233
11234 if (argc == 2)
11235 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11236 else
11237 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11238
11239 if (! peer)
11240 return CMD_WARNING;
11241
11242 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11243 {
11244 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11245 VTY_NEWLINE);
11246 return CMD_WARNING;
11247 }
11248
11249 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11250 PEER_FLAG_RSERVER_CLIENT))
11251 {
11252 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11253 VTY_NEWLINE);
11254 return CMD_WARNING;
11255 }
11256
11257 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11258
ajs5a646652004-11-05 01:25:55 +000011259 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011260}
11261
11262ALIAS (show_bgp_view_rsclient,
11263 show_bgp_rsclient_cmd,
11264 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11265 SHOW_STR
11266 BGP_STR
11267 "Information about Route Server Client\n"
11268 NEIGHBOR_ADDR_STR)
11269
Michael Lambert95cbbd22010-07-23 14:43:04 -040011270DEFUN (show_bgp_view_ipv6_safi_rsclient,
11271 show_bgp_view_ipv6_safi_rsclient_cmd,
11272 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11273 SHOW_STR
11274 BGP_STR
11275 "BGP view\n"
11276 "BGP view name\n"
11277 "Address family\n"
11278 "Address Family modifier\n"
11279 "Address Family modifier\n"
11280 "Information about Route Server Client\n"
11281 NEIGHBOR_ADDR_STR)
11282{
11283 struct bgp_table *table;
11284 struct peer *peer;
11285 safi_t safi;
11286
11287 if (argc == 3) {
11288 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11289 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11290 } else {
11291 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11292 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11293 }
11294
11295 if (! peer)
11296 return CMD_WARNING;
11297
11298 if (! peer->afc[AFI_IP6][safi])
11299 {
11300 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11301 VTY_NEWLINE);
11302 return CMD_WARNING;
11303 }
11304
11305 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11306 PEER_FLAG_RSERVER_CLIENT))
11307 {
11308 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11309 VTY_NEWLINE);
11310 return CMD_WARNING;
11311 }
11312
11313 table = peer->rib[AFI_IP6][safi];
11314
11315 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11316}
11317
11318ALIAS (show_bgp_view_ipv6_safi_rsclient,
11319 show_bgp_ipv6_safi_rsclient_cmd,
11320 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11321 SHOW_STR
11322 BGP_STR
11323 "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
paulfee0f4c2004-09-13 05:12:46 +000011329DEFUN (show_bgp_view_rsclient_route,
11330 show_bgp_view_rsclient_route_cmd,
11331 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11332 SHOW_STR
11333 BGP_STR
11334 "BGP view\n"
11335 "BGP view name\n"
11336 "Information about Route Server Client\n"
11337 NEIGHBOR_ADDR_STR
11338 "Network in the BGP routing table to display\n")
11339{
11340 struct bgp *bgp;
11341 struct peer *peer;
11342
11343 /* BGP structure lookup. */
11344 if (argc == 3)
11345 {
11346 bgp = bgp_lookup_by_name (argv[0]);
11347 if (bgp == NULL)
11348 {
11349 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11350 return CMD_WARNING;
11351 }
11352 }
11353 else
11354 {
11355 bgp = bgp_get_default ();
11356 if (bgp == NULL)
11357 {
11358 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11359 return CMD_WARNING;
11360 }
11361 }
11362
11363 if (argc == 3)
11364 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11365 else
11366 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11367
11368 if (! peer)
11369 return CMD_WARNING;
11370
11371 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11372 {
11373 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11374 VTY_NEWLINE);
11375 return CMD_WARNING;
11376 }
11377
11378 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11379 PEER_FLAG_RSERVER_CLIENT))
11380 {
11381 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11382 VTY_NEWLINE);
11383 return CMD_WARNING;
11384 }
11385
11386 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11387 (argc == 3) ? argv[2] : argv[1],
11388 AFI_IP6, SAFI_UNICAST, NULL, 0);
11389}
11390
11391ALIAS (show_bgp_view_rsclient_route,
11392 show_bgp_rsclient_route_cmd,
11393 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11394 SHOW_STR
11395 BGP_STR
11396 "Information about Route Server Client\n"
11397 NEIGHBOR_ADDR_STR
11398 "Network in the BGP routing table to display\n")
11399
Michael Lambert95cbbd22010-07-23 14:43:04 -040011400DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11401 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11402 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11403 SHOW_STR
11404 BGP_STR
11405 "BGP view\n"
11406 "BGP view name\n"
11407 "Address family\n"
11408 "Address Family modifier\n"
11409 "Address Family modifier\n"
11410 "Information about Route Server Client\n"
11411 NEIGHBOR_ADDR_STR
11412 "Network in the BGP routing table to display\n")
11413{
11414 struct bgp *bgp;
11415 struct peer *peer;
11416 safi_t safi;
11417
11418 /* BGP structure lookup. */
11419 if (argc == 4)
11420 {
11421 bgp = bgp_lookup_by_name (argv[0]);
11422 if (bgp == NULL)
11423 {
11424 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11425 return CMD_WARNING;
11426 }
11427 }
11428 else
11429 {
11430 bgp = bgp_get_default ();
11431 if (bgp == NULL)
11432 {
11433 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11434 return CMD_WARNING;
11435 }
11436 }
11437
11438 if (argc == 4) {
11439 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11440 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11441 } else {
11442 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11443 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11444 }
11445
11446 if (! peer)
11447 return CMD_WARNING;
11448
11449 if (! peer->afc[AFI_IP6][safi])
11450 {
11451 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11452 VTY_NEWLINE);
11453 return CMD_WARNING;
11454}
11455
11456 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11457 PEER_FLAG_RSERVER_CLIENT))
11458 {
11459 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11460 VTY_NEWLINE);
11461 return CMD_WARNING;
11462 }
11463
11464 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11465 (argc == 4) ? argv[3] : argv[2],
11466 AFI_IP6, safi, NULL, 0);
11467}
11468
11469ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11470 show_bgp_ipv6_safi_rsclient_route_cmd,
11471 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11472 SHOW_STR
11473 BGP_STR
11474 "Address family\n"
11475 "Address Family modifier\n"
11476 "Address Family modifier\n"
11477 "Information about Route Server Client\n"
11478 NEIGHBOR_ADDR_STR
11479 "Network in the BGP routing table to display\n")
11480
paulfee0f4c2004-09-13 05:12:46 +000011481DEFUN (show_bgp_view_rsclient_prefix,
11482 show_bgp_view_rsclient_prefix_cmd,
11483 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11484 SHOW_STR
11485 BGP_STR
11486 "BGP view\n"
11487 "BGP view name\n"
11488 "Information about Route Server Client\n"
11489 NEIGHBOR_ADDR_STR
11490 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11491{
11492 struct bgp *bgp;
11493 struct peer *peer;
11494
11495 /* BGP structure lookup. */
11496 if (argc == 3)
11497 {
11498 bgp = bgp_lookup_by_name (argv[0]);
11499 if (bgp == NULL)
11500 {
11501 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11502 return CMD_WARNING;
11503 }
11504 }
11505 else
11506 {
11507 bgp = bgp_get_default ();
11508 if (bgp == NULL)
11509 {
11510 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11511 return CMD_WARNING;
11512 }
11513 }
11514
11515 if (argc == 3)
11516 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11517 else
11518 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11519
11520 if (! peer)
11521 return CMD_WARNING;
11522
11523 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11524 {
11525 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11526 VTY_NEWLINE);
11527 return CMD_WARNING;
11528 }
11529
11530 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11531 PEER_FLAG_RSERVER_CLIENT))
11532 {
11533 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11534 VTY_NEWLINE);
11535 return CMD_WARNING;
11536 }
11537
11538 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11539 (argc == 3) ? argv[2] : argv[1],
11540 AFI_IP6, SAFI_UNICAST, NULL, 1);
11541}
11542
11543ALIAS (show_bgp_view_rsclient_prefix,
11544 show_bgp_rsclient_prefix_cmd,
11545 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11546 SHOW_STR
11547 BGP_STR
11548 "Information about Route Server Client\n"
11549 NEIGHBOR_ADDR_STR
11550 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11551
Michael Lambert95cbbd22010-07-23 14:43:04 -040011552DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11553 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11554 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11555 SHOW_STR
11556 BGP_STR
11557 "BGP view\n"
11558 "BGP view name\n"
11559 "Address family\n"
11560 "Address Family modifier\n"
11561 "Address Family modifier\n"
11562 "Information about Route Server Client\n"
11563 NEIGHBOR_ADDR_STR
11564 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11565{
11566 struct bgp *bgp;
11567 struct peer *peer;
11568 safi_t safi;
11569
11570 /* BGP structure lookup. */
11571 if (argc == 4)
11572 {
11573 bgp = bgp_lookup_by_name (argv[0]);
11574 if (bgp == NULL)
11575 {
11576 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11577 return CMD_WARNING;
11578 }
11579 }
11580 else
11581 {
11582 bgp = bgp_get_default ();
11583 if (bgp == NULL)
11584 {
11585 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11586 return CMD_WARNING;
11587 }
11588 }
11589
11590 if (argc == 4) {
11591 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11592 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11593 } else {
11594 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11595 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11596 }
11597
11598 if (! peer)
11599 return CMD_WARNING;
11600
11601 if (! peer->afc[AFI_IP6][safi])
11602 {
11603 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11604 VTY_NEWLINE);
11605 return CMD_WARNING;
11606}
11607
11608 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11609 PEER_FLAG_RSERVER_CLIENT))
11610{
11611 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11612 VTY_NEWLINE);
11613 return CMD_WARNING;
11614 }
11615
11616 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11617 (argc == 4) ? argv[3] : argv[2],
11618 AFI_IP6, safi, NULL, 1);
11619}
11620
11621ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11622 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11623 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11624 SHOW_STR
11625 BGP_STR
11626 "Address family\n"
11627 "Address Family modifier\n"
11628 "Address Family modifier\n"
11629 "Information about Route Server Client\n"
11630 NEIGHBOR_ADDR_STR
11631 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11632
paul718e3742002-12-13 20:15:29 +000011633#endif /* HAVE_IPV6 */
11634
11635struct bgp_table *bgp_distance_table;
11636
11637struct bgp_distance
11638{
11639 /* Distance value for the IP source prefix. */
11640 u_char distance;
11641
11642 /* Name of the access-list to be matched. */
11643 char *access_list;
11644};
11645
paul94f2b392005-06-28 12:44:16 +000011646static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011647bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011648{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011649 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011650}
11651
paul94f2b392005-06-28 12:44:16 +000011652static void
paul718e3742002-12-13 20:15:29 +000011653bgp_distance_free (struct bgp_distance *bdistance)
11654{
11655 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11656}
11657
paul94f2b392005-06-28 12:44:16 +000011658static int
paulfd79ac92004-10-13 05:06:08 +000011659bgp_distance_set (struct vty *vty, const char *distance_str,
11660 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011661{
11662 int ret;
11663 struct prefix_ipv4 p;
11664 u_char distance;
11665 struct bgp_node *rn;
11666 struct bgp_distance *bdistance;
11667
11668 ret = str2prefix_ipv4 (ip_str, &p);
11669 if (ret == 0)
11670 {
11671 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11672 return CMD_WARNING;
11673 }
11674
11675 distance = atoi (distance_str);
11676
11677 /* Get BGP distance node. */
11678 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11679 if (rn->info)
11680 {
11681 bdistance = rn->info;
11682 bgp_unlock_node (rn);
11683 }
11684 else
11685 {
11686 bdistance = bgp_distance_new ();
11687 rn->info = bdistance;
11688 }
11689
11690 /* Set distance value. */
11691 bdistance->distance = distance;
11692
11693 /* Reset access-list configuration. */
11694 if (bdistance->access_list)
11695 {
11696 free (bdistance->access_list);
11697 bdistance->access_list = NULL;
11698 }
11699 if (access_list_str)
11700 bdistance->access_list = strdup (access_list_str);
11701
11702 return CMD_SUCCESS;
11703}
11704
paul94f2b392005-06-28 12:44:16 +000011705static int
paulfd79ac92004-10-13 05:06:08 +000011706bgp_distance_unset (struct vty *vty, const char *distance_str,
11707 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011708{
11709 int ret;
11710 struct prefix_ipv4 p;
11711 u_char distance;
11712 struct bgp_node *rn;
11713 struct bgp_distance *bdistance;
11714
11715 ret = str2prefix_ipv4 (ip_str, &p);
11716 if (ret == 0)
11717 {
11718 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11719 return CMD_WARNING;
11720 }
11721
11722 distance = atoi (distance_str);
11723
11724 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11725 if (! rn)
11726 {
11727 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11728 return CMD_WARNING;
11729 }
11730
11731 bdistance = rn->info;
11732
11733 if (bdistance->access_list)
11734 free (bdistance->access_list);
11735 bgp_distance_free (bdistance);
11736
11737 rn->info = NULL;
11738 bgp_unlock_node (rn);
11739 bgp_unlock_node (rn);
11740
11741 return CMD_SUCCESS;
11742}
11743
paul718e3742002-12-13 20:15:29 +000011744/* Apply BGP information to distance method. */
11745u_char
11746bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11747{
11748 struct bgp_node *rn;
11749 struct prefix_ipv4 q;
11750 struct peer *peer;
11751 struct bgp_distance *bdistance;
11752 struct access_list *alist;
11753 struct bgp_static *bgp_static;
11754
11755 if (! bgp)
11756 return 0;
11757
11758 if (p->family != AF_INET)
11759 return 0;
11760
11761 peer = rinfo->peer;
11762
11763 if (peer->su.sa.sa_family != AF_INET)
11764 return 0;
11765
11766 memset (&q, 0, sizeof (struct prefix_ipv4));
11767 q.family = AF_INET;
11768 q.prefix = peer->su.sin.sin_addr;
11769 q.prefixlen = IPV4_MAX_BITLEN;
11770
11771 /* Check source address. */
11772 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11773 if (rn)
11774 {
11775 bdistance = rn->info;
11776 bgp_unlock_node (rn);
11777
11778 if (bdistance->access_list)
11779 {
11780 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11781 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11782 return bdistance->distance;
11783 }
11784 else
11785 return bdistance->distance;
11786 }
11787
11788 /* Backdoor check. */
11789 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11790 if (rn)
11791 {
11792 bgp_static = rn->info;
11793 bgp_unlock_node (rn);
11794
11795 if (bgp_static->backdoor)
11796 {
11797 if (bgp->distance_local)
11798 return bgp->distance_local;
11799 else
11800 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11801 }
11802 }
11803
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011804 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011805 {
11806 if (bgp->distance_ebgp)
11807 return bgp->distance_ebgp;
11808 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11809 }
11810 else
11811 {
11812 if (bgp->distance_ibgp)
11813 return bgp->distance_ibgp;
11814 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11815 }
11816}
11817
11818DEFUN (bgp_distance,
11819 bgp_distance_cmd,
11820 "distance bgp <1-255> <1-255> <1-255>",
11821 "Define an administrative distance\n"
11822 "BGP distance\n"
11823 "Distance for routes external to the AS\n"
11824 "Distance for routes internal to the AS\n"
11825 "Distance for local routes\n")
11826{
11827 struct bgp *bgp;
11828
11829 bgp = vty->index;
11830
11831 bgp->distance_ebgp = atoi (argv[0]);
11832 bgp->distance_ibgp = atoi (argv[1]);
11833 bgp->distance_local = atoi (argv[2]);
11834 return CMD_SUCCESS;
11835}
11836
11837DEFUN (no_bgp_distance,
11838 no_bgp_distance_cmd,
11839 "no distance bgp <1-255> <1-255> <1-255>",
11840 NO_STR
11841 "Define an administrative distance\n"
11842 "BGP distance\n"
11843 "Distance for routes external to the AS\n"
11844 "Distance for routes internal to the AS\n"
11845 "Distance for local routes\n")
11846{
11847 struct bgp *bgp;
11848
11849 bgp = vty->index;
11850
11851 bgp->distance_ebgp= 0;
11852 bgp->distance_ibgp = 0;
11853 bgp->distance_local = 0;
11854 return CMD_SUCCESS;
11855}
11856
11857ALIAS (no_bgp_distance,
11858 no_bgp_distance2_cmd,
11859 "no distance bgp",
11860 NO_STR
11861 "Define an administrative distance\n"
11862 "BGP distance\n")
11863
11864DEFUN (bgp_distance_source,
11865 bgp_distance_source_cmd,
11866 "distance <1-255> A.B.C.D/M",
11867 "Define an administrative distance\n"
11868 "Administrative distance\n"
11869 "IP source prefix\n")
11870{
11871 bgp_distance_set (vty, argv[0], argv[1], NULL);
11872 return CMD_SUCCESS;
11873}
11874
11875DEFUN (no_bgp_distance_source,
11876 no_bgp_distance_source_cmd,
11877 "no distance <1-255> A.B.C.D/M",
11878 NO_STR
11879 "Define an administrative distance\n"
11880 "Administrative distance\n"
11881 "IP source prefix\n")
11882{
11883 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11884 return CMD_SUCCESS;
11885}
11886
11887DEFUN (bgp_distance_source_access_list,
11888 bgp_distance_source_access_list_cmd,
11889 "distance <1-255> A.B.C.D/M WORD",
11890 "Define an administrative distance\n"
11891 "Administrative distance\n"
11892 "IP source prefix\n"
11893 "Access list name\n")
11894{
11895 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11896 return CMD_SUCCESS;
11897}
11898
11899DEFUN (no_bgp_distance_source_access_list,
11900 no_bgp_distance_source_access_list_cmd,
11901 "no distance <1-255> A.B.C.D/M WORD",
11902 NO_STR
11903 "Define an administrative distance\n"
11904 "Administrative distance\n"
11905 "IP source prefix\n"
11906 "Access list name\n")
11907{
11908 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11909 return CMD_SUCCESS;
11910}
11911
11912DEFUN (bgp_damp_set,
11913 bgp_damp_set_cmd,
11914 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11915 "BGP Specific commands\n"
11916 "Enable route-flap dampening\n"
11917 "Half-life time for the penalty\n"
11918 "Value to start reusing a route\n"
11919 "Value to start suppressing a route\n"
11920 "Maximum duration to suppress a stable route\n")
11921{
11922 struct bgp *bgp;
11923 int half = DEFAULT_HALF_LIFE * 60;
11924 int reuse = DEFAULT_REUSE;
11925 int suppress = DEFAULT_SUPPRESS;
11926 int max = 4 * half;
11927
11928 if (argc == 4)
11929 {
11930 half = atoi (argv[0]) * 60;
11931 reuse = atoi (argv[1]);
11932 suppress = atoi (argv[2]);
11933 max = atoi (argv[3]) * 60;
11934 }
11935 else if (argc == 1)
11936 {
11937 half = atoi (argv[0]) * 60;
11938 max = 4 * half;
11939 }
11940
11941 bgp = vty->index;
11942 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11943 half, reuse, suppress, max);
11944}
11945
11946ALIAS (bgp_damp_set,
11947 bgp_damp_set2_cmd,
11948 "bgp dampening <1-45>",
11949 "BGP Specific commands\n"
11950 "Enable route-flap dampening\n"
11951 "Half-life time for the penalty\n")
11952
11953ALIAS (bgp_damp_set,
11954 bgp_damp_set3_cmd,
11955 "bgp dampening",
11956 "BGP Specific commands\n"
11957 "Enable route-flap dampening\n")
11958
11959DEFUN (bgp_damp_unset,
11960 bgp_damp_unset_cmd,
11961 "no bgp dampening",
11962 NO_STR
11963 "BGP Specific commands\n"
11964 "Enable route-flap dampening\n")
11965{
11966 struct bgp *bgp;
11967
11968 bgp = vty->index;
11969 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11970}
11971
11972ALIAS (bgp_damp_unset,
11973 bgp_damp_unset2_cmd,
11974 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11975 NO_STR
11976 "BGP Specific commands\n"
11977 "Enable route-flap dampening\n"
11978 "Half-life time for the penalty\n"
11979 "Value to start reusing a route\n"
11980 "Value to start suppressing a route\n"
11981 "Maximum duration to suppress a stable route\n")
11982
11983DEFUN (show_ip_bgp_dampened_paths,
11984 show_ip_bgp_dampened_paths_cmd,
11985 "show ip bgp dampened-paths",
11986 SHOW_STR
11987 IP_STR
11988 BGP_STR
11989 "Display paths suppressed due to dampening\n")
11990{
ajs5a646652004-11-05 01:25:55 +000011991 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11992 NULL);
paul718e3742002-12-13 20:15:29 +000011993}
11994
11995DEFUN (show_ip_bgp_flap_statistics,
11996 show_ip_bgp_flap_statistics_cmd,
11997 "show ip bgp flap-statistics",
11998 SHOW_STR
11999 IP_STR
12000 BGP_STR
12001 "Display flap statistics of routes\n")
12002{
ajs5a646652004-11-05 01:25:55 +000012003 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12004 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012005}
12006
12007/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012008static int
paulfd79ac92004-10-13 05:06:08 +000012009bgp_clear_damp_route (struct vty *vty, const char *view_name,
12010 const char *ip_str, afi_t afi, safi_t safi,
12011 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012012{
12013 int ret;
12014 struct prefix match;
12015 struct bgp_node *rn;
12016 struct bgp_node *rm;
12017 struct bgp_info *ri;
12018 struct bgp_info *ri_temp;
12019 struct bgp *bgp;
12020 struct bgp_table *table;
12021
12022 /* BGP structure lookup. */
12023 if (view_name)
12024 {
12025 bgp = bgp_lookup_by_name (view_name);
12026 if (bgp == NULL)
12027 {
12028 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12029 return CMD_WARNING;
12030 }
12031 }
12032 else
12033 {
12034 bgp = bgp_get_default ();
12035 if (bgp == NULL)
12036 {
12037 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12038 return CMD_WARNING;
12039 }
12040 }
12041
12042 /* Check IP address argument. */
12043 ret = str2prefix (ip_str, &match);
12044 if (! ret)
12045 {
12046 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12047 return CMD_WARNING;
12048 }
12049
12050 match.family = afi2family (afi);
12051
12052 if (safi == SAFI_MPLS_VPN)
12053 {
12054 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12055 {
12056 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12057 continue;
12058
12059 if ((table = rn->info) != NULL)
12060 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012061 {
12062 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12063 {
12064 ri = rm->info;
12065 while (ri)
12066 {
12067 if (ri->extra && ri->extra->damp_info)
12068 {
12069 ri_temp = ri->next;
12070 bgp_damp_info_free (ri->extra->damp_info, 1);
12071 ri = ri_temp;
12072 }
12073 else
12074 ri = ri->next;
12075 }
12076 }
12077
12078 bgp_unlock_node (rm);
12079 }
paul718e3742002-12-13 20:15:29 +000012080 }
12081 }
12082 else
12083 {
12084 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012085 {
12086 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12087 {
12088 ri = rn->info;
12089 while (ri)
12090 {
12091 if (ri->extra && ri->extra->damp_info)
12092 {
12093 ri_temp = ri->next;
12094 bgp_damp_info_free (ri->extra->damp_info, 1);
12095 ri = ri_temp;
12096 }
12097 else
12098 ri = ri->next;
12099 }
12100 }
12101
12102 bgp_unlock_node (rn);
12103 }
paul718e3742002-12-13 20:15:29 +000012104 }
12105
12106 return CMD_SUCCESS;
12107}
12108
12109DEFUN (clear_ip_bgp_dampening,
12110 clear_ip_bgp_dampening_cmd,
12111 "clear ip bgp dampening",
12112 CLEAR_STR
12113 IP_STR
12114 BGP_STR
12115 "Clear route flap dampening information\n")
12116{
12117 bgp_damp_info_clean ();
12118 return CMD_SUCCESS;
12119}
12120
12121DEFUN (clear_ip_bgp_dampening_prefix,
12122 clear_ip_bgp_dampening_prefix_cmd,
12123 "clear ip bgp dampening A.B.C.D/M",
12124 CLEAR_STR
12125 IP_STR
12126 BGP_STR
12127 "Clear route flap dampening information\n"
12128 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12129{
12130 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12131 SAFI_UNICAST, NULL, 1);
12132}
12133
12134DEFUN (clear_ip_bgp_dampening_address,
12135 clear_ip_bgp_dampening_address_cmd,
12136 "clear ip bgp dampening A.B.C.D",
12137 CLEAR_STR
12138 IP_STR
12139 BGP_STR
12140 "Clear route flap dampening information\n"
12141 "Network to clear damping information\n")
12142{
12143 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12144 SAFI_UNICAST, NULL, 0);
12145}
12146
12147DEFUN (clear_ip_bgp_dampening_address_mask,
12148 clear_ip_bgp_dampening_address_mask_cmd,
12149 "clear ip bgp dampening A.B.C.D A.B.C.D",
12150 CLEAR_STR
12151 IP_STR
12152 BGP_STR
12153 "Clear route flap dampening information\n"
12154 "Network to clear damping information\n"
12155 "Network mask\n")
12156{
12157 int ret;
12158 char prefix_str[BUFSIZ];
12159
12160 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12161 if (! ret)
12162 {
12163 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12164 return CMD_WARNING;
12165 }
12166
12167 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12168 SAFI_UNICAST, NULL, 0);
12169}
12170
paul94f2b392005-06-28 12:44:16 +000012171static int
paul718e3742002-12-13 20:15:29 +000012172bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12173 afi_t afi, safi_t safi, int *write)
12174{
12175 struct bgp_node *prn;
12176 struct bgp_node *rn;
12177 struct bgp_table *table;
12178 struct prefix *p;
12179 struct prefix_rd *prd;
12180 struct bgp_static *bgp_static;
12181 u_int32_t label;
12182 char buf[SU_ADDRSTRLEN];
12183 char rdbuf[RD_ADDRSTRLEN];
12184
12185 /* Network configuration. */
12186 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12187 if ((table = prn->info) != NULL)
12188 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12189 if ((bgp_static = rn->info) != NULL)
12190 {
12191 p = &rn->p;
12192 prd = (struct prefix_rd *) &prn->p;
12193
12194 /* "address-family" display. */
12195 bgp_config_write_family_header (vty, afi, safi, write);
12196
12197 /* "network" configuration display. */
12198 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12199 label = decode_label (bgp_static->tag);
12200
12201 vty_out (vty, " network %s/%d rd %s tag %d",
12202 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12203 p->prefixlen,
12204 rdbuf, label);
12205 vty_out (vty, "%s", VTY_NEWLINE);
12206 }
12207 return 0;
12208}
12209
12210/* Configuration of static route announcement and aggregate
12211 information. */
12212int
12213bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12214 afi_t afi, safi_t safi, int *write)
12215{
12216 struct bgp_node *rn;
12217 struct prefix *p;
12218 struct bgp_static *bgp_static;
12219 struct bgp_aggregate *bgp_aggregate;
12220 char buf[SU_ADDRSTRLEN];
12221
12222 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12223 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12224
12225 /* Network configuration. */
12226 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12227 if ((bgp_static = rn->info) != NULL)
12228 {
12229 p = &rn->p;
12230
12231 /* "address-family" display. */
12232 bgp_config_write_family_header (vty, afi, safi, write);
12233
12234 /* "network" configuration display. */
12235 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12236 {
12237 u_int32_t destination;
12238 struct in_addr netmask;
12239
12240 destination = ntohl (p->u.prefix4.s_addr);
12241 masklen2ip (p->prefixlen, &netmask);
12242 vty_out (vty, " network %s",
12243 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12244
12245 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12246 || (IN_CLASSB (destination) && p->prefixlen == 16)
12247 || (IN_CLASSA (destination) && p->prefixlen == 8)
12248 || p->u.prefix4.s_addr == 0)
12249 {
12250 /* Natural mask is not display. */
12251 }
12252 else
12253 vty_out (vty, " mask %s", inet_ntoa (netmask));
12254 }
12255 else
12256 {
12257 vty_out (vty, " network %s/%d",
12258 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12259 p->prefixlen);
12260 }
12261
12262 if (bgp_static->rmap.name)
12263 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012264 else
12265 {
12266 if (bgp_static->backdoor)
12267 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012268 }
paul718e3742002-12-13 20:15:29 +000012269
12270 vty_out (vty, "%s", VTY_NEWLINE);
12271 }
12272
12273 /* Aggregate-address configuration. */
12274 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12275 if ((bgp_aggregate = rn->info) != NULL)
12276 {
12277 p = &rn->p;
12278
12279 /* "address-family" display. */
12280 bgp_config_write_family_header (vty, afi, safi, write);
12281
12282 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12283 {
12284 struct in_addr netmask;
12285
12286 masklen2ip (p->prefixlen, &netmask);
12287 vty_out (vty, " aggregate-address %s %s",
12288 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12289 inet_ntoa (netmask));
12290 }
12291 else
12292 {
12293 vty_out (vty, " aggregate-address %s/%d",
12294 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12295 p->prefixlen);
12296 }
12297
12298 if (bgp_aggregate->as_set)
12299 vty_out (vty, " as-set");
12300
12301 if (bgp_aggregate->summary_only)
12302 vty_out (vty, " summary-only");
12303
12304 vty_out (vty, "%s", VTY_NEWLINE);
12305 }
12306
12307 return 0;
12308}
12309
12310int
12311bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12312{
12313 struct bgp_node *rn;
12314 struct bgp_distance *bdistance;
12315
12316 /* Distance configuration. */
12317 if (bgp->distance_ebgp
12318 && bgp->distance_ibgp
12319 && bgp->distance_local
12320 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12321 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12322 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12323 vty_out (vty, " distance bgp %d %d %d%s",
12324 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12325 VTY_NEWLINE);
12326
12327 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12328 if ((bdistance = rn->info) != NULL)
12329 {
12330 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12331 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12332 bdistance->access_list ? bdistance->access_list : "",
12333 VTY_NEWLINE);
12334 }
12335
12336 return 0;
12337}
12338
12339/* Allocate routing table structure and install commands. */
12340void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012341bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012342{
12343 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012344 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012345
12346 /* IPv4 BGP commands. */
12347 install_element (BGP_NODE, &bgp_network_cmd);
12348 install_element (BGP_NODE, &bgp_network_mask_cmd);
12349 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12350 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12351 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12352 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12353 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12354 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12355 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12356 install_element (BGP_NODE, &no_bgp_network_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12358 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12359 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12360 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12361 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12362 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12363 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12364 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12365
12366 install_element (BGP_NODE, &aggregate_address_cmd);
12367 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12368 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12369 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12370 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12371 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12372 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12373 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12374 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12375 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12376 install_element (BGP_NODE, &no_aggregate_address_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12379 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12380 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12381 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12382 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12383 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12384 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12385 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12386
12387 /* IPv4 unicast configuration. */
12388 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12389 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12390 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12391 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12392 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12393 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012394 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012395 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12396 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12397 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12398 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12399 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012400
paul718e3742002-12-13 20:15:29 +000012401 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12402 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12404 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12405 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12406 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12407 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12408 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12409 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12410 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12411 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12414 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12415 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12416 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12417 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12418 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12419 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12420 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12421
12422 /* IPv4 multicast configuration. */
12423 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12424 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12425 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12426 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12427 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12428 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12429 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12431 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12432 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12433 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12434 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12435 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12438 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12439 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12440 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12441 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12442 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12443 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12444 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12455
12456 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012458 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012459 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012461 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012462 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012466 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012467 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012492 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12493 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12494 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12495 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12496 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012497 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012516 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012532 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012533 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012534 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012535 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012536 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012537 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012538 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012540 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012541 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012542 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012543 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012544 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012545 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012546
12547 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12548 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012551 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12552 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012554 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012555 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12563 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012567 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12568 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12569 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12570 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12571 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012572 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012582 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012584 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012585 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012586 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012588
12589 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012591 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012592 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012595 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012599 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012600 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12626 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12627 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12628 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12629 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012630 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012648 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012649 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012665 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012666 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012667 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012668 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012669 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012670 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012671 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012673 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012674 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012675 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012676 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012677 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012678 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012679
12680 /* BGP dampening clear commands */
12681 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12682 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12683 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12684 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12685
Paul Jakmaff7924f2006-09-04 01:10:36 +000012686 /* prefix count */
12687 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012690#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012691 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12692
paul718e3742002-12-13 20:15:29 +000012693 /* New config IPv6 BGP commands. */
12694 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12695 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12696 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12697 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12698
12699 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12700 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12701 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12702 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12703
G.Balaji73bfe0b2011-09-23 22:36:20 +053012704 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12705 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12706
paul718e3742002-12-13 20:15:29 +000012707 /* Old config IPv6 BGP commands. */
12708 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12709 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12710
12711 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12712 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12713 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12714 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12715
12716 install_element (VIEW_NODE, &show_bgp_cmd);
12717 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012719 install_element (VIEW_NODE, &show_bgp_route_cmd);
12720 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012721 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012722 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12723 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012724 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012725 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12726 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12727 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12728 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12729 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12730 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12731 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12732 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12733 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12734 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12735 install_element (VIEW_NODE, &show_bgp_community_cmd);
12736 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12737 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12739 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12740 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12741 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12742 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12743 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12744 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12745 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12749 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12751 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12753 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12755 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12757 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12759 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12761 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12762 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12763 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012765 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12767 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12768 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012769 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012771 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012772 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012773 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012775 install_element (VIEW_NODE, &show_bgp_view_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12788 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12789 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12790 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12792 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012793 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012795 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012797 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012798 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012799
12800 /* Restricted:
12801 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12802 */
12803 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12804 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012806 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012809 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12821 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012826 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012827 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012828 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012829 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012836 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012837 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012838 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012839
12840 install_element (ENABLE_NODE, &show_bgp_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012842 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012843 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012845 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012846 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012849 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012889 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012893 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012894 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012895 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012896 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012897 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012898 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012899 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012917 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012919 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012920 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012921 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012922 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012923
12924 /* Statistics */
12925 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12929
paul718e3742002-12-13 20:15:29 +000012930 /* old command */
12931 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012967
paul718e3742002-12-13 20:15:29 +000012968 /* old command */
12969 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13005
13006 /* old command */
13007 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13008 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13009 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13010 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13011
13012 /* old command */
13013 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13014 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13015 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13016 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13017
13018 /* old command */
13019 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13020 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13021 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13022 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13023#endif /* HAVE_IPV6 */
13024
13025 install_element (BGP_NODE, &bgp_distance_cmd);
13026 install_element (BGP_NODE, &no_bgp_distance_cmd);
13027 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13028 install_element (BGP_NODE, &bgp_distance_source_cmd);
13029 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13030 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13031 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13032
13033 install_element (BGP_NODE, &bgp_damp_set_cmd);
13034 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13035 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13036 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13037 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13038 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13039 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13040 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13041 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13042 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013043
13044 /* Deprecated AS-Pathlimit commands */
13045 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13046 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13047 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13048 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13049 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13050 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13051
13052 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13053 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13054 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13055 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13056 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13057 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13058
13059 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13064 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13065
13066 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13067 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13068 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13069 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13070 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13071 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13072
13073 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13074 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13078 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13079
13080 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13081 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13082 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13083 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13084 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013086
13087#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013088 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13089 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013090#endif
paul718e3742002-12-13 20:15:29 +000013091}
Chris Caputo228da422009-07-18 05:44:03 +000013092
13093void
13094bgp_route_finish (void)
13095{
13096 bgp_table_unlock (bgp_distance_table);
13097 bgp_distance_table = NULL;
13098}