blob: 8bc72d7be36b6692a0202e1609147b4230fc9f4e [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000483 if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700484 {
485 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
486 *paths_eq = 1;
487 }
488 else if (new->peer->as == exist->peer->as)
489 *paths_eq = 1;
490 }
491 else
492 {
493 /*
494 * TODO: If unequal cost ibgp multipath is enabled we can
495 * mark the paths as equal here instead of returning
496 */
497 return ret;
498 }
paul718e3742002-12-13 20:15:29 +0000499
500 /* 10. If both paths are external, prefer the path that was received
501 first (the oldest one). This step minimizes route-flap, since a
502 newer path won't displace an older one, even if it was the
503 preferred route based on the additional decision criteria below. */
504 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000505 && new_sort == BGP_PEER_EBGP
506 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000507 {
508 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
509 return 1;
510 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
511 return 0;
512 }
513
514 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000515 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
516 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000517 else
518 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000519 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
520 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000521 else
522 exist_id.s_addr = exist->peer->remote_id.s_addr;
523
524 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
525 return 1;
526 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
527 return 0;
528
529 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000530 new_cluster = exist_cluster = 0;
531
532 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
533 new_cluster = newattre->cluster->length;
534 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
535 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000536
537 if (new_cluster < exist_cluster)
538 return 1;
539 if (new_cluster > exist_cluster)
540 return 0;
541
542 /* 13. Neighbor address comparision. */
543 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
544
545 if (ret == 1)
546 return 0;
547 if (ret == -1)
548 return 1;
549
550 return 1;
551}
552
paul94f2b392005-06-28 12:44:16 +0000553static enum filter_type
paul718e3742002-12-13 20:15:29 +0000554bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
555 afi_t afi, safi_t safi)
556{
557 struct bgp_filter *filter;
558
559 filter = &peer->filter[afi][safi];
560
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#define FILTER_EXIST_WARN(F,f,filter) \
562 if (BGP_DEBUG (update, UPDATE_IN) \
563 && !(F ## _IN (filter))) \
564 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
565 peer->host, #f, F ## _IN_NAME(filter));
566
567 if (DISTRIBUTE_IN_NAME (filter)) {
568 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
569
paul718e3742002-12-13 20:15:29 +0000570 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
571 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 }
paul718e3742002-12-13 20:15:29 +0000573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574 if (PREFIX_LIST_IN_NAME (filter)) {
575 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
576
paul718e3742002-12-13 20:15:29 +0000577 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
578 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100579 }
paul718e3742002-12-13 20:15:29 +0000580
Paul Jakma650f76c2009-06-25 18:06:31 +0100581 if (FILTER_LIST_IN_NAME (filter)) {
582 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
583
paul718e3742002-12-13 20:15:29 +0000584 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
585 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100586 }
587
paul718e3742002-12-13 20:15:29 +0000588 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100589#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000590}
591
paul94f2b392005-06-28 12:44:16 +0000592static enum filter_type
paul718e3742002-12-13 20:15:29 +0000593bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
594 afi_t afi, safi_t safi)
595{
596 struct bgp_filter *filter;
597
598 filter = &peer->filter[afi][safi];
599
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#define FILTER_EXIST_WARN(F,f,filter) \
601 if (BGP_DEBUG (update, UPDATE_OUT) \
602 && !(F ## _OUT (filter))) \
603 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
604 peer->host, #f, F ## _OUT_NAME(filter));
605
606 if (DISTRIBUTE_OUT_NAME (filter)) {
607 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
paul718e3742002-12-13 20:15:29 +0000612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613 if (PREFIX_LIST_OUT_NAME (filter)) {
614 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
615
paul718e3742002-12-13 20:15:29 +0000616 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
617 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100618 }
paul718e3742002-12-13 20:15:29 +0000619
Paul Jakma650f76c2009-06-25 18:06:31 +0100620 if (FILTER_LIST_OUT_NAME (filter)) {
621 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
622
paul718e3742002-12-13 20:15:29 +0000623 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
624 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100625 }
paul718e3742002-12-13 20:15:29 +0000626
627 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100628#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000629}
630
631/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000632static int
paul718e3742002-12-13 20:15:29 +0000633bgp_community_filter (struct peer *peer, struct attr *attr)
634{
635 if (attr->community)
636 {
637 /* NO_ADVERTISE check. */
638 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
639 return 1;
640
641 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000642 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000643 community_include (attr->community, COMMUNITY_NO_EXPORT))
644 return 1;
645
646 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000647 if (peer->sort == BGP_PEER_EBGP
648 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000649 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
650 return 1;
651 }
652 return 0;
653}
654
655/* Route reflection loop check. */
656static int
657bgp_cluster_filter (struct peer *peer, struct attr *attr)
658{
659 struct in_addr cluster_id;
660
Paul Jakmafb982c22007-05-04 20:15:47 +0000661 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000662 {
663 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
664 cluster_id = peer->bgp->cluster_id;
665 else
666 cluster_id = peer->bgp->router_id;
667
Paul Jakmafb982c22007-05-04 20:15:47 +0000668 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000669 return 1;
670 }
671 return 0;
672}
673
paul94f2b392005-06-28 12:44:16 +0000674static int
paul718e3742002-12-13 20:15:29 +0000675bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
676 afi_t afi, safi_t safi)
677{
678 struct bgp_filter *filter;
679 struct bgp_info info;
680 route_map_result_t ret;
681
682 filter = &peer->filter[afi][safi];
683
684 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000685 if (peer->weight)
686 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000687
688 /* Route map apply. */
689 if (ROUTE_MAP_IN_NAME (filter))
690 {
691 /* Duplicate current value to new strucutre for modification. */
692 info.peer = peer;
693 info.attr = attr;
694
paulac41b2a2003-08-12 05:32:27 +0000695 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
696
paul718e3742002-12-13 20:15:29 +0000697 /* Apply BGP route map to the attribute. */
698 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000699
700 peer->rmap_type = 0;
701
paul718e3742002-12-13 20:15:29 +0000702 if (ret == RMAP_DENYMATCH)
703 {
704 /* Free newly generated AS path and community by route-map. */
705 bgp_attr_flush (attr);
706 return RMAP_DENY;
707 }
708 }
709 return RMAP_PERMIT;
710}
711
paul94f2b392005-06-28 12:44:16 +0000712static int
paulfee0f4c2004-09-13 05:12:46 +0000713bgp_export_modifier (struct peer *rsclient, struct peer *peer,
714 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
715{
716 struct bgp_filter *filter;
717 struct bgp_info info;
718 route_map_result_t ret;
719
720 filter = &peer->filter[afi][safi];
721
722 /* Route map apply. */
723 if (ROUTE_MAP_EXPORT_NAME (filter))
724 {
725 /* Duplicate current value to new strucutre for modification. */
726 info.peer = rsclient;
727 info.attr = attr;
728
729 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
730
731 /* Apply BGP route map to the attribute. */
732 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
733
734 rsclient->rmap_type = 0;
735
736 if (ret == RMAP_DENYMATCH)
737 {
738 /* Free newly generated AS path and community by route-map. */
739 bgp_attr_flush (attr);
740 return RMAP_DENY;
741 }
742 }
743 return RMAP_PERMIT;
744}
745
paul94f2b392005-06-28 12:44:16 +0000746static int
paulfee0f4c2004-09-13 05:12:46 +0000747bgp_import_modifier (struct peer *rsclient, struct peer *peer,
748 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
749{
750 struct bgp_filter *filter;
751 struct bgp_info info;
752 route_map_result_t ret;
753
754 filter = &rsclient->filter[afi][safi];
755
756 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000757 if (peer->weight)
758 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000759
760 /* Route map apply. */
761 if (ROUTE_MAP_IMPORT_NAME (filter))
762 {
763 /* Duplicate current value to new strucutre for modification. */
764 info.peer = peer;
765 info.attr = attr;
766
767 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
768
769 /* Apply BGP route map to the attribute. */
770 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
771
772 peer->rmap_type = 0;
773
774 if (ret == RMAP_DENYMATCH)
775 {
776 /* Free newly generated AS path and community by route-map. */
777 bgp_attr_flush (attr);
778 return RMAP_DENY;
779 }
780 }
781 return RMAP_PERMIT;
782}
783
paul94f2b392005-06-28 12:44:16 +0000784static int
paul718e3742002-12-13 20:15:29 +0000785bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
786 struct attr *attr, afi_t afi, safi_t safi)
787{
788 int ret;
789 char buf[SU_ADDRSTRLEN];
790 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000791 struct peer *from;
792 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000793 int transparent;
794 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700795 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000796
797 from = ri->peer;
798 filter = &peer->filter[afi][safi];
799 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700800 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000801
Paul Jakma750e8142008-07-22 21:11:48 +0000802 if (DISABLE_BGP_ANNOUNCE)
803 return 0;
paul718e3742002-12-13 20:15:29 +0000804
paulfee0f4c2004-09-13 05:12:46 +0000805 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
806 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
807 return 0;
808
paul718e3742002-12-13 20:15:29 +0000809 /* Do not send back route to sender. */
810 if (from == peer)
811 return 0;
812
paul35be31b2004-05-01 18:17:04 +0000813 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
814 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700815 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000816 return 0;
817#ifdef HAVE_IPV6
818 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700819 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000820 return 0;
821#endif
822
paul718e3742002-12-13 20:15:29 +0000823 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000825 if (! UNSUPPRESS_MAP_NAME (filter))
826 return 0;
827
828 /* Default route check. */
829 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
830 {
831 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
832 return 0;
833#ifdef HAVE_IPV6
834 else if (p->family == AF_INET6 && p->prefixlen == 0)
835 return 0;
836#endif /* HAVE_IPV6 */
837 }
838
paul286e1e72003-08-08 00:24:31 +0000839 /* Transparency check. */
840 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
841 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
842 transparent = 1;
843 else
844 transparent = 0;
845
paul718e3742002-12-13 20:15:29 +0000846 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000848 return 0;
849
850 /* If the attribute has originator-id and it is same as remote
851 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700852 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000853 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700854 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000855 {
856 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000857 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000858 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
859 peer->host,
860 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
861 p->prefixlen);
862 return 0;
863 }
864 }
865
866 /* ORF prefix-list filter check */
867 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
868 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
869 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
870 if (peer->orf_plist[afi][safi])
871 {
872 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
873 return 0;
874 }
875
876 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700877 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000878 {
879 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000880 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000881 "%s [Update:SEND] %s/%d is filtered",
882 peer->host,
883 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
884 p->prefixlen);
885 return 0;
886 }
887
888#ifdef BGP_SEND_ASPATH_CHECK
889 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700890 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000891 {
892 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000893 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400894 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000895 peer->host, peer->as);
896 return 0;
897 }
898#endif /* BGP_SEND_ASPATH_CHECK */
899
900 /* If we're a CONFED we need to loop check the CONFED ID too */
901 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
902 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700903 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000904 {
905 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000906 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400907 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000908 peer->host,
909 bgp->confed_id);
910 return 0;
911 }
912 }
913
914 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000915 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000916 reflect = 1;
917 else
918 reflect = 0;
919
920 /* IBGP reflection check. */
921 if (reflect)
922 {
923 /* A route from a Client peer. */
924 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 {
926 /* Reflect to all the Non-Client peers and also to the
927 Client peers other than the originator. Originator check
928 is already done. So there is noting to do. */
929 /* no bgp client-to-client reflection check. */
930 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
931 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 else
935 {
936 /* A route from a Non-client peer. Reflect to all other
937 clients. */
938 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
939 return 0;
940 }
941 }
Paul Jakma41367172007-08-06 15:24:51 +0000942
paul718e3742002-12-13 20:15:29 +0000943 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700944 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000945
paul718e3742002-12-13 20:15:29 +0000946 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000947 if ((peer->sort == BGP_PEER_IBGP
948 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000949 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
950 {
951 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
952 attr->local_pref = bgp->default_local_pref;
953 }
954
paul718e3742002-12-13 20:15:29 +0000955 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000956 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000957 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
958 {
959 if (ri->peer != bgp->peer_self && ! transparent
960 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
961 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
962 }
963
964 /* next-hop-set */
965 if (transparent || reflect
966 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
967 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000968#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000969 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000970 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000971#endif /* HAVE_IPV6 */
972 )))
paul718e3742002-12-13 20:15:29 +0000973 {
974 /* NEXT-HOP Unchanged. */
975 }
976 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
977 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
978#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000979 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000981#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000982 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000983 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
984 {
985 /* Set IPv4 nexthop. */
986 if (p->family == AF_INET)
987 {
988 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000989 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
990 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000991 else
992 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
993 }
994#ifdef HAVE_IPV6
995 /* Set IPv6 nexthop. */
996 if (p->family == AF_INET6)
997 {
998 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001000 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001002 }
1003#endif /* HAVE_IPV6 */
1004 }
1005
1006#ifdef HAVE_IPV6
1007 if (p->family == AF_INET6)
1008 {
paulfee0f4c2004-09-13 05:12:46 +00001009 /* Left nexthop_local unchanged if so configured. */
1010 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1011 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1012 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1014 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001015 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001017 }
1018
1019 /* Default nexthop_local treatment for non-RS-Clients */
1020 else
1021 {
paul718e3742002-12-13 20:15:29 +00001022 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001024
1025 /* Set link-local address for shared network peer. */
1026 if (peer->shared_network
1027 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1028 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001029 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001030 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001032 }
1033
1034 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1035 address.*/
1036 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001038
1039 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1040 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001041 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001042 }
paulfee0f4c2004-09-13 05:12:46 +00001043
1044 }
paul718e3742002-12-13 20:15:29 +00001045#endif /* HAVE_IPV6 */
1046
1047 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001048 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001049 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1050 && aspath_private_as_check (attr->aspath))
1051 attr->aspath = aspath_empty_get ();
1052
1053 /* Route map & unsuppress-map apply. */
1054 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001056 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001057 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001058 struct attr dummy_attr;
1059 struct attr_extra dummy_extra;
1060
1061 dummy_attr.extra = &dummy_extra;
1062
paul718e3742002-12-13 20:15:29 +00001063 info.peer = peer;
1064 info.attr = attr;
1065
1066 /* The route reflector is not allowed to modify the attributes
1067 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001068 if (from->sort == BGP_PEER_IBGP
1069 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001071 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001072 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001073 }
paulac41b2a2003-08-12 05:32:27 +00001074
1075 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1076
Paul Jakmafb982c22007-05-04 20:15:47 +00001077 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001078 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1079 else
1080 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1081
paulac41b2a2003-08-12 05:32:27 +00001082 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001083
paul718e3742002-12-13 20:15:29 +00001084 if (ret == RMAP_DENYMATCH)
1085 {
1086 bgp_attr_flush (attr);
1087 return 0;
1088 }
1089 }
1090 return 1;
1091}
1092
paul94f2b392005-06-28 12:44:16 +00001093static int
paulfee0f4c2004-09-13 05:12:46 +00001094bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1095 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001096{
paulfee0f4c2004-09-13 05:12:46 +00001097 int ret;
1098 char buf[SU_ADDRSTRLEN];
1099 struct bgp_filter *filter;
1100 struct bgp_info info;
1101 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001102 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001103
1104 from = ri->peer;
1105 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001106 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001107
Paul Jakma750e8142008-07-22 21:11:48 +00001108 if (DISABLE_BGP_ANNOUNCE)
1109 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001110
1111 /* Do not send back route to sender. */
1112 if (from == rsclient)
1113 return 0;
1114
1115 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001116 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001117 if (! UNSUPPRESS_MAP_NAME (filter))
1118 return 0;
1119
1120 /* Default route check. */
1121 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1122 PEER_STATUS_DEFAULT_ORIGINATE))
1123 {
1124 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1125 return 0;
1126#ifdef HAVE_IPV6
1127 else if (p->family == AF_INET6 && p->prefixlen == 0)
1128 return 0;
1129#endif /* HAVE_IPV6 */
1130 }
1131
1132 /* If the attribute has originator-id and it is same as remote
1133 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001134 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001135 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001136 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001138 {
1139 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001140 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001141 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1142 rsclient->host,
1143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1144 p->prefixlen);
1145 return 0;
1146 }
1147 }
1148
1149 /* ORF prefix-list filter check */
1150 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1151 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1152 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1153 if (rsclient->orf_plist[afi][safi])
1154 {
1155 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1156 return 0;
1157 }
1158
1159 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001160 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001161 {
1162 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001163 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001164 "%s [Update:SEND] %s/%d is filtered",
1165 rsclient->host,
1166 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1167 p->prefixlen);
1168 return 0;
1169 }
1170
1171#ifdef BGP_SEND_ASPATH_CHECK
1172 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001173 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001174 {
1175 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001176 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001177 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001178 rsclient->host, rsclient->as);
1179 return 0;
1180 }
1181#endif /* BGP_SEND_ASPATH_CHECK */
1182
1183 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001185
1186 /* next-hop-set */
1187 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1188#ifdef HAVE_IPV6
1189 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001190 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001191#endif /* HAVE_IPV6 */
1192 )
1193 {
1194 /* Set IPv4 nexthop. */
1195 if (p->family == AF_INET)
1196 {
1197 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001198 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001199 IPV4_MAX_BYTELEN);
1200 else
1201 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1202 }
1203#ifdef HAVE_IPV6
1204 /* Set IPv6 nexthop. */
1205 if (p->family == AF_INET6)
1206 {
1207 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001211 }
1212#endif /* HAVE_IPV6 */
1213 }
1214
1215#ifdef HAVE_IPV6
1216 if (p->family == AF_INET6)
1217 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001219
paulfee0f4c2004-09-13 05:12:46 +00001220 /* Left nexthop_local unchanged if so configured. */
1221 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1222 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1223 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1225 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001226 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001227 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001228 }
1229
1230 /* Default nexthop_local treatment for RS-Clients */
1231 else
1232 {
1233 /* Announcer and RS-Client are both in the same network */
1234 if (rsclient->shared_network && from->shared_network &&
1235 (rsclient->ifindex == from->ifindex))
1236 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1238 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001239 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001241 }
1242
1243 /* Set link-local address for shared network peer. */
1244 else if (rsclient->shared_network
1245 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1246 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001248 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001250 }
1251
1252 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001253 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001254 }
1255
1256 }
1257#endif /* HAVE_IPV6 */
1258
1259
1260 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001261 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001262 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1263 && aspath_private_as_check (attr->aspath))
1264 attr->aspath = aspath_empty_get ();
1265
1266 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001268 {
1269 info.peer = rsclient;
1270 info.attr = attr;
1271
1272 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1273
Paul Jakmafb982c22007-05-04 20:15:47 +00001274 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001275 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1276 else
1277 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1278
1279 rsclient->rmap_type = 0;
1280
1281 if (ret == RMAP_DENYMATCH)
1282 {
1283 bgp_attr_flush (attr);
1284 return 0;
1285 }
1286 }
1287
1288 return 1;
1289}
1290
1291struct bgp_info_pair
1292{
1293 struct bgp_info *old;
1294 struct bgp_info *new;
1295};
1296
paul94f2b392005-06-28 12:44:16 +00001297static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001298bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1299 struct bgp_maxpaths_cfg *mpath_cfg,
1300 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001301{
paul718e3742002-12-13 20:15:29 +00001302 struct bgp_info *new_select;
1303 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001304 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001305 struct bgp_info *ri1;
1306 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001307 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001308 int paths_eq, do_mpath;
1309 struct list mp_list;
1310
1311 bgp_mp_list_init (&mp_list);
1312 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1313 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1314
paul718e3742002-12-13 20:15:29 +00001315 /* bgp deterministic-med */
1316 new_select = NULL;
1317 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1318 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1319 {
1320 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1321 continue;
1322 if (BGP_INFO_HOLDDOWN (ri1))
1323 continue;
1324
1325 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001326 if (do_mpath)
1327 bgp_mp_list_add (&mp_list, ri1);
1328 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001329 if (ri1->next)
1330 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1331 {
1332 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1333 continue;
1334 if (BGP_INFO_HOLDDOWN (ri2))
1335 continue;
1336
1337 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1338 || aspath_cmp_left_confed (ri1->attr->aspath,
1339 ri2->attr->aspath))
1340 {
Josh Bailey6918e742011-07-20 20:48:20 -07001341 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1342 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001343 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001344 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001345 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001346 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001347 if (do_mpath && !paths_eq)
1348 {
1349 bgp_mp_list_clear (&mp_list);
1350 bgp_mp_list_add (&mp_list, ri2);
1351 }
paul718e3742002-12-13 20:15:29 +00001352 }
1353
Josh Bailey6918e742011-07-20 20:48:20 -07001354 if (do_mpath && paths_eq)
1355 bgp_mp_list_add (&mp_list, ri2);
1356
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001358 }
1359 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1361 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001362
1363 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1364 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001365 }
1366
1367 /* Check old selected route and new selected route. */
1368 old_select = NULL;
1369 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001370 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001371 {
1372 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1373 old_select = ri;
1374
1375 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001376 {
1377 /* reap REMOVED routes, if needs be
1378 * selected route must stay for a while longer though
1379 */
1380 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1381 && (ri != old_select))
1382 bgp_info_reap (rn, ri);
1383
1384 continue;
1385 }
paul718e3742002-12-13 20:15:29 +00001386
1387 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1388 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1389 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001390 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001391 continue;
1392 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001393 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1394 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001395
Josh Bailey96450fa2011-07-20 20:45:12 -07001396 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1397 {
Josh Bailey6918e742011-07-20 20:48:20 -07001398 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1399 bgp_mp_dmed_deselect (new_select);
1400
Josh Bailey96450fa2011-07-20 20:45:12 -07001401 new_select = ri;
1402
1403 if (do_mpath && !paths_eq)
1404 {
1405 bgp_mp_list_clear (&mp_list);
1406 bgp_mp_list_add (&mp_list, ri);
1407 }
1408 }
Josh Bailey6918e742011-07-20 20:48:20 -07001409 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1410 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001411
1412 if (do_mpath && paths_eq)
1413 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001414 }
paulb40d9392005-08-22 22:34:41 +00001415
paulfee0f4c2004-09-13 05:12:46 +00001416
Josh Bailey6918e742011-07-20 20:48:20 -07001417 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1418 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001419
Josh Bailey0b597ef2011-07-20 20:49:11 -07001420 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001421 bgp_mp_list_clear (&mp_list);
1422
1423 result->old = old_select;
1424 result->new = new_select;
1425
1426 return;
paulfee0f4c2004-09-13 05:12:46 +00001427}
1428
paul94f2b392005-06-28 12:44:16 +00001429static int
paulfee0f4c2004-09-13 05:12:46 +00001430bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001431 struct bgp_node *rn, afi_t afi, safi_t safi)
1432{
paulfee0f4c2004-09-13 05:12:46 +00001433 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001434 struct attr attr;
1435 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001436
1437 p = &rn->p;
1438
Paul Jakma9eda90c2007-08-30 13:36:17 +00001439 /* Announce route to Established peer. */
1440 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001441 return 0;
1442
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 /* Address family configuration check. */
1444 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001445 return 0;
1446
Paul Jakma9eda90c2007-08-30 13:36:17 +00001447 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001448 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1449 PEER_STATUS_ORF_WAIT_REFRESH))
1450 return 0;
1451
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001452 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1453 attr.extra = &extra;
1454
Avneesh Sachdev67174042012-08-17 08:19:49 -07001455 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001456 {
1457 case BGP_TABLE_MAIN:
1458 /* Announcement to peer->conf. If the route is filtered,
1459 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1461 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001462 else
1463 bgp_adj_out_unset (rn, peer, p, afi, safi);
1464 break;
1465 case BGP_TABLE_RSCLIENT:
1466 /* Announcement to peer->conf. If the route is filtered,
1467 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001468 if (selected &&
1469 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1470 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1471 else
1472 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001473 break;
1474 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001475
paulfee0f4c2004-09-13 05:12:46 +00001476 return 0;
paul200df112005-06-01 11:17:05 +00001477}
paulfee0f4c2004-09-13 05:12:46 +00001478
paul200df112005-06-01 11:17:05 +00001479struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001480{
paul200df112005-06-01 11:17:05 +00001481 struct bgp *bgp;
1482 struct bgp_node *rn;
1483 afi_t afi;
1484 safi_t safi;
1485};
1486
1487static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001488bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001489{
paul0fb58d52005-11-14 14:31:49 +00001490 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001491 struct bgp *bgp = pq->bgp;
1492 struct bgp_node *rn = pq->rn;
1493 afi_t afi = pq->afi;
1494 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001495 struct bgp_info *new_select;
1496 struct bgp_info *old_select;
1497 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001498 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001499 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001500
paulfee0f4c2004-09-13 05:12:46 +00001501 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001502 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001503 new_select = old_and_new.new;
1504 old_select = old_and_new.old;
1505
paul200df112005-06-01 11:17:05 +00001506 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1507 {
Chris Caputo228da422009-07-18 05:44:03 +00001508 if (rsclient->group)
1509 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1510 {
1511 /* Nothing to do. */
1512 if (old_select && old_select == new_select)
1513 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1514 continue;
paulfee0f4c2004-09-13 05:12:46 +00001515
Chris Caputo228da422009-07-18 05:44:03 +00001516 if (old_select)
1517 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1518 if (new_select)
1519 {
1520 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1521 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001522 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1523 }
paulfee0f4c2004-09-13 05:12:46 +00001524
Chris Caputo228da422009-07-18 05:44:03 +00001525 bgp_process_announce_selected (rsclient, new_select, rn,
1526 afi, safi);
1527 }
paul200df112005-06-01 11:17:05 +00001528 }
1529 else
1530 {
hassob7395792005-08-26 12:58:38 +00001531 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001532 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001533 if (new_select)
1534 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001535 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1536 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001537 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001538 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001539 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001540 }
paulfee0f4c2004-09-13 05:12:46 +00001541
paulb40d9392005-08-22 22:34:41 +00001542 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1543 bgp_info_reap (rn, old_select);
1544
paul200df112005-06-01 11:17:05 +00001545 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1546 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001547}
1548
paul200df112005-06-01 11:17:05 +00001549static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001550bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001551{
paul0fb58d52005-11-14 14:31:49 +00001552 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001553 struct bgp *bgp = pq->bgp;
1554 struct bgp_node *rn = pq->rn;
1555 afi_t afi = pq->afi;
1556 safi_t safi = pq->safi;
1557 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001558 struct bgp_info *new_select;
1559 struct bgp_info *old_select;
1560 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001561 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001562 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001563
paulfee0f4c2004-09-13 05:12:46 +00001564 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001565 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001566 old_select = old_and_new.old;
1567 new_select = old_and_new.new;
1568
1569 /* Nothing to do. */
1570 if (old_select && old_select == new_select)
1571 {
1572 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001573 {
Josh Bailey8196f132011-07-20 20:47:07 -07001574 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1575 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001576 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001577
Josh Bailey8196f132011-07-20 20:47:07 -07001578 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001579 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1580 return WQ_SUCCESS;
1581 }
paulfee0f4c2004-09-13 05:12:46 +00001582 }
paul718e3742002-12-13 20:15:29 +00001583
hasso338b3422005-02-23 14:27:24 +00001584 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001585 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001586 if (new_select)
1587 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001588 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1589 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001590 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001591 }
1592
1593
paul718e3742002-12-13 20:15:29 +00001594 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001595 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001596 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001597 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001598 }
1599
1600 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001601 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1602 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001603 {
1604 if (new_select
1605 && new_select->type == ZEBRA_ROUTE_BGP
1606 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001607 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001608 else
1609 {
1610 /* Withdraw the route from the kernel. */
1611 if (old_select
1612 && old_select->type == ZEBRA_ROUTE_BGP
1613 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001614 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001615 }
1616 }
paulb40d9392005-08-22 22:34:41 +00001617
1618 /* Reap old select bgp_info, it it has been removed */
1619 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1620 bgp_info_reap (rn, old_select);
1621
paul200df112005-06-01 11:17:05 +00001622 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1623 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001624}
1625
paul200df112005-06-01 11:17:05 +00001626static void
paul0fb58d52005-11-14 14:31:49 +00001627bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001628{
paul0fb58d52005-11-14 14:31:49 +00001629 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001630 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001631
Chris Caputo228da422009-07-18 05:44:03 +00001632 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001633 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001634 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001635 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1636}
1637
1638static void
1639bgp_process_queue_init (void)
1640{
1641 bm->process_main_queue
1642 = work_queue_new (bm->master, "process_main_queue");
1643 bm->process_rsclient_queue
1644 = work_queue_new (bm->master, "process_rsclient_queue");
1645
1646 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1647 {
1648 zlog_err ("%s: Failed to allocate work queue", __func__);
1649 exit (1);
1650 }
1651
1652 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001653 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001654 bm->process_main_queue->spec.max_retries = 0;
1655 bm->process_main_queue->spec.hold = 50;
1656
1657 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1658 sizeof (struct work_queue *));
1659 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001660}
1661
1662void
paulfee0f4c2004-09-13 05:12:46 +00001663bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1664{
paul200df112005-06-01 11:17:05 +00001665 struct bgp_process_queue *pqnode;
1666
1667 /* already scheduled for processing? */
1668 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1669 return;
1670
1671 if ( (bm->process_main_queue == NULL) ||
1672 (bm->process_rsclient_queue == NULL) )
1673 bgp_process_queue_init ();
1674
1675 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1676 sizeof (struct bgp_process_queue));
1677 if (!pqnode)
1678 return;
Chris Caputo228da422009-07-18 05:44:03 +00001679
1680 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001681 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001682 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001683 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001684 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001685 pqnode->afi = afi;
1686 pqnode->safi = safi;
1687
Avneesh Sachdev67174042012-08-17 08:19:49 -07001688 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001689 {
paul200df112005-06-01 11:17:05 +00001690 case BGP_TABLE_MAIN:
1691 work_queue_add (bm->process_main_queue, pqnode);
1692 break;
1693 case BGP_TABLE_RSCLIENT:
1694 work_queue_add (bm->process_rsclient_queue, pqnode);
1695 break;
paulfee0f4c2004-09-13 05:12:46 +00001696 }
paul200df112005-06-01 11:17:05 +00001697
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001698 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001699 return;
paulfee0f4c2004-09-13 05:12:46 +00001700}
hasso0a486e52005-02-01 20:57:17 +00001701
paul94f2b392005-06-28 12:44:16 +00001702static int
hasso0a486e52005-02-01 20:57:17 +00001703bgp_maximum_prefix_restart_timer (struct thread *thread)
1704{
1705 struct peer *peer;
1706
1707 peer = THREAD_ARG (thread);
1708 peer->t_pmax_restart = NULL;
1709
1710 if (BGP_DEBUG (events, EVENTS))
1711 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1712 peer->host);
1713
1714 peer_clear (peer);
1715
1716 return 0;
1717}
1718
paulfee0f4c2004-09-13 05:12:46 +00001719int
paul5228ad22004-06-04 17:58:18 +00001720bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1721 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001722{
hassoe0701b72004-05-20 09:19:34 +00001723 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1724 return 0;
1725
1726 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001727 {
hassoe0701b72004-05-20 09:19:34 +00001728 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1729 && ! always)
1730 return 0;
paul718e3742002-12-13 20:15:29 +00001731
hassoe0701b72004-05-20 09:19:34 +00001732 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001733 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1734 "limit %ld", afi_safi_print (afi, safi), peer->host,
1735 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001736 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001737
hassoe0701b72004-05-20 09:19:34 +00001738 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1739 return 0;
paul718e3742002-12-13 20:15:29 +00001740
hassoe0701b72004-05-20 09:19:34 +00001741 {
paul5228ad22004-06-04 17:58:18 +00001742 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001743
1744 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001745 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001746
1747 ndata[0] = (afi >> 8);
1748 ndata[1] = afi;
1749 ndata[2] = safi;
1750 ndata[3] = (peer->pmax[afi][safi] >> 24);
1751 ndata[4] = (peer->pmax[afi][safi] >> 16);
1752 ndata[5] = (peer->pmax[afi][safi] >> 8);
1753 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001754
1755 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1756 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1757 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1758 }
hasso0a486e52005-02-01 20:57:17 +00001759
1760 /* restart timer start */
1761 if (peer->pmax_restart[afi][safi])
1762 {
1763 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1764
1765 if (BGP_DEBUG (events, EVENTS))
1766 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1767 peer->host, peer->v_pmax_restart);
1768
1769 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1770 peer->v_pmax_restart);
1771 }
1772
hassoe0701b72004-05-20 09:19:34 +00001773 return 1;
paul718e3742002-12-13 20:15:29 +00001774 }
hassoe0701b72004-05-20 09:19:34 +00001775 else
1776 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1777
1778 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1779 {
1780 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1781 && ! always)
1782 return 0;
1783
1784 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001785 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1786 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1787 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001788 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1789 }
1790 else
1791 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001792 return 0;
1793}
1794
paulb40d9392005-08-22 22:34:41 +00001795/* Unconditionally remove the route from the RIB, without taking
1796 * damping into consideration (eg, because the session went down)
1797 */
paul94f2b392005-06-28 12:44:16 +00001798static void
paul718e3742002-12-13 20:15:29 +00001799bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1800 afi_t afi, safi_t safi)
1801{
paul902212c2006-02-05 17:51:19 +00001802 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1803
1804 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1805 bgp_info_delete (rn, ri); /* keep historical info */
1806
paulb40d9392005-08-22 22:34:41 +00001807 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001808}
1809
paul94f2b392005-06-28 12:44:16 +00001810static void
paul718e3742002-12-13 20:15:29 +00001811bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001812 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001813{
paul718e3742002-12-13 20:15:29 +00001814 int status = BGP_DAMP_NONE;
1815
paulb40d9392005-08-22 22:34:41 +00001816 /* apply dampening, if result is suppressed, we'll be retaining
1817 * the bgp_info in the RIB for historical reference.
1818 */
1819 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001820 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001821 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1822 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001823 {
paul902212c2006-02-05 17:51:19 +00001824 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1825 return;
1826 }
1827
1828 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001829}
1830
paul94f2b392005-06-28 12:44:16 +00001831static void
paulfee0f4c2004-09-13 05:12:46 +00001832bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1833 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1834 int sub_type, struct prefix_rd *prd, u_char *tag)
1835{
1836 struct bgp_node *rn;
1837 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001838 struct attr new_attr;
1839 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001840 struct attr *attr_new;
1841 struct attr *attr_new2;
1842 struct bgp_info *ri;
1843 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001844 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001845 char buf[SU_ADDRSTRLEN];
1846
1847 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1848 if (peer == rsclient)
1849 return;
1850
1851 bgp = peer->bgp;
1852 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1853
1854 /* Check previously received route. */
1855 for (ri = rn->info; ri; ri = ri->next)
1856 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1857 break;
1858
1859 /* AS path loop check. */
1860 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1861 {
1862 reason = "as-path contains our own AS;";
1863 goto filtered;
1864 }
1865
1866 /* Route reflector originator ID check. */
1867 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001868 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001869 {
1870 reason = "originator is us;";
1871 goto filtered;
1872 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001873
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001874 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001875 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001876
1877 /* Apply export policy. */
1878 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1879 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1880 {
1881 reason = "export-policy;";
1882 goto filtered;
1883 }
1884
1885 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001886
paulfee0f4c2004-09-13 05:12:46 +00001887 /* Apply import policy. */
1888 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1889 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001890 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001891
1892 reason = "import-policy;";
1893 goto filtered;
1894 }
1895
1896 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001897 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001898
1899 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001900 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001901 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001902 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001903 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001904 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001905 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001906 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001907
1908 reason = "martian next-hop;";
1909 goto filtered;
1910 }
1911 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001912
paulfee0f4c2004-09-13 05:12:46 +00001913 /* If the update is implicit withdraw. */
1914 if (ri)
1915 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001916 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001917
1918 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001919 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1920 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001921 {
1922
Paul Jakma1a392d42006-09-07 00:24:49 +00001923 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001924
1925 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001926 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001927 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1928 peer->host,
1929 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1930 p->prefixlen, rsclient->host);
1931
Chris Caputo228da422009-07-18 05:44:03 +00001932 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001933 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001934
Chris Caputo228da422009-07-18 05:44:03 +00001935 return;
paulfee0f4c2004-09-13 05:12:46 +00001936 }
1937
Paul Jakma16d2e242007-04-10 19:32:10 +00001938 /* Withdraw/Announce before we fully processed the withdraw */
1939 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1940 bgp_info_restore (rn, ri);
1941
paulfee0f4c2004-09-13 05:12:46 +00001942 /* Received Logging. */
1943 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001944 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001945 peer->host,
1946 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1947 p->prefixlen, rsclient->host);
1948
1949 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001950 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001953 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001954 ri->attr = attr_new;
1955
1956 /* Update MPLS tag. */
1957 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001958 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001959
Paul Jakma1a392d42006-09-07 00:24:49 +00001960 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 /* Process change. */
1963 bgp_process (bgp, rn, afi, safi);
1964 bgp_unlock_node (rn);
1965
1966 return;
1967 }
1968
1969 /* Received Logging. */
1970 if (BGP_DEBUG (update, UPDATE_IN))
1971 {
ajsd2c1f162004-12-08 21:10:20 +00001972 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001973 peer->host,
1974 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1975 p->prefixlen, rsclient->host);
1976 }
1977
1978 /* Make new BGP info. */
1979 new = bgp_info_new ();
1980 new->type = type;
1981 new->sub_type = sub_type;
1982 new->peer = peer;
1983 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001984 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001985
1986 /* Update MPLS tag. */
1987 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001988 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001989
Paul Jakma1a392d42006-09-07 00:24:49 +00001990 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001991
1992 /* Register new BGP information. */
1993 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001994
1995 /* route_node_get lock */
1996 bgp_unlock_node (rn);
1997
paulfee0f4c2004-09-13 05:12:46 +00001998 /* Process change. */
1999 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002000
paulfee0f4c2004-09-13 05:12:46 +00002001 return;
2002
2003 filtered:
2004
2005 /* This BGP update is filtered. Log the reason then update BGP entry. */
2006 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002007 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002008 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2009 peer->host,
2010 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2011 p->prefixlen, rsclient->host, reason);
2012
2013 if (ri)
paulb40d9392005-08-22 22:34:41 +00002014 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002015
2016 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002017
paulfee0f4c2004-09-13 05:12:46 +00002018 return;
2019}
2020
paul94f2b392005-06-28 12:44:16 +00002021static void
paulfee0f4c2004-09-13 05:12:46 +00002022bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2023 struct peer *peer, struct prefix *p, int type, int sub_type,
2024 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002025{
paulfee0f4c2004-09-13 05:12:46 +00002026 struct bgp_node *rn;
2027 struct bgp_info *ri;
2028 char buf[SU_ADDRSTRLEN];
2029
2030 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002031 return;
paulfee0f4c2004-09-13 05:12:46 +00002032
2033 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2034
2035 /* Lookup withdrawn route. */
2036 for (ri = rn->info; ri; ri = ri->next)
2037 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2038 break;
2039
2040 /* Withdraw specified route from routing table. */
2041 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002042 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002043 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002044 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002045 "%s Can't find the route %s/%d", peer->host,
2046 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2047 p->prefixlen);
2048
2049 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002050 bgp_unlock_node (rn);
2051}
paulfee0f4c2004-09-13 05:12:46 +00002052
paul94f2b392005-06-28 12:44:16 +00002053static int
paulfee0f4c2004-09-13 05:12:46 +00002054bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002055 afi_t afi, safi_t safi, int type, int sub_type,
2056 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2057{
2058 int ret;
2059 int aspath_loop_count = 0;
2060 struct bgp_node *rn;
2061 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002062 struct attr new_attr;
2063 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002064 struct attr *attr_new;
2065 struct bgp_info *ri;
2066 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002067 const char *reason;
paul718e3742002-12-13 20:15:29 +00002068 char buf[SU_ADDRSTRLEN];
2069
2070 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002071 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002072
paul718e3742002-12-13 20:15:29 +00002073 /* When peer's soft reconfiguration enabled. Record input packet in
2074 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002075 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2076 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002077 bgp_adj_in_set (rn, peer, attr);
2078
2079 /* Check previously received route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* AS path local-as loop check. */
2085 if (peer->change_local_as)
2086 {
2087 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2088 aspath_loop_count = 1;
2089
2090 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2091 {
2092 reason = "as-path contains our own AS;";
2093 goto filtered;
2094 }
2095 }
2096
2097 /* AS path loop check. */
2098 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2099 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2100 && aspath_loop_check(attr->aspath, bgp->confed_id)
2101 > peer->allowas_in[afi][safi]))
2102 {
2103 reason = "as-path contains our own AS;";
2104 goto filtered;
2105 }
2106
2107 /* Route reflector originator ID check. */
2108 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002109 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002110 {
2111 reason = "originator is us;";
2112 goto filtered;
2113 }
2114
2115 /* Route reflector cluster ID check. */
2116 if (bgp_cluster_filter (peer, attr))
2117 {
2118 reason = "reflected from the same cluster;";
2119 goto filtered;
2120 }
2121
2122 /* Apply incoming filter. */
2123 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2124 {
2125 reason = "filter;";
2126 goto filtered;
2127 }
2128
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002129 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002130 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002131
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002132 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002133 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2134 {
2135 reason = "route-map;";
2136 goto filtered;
2137 }
2138
2139 /* IPv4 unicast next hop check. */
2140 if (afi == AFI_IP && safi == SAFI_UNICAST)
2141 {
2142 /* If the peer is EBGP and nexthop is not on connected route,
2143 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002144 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002145 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002146 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002147 {
2148 reason = "non-connected next-hop;";
2149 goto filtered;
2150 }
2151
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002152 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002153 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002154 if (new_attr.nexthop.s_addr == 0
2155 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2156 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002157 {
2158 reason = "martian next-hop;";
2159 goto filtered;
2160 }
2161 }
2162
2163 attr_new = bgp_attr_intern (&new_attr);
2164
2165 /* If the update is implicit withdraw. */
2166 if (ri)
2167 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002168 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002169
2170 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002171 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2172 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002173 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002174 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002175
2176 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002177 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002178 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2179 {
2180 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002181 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002182 peer->host,
2183 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2184 p->prefixlen);
2185
paul902212c2006-02-05 17:51:19 +00002186 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2187 {
2188 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2189 bgp_process (bgp, rn, afi, safi);
2190 }
paul718e3742002-12-13 20:15:29 +00002191 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002192 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002193 {
2194 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002195 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002196 "%s rcvd %s/%d...duplicate ignored",
2197 peer->host,
2198 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2199 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002200
2201 /* graceful restart STALE flag unset. */
2202 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2203 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002204 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002205 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002206 }
paul718e3742002-12-13 20:15:29 +00002207 }
2208
2209 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002210 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002211
paul718e3742002-12-13 20:15:29 +00002212 return 0;
2213 }
2214
Paul Jakma16d2e242007-04-10 19:32:10 +00002215 /* Withdraw/Announce before we fully processed the withdraw */
2216 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2217 {
2218 if (BGP_DEBUG (update, UPDATE_IN))
2219 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2220 peer->host,
2221 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2222 p->prefixlen);
2223 bgp_info_restore (rn, ri);
2224 }
2225
paul718e3742002-12-13 20:15:29 +00002226 /* Received Logging. */
2227 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002228 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002229 peer->host,
2230 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen);
2232
hasso93406d82005-02-02 14:40:33 +00002233 /* graceful restart STALE flag unset. */
2234 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002235 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002236
paul718e3742002-12-13 20:15:29 +00002237 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002238 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002239
2240 /* implicit withdraw, decrement aggregate and pcount here.
2241 * only if update is accepted, they'll increment below.
2242 */
paul902212c2006-02-05 17:51:19 +00002243 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2244
paul718e3742002-12-13 20:15:29 +00002245 /* Update bgp route dampening information. */
2246 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002247 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002248 {
2249 /* This is implicit withdraw so we should update dampening
2250 information. */
2251 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002253 }
2254
paul718e3742002-12-13 20:15:29 +00002255 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002256 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002257 ri->attr = attr_new;
2258
2259 /* Update MPLS tag. */
2260 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002261 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002262
2263 /* Update bgp route dampening information. */
2264 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002265 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002266 {
2267 /* Now we do normal update dampening. */
2268 ret = bgp_damp_update (ri, rn, afi, safi);
2269 if (ret == BGP_DAMP_SUPPRESSED)
2270 {
2271 bgp_unlock_node (rn);
2272 return 0;
2273 }
2274 }
2275
2276 /* Nexthop reachability check. */
2277 if ((afi == AFI_IP || afi == AFI_IP6)
2278 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002279 && (peer->sort == BGP_PEER_IBGP
2280 || peer->sort == BGP_PEER_CONFED
2281 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002282 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002283 {
2284 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002287 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002288 }
2289 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002290 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002291
2292 /* Process change. */
2293 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2294
2295 bgp_process (bgp, rn, afi, safi);
2296 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002297
paul718e3742002-12-13 20:15:29 +00002298 return 0;
2299 }
2300
2301 /* Received Logging. */
2302 if (BGP_DEBUG (update, UPDATE_IN))
2303 {
ajsd2c1f162004-12-08 21:10:20 +00002304 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002305 peer->host,
2306 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2307 p->prefixlen);
2308 }
2309
paul718e3742002-12-13 20:15:29 +00002310 /* Make new BGP info. */
2311 new = bgp_info_new ();
2312 new->type = type;
2313 new->sub_type = sub_type;
2314 new->peer = peer;
2315 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002316 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002317
2318 /* Update MPLS tag. */
2319 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002320 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002321
2322 /* Nexthop reachability check. */
2323 if ((afi == AFI_IP || afi == AFI_IP6)
2324 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002325 && (peer->sort == BGP_PEER_IBGP
2326 || peer->sort == BGP_PEER_CONFED
2327 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002328 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002329 {
2330 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002331 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002332 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002333 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002334 }
2335 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002336 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002337
paul902212c2006-02-05 17:51:19 +00002338 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002339 bgp_aggregate_increment (bgp, p, new, afi, safi);
2340
2341 /* Register new BGP information. */
2342 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002343
2344 /* route_node_get lock */
2345 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002346
paul718e3742002-12-13 20:15:29 +00002347 /* If maximum prefix count is configured and current prefix
2348 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002349 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2350 return -1;
paul718e3742002-12-13 20:15:29 +00002351
2352 /* Process change. */
2353 bgp_process (bgp, rn, afi, safi);
2354
2355 return 0;
2356
2357 /* This BGP update is filtered. Log the reason then update BGP
2358 entry. */
2359 filtered:
2360 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002361 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002362 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2363 peer->host,
2364 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2365 p->prefixlen, reason);
2366
2367 if (ri)
paulb40d9392005-08-22 22:34:41 +00002368 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002369
2370 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002371
paul718e3742002-12-13 20:15:29 +00002372 return 0;
2373}
2374
2375int
paulfee0f4c2004-09-13 05:12:46 +00002376bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2377 afi_t afi, safi_t safi, int type, int sub_type,
2378 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2379{
2380 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002381 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002382 struct bgp *bgp;
2383 int ret;
2384
2385 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2386 soft_reconfig);
2387
2388 bgp = peer->bgp;
2389
2390 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002391 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002392 {
2393 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2394 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2395 sub_type, prd, tag);
2396 }
2397
2398 return ret;
2399}
2400
2401int
paul718e3742002-12-13 20:15:29 +00002402bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002403 afi_t afi, safi_t safi, int type, int sub_type,
2404 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002405{
2406 struct bgp *bgp;
2407 char buf[SU_ADDRSTRLEN];
2408 struct bgp_node *rn;
2409 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002410 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002411 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002412
2413 bgp = peer->bgp;
2414
paulfee0f4c2004-09-13 05:12:46 +00002415 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002416 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002417 {
2418 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2419 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2420 }
2421
paul718e3742002-12-13 20:15:29 +00002422 /* Logging. */
2423 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002424 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002425 peer->host,
2426 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2427 p->prefixlen);
2428
2429 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002430 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002431
2432 /* If peer is soft reconfiguration enabled. Record input packet for
2433 further calculation. */
2434 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2435 && peer != bgp->peer_self)
2436 bgp_adj_in_unset (rn, peer);
2437
2438 /* Lookup withdrawn route. */
2439 for (ri = rn->info; ri; ri = ri->next)
2440 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2441 break;
2442
2443 /* Withdraw specified route from routing table. */
2444 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002445 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002446 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002447 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002448 "%s Can't find the route %s/%d", peer->host,
2449 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2450 p->prefixlen);
2451
2452 /* Unlock bgp_node_get() lock. */
2453 bgp_unlock_node (rn);
2454
2455 return 0;
2456}
2457
2458void
2459bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2460{
2461 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002462 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002463 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002464 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002465 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002466 struct bgp_node *rn;
2467 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002468 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002469
Paul Jakmab2497022007-06-14 11:17:58 +00002470 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002471 return;
2472
paul718e3742002-12-13 20:15:29 +00002473 bgp = peer->bgp;
2474 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002475
paul718e3742002-12-13 20:15:29 +00002476 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2477 aspath = attr.aspath;
2478 attr.local_pref = bgp->default_local_pref;
2479 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2480
2481 if (afi == AFI_IP)
2482 str2prefix ("0.0.0.0/0", &p);
2483#ifdef HAVE_IPV6
2484 else if (afi == AFI_IP6)
2485 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002486 struct attr_extra *ae = attr.extra;
2487
paul718e3742002-12-13 20:15:29 +00002488 str2prefix ("::/0", &p);
2489
2490 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002491 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002492 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002493 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002494
2495 /* If the peer is on shared nextwork and we have link-local
2496 nexthop set it. */
2497 if (peer->shared_network
2498 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2499 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002500 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002501 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002502 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002503 }
2504 }
2505#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002506
2507 if (peer->default_rmap[afi][safi].name)
2508 {
paulfee0f4c2004-09-13 05:12:46 +00002509 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002510 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2511 {
2512 for (ri = rn->info; ri; ri = ri->next)
2513 {
2514 struct attr dummy_attr;
2515 struct attr_extra dummy_extra;
2516 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002517
Christian Frankedcab1bb2012-12-07 16:45:52 +00002518 /* Provide dummy so the route-map can't modify the attributes */
2519 dummy_attr.extra = &dummy_extra;
2520 bgp_attr_dup(&dummy_attr, ri->attr);
2521 info.peer = ri->peer;
2522 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002523
Christian Frankedcab1bb2012-12-07 16:45:52 +00002524 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2525 RMAP_BGP, &info);
2526
2527 /* The route map might have set attributes. If we don't flush them
2528 * here, they will be leaked. */
2529 bgp_attr_flush(&dummy_attr);
2530 if (ret != RMAP_DENYMATCH)
2531 break;
2532 }
2533 if (ret != RMAP_DENYMATCH)
2534 break;
2535 }
paulfee0f4c2004-09-13 05:12:46 +00002536 bgp->peer_self->rmap_type = 0;
2537
paul718e3742002-12-13 20:15:29 +00002538 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002539 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002540 }
2541
2542 if (withdraw)
2543 {
2544 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2545 bgp_default_withdraw_send (peer, afi, safi);
2546 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2547 }
2548 else
2549 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002550 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2551 {
2552 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2553 bgp_default_update_send (peer, &attr, afi, safi, from);
2554 }
paul718e3742002-12-13 20:15:29 +00002555 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002556
2557 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002558 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002559}
2560
2561static void
2562bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002563 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002564{
2565 struct bgp_node *rn;
2566 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002567 struct attr attr;
2568 struct attr_extra extra;
2569
paul718e3742002-12-13 20:15:29 +00002570 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002571 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002572
2573 if (safi != SAFI_MPLS_VPN
2574 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2575 bgp_default_originate (peer, afi, safi, 0);
2576
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002577 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2578 attr.extra = &extra;
2579
paul718e3742002-12-13 20:15:29 +00002580 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2581 for (ri = rn->info; ri; ri = ri->next)
2582 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2583 {
paulfee0f4c2004-09-13 05:12:46 +00002584 if ( (rsclient) ?
2585 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2586 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002587 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2588 else
2589 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2590 }
2591}
2592
2593void
2594bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2595{
2596 struct bgp_node *rn;
2597 struct bgp_table *table;
2598
2599 if (peer->status != Established)
2600 return;
2601
2602 if (! peer->afc_nego[afi][safi])
2603 return;
2604
2605 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2606 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2607 return;
2608
2609 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002610 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002611 else
2612 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2613 rn = bgp_route_next(rn))
2614 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002615 bgp_announce_table (peer, afi, safi, table, 0);
2616
2617 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2618 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002619}
2620
2621void
2622bgp_announce_route_all (struct peer *peer)
2623{
2624 afi_t afi;
2625 safi_t safi;
2626
2627 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2628 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2629 bgp_announce_route (peer, afi, safi);
2630}
2631
2632static void
paulfee0f4c2004-09-13 05:12:46 +00002633bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002634 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002635{
2636 struct bgp_node *rn;
2637 struct bgp_adj_in *ain;
2638
2639 if (! table)
2640 table = rsclient->bgp->rib[afi][safi];
2641
2642 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2643 for (ain = rn->adj_in; ain; ain = ain->next)
2644 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002645 struct bgp_info *ri = rn->info;
2646
paulfee0f4c2004-09-13 05:12:46 +00002647 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002648 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2649 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002650 }
2651}
2652
2653void
2654bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2655{
2656 struct bgp_table *table;
2657 struct bgp_node *rn;
2658
2659 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002660 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002661
2662 else
2663 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2664 rn = bgp_route_next (rn))
2665 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002666 {
2667 struct prefix_rd prd;
2668 prd.family = AF_UNSPEC;
2669 prd.prefixlen = 64;
2670 memcpy(&prd.val, rn->p.u.val, 8);
2671
2672 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2673 }
paulfee0f4c2004-09-13 05:12:46 +00002674}
2675
2676static void
paul718e3742002-12-13 20:15:29 +00002677bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002678 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002679{
2680 int ret;
2681 struct bgp_node *rn;
2682 struct bgp_adj_in *ain;
2683
2684 if (! table)
2685 table = peer->bgp->rib[afi][safi];
2686
2687 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2688 for (ain = rn->adj_in; ain; ain = ain->next)
2689 {
2690 if (ain->peer == peer)
2691 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002692 struct bgp_info *ri = rn->info;
2693
paul718e3742002-12-13 20:15:29 +00002694 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2695 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002696 prd, (bgp_info_extra_get (ri))->tag, 1);
2697
paul718e3742002-12-13 20:15:29 +00002698 if (ret < 0)
2699 {
2700 bgp_unlock_node (rn);
2701 return;
2702 }
2703 continue;
2704 }
2705 }
2706}
2707
2708void
2709bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2710{
2711 struct bgp_node *rn;
2712 struct bgp_table *table;
2713
2714 if (peer->status != Established)
2715 return;
2716
2717 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002718 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002719 else
2720 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2721 rn = bgp_route_next (rn))
2722 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 {
2724 struct prefix_rd prd;
2725 prd.family = AF_UNSPEC;
2726 prd.prefixlen = 64;
2727 memcpy(&prd.val, rn->p.u.val, 8);
2728
2729 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2730 }
paul718e3742002-12-13 20:15:29 +00002731}
2732
Chris Caputo228da422009-07-18 05:44:03 +00002733
2734struct bgp_clear_node_queue
2735{
2736 struct bgp_node *rn;
2737 enum bgp_clear_route_type purpose;
2738};
2739
paul200df112005-06-01 11:17:05 +00002740static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002741bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002742{
Chris Caputo228da422009-07-18 05:44:03 +00002743 struct bgp_clear_node_queue *cnq = data;
2744 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002745 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002746 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002747 afi_t afi = bgp_node_table (rn)->afi;
2748 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002749
Paul Jakma64e580a2006-02-21 01:09:01 +00002750 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002751
Paul Jakma64e580a2006-02-21 01:09:01 +00002752 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002753 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002754 {
2755 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002756 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2757 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002758 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002759 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2760 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002761 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002762 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002763 break;
2764 }
paul200df112005-06-01 11:17:05 +00002765 return WQ_SUCCESS;
2766}
2767
2768static void
paul0fb58d52005-11-14 14:31:49 +00002769bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002770{
Chris Caputo228da422009-07-18 05:44:03 +00002771 struct bgp_clear_node_queue *cnq = data;
2772 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002773 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002774
2775 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002776 bgp_table_unlock (table);
2777 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002778}
2779
2780static void
paul94f2b392005-06-28 12:44:16 +00002781bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002782{
Paul Jakma64e580a2006-02-21 01:09:01 +00002783 struct peer *peer = wq->spec.data;
2784
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002785 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002786 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002787
2788 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002789}
2790
2791static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002792bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002793{
Paul Jakmaa2943652009-07-21 14:02:04 +01002794 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002795
Paul Jakmaa2943652009-07-21 14:02:04 +01002796 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002797#undef CLEAR_QUEUE_NAME_LEN
2798
2799 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002800 {
2801 zlog_err ("%s: Failed to allocate work queue", __func__);
2802 exit (1);
2803 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002804 peer->clear_node_queue->spec.hold = 10;
2805 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2806 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2807 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2808 peer->clear_node_queue->spec.max_retries = 0;
2809
2810 /* we only 'lock' this peer reference when the queue is actually active */
2811 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002812}
2813
paul718e3742002-12-13 20:15:29 +00002814static void
2815bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002816 struct bgp_table *table, struct peer *rsclient,
2817 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002818{
2819 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002820
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002821
paul718e3742002-12-13 20:15:29 +00002822 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002823 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002824
hasso6cf159b2005-03-21 10:28:14 +00002825 /* If still no table => afi/safi isn't configured at all or smth. */
2826 if (! table)
2827 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002828
2829 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2830 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002831 struct bgp_info *ri;
2832 struct bgp_adj_in *ain;
2833 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002834
2835 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2836 * queued for every clearing peer, regardless of whether it is
2837 * relevant to the peer at hand.
2838 *
2839 * Overview: There are 3 different indices which need to be
2840 * scrubbed, potentially, when a peer is removed:
2841 *
2842 * 1 peer's routes visible via the RIB (ie accepted routes)
2843 * 2 peer's routes visible by the (optional) peer's adj-in index
2844 * 3 other routes visible by the peer's adj-out index
2845 *
2846 * 3 there is no hurry in scrubbing, once the struct peer is
2847 * removed from bgp->peer, we could just GC such deleted peer's
2848 * adj-outs at our leisure.
2849 *
2850 * 1 and 2 must be 'scrubbed' in some way, at least made
2851 * invisible via RIB index before peer session is allowed to be
2852 * brought back up. So one needs to know when such a 'search' is
2853 * complete.
2854 *
2855 * Ideally:
2856 *
2857 * - there'd be a single global queue or a single RIB walker
2858 * - rather than tracking which route_nodes still need to be
2859 * examined on a peer basis, we'd track which peers still
2860 * aren't cleared
2861 *
2862 * Given that our per-peer prefix-counts now should be reliable,
2863 * this may actually be achievable. It doesn't seem to be a huge
2864 * problem at this time,
2865 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002866 for (ain = rn->adj_in; ain; ain = ain->next)
2867 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2868 {
2869 bgp_adj_in_remove (rn, ain);
2870 bgp_unlock_node (rn);
2871 break;
2872 }
2873 for (aout = rn->adj_out; aout; aout = aout->next)
2874 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2875 {
2876 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2877 bgp_unlock_node (rn);
2878 break;
2879 }
2880
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002881 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002882 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002883 {
Chris Caputo228da422009-07-18 05:44:03 +00002884 struct bgp_clear_node_queue *cnq;
2885
2886 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002887 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002888 bgp_lock_node (rn);
2889 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2890 sizeof (struct bgp_clear_node_queue));
2891 cnq->rn = rn;
2892 cnq->purpose = purpose;
2893 work_queue_add (peer->clear_node_queue, cnq);
2894 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002895 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002896 }
2897 return;
2898}
2899
2900void
Chris Caputo228da422009-07-18 05:44:03 +00002901bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2902 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002903{
2904 struct bgp_node *rn;
2905 struct bgp_table *table;
2906 struct peer *rsclient;
2907 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002908
Paul Jakma64e580a2006-02-21 01:09:01 +00002909 if (peer->clear_node_queue == NULL)
2910 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002911
Paul Jakmaca058a32006-09-14 02:58:49 +00002912 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2913 * Idle until it receives a Clearing_Completed event. This protects
2914 * against peers which flap faster than we can we clear, which could
2915 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002916 *
2917 * a) race with routes from the new session being installed before
2918 * clear_route_node visits the node (to delete the route of that
2919 * peer)
2920 * b) resource exhaustion, clear_route_node likely leads to an entry
2921 * on the process_main queue. Fast-flapping could cause that queue
2922 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002923 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002924 if (!peer->clear_node_queue->thread)
2925 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002926
Chris Caputo228da422009-07-18 05:44:03 +00002927 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002928 {
Chris Caputo228da422009-07-18 05:44:03 +00002929 case BGP_CLEAR_ROUTE_NORMAL:
2930 if (safi != SAFI_MPLS_VPN)
2931 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2932 else
2933 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2934 rn = bgp_route_next (rn))
2935 if ((table = rn->info) != NULL)
2936 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2937
2938 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2939 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2940 PEER_FLAG_RSERVER_CLIENT))
2941 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2942 break;
2943
2944 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2945 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2946 break;
2947
2948 default:
2949 assert (0);
2950 break;
paulfee0f4c2004-09-13 05:12:46 +00002951 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002952
Paul Jakmaca058a32006-09-14 02:58:49 +00002953 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002954 * completion function won't be run by workqueue code - call it here.
2955 * XXX: Actually, this assumption doesn't hold, see
2956 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002957 *
2958 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002959 * really needed if peer state is Established - peers in
2960 * pre-Established states shouldn't have any route-update state
2961 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002962 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002963 * We still can get here in pre-Established though, through
2964 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2965 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002966 *
2967 * At some future point, this check could be move to the top of the
2968 * function, and do a quick early-return when state is
2969 * pre-Established, avoiding above list and table scans. Once we're
2970 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002971 */
2972 if (!peer->clear_node_queue->thread)
2973 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002974}
2975
2976void
2977bgp_clear_route_all (struct peer *peer)
2978{
2979 afi_t afi;
2980 safi_t safi;
2981
2982 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2983 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002984 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002985}
2986
2987void
2988bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2989{
2990 struct bgp_table *table;
2991 struct bgp_node *rn;
2992 struct bgp_adj_in *ain;
2993
2994 table = peer->bgp->rib[afi][safi];
2995
2996 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2997 for (ain = rn->adj_in; ain ; ain = ain->next)
2998 if (ain->peer == peer)
2999 {
3000 bgp_adj_in_remove (rn, ain);
3001 bgp_unlock_node (rn);
3002 break;
3003 }
3004}
hasso93406d82005-02-02 14:40:33 +00003005
3006void
3007bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3008{
3009 struct bgp_node *rn;
3010 struct bgp_info *ri;
3011 struct bgp_table *table;
3012
3013 table = peer->bgp->rib[afi][safi];
3014
3015 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3016 {
3017 for (ri = rn->info; ri; ri = ri->next)
3018 if (ri->peer == peer)
3019 {
3020 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3021 bgp_rib_remove (rn, ri, peer, afi, safi);
3022 break;
3023 }
3024 }
3025}
paul718e3742002-12-13 20:15:29 +00003026
3027/* Delete all kernel routes. */
3028void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003029bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003030{
3031 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003032 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003033 struct bgp_node *rn;
3034 struct bgp_table *table;
3035 struct bgp_info *ri;
3036
paul1eb8ef22005-04-07 07:30:20 +00003037 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003038 {
3039 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3040
3041 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3042 for (ri = rn->info; ri; ri = ri->next)
3043 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3044 && ri->type == ZEBRA_ROUTE_BGP
3045 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003046 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003047
3048 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3049
3050 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3051 for (ri = rn->info; ri; ri = ri->next)
3052 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3053 && ri->type == ZEBRA_ROUTE_BGP
3054 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003055 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003056 }
3057}
3058
3059void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003060bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003061{
3062 vty_reset ();
3063 bgp_zclient_reset ();
3064 access_list_reset ();
3065 prefix_list_reset ();
3066}
3067
3068/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3069 value. */
3070int
3071bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3072{
3073 u_char *pnt;
3074 u_char *lim;
3075 struct prefix p;
3076 int psize;
3077 int ret;
3078
3079 /* Check peer status. */
3080 if (peer->status != Established)
3081 return 0;
3082
3083 pnt = packet->nlri;
3084 lim = pnt + packet->length;
3085
3086 for (; pnt < lim; pnt += psize)
3087 {
3088 /* Clear prefix structure. */
3089 memset (&p, 0, sizeof (struct prefix));
3090
3091 /* Fetch prefix length. */
3092 p.prefixlen = *pnt++;
3093 p.family = afi2family (packet->afi);
3094
3095 /* Already checked in nlri_sanity_check(). We do double check
3096 here. */
3097 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3098 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3099 return -1;
3100
3101 /* Packet size overflow check. */
3102 psize = PSIZE (p.prefixlen);
3103
3104 /* When packet overflow occur return immediately. */
3105 if (pnt + psize > lim)
3106 return -1;
3107
3108 /* Fetch prefix from NLRI packet. */
3109 memcpy (&p.u.prefix, pnt, psize);
3110
3111 /* Check address. */
3112 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3113 {
3114 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3115 {
paulf5ba3872004-07-09 12:11:31 +00003116 /*
3117 * From draft-ietf-idr-bgp4-22, Section 6.3:
3118 * If a BGP router receives an UPDATE message with a
3119 * semantically incorrect NLRI field, in which a prefix is
3120 * semantically incorrect (eg. an unexpected multicast IP
3121 * address), it should ignore the prefix.
3122 */
paul718e3742002-12-13 20:15:29 +00003123 zlog (peer->log, LOG_ERR,
3124 "IPv4 unicast NLRI is multicast address %s",
3125 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003126
paul718e3742002-12-13 20:15:29 +00003127 return -1;
3128 }
3129 }
3130
3131#ifdef HAVE_IPV6
3132 /* Check address. */
3133 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3134 {
3135 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3136 {
3137 char buf[BUFSIZ];
3138
3139 zlog (peer->log, LOG_WARNING,
3140 "IPv6 link-local NLRI received %s ignore this NLRI",
3141 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3142
3143 continue;
3144 }
3145 }
3146#endif /* HAVE_IPV6 */
3147
3148 /* Normal process. */
3149 if (attr)
3150 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3151 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3152 else
3153 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3154 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3155
3156 /* Address family configuration mismatch or maximum-prefix count
3157 overflow. */
3158 if (ret < 0)
3159 return -1;
3160 }
3161
3162 /* Packet length consistency check. */
3163 if (pnt != lim)
3164 return -1;
3165
3166 return 0;
3167}
3168
3169/* NLRI encode syntax check routine. */
3170int
3171bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3172 bgp_size_t length)
3173{
3174 u_char *end;
3175 u_char prefixlen;
3176 int psize;
3177
3178 end = pnt + length;
3179
3180 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3181 syntactic validity. If the field is syntactically incorrect,
3182 then the Error Subcode is set to Invalid Network Field. */
3183
3184 while (pnt < end)
3185 {
3186 prefixlen = *pnt++;
3187
3188 /* Prefix length check. */
3189 if ((afi == AFI_IP && prefixlen > 32)
3190 || (afi == AFI_IP6 && prefixlen > 128))
3191 {
3192 plog_err (peer->log,
3193 "%s [Error] Update packet error (wrong prefix length %d)",
3194 peer->host, prefixlen);
3195 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3196 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3197 return -1;
3198 }
3199
3200 /* Packet size overflow check. */
3201 psize = PSIZE (prefixlen);
3202
3203 if (pnt + psize > end)
3204 {
3205 plog_err (peer->log,
3206 "%s [Error] Update packet error"
3207 " (prefix data overflow prefix size is %d)",
3208 peer->host, psize);
3209 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3210 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3211 return -1;
3212 }
3213
3214 pnt += psize;
3215 }
3216
3217 /* Packet length consistency check. */
3218 if (pnt != end)
3219 {
3220 plog_err (peer->log,
3221 "%s [Error] Update packet error"
3222 " (prefix length mismatch with total length)",
3223 peer->host);
3224 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3225 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3226 return -1;
3227 }
3228 return 0;
3229}
3230
paul94f2b392005-06-28 12:44:16 +00003231static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003232bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003233{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003234 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003235}
3236
paul94f2b392005-06-28 12:44:16 +00003237static void
paul718e3742002-12-13 20:15:29 +00003238bgp_static_free (struct bgp_static *bgp_static)
3239{
3240 if (bgp_static->rmap.name)
3241 free (bgp_static->rmap.name);
3242 XFREE (MTYPE_BGP_STATIC, bgp_static);
3243}
3244
paul94f2b392005-06-28 12:44:16 +00003245static void
paulfee0f4c2004-09-13 05:12:46 +00003246bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3247 struct prefix *p, afi_t afi, safi_t safi)
3248{
3249 struct bgp_node *rn;
3250 struct bgp_info *ri;
3251
3252 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3253
3254 /* Check selected route and self inserted route. */
3255 for (ri = rn->info; ri; ri = ri->next)
3256 if (ri->peer == bgp->peer_self
3257 && ri->type == ZEBRA_ROUTE_BGP
3258 && ri->sub_type == BGP_ROUTE_STATIC)
3259 break;
3260
3261 /* Withdraw static BGP route from routing table. */
3262 if (ri)
3263 {
paulfee0f4c2004-09-13 05:12:46 +00003264 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003265 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003266 }
3267
3268 /* Unlock bgp_node_lookup. */
3269 bgp_unlock_node (rn);
3270}
3271
paul94f2b392005-06-28 12:44:16 +00003272static void
paulfee0f4c2004-09-13 05:12:46 +00003273bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003274 struct bgp_static *bgp_static,
3275 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003276{
3277 struct bgp_node *rn;
3278 struct bgp_info *ri;
3279 struct bgp_info *new;
3280 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003281 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003282 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003283 struct attr new_attr;
3284 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003285 struct bgp *bgp;
3286 int ret;
3287 char buf[SU_ADDRSTRLEN];
3288
3289 bgp = rsclient->bgp;
3290
Paul Jakma06e110f2006-05-12 23:29:22 +00003291 assert (bgp_static);
3292 if (!bgp_static)
3293 return;
3294
paulfee0f4c2004-09-13 05:12:46 +00003295 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3296
3297 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003298
3299 attr.nexthop = bgp_static->igpnexthop;
3300 attr.med = bgp_static->igpmetric;
3301 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003302
Paul Jakma41367172007-08-06 15:24:51 +00003303 if (bgp_static->atomic)
3304 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3305
paulfee0f4c2004-09-13 05:12:46 +00003306 /* Apply network route-map for export to this rsclient. */
3307 if (bgp_static->rmap.name)
3308 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003309 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003310 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003311 info.attr = &attr_tmp;
3312
paulfee0f4c2004-09-13 05:12:46 +00003313 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3314 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3315
3316 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3317
3318 rsclient->rmap_type = 0;
3319
3320 if (ret == RMAP_DENYMATCH)
3321 {
3322 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003323 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003324
3325 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003326 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003327 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003328 bgp_attr_extra_free (&attr);
3329
paulfee0f4c2004-09-13 05:12:46 +00003330 return;
3331 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003332 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003333 }
3334 else
3335 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003336
3337 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003338 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003339
paulfee0f4c2004-09-13 05:12:46 +00003340 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3341
Paul Jakmafb982c22007-05-04 20:15:47 +00003342 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3343 == RMAP_DENY)
3344 {
paulfee0f4c2004-09-13 05:12:46 +00003345 /* This BGP update is filtered. Log the reason then update BGP entry. */
3346 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003347 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003348 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3349 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3350 p->prefixlen, rsclient->host);
3351
3352 bgp->peer_self->rmap_type = 0;
3353
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003354 bgp_attr_unintern (&attr_new);
3355 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003356 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003357
3358 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3359
3360 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003361 }
paulfee0f4c2004-09-13 05:12:46 +00003362
3363 bgp->peer_self->rmap_type = 0;
3364
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003365 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003366 attr_new = bgp_attr_intern (&new_attr);
3367
3368 for (ri = rn->info; ri; ri = ri->next)
3369 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3370 && ri->sub_type == BGP_ROUTE_STATIC)
3371 break;
3372
3373 if (ri)
3374 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003375 if (attrhash_cmp (ri->attr, attr_new) &&
3376 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003377 {
3378 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003379 bgp_attr_unintern (&attr_new);
3380 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003382 return;
3383 }
3384 else
3385 {
3386 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003387 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003388
3389 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003390 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3391 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003392 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003393 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003394 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003395
3396 /* Process change. */
3397 bgp_process (bgp, rn, afi, safi);
3398 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003399 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003401 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003402 }
paulfee0f4c2004-09-13 05:12:46 +00003403 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003404
paulfee0f4c2004-09-13 05:12:46 +00003405 /* Make new BGP info. */
3406 new = bgp_info_new ();
3407 new->type = ZEBRA_ROUTE_BGP;
3408 new->sub_type = BGP_ROUTE_STATIC;
3409 new->peer = bgp->peer_self;
3410 SET_FLAG (new->flags, BGP_INFO_VALID);
3411 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003412 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 /* Register new BGP information. */
3415 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003416
3417 /* route_node_get lock */
3418 bgp_unlock_node (rn);
3419
paulfee0f4c2004-09-13 05:12:46 +00003420 /* Process change. */
3421 bgp_process (bgp, rn, afi, safi);
3422
3423 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003424 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003425 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003426}
3427
paul94f2b392005-06-28 12:44:16 +00003428static void
paulfee0f4c2004-09-13 05:12:46 +00003429bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003430 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3431{
3432 struct bgp_node *rn;
3433 struct bgp_info *ri;
3434 struct bgp_info *new;
3435 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003436 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003437 struct attr *attr_new;
3438 int ret;
3439
Paul Jakmadd8103a2006-05-12 23:27:30 +00003440 assert (bgp_static);
3441 if (!bgp_static)
3442 return;
3443
paulfee0f4c2004-09-13 05:12:46 +00003444 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003445
3446 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003447
3448 attr.nexthop = bgp_static->igpnexthop;
3449 attr.med = bgp_static->igpmetric;
3450 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003451
Paul Jakma41367172007-08-06 15:24:51 +00003452 if (bgp_static->atomic)
3453 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3454
paul718e3742002-12-13 20:15:29 +00003455 /* Apply route-map. */
3456 if (bgp_static->rmap.name)
3457 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003458 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003459 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003460 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003461
paulfee0f4c2004-09-13 05:12:46 +00003462 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3463
paul718e3742002-12-13 20:15:29 +00003464 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003465
paulfee0f4c2004-09-13 05:12:46 +00003466 bgp->peer_self->rmap_type = 0;
3467
paul718e3742002-12-13 20:15:29 +00003468 if (ret == RMAP_DENYMATCH)
3469 {
3470 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003471 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003472
3473 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003474 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003476 bgp_static_withdraw (bgp, p, afi, safi);
3477 return;
3478 }
paul286e1e72003-08-08 00:24:31 +00003479 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003480 }
paul286e1e72003-08-08 00:24:31 +00003481 else
3482 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003483
3484 for (ri = rn->info; ri; ri = ri->next)
3485 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3486 && ri->sub_type == BGP_ROUTE_STATIC)
3487 break;
3488
3489 if (ri)
3490 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003491 if (attrhash_cmp (ri->attr, attr_new) &&
3492 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003493 {
3494 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003495 bgp_attr_unintern (&attr_new);
3496 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003497 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003498 return;
3499 }
3500 else
3501 {
3502 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003503 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003504
3505 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003506 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3507 bgp_info_restore(rn, ri);
3508 else
3509 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003510 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003511 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003512 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003513
3514 /* Process change. */
3515 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3516 bgp_process (bgp, rn, afi, safi);
3517 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003519 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003520 return;
3521 }
3522 }
3523
3524 /* Make new BGP info. */
3525 new = bgp_info_new ();
3526 new->type = ZEBRA_ROUTE_BGP;
3527 new->sub_type = BGP_ROUTE_STATIC;
3528 new->peer = bgp->peer_self;
3529 SET_FLAG (new->flags, BGP_INFO_VALID);
3530 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003531 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003532
3533 /* Aggregate address increment. */
3534 bgp_aggregate_increment (bgp, p, new, afi, safi);
3535
3536 /* Register new BGP information. */
3537 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003538
3539 /* route_node_get lock */
3540 bgp_unlock_node (rn);
3541
paul718e3742002-12-13 20:15:29 +00003542 /* Process change. */
3543 bgp_process (bgp, rn, afi, safi);
3544
3545 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003547 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003548}
3549
3550void
paulfee0f4c2004-09-13 05:12:46 +00003551bgp_static_update (struct bgp *bgp, struct prefix *p,
3552 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3553{
3554 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003555 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003556
3557 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3558
paul1eb8ef22005-04-07 07:30:20 +00003559 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003560 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003561 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3562 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003563 }
3564}
3565
paul94f2b392005-06-28 12:44:16 +00003566static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003567bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3568 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003569{
3570 struct bgp_node *rn;
3571 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003572
paulfee0f4c2004-09-13 05:12:46 +00003573 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003574
3575 /* Make new BGP info. */
3576 new = bgp_info_new ();
3577 new->type = ZEBRA_ROUTE_BGP;
3578 new->sub_type = BGP_ROUTE_STATIC;
3579 new->peer = bgp->peer_self;
3580 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3581 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003582 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003583 new->extra = bgp_info_extra_new();
3584 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003585
3586 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003587 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003588
3589 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003590 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003591
paul200df112005-06-01 11:17:05 +00003592 /* route_node_get lock */
3593 bgp_unlock_node (rn);
3594
paul718e3742002-12-13 20:15:29 +00003595 /* Process change. */
3596 bgp_process (bgp, rn, afi, safi);
3597}
3598
3599void
3600bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3601 safi_t safi)
3602{
3603 struct bgp_node *rn;
3604 struct bgp_info *ri;
3605
paulfee0f4c2004-09-13 05:12:46 +00003606 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003607
3608 /* Check selected route and self inserted route. */
3609 for (ri = rn->info; ri; ri = ri->next)
3610 if (ri->peer == bgp->peer_self
3611 && ri->type == ZEBRA_ROUTE_BGP
3612 && ri->sub_type == BGP_ROUTE_STATIC)
3613 break;
3614
3615 /* Withdraw static BGP route from routing table. */
3616 if (ri)
3617 {
3618 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003619 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003620 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003621 }
3622
3623 /* Unlock bgp_node_lookup. */
3624 bgp_unlock_node (rn);
3625}
3626
3627void
paulfee0f4c2004-09-13 05:12:46 +00003628bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3629{
3630 struct bgp_static *bgp_static;
3631 struct bgp *bgp;
3632 struct bgp_node *rn;
3633 struct prefix *p;
3634
3635 bgp = rsclient->bgp;
3636
3637 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3638 if ((bgp_static = rn->info) != NULL)
3639 {
3640 p = &rn->p;
3641
3642 bgp_static_update_rsclient (rsclient, p, bgp_static,
3643 afi, safi);
3644 }
3645}
3646
paul94f2b392005-06-28 12:44:16 +00003647static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003648bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3649 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003650{
3651 struct bgp_node *rn;
3652 struct bgp_info *ri;
3653
paulfee0f4c2004-09-13 05:12:46 +00003654 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003655
3656 /* Check selected route and self inserted route. */
3657 for (ri = rn->info; ri; ri = ri->next)
3658 if (ri->peer == bgp->peer_self
3659 && ri->type == ZEBRA_ROUTE_BGP
3660 && ri->sub_type == BGP_ROUTE_STATIC)
3661 break;
3662
3663 /* Withdraw static BGP route from routing table. */
3664 if (ri)
3665 {
3666 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003667 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003668 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003669 }
3670
3671 /* Unlock bgp_node_lookup. */
3672 bgp_unlock_node (rn);
3673}
3674
3675/* Configure static BGP network. When user don't run zebra, static
3676 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003677static int
paulfd79ac92004-10-13 05:06:08 +00003678bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003679 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003680{
3681 int ret;
3682 struct prefix p;
3683 struct bgp_static *bgp_static;
3684 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003685 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003686
3687 /* Convert IP prefix string to struct prefix. */
3688 ret = str2prefix (ip_str, &p);
3689 if (! ret)
3690 {
3691 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3692 return CMD_WARNING;
3693 }
3694#ifdef HAVE_IPV6
3695 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3696 {
3697 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3698 VTY_NEWLINE);
3699 return CMD_WARNING;
3700 }
3701#endif /* HAVE_IPV6 */
3702
3703 apply_mask (&p);
3704
3705 /* Set BGP static route configuration. */
3706 rn = bgp_node_get (bgp->route[afi][safi], &p);
3707
3708 if (rn->info)
3709 {
3710 /* Configuration change. */
3711 bgp_static = rn->info;
3712
3713 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003714 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3715 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003716
paul718e3742002-12-13 20:15:29 +00003717 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003718
paul718e3742002-12-13 20:15:29 +00003719 if (rmap)
3720 {
3721 if (bgp_static->rmap.name)
3722 free (bgp_static->rmap.name);
3723 bgp_static->rmap.name = strdup (rmap);
3724 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3725 }
3726 else
3727 {
3728 if (bgp_static->rmap.name)
3729 free (bgp_static->rmap.name);
3730 bgp_static->rmap.name = NULL;
3731 bgp_static->rmap.map = NULL;
3732 bgp_static->valid = 0;
3733 }
3734 bgp_unlock_node (rn);
3735 }
3736 else
3737 {
3738 /* New configuration. */
3739 bgp_static = bgp_static_new ();
3740 bgp_static->backdoor = backdoor;
3741 bgp_static->valid = 0;
3742 bgp_static->igpmetric = 0;
3743 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003744
paul718e3742002-12-13 20:15:29 +00003745 if (rmap)
3746 {
3747 if (bgp_static->rmap.name)
3748 free (bgp_static->rmap.name);
3749 bgp_static->rmap.name = strdup (rmap);
3750 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3751 }
3752 rn->info = bgp_static;
3753 }
3754
3755 /* If BGP scan is not enabled, we should install this route here. */
3756 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3757 {
3758 bgp_static->valid = 1;
3759
3760 if (need_update)
3761 bgp_static_withdraw (bgp, &p, afi, safi);
3762
3763 if (! bgp_static->backdoor)
3764 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3765 }
3766
3767 return CMD_SUCCESS;
3768}
3769
3770/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003771static int
paulfd79ac92004-10-13 05:06:08 +00003772bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003773 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003774{
3775 int ret;
3776 struct prefix p;
3777 struct bgp_static *bgp_static;
3778 struct bgp_node *rn;
3779
3780 /* Convert IP prefix string to struct prefix. */
3781 ret = str2prefix (ip_str, &p);
3782 if (! ret)
3783 {
3784 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3785 return CMD_WARNING;
3786 }
3787#ifdef HAVE_IPV6
3788 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3789 {
3790 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3791 VTY_NEWLINE);
3792 return CMD_WARNING;
3793 }
3794#endif /* HAVE_IPV6 */
3795
3796 apply_mask (&p);
3797
3798 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3799 if (! rn)
3800 {
3801 vty_out (vty, "%% Can't find specified static route configuration.%s",
3802 VTY_NEWLINE);
3803 return CMD_WARNING;
3804 }
3805
3806 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003807
paul718e3742002-12-13 20:15:29 +00003808 /* Update BGP RIB. */
3809 if (! bgp_static->backdoor)
3810 bgp_static_withdraw (bgp, &p, afi, safi);
3811
3812 /* Clear configuration. */
3813 bgp_static_free (bgp_static);
3814 rn->info = NULL;
3815 bgp_unlock_node (rn);
3816 bgp_unlock_node (rn);
3817
3818 return CMD_SUCCESS;
3819}
3820
3821/* Called from bgp_delete(). Delete all static routes from the BGP
3822 instance. */
3823void
3824bgp_static_delete (struct bgp *bgp)
3825{
3826 afi_t afi;
3827 safi_t safi;
3828 struct bgp_node *rn;
3829 struct bgp_node *rm;
3830 struct bgp_table *table;
3831 struct bgp_static *bgp_static;
3832
3833 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3834 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3835 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3836 if (rn->info != NULL)
3837 {
3838 if (safi == SAFI_MPLS_VPN)
3839 {
3840 table = rn->info;
3841
3842 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3843 {
3844 bgp_static = rn->info;
3845 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3846 AFI_IP, SAFI_MPLS_VPN,
3847 (struct prefix_rd *)&rn->p,
3848 bgp_static->tag);
3849 bgp_static_free (bgp_static);
3850 rn->info = NULL;
3851 bgp_unlock_node (rn);
3852 }
3853 }
3854 else
3855 {
3856 bgp_static = rn->info;
3857 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3858 bgp_static_free (bgp_static);
3859 rn->info = NULL;
3860 bgp_unlock_node (rn);
3861 }
3862 }
3863}
3864
3865int
paulfd79ac92004-10-13 05:06:08 +00003866bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3867 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003868{
3869 int ret;
3870 struct prefix p;
3871 struct prefix_rd prd;
3872 struct bgp *bgp;
3873 struct bgp_node *prn;
3874 struct bgp_node *rn;
3875 struct bgp_table *table;
3876 struct bgp_static *bgp_static;
3877 u_char tag[3];
3878
3879 bgp = vty->index;
3880
3881 ret = str2prefix (ip_str, &p);
3882 if (! ret)
3883 {
3884 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3885 return CMD_WARNING;
3886 }
3887 apply_mask (&p);
3888
3889 ret = str2prefix_rd (rd_str, &prd);
3890 if (! ret)
3891 {
3892 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3893 return CMD_WARNING;
3894 }
3895
3896 ret = str2tag (tag_str, tag);
3897 if (! ret)
3898 {
3899 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3900 return CMD_WARNING;
3901 }
3902
3903 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3904 (struct prefix *)&prd);
3905 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003906 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003907 else
3908 bgp_unlock_node (prn);
3909 table = prn->info;
3910
3911 rn = bgp_node_get (table, &p);
3912
3913 if (rn->info)
3914 {
3915 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3916 bgp_unlock_node (rn);
3917 }
3918 else
3919 {
3920 /* New configuration. */
3921 bgp_static = bgp_static_new ();
3922 bgp_static->valid = 1;
3923 memcpy (bgp_static->tag, tag, 3);
3924 rn->info = bgp_static;
3925
3926 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3927 }
3928
3929 return CMD_SUCCESS;
3930}
3931
3932/* Configure static BGP network. */
3933int
paulfd79ac92004-10-13 05:06:08 +00003934bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3935 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003936{
3937 int ret;
3938 struct bgp *bgp;
3939 struct prefix p;
3940 struct prefix_rd prd;
3941 struct bgp_node *prn;
3942 struct bgp_node *rn;
3943 struct bgp_table *table;
3944 struct bgp_static *bgp_static;
3945 u_char tag[3];
3946
3947 bgp = vty->index;
3948
3949 /* Convert IP prefix string to struct prefix. */
3950 ret = str2prefix (ip_str, &p);
3951 if (! ret)
3952 {
3953 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3954 return CMD_WARNING;
3955 }
3956 apply_mask (&p);
3957
3958 ret = str2prefix_rd (rd_str, &prd);
3959 if (! ret)
3960 {
3961 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3962 return CMD_WARNING;
3963 }
3964
3965 ret = str2tag (tag_str, tag);
3966 if (! ret)
3967 {
3968 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3969 return CMD_WARNING;
3970 }
3971
3972 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3973 (struct prefix *)&prd);
3974 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003975 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003976 else
3977 bgp_unlock_node (prn);
3978 table = prn->info;
3979
3980 rn = bgp_node_lookup (table, &p);
3981
3982 if (rn)
3983 {
3984 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3985
3986 bgp_static = rn->info;
3987 bgp_static_free (bgp_static);
3988 rn->info = NULL;
3989 bgp_unlock_node (rn);
3990 bgp_unlock_node (rn);
3991 }
3992 else
3993 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3994
3995 return CMD_SUCCESS;
3996}
3997
3998DEFUN (bgp_network,
3999 bgp_network_cmd,
4000 "network A.B.C.D/M",
4001 "Specify a network to announce via BGP\n"
4002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4003{
4004 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004005 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004006}
4007
4008DEFUN (bgp_network_route_map,
4009 bgp_network_route_map_cmd,
4010 "network A.B.C.D/M route-map WORD",
4011 "Specify a network to announce via BGP\n"
4012 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4013 "Route-map to modify the attributes\n"
4014 "Name of the route map\n")
4015{
4016 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004017 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004018}
4019
4020DEFUN (bgp_network_backdoor,
4021 bgp_network_backdoor_cmd,
4022 "network A.B.C.D/M backdoor",
4023 "Specify a network to announce via BGP\n"
4024 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4025 "Specify a BGP backdoor route\n")
4026{
Paul Jakma41367172007-08-06 15:24:51 +00004027 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004028 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004029}
4030
4031DEFUN (bgp_network_mask,
4032 bgp_network_mask_cmd,
4033 "network A.B.C.D mask A.B.C.D",
4034 "Specify a network to announce via BGP\n"
4035 "Network number\n"
4036 "Network mask\n"
4037 "Network mask\n")
4038{
4039 int ret;
4040 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004041
paul718e3742002-12-13 20:15:29 +00004042 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4043 if (! ret)
4044 {
4045 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4046 return CMD_WARNING;
4047 }
4048
4049 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004050 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004051}
4052
4053DEFUN (bgp_network_mask_route_map,
4054 bgp_network_mask_route_map_cmd,
4055 "network A.B.C.D mask A.B.C.D route-map WORD",
4056 "Specify a network to announce via BGP\n"
4057 "Network number\n"
4058 "Network mask\n"
4059 "Network mask\n"
4060 "Route-map to modify the attributes\n"
4061 "Name of the route map\n")
4062{
4063 int ret;
4064 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004065
paul718e3742002-12-13 20:15:29 +00004066 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4067 if (! ret)
4068 {
4069 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4070 return CMD_WARNING;
4071 }
4072
4073 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004074 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004075}
4076
4077DEFUN (bgp_network_mask_backdoor,
4078 bgp_network_mask_backdoor_cmd,
4079 "network A.B.C.D mask A.B.C.D backdoor",
4080 "Specify a network to announce via BGP\n"
4081 "Network number\n"
4082 "Network mask\n"
4083 "Network mask\n"
4084 "Specify a BGP backdoor route\n")
4085{
4086 int ret;
4087 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004088
paul718e3742002-12-13 20:15:29 +00004089 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4090 if (! ret)
4091 {
4092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4093 return CMD_WARNING;
4094 }
4095
Paul Jakma41367172007-08-06 15:24:51 +00004096 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004097 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004098}
4099
4100DEFUN (bgp_network_mask_natural,
4101 bgp_network_mask_natural_cmd,
4102 "network A.B.C.D",
4103 "Specify a network to announce via BGP\n"
4104 "Network number\n")
4105{
4106 int ret;
4107 char prefix_str[BUFSIZ];
4108
4109 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4110 if (! ret)
4111 {
4112 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4113 return CMD_WARNING;
4114 }
4115
4116 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004117 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004118}
4119
4120DEFUN (bgp_network_mask_natural_route_map,
4121 bgp_network_mask_natural_route_map_cmd,
4122 "network A.B.C.D route-map WORD",
4123 "Specify a network to announce via BGP\n"
4124 "Network number\n"
4125 "Route-map to modify the attributes\n"
4126 "Name of the route map\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
4138 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004139 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004140}
4141
4142DEFUN (bgp_network_mask_natural_backdoor,
4143 bgp_network_mask_natural_backdoor_cmd,
4144 "network A.B.C.D backdoor",
4145 "Specify a network to announce via BGP\n"
4146 "Network number\n"
4147 "Specify a BGP backdoor route\n")
4148{
4149 int ret;
4150 char prefix_str[BUFSIZ];
4151
4152 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4153 if (! ret)
4154 {
4155 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4156 return CMD_WARNING;
4157 }
4158
Paul Jakma41367172007-08-06 15:24:51 +00004159 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004160 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004161}
4162
4163DEFUN (no_bgp_network,
4164 no_bgp_network_cmd,
4165 "no network A.B.C.D/M",
4166 NO_STR
4167 "Specify a network to announce via BGP\n"
4168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4169{
4170 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4171 bgp_node_safi (vty));
4172}
4173
4174ALIAS (no_bgp_network,
4175 no_bgp_network_route_map_cmd,
4176 "no network A.B.C.D/M route-map WORD",
4177 NO_STR
4178 "Specify a network to announce via BGP\n"
4179 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4180 "Route-map to modify the attributes\n"
4181 "Name of the route map\n")
4182
4183ALIAS (no_bgp_network,
4184 no_bgp_network_backdoor_cmd,
4185 "no network A.B.C.D/M backdoor",
4186 NO_STR
4187 "Specify a network to announce via BGP\n"
4188 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4189 "Specify a BGP backdoor route\n")
4190
4191DEFUN (no_bgp_network_mask,
4192 no_bgp_network_mask_cmd,
4193 "no network A.B.C.D mask A.B.C.D",
4194 NO_STR
4195 "Specify a network to announce via BGP\n"
4196 "Network number\n"
4197 "Network mask\n"
4198 "Network mask\n")
4199{
4200 int ret;
4201 char prefix_str[BUFSIZ];
4202
4203 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4204 if (! ret)
4205 {
4206 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4207 return CMD_WARNING;
4208 }
4209
4210 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4211 bgp_node_safi (vty));
4212}
4213
4214ALIAS (no_bgp_network_mask,
4215 no_bgp_network_mask_route_map_cmd,
4216 "no network A.B.C.D mask A.B.C.D route-map WORD",
4217 NO_STR
4218 "Specify a network to announce via BGP\n"
4219 "Network number\n"
4220 "Network mask\n"
4221 "Network mask\n"
4222 "Route-map to modify the attributes\n"
4223 "Name of the route map\n")
4224
4225ALIAS (no_bgp_network_mask,
4226 no_bgp_network_mask_backdoor_cmd,
4227 "no network A.B.C.D mask A.B.C.D backdoor",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "Network number\n"
4231 "Network mask\n"
4232 "Network mask\n"
4233 "Specify a BGP backdoor route\n")
4234
4235DEFUN (no_bgp_network_mask_natural,
4236 no_bgp_network_mask_natural_cmd,
4237 "no network A.B.C.D",
4238 NO_STR
4239 "Specify a network to announce via BGP\n"
4240 "Network number\n")
4241{
4242 int ret;
4243 char prefix_str[BUFSIZ];
4244
4245 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4246 if (! ret)
4247 {
4248 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4249 return CMD_WARNING;
4250 }
4251
4252 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4253 bgp_node_safi (vty));
4254}
4255
4256ALIAS (no_bgp_network_mask_natural,
4257 no_bgp_network_mask_natural_route_map_cmd,
4258 "no network A.B.C.D route-map WORD",
4259 NO_STR
4260 "Specify a network to announce via BGP\n"
4261 "Network number\n"
4262 "Route-map to modify the attributes\n"
4263 "Name of the route map\n")
4264
4265ALIAS (no_bgp_network_mask_natural,
4266 no_bgp_network_mask_natural_backdoor_cmd,
4267 "no network A.B.C.D backdoor",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "Network number\n"
4271 "Specify a BGP backdoor route\n")
4272
4273#ifdef HAVE_IPV6
4274DEFUN (ipv6_bgp_network,
4275 ipv6_bgp_network_cmd,
4276 "network X:X::X:X/M",
4277 "Specify a network to announce via BGP\n"
4278 "IPv6 prefix <network>/<length>\n")
4279{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304280 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004281 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004282}
4283
4284DEFUN (ipv6_bgp_network_route_map,
4285 ipv6_bgp_network_route_map_cmd,
4286 "network X:X::X:X/M route-map WORD",
4287 "Specify a network to announce via BGP\n"
4288 "IPv6 prefix <network>/<length>\n"
4289 "Route-map to modify the attributes\n"
4290 "Name of the route map\n")
4291{
4292 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004293 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004294}
4295
4296DEFUN (no_ipv6_bgp_network,
4297 no_ipv6_bgp_network_cmd,
4298 "no network X:X::X:X/M",
4299 NO_STR
4300 "Specify a network to announce via BGP\n"
4301 "IPv6 prefix <network>/<length>\n")
4302{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304303 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004304}
4305
4306ALIAS (no_ipv6_bgp_network,
4307 no_ipv6_bgp_network_route_map_cmd,
4308 "no network X:X::X:X/M route-map WORD",
4309 NO_STR
4310 "Specify a network to announce via BGP\n"
4311 "IPv6 prefix <network>/<length>\n"
4312 "Route-map to modify the attributes\n"
4313 "Name of the route map\n")
4314
4315ALIAS (ipv6_bgp_network,
4316 old_ipv6_bgp_network_cmd,
4317 "ipv6 bgp network X:X::X:X/M",
4318 IPV6_STR
4319 BGP_STR
4320 "Specify a network to announce via BGP\n"
4321 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4322
4323ALIAS (no_ipv6_bgp_network,
4324 old_no_ipv6_bgp_network_cmd,
4325 "no ipv6 bgp network X:X::X:X/M",
4326 NO_STR
4327 IPV6_STR
4328 BGP_STR
4329 "Specify a network to announce via BGP\n"
4330 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4331#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004332
4333/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4334ALIAS_DEPRECATED (bgp_network,
4335 bgp_network_ttl_cmd,
4336 "network A.B.C.D/M pathlimit <0-255>",
4337 "Specify a network to announce via BGP\n"
4338 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4339 "AS-Path hopcount limit attribute\n"
4340 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4341ALIAS_DEPRECATED (bgp_network_backdoor,
4342 bgp_network_backdoor_ttl_cmd,
4343 "network A.B.C.D/M backdoor pathlimit <0-255>",
4344 "Specify a network to announce via BGP\n"
4345 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4346 "Specify a BGP backdoor route\n"
4347 "AS-Path hopcount limit attribute\n"
4348 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4349ALIAS_DEPRECATED (bgp_network_mask,
4350 bgp_network_mask_ttl_cmd,
4351 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4352 "Specify a network to announce via BGP\n"
4353 "Network number\n"
4354 "Network mask\n"
4355 "Network mask\n"
4356 "AS-Path hopcount limit attribute\n"
4357 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4358ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4359 bgp_network_mask_backdoor_ttl_cmd,
4360 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4361 "Specify a network to announce via BGP\n"
4362 "Network number\n"
4363 "Network mask\n"
4364 "Network mask\n"
4365 "Specify a BGP backdoor route\n"
4366 "AS-Path hopcount limit attribute\n"
4367 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4368ALIAS_DEPRECATED (bgp_network_mask_natural,
4369 bgp_network_mask_natural_ttl_cmd,
4370 "network A.B.C.D pathlimit <0-255>",
4371 "Specify a network to announce via BGP\n"
4372 "Network number\n"
4373 "AS-Path hopcount limit attribute\n"
4374 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4375ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4376 bgp_network_mask_natural_backdoor_ttl_cmd,
4377 "network A.B.C.D backdoor pathlimit (1-255>",
4378 "Specify a network to announce via BGP\n"
4379 "Network number\n"
4380 "Specify a BGP backdoor route\n"
4381 "AS-Path hopcount limit attribute\n"
4382 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4383ALIAS_DEPRECATED (no_bgp_network,
4384 no_bgp_network_ttl_cmd,
4385 "no network A.B.C.D/M pathlimit <0-255>",
4386 NO_STR
4387 "Specify a network to announce via BGP\n"
4388 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4389 "AS-Path hopcount limit attribute\n"
4390 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4391ALIAS_DEPRECATED (no_bgp_network,
4392 no_bgp_network_backdoor_ttl_cmd,
4393 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4394 NO_STR
4395 "Specify a network to announce via BGP\n"
4396 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\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,
4401 no_bgp_network_mask_ttl_cmd,
4402 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4403 NO_STR
4404 "Specify a network to announce via BGP\n"
4405 "Network number\n"
4406 "Network mask\n"
4407 "Network mask\n"
4408 "AS-Path hopcount limit attribute\n"
4409 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4410ALIAS_DEPRECATED (no_bgp_network_mask,
4411 no_bgp_network_mask_backdoor_ttl_cmd,
4412 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4413 NO_STR
4414 "Specify a network to announce via BGP\n"
4415 "Network number\n"
4416 "Network mask\n"
4417 "Network mask\n"
4418 "Specify a BGP backdoor route\n"
4419 "AS-Path hopcount limit attribute\n"
4420 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4421ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4422 no_bgp_network_mask_natural_ttl_cmd,
4423 "no network A.B.C.D pathlimit <0-255>",
4424 NO_STR
4425 "Specify a network to announce via BGP\n"
4426 "Network number\n"
4427 "AS-Path hopcount limit attribute\n"
4428 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4429ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4430 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4431 "no network A.B.C.D backdoor pathlimit <0-255>",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "Network number\n"
4435 "Specify a BGP backdoor route\n"
4436 "AS-Path hopcount limit attribute\n"
4437 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004438#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004439ALIAS_DEPRECATED (ipv6_bgp_network,
4440 ipv6_bgp_network_ttl_cmd,
4441 "network X:X::X:X/M pathlimit <0-255>",
4442 "Specify a network to announce via BGP\n"
4443 "IPv6 prefix <network>/<length>\n"
4444 "AS-Path hopcount limit attribute\n"
4445 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4446ALIAS_DEPRECATED (no_ipv6_bgp_network,
4447 no_ipv6_bgp_network_ttl_cmd,
4448 "no network X:X::X:X/M pathlimit <0-255>",
4449 NO_STR
4450 "Specify a network to announce via BGP\n"
4451 "IPv6 prefix <network>/<length>\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004454#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004455
4456/* Aggreagete address:
4457
4458 advertise-map Set condition to advertise attribute
4459 as-set Generate AS set path information
4460 attribute-map Set attributes of aggregate
4461 route-map Set parameters of aggregate
4462 summary-only Filter more specific routes from updates
4463 suppress-map Conditionally filter more specific routes from updates
4464 <cr>
4465 */
4466struct bgp_aggregate
4467{
4468 /* Summary-only flag. */
4469 u_char summary_only;
4470
4471 /* AS set generation. */
4472 u_char as_set;
4473
4474 /* Route-map for aggregated route. */
4475 struct route_map *map;
4476
4477 /* Suppress-count. */
4478 unsigned long count;
4479
4480 /* SAFI configuration. */
4481 safi_t safi;
4482};
4483
paul94f2b392005-06-28 12:44:16 +00004484static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004485bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004486{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004487 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004488}
4489
paul94f2b392005-06-28 12:44:16 +00004490static void
paul718e3742002-12-13 20:15:29 +00004491bgp_aggregate_free (struct bgp_aggregate *aggregate)
4492{
4493 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4494}
4495
paul94f2b392005-06-28 12:44:16 +00004496static void
paul718e3742002-12-13 20:15:29 +00004497bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4498 afi_t afi, safi_t safi, struct bgp_info *del,
4499 struct bgp_aggregate *aggregate)
4500{
4501 struct bgp_table *table;
4502 struct bgp_node *top;
4503 struct bgp_node *rn;
4504 u_char origin;
4505 struct aspath *aspath = NULL;
4506 struct aspath *asmerge = NULL;
4507 struct community *community = NULL;
4508 struct community *commerge = NULL;
4509 struct in_addr nexthop;
4510 u_int32_t med = 0;
4511 struct bgp_info *ri;
4512 struct bgp_info *new;
4513 int first = 1;
4514 unsigned long match = 0;
4515
4516 /* Record adding route's nexthop and med. */
4517 if (rinew)
4518 {
4519 nexthop = rinew->attr->nexthop;
4520 med = rinew->attr->med;
4521 }
4522
4523 /* ORIGIN attribute: If at least one route among routes that are
4524 aggregated has ORIGIN with the value INCOMPLETE, then the
4525 aggregated route must have the ORIGIN attribute with the value
4526 INCOMPLETE. Otherwise, if at least one route among routes that
4527 are aggregated has ORIGIN with the value EGP, then the aggregated
4528 route must have the origin attribute with the value EGP. In all
4529 other case the value of the ORIGIN attribute of the aggregated
4530 route is INTERNAL. */
4531 origin = BGP_ORIGIN_IGP;
4532
4533 table = bgp->rib[afi][safi];
4534
4535 top = bgp_node_get (table, p);
4536 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4537 if (rn->p.prefixlen > p->prefixlen)
4538 {
4539 match = 0;
4540
4541 for (ri = rn->info; ri; ri = ri->next)
4542 {
4543 if (BGP_INFO_HOLDDOWN (ri))
4544 continue;
4545
4546 if (del && ri == del)
4547 continue;
4548
4549 if (! rinew && first)
4550 {
4551 nexthop = ri->attr->nexthop;
4552 med = ri->attr->med;
4553 first = 0;
4554 }
4555
4556#ifdef AGGREGATE_NEXTHOP_CHECK
4557 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4558 || ri->attr->med != med)
4559 {
4560 if (aspath)
4561 aspath_free (aspath);
4562 if (community)
4563 community_free (community);
4564 bgp_unlock_node (rn);
4565 bgp_unlock_node (top);
4566 return;
4567 }
4568#endif /* AGGREGATE_NEXTHOP_CHECK */
4569
4570 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4571 {
4572 if (aggregate->summary_only)
4573 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004574 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004575 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004576 match++;
4577 }
4578
4579 aggregate->count++;
4580
4581 if (aggregate->as_set)
4582 {
4583 if (origin < ri->attr->origin)
4584 origin = ri->attr->origin;
4585
4586 if (aspath)
4587 {
4588 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4589 aspath_free (aspath);
4590 aspath = asmerge;
4591 }
4592 else
4593 aspath = aspath_dup (ri->attr->aspath);
4594
4595 if (ri->attr->community)
4596 {
4597 if (community)
4598 {
4599 commerge = community_merge (community,
4600 ri->attr->community);
4601 community = community_uniq_sort (commerge);
4602 community_free (commerge);
4603 }
4604 else
4605 community = community_dup (ri->attr->community);
4606 }
4607 }
4608 }
4609 }
4610 if (match)
4611 bgp_process (bgp, rn, afi, safi);
4612 }
4613 bgp_unlock_node (top);
4614
4615 if (rinew)
4616 {
4617 aggregate->count++;
4618
4619 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004620 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004621
4622 if (aggregate->as_set)
4623 {
4624 if (origin < rinew->attr->origin)
4625 origin = rinew->attr->origin;
4626
4627 if (aspath)
4628 {
4629 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4630 aspath_free (aspath);
4631 aspath = asmerge;
4632 }
4633 else
4634 aspath = aspath_dup (rinew->attr->aspath);
4635
4636 if (rinew->attr->community)
4637 {
4638 if (community)
4639 {
4640 commerge = community_merge (community,
4641 rinew->attr->community);
4642 community = community_uniq_sort (commerge);
4643 community_free (commerge);
4644 }
4645 else
4646 community = community_dup (rinew->attr->community);
4647 }
4648 }
4649 }
4650
4651 if (aggregate->count > 0)
4652 {
4653 rn = bgp_node_get (table, p);
4654 new = bgp_info_new ();
4655 new->type = ZEBRA_ROUTE_BGP;
4656 new->sub_type = BGP_ROUTE_AGGREGATE;
4657 new->peer = bgp->peer_self;
4658 SET_FLAG (new->flags, BGP_INFO_VALID);
4659 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004660 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004661
4662 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004663 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004664 bgp_process (bgp, rn, afi, safi);
4665 }
4666 else
4667 {
4668 if (aspath)
4669 aspath_free (aspath);
4670 if (community)
4671 community_free (community);
4672 }
4673}
4674
4675void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4676 struct bgp_aggregate *);
4677
4678void
4679bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4680 struct bgp_info *ri, afi_t afi, safi_t safi)
4681{
4682 struct bgp_node *child;
4683 struct bgp_node *rn;
4684 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004685 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004686
4687 /* MPLS-VPN aggregation is not yet supported. */
4688 if (safi == SAFI_MPLS_VPN)
4689 return;
4690
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004691 table = bgp->aggregate[afi][safi];
4692
4693 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004694 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004695 return;
4696
paul718e3742002-12-13 20:15:29 +00004697 if (p->prefixlen == 0)
4698 return;
4699
4700 if (BGP_INFO_HOLDDOWN (ri))
4701 return;
4702
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004703 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004704
4705 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004706 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004707 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4708 {
4709 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004710 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004711 }
4712 bgp_unlock_node (child);
4713}
4714
4715void
4716bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4717 struct bgp_info *del, afi_t afi, safi_t safi)
4718{
4719 struct bgp_node *child;
4720 struct bgp_node *rn;
4721 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004722 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004723
4724 /* MPLS-VPN aggregation is not yet supported. */
4725 if (safi == SAFI_MPLS_VPN)
4726 return;
4727
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004728 table = bgp->aggregate[afi][safi];
4729
4730 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004731 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004732 return;
4733
paul718e3742002-12-13 20:15:29 +00004734 if (p->prefixlen == 0)
4735 return;
4736
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004737 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004738
4739 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004740 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004741 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4742 {
4743 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004744 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004745 }
4746 bgp_unlock_node (child);
4747}
4748
paul94f2b392005-06-28 12:44:16 +00004749static void
paul718e3742002-12-13 20:15:29 +00004750bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4751 struct bgp_aggregate *aggregate)
4752{
4753 struct bgp_table *table;
4754 struct bgp_node *top;
4755 struct bgp_node *rn;
4756 struct bgp_info *new;
4757 struct bgp_info *ri;
4758 unsigned long match;
4759 u_char origin = BGP_ORIGIN_IGP;
4760 struct aspath *aspath = NULL;
4761 struct aspath *asmerge = NULL;
4762 struct community *community = NULL;
4763 struct community *commerge = NULL;
4764
4765 table = bgp->rib[afi][safi];
4766
4767 /* Sanity check. */
4768 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4769 return;
4770 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4771 return;
4772
4773 /* If routes exists below this node, generate aggregate routes. */
4774 top = bgp_node_get (table, p);
4775 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4776 if (rn->p.prefixlen > p->prefixlen)
4777 {
4778 match = 0;
4779
4780 for (ri = rn->info; ri; ri = ri->next)
4781 {
4782 if (BGP_INFO_HOLDDOWN (ri))
4783 continue;
4784
4785 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4786 {
4787 /* summary-only aggregate route suppress aggregated
4788 route announcement. */
4789 if (aggregate->summary_only)
4790 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004791 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004792 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004793 match++;
4794 }
4795 /* as-set aggregate route generate origin, as path,
4796 community aggregation. */
4797 if (aggregate->as_set)
4798 {
4799 if (origin < ri->attr->origin)
4800 origin = ri->attr->origin;
4801
4802 if (aspath)
4803 {
4804 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4805 aspath_free (aspath);
4806 aspath = asmerge;
4807 }
4808 else
4809 aspath = aspath_dup (ri->attr->aspath);
4810
4811 if (ri->attr->community)
4812 {
4813 if (community)
4814 {
4815 commerge = community_merge (community,
4816 ri->attr->community);
4817 community = community_uniq_sort (commerge);
4818 community_free (commerge);
4819 }
4820 else
4821 community = community_dup (ri->attr->community);
4822 }
4823 }
4824 aggregate->count++;
4825 }
4826 }
4827
4828 /* If this node is suppressed, process the change. */
4829 if (match)
4830 bgp_process (bgp, rn, afi, safi);
4831 }
4832 bgp_unlock_node (top);
4833
4834 /* Add aggregate route to BGP table. */
4835 if (aggregate->count)
4836 {
4837 rn = bgp_node_get (table, p);
4838
4839 new = bgp_info_new ();
4840 new->type = ZEBRA_ROUTE_BGP;
4841 new->sub_type = BGP_ROUTE_AGGREGATE;
4842 new->peer = bgp->peer_self;
4843 SET_FLAG (new->flags, BGP_INFO_VALID);
4844 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004845 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004846
4847 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004848 bgp_unlock_node (rn);
4849
paul718e3742002-12-13 20:15:29 +00004850 /* Process change. */
4851 bgp_process (bgp, rn, afi, safi);
4852 }
4853}
4854
4855void
4856bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4857 safi_t safi, struct bgp_aggregate *aggregate)
4858{
4859 struct bgp_table *table;
4860 struct bgp_node *top;
4861 struct bgp_node *rn;
4862 struct bgp_info *ri;
4863 unsigned long match;
4864
4865 table = bgp->rib[afi][safi];
4866
4867 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4868 return;
4869 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4870 return;
4871
4872 /* If routes exists below this node, generate aggregate routes. */
4873 top = bgp_node_get (table, p);
4874 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4875 if (rn->p.prefixlen > p->prefixlen)
4876 {
4877 match = 0;
4878
4879 for (ri = rn->info; ri; ri = ri->next)
4880 {
4881 if (BGP_INFO_HOLDDOWN (ri))
4882 continue;
4883
4884 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4885 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004886 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004887 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004888 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004889
Paul Jakmafb982c22007-05-04 20:15:47 +00004890 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004891 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004892 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004893 match++;
4894 }
4895 }
4896 aggregate->count--;
4897 }
4898 }
4899
Paul Jakmafb982c22007-05-04 20:15:47 +00004900 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004901 if (match)
4902 bgp_process (bgp, rn, afi, safi);
4903 }
4904 bgp_unlock_node (top);
4905
4906 /* Delete aggregate route from BGP table. */
4907 rn = bgp_node_get (table, p);
4908
4909 for (ri = rn->info; ri; ri = ri->next)
4910 if (ri->peer == bgp->peer_self
4911 && ri->type == ZEBRA_ROUTE_BGP
4912 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4913 break;
4914
4915 /* Withdraw static BGP route from routing table. */
4916 if (ri)
4917 {
paul718e3742002-12-13 20:15:29 +00004918 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004919 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004920 }
4921
4922 /* Unlock bgp_node_lookup. */
4923 bgp_unlock_node (rn);
4924}
4925
4926/* Aggregate route attribute. */
4927#define AGGREGATE_SUMMARY_ONLY 1
4928#define AGGREGATE_AS_SET 1
4929
paul94f2b392005-06-28 12:44:16 +00004930static int
Robert Baysf6269b42010-08-05 10:26:28 -07004931bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4932 afi_t afi, safi_t safi)
4933{
4934 int ret;
4935 struct prefix p;
4936 struct bgp_node *rn;
4937 struct bgp *bgp;
4938 struct bgp_aggregate *aggregate;
4939
4940 /* Convert string to prefix structure. */
4941 ret = str2prefix (prefix_str, &p);
4942 if (!ret)
4943 {
4944 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4945 return CMD_WARNING;
4946 }
4947 apply_mask (&p);
4948
4949 /* Get BGP structure. */
4950 bgp = vty->index;
4951
4952 /* Old configuration check. */
4953 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4954 if (! rn)
4955 {
4956 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4957 VTY_NEWLINE);
4958 return CMD_WARNING;
4959 }
4960
4961 aggregate = rn->info;
4962 if (aggregate->safi & SAFI_UNICAST)
4963 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4964 if (aggregate->safi & SAFI_MULTICAST)
4965 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4966
4967 /* Unlock aggregate address configuration. */
4968 rn->info = NULL;
4969 bgp_aggregate_free (aggregate);
4970 bgp_unlock_node (rn);
4971 bgp_unlock_node (rn);
4972
4973 return CMD_SUCCESS;
4974}
4975
4976static int
4977bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004978 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004979 u_char summary_only, u_char as_set)
4980{
4981 int ret;
4982 struct prefix p;
4983 struct bgp_node *rn;
4984 struct bgp *bgp;
4985 struct bgp_aggregate *aggregate;
4986
4987 /* Convert string to prefix structure. */
4988 ret = str2prefix (prefix_str, &p);
4989 if (!ret)
4990 {
4991 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4992 return CMD_WARNING;
4993 }
4994 apply_mask (&p);
4995
4996 /* Get BGP structure. */
4997 bgp = vty->index;
4998
4999 /* Old configuration check. */
5000 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5001
5002 if (rn->info)
5003 {
5004 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005005 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005006 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5007 if (ret)
5008 {
Robert Bays368473f2010-08-05 10:26:29 -07005009 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5010 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005011 return CMD_WARNING;
5012 }
paul718e3742002-12-13 20:15:29 +00005013 }
5014
5015 /* Make aggregate address structure. */
5016 aggregate = bgp_aggregate_new ();
5017 aggregate->summary_only = summary_only;
5018 aggregate->as_set = as_set;
5019 aggregate->safi = safi;
5020 rn->info = aggregate;
5021
5022 /* Aggregate address insert into BGP routing table. */
5023 if (safi & SAFI_UNICAST)
5024 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5025 if (safi & SAFI_MULTICAST)
5026 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5027
5028 return CMD_SUCCESS;
5029}
5030
paul718e3742002-12-13 20:15:29 +00005031DEFUN (aggregate_address,
5032 aggregate_address_cmd,
5033 "aggregate-address A.B.C.D/M",
5034 "Configure BGP aggregate entries\n"
5035 "Aggregate prefix\n")
5036{
5037 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5038}
5039
5040DEFUN (aggregate_address_mask,
5041 aggregate_address_mask_cmd,
5042 "aggregate-address A.B.C.D A.B.C.D",
5043 "Configure BGP aggregate entries\n"
5044 "Aggregate address\n"
5045 "Aggregate mask\n")
5046{
5047 int ret;
5048 char prefix_str[BUFSIZ];
5049
5050 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5051
5052 if (! ret)
5053 {
5054 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5055 return CMD_WARNING;
5056 }
5057
5058 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5059 0, 0);
5060}
5061
5062DEFUN (aggregate_address_summary_only,
5063 aggregate_address_summary_only_cmd,
5064 "aggregate-address A.B.C.D/M summary-only",
5065 "Configure BGP aggregate entries\n"
5066 "Aggregate prefix\n"
5067 "Filter more specific routes from updates\n")
5068{
5069 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5070 AGGREGATE_SUMMARY_ONLY, 0);
5071}
5072
5073DEFUN (aggregate_address_mask_summary_only,
5074 aggregate_address_mask_summary_only_cmd,
5075 "aggregate-address A.B.C.D A.B.C.D summary-only",
5076 "Configure BGP aggregate entries\n"
5077 "Aggregate address\n"
5078 "Aggregate mask\n"
5079 "Filter more specific routes from updates\n")
5080{
5081 int ret;
5082 char prefix_str[BUFSIZ];
5083
5084 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5085
5086 if (! ret)
5087 {
5088 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5089 return CMD_WARNING;
5090 }
5091
5092 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5093 AGGREGATE_SUMMARY_ONLY, 0);
5094}
5095
5096DEFUN (aggregate_address_as_set,
5097 aggregate_address_as_set_cmd,
5098 "aggregate-address A.B.C.D/M as-set",
5099 "Configure BGP aggregate entries\n"
5100 "Aggregate prefix\n"
5101 "Generate AS set path information\n")
5102{
5103 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5104 0, AGGREGATE_AS_SET);
5105}
5106
5107DEFUN (aggregate_address_mask_as_set,
5108 aggregate_address_mask_as_set_cmd,
5109 "aggregate-address A.B.C.D A.B.C.D as-set",
5110 "Configure BGP aggregate entries\n"
5111 "Aggregate address\n"
5112 "Aggregate mask\n"
5113 "Generate AS set path information\n")
5114{
5115 int ret;
5116 char prefix_str[BUFSIZ];
5117
5118 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5119
5120 if (! ret)
5121 {
5122 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5123 return CMD_WARNING;
5124 }
5125
5126 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5127 0, AGGREGATE_AS_SET);
5128}
5129
5130
5131DEFUN (aggregate_address_as_set_summary,
5132 aggregate_address_as_set_summary_cmd,
5133 "aggregate-address A.B.C.D/M as-set summary-only",
5134 "Configure BGP aggregate entries\n"
5135 "Aggregate prefix\n"
5136 "Generate AS set path information\n"
5137 "Filter more specific routes from updates\n")
5138{
5139 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5140 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5141}
5142
5143ALIAS (aggregate_address_as_set_summary,
5144 aggregate_address_summary_as_set_cmd,
5145 "aggregate-address A.B.C.D/M summary-only as-set",
5146 "Configure BGP aggregate entries\n"
5147 "Aggregate prefix\n"
5148 "Filter more specific routes from updates\n"
5149 "Generate AS set path information\n")
5150
5151DEFUN (aggregate_address_mask_as_set_summary,
5152 aggregate_address_mask_as_set_summary_cmd,
5153 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5154 "Configure BGP aggregate entries\n"
5155 "Aggregate address\n"
5156 "Aggregate mask\n"
5157 "Generate AS set path information\n"
5158 "Filter more specific routes from updates\n")
5159{
5160 int ret;
5161 char prefix_str[BUFSIZ];
5162
5163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5164
5165 if (! ret)
5166 {
5167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5168 return CMD_WARNING;
5169 }
5170
5171 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5172 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5173}
5174
5175ALIAS (aggregate_address_mask_as_set_summary,
5176 aggregate_address_mask_summary_as_set_cmd,
5177 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate address\n"
5180 "Aggregate mask\n"
5181 "Filter more specific routes from updates\n"
5182 "Generate AS set path information\n")
5183
5184DEFUN (no_aggregate_address,
5185 no_aggregate_address_cmd,
5186 "no aggregate-address A.B.C.D/M",
5187 NO_STR
5188 "Configure BGP aggregate entries\n"
5189 "Aggregate prefix\n")
5190{
5191 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5192}
5193
5194ALIAS (no_aggregate_address,
5195 no_aggregate_address_summary_only_cmd,
5196 "no aggregate-address A.B.C.D/M summary-only",
5197 NO_STR
5198 "Configure BGP aggregate entries\n"
5199 "Aggregate prefix\n"
5200 "Filter more specific routes from updates\n")
5201
5202ALIAS (no_aggregate_address,
5203 no_aggregate_address_as_set_cmd,
5204 "no aggregate-address A.B.C.D/M as-set",
5205 NO_STR
5206 "Configure BGP aggregate entries\n"
5207 "Aggregate prefix\n"
5208 "Generate AS set path information\n")
5209
5210ALIAS (no_aggregate_address,
5211 no_aggregate_address_as_set_summary_cmd,
5212 "no aggregate-address A.B.C.D/M as-set summary-only",
5213 NO_STR
5214 "Configure BGP aggregate entries\n"
5215 "Aggregate prefix\n"
5216 "Generate AS set path information\n"
5217 "Filter more specific routes from updates\n")
5218
5219ALIAS (no_aggregate_address,
5220 no_aggregate_address_summary_as_set_cmd,
5221 "no aggregate-address A.B.C.D/M summary-only as-set",
5222 NO_STR
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate prefix\n"
5225 "Filter more specific routes from updates\n"
5226 "Generate AS set path information\n")
5227
5228DEFUN (no_aggregate_address_mask,
5229 no_aggregate_address_mask_cmd,
5230 "no aggregate-address A.B.C.D A.B.C.D",
5231 NO_STR
5232 "Configure BGP aggregate entries\n"
5233 "Aggregate address\n"
5234 "Aggregate mask\n")
5235{
5236 int ret;
5237 char prefix_str[BUFSIZ];
5238
5239 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5240
5241 if (! ret)
5242 {
5243 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5244 return CMD_WARNING;
5245 }
5246
5247 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5248}
5249
5250ALIAS (no_aggregate_address_mask,
5251 no_aggregate_address_mask_summary_only_cmd,
5252 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5253 NO_STR
5254 "Configure BGP aggregate entries\n"
5255 "Aggregate address\n"
5256 "Aggregate mask\n"
5257 "Filter more specific routes from updates\n")
5258
5259ALIAS (no_aggregate_address_mask,
5260 no_aggregate_address_mask_as_set_cmd,
5261 "no aggregate-address A.B.C.D A.B.C.D as-set",
5262 NO_STR
5263 "Configure BGP aggregate entries\n"
5264 "Aggregate address\n"
5265 "Aggregate mask\n"
5266 "Generate AS set path information\n")
5267
5268ALIAS (no_aggregate_address_mask,
5269 no_aggregate_address_mask_as_set_summary_cmd,
5270 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5271 NO_STR
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate address\n"
5274 "Aggregate mask\n"
5275 "Generate AS set path information\n"
5276 "Filter more specific routes from updates\n")
5277
5278ALIAS (no_aggregate_address_mask,
5279 no_aggregate_address_mask_summary_as_set_cmd,
5280 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5281 NO_STR
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n"
5285 "Filter more specific routes from updates\n"
5286 "Generate AS set path information\n")
5287
5288#ifdef HAVE_IPV6
5289DEFUN (ipv6_aggregate_address,
5290 ipv6_aggregate_address_cmd,
5291 "aggregate-address X:X::X:X/M",
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate prefix\n")
5294{
5295 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5296}
5297
5298DEFUN (ipv6_aggregate_address_summary_only,
5299 ipv6_aggregate_address_summary_only_cmd,
5300 "aggregate-address X:X::X:X/M summary-only",
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate prefix\n"
5303 "Filter more specific routes from updates\n")
5304{
5305 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5306 AGGREGATE_SUMMARY_ONLY, 0);
5307}
5308
5309DEFUN (no_ipv6_aggregate_address,
5310 no_ipv6_aggregate_address_cmd,
5311 "no aggregate-address X:X::X:X/M",
5312 NO_STR
5313 "Configure BGP aggregate entries\n"
5314 "Aggregate prefix\n")
5315{
5316 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5317}
5318
5319DEFUN (no_ipv6_aggregate_address_summary_only,
5320 no_ipv6_aggregate_address_summary_only_cmd,
5321 "no aggregate-address X:X::X:X/M summary-only",
5322 NO_STR
5323 "Configure BGP aggregate entries\n"
5324 "Aggregate prefix\n"
5325 "Filter more specific routes from updates\n")
5326{
5327 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5328}
5329
5330ALIAS (ipv6_aggregate_address,
5331 old_ipv6_aggregate_address_cmd,
5332 "ipv6 bgp aggregate-address X:X::X:X/M",
5333 IPV6_STR
5334 BGP_STR
5335 "Configure BGP aggregate entries\n"
5336 "Aggregate prefix\n")
5337
5338ALIAS (ipv6_aggregate_address_summary_only,
5339 old_ipv6_aggregate_address_summary_only_cmd,
5340 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5341 IPV6_STR
5342 BGP_STR
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate prefix\n"
5345 "Filter more specific routes from updates\n")
5346
5347ALIAS (no_ipv6_aggregate_address,
5348 old_no_ipv6_aggregate_address_cmd,
5349 "no ipv6 bgp aggregate-address X:X::X:X/M",
5350 NO_STR
5351 IPV6_STR
5352 BGP_STR
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n")
5355
5356ALIAS (no_ipv6_aggregate_address_summary_only,
5357 old_no_ipv6_aggregate_address_summary_only_cmd,
5358 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5359 NO_STR
5360 IPV6_STR
5361 BGP_STR
5362 "Configure BGP aggregate entries\n"
5363 "Aggregate prefix\n"
5364 "Filter more specific routes from updates\n")
5365#endif /* HAVE_IPV6 */
5366
5367/* Redistribute route treatment. */
5368void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005369bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5370 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005371 u_int32_t metric, u_char type)
5372{
5373 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005374 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005375 struct bgp_info *new;
5376 struct bgp_info *bi;
5377 struct bgp_info info;
5378 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005379 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005380 struct attr *new_attr;
5381 afi_t afi;
5382 int ret;
5383
5384 /* Make default attribute. */
5385 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5386 if (nexthop)
5387 attr.nexthop = *nexthop;
5388
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005389#ifdef HAVE_IPV6
5390 if (nexthop6)
5391 {
5392 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5393 extra->mp_nexthop_global = *nexthop6;
5394 extra->mp_nexthop_len = 16;
5395 }
5396#endif
5397
paul718e3742002-12-13 20:15:29 +00005398 attr.med = metric;
5399 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5400
paul1eb8ef22005-04-07 07:30:20 +00005401 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005402 {
5403 afi = family2afi (p->family);
5404
5405 if (bgp->redist[afi][type])
5406 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005407 struct attr attr_new;
5408 struct attr_extra extra_new;
5409
paul718e3742002-12-13 20:15:29 +00005410 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005411 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005412 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005413
5414 if (bgp->redist_metric_flag[afi][type])
5415 attr_new.med = bgp->redist_metric[afi][type];
5416
5417 /* Apply route-map. */
5418 if (bgp->rmap[afi][type].map)
5419 {
5420 info.peer = bgp->peer_self;
5421 info.attr = &attr_new;
5422
paulfee0f4c2004-09-13 05:12:46 +00005423 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5424
paul718e3742002-12-13 20:15:29 +00005425 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5426 &info);
paulfee0f4c2004-09-13 05:12:46 +00005427
5428 bgp->peer_self->rmap_type = 0;
5429
paul718e3742002-12-13 20:15:29 +00005430 if (ret == RMAP_DENYMATCH)
5431 {
5432 /* Free uninterned attribute. */
5433 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005434
paul718e3742002-12-13 20:15:29 +00005435 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005436 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005437 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005438 bgp_redistribute_delete (p, type);
5439 return;
5440 }
5441 }
5442
Paul Jakmafb982c22007-05-04 20:15:47 +00005443 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5444 afi, SAFI_UNICAST, p, NULL);
5445
paul718e3742002-12-13 20:15:29 +00005446 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005447
paul718e3742002-12-13 20:15:29 +00005448 for (bi = bn->info; bi; bi = bi->next)
5449 if (bi->peer == bgp->peer_self
5450 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5451 break;
5452
5453 if (bi)
5454 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005455 if (attrhash_cmp (bi->attr, new_attr) &&
5456 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005457 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005458 bgp_attr_unintern (&new_attr);
5459 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005460 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005461 bgp_unlock_node (bn);
5462 return;
5463 }
5464 else
5465 {
5466 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005467 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005468
5469 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005470 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5471 bgp_info_restore(bn, bi);
5472 else
5473 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005474 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005475 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005476 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005477
5478 /* Process change. */
5479 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5480 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5481 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005482 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005483 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005484 return;
5485 }
5486 }
5487
5488 new = bgp_info_new ();
5489 new->type = type;
5490 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5491 new->peer = bgp->peer_self;
5492 SET_FLAG (new->flags, BGP_INFO_VALID);
5493 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005494 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005495
5496 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5497 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005498 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005499 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5500 }
5501 }
5502
5503 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005504 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005505 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005506}
5507
5508void
5509bgp_redistribute_delete (struct prefix *p, u_char type)
5510{
5511 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005512 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005513 afi_t afi;
5514 struct bgp_node *rn;
5515 struct bgp_info *ri;
5516
paul1eb8ef22005-04-07 07:30:20 +00005517 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005518 {
5519 afi = family2afi (p->family);
5520
5521 if (bgp->redist[afi][type])
5522 {
paulfee0f4c2004-09-13 05:12:46 +00005523 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005524
5525 for (ri = rn->info; ri; ri = ri->next)
5526 if (ri->peer == bgp->peer_self
5527 && ri->type == type)
5528 break;
5529
5530 if (ri)
5531 {
5532 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005533 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005534 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005535 }
5536 bgp_unlock_node (rn);
5537 }
5538 }
5539}
5540
5541/* Withdraw specified route type's route. */
5542void
5543bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5544{
5545 struct bgp_node *rn;
5546 struct bgp_info *ri;
5547 struct bgp_table *table;
5548
5549 table = bgp->rib[afi][SAFI_UNICAST];
5550
5551 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5552 {
5553 for (ri = rn->info; ri; ri = ri->next)
5554 if (ri->peer == bgp->peer_self
5555 && ri->type == type)
5556 break;
5557
5558 if (ri)
5559 {
5560 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005561 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005562 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005563 }
5564 }
5565}
5566
5567/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005568static void
paul718e3742002-12-13 20:15:29 +00005569route_vty_out_route (struct prefix *p, struct vty *vty)
5570{
5571 int len;
5572 u_int32_t destination;
5573 char buf[BUFSIZ];
5574
5575 if (p->family == AF_INET)
5576 {
5577 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5578 destination = ntohl (p->u.prefix4.s_addr);
5579
5580 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5581 || (IN_CLASSB (destination) && p->prefixlen == 16)
5582 || (IN_CLASSA (destination) && p->prefixlen == 8)
5583 || p->u.prefix4.s_addr == 0)
5584 {
5585 /* When mask is natural, mask is not displayed. */
5586 }
5587 else
5588 len += vty_out (vty, "/%d", p->prefixlen);
5589 }
5590 else
5591 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5592 p->prefixlen);
5593
5594 len = 17 - len;
5595 if (len < 1)
5596 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5597 else
5598 vty_out (vty, "%*s", len, " ");
5599}
5600
paul718e3742002-12-13 20:15:29 +00005601enum bgp_display_type
5602{
5603 normal_list,
5604};
5605
paulb40d9392005-08-22 22:34:41 +00005606/* Print the short form route status for a bgp_info */
5607static void
5608route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005609{
paulb40d9392005-08-22 22:34:41 +00005610 /* Route status display. */
5611 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5612 vty_out (vty, "R");
5613 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005614 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005615 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005616 vty_out (vty, "s");
5617 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5618 vty_out (vty, "*");
5619 else
5620 vty_out (vty, " ");
5621
5622 /* Selected */
5623 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5624 vty_out (vty, "h");
5625 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5626 vty_out (vty, "d");
5627 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5628 vty_out (vty, ">");
5629 else
5630 vty_out (vty, " ");
5631
5632 /* Internal route. */
5633 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5634 vty_out (vty, "i");
5635 else
paulb40d9392005-08-22 22:34:41 +00005636 vty_out (vty, " ");
5637}
5638
5639/* called from terminal list command */
5640void
5641route_vty_out (struct vty *vty, struct prefix *p,
5642 struct bgp_info *binfo, int display, safi_t safi)
5643{
5644 struct attr *attr;
5645
5646 /* short status lead text */
5647 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005648
5649 /* print prefix and mask */
5650 if (! display)
5651 route_vty_out_route (p, vty);
5652 else
5653 vty_out (vty, "%*s", 17, " ");
5654
5655 /* Print attribute */
5656 attr = binfo->attr;
5657 if (attr)
5658 {
5659 if (p->family == AF_INET)
5660 {
5661 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005662 vty_out (vty, "%-16s",
5663 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005664 else
5665 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5666 }
5667#ifdef HAVE_IPV6
5668 else if (p->family == AF_INET6)
5669 {
5670 int len;
5671 char buf[BUFSIZ];
5672
5673 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005674 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5675 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005676 len = 16 - len;
5677 if (len < 1)
5678 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5679 else
5680 vty_out (vty, "%*s", len, " ");
5681 }
5682#endif /* HAVE_IPV6 */
5683
5684 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005685 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005686 else
5687 vty_out (vty, " ");
5688
5689 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005690 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005691 else
5692 vty_out (vty, " ");
5693
Paul Jakmafb982c22007-05-04 20:15:47 +00005694 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005695
Paul Jakmab2518c12006-05-12 23:48:40 +00005696 /* Print aspath */
5697 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005698 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005699
Paul Jakmab2518c12006-05-12 23:48:40 +00005700 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005701 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005702 }
paul718e3742002-12-13 20:15:29 +00005703 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005704}
5705
5706/* called from terminal list command */
5707void
5708route_vty_out_tmp (struct vty *vty, struct prefix *p,
5709 struct attr *attr, safi_t safi)
5710{
5711 /* Route status display. */
5712 vty_out (vty, "*");
5713 vty_out (vty, ">");
5714 vty_out (vty, " ");
5715
5716 /* print prefix and mask */
5717 route_vty_out_route (p, vty);
5718
5719 /* Print attribute */
5720 if (attr)
5721 {
5722 if (p->family == AF_INET)
5723 {
5724 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005725 vty_out (vty, "%-16s",
5726 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005727 else
5728 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5729 }
5730#ifdef HAVE_IPV6
5731 else if (p->family == AF_INET6)
5732 {
5733 int len;
5734 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005735
5736 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005737
5738 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005739 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5740 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005741 len = 16 - len;
5742 if (len < 1)
5743 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5744 else
5745 vty_out (vty, "%*s", len, " ");
5746 }
5747#endif /* HAVE_IPV6 */
5748
5749 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005750 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005751 else
5752 vty_out (vty, " ");
5753
5754 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005755 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005756 else
5757 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005758
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005759 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005760
Paul Jakmab2518c12006-05-12 23:48:40 +00005761 /* Print aspath */
5762 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005763 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005764
Paul Jakmab2518c12006-05-12 23:48:40 +00005765 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005766 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005767 }
paul718e3742002-12-13 20:15:29 +00005768
5769 vty_out (vty, "%s", VTY_NEWLINE);
5770}
5771
ajs5a646652004-11-05 01:25:55 +00005772void
paul718e3742002-12-13 20:15:29 +00005773route_vty_out_tag (struct vty *vty, struct prefix *p,
5774 struct bgp_info *binfo, int display, safi_t safi)
5775{
5776 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005777 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005778
5779 if (!binfo->extra)
5780 return;
5781
paulb40d9392005-08-22 22:34:41 +00005782 /* short status lead text */
5783 route_vty_short_status_out (vty, binfo);
5784
paul718e3742002-12-13 20:15:29 +00005785 /* print prefix and mask */
5786 if (! display)
5787 route_vty_out_route (p, vty);
5788 else
5789 vty_out (vty, "%*s", 17, " ");
5790
5791 /* Print attribute */
5792 attr = binfo->attr;
5793 if (attr)
5794 {
5795 if (p->family == AF_INET)
5796 {
5797 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005798 vty_out (vty, "%-16s",
5799 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005800 else
5801 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5802 }
5803#ifdef HAVE_IPV6
5804 else if (p->family == AF_INET6)
5805 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005806 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005807 char buf[BUFSIZ];
5808 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005809 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005810 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005811 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5812 buf, BUFSIZ));
5813 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005814 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005815 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5816 buf, BUFSIZ),
5817 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5818 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005819
5820 }
5821#endif /* HAVE_IPV6 */
5822 }
5823
Paul Jakmafb982c22007-05-04 20:15:47 +00005824 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005825
5826 vty_out (vty, "notag/%d", label);
5827
5828 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005829}
5830
5831/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005832static void
paul718e3742002-12-13 20:15:29 +00005833damp_route_vty_out (struct vty *vty, struct prefix *p,
5834 struct bgp_info *binfo, int display, safi_t safi)
5835{
5836 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005837 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005838 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005839
paulb40d9392005-08-22 22:34:41 +00005840 /* short status lead text */
5841 route_vty_short_status_out (vty, binfo);
5842
paul718e3742002-12-13 20:15:29 +00005843 /* print prefix and mask */
5844 if (! display)
5845 route_vty_out_route (p, vty);
5846 else
5847 vty_out (vty, "%*s", 17, " ");
5848
5849 len = vty_out (vty, "%s", binfo->peer->host);
5850 len = 17 - len;
5851 if (len < 1)
5852 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5853 else
5854 vty_out (vty, "%*s", len, " ");
5855
Chris Caputo50aef6f2009-06-23 06:06:49 +00005856 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005857
5858 /* Print attribute */
5859 attr = binfo->attr;
5860 if (attr)
5861 {
5862 /* Print aspath */
5863 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005864 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005865
5866 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005867 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005868 }
5869 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005870}
5871
paul718e3742002-12-13 20:15:29 +00005872/* flap route */
ajs5a646652004-11-05 01:25:55 +00005873static void
paul718e3742002-12-13 20:15:29 +00005874flap_route_vty_out (struct vty *vty, struct prefix *p,
5875 struct bgp_info *binfo, int display, safi_t safi)
5876{
5877 struct attr *attr;
5878 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005879 char timebuf[BGP_UPTIME_LEN];
5880 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005881
5882 if (!binfo->extra)
5883 return;
5884
5885 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005886
paulb40d9392005-08-22 22:34:41 +00005887 /* short status lead text */
5888 route_vty_short_status_out (vty, binfo);
5889
paul718e3742002-12-13 20:15:29 +00005890 /* print prefix and mask */
5891 if (! display)
5892 route_vty_out_route (p, vty);
5893 else
5894 vty_out (vty, "%*s", 17, " ");
5895
5896 len = vty_out (vty, "%s", binfo->peer->host);
5897 len = 16 - len;
5898 if (len < 1)
5899 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5900 else
5901 vty_out (vty, "%*s", len, " ");
5902
5903 len = vty_out (vty, "%d", bdi->flap);
5904 len = 5 - len;
5905 if (len < 1)
5906 vty_out (vty, " ");
5907 else
5908 vty_out (vty, "%*s ", len, " ");
5909
5910 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5911 timebuf, BGP_UPTIME_LEN));
5912
5913 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5914 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005915 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005916 else
5917 vty_out (vty, "%*s ", 8, " ");
5918
5919 /* Print attribute */
5920 attr = binfo->attr;
5921 if (attr)
5922 {
5923 /* Print aspath */
5924 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005925 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005926
5927 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005928 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005929 }
5930 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005931}
5932
paul94f2b392005-06-28 12:44:16 +00005933static void
paul718e3742002-12-13 20:15:29 +00005934route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5935 struct bgp_info *binfo, afi_t afi, safi_t safi)
5936{
5937 char buf[INET6_ADDRSTRLEN];
5938 char buf1[BUFSIZ];
5939 struct attr *attr;
5940 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005941#ifdef HAVE_CLOCK_MONOTONIC
5942 time_t tbuf;
5943#endif
paul718e3742002-12-13 20:15:29 +00005944
5945 attr = binfo->attr;
5946
5947 if (attr)
5948 {
5949 /* Line1 display AS-path, Aggregator */
5950 if (attr->aspath)
5951 {
5952 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005953 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005954 vty_out (vty, "Local");
5955 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005956 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005957 }
5958
paulb40d9392005-08-22 22:34:41 +00005959 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5960 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005961 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5962 vty_out (vty, ", (stale)");
5963 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005964 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005965 attr->extra->aggregator_as,
5966 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005967 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5968 vty_out (vty, ", (Received from a RR-client)");
5969 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5970 vty_out (vty, ", (Received from a RS-client)");
5971 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5972 vty_out (vty, ", (history entry)");
5973 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5974 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005975 vty_out (vty, "%s", VTY_NEWLINE);
5976
5977 /* Line2 display Next-hop, Neighbor, Router-id */
5978 if (p->family == AF_INET)
5979 {
5980 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005981 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005982 inet_ntoa (attr->nexthop));
5983 }
5984#ifdef HAVE_IPV6
5985 else
5986 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005987 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005988 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005989 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005990 buf, INET6_ADDRSTRLEN));
5991 }
5992#endif /* HAVE_IPV6 */
5993
5994 if (binfo->peer == bgp->peer_self)
5995 {
5996 vty_out (vty, " from %s ",
5997 p->family == AF_INET ? "0.0.0.0" : "::");
5998 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5999 }
6000 else
6001 {
6002 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6003 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006004 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006005 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006006 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006007 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006009 else
6010 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6011 }
6012 vty_out (vty, "%s", VTY_NEWLINE);
6013
6014#ifdef HAVE_IPV6
6015 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006017 {
6018 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006019 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006020 buf, INET6_ADDRSTRLEN),
6021 VTY_NEWLINE);
6022 }
6023#endif /* HAVE_IPV6 */
6024
6025 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6026 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6027
6028 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006029 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006030
6031 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006032 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006033 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006034 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006035
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006037 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006038
6039 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6040 vty_out (vty, ", valid");
6041
6042 if (binfo->peer != bgp->peer_self)
6043 {
6044 if (binfo->peer->as == binfo->peer->local_as)
6045 vty_out (vty, ", internal");
6046 else
6047 vty_out (vty, ", %s",
6048 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6049 }
6050 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6051 vty_out (vty, ", aggregated, local");
6052 else if (binfo->type != ZEBRA_ROUTE_BGP)
6053 vty_out (vty, ", sourced");
6054 else
6055 vty_out (vty, ", sourced, local");
6056
6057 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6058 vty_out (vty, ", atomic-aggregate");
6059
Josh Baileyde8d5df2011-07-20 20:46:01 -07006060 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6061 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6062 bgp_info_mpath_count (binfo)))
6063 vty_out (vty, ", multipath");
6064
paul718e3742002-12-13 20:15:29 +00006065 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6066 vty_out (vty, ", best");
6067
6068 vty_out (vty, "%s", VTY_NEWLINE);
6069
6070 /* Line 4 display Community */
6071 if (attr->community)
6072 vty_out (vty, " Community: %s%s", attr->community->str,
6073 VTY_NEWLINE);
6074
6075 /* Line 5 display Extended-community */
6076 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006077 vty_out (vty, " Extended Community: %s%s",
6078 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006079
6080 /* Line 6 display Originator, Cluster-id */
6081 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6082 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006084 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006085 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 vty_out (vty, " Originator: %s",
6087 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006088
6089 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6090 {
6091 int i;
6092 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006093 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6094 vty_out (vty, "%s ",
6095 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006096 }
6097 vty_out (vty, "%s", VTY_NEWLINE);
6098 }
Paul Jakma41367172007-08-06 15:24:51 +00006099
Paul Jakmafb982c22007-05-04 20:15:47 +00006100 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006101 bgp_damp_info_vty (vty, binfo);
6102
6103 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006104#ifdef HAVE_CLOCK_MONOTONIC
6105 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006106 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006107#else
6108 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6109#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006110 }
6111 vty_out (vty, "%s", VTY_NEWLINE);
6112}
6113
paulb40d9392005-08-22 22:34:41 +00006114#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 +00006115#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006116#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6117#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6118#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6119
6120enum bgp_show_type
6121{
6122 bgp_show_type_normal,
6123 bgp_show_type_regexp,
6124 bgp_show_type_prefix_list,
6125 bgp_show_type_filter_list,
6126 bgp_show_type_route_map,
6127 bgp_show_type_neighbor,
6128 bgp_show_type_cidr_only,
6129 bgp_show_type_prefix_longer,
6130 bgp_show_type_community_all,
6131 bgp_show_type_community,
6132 bgp_show_type_community_exact,
6133 bgp_show_type_community_list,
6134 bgp_show_type_community_list_exact,
6135 bgp_show_type_flap_statistics,
6136 bgp_show_type_flap_address,
6137 bgp_show_type_flap_prefix,
6138 bgp_show_type_flap_cidr_only,
6139 bgp_show_type_flap_regexp,
6140 bgp_show_type_flap_filter_list,
6141 bgp_show_type_flap_prefix_list,
6142 bgp_show_type_flap_prefix_longer,
6143 bgp_show_type_flap_route_map,
6144 bgp_show_type_flap_neighbor,
6145 bgp_show_type_dampend_paths,
6146 bgp_show_type_damp_neighbor
6147};
6148
ajs5a646652004-11-05 01:25:55 +00006149static int
paulfee0f4c2004-09-13 05:12:46 +00006150bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006151 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006152{
paul718e3742002-12-13 20:15:29 +00006153 struct bgp_info *ri;
6154 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006155 int header = 1;
paul718e3742002-12-13 20:15:29 +00006156 int display;
ajs5a646652004-11-05 01:25:55 +00006157 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006158
6159 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006160 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006161
paul718e3742002-12-13 20:15:29 +00006162 /* Start processing of routes. */
6163 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6164 if (rn->info != NULL)
6165 {
6166 display = 0;
6167
6168 for (ri = rn->info; ri; ri = ri->next)
6169 {
ajs5a646652004-11-05 01:25:55 +00006170 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006171 || type == bgp_show_type_flap_address
6172 || type == bgp_show_type_flap_prefix
6173 || type == bgp_show_type_flap_cidr_only
6174 || type == bgp_show_type_flap_regexp
6175 || type == bgp_show_type_flap_filter_list
6176 || type == bgp_show_type_flap_prefix_list
6177 || type == bgp_show_type_flap_prefix_longer
6178 || type == bgp_show_type_flap_route_map
6179 || type == bgp_show_type_flap_neighbor
6180 || type == bgp_show_type_dampend_paths
6181 || type == bgp_show_type_damp_neighbor)
6182 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006183 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006184 continue;
6185 }
6186 if (type == bgp_show_type_regexp
6187 || type == bgp_show_type_flap_regexp)
6188 {
ajs5a646652004-11-05 01:25:55 +00006189 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006190
6191 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6192 continue;
6193 }
6194 if (type == bgp_show_type_prefix_list
6195 || type == bgp_show_type_flap_prefix_list)
6196 {
ajs5a646652004-11-05 01:25:55 +00006197 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006198
6199 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6200 continue;
6201 }
6202 if (type == bgp_show_type_filter_list
6203 || type == bgp_show_type_flap_filter_list)
6204 {
ajs5a646652004-11-05 01:25:55 +00006205 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006206
6207 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6208 continue;
6209 }
6210 if (type == bgp_show_type_route_map
6211 || type == bgp_show_type_flap_route_map)
6212 {
ajs5a646652004-11-05 01:25:55 +00006213 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006214 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006215 struct attr dummy_attr;
6216 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006217 int ret;
6218
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006219 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006220 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006221
paul718e3742002-12-13 20:15:29 +00006222 binfo.peer = ri->peer;
6223 binfo.attr = &dummy_attr;
6224
6225 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006226 if (ret == RMAP_DENYMATCH)
6227 continue;
6228 }
6229 if (type == bgp_show_type_neighbor
6230 || type == bgp_show_type_flap_neighbor
6231 || type == bgp_show_type_damp_neighbor)
6232 {
ajs5a646652004-11-05 01:25:55 +00006233 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006234
6235 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6236 continue;
6237 }
6238 if (type == bgp_show_type_cidr_only
6239 || type == bgp_show_type_flap_cidr_only)
6240 {
6241 u_int32_t destination;
6242
6243 destination = ntohl (rn->p.u.prefix4.s_addr);
6244 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6245 continue;
6246 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6247 continue;
6248 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6249 continue;
6250 }
6251 if (type == bgp_show_type_prefix_longer
6252 || type == bgp_show_type_flap_prefix_longer)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (! prefix_match (p, &rn->p))
6257 continue;
6258 }
6259 if (type == bgp_show_type_community_all)
6260 {
6261 if (! ri->attr->community)
6262 continue;
6263 }
6264 if (type == bgp_show_type_community)
6265 {
ajs5a646652004-11-05 01:25:55 +00006266 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006267
6268 if (! ri->attr->community ||
6269 ! community_match (ri->attr->community, com))
6270 continue;
6271 }
6272 if (type == bgp_show_type_community_exact)
6273 {
ajs5a646652004-11-05 01:25:55 +00006274 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006275
6276 if (! ri->attr->community ||
6277 ! community_cmp (ri->attr->community, com))
6278 continue;
6279 }
6280 if (type == bgp_show_type_community_list)
6281 {
ajs5a646652004-11-05 01:25:55 +00006282 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006283
6284 if (! community_list_match (ri->attr->community, list))
6285 continue;
6286 }
6287 if (type == bgp_show_type_community_list_exact)
6288 {
ajs5a646652004-11-05 01:25:55 +00006289 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006290
6291 if (! community_list_exact_match (ri->attr->community, list))
6292 continue;
6293 }
6294 if (type == bgp_show_type_flap_address
6295 || type == bgp_show_type_flap_prefix)
6296 {
ajs5a646652004-11-05 01:25:55 +00006297 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006298
6299 if (! prefix_match (&rn->p, p))
6300 continue;
6301
6302 if (type == bgp_show_type_flap_prefix)
6303 if (p->prefixlen != rn->p.prefixlen)
6304 continue;
6305 }
6306 if (type == bgp_show_type_dampend_paths
6307 || type == bgp_show_type_damp_neighbor)
6308 {
6309 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6310 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6311 continue;
6312 }
6313
6314 if (header)
6315 {
hasso93406d82005-02-02 14:40:33 +00006316 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6317 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6318 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006319 if (type == bgp_show_type_dampend_paths
6320 || type == bgp_show_type_damp_neighbor)
6321 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6322 else if (type == bgp_show_type_flap_statistics
6323 || type == bgp_show_type_flap_address
6324 || type == bgp_show_type_flap_prefix
6325 || type == bgp_show_type_flap_cidr_only
6326 || type == bgp_show_type_flap_regexp
6327 || type == bgp_show_type_flap_filter_list
6328 || type == bgp_show_type_flap_prefix_list
6329 || type == bgp_show_type_flap_prefix_longer
6330 || type == bgp_show_type_flap_route_map
6331 || type == bgp_show_type_flap_neighbor)
6332 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6333 else
6334 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006335 header = 0;
6336 }
6337
6338 if (type == bgp_show_type_dampend_paths
6339 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006340 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006341 else if (type == bgp_show_type_flap_statistics
6342 || type == bgp_show_type_flap_address
6343 || type == bgp_show_type_flap_prefix
6344 || type == bgp_show_type_flap_cidr_only
6345 || type == bgp_show_type_flap_regexp
6346 || type == bgp_show_type_flap_filter_list
6347 || type == bgp_show_type_flap_prefix_list
6348 || type == bgp_show_type_flap_prefix_longer
6349 || type == bgp_show_type_flap_route_map
6350 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006351 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006352 else
ajs5a646652004-11-05 01:25:55 +00006353 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006354 display++;
6355 }
6356 if (display)
ajs5a646652004-11-05 01:25:55 +00006357 output_count++;
paul718e3742002-12-13 20:15:29 +00006358 }
6359
6360 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006361 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006362 {
6363 if (type == bgp_show_type_normal)
6364 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6365 }
6366 else
6367 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006368 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006369
6370 return CMD_SUCCESS;
6371}
6372
ajs5a646652004-11-05 01:25:55 +00006373static int
paulfee0f4c2004-09-13 05:12:46 +00006374bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006375 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006376{
6377 struct bgp_table *table;
6378
6379 if (bgp == NULL) {
6380 bgp = bgp_get_default ();
6381 }
6382
6383 if (bgp == NULL)
6384 {
6385 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6386 return CMD_WARNING;
6387 }
6388
6389
6390 table = bgp->rib[afi][safi];
6391
ajs5a646652004-11-05 01:25:55 +00006392 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006393}
6394
paul718e3742002-12-13 20:15:29 +00006395/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006396static void
paul718e3742002-12-13 20:15:29 +00006397route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6398 struct bgp_node *rn,
6399 struct prefix_rd *prd, afi_t afi, safi_t safi)
6400{
6401 struct bgp_info *ri;
6402 struct prefix *p;
6403 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006404 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006405 char buf1[INET6_ADDRSTRLEN];
6406 char buf2[INET6_ADDRSTRLEN];
6407 int count = 0;
6408 int best = 0;
6409 int suppress = 0;
6410 int no_export = 0;
6411 int no_advertise = 0;
6412 int local_as = 0;
6413 int first = 0;
6414
6415 p = &rn->p;
6416 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6417 (safi == SAFI_MPLS_VPN ?
6418 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6419 safi == SAFI_MPLS_VPN ? ":" : "",
6420 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6421 p->prefixlen, VTY_NEWLINE);
6422
6423 for (ri = rn->info; ri; ri = ri->next)
6424 {
6425 count++;
6426 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6427 {
6428 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006429 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006430 suppress = 1;
6431 if (ri->attr->community != NULL)
6432 {
6433 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6434 no_advertise = 1;
6435 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6436 no_export = 1;
6437 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6438 local_as = 1;
6439 }
6440 }
6441 }
6442
6443 vty_out (vty, "Paths: (%d available", count);
6444 if (best)
6445 {
6446 vty_out (vty, ", best #%d", best);
6447 if (safi == SAFI_UNICAST)
6448 vty_out (vty, ", table Default-IP-Routing-Table");
6449 }
6450 else
6451 vty_out (vty, ", no best path");
6452 if (no_advertise)
6453 vty_out (vty, ", not advertised to any peer");
6454 else if (no_export)
6455 vty_out (vty, ", not advertised to EBGP peer");
6456 else if (local_as)
6457 vty_out (vty, ", not advertised outside local AS");
6458 if (suppress)
6459 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6460 vty_out (vty, ")%s", VTY_NEWLINE);
6461
6462 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006463 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006464 {
6465 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6466 {
6467 if (! first)
6468 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6469 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6470 first = 1;
6471 }
6472 }
6473 if (! first)
6474 vty_out (vty, " Not advertised to any peer");
6475 vty_out (vty, "%s", VTY_NEWLINE);
6476}
6477
6478/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006479static int
paulfee0f4c2004-09-13 05:12:46 +00006480bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006481 struct bgp_table *rib, const char *ip_str,
6482 afi_t afi, safi_t safi, struct prefix_rd *prd,
6483 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006484{
6485 int ret;
6486 int header;
6487 int display = 0;
6488 struct prefix match;
6489 struct bgp_node *rn;
6490 struct bgp_node *rm;
6491 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006492 struct bgp_table *table;
6493
paul718e3742002-12-13 20:15:29 +00006494 /* Check IP address argument. */
6495 ret = str2prefix (ip_str, &match);
6496 if (! ret)
6497 {
6498 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6499 return CMD_WARNING;
6500 }
6501
6502 match.family = afi2family (afi);
6503
6504 if (safi == SAFI_MPLS_VPN)
6505 {
paulfee0f4c2004-09-13 05:12:46 +00006506 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006507 {
6508 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6509 continue;
6510
6511 if ((table = rn->info) != NULL)
6512 {
6513 header = 1;
6514
6515 if ((rm = bgp_node_match (table, &match)) != NULL)
6516 {
6517 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006518 {
6519 bgp_unlock_node (rm);
6520 continue;
6521 }
paul718e3742002-12-13 20:15:29 +00006522
6523 for (ri = rm->info; ri; ri = ri->next)
6524 {
6525 if (header)
6526 {
6527 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6528 AFI_IP, SAFI_MPLS_VPN);
6529
6530 header = 0;
6531 }
6532 display++;
6533 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6534 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006535
6536 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006537 }
6538 }
6539 }
6540 }
6541 else
6542 {
6543 header = 1;
6544
paulfee0f4c2004-09-13 05:12:46 +00006545 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006546 {
6547 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6548 {
6549 for (ri = rn->info; ri; ri = ri->next)
6550 {
6551 if (header)
6552 {
6553 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6554 header = 0;
6555 }
6556 display++;
6557 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6558 }
6559 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006560
6561 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006562 }
6563 }
6564
6565 if (! display)
6566 {
6567 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6568 return CMD_WARNING;
6569 }
6570
6571 return CMD_SUCCESS;
6572}
6573
paulfee0f4c2004-09-13 05:12:46 +00006574/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006575static int
paulfd79ac92004-10-13 05:06:08 +00006576bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006577 afi_t afi, safi_t safi, struct prefix_rd *prd,
6578 int prefix_check)
6579{
6580 struct bgp *bgp;
6581
6582 /* BGP structure lookup. */
6583 if (view_name)
6584 {
6585 bgp = bgp_lookup_by_name (view_name);
6586 if (bgp == NULL)
6587 {
6588 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6589 return CMD_WARNING;
6590 }
6591 }
6592 else
6593 {
6594 bgp = bgp_get_default ();
6595 if (bgp == NULL)
6596 {
6597 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6598 return CMD_WARNING;
6599 }
6600 }
6601
6602 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6603 afi, safi, prd, prefix_check);
6604}
6605
paul718e3742002-12-13 20:15:29 +00006606/* BGP route print out function. */
6607DEFUN (show_ip_bgp,
6608 show_ip_bgp_cmd,
6609 "show ip bgp",
6610 SHOW_STR
6611 IP_STR
6612 BGP_STR)
6613{
ajs5a646652004-11-05 01:25:55 +00006614 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006615}
6616
6617DEFUN (show_ip_bgp_ipv4,
6618 show_ip_bgp_ipv4_cmd,
6619 "show ip bgp ipv4 (unicast|multicast)",
6620 SHOW_STR
6621 IP_STR
6622 BGP_STR
6623 "Address family\n"
6624 "Address Family modifier\n"
6625 "Address Family modifier\n")
6626{
6627 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006628 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6629 NULL);
paul718e3742002-12-13 20:15:29 +00006630
ajs5a646652004-11-05 01:25:55 +00006631 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006632}
6633
Michael Lambert95cbbd22010-07-23 14:43:04 -04006634ALIAS (show_ip_bgp_ipv4,
6635 show_bgp_ipv4_safi_cmd,
6636 "show bgp ipv4 (unicast|multicast)",
6637 SHOW_STR
6638 BGP_STR
6639 "Address family\n"
6640 "Address Family modifier\n"
6641 "Address Family modifier\n")
6642
paul718e3742002-12-13 20:15:29 +00006643DEFUN (show_ip_bgp_route,
6644 show_ip_bgp_route_cmd,
6645 "show ip bgp A.B.C.D",
6646 SHOW_STR
6647 IP_STR
6648 BGP_STR
6649 "Network in the BGP routing table to display\n")
6650{
6651 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6652}
6653
6654DEFUN (show_ip_bgp_ipv4_route,
6655 show_ip_bgp_ipv4_route_cmd,
6656 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6657 SHOW_STR
6658 IP_STR
6659 BGP_STR
6660 "Address family\n"
6661 "Address Family modifier\n"
6662 "Address Family modifier\n"
6663 "Network in the BGP routing table to display\n")
6664{
6665 if (strncmp (argv[0], "m", 1) == 0)
6666 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6667
6668 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6669}
6670
Michael Lambert95cbbd22010-07-23 14:43:04 -04006671ALIAS (show_ip_bgp_ipv4_route,
6672 show_bgp_ipv4_safi_route_cmd,
6673 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6674 SHOW_STR
6675 BGP_STR
6676 "Address family\n"
6677 "Address Family modifier\n"
6678 "Address Family modifier\n"
6679 "Network in the BGP routing table to display\n")
6680
paul718e3742002-12-13 20:15:29 +00006681DEFUN (show_ip_bgp_vpnv4_all_route,
6682 show_ip_bgp_vpnv4_all_route_cmd,
6683 "show ip bgp vpnv4 all A.B.C.D",
6684 SHOW_STR
6685 IP_STR
6686 BGP_STR
6687 "Display VPNv4 NLRI specific information\n"
6688 "Display information about all VPNv4 NLRIs\n"
6689 "Network in the BGP routing table to display\n")
6690{
6691 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6692}
6693
6694DEFUN (show_ip_bgp_vpnv4_rd_route,
6695 show_ip_bgp_vpnv4_rd_route_cmd,
6696 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6697 SHOW_STR
6698 IP_STR
6699 BGP_STR
6700 "Display VPNv4 NLRI specific information\n"
6701 "Display information for a route distinguisher\n"
6702 "VPN Route Distinguisher\n"
6703 "Network in the BGP routing table to display\n")
6704{
6705 int ret;
6706 struct prefix_rd prd;
6707
6708 ret = str2prefix_rd (argv[0], &prd);
6709 if (! ret)
6710 {
6711 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6712 return CMD_WARNING;
6713 }
6714 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6715}
6716
6717DEFUN (show_ip_bgp_prefix,
6718 show_ip_bgp_prefix_cmd,
6719 "show ip bgp A.B.C.D/M",
6720 SHOW_STR
6721 IP_STR
6722 BGP_STR
6723 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6724{
6725 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6726}
6727
6728DEFUN (show_ip_bgp_ipv4_prefix,
6729 show_ip_bgp_ipv4_prefix_cmd,
6730 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6731 SHOW_STR
6732 IP_STR
6733 BGP_STR
6734 "Address family\n"
6735 "Address Family modifier\n"
6736 "Address Family modifier\n"
6737 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6738{
6739 if (strncmp (argv[0], "m", 1) == 0)
6740 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6741
6742 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6743}
6744
Michael Lambert95cbbd22010-07-23 14:43:04 -04006745ALIAS (show_ip_bgp_ipv4_prefix,
6746 show_bgp_ipv4_safi_prefix_cmd,
6747 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6748 SHOW_STR
6749 BGP_STR
6750 "Address family\n"
6751 "Address Family modifier\n"
6752 "Address Family modifier\n"
6753 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6754
paul718e3742002-12-13 20:15:29 +00006755DEFUN (show_ip_bgp_vpnv4_all_prefix,
6756 show_ip_bgp_vpnv4_all_prefix_cmd,
6757 "show ip bgp vpnv4 all A.B.C.D/M",
6758 SHOW_STR
6759 IP_STR
6760 BGP_STR
6761 "Display VPNv4 NLRI specific information\n"
6762 "Display information about all VPNv4 NLRIs\n"
6763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6764{
6765 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6766}
6767
6768DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6769 show_ip_bgp_vpnv4_rd_prefix_cmd,
6770 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6771 SHOW_STR
6772 IP_STR
6773 BGP_STR
6774 "Display VPNv4 NLRI specific information\n"
6775 "Display information for a route distinguisher\n"
6776 "VPN Route Distinguisher\n"
6777 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6778{
6779 int ret;
6780 struct prefix_rd prd;
6781
6782 ret = str2prefix_rd (argv[0], &prd);
6783 if (! ret)
6784 {
6785 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6786 return CMD_WARNING;
6787 }
6788 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6789}
6790
6791DEFUN (show_ip_bgp_view,
6792 show_ip_bgp_view_cmd,
6793 "show ip bgp view WORD",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "BGP view\n"
6798 "BGP view name\n")
6799{
paulbb46e942003-10-24 19:02:03 +00006800 struct bgp *bgp;
6801
6802 /* BGP structure lookup. */
6803 bgp = bgp_lookup_by_name (argv[0]);
6804 if (bgp == NULL)
6805 {
6806 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6807 return CMD_WARNING;
6808 }
6809
ajs5a646652004-11-05 01:25:55 +00006810 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006811}
6812
6813DEFUN (show_ip_bgp_view_route,
6814 show_ip_bgp_view_route_cmd,
6815 "show ip bgp view WORD A.B.C.D",
6816 SHOW_STR
6817 IP_STR
6818 BGP_STR
6819 "BGP view\n"
6820 "BGP view name\n"
6821 "Network in the BGP routing table to display\n")
6822{
6823 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6824}
6825
6826DEFUN (show_ip_bgp_view_prefix,
6827 show_ip_bgp_view_prefix_cmd,
6828 "show ip bgp view WORD A.B.C.D/M",
6829 SHOW_STR
6830 IP_STR
6831 BGP_STR
6832 "BGP view\n"
6833 "BGP view name\n"
6834 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6835{
6836 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6837}
6838
6839#ifdef HAVE_IPV6
6840DEFUN (show_bgp,
6841 show_bgp_cmd,
6842 "show bgp",
6843 SHOW_STR
6844 BGP_STR)
6845{
ajs5a646652004-11-05 01:25:55 +00006846 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6847 NULL);
paul718e3742002-12-13 20:15:29 +00006848}
6849
6850ALIAS (show_bgp,
6851 show_bgp_ipv6_cmd,
6852 "show bgp ipv6",
6853 SHOW_STR
6854 BGP_STR
6855 "Address family\n")
6856
Michael Lambert95cbbd22010-07-23 14:43:04 -04006857DEFUN (show_bgp_ipv6_safi,
6858 show_bgp_ipv6_safi_cmd,
6859 "show bgp ipv6 (unicast|multicast)",
6860 SHOW_STR
6861 BGP_STR
6862 "Address family\n"
6863 "Address Family modifier\n"
6864 "Address Family modifier\n")
6865{
6866 if (strncmp (argv[0], "m", 1) == 0)
6867 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6868 NULL);
6869
6870 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6871}
6872
paul718e3742002-12-13 20:15:29 +00006873/* old command */
6874DEFUN (show_ipv6_bgp,
6875 show_ipv6_bgp_cmd,
6876 "show ipv6 bgp",
6877 SHOW_STR
6878 IP_STR
6879 BGP_STR)
6880{
ajs5a646652004-11-05 01:25:55 +00006881 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6882 NULL);
paul718e3742002-12-13 20:15:29 +00006883}
6884
6885DEFUN (show_bgp_route,
6886 show_bgp_route_cmd,
6887 "show bgp X:X::X:X",
6888 SHOW_STR
6889 BGP_STR
6890 "Network in the BGP routing table to display\n")
6891{
6892 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6893}
6894
6895ALIAS (show_bgp_route,
6896 show_bgp_ipv6_route_cmd,
6897 "show bgp ipv6 X:X::X:X",
6898 SHOW_STR
6899 BGP_STR
6900 "Address family\n"
6901 "Network in the BGP routing table to display\n")
6902
Michael Lambert95cbbd22010-07-23 14:43:04 -04006903DEFUN (show_bgp_ipv6_safi_route,
6904 show_bgp_ipv6_safi_route_cmd,
6905 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6906 SHOW_STR
6907 BGP_STR
6908 "Address family\n"
6909 "Address Family modifier\n"
6910 "Address Family modifier\n"
6911 "Network in the BGP routing table to display\n")
6912{
6913 if (strncmp (argv[0], "m", 1) == 0)
6914 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6915
6916 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6917}
6918
paul718e3742002-12-13 20:15:29 +00006919/* old command */
6920DEFUN (show_ipv6_bgp_route,
6921 show_ipv6_bgp_route_cmd,
6922 "show ipv6 bgp X:X::X:X",
6923 SHOW_STR
6924 IP_STR
6925 BGP_STR
6926 "Network in the BGP routing table to display\n")
6927{
6928 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6929}
6930
6931DEFUN (show_bgp_prefix,
6932 show_bgp_prefix_cmd,
6933 "show bgp X:X::X:X/M",
6934 SHOW_STR
6935 BGP_STR
6936 "IPv6 prefix <network>/<length>\n")
6937{
6938 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6939}
6940
6941ALIAS (show_bgp_prefix,
6942 show_bgp_ipv6_prefix_cmd,
6943 "show bgp ipv6 X:X::X:X/M",
6944 SHOW_STR
6945 BGP_STR
6946 "Address family\n"
6947 "IPv6 prefix <network>/<length>\n")
6948
Michael Lambert95cbbd22010-07-23 14:43:04 -04006949DEFUN (show_bgp_ipv6_safi_prefix,
6950 show_bgp_ipv6_safi_prefix_cmd,
6951 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6952 SHOW_STR
6953 BGP_STR
6954 "Address family\n"
6955 "Address Family modifier\n"
6956 "Address Family modifier\n"
6957 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6958{
6959 if (strncmp (argv[0], "m", 1) == 0)
6960 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6961
6962 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6963}
6964
paul718e3742002-12-13 20:15:29 +00006965/* old command */
6966DEFUN (show_ipv6_bgp_prefix,
6967 show_ipv6_bgp_prefix_cmd,
6968 "show ipv6 bgp X:X::X:X/M",
6969 SHOW_STR
6970 IP_STR
6971 BGP_STR
6972 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6973{
6974 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6975}
6976
paulbb46e942003-10-24 19:02:03 +00006977DEFUN (show_bgp_view,
6978 show_bgp_view_cmd,
6979 "show bgp view WORD",
6980 SHOW_STR
6981 BGP_STR
6982 "BGP view\n"
6983 "View name\n")
6984{
6985 struct bgp *bgp;
6986
6987 /* BGP structure lookup. */
6988 bgp = bgp_lookup_by_name (argv[0]);
6989 if (bgp == NULL)
6990 {
6991 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6992 return CMD_WARNING;
6993 }
6994
ajs5a646652004-11-05 01:25:55 +00006995 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006996}
6997
6998ALIAS (show_bgp_view,
6999 show_bgp_view_ipv6_cmd,
7000 "show bgp view WORD ipv6",
7001 SHOW_STR
7002 BGP_STR
7003 "BGP view\n"
7004 "View name\n"
7005 "Address family\n")
7006
7007DEFUN (show_bgp_view_route,
7008 show_bgp_view_route_cmd,
7009 "show bgp view WORD X:X::X:X",
7010 SHOW_STR
7011 BGP_STR
7012 "BGP view\n"
7013 "View name\n"
7014 "Network in the BGP routing table to display\n")
7015{
7016 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7017}
7018
7019ALIAS (show_bgp_view_route,
7020 show_bgp_view_ipv6_route_cmd,
7021 "show bgp view WORD ipv6 X:X::X:X",
7022 SHOW_STR
7023 BGP_STR
7024 "BGP view\n"
7025 "View name\n"
7026 "Address family\n"
7027 "Network in the BGP routing table to display\n")
7028
7029DEFUN (show_bgp_view_prefix,
7030 show_bgp_view_prefix_cmd,
7031 "show bgp view WORD X:X::X:X/M",
7032 SHOW_STR
7033 BGP_STR
7034 "BGP view\n"
7035 "View name\n"
7036 "IPv6 prefix <network>/<length>\n")
7037{
7038 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7039}
7040
7041ALIAS (show_bgp_view_prefix,
7042 show_bgp_view_ipv6_prefix_cmd,
7043 "show bgp view WORD ipv6 X:X::X:X/M",
7044 SHOW_STR
7045 BGP_STR
7046 "BGP view\n"
7047 "View name\n"
7048 "Address family\n"
7049 "IPv6 prefix <network>/<length>\n")
7050
paul718e3742002-12-13 20:15:29 +00007051/* old command */
7052DEFUN (show_ipv6_mbgp,
7053 show_ipv6_mbgp_cmd,
7054 "show ipv6 mbgp",
7055 SHOW_STR
7056 IP_STR
7057 MBGP_STR)
7058{
ajs5a646652004-11-05 01:25:55 +00007059 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7060 NULL);
paul718e3742002-12-13 20:15:29 +00007061}
7062
7063/* old command */
7064DEFUN (show_ipv6_mbgp_route,
7065 show_ipv6_mbgp_route_cmd,
7066 "show ipv6 mbgp X:X::X:X",
7067 SHOW_STR
7068 IP_STR
7069 MBGP_STR
7070 "Network in the MBGP routing table to display\n")
7071{
7072 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7073}
7074
7075/* old command */
7076DEFUN (show_ipv6_mbgp_prefix,
7077 show_ipv6_mbgp_prefix_cmd,
7078 "show ipv6 mbgp X:X::X:X/M",
7079 SHOW_STR
7080 IP_STR
7081 MBGP_STR
7082 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7083{
7084 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7085}
7086#endif
7087
paul718e3742002-12-13 20:15:29 +00007088
paul94f2b392005-06-28 12:44:16 +00007089static int
paulfd79ac92004-10-13 05:06:08 +00007090bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007091 safi_t safi, enum bgp_show_type type)
7092{
7093 int i;
7094 struct buffer *b;
7095 char *regstr;
7096 int first;
7097 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007098 int rc;
paul718e3742002-12-13 20:15:29 +00007099
7100 first = 0;
7101 b = buffer_new (1024);
7102 for (i = 0; i < argc; i++)
7103 {
7104 if (first)
7105 buffer_putc (b, ' ');
7106 else
7107 {
7108 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7109 continue;
7110 first = 1;
7111 }
7112
7113 buffer_putstr (b, argv[i]);
7114 }
7115 buffer_putc (b, '\0');
7116
7117 regstr = buffer_getstr (b);
7118 buffer_free (b);
7119
7120 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007121 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007122 if (! regex)
7123 {
7124 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7125 VTY_NEWLINE);
7126 return CMD_WARNING;
7127 }
7128
ajs5a646652004-11-05 01:25:55 +00007129 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7130 bgp_regex_free (regex);
7131 return rc;
paul718e3742002-12-13 20:15:29 +00007132}
7133
7134DEFUN (show_ip_bgp_regexp,
7135 show_ip_bgp_regexp_cmd,
7136 "show ip bgp regexp .LINE",
7137 SHOW_STR
7138 IP_STR
7139 BGP_STR
7140 "Display routes matching the AS path regular expression\n"
7141 "A regular-expression to match the BGP AS paths\n")
7142{
7143 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7144 bgp_show_type_regexp);
7145}
7146
7147DEFUN (show_ip_bgp_flap_regexp,
7148 show_ip_bgp_flap_regexp_cmd,
7149 "show ip bgp flap-statistics regexp .LINE",
7150 SHOW_STR
7151 IP_STR
7152 BGP_STR
7153 "Display flap statistics of routes\n"
7154 "Display routes matching the AS path regular expression\n"
7155 "A regular-expression to match the BGP AS paths\n")
7156{
7157 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7158 bgp_show_type_flap_regexp);
7159}
7160
7161DEFUN (show_ip_bgp_ipv4_regexp,
7162 show_ip_bgp_ipv4_regexp_cmd,
7163 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Address family\n"
7168 "Address Family modifier\n"
7169 "Address Family modifier\n"
7170 "Display routes matching the AS path regular expression\n"
7171 "A regular-expression to match the BGP AS paths\n")
7172{
7173 if (strncmp (argv[0], "m", 1) == 0)
7174 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7175 bgp_show_type_regexp);
7176
7177 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7178 bgp_show_type_regexp);
7179}
7180
7181#ifdef HAVE_IPV6
7182DEFUN (show_bgp_regexp,
7183 show_bgp_regexp_cmd,
7184 "show bgp regexp .LINE",
7185 SHOW_STR
7186 BGP_STR
7187 "Display routes matching the AS path regular expression\n"
7188 "A regular-expression to match the BGP AS paths\n")
7189{
7190 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7191 bgp_show_type_regexp);
7192}
7193
7194ALIAS (show_bgp_regexp,
7195 show_bgp_ipv6_regexp_cmd,
7196 "show bgp ipv6 regexp .LINE",
7197 SHOW_STR
7198 BGP_STR
7199 "Address family\n"
7200 "Display routes matching the AS path regular expression\n"
7201 "A regular-expression to match the BGP AS paths\n")
7202
7203/* old command */
7204DEFUN (show_ipv6_bgp_regexp,
7205 show_ipv6_bgp_regexp_cmd,
7206 "show ipv6 bgp regexp .LINE",
7207 SHOW_STR
7208 IP_STR
7209 BGP_STR
7210 "Display routes matching the AS path regular expression\n"
7211 "A regular-expression to match the BGP AS paths\n")
7212{
7213 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7214 bgp_show_type_regexp);
7215}
7216
7217/* old command */
7218DEFUN (show_ipv6_mbgp_regexp,
7219 show_ipv6_mbgp_regexp_cmd,
7220 "show ipv6 mbgp regexp .LINE",
7221 SHOW_STR
7222 IP_STR
7223 BGP_STR
7224 "Display routes matching the AS path regular expression\n"
7225 "A regular-expression to match the MBGP AS paths\n")
7226{
7227 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7228 bgp_show_type_regexp);
7229}
7230#endif /* HAVE_IPV6 */
7231
paul94f2b392005-06-28 12:44:16 +00007232static int
paulfd79ac92004-10-13 05:06:08 +00007233bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007234 safi_t safi, enum bgp_show_type type)
7235{
7236 struct prefix_list *plist;
7237
7238 plist = prefix_list_lookup (afi, prefix_list_str);
7239 if (plist == NULL)
7240 {
7241 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7242 prefix_list_str, VTY_NEWLINE);
7243 return CMD_WARNING;
7244 }
7245
ajs5a646652004-11-05 01:25:55 +00007246 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007247}
7248
7249DEFUN (show_ip_bgp_prefix_list,
7250 show_ip_bgp_prefix_list_cmd,
7251 "show ip bgp prefix-list WORD",
7252 SHOW_STR
7253 IP_STR
7254 BGP_STR
7255 "Display routes conforming to the prefix-list\n"
7256 "IP prefix-list name\n")
7257{
7258 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7259 bgp_show_type_prefix_list);
7260}
7261
7262DEFUN (show_ip_bgp_flap_prefix_list,
7263 show_ip_bgp_flap_prefix_list_cmd,
7264 "show ip bgp flap-statistics prefix-list WORD",
7265 SHOW_STR
7266 IP_STR
7267 BGP_STR
7268 "Display flap statistics of routes\n"
7269 "Display routes conforming to the prefix-list\n"
7270 "IP prefix-list name\n")
7271{
7272 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7273 bgp_show_type_flap_prefix_list);
7274}
7275
7276DEFUN (show_ip_bgp_ipv4_prefix_list,
7277 show_ip_bgp_ipv4_prefix_list_cmd,
7278 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7279 SHOW_STR
7280 IP_STR
7281 BGP_STR
7282 "Address family\n"
7283 "Address Family modifier\n"
7284 "Address Family modifier\n"
7285 "Display routes conforming to the prefix-list\n"
7286 "IP prefix-list name\n")
7287{
7288 if (strncmp (argv[0], "m", 1) == 0)
7289 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7290 bgp_show_type_prefix_list);
7291
7292 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7293 bgp_show_type_prefix_list);
7294}
7295
7296#ifdef HAVE_IPV6
7297DEFUN (show_bgp_prefix_list,
7298 show_bgp_prefix_list_cmd,
7299 "show bgp prefix-list WORD",
7300 SHOW_STR
7301 BGP_STR
7302 "Display routes conforming to the prefix-list\n"
7303 "IPv6 prefix-list name\n")
7304{
7305 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7306 bgp_show_type_prefix_list);
7307}
7308
7309ALIAS (show_bgp_prefix_list,
7310 show_bgp_ipv6_prefix_list_cmd,
7311 "show bgp ipv6 prefix-list WORD",
7312 SHOW_STR
7313 BGP_STR
7314 "Address family\n"
7315 "Display routes conforming to the prefix-list\n"
7316 "IPv6 prefix-list name\n")
7317
7318/* old command */
7319DEFUN (show_ipv6_bgp_prefix_list,
7320 show_ipv6_bgp_prefix_list_cmd,
7321 "show ipv6 bgp prefix-list WORD",
7322 SHOW_STR
7323 IPV6_STR
7324 BGP_STR
7325 "Display routes matching the prefix-list\n"
7326 "IPv6 prefix-list name\n")
7327{
7328 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7329 bgp_show_type_prefix_list);
7330}
7331
7332/* old command */
7333DEFUN (show_ipv6_mbgp_prefix_list,
7334 show_ipv6_mbgp_prefix_list_cmd,
7335 "show ipv6 mbgp prefix-list WORD",
7336 SHOW_STR
7337 IPV6_STR
7338 MBGP_STR
7339 "Display routes matching the prefix-list\n"
7340 "IPv6 prefix-list name\n")
7341{
7342 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7343 bgp_show_type_prefix_list);
7344}
7345#endif /* HAVE_IPV6 */
7346
paul94f2b392005-06-28 12:44:16 +00007347static int
paulfd79ac92004-10-13 05:06:08 +00007348bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007349 safi_t safi, enum bgp_show_type type)
7350{
7351 struct as_list *as_list;
7352
7353 as_list = as_list_lookup (filter);
7354 if (as_list == NULL)
7355 {
7356 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7357 return CMD_WARNING;
7358 }
7359
ajs5a646652004-11-05 01:25:55 +00007360 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007361}
7362
7363DEFUN (show_ip_bgp_filter_list,
7364 show_ip_bgp_filter_list_cmd,
7365 "show ip bgp filter-list WORD",
7366 SHOW_STR
7367 IP_STR
7368 BGP_STR
7369 "Display routes conforming to the filter-list\n"
7370 "Regular expression access list name\n")
7371{
7372 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7373 bgp_show_type_filter_list);
7374}
7375
7376DEFUN (show_ip_bgp_flap_filter_list,
7377 show_ip_bgp_flap_filter_list_cmd,
7378 "show ip bgp flap-statistics filter-list WORD",
7379 SHOW_STR
7380 IP_STR
7381 BGP_STR
7382 "Display flap statistics of routes\n"
7383 "Display routes conforming to the filter-list\n"
7384 "Regular expression access list name\n")
7385{
7386 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7387 bgp_show_type_flap_filter_list);
7388}
7389
7390DEFUN (show_ip_bgp_ipv4_filter_list,
7391 show_ip_bgp_ipv4_filter_list_cmd,
7392 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7393 SHOW_STR
7394 IP_STR
7395 BGP_STR
7396 "Address family\n"
7397 "Address Family modifier\n"
7398 "Address Family modifier\n"
7399 "Display routes conforming to the filter-list\n"
7400 "Regular expression access list name\n")
7401{
7402 if (strncmp (argv[0], "m", 1) == 0)
7403 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7404 bgp_show_type_filter_list);
7405
7406 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7407 bgp_show_type_filter_list);
7408}
7409
7410#ifdef HAVE_IPV6
7411DEFUN (show_bgp_filter_list,
7412 show_bgp_filter_list_cmd,
7413 "show bgp filter-list WORD",
7414 SHOW_STR
7415 BGP_STR
7416 "Display routes conforming to the filter-list\n"
7417 "Regular expression access list name\n")
7418{
7419 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7420 bgp_show_type_filter_list);
7421}
7422
7423ALIAS (show_bgp_filter_list,
7424 show_bgp_ipv6_filter_list_cmd,
7425 "show bgp ipv6 filter-list WORD",
7426 SHOW_STR
7427 BGP_STR
7428 "Address family\n"
7429 "Display routes conforming to the filter-list\n"
7430 "Regular expression access list name\n")
7431
7432/* old command */
7433DEFUN (show_ipv6_bgp_filter_list,
7434 show_ipv6_bgp_filter_list_cmd,
7435 "show ipv6 bgp filter-list WORD",
7436 SHOW_STR
7437 IPV6_STR
7438 BGP_STR
7439 "Display routes conforming to the filter-list\n"
7440 "Regular expression access list name\n")
7441{
7442 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7443 bgp_show_type_filter_list);
7444}
7445
7446/* old command */
7447DEFUN (show_ipv6_mbgp_filter_list,
7448 show_ipv6_mbgp_filter_list_cmd,
7449 "show ipv6 mbgp filter-list WORD",
7450 SHOW_STR
7451 IPV6_STR
7452 MBGP_STR
7453 "Display routes conforming to the filter-list\n"
7454 "Regular expression access list name\n")
7455{
7456 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7457 bgp_show_type_filter_list);
7458}
7459#endif /* HAVE_IPV6 */
7460
paul94f2b392005-06-28 12:44:16 +00007461static int
paulfd79ac92004-10-13 05:06:08 +00007462bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007463 safi_t safi, enum bgp_show_type type)
7464{
7465 struct route_map *rmap;
7466
7467 rmap = route_map_lookup_by_name (rmap_str);
7468 if (! rmap)
7469 {
7470 vty_out (vty, "%% %s is not a valid route-map name%s",
7471 rmap_str, VTY_NEWLINE);
7472 return CMD_WARNING;
7473 }
7474
ajs5a646652004-11-05 01:25:55 +00007475 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007476}
7477
7478DEFUN (show_ip_bgp_route_map,
7479 show_ip_bgp_route_map_cmd,
7480 "show ip bgp route-map WORD",
7481 SHOW_STR
7482 IP_STR
7483 BGP_STR
7484 "Display routes matching the route-map\n"
7485 "A route-map to match on\n")
7486{
7487 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7488 bgp_show_type_route_map);
7489}
7490
7491DEFUN (show_ip_bgp_flap_route_map,
7492 show_ip_bgp_flap_route_map_cmd,
7493 "show ip bgp flap-statistics route-map WORD",
7494 SHOW_STR
7495 IP_STR
7496 BGP_STR
7497 "Display flap statistics of routes\n"
7498 "Display routes matching the route-map\n"
7499 "A route-map to match on\n")
7500{
7501 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7502 bgp_show_type_flap_route_map);
7503}
7504
7505DEFUN (show_ip_bgp_ipv4_route_map,
7506 show_ip_bgp_ipv4_route_map_cmd,
7507 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7508 SHOW_STR
7509 IP_STR
7510 BGP_STR
7511 "Address family\n"
7512 "Address Family modifier\n"
7513 "Address Family modifier\n"
7514 "Display routes matching the route-map\n"
7515 "A route-map to match on\n")
7516{
7517 if (strncmp (argv[0], "m", 1) == 0)
7518 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7519 bgp_show_type_route_map);
7520
7521 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7522 bgp_show_type_route_map);
7523}
7524
7525DEFUN (show_bgp_route_map,
7526 show_bgp_route_map_cmd,
7527 "show bgp route-map WORD",
7528 SHOW_STR
7529 BGP_STR
7530 "Display routes matching the route-map\n"
7531 "A route-map to match on\n")
7532{
7533 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7534 bgp_show_type_route_map);
7535}
7536
7537ALIAS (show_bgp_route_map,
7538 show_bgp_ipv6_route_map_cmd,
7539 "show bgp ipv6 route-map WORD",
7540 SHOW_STR
7541 BGP_STR
7542 "Address family\n"
7543 "Display routes matching the route-map\n"
7544 "A route-map to match on\n")
7545
7546DEFUN (show_ip_bgp_cidr_only,
7547 show_ip_bgp_cidr_only_cmd,
7548 "show ip bgp cidr-only",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Display only routes with non-natural netmasks\n")
7553{
7554 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007555 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007556}
7557
7558DEFUN (show_ip_bgp_flap_cidr_only,
7559 show_ip_bgp_flap_cidr_only_cmd,
7560 "show ip bgp flap-statistics cidr-only",
7561 SHOW_STR
7562 IP_STR
7563 BGP_STR
7564 "Display flap statistics of routes\n"
7565 "Display only routes with non-natural netmasks\n")
7566{
7567 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007568 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007569}
7570
7571DEFUN (show_ip_bgp_ipv4_cidr_only,
7572 show_ip_bgp_ipv4_cidr_only_cmd,
7573 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7574 SHOW_STR
7575 IP_STR
7576 BGP_STR
7577 "Address family\n"
7578 "Address Family modifier\n"
7579 "Address Family modifier\n"
7580 "Display only routes with non-natural netmasks\n")
7581{
7582 if (strncmp (argv[0], "m", 1) == 0)
7583 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007584 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007585
7586 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007587 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007588}
7589
7590DEFUN (show_ip_bgp_community_all,
7591 show_ip_bgp_community_all_cmd,
7592 "show ip bgp community",
7593 SHOW_STR
7594 IP_STR
7595 BGP_STR
7596 "Display routes matching the communities\n")
7597{
7598 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007599 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007600}
7601
7602DEFUN (show_ip_bgp_ipv4_community_all,
7603 show_ip_bgp_ipv4_community_all_cmd,
7604 "show ip bgp ipv4 (unicast|multicast) community",
7605 SHOW_STR
7606 IP_STR
7607 BGP_STR
7608 "Address family\n"
7609 "Address Family modifier\n"
7610 "Address Family modifier\n"
7611 "Display routes matching the communities\n")
7612{
7613 if (strncmp (argv[0], "m", 1) == 0)
7614 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007615 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007616
7617 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007618 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007619}
7620
7621#ifdef HAVE_IPV6
7622DEFUN (show_bgp_community_all,
7623 show_bgp_community_all_cmd,
7624 "show bgp community",
7625 SHOW_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
7633ALIAS (show_bgp_community_all,
7634 show_bgp_ipv6_community_all_cmd,
7635 "show bgp ipv6 community",
7636 SHOW_STR
7637 BGP_STR
7638 "Address family\n"
7639 "Display routes matching the communities\n")
7640
7641/* old command */
7642DEFUN (show_ipv6_bgp_community_all,
7643 show_ipv6_bgp_community_all_cmd,
7644 "show ipv6 bgp community",
7645 SHOW_STR
7646 IPV6_STR
7647 BGP_STR
7648 "Display routes matching the communities\n")
7649{
7650 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007651 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007652}
7653
7654/* old command */
7655DEFUN (show_ipv6_mbgp_community_all,
7656 show_ipv6_mbgp_community_all_cmd,
7657 "show ipv6 mbgp community",
7658 SHOW_STR
7659 IPV6_STR
7660 MBGP_STR
7661 "Display routes matching the communities\n")
7662{
7663 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007664 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007665}
7666#endif /* HAVE_IPV6 */
7667
paul94f2b392005-06-28 12:44:16 +00007668static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007669bgp_show_community (struct vty *vty, const char *view_name, int argc,
7670 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007671{
7672 struct community *com;
7673 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007674 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007675 int i;
7676 char *str;
7677 int first = 0;
7678
Michael Lambert95cbbd22010-07-23 14:43:04 -04007679 /* BGP structure lookup */
7680 if (view_name)
7681 {
7682 bgp = bgp_lookup_by_name (view_name);
7683 if (bgp == NULL)
7684 {
7685 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7686 return CMD_WARNING;
7687 }
7688 }
7689 else
7690 {
7691 bgp = bgp_get_default ();
7692 if (bgp == NULL)
7693 {
7694 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7695 return CMD_WARNING;
7696 }
7697 }
7698
paul718e3742002-12-13 20:15:29 +00007699 b = buffer_new (1024);
7700 for (i = 0; i < argc; i++)
7701 {
7702 if (first)
7703 buffer_putc (b, ' ');
7704 else
7705 {
7706 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7707 continue;
7708 first = 1;
7709 }
7710
7711 buffer_putstr (b, argv[i]);
7712 }
7713 buffer_putc (b, '\0');
7714
7715 str = buffer_getstr (b);
7716 buffer_free (b);
7717
7718 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007719 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007720 if (! com)
7721 {
7722 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7723 return CMD_WARNING;
7724 }
7725
Michael Lambert95cbbd22010-07-23 14:43:04 -04007726 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007727 (exact ? bgp_show_type_community_exact :
7728 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007729}
7730
7731DEFUN (show_ip_bgp_community,
7732 show_ip_bgp_community_cmd,
7733 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7734 SHOW_STR
7735 IP_STR
7736 BGP_STR
7737 "Display routes matching the communities\n"
7738 "community number\n"
7739 "Do not send outside local AS (well-known community)\n"
7740 "Do not advertise to any peer (well-known community)\n"
7741 "Do not export to next AS (well-known community)\n")
7742{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007743 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007744}
7745
7746ALIAS (show_ip_bgp_community,
7747 show_ip_bgp_community2_cmd,
7748 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7749 SHOW_STR
7750 IP_STR
7751 BGP_STR
7752 "Display routes matching the communities\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n")
7761
7762ALIAS (show_ip_bgp_community,
7763 show_ip_bgp_community3_cmd,
7764 "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)",
7765 SHOW_STR
7766 IP_STR
7767 BGP_STR
7768 "Display routes matching the communities\n"
7769 "community number\n"
7770 "Do not send outside local AS (well-known community)\n"
7771 "Do not advertise to any peer (well-known community)\n"
7772 "Do not export to next AS (well-known community)\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n")
7781
7782ALIAS (show_ip_bgp_community,
7783 show_ip_bgp_community4_cmd,
7784 "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)",
7785 SHOW_STR
7786 IP_STR
7787 BGP_STR
7788 "Display routes matching the communities\n"
7789 "community number\n"
7790 "Do not send outside local AS (well-known community)\n"
7791 "Do not advertise to any peer (well-known community)\n"
7792 "Do not export to next AS (well-known community)\n"
7793 "community number\n"
7794 "Do not send outside local AS (well-known community)\n"
7795 "Do not advertise to any peer (well-known community)\n"
7796 "Do not export to next AS (well-known community)\n"
7797 "community number\n"
7798 "Do not send outside local AS (well-known community)\n"
7799 "Do not advertise to any peer (well-known community)\n"
7800 "Do not export to next AS (well-known community)\n"
7801 "community number\n"
7802 "Do not send outside local AS (well-known community)\n"
7803 "Do not advertise to any peer (well-known community)\n"
7804 "Do not export to next AS (well-known community)\n")
7805
7806DEFUN (show_ip_bgp_ipv4_community,
7807 show_ip_bgp_ipv4_community_cmd,
7808 "show ip bgp ipv4 (unicast|multicast) community (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{
7821 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007822 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007823
Michael Lambert95cbbd22010-07-23 14:43:04 -04007824 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007825}
7826
7827ALIAS (show_ip_bgp_ipv4_community,
7828 show_ip_bgp_ipv4_community2_cmd,
7829 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7830 SHOW_STR
7831 IP_STR
7832 BGP_STR
7833 "Address family\n"
7834 "Address Family modifier\n"
7835 "Address Family modifier\n"
7836 "Display routes matching the communities\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n")
7845
7846ALIAS (show_ip_bgp_ipv4_community,
7847 show_ip_bgp_ipv4_community3_cmd,
7848 "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)",
7849 SHOW_STR
7850 IP_STR
7851 BGP_STR
7852 "Address family\n"
7853 "Address Family modifier\n"
7854 "Address Family modifier\n"
7855 "Display routes matching the communities\n"
7856 "community number\n"
7857 "Do not send outside local AS (well-known community)\n"
7858 "Do not advertise to any peer (well-known community)\n"
7859 "Do not export to next AS (well-known community)\n"
7860 "community number\n"
7861 "Do not send outside local AS (well-known community)\n"
7862 "Do not advertise to any peer (well-known community)\n"
7863 "Do not export to next AS (well-known community)\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n")
7868
7869ALIAS (show_ip_bgp_ipv4_community,
7870 show_ip_bgp_ipv4_community4_cmd,
7871 "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)",
7872 SHOW_STR
7873 IP_STR
7874 BGP_STR
7875 "Address family\n"
7876 "Address Family modifier\n"
7877 "Address Family modifier\n"
7878 "Display routes matching the communities\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n"
7887 "community number\n"
7888 "Do not send outside local AS (well-known community)\n"
7889 "Do not advertise to any peer (well-known community)\n"
7890 "Do not export to next AS (well-known community)\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n")
7895
Michael Lambert95cbbd22010-07-23 14:43:04 -04007896DEFUN (show_bgp_view_afi_safi_community_all,
7897 show_bgp_view_afi_safi_community_all_cmd,
7898#ifdef HAVE_IPV6
7899 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7900#else
7901 "show bgp view WORD ipv4 (unicast|multicast) community",
7902#endif
7903 SHOW_STR
7904 BGP_STR
7905 "BGP view\n"
7906 "BGP view name\n"
7907 "Address family\n"
7908#ifdef HAVE_IPV6
7909 "Address family\n"
7910#endif
7911 "Address Family modifier\n"
7912 "Address Family modifier\n"
7913 "Display routes containing communities\n")
7914{
7915 int afi;
7916 int safi;
7917 struct bgp *bgp;
7918
7919 /* BGP structure lookup. */
7920 bgp = bgp_lookup_by_name (argv[0]);
7921 if (bgp == NULL)
7922 {
7923 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7924 return CMD_WARNING;
7925 }
7926
7927#ifdef HAVE_IPV6
7928 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7929 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7930#else
7931 afi = AFI_IP;
7932 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7933#endif
7934 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7935}
7936
7937DEFUN (show_bgp_view_afi_safi_community,
7938 show_bgp_view_afi_safi_community_cmd,
7939#ifdef HAVE_IPV6
7940 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7941#else
7942 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7943#endif
7944 SHOW_STR
7945 BGP_STR
7946 "BGP view\n"
7947 "BGP view name\n"
7948 "Address family\n"
7949#ifdef HAVE_IPV6
7950 "Address family\n"
7951#endif
7952 "Address family modifier\n"
7953 "Address family modifier\n"
7954 "Display routes matching the communities\n"
7955 "community number\n"
7956 "Do not send outside local AS (well-known community)\n"
7957 "Do not advertise to any peer (well-known community)\n"
7958 "Do not export to next AS (well-known community)\n")
7959{
7960 int afi;
7961 int safi;
7962
7963#ifdef HAVE_IPV6
7964 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7965 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7966 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7967#else
7968 afi = AFI_IP;
7969 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7970 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7971#endif
7972}
7973
7974ALIAS (show_bgp_view_afi_safi_community,
7975 show_bgp_view_afi_safi_community2_cmd,
7976#ifdef HAVE_IPV6
7977 "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)",
7978#else
7979 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7980#endif
7981 SHOW_STR
7982 BGP_STR
7983 "BGP view\n"
7984 "BGP view name\n"
7985 "Address family\n"
7986#ifdef HAVE_IPV6
7987 "Address family\n"
7988#endif
7989 "Address family modifier\n"
7990 "Address family modifier\n"
7991 "Display routes matching the communities\n"
7992 "community number\n"
7993 "Do not send outside local AS (well-known community)\n"
7994 "Do not advertise to any peer (well-known community)\n"
7995 "Do not export to next AS (well-known community)\n"
7996 "community number\n"
7997 "Do not send outside local AS (well-known community)\n"
7998 "Do not advertise to any peer (well-known community)\n"
7999 "Do not export to next AS (well-known community)\n")
8000
8001ALIAS (show_bgp_view_afi_safi_community,
8002 show_bgp_view_afi_safi_community3_cmd,
8003#ifdef HAVE_IPV6
8004 "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)",
8005#else
8006 "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)",
8007#endif
8008 SHOW_STR
8009 BGP_STR
8010 "BGP view\n"
8011 "BGP view name\n"
8012 "Address family\n"
8013#ifdef HAVE_IPV6
8014 "Address family\n"
8015#endif
8016 "Address family modifier\n"
8017 "Address family modifier\n"
8018 "Display routes matching the communities\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n"
8027 "community number\n"
8028 "Do not send outside local AS (well-known community)\n"
8029 "Do not advertise to any peer (well-known community)\n"
8030 "Do not export to next AS (well-known community)\n")
8031
8032ALIAS (show_bgp_view_afi_safi_community,
8033 show_bgp_view_afi_safi_community4_cmd,
8034#ifdef HAVE_IPV6
8035 "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)",
8036#else
8037 "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)",
8038#endif
8039 SHOW_STR
8040 BGP_STR
8041 "BGP view\n"
8042 "BGP view name\n"
8043 "Address family\n"
8044#ifdef HAVE_IPV6
8045 "Address family\n"
8046#endif
8047 "Address family modifier\n"
8048 "Address family modifier\n"
8049 "Display routes matching the communities\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "community number\n"
8059 "Do not send outside local AS (well-known community)\n"
8060 "Do not advertise to any peer (well-known community)\n"
8061 "Do not export to next AS (well-known community)\n"
8062 "community number\n"
8063 "Do not send outside local AS (well-known community)\n"
8064 "Do not advertise to any peer (well-known community)\n"
8065 "Do not export to next AS (well-known community)\n")
8066
paul718e3742002-12-13 20:15:29 +00008067DEFUN (show_ip_bgp_community_exact,
8068 show_ip_bgp_community_exact_cmd,
8069 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8070 SHOW_STR
8071 IP_STR
8072 BGP_STR
8073 "Display routes matching the communities\n"
8074 "community number\n"
8075 "Do not send outside local AS (well-known community)\n"
8076 "Do not advertise to any peer (well-known community)\n"
8077 "Do not export to next AS (well-known community)\n"
8078 "Exact match of the communities")
8079{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008080 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008081}
8082
8083ALIAS (show_ip_bgp_community_exact,
8084 show_ip_bgp_community2_exact_cmd,
8085 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8086 SHOW_STR
8087 IP_STR
8088 BGP_STR
8089 "Display routes matching the communities\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_community3_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) 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 "Exact match of the communities")
8120
8121ALIAS (show_ip_bgp_community_exact,
8122 show_ip_bgp_community4_exact_cmd,
8123 "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",
8124 SHOW_STR
8125 IP_STR
8126 BGP_STR
8127 "Display routes matching the communities\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "community number\n"
8141 "Do not send outside local AS (well-known community)\n"
8142 "Do not advertise to any peer (well-known community)\n"
8143 "Do not export to next AS (well-known community)\n"
8144 "Exact match of the communities")
8145
8146DEFUN (show_ip_bgp_ipv4_community_exact,
8147 show_ip_bgp_ipv4_community_exact_cmd,
8148 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8149 SHOW_STR
8150 IP_STR
8151 BGP_STR
8152 "Address family\n"
8153 "Address Family modifier\n"
8154 "Address Family modifier\n"
8155 "Display routes matching the communities\n"
8156 "community number\n"
8157 "Do not send outside local AS (well-known community)\n"
8158 "Do not advertise to any peer (well-known community)\n"
8159 "Do not export to next AS (well-known community)\n"
8160 "Exact match of the communities")
8161{
8162 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008163 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008164
Michael Lambert95cbbd22010-07-23 14:43:04 -04008165 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008166}
8167
8168ALIAS (show_ip_bgp_ipv4_community_exact,
8169 show_ip_bgp_ipv4_community2_exact_cmd,
8170 "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",
8171 SHOW_STR
8172 IP_STR
8173 BGP_STR
8174 "Address family\n"
8175 "Address Family modifier\n"
8176 "Address Family modifier\n"
8177 "Display routes matching the communities\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "community number\n"
8183 "Do not send outside local AS (well-known community)\n"
8184 "Do not advertise to any peer (well-known community)\n"
8185 "Do not export to next AS (well-known community)\n"
8186 "Exact match of the communities")
8187
8188ALIAS (show_ip_bgp_ipv4_community_exact,
8189 show_ip_bgp_ipv4_community3_exact_cmd,
8190 "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",
8191 SHOW_STR
8192 IP_STR
8193 BGP_STR
8194 "Address family\n"
8195 "Address Family modifier\n"
8196 "Address Family modifier\n"
8197 "Display routes matching the communities\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "Exact match of the communities")
8211
8212ALIAS (show_ip_bgp_ipv4_community_exact,
8213 show_ip_bgp_ipv4_community4_exact_cmd,
8214 "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",
8215 SHOW_STR
8216 IP_STR
8217 BGP_STR
8218 "Address family\n"
8219 "Address Family modifier\n"
8220 "Address Family modifier\n"
8221 "Display routes matching the communities\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\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 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n"
8238 "Exact match of the communities")
8239
8240#ifdef HAVE_IPV6
8241DEFUN (show_bgp_community,
8242 show_bgp_community_cmd,
8243 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8244 SHOW_STR
8245 BGP_STR
8246 "Display routes matching the communities\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n")
8251{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008252 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008253}
8254
8255ALIAS (show_bgp_community,
8256 show_bgp_ipv6_community_cmd,
8257 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8258 SHOW_STR
8259 BGP_STR
8260 "Address family\n"
8261 "Display routes matching the communities\n"
8262 "community number\n"
8263 "Do not send outside local AS (well-known community)\n"
8264 "Do not advertise to any peer (well-known community)\n"
8265 "Do not export to next AS (well-known community)\n")
8266
8267ALIAS (show_bgp_community,
8268 show_bgp_community2_cmd,
8269 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8270 SHOW_STR
8271 BGP_STR
8272 "Display routes matching the communities\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n"
8277 "community number\n"
8278 "Do not send outside local AS (well-known community)\n"
8279 "Do not advertise to any peer (well-known community)\n"
8280 "Do not export to next AS (well-known community)\n")
8281
8282ALIAS (show_bgp_community,
8283 show_bgp_ipv6_community2_cmd,
8284 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8285 SHOW_STR
8286 BGP_STR
8287 "Address family\n"
8288 "Display routes matching the communities\n"
8289 "community number\n"
8290 "Do not send outside local AS (well-known community)\n"
8291 "Do not advertise to any peer (well-known community)\n"
8292 "Do not export to next AS (well-known community)\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\n")
8297
8298ALIAS (show_bgp_community,
8299 show_bgp_community3_cmd,
8300 "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)",
8301 SHOW_STR
8302 BGP_STR
8303 "Display routes matching the communities\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n")
8316
8317ALIAS (show_bgp_community,
8318 show_bgp_ipv6_community3_cmd,
8319 "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)",
8320 SHOW_STR
8321 BGP_STR
8322 "Address family\n"
8323 "Display routes matching the communities\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n")
8336
8337ALIAS (show_bgp_community,
8338 show_bgp_community4_cmd,
8339 "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)",
8340 SHOW_STR
8341 BGP_STR
8342 "Display routes matching the communities\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n")
8359
8360ALIAS (show_bgp_community,
8361 show_bgp_ipv6_community4_cmd,
8362 "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)",
8363 SHOW_STR
8364 BGP_STR
8365 "Address family\n"
8366 "Display routes matching the communities\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\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 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n")
8383
8384/* old command */
8385DEFUN (show_ipv6_bgp_community,
8386 show_ipv6_bgp_community_cmd,
8387 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8388 SHOW_STR
8389 IPV6_STR
8390 BGP_STR
8391 "Display routes matching the communities\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\n")
8396{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008397 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008398}
8399
8400/* old command */
8401ALIAS (show_ipv6_bgp_community,
8402 show_ipv6_bgp_community2_cmd,
8403 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8404 SHOW_STR
8405 IPV6_STR
8406 BGP_STR
8407 "Display routes matching the communities\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_community3_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)",
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
8438/* old command */
8439ALIAS (show_ipv6_bgp_community,
8440 show_ipv6_bgp_community4_cmd,
8441 "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)",
8442 SHOW_STR
8443 IPV6_STR
8444 BGP_STR
8445 "Display routes matching the communities\n"
8446 "community number\n"
8447 "Do not send outside local AS (well-known community)\n"
8448 "Do not advertise to any peer (well-known community)\n"
8449 "Do not export to next AS (well-known community)\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n")
8462
8463DEFUN (show_bgp_community_exact,
8464 show_bgp_community_exact_cmd,
8465 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8466 SHOW_STR
8467 BGP_STR
8468 "Display routes matching the communities\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "Exact match of the communities")
8474{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008475 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008476}
8477
8478ALIAS (show_bgp_community_exact,
8479 show_bgp_ipv6_community_exact_cmd,
8480 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8481 SHOW_STR
8482 BGP_STR
8483 "Address family\n"
8484 "Display routes matching the communities\n"
8485 "community number\n"
8486 "Do not send outside local AS (well-known community)\n"
8487 "Do not advertise to any peer (well-known community)\n"
8488 "Do not export to next AS (well-known community)\n"
8489 "Exact match of the communities")
8490
8491ALIAS (show_bgp_community_exact,
8492 show_bgp_community2_exact_cmd,
8493 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8494 SHOW_STR
8495 BGP_STR
8496 "Display routes matching the communities\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 "community number\n"
8502 "Do not send outside local AS (well-known community)\n"
8503 "Do not advertise to any peer (well-known community)\n"
8504 "Do not export to next AS (well-known community)\n"
8505 "Exact match of the communities")
8506
8507ALIAS (show_bgp_community_exact,
8508 show_bgp_ipv6_community2_exact_cmd,
8509 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8510 SHOW_STR
8511 BGP_STR
8512 "Address family\n"
8513 "Display routes matching the communities\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "community number\n"
8519 "Do not send outside local AS (well-known community)\n"
8520 "Do not advertise to any peer (well-known community)\n"
8521 "Do not export to next AS (well-known community)\n"
8522 "Exact match of the communities")
8523
8524ALIAS (show_bgp_community_exact,
8525 show_bgp_community3_exact_cmd,
8526 "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",
8527 SHOW_STR
8528 BGP_STR
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_ipv6_community3_exact_cmd,
8546 "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",
8547 SHOW_STR
8548 BGP_STR
8549 "Address family\n"
8550 "Display routes matching the communities\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "Exact match of the communities")
8564
8565ALIAS (show_bgp_community_exact,
8566 show_bgp_community4_exact_cmd,
8567 "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",
8568 SHOW_STR
8569 BGP_STR
8570 "Display routes matching the communities\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8588
8589ALIAS (show_bgp_community_exact,
8590 show_bgp_ipv6_community4_exact_cmd,
8591 "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",
8592 SHOW_STR
8593 BGP_STR
8594 "Address family\n"
8595 "Display routes matching the communities\n"
8596 "community number\n"
8597 "Do not send outside local AS (well-known community)\n"
8598 "Do not advertise to any peer (well-known community)\n"
8599 "Do not export to next AS (well-known community)\n"
8600 "community number\n"
8601 "Do not send outside local AS (well-known community)\n"
8602 "Do not advertise to any peer (well-known community)\n"
8603 "Do not export to next AS (well-known community)\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "Exact match of the communities")
8613
8614/* old command */
8615DEFUN (show_ipv6_bgp_community_exact,
8616 show_ipv6_bgp_community_exact_cmd,
8617 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8618 SHOW_STR
8619 IPV6_STR
8620 BGP_STR
8621 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008628 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008629}
8630
8631/* old command */
8632ALIAS (show_ipv6_bgp_community_exact,
8633 show_ipv6_bgp_community2_exact_cmd,
8634 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8635 SHOW_STR
8636 IPV6_STR
8637 BGP_STR
8638 "Display routes matching the communities\n"
8639 "community number\n"
8640 "Do not send outside local AS (well-known community)\n"
8641 "Do not advertise to any peer (well-known community)\n"
8642 "Do not export to next AS (well-known community)\n"
8643 "community number\n"
8644 "Do not send outside local AS (well-known community)\n"
8645 "Do not advertise to any peer (well-known community)\n"
8646 "Do not export to next AS (well-known community)\n"
8647 "Exact match of the communities")
8648
8649/* old command */
8650ALIAS (show_ipv6_bgp_community_exact,
8651 show_ipv6_bgp_community3_exact_cmd,
8652 "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",
8653 SHOW_STR
8654 IPV6_STR
8655 BGP_STR
8656 "Display routes matching the communities\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "Exact match of the communities")
8670
8671/* old command */
8672ALIAS (show_ipv6_bgp_community_exact,
8673 show_ipv6_bgp_community4_exact_cmd,
8674 "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",
8675 SHOW_STR
8676 IPV6_STR
8677 BGP_STR
8678 "Display routes matching the communities\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n"
8687 "community number\n"
8688 "Do not send outside local AS (well-known community)\n"
8689 "Do not advertise to any peer (well-known community)\n"
8690 "Do not export to next AS (well-known community)\n"
8691 "community number\n"
8692 "Do not send outside local AS (well-known community)\n"
8693 "Do not advertise to any peer (well-known community)\n"
8694 "Do not export to next AS (well-known community)\n"
8695 "Exact match of the communities")
8696
8697/* old command */
8698DEFUN (show_ipv6_mbgp_community,
8699 show_ipv6_mbgp_community_cmd,
8700 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8701 SHOW_STR
8702 IPV6_STR
8703 MBGP_STR
8704 "Display routes matching the communities\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n")
8709{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008710 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008711}
8712
8713/* old command */
8714ALIAS (show_ipv6_mbgp_community,
8715 show_ipv6_mbgp_community2_cmd,
8716 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8717 SHOW_STR
8718 IPV6_STR
8719 MBGP_STR
8720 "Display routes matching the communities\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_community3_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)",
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
8751/* old command */
8752ALIAS (show_ipv6_mbgp_community,
8753 show_ipv6_mbgp_community4_cmd,
8754 "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)",
8755 SHOW_STR
8756 IPV6_STR
8757 MBGP_STR
8758 "Display routes matching the communities\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\n"
8767 "community number\n"
8768 "Do not send outside local AS (well-known community)\n"
8769 "Do not advertise to any peer (well-known community)\n"
8770 "Do not export to next AS (well-known community)\n"
8771 "community number\n"
8772 "Do not send outside local AS (well-known community)\n"
8773 "Do not advertise to any peer (well-known community)\n"
8774 "Do not export to next AS (well-known community)\n")
8775
8776/* old command */
8777DEFUN (show_ipv6_mbgp_community_exact,
8778 show_ipv6_mbgp_community_exact_cmd,
8779 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8780 SHOW_STR
8781 IPV6_STR
8782 MBGP_STR
8783 "Display routes matching the communities\n"
8784 "community number\n"
8785 "Do not send outside local AS (well-known community)\n"
8786 "Do not advertise to any peer (well-known community)\n"
8787 "Do not export to next AS (well-known community)\n"
8788 "Exact match of the communities")
8789{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008790 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008791}
8792
8793/* old command */
8794ALIAS (show_ipv6_mbgp_community_exact,
8795 show_ipv6_mbgp_community2_exact_cmd,
8796 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8797 SHOW_STR
8798 IPV6_STR
8799 MBGP_STR
8800 "Display routes matching the communities\n"
8801 "community number\n"
8802 "Do not send outside local AS (well-known community)\n"
8803 "Do not advertise to any peer (well-known community)\n"
8804 "Do not export to next AS (well-known community)\n"
8805 "community number\n"
8806 "Do not send outside local AS (well-known community)\n"
8807 "Do not advertise to any peer (well-known community)\n"
8808 "Do not export to next AS (well-known community)\n"
8809 "Exact match of the communities")
8810
8811/* old command */
8812ALIAS (show_ipv6_mbgp_community_exact,
8813 show_ipv6_mbgp_community3_exact_cmd,
8814 "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",
8815 SHOW_STR
8816 IPV6_STR
8817 MBGP_STR
8818 "Display routes matching the communities\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\n"
8831 "Exact match of the communities")
8832
8833/* old command */
8834ALIAS (show_ipv6_mbgp_community_exact,
8835 show_ipv6_mbgp_community4_exact_cmd,
8836 "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",
8837 SHOW_STR
8838 IPV6_STR
8839 MBGP_STR
8840 "Display routes matching the communities\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "community number\n"
8846 "Do not send outside local AS (well-known community)\n"
8847 "Do not advertise to any peer (well-known community)\n"
8848 "Do not export to next AS (well-known community)\n"
8849 "community number\n"
8850 "Do not send outside local AS (well-known community)\n"
8851 "Do not advertise to any peer (well-known community)\n"
8852 "Do not export to next AS (well-known community)\n"
8853 "community number\n"
8854 "Do not send outside local AS (well-known community)\n"
8855 "Do not advertise to any peer (well-known community)\n"
8856 "Do not export to next AS (well-known community)\n"
8857 "Exact match of the communities")
8858#endif /* HAVE_IPV6 */
8859
paul94f2b392005-06-28 12:44:16 +00008860static int
paulfd79ac92004-10-13 05:06:08 +00008861bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008862 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008863{
8864 struct community_list *list;
8865
hassofee6e4e2005-02-02 16:29:31 +00008866 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008867 if (list == NULL)
8868 {
8869 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8870 VTY_NEWLINE);
8871 return CMD_WARNING;
8872 }
8873
ajs5a646652004-11-05 01:25:55 +00008874 return bgp_show (vty, NULL, afi, safi,
8875 (exact ? bgp_show_type_community_list_exact :
8876 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008877}
8878
8879DEFUN (show_ip_bgp_community_list,
8880 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008881 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008882 SHOW_STR
8883 IP_STR
8884 BGP_STR
8885 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008886 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008887 "community-list name\n")
8888{
8889 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8890}
8891
8892DEFUN (show_ip_bgp_ipv4_community_list,
8893 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008894 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008895 SHOW_STR
8896 IP_STR
8897 BGP_STR
8898 "Address family\n"
8899 "Address Family modifier\n"
8900 "Address Family modifier\n"
8901 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008902 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008903 "community-list name\n")
8904{
8905 if (strncmp (argv[0], "m", 1) == 0)
8906 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8907
8908 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8909}
8910
8911DEFUN (show_ip_bgp_community_list_exact,
8912 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008913 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008914 SHOW_STR
8915 IP_STR
8916 BGP_STR
8917 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008918 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008919 "community-list name\n"
8920 "Exact match of the communities\n")
8921{
8922 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8923}
8924
8925DEFUN (show_ip_bgp_ipv4_community_list_exact,
8926 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008927 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008928 SHOW_STR
8929 IP_STR
8930 BGP_STR
8931 "Address family\n"
8932 "Address Family modifier\n"
8933 "Address Family modifier\n"
8934 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008935 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008936 "community-list name\n"
8937 "Exact match of the communities\n")
8938{
8939 if (strncmp (argv[0], "m", 1) == 0)
8940 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8941
8942 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8943}
8944
8945#ifdef HAVE_IPV6
8946DEFUN (show_bgp_community_list,
8947 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008948 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008949 SHOW_STR
8950 BGP_STR
8951 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008952 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008953 "community-list name\n")
8954{
8955 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8956}
8957
8958ALIAS (show_bgp_community_list,
8959 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008960 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008961 SHOW_STR
8962 BGP_STR
8963 "Address family\n"
8964 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008965 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008966 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008967
8968/* old command */
8969DEFUN (show_ipv6_bgp_community_list,
8970 show_ipv6_bgp_community_list_cmd,
8971 "show ipv6 bgp community-list WORD",
8972 SHOW_STR
8973 IPV6_STR
8974 BGP_STR
8975 "Display routes matching the community-list\n"
8976 "community-list name\n")
8977{
8978 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8979}
8980
8981/* old command */
8982DEFUN (show_ipv6_mbgp_community_list,
8983 show_ipv6_mbgp_community_list_cmd,
8984 "show ipv6 mbgp community-list WORD",
8985 SHOW_STR
8986 IPV6_STR
8987 MBGP_STR
8988 "Display routes matching the community-list\n"
8989 "community-list name\n")
8990{
8991 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8992}
8993
8994DEFUN (show_bgp_community_list_exact,
8995 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008996 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008997 SHOW_STR
8998 BGP_STR
8999 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009000 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009001 "community-list name\n"
9002 "Exact match of the communities\n")
9003{
9004 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9005}
9006
9007ALIAS (show_bgp_community_list_exact,
9008 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009009 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009010 SHOW_STR
9011 BGP_STR
9012 "Address family\n"
9013 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009014 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009015 "community-list name\n"
9016 "Exact match of the communities\n")
9017
9018/* old command */
9019DEFUN (show_ipv6_bgp_community_list_exact,
9020 show_ipv6_bgp_community_list_exact_cmd,
9021 "show ipv6 bgp community-list WORD exact-match",
9022 SHOW_STR
9023 IPV6_STR
9024 BGP_STR
9025 "Display routes matching the community-list\n"
9026 "community-list name\n"
9027 "Exact match of the communities\n")
9028{
9029 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9030}
9031
9032/* old command */
9033DEFUN (show_ipv6_mbgp_community_list_exact,
9034 show_ipv6_mbgp_community_list_exact_cmd,
9035 "show ipv6 mbgp community-list WORD exact-match",
9036 SHOW_STR
9037 IPV6_STR
9038 MBGP_STR
9039 "Display routes matching the community-list\n"
9040 "community-list name\n"
9041 "Exact match of the communities\n")
9042{
9043 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9044}
9045#endif /* HAVE_IPV6 */
9046
paul94f2b392005-06-28 12:44:16 +00009047static int
paulfd79ac92004-10-13 05:06:08 +00009048bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009049 safi_t safi, enum bgp_show_type type)
9050{
9051 int ret;
9052 struct prefix *p;
9053
9054 p = prefix_new();
9055
9056 ret = str2prefix (prefix, p);
9057 if (! ret)
9058 {
9059 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9060 return CMD_WARNING;
9061 }
9062
ajs5a646652004-11-05 01:25:55 +00009063 ret = bgp_show (vty, NULL, afi, safi, type, p);
9064 prefix_free(p);
9065 return ret;
paul718e3742002-12-13 20:15:29 +00009066}
9067
9068DEFUN (show_ip_bgp_prefix_longer,
9069 show_ip_bgp_prefix_longer_cmd,
9070 "show ip bgp A.B.C.D/M longer-prefixes",
9071 SHOW_STR
9072 IP_STR
9073 BGP_STR
9074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9075 "Display route and more specific routes\n")
9076{
9077 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9078 bgp_show_type_prefix_longer);
9079}
9080
9081DEFUN (show_ip_bgp_flap_prefix_longer,
9082 show_ip_bgp_flap_prefix_longer_cmd,
9083 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9084 SHOW_STR
9085 IP_STR
9086 BGP_STR
9087 "Display flap statistics of routes\n"
9088 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9089 "Display route and more specific routes\n")
9090{
9091 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9092 bgp_show_type_flap_prefix_longer);
9093}
9094
9095DEFUN (show_ip_bgp_ipv4_prefix_longer,
9096 show_ip_bgp_ipv4_prefix_longer_cmd,
9097 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9098 SHOW_STR
9099 IP_STR
9100 BGP_STR
9101 "Address family\n"
9102 "Address Family modifier\n"
9103 "Address Family modifier\n"
9104 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9105 "Display route and more specific routes\n")
9106{
9107 if (strncmp (argv[0], "m", 1) == 0)
9108 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9109 bgp_show_type_prefix_longer);
9110
9111 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9112 bgp_show_type_prefix_longer);
9113}
9114
9115DEFUN (show_ip_bgp_flap_address,
9116 show_ip_bgp_flap_address_cmd,
9117 "show ip bgp flap-statistics A.B.C.D",
9118 SHOW_STR
9119 IP_STR
9120 BGP_STR
9121 "Display flap statistics of routes\n"
9122 "Network in the BGP routing table to display\n")
9123{
9124 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9125 bgp_show_type_flap_address);
9126}
9127
9128DEFUN (show_ip_bgp_flap_prefix,
9129 show_ip_bgp_flap_prefix_cmd,
9130 "show ip bgp flap-statistics A.B.C.D/M",
9131 SHOW_STR
9132 IP_STR
9133 BGP_STR
9134 "Display flap statistics of routes\n"
9135 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9136{
9137 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9138 bgp_show_type_flap_prefix);
9139}
9140#ifdef HAVE_IPV6
9141DEFUN (show_bgp_prefix_longer,
9142 show_bgp_prefix_longer_cmd,
9143 "show bgp X:X::X:X/M longer-prefixes",
9144 SHOW_STR
9145 BGP_STR
9146 "IPv6 prefix <network>/<length>\n"
9147 "Display route and more specific routes\n")
9148{
9149 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9150 bgp_show_type_prefix_longer);
9151}
9152
9153ALIAS (show_bgp_prefix_longer,
9154 show_bgp_ipv6_prefix_longer_cmd,
9155 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9156 SHOW_STR
9157 BGP_STR
9158 "Address family\n"
9159 "IPv6 prefix <network>/<length>\n"
9160 "Display route and more specific routes\n")
9161
9162/* old command */
9163DEFUN (show_ipv6_bgp_prefix_longer,
9164 show_ipv6_bgp_prefix_longer_cmd,
9165 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9166 SHOW_STR
9167 IPV6_STR
9168 BGP_STR
9169 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9170 "Display route and more specific routes\n")
9171{
9172 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9173 bgp_show_type_prefix_longer);
9174}
9175
9176/* old command */
9177DEFUN (show_ipv6_mbgp_prefix_longer,
9178 show_ipv6_mbgp_prefix_longer_cmd,
9179 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9180 SHOW_STR
9181 IPV6_STR
9182 MBGP_STR
9183 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9184 "Display route and more specific routes\n")
9185{
9186 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9187 bgp_show_type_prefix_longer);
9188}
9189#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009190
paul94f2b392005-06-28 12:44:16 +00009191static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009192peer_lookup_in_view (struct vty *vty, const char *view_name,
9193 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009194{
9195 int ret;
9196 struct bgp *bgp;
9197 struct peer *peer;
9198 union sockunion su;
9199
9200 /* BGP structure lookup. */
9201 if (view_name)
9202 {
9203 bgp = bgp_lookup_by_name (view_name);
9204 if (! bgp)
9205 {
9206 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9207 return NULL;
9208 }
9209 }
paul5228ad22004-06-04 17:58:18 +00009210 else
paulbb46e942003-10-24 19:02:03 +00009211 {
9212 bgp = bgp_get_default ();
9213 if (! bgp)
9214 {
9215 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9216 return NULL;
9217 }
9218 }
9219
9220 /* Get peer sockunion. */
9221 ret = str2sockunion (ip_str, &su);
9222 if (ret < 0)
9223 {
9224 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9225 return NULL;
9226 }
9227
9228 /* Peer structure lookup. */
9229 peer = peer_lookup (bgp, &su);
9230 if (! peer)
9231 {
9232 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9233 return NULL;
9234 }
9235
9236 return peer;
9237}
Paul Jakma2815e612006-09-14 02:56:07 +00009238
9239enum bgp_stats
9240{
9241 BGP_STATS_MAXBITLEN = 0,
9242 BGP_STATS_RIB,
9243 BGP_STATS_PREFIXES,
9244 BGP_STATS_TOTPLEN,
9245 BGP_STATS_UNAGGREGATEABLE,
9246 BGP_STATS_MAX_AGGREGATEABLE,
9247 BGP_STATS_AGGREGATES,
9248 BGP_STATS_SPACE,
9249 BGP_STATS_ASPATH_COUNT,
9250 BGP_STATS_ASPATH_MAXHOPS,
9251 BGP_STATS_ASPATH_TOTHOPS,
9252 BGP_STATS_ASPATH_MAXSIZE,
9253 BGP_STATS_ASPATH_TOTSIZE,
9254 BGP_STATS_ASN_HIGHEST,
9255 BGP_STATS_MAX,
9256};
paulbb46e942003-10-24 19:02:03 +00009257
Paul Jakma2815e612006-09-14 02:56:07 +00009258static const char *table_stats_strs[] =
9259{
9260 [BGP_STATS_PREFIXES] = "Total Prefixes",
9261 [BGP_STATS_TOTPLEN] = "Average prefix length",
9262 [BGP_STATS_RIB] = "Total Advertisements",
9263 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9264 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9265 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9266 [BGP_STATS_SPACE] = "Address space advertised",
9267 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9268 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9269 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9270 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9271 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9272 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9273 [BGP_STATS_MAX] = NULL,
9274};
9275
9276struct bgp_table_stats
9277{
9278 struct bgp_table *table;
9279 unsigned long long counts[BGP_STATS_MAX];
9280};
9281
9282#if 0
9283#define TALLY_SIGFIG 100000
9284static unsigned long
9285ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9286{
9287 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9288 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9289 unsigned long ret = newtot / count;
9290
9291 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9292 return ret + 1;
9293 else
9294 return ret;
9295}
9296#endif
9297
9298static int
9299bgp_table_stats_walker (struct thread *t)
9300{
9301 struct bgp_node *rn;
9302 struct bgp_node *top;
9303 struct bgp_table_stats *ts = THREAD_ARG (t);
9304 unsigned int space = 0;
9305
Paul Jakma53d9f672006-10-15 23:41:16 +00009306 if (!(top = bgp_table_top (ts->table)))
9307 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009308
9309 switch (top->p.family)
9310 {
9311 case AF_INET:
9312 space = IPV4_MAX_BITLEN;
9313 break;
9314 case AF_INET6:
9315 space = IPV6_MAX_BITLEN;
9316 break;
9317 }
9318
9319 ts->counts[BGP_STATS_MAXBITLEN] = space;
9320
9321 for (rn = top; rn; rn = bgp_route_next (rn))
9322 {
9323 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009324 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009325 unsigned int rinum = 0;
9326
9327 if (rn == top)
9328 continue;
9329
9330 if (!rn->info)
9331 continue;
9332
9333 ts->counts[BGP_STATS_PREFIXES]++;
9334 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9335
9336#if 0
9337 ts->counts[BGP_STATS_AVGPLEN]
9338 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9339 ts->counts[BGP_STATS_AVGPLEN],
9340 rn->p.prefixlen);
9341#endif
9342
9343 /* check if the prefix is included by any other announcements */
9344 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009345 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009346
9347 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009348 {
9349 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9350 /* announced address space */
9351 if (space)
9352 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9353 }
Paul Jakma2815e612006-09-14 02:56:07 +00009354 else if (prn->info)
9355 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9356
Paul Jakma2815e612006-09-14 02:56:07 +00009357 for (ri = rn->info; ri; ri = ri->next)
9358 {
9359 rinum++;
9360 ts->counts[BGP_STATS_RIB]++;
9361
9362 if (ri->attr &&
9363 (CHECK_FLAG (ri->attr->flag,
9364 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9365 ts->counts[BGP_STATS_AGGREGATES]++;
9366
9367 /* as-path stats */
9368 if (ri->attr && ri->attr->aspath)
9369 {
9370 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9371 unsigned int size = aspath_size (ri->attr->aspath);
9372 as_t highest = aspath_highest (ri->attr->aspath);
9373
9374 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9375
9376 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9377 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9378
9379 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9380 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9381
9382 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9383 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9384#if 0
9385 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9386 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9387 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9388 hops);
9389 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9390 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9391 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9392 size);
9393#endif
9394 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9395 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9396 }
9397 }
9398 }
9399 return 0;
9400}
9401
9402static int
9403bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9404{
9405 struct bgp_table_stats ts;
9406 unsigned int i;
9407
9408 if (!bgp->rib[afi][safi])
9409 {
9410 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9411 return CMD_WARNING;
9412 }
9413
9414 memset (&ts, 0, sizeof (ts));
9415 ts.table = bgp->rib[afi][safi];
9416 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9417
9418 vty_out (vty, "BGP %s RIB statistics%s%s",
9419 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9420
9421 for (i = 0; i < BGP_STATS_MAX; i++)
9422 {
9423 if (!table_stats_strs[i])
9424 continue;
9425
9426 switch (i)
9427 {
9428#if 0
9429 case BGP_STATS_ASPATH_AVGHOPS:
9430 case BGP_STATS_ASPATH_AVGSIZE:
9431 case BGP_STATS_AVGPLEN:
9432 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9433 vty_out (vty, "%12.2f",
9434 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9435 break;
9436#endif
9437 case BGP_STATS_ASPATH_TOTHOPS:
9438 case BGP_STATS_ASPATH_TOTSIZE:
9439 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9440 vty_out (vty, "%12.2f",
9441 ts.counts[i] ?
9442 (float)ts.counts[i] /
9443 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9444 : 0);
9445 break;
9446 case BGP_STATS_TOTPLEN:
9447 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9448 vty_out (vty, "%12.2f",
9449 ts.counts[i] ?
9450 (float)ts.counts[i] /
9451 (float)ts.counts[BGP_STATS_PREFIXES]
9452 : 0);
9453 break;
9454 case BGP_STATS_SPACE:
9455 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9456 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9457 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9458 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009459 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009460 vty_out (vty, "%12.2f%s",
9461 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009462 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009463 VTY_NEWLINE);
9464 vty_out (vty, "%30s: ", "/8 equivalent ");
9465 vty_out (vty, "%12.2f%s",
9466 (float)ts.counts[BGP_STATS_SPACE] /
9467 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9468 VTY_NEWLINE);
9469 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9470 break;
9471 vty_out (vty, "%30s: ", "/24 equivalent ");
9472 vty_out (vty, "%12.2f",
9473 (float)ts.counts[BGP_STATS_SPACE] /
9474 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9475 break;
9476 default:
9477 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9478 vty_out (vty, "%12llu", ts.counts[i]);
9479 }
9480
9481 vty_out (vty, "%s", VTY_NEWLINE);
9482 }
9483 return CMD_SUCCESS;
9484}
9485
9486static int
9487bgp_table_stats_vty (struct vty *vty, const char *name,
9488 const char *afi_str, const char *safi_str)
9489{
9490 struct bgp *bgp;
9491 afi_t afi;
9492 safi_t safi;
9493
9494 if (name)
9495 bgp = bgp_lookup_by_name (name);
9496 else
9497 bgp = bgp_get_default ();
9498
9499 if (!bgp)
9500 {
9501 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9502 return CMD_WARNING;
9503 }
9504 if (strncmp (afi_str, "ipv", 3) == 0)
9505 {
9506 if (strncmp (afi_str, "ipv4", 4) == 0)
9507 afi = AFI_IP;
9508 else if (strncmp (afi_str, "ipv6", 4) == 0)
9509 afi = AFI_IP6;
9510 else
9511 {
9512 vty_out (vty, "%% Invalid address family %s%s",
9513 afi_str, VTY_NEWLINE);
9514 return CMD_WARNING;
9515 }
9516 if (strncmp (safi_str, "m", 1) == 0)
9517 safi = SAFI_MULTICAST;
9518 else if (strncmp (safi_str, "u", 1) == 0)
9519 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009520 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9521 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009522 else
9523 {
9524 vty_out (vty, "%% Invalid subsequent address family %s%s",
9525 safi_str, VTY_NEWLINE);
9526 return CMD_WARNING;
9527 }
9528 }
9529 else
9530 {
9531 vty_out (vty, "%% Invalid address family %s%s",
9532 afi_str, VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535
Paul Jakma2815e612006-09-14 02:56:07 +00009536 return bgp_table_stats (vty, bgp, afi, safi);
9537}
9538
9539DEFUN (show_bgp_statistics,
9540 show_bgp_statistics_cmd,
9541 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9542 SHOW_STR
9543 BGP_STR
9544 "Address family\n"
9545 "Address family\n"
9546 "Address Family modifier\n"
9547 "Address Family modifier\n"
9548 "BGP RIB advertisement statistics\n")
9549{
9550 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9551}
9552
9553ALIAS (show_bgp_statistics,
9554 show_bgp_statistics_vpnv4_cmd,
9555 "show bgp (ipv4) (vpnv4) statistics",
9556 SHOW_STR
9557 BGP_STR
9558 "Address family\n"
9559 "Address Family modifier\n"
9560 "BGP RIB advertisement statistics\n")
9561
9562DEFUN (show_bgp_statistics_view,
9563 show_bgp_statistics_view_cmd,
9564 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9565 SHOW_STR
9566 BGP_STR
9567 "BGP view\n"
9568 "Address family\n"
9569 "Address family\n"
9570 "Address Family modifier\n"
9571 "Address Family modifier\n"
9572 "BGP RIB advertisement statistics\n")
9573{
9574 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9575}
9576
9577ALIAS (show_bgp_statistics_view,
9578 show_bgp_statistics_view_vpnv4_cmd,
9579 "show bgp view WORD (ipv4) (vpnv4) statistics",
9580 SHOW_STR
9581 BGP_STR
9582 "BGP view\n"
9583 "Address family\n"
9584 "Address Family modifier\n"
9585 "BGP RIB advertisement statistics\n")
9586
Paul Jakmaff7924f2006-09-04 01:10:36 +00009587enum bgp_pcounts
9588{
9589 PCOUNT_ADJ_IN = 0,
9590 PCOUNT_DAMPED,
9591 PCOUNT_REMOVED,
9592 PCOUNT_HISTORY,
9593 PCOUNT_STALE,
9594 PCOUNT_VALID,
9595 PCOUNT_ALL,
9596 PCOUNT_COUNTED,
9597 PCOUNT_PFCNT, /* the figure we display to users */
9598 PCOUNT_MAX,
9599};
9600
9601static const char *pcount_strs[] =
9602{
9603 [PCOUNT_ADJ_IN] = "Adj-in",
9604 [PCOUNT_DAMPED] = "Damped",
9605 [PCOUNT_REMOVED] = "Removed",
9606 [PCOUNT_HISTORY] = "History",
9607 [PCOUNT_STALE] = "Stale",
9608 [PCOUNT_VALID] = "Valid",
9609 [PCOUNT_ALL] = "All RIB",
9610 [PCOUNT_COUNTED] = "PfxCt counted",
9611 [PCOUNT_PFCNT] = "Useable",
9612 [PCOUNT_MAX] = NULL,
9613};
9614
Paul Jakma2815e612006-09-14 02:56:07 +00009615struct peer_pcounts
9616{
9617 unsigned int count[PCOUNT_MAX];
9618 const struct peer *peer;
9619 const struct bgp_table *table;
9620};
9621
Paul Jakmaff7924f2006-09-04 01:10:36 +00009622static int
Paul Jakma2815e612006-09-14 02:56:07 +00009623bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624{
9625 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009626 struct peer_pcounts *pc = THREAD_ARG (t);
9627 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009628
Paul Jakma2815e612006-09-14 02:56:07 +00009629 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009630 {
9631 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009632 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633
9634 for (ain = rn->adj_in; ain; ain = ain->next)
9635 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009636 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009637
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638 for (ri = rn->info; ri; ri = ri->next)
9639 {
9640 char buf[SU_ADDRSTRLEN];
9641
9642 if (ri->peer != peer)
9643 continue;
9644
Paul Jakma2815e612006-09-14 02:56:07 +00009645 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646
9647 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009648 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009650 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009651 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009652 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009654 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009655 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009656 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009657 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009658 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659
9660 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9661 {
Paul Jakma2815e612006-09-14 02:56:07 +00009662 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009663 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009664 plog_warn (peer->log,
9665 "%s [pcount] %s/%d is counted but flags 0x%x",
9666 peer->host,
9667 inet_ntop(rn->p.family, &rn->p.u.prefix,
9668 buf, SU_ADDRSTRLEN),
9669 rn->p.prefixlen,
9670 ri->flags);
9671 }
9672 else
9673 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009674 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675 plog_warn (peer->log,
9676 "%s [pcount] %s/%d not counted but flags 0x%x",
9677 peer->host,
9678 inet_ntop(rn->p.family, &rn->p.u.prefix,
9679 buf, SU_ADDRSTRLEN),
9680 rn->p.prefixlen,
9681 ri->flags);
9682 }
9683 }
9684 }
Paul Jakma2815e612006-09-14 02:56:07 +00009685 return 0;
9686}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009687
Paul Jakma2815e612006-09-14 02:56:07 +00009688static int
9689bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9690{
9691 struct peer_pcounts pcounts = { .peer = peer };
9692 unsigned int i;
9693
9694 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9695 || !peer->bgp->rib[afi][safi])
9696 {
9697 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9698 return CMD_WARNING;
9699 }
9700
9701 memset (&pcounts, 0, sizeof(pcounts));
9702 pcounts.peer = peer;
9703 pcounts.table = peer->bgp->rib[afi][safi];
9704
9705 /* in-place call via thread subsystem so as to record execution time
9706 * stats for the thread-walk (i.e. ensure this can't be blamed on
9707 * on just vty_read()).
9708 */
9709 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9710
Paul Jakmaff7924f2006-09-04 01:10:36 +00009711 vty_out (vty, "Prefix counts for %s, %s%s",
9712 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9713 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9714 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9715 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9716
9717 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009718 vty_out (vty, "%20s: %-10d%s",
9719 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009720
Paul Jakma2815e612006-09-14 02:56:07 +00009721 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009722 {
9723 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9724 peer->host, VTY_NEWLINE);
9725 vty_out (vty, "Please report this bug, with the above command output%s",
9726 VTY_NEWLINE);
9727 }
9728
9729 return CMD_SUCCESS;
9730}
9731
9732DEFUN (show_ip_bgp_neighbor_prefix_counts,
9733 show_ip_bgp_neighbor_prefix_counts_cmd,
9734 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9735 SHOW_STR
9736 IP_STR
9737 BGP_STR
9738 "Detailed information on TCP and BGP neighbor connections\n"
9739 "Neighbor to display information about\n"
9740 "Neighbor to display information about\n"
9741 "Display detailed prefix count information\n")
9742{
9743 struct peer *peer;
9744
9745 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9746 if (! peer)
9747 return CMD_WARNING;
9748
9749 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9750}
9751
9752DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9753 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9754 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9755 SHOW_STR
9756 BGP_STR
9757 "Address family\n"
9758 "Detailed information on TCP and BGP neighbor connections\n"
9759 "Neighbor to display information about\n"
9760 "Neighbor to display information about\n"
9761 "Display detailed prefix count information\n")
9762{
9763 struct peer *peer;
9764
9765 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9766 if (! peer)
9767 return CMD_WARNING;
9768
9769 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9770}
9771
9772DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9773 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9774 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9775 SHOW_STR
9776 IP_STR
9777 BGP_STR
9778 "Address family\n"
9779 "Address Family modifier\n"
9780 "Address Family modifier\n"
9781 "Detailed information on TCP and BGP neighbor connections\n"
9782 "Neighbor to display information about\n"
9783 "Neighbor to display information about\n"
9784 "Display detailed prefix count information\n")
9785{
9786 struct peer *peer;
9787
9788 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9789 if (! peer)
9790 return CMD_WARNING;
9791
9792 if (strncmp (argv[0], "m", 1) == 0)
9793 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9794
9795 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9796}
9797
9798DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9799 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9800 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9801 SHOW_STR
9802 IP_STR
9803 BGP_STR
9804 "Address family\n"
9805 "Address Family modifier\n"
9806 "Address Family modifier\n"
9807 "Detailed information on TCP and BGP neighbor connections\n"
9808 "Neighbor to display information about\n"
9809 "Neighbor to display information about\n"
9810 "Display detailed prefix count information\n")
9811{
9812 struct peer *peer;
9813
9814 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9815 if (! peer)
9816 return CMD_WARNING;
9817
9818 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9819}
9820
9821
paul94f2b392005-06-28 12:44:16 +00009822static void
paul718e3742002-12-13 20:15:29 +00009823show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9824 int in)
9825{
9826 struct bgp_table *table;
9827 struct bgp_adj_in *ain;
9828 struct bgp_adj_out *adj;
9829 unsigned long output_count;
9830 struct bgp_node *rn;
9831 int header1 = 1;
9832 struct bgp *bgp;
9833 int header2 = 1;
9834
paulbb46e942003-10-24 19:02:03 +00009835 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009836
9837 if (! bgp)
9838 return;
9839
9840 table = bgp->rib[afi][safi];
9841
9842 output_count = 0;
9843
9844 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9845 PEER_STATUS_DEFAULT_ORIGINATE))
9846 {
9847 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 +00009848 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9849 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009850
9851 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9852 VTY_NEWLINE, VTY_NEWLINE);
9853 header1 = 0;
9854 }
9855
9856 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9857 if (in)
9858 {
9859 for (ain = rn->adj_in; ain; ain = ain->next)
9860 if (ain->peer == peer)
9861 {
9862 if (header1)
9863 {
9864 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 +00009865 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9866 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009867 header1 = 0;
9868 }
9869 if (header2)
9870 {
9871 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9872 header2 = 0;
9873 }
9874 if (ain->attr)
9875 {
9876 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9877 output_count++;
9878 }
9879 }
9880 }
9881 else
9882 {
9883 for (adj = rn->adj_out; adj; adj = adj->next)
9884 if (adj->peer == peer)
9885 {
9886 if (header1)
9887 {
9888 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 +00009889 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9890 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009891 header1 = 0;
9892 }
9893 if (header2)
9894 {
9895 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9896 header2 = 0;
9897 }
9898 if (adj->attr)
9899 {
9900 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9901 output_count++;
9902 }
9903 }
9904 }
9905
9906 if (output_count != 0)
9907 vty_out (vty, "%sTotal number of prefixes %ld%s",
9908 VTY_NEWLINE, output_count, VTY_NEWLINE);
9909}
9910
paul94f2b392005-06-28 12:44:16 +00009911static int
paulbb46e942003-10-24 19:02:03 +00009912peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9913{
paul718e3742002-12-13 20:15:29 +00009914 if (! peer || ! peer->afc[afi][safi])
9915 {
9916 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9917 return CMD_WARNING;
9918 }
9919
9920 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9921 {
9922 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9923 VTY_NEWLINE);
9924 return CMD_WARNING;
9925 }
9926
9927 show_adj_route (vty, peer, afi, safi, in);
9928
9929 return CMD_SUCCESS;
9930}
9931
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009932DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9933 show_ip_bgp_view_neighbor_advertised_route_cmd,
9934 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9935 SHOW_STR
9936 IP_STR
9937 BGP_STR
9938 "BGP view\n"
9939 "View name\n"
9940 "Detailed information on TCP and BGP neighbor connections\n"
9941 "Neighbor to display information about\n"
9942 "Neighbor to display information about\n"
9943 "Display the routes advertised to a BGP neighbor\n")
9944{
9945 struct peer *peer;
9946
9947 if (argc == 2)
9948 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9949 else
9950 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9951
9952 if (! peer)
9953 return CMD_WARNING;
9954
9955 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9956}
9957
9958ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009959 show_ip_bgp_neighbor_advertised_route_cmd,
9960 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9961 SHOW_STR
9962 IP_STR
9963 BGP_STR
9964 "Detailed information on TCP and BGP neighbor connections\n"
9965 "Neighbor to display information about\n"
9966 "Neighbor to display information about\n"
9967 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009968
9969DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9970 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9971 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9972 SHOW_STR
9973 IP_STR
9974 BGP_STR
9975 "Address family\n"
9976 "Address Family modifier\n"
9977 "Address Family modifier\n"
9978 "Detailed information on TCP and BGP neighbor connections\n"
9979 "Neighbor to display information about\n"
9980 "Neighbor to display information about\n"
9981 "Display the routes advertised to a BGP neighbor\n")
9982{
paulbb46e942003-10-24 19:02:03 +00009983 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009984
paulbb46e942003-10-24 19:02:03 +00009985 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9986 if (! peer)
9987 return CMD_WARNING;
9988
9989 if (strncmp (argv[0], "m", 1) == 0)
9990 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9991
9992 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009993}
9994
9995#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009996DEFUN (show_bgp_view_neighbor_advertised_route,
9997 show_bgp_view_neighbor_advertised_route_cmd,
9998 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9999 SHOW_STR
10000 BGP_STR
10001 "BGP view\n"
10002 "View name\n"
10003 "Detailed information on TCP and BGP neighbor connections\n"
10004 "Neighbor to display information about\n"
10005 "Neighbor to display information about\n"
10006 "Display the routes advertised to a BGP neighbor\n")
10007{
10008 struct peer *peer;
10009
10010 if (argc == 2)
10011 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10012 else
10013 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10014
10015 if (! peer)
10016 return CMD_WARNING;
10017
10018 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10019}
10020
10021ALIAS (show_bgp_view_neighbor_advertised_route,
10022 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10023 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10024 SHOW_STR
10025 BGP_STR
10026 "BGP view\n"
10027 "View name\n"
10028 "Address family\n"
10029 "Detailed information on TCP and BGP neighbor connections\n"
10030 "Neighbor to display information about\n"
10031 "Neighbor to display information about\n"
10032 "Display the routes advertised to a BGP neighbor\n")
10033
10034DEFUN (show_bgp_view_neighbor_received_routes,
10035 show_bgp_view_neighbor_received_routes_cmd,
10036 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10037 SHOW_STR
10038 BGP_STR
10039 "BGP view\n"
10040 "View name\n"
10041 "Detailed information on TCP and BGP neighbor connections\n"
10042 "Neighbor to display information about\n"
10043 "Neighbor to display information about\n"
10044 "Display the received routes from neighbor\n")
10045{
10046 struct peer *peer;
10047
10048 if (argc == 2)
10049 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10050 else
10051 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10052
10053 if (! peer)
10054 return CMD_WARNING;
10055
10056 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10057}
10058
10059ALIAS (show_bgp_view_neighbor_received_routes,
10060 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10061 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10062 SHOW_STR
10063 BGP_STR
10064 "BGP view\n"
10065 "View name\n"
10066 "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 received routes from neighbor\n")
10071
10072ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010073 show_bgp_neighbor_advertised_route_cmd,
10074 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10075 SHOW_STR
10076 BGP_STR
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010081
10082ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010083 show_bgp_ipv6_neighbor_advertised_route_cmd,
10084 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10085 SHOW_STR
10086 BGP_STR
10087 "Address family\n"
10088 "Detailed information on TCP and BGP neighbor connections\n"
10089 "Neighbor to display information about\n"
10090 "Neighbor to display information about\n"
10091 "Display the routes advertised to a BGP neighbor\n")
10092
10093/* old command */
paulbb46e942003-10-24 19:02:03 +000010094ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010095 ipv6_bgp_neighbor_advertised_route_cmd,
10096 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10097 SHOW_STR
10098 IPV6_STR
10099 BGP_STR
10100 "Detailed information on TCP and BGP neighbor connections\n"
10101 "Neighbor to display information about\n"
10102 "Neighbor to display information about\n"
10103 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010104
paul718e3742002-12-13 20:15:29 +000010105/* old command */
10106DEFUN (ipv6_mbgp_neighbor_advertised_route,
10107 ipv6_mbgp_neighbor_advertised_route_cmd,
10108 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10109 SHOW_STR
10110 IPV6_STR
10111 MBGP_STR
10112 "Detailed information on TCP and BGP neighbor connections\n"
10113 "Neighbor to display information about\n"
10114 "Neighbor to display information about\n"
10115 "Display the routes advertised to a BGP neighbor\n")
10116{
paulbb46e942003-10-24 19:02:03 +000010117 struct peer *peer;
10118
10119 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10120 if (! peer)
10121 return CMD_WARNING;
10122
10123 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010124}
10125#endif /* HAVE_IPV6 */
10126
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010127DEFUN (show_ip_bgp_view_neighbor_received_routes,
10128 show_ip_bgp_view_neighbor_received_routes_cmd,
10129 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10130 SHOW_STR
10131 IP_STR
10132 BGP_STR
10133 "BGP view\n"
10134 "View name\n"
10135 "Detailed information on TCP and BGP neighbor connections\n"
10136 "Neighbor to display information about\n"
10137 "Neighbor to display information about\n"
10138 "Display the received routes from neighbor\n")
10139{
10140 struct peer *peer;
10141
10142 if (argc == 2)
10143 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10144 else
10145 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10146
10147 if (! peer)
10148 return CMD_WARNING;
10149
10150 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10151}
10152
10153ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010154 show_ip_bgp_neighbor_received_routes_cmd,
10155 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10156 SHOW_STR
10157 IP_STR
10158 BGP_STR
10159 "Detailed information on TCP and BGP neighbor connections\n"
10160 "Neighbor to display information about\n"
10161 "Neighbor to display information about\n"
10162 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010163
10164DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10165 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10166 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10167 SHOW_STR
10168 IP_STR
10169 BGP_STR
10170 "Address family\n"
10171 "Address Family modifier\n"
10172 "Address Family modifier\n"
10173 "Detailed information on TCP and BGP neighbor connections\n"
10174 "Neighbor to display information about\n"
10175 "Neighbor to display information about\n"
10176 "Display the received routes from neighbor\n")
10177{
paulbb46e942003-10-24 19:02:03 +000010178 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010179
paulbb46e942003-10-24 19:02:03 +000010180 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10181 if (! peer)
10182 return CMD_WARNING;
10183
10184 if (strncmp (argv[0], "m", 1) == 0)
10185 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10186
10187 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010188}
10189
Michael Lambert95cbbd22010-07-23 14:43:04 -040010190DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10191 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10192#ifdef HAVE_IPV6
10193 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10194#else
10195 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10196#endif
10197 SHOW_STR
10198 BGP_STR
10199 "BGP view\n"
10200 "BGP view name\n"
10201 "Address family\n"
10202#ifdef HAVE_IPV6
10203 "Address family\n"
10204#endif
10205 "Address family modifier\n"
10206 "Address family modifier\n"
10207 "Detailed information on TCP and BGP neighbor connections\n"
10208 "Neighbor to display information about\n"
10209 "Neighbor to display information about\n"
10210 "Display the advertised routes to neighbor\n"
10211 "Display the received routes from neighbor\n")
10212{
10213 int afi;
10214 int safi;
10215 int in;
10216 struct peer *peer;
10217
10218#ifdef HAVE_IPV6
10219 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10220#else
10221 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10222#endif
10223
10224 if (! peer)
10225 return CMD_WARNING;
10226
10227#ifdef HAVE_IPV6
10228 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10229 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10230 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10231#else
10232 afi = AFI_IP;
10233 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10234 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10235#endif
10236
10237 return peer_adj_routes (vty, peer, afi, safi, in);
10238}
10239
paul718e3742002-12-13 20:15:29 +000010240DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10241 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10242 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10243 SHOW_STR
10244 IP_STR
10245 BGP_STR
10246 "Detailed information on TCP and BGP neighbor connections\n"
10247 "Neighbor to display information about\n"
10248 "Neighbor to display information about\n"
10249 "Display information received from a BGP neighbor\n"
10250 "Display the prefixlist filter\n")
10251{
10252 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010253 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010254 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010255 int count, ret;
paul718e3742002-12-13 20:15:29 +000010256
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010257 ret = str2sockunion (argv[0], &su);
10258 if (ret < 0)
10259 {
10260 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10261 return CMD_WARNING;
10262 }
paul718e3742002-12-13 20:15:29 +000010263
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010264 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010265 if (! peer)
10266 return CMD_WARNING;
10267
10268 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10269 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10270 if (count)
10271 {
10272 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10273 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10274 }
10275
10276 return CMD_SUCCESS;
10277}
10278
10279DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10280 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10281 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10282 SHOW_STR
10283 IP_STR
10284 BGP_STR
10285 "Address family\n"
10286 "Address Family modifier\n"
10287 "Address Family modifier\n"
10288 "Detailed information on TCP and BGP neighbor connections\n"
10289 "Neighbor to display information about\n"
10290 "Neighbor to display information about\n"
10291 "Display information received from a BGP neighbor\n"
10292 "Display the prefixlist filter\n")
10293{
10294 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010295 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010296 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010297 int count, ret;
paul718e3742002-12-13 20:15:29 +000010298
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010299 ret = str2sockunion (argv[1], &su);
10300 if (ret < 0)
10301 {
10302 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10303 return CMD_WARNING;
10304 }
paul718e3742002-12-13 20:15:29 +000010305
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010306 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010307 if (! peer)
10308 return CMD_WARNING;
10309
10310 if (strncmp (argv[0], "m", 1) == 0)
10311 {
10312 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10313 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10314 if (count)
10315 {
10316 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10317 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10318 }
10319 }
10320 else
10321 {
10322 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10323 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10324 if (count)
10325 {
10326 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10327 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10328 }
10329 }
10330
10331 return CMD_SUCCESS;
10332}
10333
10334
10335#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010336ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010337 show_bgp_neighbor_received_routes_cmd,
10338 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
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 the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010345
paulbb46e942003-10-24 19:02:03 +000010346ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010347 show_bgp_ipv6_neighbor_received_routes_cmd,
10348 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10349 SHOW_STR
10350 BGP_STR
10351 "Address family\n"
10352 "Detailed information on TCP and BGP neighbor connections\n"
10353 "Neighbor to display information about\n"
10354 "Neighbor to display information about\n"
10355 "Display the received routes from neighbor\n")
10356
10357DEFUN (show_bgp_neighbor_received_prefix_filter,
10358 show_bgp_neighbor_received_prefix_filter_cmd,
10359 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10360 SHOW_STR
10361 BGP_STR
10362 "Detailed information on TCP and BGP neighbor connections\n"
10363 "Neighbor to display information about\n"
10364 "Neighbor to display information about\n"
10365 "Display information received from a BGP neighbor\n"
10366 "Display the prefixlist filter\n")
10367{
10368 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010369 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010370 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010371 int count, ret;
paul718e3742002-12-13 20:15:29 +000010372
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010373 ret = str2sockunion (argv[0], &su);
10374 if (ret < 0)
10375 {
10376 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10377 return CMD_WARNING;
10378 }
paul718e3742002-12-13 20:15:29 +000010379
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010380 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010381 if (! peer)
10382 return CMD_WARNING;
10383
10384 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10385 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10386 if (count)
10387 {
10388 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10389 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10390 }
10391
10392 return CMD_SUCCESS;
10393}
10394
10395ALIAS (show_bgp_neighbor_received_prefix_filter,
10396 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10397 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10398 SHOW_STR
10399 BGP_STR
10400 "Address family\n"
10401 "Detailed information on TCP and BGP neighbor connections\n"
10402 "Neighbor to display information about\n"
10403 "Neighbor to display information about\n"
10404 "Display information received from a BGP neighbor\n"
10405 "Display the prefixlist filter\n")
10406
10407/* old command */
paulbb46e942003-10-24 19:02:03 +000010408ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010409 ipv6_bgp_neighbor_received_routes_cmd,
10410 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10411 SHOW_STR
10412 IPV6_STR
10413 BGP_STR
10414 "Detailed information on TCP and BGP neighbor connections\n"
10415 "Neighbor to display information about\n"
10416 "Neighbor to display information about\n"
10417 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010418
10419/* old command */
10420DEFUN (ipv6_mbgp_neighbor_received_routes,
10421 ipv6_mbgp_neighbor_received_routes_cmd,
10422 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10423 SHOW_STR
10424 IPV6_STR
10425 MBGP_STR
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 the received routes from neighbor\n")
10430{
paulbb46e942003-10-24 19:02:03 +000010431 struct peer *peer;
10432
10433 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10434 if (! peer)
10435 return CMD_WARNING;
10436
10437 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010438}
paulbb46e942003-10-24 19:02:03 +000010439
10440DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10441 show_bgp_view_neighbor_received_prefix_filter_cmd,
10442 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10443 SHOW_STR
10444 BGP_STR
10445 "BGP view\n"
10446 "View name\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display information received from a BGP neighbor\n"
10451 "Display the prefixlist filter\n")
10452{
10453 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010454 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010455 struct peer *peer;
10456 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010457 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010458
10459 /* BGP structure lookup. */
10460 bgp = bgp_lookup_by_name (argv[0]);
10461 if (bgp == NULL)
10462 {
10463 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10464 return CMD_WARNING;
10465 }
10466
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010467 ret = str2sockunion (argv[1], &su);
10468 if (ret < 0)
10469 {
10470 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10471 return CMD_WARNING;
10472 }
paulbb46e942003-10-24 19:02:03 +000010473
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010474 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010475 if (! peer)
10476 return CMD_WARNING;
10477
10478 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10479 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10480 if (count)
10481 {
10482 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10483 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10484 }
10485
10486 return CMD_SUCCESS;
10487}
10488
10489ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10490 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10491 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10492 SHOW_STR
10493 BGP_STR
10494 "BGP view\n"
10495 "View name\n"
10496 "Address family\n"
10497 "Detailed information on TCP and BGP neighbor connections\n"
10498 "Neighbor to display information about\n"
10499 "Neighbor to display information about\n"
10500 "Display information received from a BGP neighbor\n"
10501 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010502#endif /* HAVE_IPV6 */
10503
paul94f2b392005-06-28 12:44:16 +000010504static int
paulbb46e942003-10-24 19:02:03 +000010505bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010506 safi_t safi, enum bgp_show_type type)
10507{
paul718e3742002-12-13 20:15:29 +000010508 if (! peer || ! peer->afc[afi][safi])
10509 {
10510 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010511 return CMD_WARNING;
10512 }
10513
ajs5a646652004-11-05 01:25:55 +000010514 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010515}
10516
10517DEFUN (show_ip_bgp_neighbor_routes,
10518 show_ip_bgp_neighbor_routes_cmd,
10519 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
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 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_neighbor);
10536}
10537
10538DEFUN (show_ip_bgp_neighbor_flap,
10539 show_ip_bgp_neighbor_flap_cmd,
10540 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
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 flap statistics of the routes learned 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_flap_neighbor);
10557}
10558
10559DEFUN (show_ip_bgp_neighbor_damp,
10560 show_ip_bgp_neighbor_damp_cmd,
10561 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10562 SHOW_STR
10563 IP_STR
10564 BGP_STR
10565 "Detailed information on TCP and BGP neighbor connections\n"
10566 "Neighbor to display information about\n"
10567 "Neighbor to display information about\n"
10568 "Display the dampened routes received from neighbor\n")
10569{
paulbb46e942003-10-24 19:02:03 +000010570 struct peer *peer;
10571
10572 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10573 if (! peer)
10574 return CMD_WARNING;
10575
10576 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010577 bgp_show_type_damp_neighbor);
10578}
10579
10580DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10581 show_ip_bgp_ipv4_neighbor_routes_cmd,
10582 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10583 SHOW_STR
10584 IP_STR
10585 BGP_STR
10586 "Address family\n"
10587 "Address Family modifier\n"
10588 "Address Family modifier\n"
10589 "Detailed information on TCP and BGP neighbor connections\n"
10590 "Neighbor to display information about\n"
10591 "Neighbor to display information about\n"
10592 "Display routes learned from neighbor\n")
10593{
paulbb46e942003-10-24 19:02:03 +000010594 struct peer *peer;
10595
10596 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10597 if (! peer)
10598 return CMD_WARNING;
10599
paul718e3742002-12-13 20:15:29 +000010600 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010601 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010602 bgp_show_type_neighbor);
10603
paulbb46e942003-10-24 19:02:03 +000010604 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010605 bgp_show_type_neighbor);
10606}
paulbb46e942003-10-24 19:02:03 +000010607
paulfee0f4c2004-09-13 05:12:46 +000010608DEFUN (show_ip_bgp_view_rsclient,
10609 show_ip_bgp_view_rsclient_cmd,
10610 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10611 SHOW_STR
10612 IP_STR
10613 BGP_STR
10614 "BGP view\n"
10615 "BGP view name\n"
10616 "Information about Route Server Client\n"
10617 NEIGHBOR_ADDR_STR)
10618{
10619 struct bgp_table *table;
10620 struct peer *peer;
10621
10622 if (argc == 2)
10623 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10624 else
10625 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10626
10627 if (! peer)
10628 return CMD_WARNING;
10629
10630 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10631 {
10632 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10633 VTY_NEWLINE);
10634 return CMD_WARNING;
10635 }
10636
10637 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10638 PEER_FLAG_RSERVER_CLIENT))
10639 {
10640 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10641 VTY_NEWLINE);
10642 return CMD_WARNING;
10643 }
10644
10645 table = peer->rib[AFI_IP][SAFI_UNICAST];
10646
ajs5a646652004-11-05 01:25:55 +000010647 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010648}
10649
10650ALIAS (show_ip_bgp_view_rsclient,
10651 show_ip_bgp_rsclient_cmd,
10652 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10653 SHOW_STR
10654 IP_STR
10655 BGP_STR
10656 "Information about Route Server Client\n"
10657 NEIGHBOR_ADDR_STR)
10658
Michael Lambert95cbbd22010-07-23 14:43:04 -040010659DEFUN (show_bgp_view_ipv4_safi_rsclient,
10660 show_bgp_view_ipv4_safi_rsclient_cmd,
10661 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10662 SHOW_STR
10663 BGP_STR
10664 "BGP view\n"
10665 "BGP view name\n"
10666 "Address family\n"
10667 "Address Family modifier\n"
10668 "Address Family modifier\n"
10669 "Information about Route Server Client\n"
10670 NEIGHBOR_ADDR_STR)
10671{
10672 struct bgp_table *table;
10673 struct peer *peer;
10674 safi_t safi;
10675
10676 if (argc == 3) {
10677 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10678 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10679 } else {
10680 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10681 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10682 }
10683
10684 if (! peer)
10685 return CMD_WARNING;
10686
10687 if (! peer->afc[AFI_IP][safi])
10688 {
10689 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10690 VTY_NEWLINE);
10691 return CMD_WARNING;
10692 }
10693
10694 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10695 PEER_FLAG_RSERVER_CLIENT))
10696 {
10697 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10698 VTY_NEWLINE);
10699 return CMD_WARNING;
10700 }
10701
10702 table = peer->rib[AFI_IP][safi];
10703
10704 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10705}
10706
10707ALIAS (show_bgp_view_ipv4_safi_rsclient,
10708 show_bgp_ipv4_safi_rsclient_cmd,
10709 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10710 SHOW_STR
10711 BGP_STR
10712 "Address family\n"
10713 "Address Family modifier\n"
10714 "Address Family modifier\n"
10715 "Information about Route Server Client\n"
10716 NEIGHBOR_ADDR_STR)
10717
paulfee0f4c2004-09-13 05:12:46 +000010718DEFUN (show_ip_bgp_view_rsclient_route,
10719 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010720 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010721 SHOW_STR
10722 IP_STR
10723 BGP_STR
10724 "BGP view\n"
10725 "BGP view name\n"
10726 "Information about Route Server Client\n"
10727 NEIGHBOR_ADDR_STR
10728 "Network in the BGP routing table to display\n")
10729{
10730 struct bgp *bgp;
10731 struct peer *peer;
10732
10733 /* BGP structure lookup. */
10734 if (argc == 3)
10735 {
10736 bgp = bgp_lookup_by_name (argv[0]);
10737 if (bgp == NULL)
10738 {
10739 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10740 return CMD_WARNING;
10741 }
10742 }
10743 else
10744 {
10745 bgp = bgp_get_default ();
10746 if (bgp == NULL)
10747 {
10748 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10749 return CMD_WARNING;
10750 }
10751 }
10752
10753 if (argc == 3)
10754 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10755 else
10756 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10757
10758 if (! peer)
10759 return CMD_WARNING;
10760
10761 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10762 {
10763 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10764 VTY_NEWLINE);
10765 return CMD_WARNING;
10766}
10767
10768 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10769 PEER_FLAG_RSERVER_CLIENT))
10770 {
10771 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10772 VTY_NEWLINE);
10773 return CMD_WARNING;
10774 }
10775
10776 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10777 (argc == 3) ? argv[2] : argv[1],
10778 AFI_IP, SAFI_UNICAST, NULL, 0);
10779}
10780
10781ALIAS (show_ip_bgp_view_rsclient_route,
10782 show_ip_bgp_rsclient_route_cmd,
10783 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10784 SHOW_STR
10785 IP_STR
10786 BGP_STR
10787 "Information about Route Server Client\n"
10788 NEIGHBOR_ADDR_STR
10789 "Network in the BGP routing table to display\n")
10790
Michael Lambert95cbbd22010-07-23 14:43:04 -040010791DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10792 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10793 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10794 SHOW_STR
10795 BGP_STR
10796 "BGP view\n"
10797 "BGP view name\n"
10798 "Address family\n"
10799 "Address Family modifier\n"
10800 "Address Family modifier\n"
10801 "Information about Route Server Client\n"
10802 NEIGHBOR_ADDR_STR
10803 "Network in the BGP routing table to display\n")
10804{
10805 struct bgp *bgp;
10806 struct peer *peer;
10807 safi_t safi;
10808
10809 /* BGP structure lookup. */
10810 if (argc == 4)
10811 {
10812 bgp = bgp_lookup_by_name (argv[0]);
10813 if (bgp == NULL)
10814 {
10815 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10816 return CMD_WARNING;
10817 }
10818 }
10819 else
10820 {
10821 bgp = bgp_get_default ();
10822 if (bgp == NULL)
10823 {
10824 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10825 return CMD_WARNING;
10826 }
10827 }
10828
10829 if (argc == 4) {
10830 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10831 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10832 } else {
10833 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10834 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10835 }
10836
10837 if (! peer)
10838 return CMD_WARNING;
10839
10840 if (! peer->afc[AFI_IP][safi])
10841 {
10842 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10843 VTY_NEWLINE);
10844 return CMD_WARNING;
10845}
10846
10847 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10848 PEER_FLAG_RSERVER_CLIENT))
10849 {
10850 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10851 VTY_NEWLINE);
10852 return CMD_WARNING;
10853 }
10854
10855 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10856 (argc == 4) ? argv[3] : argv[2],
10857 AFI_IP, safi, NULL, 0);
10858}
10859
10860ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10861 show_bgp_ipv4_safi_rsclient_route_cmd,
10862 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10863 SHOW_STR
10864 BGP_STR
10865 "Address family\n"
10866 "Address Family modifier\n"
10867 "Address Family modifier\n"
10868 "Information about Route Server Client\n"
10869 NEIGHBOR_ADDR_STR
10870 "Network in the BGP routing table to display\n")
10871
paulfee0f4c2004-09-13 05:12:46 +000010872DEFUN (show_ip_bgp_view_rsclient_prefix,
10873 show_ip_bgp_view_rsclient_prefix_cmd,
10874 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10875 SHOW_STR
10876 IP_STR
10877 BGP_STR
10878 "BGP view\n"
10879 "BGP view name\n"
10880 "Information about Route Server Client\n"
10881 NEIGHBOR_ADDR_STR
10882 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10883{
10884 struct bgp *bgp;
10885 struct peer *peer;
10886
10887 /* BGP structure lookup. */
10888 if (argc == 3)
10889 {
10890 bgp = bgp_lookup_by_name (argv[0]);
10891 if (bgp == NULL)
10892 {
10893 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10894 return CMD_WARNING;
10895 }
10896 }
10897 else
10898 {
10899 bgp = bgp_get_default ();
10900 if (bgp == NULL)
10901 {
10902 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10903 return CMD_WARNING;
10904 }
10905 }
10906
10907 if (argc == 3)
10908 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10909 else
10910 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10911
10912 if (! peer)
10913 return CMD_WARNING;
10914
10915 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10916 {
10917 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10918 VTY_NEWLINE);
10919 return CMD_WARNING;
10920}
10921
10922 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10923 PEER_FLAG_RSERVER_CLIENT))
10924{
10925 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10926 VTY_NEWLINE);
10927 return CMD_WARNING;
10928 }
10929
10930 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10931 (argc == 3) ? argv[2] : argv[1],
10932 AFI_IP, SAFI_UNICAST, NULL, 1);
10933}
10934
10935ALIAS (show_ip_bgp_view_rsclient_prefix,
10936 show_ip_bgp_rsclient_prefix_cmd,
10937 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10938 SHOW_STR
10939 IP_STR
10940 BGP_STR
10941 "Information about Route Server Client\n"
10942 NEIGHBOR_ADDR_STR
10943 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10944
Michael Lambert95cbbd22010-07-23 14:43:04 -040010945DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10946 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10947 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10948 SHOW_STR
10949 BGP_STR
10950 "BGP view\n"
10951 "BGP view name\n"
10952 "Address family\n"
10953 "Address Family modifier\n"
10954 "Address Family modifier\n"
10955 "Information about Route Server Client\n"
10956 NEIGHBOR_ADDR_STR
10957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10958{
10959 struct bgp *bgp;
10960 struct peer *peer;
10961 safi_t safi;
10962
10963 /* BGP structure lookup. */
10964 if (argc == 4)
10965 {
10966 bgp = bgp_lookup_by_name (argv[0]);
10967 if (bgp == NULL)
10968 {
10969 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10970 return CMD_WARNING;
10971 }
10972 }
10973 else
10974 {
10975 bgp = bgp_get_default ();
10976 if (bgp == NULL)
10977 {
10978 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10979 return CMD_WARNING;
10980 }
10981 }
10982
10983 if (argc == 4) {
10984 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10985 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10986 } else {
10987 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10988 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10989 }
10990
10991 if (! peer)
10992 return CMD_WARNING;
10993
10994 if (! peer->afc[AFI_IP][safi])
10995 {
10996 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10997 VTY_NEWLINE);
10998 return CMD_WARNING;
10999}
11000
11001 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11002 PEER_FLAG_RSERVER_CLIENT))
11003{
11004 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11005 VTY_NEWLINE);
11006 return CMD_WARNING;
11007 }
11008
11009 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11010 (argc == 4) ? argv[3] : argv[2],
11011 AFI_IP, safi, NULL, 1);
11012}
11013
11014ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11015 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11016 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11017 SHOW_STR
11018 BGP_STR
11019 "Address family\n"
11020 "Address Family modifier\n"
11021 "Address Family modifier\n"
11022 "Information about Route Server Client\n"
11023 NEIGHBOR_ADDR_STR
11024 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011025
paul718e3742002-12-13 20:15:29 +000011026#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011027DEFUN (show_bgp_view_neighbor_routes,
11028 show_bgp_view_neighbor_routes_cmd,
11029 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11030 SHOW_STR
11031 BGP_STR
11032 "BGP view\n"
11033 "BGP view name\n"
11034 "Detailed information on TCP and BGP neighbor connections\n"
11035 "Neighbor to display information about\n"
11036 "Neighbor to display information about\n"
11037 "Display routes learned from neighbor\n")
11038{
11039 struct peer *peer;
11040
11041 if (argc == 2)
11042 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11043 else
11044 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11045
11046 if (! peer)
11047 return CMD_WARNING;
11048
11049 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11050 bgp_show_type_neighbor);
11051}
11052
11053ALIAS (show_bgp_view_neighbor_routes,
11054 show_bgp_view_ipv6_neighbor_routes_cmd,
11055 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11056 SHOW_STR
11057 BGP_STR
11058 "BGP view\n"
11059 "BGP view name\n"
11060 "Address family\n"
11061 "Detailed information on TCP and BGP neighbor connections\n"
11062 "Neighbor to display information about\n"
11063 "Neighbor to display information about\n"
11064 "Display routes learned from neighbor\n")
11065
11066DEFUN (show_bgp_view_neighbor_damp,
11067 show_bgp_view_neighbor_damp_cmd,
11068 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11069 SHOW_STR
11070 BGP_STR
11071 "BGP view\n"
11072 "BGP view name\n"
11073 "Detailed information on TCP and BGP neighbor connections\n"
11074 "Neighbor to display information about\n"
11075 "Neighbor to display information about\n"
11076 "Display the dampened routes received from neighbor\n")
11077{
11078 struct peer *peer;
11079
11080 if (argc == 2)
11081 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11082 else
11083 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11084
11085 if (! peer)
11086 return CMD_WARNING;
11087
11088 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11089 bgp_show_type_damp_neighbor);
11090}
11091
11092ALIAS (show_bgp_view_neighbor_damp,
11093 show_bgp_view_ipv6_neighbor_damp_cmd,
11094 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11095 SHOW_STR
11096 BGP_STR
11097 "BGP view\n"
11098 "BGP view name\n"
11099 "Address family\n"
11100 "Detailed information on TCP and BGP neighbor connections\n"
11101 "Neighbor to display information about\n"
11102 "Neighbor to display information about\n"
11103 "Display the dampened routes received from neighbor\n")
11104
11105DEFUN (show_bgp_view_neighbor_flap,
11106 show_bgp_view_neighbor_flap_cmd,
11107 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11108 SHOW_STR
11109 BGP_STR
11110 "BGP view\n"
11111 "BGP view name\n"
11112 "Detailed information on TCP and BGP neighbor connections\n"
11113 "Neighbor to display information about\n"
11114 "Neighbor to display information about\n"
11115 "Display flap statistics of the routes learned from neighbor\n")
11116{
11117 struct peer *peer;
11118
11119 if (argc == 2)
11120 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11121 else
11122 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11123
11124 if (! peer)
11125 return CMD_WARNING;
11126
11127 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11128 bgp_show_type_flap_neighbor);
11129}
11130
11131ALIAS (show_bgp_view_neighbor_flap,
11132 show_bgp_view_ipv6_neighbor_flap_cmd,
11133 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11134 SHOW_STR
11135 BGP_STR
11136 "BGP view\n"
11137 "BGP view name\n"
11138 "Address family\n"
11139 "Detailed information on TCP and BGP neighbor connections\n"
11140 "Neighbor to display information about\n"
11141 "Neighbor to display information about\n"
11142 "Display flap statistics of the routes learned from neighbor\n")
11143
11144ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011145 show_bgp_neighbor_routes_cmd,
11146 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11147 SHOW_STR
11148 BGP_STR
11149 "Detailed information on TCP and BGP neighbor connections\n"
11150 "Neighbor to display information about\n"
11151 "Neighbor to display information about\n"
11152 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011153
paulbb46e942003-10-24 19:02:03 +000011154
11155ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011156 show_bgp_ipv6_neighbor_routes_cmd,
11157 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11158 SHOW_STR
11159 BGP_STR
11160 "Address family\n"
11161 "Detailed information on TCP and BGP neighbor connections\n"
11162 "Neighbor to display information about\n"
11163 "Neighbor to display information about\n"
11164 "Display routes learned from neighbor\n")
11165
11166/* old command */
paulbb46e942003-10-24 19:02:03 +000011167ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011168 ipv6_bgp_neighbor_routes_cmd,
11169 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11170 SHOW_STR
11171 IPV6_STR
11172 BGP_STR
11173 "Detailed information on TCP and BGP neighbor connections\n"
11174 "Neighbor to display information about\n"
11175 "Neighbor to display information about\n"
11176 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011177
11178/* old command */
11179DEFUN (ipv6_mbgp_neighbor_routes,
11180 ipv6_mbgp_neighbor_routes_cmd,
11181 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11182 SHOW_STR
11183 IPV6_STR
11184 MBGP_STR
11185 "Detailed information on TCP and BGP neighbor connections\n"
11186 "Neighbor to display information about\n"
11187 "Neighbor to display information about\n"
11188 "Display routes learned from neighbor\n")
11189{
paulbb46e942003-10-24 19:02:03 +000011190 struct peer *peer;
11191
11192 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11193 if (! peer)
11194 return CMD_WARNING;
11195
11196 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011197 bgp_show_type_neighbor);
11198}
paulbb46e942003-10-24 19:02:03 +000011199
11200ALIAS (show_bgp_view_neighbor_flap,
11201 show_bgp_neighbor_flap_cmd,
11202 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
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 flap statistics of the routes learned from neighbor\n")
11209
11210ALIAS (show_bgp_view_neighbor_flap,
11211 show_bgp_ipv6_neighbor_flap_cmd,
11212 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
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"
11219 "Display flap statistics of the routes learned from neighbor\n")
11220
11221ALIAS (show_bgp_view_neighbor_damp,
11222 show_bgp_neighbor_damp_cmd,
11223 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11224 SHOW_STR
11225 BGP_STR
11226 "Detailed information on TCP and BGP neighbor connections\n"
11227 "Neighbor to display information about\n"
11228 "Neighbor to display information about\n"
11229 "Display the dampened routes received from neighbor\n")
11230
11231ALIAS (show_bgp_view_neighbor_damp,
11232 show_bgp_ipv6_neighbor_damp_cmd,
11233 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11234 SHOW_STR
11235 BGP_STR
11236 "Address family\n"
11237 "Detailed information on TCP and BGP neighbor connections\n"
11238 "Neighbor to display information about\n"
11239 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011240 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011241
11242DEFUN (show_bgp_view_rsclient,
11243 show_bgp_view_rsclient_cmd,
11244 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11245 SHOW_STR
11246 BGP_STR
11247 "BGP view\n"
11248 "BGP view name\n"
11249 "Information about Route Server Client\n"
11250 NEIGHBOR_ADDR_STR)
11251{
11252 struct bgp_table *table;
11253 struct peer *peer;
11254
11255 if (argc == 2)
11256 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11257 else
11258 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11259
11260 if (! peer)
11261 return CMD_WARNING;
11262
11263 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11264 {
11265 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11266 VTY_NEWLINE);
11267 return CMD_WARNING;
11268 }
11269
11270 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11271 PEER_FLAG_RSERVER_CLIENT))
11272 {
11273 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11274 VTY_NEWLINE);
11275 return CMD_WARNING;
11276 }
11277
11278 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11279
ajs5a646652004-11-05 01:25:55 +000011280 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011281}
11282
11283ALIAS (show_bgp_view_rsclient,
11284 show_bgp_rsclient_cmd,
11285 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11286 SHOW_STR
11287 BGP_STR
11288 "Information about Route Server Client\n"
11289 NEIGHBOR_ADDR_STR)
11290
Michael Lambert95cbbd22010-07-23 14:43:04 -040011291DEFUN (show_bgp_view_ipv6_safi_rsclient,
11292 show_bgp_view_ipv6_safi_rsclient_cmd,
11293 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11294 SHOW_STR
11295 BGP_STR
11296 "BGP view\n"
11297 "BGP view name\n"
11298 "Address family\n"
11299 "Address Family modifier\n"
11300 "Address Family modifier\n"
11301 "Information about Route Server Client\n"
11302 NEIGHBOR_ADDR_STR)
11303{
11304 struct bgp_table *table;
11305 struct peer *peer;
11306 safi_t safi;
11307
11308 if (argc == 3) {
11309 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11310 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11311 } else {
11312 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11313 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11314 }
11315
11316 if (! peer)
11317 return CMD_WARNING;
11318
11319 if (! peer->afc[AFI_IP6][safi])
11320 {
11321 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11322 VTY_NEWLINE);
11323 return CMD_WARNING;
11324 }
11325
11326 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11327 PEER_FLAG_RSERVER_CLIENT))
11328 {
11329 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11330 VTY_NEWLINE);
11331 return CMD_WARNING;
11332 }
11333
11334 table = peer->rib[AFI_IP6][safi];
11335
11336 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11337}
11338
11339ALIAS (show_bgp_view_ipv6_safi_rsclient,
11340 show_bgp_ipv6_safi_rsclient_cmd,
11341 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11342 SHOW_STR
11343 BGP_STR
11344 "Address family\n"
11345 "Address Family modifier\n"
11346 "Address Family modifier\n"
11347 "Information about Route Server Client\n"
11348 NEIGHBOR_ADDR_STR)
11349
paulfee0f4c2004-09-13 05:12:46 +000011350DEFUN (show_bgp_view_rsclient_route,
11351 show_bgp_view_rsclient_route_cmd,
11352 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11353 SHOW_STR
11354 BGP_STR
11355 "BGP view\n"
11356 "BGP view name\n"
11357 "Information about Route Server Client\n"
11358 NEIGHBOR_ADDR_STR
11359 "Network in the BGP routing table to display\n")
11360{
11361 struct bgp *bgp;
11362 struct peer *peer;
11363
11364 /* BGP structure lookup. */
11365 if (argc == 3)
11366 {
11367 bgp = bgp_lookup_by_name (argv[0]);
11368 if (bgp == NULL)
11369 {
11370 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11371 return CMD_WARNING;
11372 }
11373 }
11374 else
11375 {
11376 bgp = bgp_get_default ();
11377 if (bgp == NULL)
11378 {
11379 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11380 return CMD_WARNING;
11381 }
11382 }
11383
11384 if (argc == 3)
11385 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11386 else
11387 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11388
11389 if (! peer)
11390 return CMD_WARNING;
11391
11392 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11393 {
11394 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11395 VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11400 PEER_FLAG_RSERVER_CLIENT))
11401 {
11402 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11403 VTY_NEWLINE);
11404 return CMD_WARNING;
11405 }
11406
11407 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11408 (argc == 3) ? argv[2] : argv[1],
11409 AFI_IP6, SAFI_UNICAST, NULL, 0);
11410}
11411
11412ALIAS (show_bgp_view_rsclient_route,
11413 show_bgp_rsclient_route_cmd,
11414 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11415 SHOW_STR
11416 BGP_STR
11417 "Information about Route Server Client\n"
11418 NEIGHBOR_ADDR_STR
11419 "Network in the BGP routing table to display\n")
11420
Michael Lambert95cbbd22010-07-23 14:43:04 -040011421DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11422 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11423 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11424 SHOW_STR
11425 BGP_STR
11426 "BGP view\n"
11427 "BGP view name\n"
11428 "Address family\n"
11429 "Address Family modifier\n"
11430 "Address Family modifier\n"
11431 "Information about Route Server Client\n"
11432 NEIGHBOR_ADDR_STR
11433 "Network in the BGP routing table to display\n")
11434{
11435 struct bgp *bgp;
11436 struct peer *peer;
11437 safi_t safi;
11438
11439 /* BGP structure lookup. */
11440 if (argc == 4)
11441 {
11442 bgp = bgp_lookup_by_name (argv[0]);
11443 if (bgp == NULL)
11444 {
11445 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11446 return CMD_WARNING;
11447 }
11448 }
11449 else
11450 {
11451 bgp = bgp_get_default ();
11452 if (bgp == NULL)
11453 {
11454 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11455 return CMD_WARNING;
11456 }
11457 }
11458
11459 if (argc == 4) {
11460 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11461 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11462 } else {
11463 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11464 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11465 }
11466
11467 if (! peer)
11468 return CMD_WARNING;
11469
11470 if (! peer->afc[AFI_IP6][safi])
11471 {
11472 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11473 VTY_NEWLINE);
11474 return CMD_WARNING;
11475}
11476
11477 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11478 PEER_FLAG_RSERVER_CLIENT))
11479 {
11480 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11481 VTY_NEWLINE);
11482 return CMD_WARNING;
11483 }
11484
11485 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11486 (argc == 4) ? argv[3] : argv[2],
11487 AFI_IP6, safi, NULL, 0);
11488}
11489
11490ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11491 show_bgp_ipv6_safi_rsclient_route_cmd,
11492 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11493 SHOW_STR
11494 BGP_STR
11495 "Address family\n"
11496 "Address Family modifier\n"
11497 "Address Family modifier\n"
11498 "Information about Route Server Client\n"
11499 NEIGHBOR_ADDR_STR
11500 "Network in the BGP routing table to display\n")
11501
paulfee0f4c2004-09-13 05:12:46 +000011502DEFUN (show_bgp_view_rsclient_prefix,
11503 show_bgp_view_rsclient_prefix_cmd,
11504 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11505 SHOW_STR
11506 BGP_STR
11507 "BGP view\n"
11508 "BGP view name\n"
11509 "Information about Route Server Client\n"
11510 NEIGHBOR_ADDR_STR
11511 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11512{
11513 struct bgp *bgp;
11514 struct peer *peer;
11515
11516 /* BGP structure lookup. */
11517 if (argc == 3)
11518 {
11519 bgp = bgp_lookup_by_name (argv[0]);
11520 if (bgp == NULL)
11521 {
11522 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11523 return CMD_WARNING;
11524 }
11525 }
11526 else
11527 {
11528 bgp = bgp_get_default ();
11529 if (bgp == NULL)
11530 {
11531 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11532 return CMD_WARNING;
11533 }
11534 }
11535
11536 if (argc == 3)
11537 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11538 else
11539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11540
11541 if (! peer)
11542 return CMD_WARNING;
11543
11544 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11545 {
11546 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11547 VTY_NEWLINE);
11548 return CMD_WARNING;
11549 }
11550
11551 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11552 PEER_FLAG_RSERVER_CLIENT))
11553 {
11554 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11555 VTY_NEWLINE);
11556 return CMD_WARNING;
11557 }
11558
11559 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11560 (argc == 3) ? argv[2] : argv[1],
11561 AFI_IP6, SAFI_UNICAST, NULL, 1);
11562}
11563
11564ALIAS (show_bgp_view_rsclient_prefix,
11565 show_bgp_rsclient_prefix_cmd,
11566 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11567 SHOW_STR
11568 BGP_STR
11569 "Information about Route Server Client\n"
11570 NEIGHBOR_ADDR_STR
11571 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11572
Michael Lambert95cbbd22010-07-23 14:43:04 -040011573DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11574 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11575 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11576 SHOW_STR
11577 BGP_STR
11578 "BGP view\n"
11579 "BGP view name\n"
11580 "Address family\n"
11581 "Address Family modifier\n"
11582 "Address Family modifier\n"
11583 "Information about Route Server Client\n"
11584 NEIGHBOR_ADDR_STR
11585 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11586{
11587 struct bgp *bgp;
11588 struct peer *peer;
11589 safi_t safi;
11590
11591 /* BGP structure lookup. */
11592 if (argc == 4)
11593 {
11594 bgp = bgp_lookup_by_name (argv[0]);
11595 if (bgp == NULL)
11596 {
11597 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11598 return CMD_WARNING;
11599 }
11600 }
11601 else
11602 {
11603 bgp = bgp_get_default ();
11604 if (bgp == NULL)
11605 {
11606 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11607 return CMD_WARNING;
11608 }
11609 }
11610
11611 if (argc == 4) {
11612 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11613 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11614 } else {
11615 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11616 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11617 }
11618
11619 if (! peer)
11620 return CMD_WARNING;
11621
11622 if (! peer->afc[AFI_IP6][safi])
11623 {
11624 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11625 VTY_NEWLINE);
11626 return CMD_WARNING;
11627}
11628
11629 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11630 PEER_FLAG_RSERVER_CLIENT))
11631{
11632 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11633 VTY_NEWLINE);
11634 return CMD_WARNING;
11635 }
11636
11637 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11638 (argc == 4) ? argv[3] : argv[2],
11639 AFI_IP6, safi, NULL, 1);
11640}
11641
11642ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11643 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11644 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11645 SHOW_STR
11646 BGP_STR
11647 "Address family\n"
11648 "Address Family modifier\n"
11649 "Address Family modifier\n"
11650 "Information about Route Server Client\n"
11651 NEIGHBOR_ADDR_STR
11652 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11653
paul718e3742002-12-13 20:15:29 +000011654#endif /* HAVE_IPV6 */
11655
11656struct bgp_table *bgp_distance_table;
11657
11658struct bgp_distance
11659{
11660 /* Distance value for the IP source prefix. */
11661 u_char distance;
11662
11663 /* Name of the access-list to be matched. */
11664 char *access_list;
11665};
11666
paul94f2b392005-06-28 12:44:16 +000011667static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011668bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011669{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011670 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011671}
11672
paul94f2b392005-06-28 12:44:16 +000011673static void
paul718e3742002-12-13 20:15:29 +000011674bgp_distance_free (struct bgp_distance *bdistance)
11675{
11676 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11677}
11678
paul94f2b392005-06-28 12:44:16 +000011679static int
paulfd79ac92004-10-13 05:06:08 +000011680bgp_distance_set (struct vty *vty, const char *distance_str,
11681 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011682{
11683 int ret;
11684 struct prefix_ipv4 p;
11685 u_char distance;
11686 struct bgp_node *rn;
11687 struct bgp_distance *bdistance;
11688
11689 ret = str2prefix_ipv4 (ip_str, &p);
11690 if (ret == 0)
11691 {
11692 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11693 return CMD_WARNING;
11694 }
11695
11696 distance = atoi (distance_str);
11697
11698 /* Get BGP distance node. */
11699 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11700 if (rn->info)
11701 {
11702 bdistance = rn->info;
11703 bgp_unlock_node (rn);
11704 }
11705 else
11706 {
11707 bdistance = bgp_distance_new ();
11708 rn->info = bdistance;
11709 }
11710
11711 /* Set distance value. */
11712 bdistance->distance = distance;
11713
11714 /* Reset access-list configuration. */
11715 if (bdistance->access_list)
11716 {
11717 free (bdistance->access_list);
11718 bdistance->access_list = NULL;
11719 }
11720 if (access_list_str)
11721 bdistance->access_list = strdup (access_list_str);
11722
11723 return CMD_SUCCESS;
11724}
11725
paul94f2b392005-06-28 12:44:16 +000011726static int
paulfd79ac92004-10-13 05:06:08 +000011727bgp_distance_unset (struct vty *vty, const char *distance_str,
11728 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011729{
11730 int ret;
11731 struct prefix_ipv4 p;
11732 u_char distance;
11733 struct bgp_node *rn;
11734 struct bgp_distance *bdistance;
11735
11736 ret = str2prefix_ipv4 (ip_str, &p);
11737 if (ret == 0)
11738 {
11739 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11740 return CMD_WARNING;
11741 }
11742
11743 distance = atoi (distance_str);
11744
11745 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11746 if (! rn)
11747 {
11748 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11749 return CMD_WARNING;
11750 }
11751
11752 bdistance = rn->info;
11753
11754 if (bdistance->access_list)
11755 free (bdistance->access_list);
11756 bgp_distance_free (bdistance);
11757
11758 rn->info = NULL;
11759 bgp_unlock_node (rn);
11760 bgp_unlock_node (rn);
11761
11762 return CMD_SUCCESS;
11763}
11764
paul718e3742002-12-13 20:15:29 +000011765/* Apply BGP information to distance method. */
11766u_char
11767bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11768{
11769 struct bgp_node *rn;
11770 struct prefix_ipv4 q;
11771 struct peer *peer;
11772 struct bgp_distance *bdistance;
11773 struct access_list *alist;
11774 struct bgp_static *bgp_static;
11775
11776 if (! bgp)
11777 return 0;
11778
11779 if (p->family != AF_INET)
11780 return 0;
11781
11782 peer = rinfo->peer;
11783
11784 if (peer->su.sa.sa_family != AF_INET)
11785 return 0;
11786
11787 memset (&q, 0, sizeof (struct prefix_ipv4));
11788 q.family = AF_INET;
11789 q.prefix = peer->su.sin.sin_addr;
11790 q.prefixlen = IPV4_MAX_BITLEN;
11791
11792 /* Check source address. */
11793 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11794 if (rn)
11795 {
11796 bdistance = rn->info;
11797 bgp_unlock_node (rn);
11798
11799 if (bdistance->access_list)
11800 {
11801 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11802 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11803 return bdistance->distance;
11804 }
11805 else
11806 return bdistance->distance;
11807 }
11808
11809 /* Backdoor check. */
11810 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11811 if (rn)
11812 {
11813 bgp_static = rn->info;
11814 bgp_unlock_node (rn);
11815
11816 if (bgp_static->backdoor)
11817 {
11818 if (bgp->distance_local)
11819 return bgp->distance_local;
11820 else
11821 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11822 }
11823 }
11824
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011825 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011826 {
11827 if (bgp->distance_ebgp)
11828 return bgp->distance_ebgp;
11829 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11830 }
11831 else
11832 {
11833 if (bgp->distance_ibgp)
11834 return bgp->distance_ibgp;
11835 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11836 }
11837}
11838
11839DEFUN (bgp_distance,
11840 bgp_distance_cmd,
11841 "distance bgp <1-255> <1-255> <1-255>",
11842 "Define an administrative distance\n"
11843 "BGP distance\n"
11844 "Distance for routes external to the AS\n"
11845 "Distance for routes internal to the AS\n"
11846 "Distance for local routes\n")
11847{
11848 struct bgp *bgp;
11849
11850 bgp = vty->index;
11851
11852 bgp->distance_ebgp = atoi (argv[0]);
11853 bgp->distance_ibgp = atoi (argv[1]);
11854 bgp->distance_local = atoi (argv[2]);
11855 return CMD_SUCCESS;
11856}
11857
11858DEFUN (no_bgp_distance,
11859 no_bgp_distance_cmd,
11860 "no distance bgp <1-255> <1-255> <1-255>",
11861 NO_STR
11862 "Define an administrative distance\n"
11863 "BGP distance\n"
11864 "Distance for routes external to the AS\n"
11865 "Distance for routes internal to the AS\n"
11866 "Distance for local routes\n")
11867{
11868 struct bgp *bgp;
11869
11870 bgp = vty->index;
11871
11872 bgp->distance_ebgp= 0;
11873 bgp->distance_ibgp = 0;
11874 bgp->distance_local = 0;
11875 return CMD_SUCCESS;
11876}
11877
11878ALIAS (no_bgp_distance,
11879 no_bgp_distance2_cmd,
11880 "no distance bgp",
11881 NO_STR
11882 "Define an administrative distance\n"
11883 "BGP distance\n")
11884
11885DEFUN (bgp_distance_source,
11886 bgp_distance_source_cmd,
11887 "distance <1-255> A.B.C.D/M",
11888 "Define an administrative distance\n"
11889 "Administrative distance\n"
11890 "IP source prefix\n")
11891{
11892 bgp_distance_set (vty, argv[0], argv[1], NULL);
11893 return CMD_SUCCESS;
11894}
11895
11896DEFUN (no_bgp_distance_source,
11897 no_bgp_distance_source_cmd,
11898 "no distance <1-255> A.B.C.D/M",
11899 NO_STR
11900 "Define an administrative distance\n"
11901 "Administrative distance\n"
11902 "IP source prefix\n")
11903{
11904 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11905 return CMD_SUCCESS;
11906}
11907
11908DEFUN (bgp_distance_source_access_list,
11909 bgp_distance_source_access_list_cmd,
11910 "distance <1-255> A.B.C.D/M WORD",
11911 "Define an administrative distance\n"
11912 "Administrative distance\n"
11913 "IP source prefix\n"
11914 "Access list name\n")
11915{
11916 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11917 return CMD_SUCCESS;
11918}
11919
11920DEFUN (no_bgp_distance_source_access_list,
11921 no_bgp_distance_source_access_list_cmd,
11922 "no distance <1-255> A.B.C.D/M WORD",
11923 NO_STR
11924 "Define an administrative distance\n"
11925 "Administrative distance\n"
11926 "IP source prefix\n"
11927 "Access list name\n")
11928{
11929 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11930 return CMD_SUCCESS;
11931}
11932
11933DEFUN (bgp_damp_set,
11934 bgp_damp_set_cmd,
11935 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11936 "BGP Specific commands\n"
11937 "Enable route-flap dampening\n"
11938 "Half-life time for the penalty\n"
11939 "Value to start reusing a route\n"
11940 "Value to start suppressing a route\n"
11941 "Maximum duration to suppress a stable route\n")
11942{
11943 struct bgp *bgp;
11944 int half = DEFAULT_HALF_LIFE * 60;
11945 int reuse = DEFAULT_REUSE;
11946 int suppress = DEFAULT_SUPPRESS;
11947 int max = 4 * half;
11948
11949 if (argc == 4)
11950 {
11951 half = atoi (argv[0]) * 60;
11952 reuse = atoi (argv[1]);
11953 suppress = atoi (argv[2]);
11954 max = atoi (argv[3]) * 60;
11955 }
11956 else if (argc == 1)
11957 {
11958 half = atoi (argv[0]) * 60;
11959 max = 4 * half;
11960 }
11961
11962 bgp = vty->index;
11963 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11964 half, reuse, suppress, max);
11965}
11966
11967ALIAS (bgp_damp_set,
11968 bgp_damp_set2_cmd,
11969 "bgp dampening <1-45>",
11970 "BGP Specific commands\n"
11971 "Enable route-flap dampening\n"
11972 "Half-life time for the penalty\n")
11973
11974ALIAS (bgp_damp_set,
11975 bgp_damp_set3_cmd,
11976 "bgp dampening",
11977 "BGP Specific commands\n"
11978 "Enable route-flap dampening\n")
11979
11980DEFUN (bgp_damp_unset,
11981 bgp_damp_unset_cmd,
11982 "no bgp dampening",
11983 NO_STR
11984 "BGP Specific commands\n"
11985 "Enable route-flap dampening\n")
11986{
11987 struct bgp *bgp;
11988
11989 bgp = vty->index;
11990 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11991}
11992
11993ALIAS (bgp_damp_unset,
11994 bgp_damp_unset2_cmd,
11995 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11996 NO_STR
11997 "BGP Specific commands\n"
11998 "Enable route-flap dampening\n"
11999 "Half-life time for the penalty\n"
12000 "Value to start reusing a route\n"
12001 "Value to start suppressing a route\n"
12002 "Maximum duration to suppress a stable route\n")
12003
12004DEFUN (show_ip_bgp_dampened_paths,
12005 show_ip_bgp_dampened_paths_cmd,
12006 "show ip bgp dampened-paths",
12007 SHOW_STR
12008 IP_STR
12009 BGP_STR
12010 "Display paths suppressed due to dampening\n")
12011{
ajs5a646652004-11-05 01:25:55 +000012012 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12013 NULL);
paul718e3742002-12-13 20:15:29 +000012014}
12015
12016DEFUN (show_ip_bgp_flap_statistics,
12017 show_ip_bgp_flap_statistics_cmd,
12018 "show ip bgp flap-statistics",
12019 SHOW_STR
12020 IP_STR
12021 BGP_STR
12022 "Display flap statistics of routes\n")
12023{
ajs5a646652004-11-05 01:25:55 +000012024 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12025 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012026}
12027
12028/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012029static int
paulfd79ac92004-10-13 05:06:08 +000012030bgp_clear_damp_route (struct vty *vty, const char *view_name,
12031 const char *ip_str, afi_t afi, safi_t safi,
12032 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012033{
12034 int ret;
12035 struct prefix match;
12036 struct bgp_node *rn;
12037 struct bgp_node *rm;
12038 struct bgp_info *ri;
12039 struct bgp_info *ri_temp;
12040 struct bgp *bgp;
12041 struct bgp_table *table;
12042
12043 /* BGP structure lookup. */
12044 if (view_name)
12045 {
12046 bgp = bgp_lookup_by_name (view_name);
12047 if (bgp == NULL)
12048 {
12049 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12050 return CMD_WARNING;
12051 }
12052 }
12053 else
12054 {
12055 bgp = bgp_get_default ();
12056 if (bgp == NULL)
12057 {
12058 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12059 return CMD_WARNING;
12060 }
12061 }
12062
12063 /* Check IP address argument. */
12064 ret = str2prefix (ip_str, &match);
12065 if (! ret)
12066 {
12067 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12068 return CMD_WARNING;
12069 }
12070
12071 match.family = afi2family (afi);
12072
12073 if (safi == SAFI_MPLS_VPN)
12074 {
12075 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12076 {
12077 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12078 continue;
12079
12080 if ((table = rn->info) != NULL)
12081 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012082 {
12083 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12084 {
12085 ri = rm->info;
12086 while (ri)
12087 {
12088 if (ri->extra && ri->extra->damp_info)
12089 {
12090 ri_temp = ri->next;
12091 bgp_damp_info_free (ri->extra->damp_info, 1);
12092 ri = ri_temp;
12093 }
12094 else
12095 ri = ri->next;
12096 }
12097 }
12098
12099 bgp_unlock_node (rm);
12100 }
paul718e3742002-12-13 20:15:29 +000012101 }
12102 }
12103 else
12104 {
12105 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012106 {
12107 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12108 {
12109 ri = rn->info;
12110 while (ri)
12111 {
12112 if (ri->extra && ri->extra->damp_info)
12113 {
12114 ri_temp = ri->next;
12115 bgp_damp_info_free (ri->extra->damp_info, 1);
12116 ri = ri_temp;
12117 }
12118 else
12119 ri = ri->next;
12120 }
12121 }
12122
12123 bgp_unlock_node (rn);
12124 }
paul718e3742002-12-13 20:15:29 +000012125 }
12126
12127 return CMD_SUCCESS;
12128}
12129
12130DEFUN (clear_ip_bgp_dampening,
12131 clear_ip_bgp_dampening_cmd,
12132 "clear ip bgp dampening",
12133 CLEAR_STR
12134 IP_STR
12135 BGP_STR
12136 "Clear route flap dampening information\n")
12137{
12138 bgp_damp_info_clean ();
12139 return CMD_SUCCESS;
12140}
12141
12142DEFUN (clear_ip_bgp_dampening_prefix,
12143 clear_ip_bgp_dampening_prefix_cmd,
12144 "clear ip bgp dampening A.B.C.D/M",
12145 CLEAR_STR
12146 IP_STR
12147 BGP_STR
12148 "Clear route flap dampening information\n"
12149 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12150{
12151 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12152 SAFI_UNICAST, NULL, 1);
12153}
12154
12155DEFUN (clear_ip_bgp_dampening_address,
12156 clear_ip_bgp_dampening_address_cmd,
12157 "clear ip bgp dampening A.B.C.D",
12158 CLEAR_STR
12159 IP_STR
12160 BGP_STR
12161 "Clear route flap dampening information\n"
12162 "Network to clear damping information\n")
12163{
12164 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12165 SAFI_UNICAST, NULL, 0);
12166}
12167
12168DEFUN (clear_ip_bgp_dampening_address_mask,
12169 clear_ip_bgp_dampening_address_mask_cmd,
12170 "clear ip bgp dampening A.B.C.D A.B.C.D",
12171 CLEAR_STR
12172 IP_STR
12173 BGP_STR
12174 "Clear route flap dampening information\n"
12175 "Network to clear damping information\n"
12176 "Network mask\n")
12177{
12178 int ret;
12179 char prefix_str[BUFSIZ];
12180
12181 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12182 if (! ret)
12183 {
12184 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12185 return CMD_WARNING;
12186 }
12187
12188 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12189 SAFI_UNICAST, NULL, 0);
12190}
12191
paul94f2b392005-06-28 12:44:16 +000012192static int
paul718e3742002-12-13 20:15:29 +000012193bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12194 afi_t afi, safi_t safi, int *write)
12195{
12196 struct bgp_node *prn;
12197 struct bgp_node *rn;
12198 struct bgp_table *table;
12199 struct prefix *p;
12200 struct prefix_rd *prd;
12201 struct bgp_static *bgp_static;
12202 u_int32_t label;
12203 char buf[SU_ADDRSTRLEN];
12204 char rdbuf[RD_ADDRSTRLEN];
12205
12206 /* Network configuration. */
12207 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12208 if ((table = prn->info) != NULL)
12209 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12210 if ((bgp_static = rn->info) != NULL)
12211 {
12212 p = &rn->p;
12213 prd = (struct prefix_rd *) &prn->p;
12214
12215 /* "address-family" display. */
12216 bgp_config_write_family_header (vty, afi, safi, write);
12217
12218 /* "network" configuration display. */
12219 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12220 label = decode_label (bgp_static->tag);
12221
12222 vty_out (vty, " network %s/%d rd %s tag %d",
12223 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12224 p->prefixlen,
12225 rdbuf, label);
12226 vty_out (vty, "%s", VTY_NEWLINE);
12227 }
12228 return 0;
12229}
12230
12231/* Configuration of static route announcement and aggregate
12232 information. */
12233int
12234bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12235 afi_t afi, safi_t safi, int *write)
12236{
12237 struct bgp_node *rn;
12238 struct prefix *p;
12239 struct bgp_static *bgp_static;
12240 struct bgp_aggregate *bgp_aggregate;
12241 char buf[SU_ADDRSTRLEN];
12242
12243 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12244 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12245
12246 /* Network configuration. */
12247 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12248 if ((bgp_static = rn->info) != NULL)
12249 {
12250 p = &rn->p;
12251
12252 /* "address-family" display. */
12253 bgp_config_write_family_header (vty, afi, safi, write);
12254
12255 /* "network" configuration display. */
12256 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12257 {
12258 u_int32_t destination;
12259 struct in_addr netmask;
12260
12261 destination = ntohl (p->u.prefix4.s_addr);
12262 masklen2ip (p->prefixlen, &netmask);
12263 vty_out (vty, " network %s",
12264 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12265
12266 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12267 || (IN_CLASSB (destination) && p->prefixlen == 16)
12268 || (IN_CLASSA (destination) && p->prefixlen == 8)
12269 || p->u.prefix4.s_addr == 0)
12270 {
12271 /* Natural mask is not display. */
12272 }
12273 else
12274 vty_out (vty, " mask %s", inet_ntoa (netmask));
12275 }
12276 else
12277 {
12278 vty_out (vty, " network %s/%d",
12279 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12280 p->prefixlen);
12281 }
12282
12283 if (bgp_static->rmap.name)
12284 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012285 else
12286 {
12287 if (bgp_static->backdoor)
12288 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012289 }
paul718e3742002-12-13 20:15:29 +000012290
12291 vty_out (vty, "%s", VTY_NEWLINE);
12292 }
12293
12294 /* Aggregate-address configuration. */
12295 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12296 if ((bgp_aggregate = rn->info) != NULL)
12297 {
12298 p = &rn->p;
12299
12300 /* "address-family" display. */
12301 bgp_config_write_family_header (vty, afi, safi, write);
12302
12303 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12304 {
12305 struct in_addr netmask;
12306
12307 masklen2ip (p->prefixlen, &netmask);
12308 vty_out (vty, " aggregate-address %s %s",
12309 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12310 inet_ntoa (netmask));
12311 }
12312 else
12313 {
12314 vty_out (vty, " aggregate-address %s/%d",
12315 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12316 p->prefixlen);
12317 }
12318
12319 if (bgp_aggregate->as_set)
12320 vty_out (vty, " as-set");
12321
12322 if (bgp_aggregate->summary_only)
12323 vty_out (vty, " summary-only");
12324
12325 vty_out (vty, "%s", VTY_NEWLINE);
12326 }
12327
12328 return 0;
12329}
12330
12331int
12332bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12333{
12334 struct bgp_node *rn;
12335 struct bgp_distance *bdistance;
12336
12337 /* Distance configuration. */
12338 if (bgp->distance_ebgp
12339 && bgp->distance_ibgp
12340 && bgp->distance_local
12341 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12342 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12343 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12344 vty_out (vty, " distance bgp %d %d %d%s",
12345 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12346 VTY_NEWLINE);
12347
12348 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12349 if ((bdistance = rn->info) != NULL)
12350 {
12351 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12352 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12353 bdistance->access_list ? bdistance->access_list : "",
12354 VTY_NEWLINE);
12355 }
12356
12357 return 0;
12358}
12359
12360/* Allocate routing table structure and install commands. */
12361void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012362bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012363{
12364 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012365 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012366
12367 /* IPv4 BGP commands. */
12368 install_element (BGP_NODE, &bgp_network_cmd);
12369 install_element (BGP_NODE, &bgp_network_mask_cmd);
12370 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12371 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12372 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12373 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12374 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12375 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12376 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12377 install_element (BGP_NODE, &no_bgp_network_cmd);
12378 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12379 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12380 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12381 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12382 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12383 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12384 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12385 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12386
12387 install_element (BGP_NODE, &aggregate_address_cmd);
12388 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12389 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12390 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12391 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12392 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12393 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12394 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12395 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12396 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12397 install_element (BGP_NODE, &no_aggregate_address_cmd);
12398 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12399 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12400 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12401 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12402 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12403 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12404 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12405 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12406 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12407
12408 /* IPv4 unicast configuration. */
12409 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12410 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12411 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12412 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12413 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12414 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012415 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012416 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12417 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12418 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12419 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12420 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012421
paul718e3742002-12-13 20:15:29 +000012422 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12423 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12424 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12425 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12426 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12427 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12428 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12429 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12430 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12431 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12432 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12433 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12434 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12435 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12436 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12437 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12438 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12439 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12440 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12441 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12442
12443 /* IPv4 multicast configuration. */
12444 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12445 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12446 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12447 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12448 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12449 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12455 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12456 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12457 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12458 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12459 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12460 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12461 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12462 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12463 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12464 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12465 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12468 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12469 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12470 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12471 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12476
12477 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012479 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012480 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012482 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012483 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012487 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012488 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012513 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12515 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12517 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012518 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012537 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012553 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012554 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012555 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012557 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012558 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012559 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012561 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012562 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012563 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012564 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012565 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012566 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012567
12568 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012571 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012572 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012575 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012576 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12582 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12583 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12584 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12585 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012588 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12589 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12590 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12591 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12592 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012593 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12594 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12597 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12598 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012602 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012603 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012604 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012605 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012606 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012607 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012608 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012609
12610 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012612 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012613 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012615 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012616 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012620 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012621 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012646 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12647 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12648 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12649 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12650 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012651 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012670 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012686 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012687 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012688 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012689 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012690 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012691 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012692 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012694 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012695 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012696 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012697 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012698 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012699 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012700
12701 /* BGP dampening clear commands */
12702 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12703 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12704 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12705 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12706
Paul Jakmaff7924f2006-09-04 01:10:36 +000012707 /* prefix count */
12708 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12709 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12710 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012711#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012712 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12713
paul718e3742002-12-13 20:15:29 +000012714 /* New config IPv6 BGP commands. */
12715 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12716 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12717 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12718 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12719
12720 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12721 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12722 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12723 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12724
G.Balaji73bfe0b2011-09-23 22:36:20 +053012725 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12726 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12727
paul718e3742002-12-13 20:15:29 +000012728 /* Old config IPv6 BGP commands. */
12729 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12730 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12731
12732 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12733 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12734 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12735 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12736
12737 install_element (VIEW_NODE, &show_bgp_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012739 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012740 install_element (VIEW_NODE, &show_bgp_route_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012742 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012743 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12744 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012745 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012746 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12748 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12750 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12752 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12754 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12756 install_element (VIEW_NODE, &show_bgp_community_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12758 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12760 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12762 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12764 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12766 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12768 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12770 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12772 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12774 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12776 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12778 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12780 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12782 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12784 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012786 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12788 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012790 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012791 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012792 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012793 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012794 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012795 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012796 install_element (VIEW_NODE, &show_bgp_view_cmd);
12797 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12798 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12799 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12800 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12801 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12802 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12807 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12808 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12809 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12810 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12811 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12812 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12813 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012814 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012815 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012816 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012817 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012818 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012819 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012820
12821 /* Restricted:
12822 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12823 */
12824 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012826 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012827 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12828 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012830 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12840 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012848 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012850 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012858 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012859 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012860
12861 install_element (ENABLE_NODE, &show_bgp_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012863 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012864 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012866 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012867 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012869 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012870 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012910 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012914 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012915 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012916 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012917 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012918 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012919 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012920 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012938 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012939 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012940 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012942 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012944
12945 /* Statistics */
12946 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12950
paul718e3742002-12-13 20:15:29 +000012951 /* old command */
12952 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012988
paul718e3742002-12-13 20:15:29 +000012989 /* old command */
12990 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13026
13027 /* old command */
13028 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13029 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13030 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13031 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13032
13033 /* old command */
13034 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13035 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13036 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13037 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13038
13039 /* old command */
13040 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13041 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13042 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13043 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13044#endif /* HAVE_IPV6 */
13045
13046 install_element (BGP_NODE, &bgp_distance_cmd);
13047 install_element (BGP_NODE, &no_bgp_distance_cmd);
13048 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13049 install_element (BGP_NODE, &bgp_distance_source_cmd);
13050 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13051 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13052 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13053
13054 install_element (BGP_NODE, &bgp_damp_set_cmd);
13055 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13056 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13057 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13058 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13059 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013064
13065 /* Deprecated AS-Pathlimit commands */
13066 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13067 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13068 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13069 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13070 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13071 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13072
13073 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13074 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13075 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13076 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13077 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13078 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13079
13080 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13086
13087 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13088 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13089 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13090 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13091 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13092 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13093
13094 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13095 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13096 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13097 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13098 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13099 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13100
13101 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13102 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13103 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13104 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13105 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13106 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013107
13108#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013109 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13110 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013111#endif
paul718e3742002-12-13 20:15:29 +000013112}
Chris Caputo228da422009-07-18 05:44:03 +000013113
13114void
13115bgp_route_finish (void)
13116{
13117 bgp_table_unlock (bgp_distance_table);
13118 bgp_distance_table = NULL;
13119}