blob: 06bd59916cdd0e5c2cd8b528b8bdaa9a8d2a3095 [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;
2465 struct bgp_info binfo;
2466 struct peer *from;
2467 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002468
Paul Jakmab2497022007-06-14 11:17:58 +00002469 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002470 return;
2471
paul718e3742002-12-13 20:15:29 +00002472 bgp = peer->bgp;
2473 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002474
paul718e3742002-12-13 20:15:29 +00002475 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2476 aspath = attr.aspath;
2477 attr.local_pref = bgp->default_local_pref;
2478 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2479
2480 if (afi == AFI_IP)
2481 str2prefix ("0.0.0.0/0", &p);
2482#ifdef HAVE_IPV6
2483 else if (afi == AFI_IP6)
2484 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002485 struct attr_extra *ae = attr.extra;
2486
paul718e3742002-12-13 20:15:29 +00002487 str2prefix ("::/0", &p);
2488
2489 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002490 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002491 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002492 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002493
2494 /* If the peer is on shared nextwork and we have link-local
2495 nexthop set it. */
2496 if (peer->shared_network
2497 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2498 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002499 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002500 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002501 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002502 }
2503 }
2504#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002505
2506 if (peer->default_rmap[afi][safi].name)
2507 {
2508 binfo.peer = bgp->peer_self;
2509 binfo.attr = &attr;
2510
paulfee0f4c2004-09-13 05:12:46 +00002511 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2512
paul718e3742002-12-13 20:15:29 +00002513 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2514 RMAP_BGP, &binfo);
2515
paulfee0f4c2004-09-13 05:12:46 +00002516 bgp->peer_self->rmap_type = 0;
2517
paul718e3742002-12-13 20:15:29 +00002518 if (ret == RMAP_DENYMATCH)
2519 {
2520 bgp_attr_flush (&attr);
2521 withdraw = 1;
2522 }
2523 }
2524
2525 if (withdraw)
2526 {
2527 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2528 bgp_default_withdraw_send (peer, afi, safi);
2529 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2530 }
2531 else
2532 {
2533 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2534 bgp_default_update_send (peer, &attr, afi, safi, from);
2535 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002536
2537 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002538 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002539}
2540
2541static void
2542bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002543 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002544{
2545 struct bgp_node *rn;
2546 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002547 struct attr attr;
2548 struct attr_extra extra;
2549
paul718e3742002-12-13 20:15:29 +00002550 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002551 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002552
2553 if (safi != SAFI_MPLS_VPN
2554 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2555 bgp_default_originate (peer, afi, safi, 0);
2556
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002557 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2558 attr.extra = &extra;
2559
paul718e3742002-12-13 20:15:29 +00002560 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2561 for (ri = rn->info; ri; ri = ri->next)
2562 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2563 {
paulfee0f4c2004-09-13 05:12:46 +00002564 if ( (rsclient) ?
2565 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2566 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002567 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2568 else
2569 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2570 }
2571}
2572
2573void
2574bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2575{
2576 struct bgp_node *rn;
2577 struct bgp_table *table;
2578
2579 if (peer->status != Established)
2580 return;
2581
2582 if (! peer->afc_nego[afi][safi])
2583 return;
2584
2585 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2586 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2587 return;
2588
2589 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002590 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002591 else
2592 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2593 rn = bgp_route_next(rn))
2594 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002595 bgp_announce_table (peer, afi, safi, table, 0);
2596
2597 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2598 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002599}
2600
2601void
2602bgp_announce_route_all (struct peer *peer)
2603{
2604 afi_t afi;
2605 safi_t safi;
2606
2607 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2608 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2609 bgp_announce_route (peer, afi, safi);
2610}
2611
2612static void
paulfee0f4c2004-09-13 05:12:46 +00002613bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002614 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002615{
2616 struct bgp_node *rn;
2617 struct bgp_adj_in *ain;
2618
2619 if (! table)
2620 table = rsclient->bgp->rib[afi][safi];
2621
2622 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2623 for (ain = rn->adj_in; ain; ain = ain->next)
2624 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002625 struct bgp_info *ri = rn->info;
2626
paulfee0f4c2004-09-13 05:12:46 +00002627 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002628 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2629 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002630 }
2631}
2632
2633void
2634bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2635{
2636 struct bgp_table *table;
2637 struct bgp_node *rn;
2638
2639 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002640 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002641
2642 else
2643 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2644 rn = bgp_route_next (rn))
2645 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002646 {
2647 struct prefix_rd prd;
2648 prd.family = AF_UNSPEC;
2649 prd.prefixlen = 64;
2650 memcpy(&prd.val, rn->p.u.val, 8);
2651
2652 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2653 }
paulfee0f4c2004-09-13 05:12:46 +00002654}
2655
2656static void
paul718e3742002-12-13 20:15:29 +00002657bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002658 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002659{
2660 int ret;
2661 struct bgp_node *rn;
2662 struct bgp_adj_in *ain;
2663
2664 if (! table)
2665 table = peer->bgp->rib[afi][safi];
2666
2667 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2668 for (ain = rn->adj_in; ain; ain = ain->next)
2669 {
2670 if (ain->peer == peer)
2671 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002672 struct bgp_info *ri = rn->info;
2673
paul718e3742002-12-13 20:15:29 +00002674 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2675 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002676 prd, (bgp_info_extra_get (ri))->tag, 1);
2677
paul718e3742002-12-13 20:15:29 +00002678 if (ret < 0)
2679 {
2680 bgp_unlock_node (rn);
2681 return;
2682 }
2683 continue;
2684 }
2685 }
2686}
2687
2688void
2689bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2690{
2691 struct bgp_node *rn;
2692 struct bgp_table *table;
2693
2694 if (peer->status != Established)
2695 return;
2696
2697 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002698 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002699 else
2700 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2701 rn = bgp_route_next (rn))
2702 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002703 {
2704 struct prefix_rd prd;
2705 prd.family = AF_UNSPEC;
2706 prd.prefixlen = 64;
2707 memcpy(&prd.val, rn->p.u.val, 8);
2708
2709 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2710 }
paul718e3742002-12-13 20:15:29 +00002711}
2712
Chris Caputo228da422009-07-18 05:44:03 +00002713
2714struct bgp_clear_node_queue
2715{
2716 struct bgp_node *rn;
2717 enum bgp_clear_route_type purpose;
2718};
2719
paul200df112005-06-01 11:17:05 +00002720static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002721bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002722{
Chris Caputo228da422009-07-18 05:44:03 +00002723 struct bgp_clear_node_queue *cnq = data;
2724 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002725 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002726 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002727 afi_t afi = bgp_node_table (rn)->afi;
2728 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002729
Paul Jakma64e580a2006-02-21 01:09:01 +00002730 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002731
Paul Jakma64e580a2006-02-21 01:09:01 +00002732 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002733 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002734 {
2735 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002736 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2737 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002738 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002739 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2740 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002741 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002742 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002743 break;
2744 }
paul200df112005-06-01 11:17:05 +00002745 return WQ_SUCCESS;
2746}
2747
2748static void
paul0fb58d52005-11-14 14:31:49 +00002749bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002750{
Chris Caputo228da422009-07-18 05:44:03 +00002751 struct bgp_clear_node_queue *cnq = data;
2752 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002753 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002754
2755 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002756 bgp_table_unlock (table);
2757 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002758}
2759
2760static void
paul94f2b392005-06-28 12:44:16 +00002761bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002762{
Paul Jakma64e580a2006-02-21 01:09:01 +00002763 struct peer *peer = wq->spec.data;
2764
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002765 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002766 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002767
2768 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002769}
2770
2771static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002772bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002773{
Paul Jakmaa2943652009-07-21 14:02:04 +01002774 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002775
Paul Jakmaa2943652009-07-21 14:02:04 +01002776 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002777#undef CLEAR_QUEUE_NAME_LEN
2778
2779 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002780 {
2781 zlog_err ("%s: Failed to allocate work queue", __func__);
2782 exit (1);
2783 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002784 peer->clear_node_queue->spec.hold = 10;
2785 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2786 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2787 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2788 peer->clear_node_queue->spec.max_retries = 0;
2789
2790 /* we only 'lock' this peer reference when the queue is actually active */
2791 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002792}
2793
paul718e3742002-12-13 20:15:29 +00002794static void
2795bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002796 struct bgp_table *table, struct peer *rsclient,
2797 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002798{
2799 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002800
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002801
paul718e3742002-12-13 20:15:29 +00002802 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002803 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002804
hasso6cf159b2005-03-21 10:28:14 +00002805 /* If still no table => afi/safi isn't configured at all or smth. */
2806 if (! table)
2807 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002808
2809 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2810 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002811 struct bgp_info *ri;
2812 struct bgp_adj_in *ain;
2813 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002814
2815 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2816 * queued for every clearing peer, regardless of whether it is
2817 * relevant to the peer at hand.
2818 *
2819 * Overview: There are 3 different indices which need to be
2820 * scrubbed, potentially, when a peer is removed:
2821 *
2822 * 1 peer's routes visible via the RIB (ie accepted routes)
2823 * 2 peer's routes visible by the (optional) peer's adj-in index
2824 * 3 other routes visible by the peer's adj-out index
2825 *
2826 * 3 there is no hurry in scrubbing, once the struct peer is
2827 * removed from bgp->peer, we could just GC such deleted peer's
2828 * adj-outs at our leisure.
2829 *
2830 * 1 and 2 must be 'scrubbed' in some way, at least made
2831 * invisible via RIB index before peer session is allowed to be
2832 * brought back up. So one needs to know when such a 'search' is
2833 * complete.
2834 *
2835 * Ideally:
2836 *
2837 * - there'd be a single global queue or a single RIB walker
2838 * - rather than tracking which route_nodes still need to be
2839 * examined on a peer basis, we'd track which peers still
2840 * aren't cleared
2841 *
2842 * Given that our per-peer prefix-counts now should be reliable,
2843 * this may actually be achievable. It doesn't seem to be a huge
2844 * problem at this time,
2845 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002846 for (ain = rn->adj_in; ain; ain = ain->next)
2847 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2848 {
2849 bgp_adj_in_remove (rn, ain);
2850 bgp_unlock_node (rn);
2851 break;
2852 }
2853 for (aout = rn->adj_out; aout; aout = aout->next)
2854 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2855 {
2856 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2857 bgp_unlock_node (rn);
2858 break;
2859 }
2860
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002861 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002862 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002863 {
Chris Caputo228da422009-07-18 05:44:03 +00002864 struct bgp_clear_node_queue *cnq;
2865
2866 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002867 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002868 bgp_lock_node (rn);
2869 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2870 sizeof (struct bgp_clear_node_queue));
2871 cnq->rn = rn;
2872 cnq->purpose = purpose;
2873 work_queue_add (peer->clear_node_queue, cnq);
2874 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002875 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002876 }
2877 return;
2878}
2879
2880void
Chris Caputo228da422009-07-18 05:44:03 +00002881bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2882 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002883{
2884 struct bgp_node *rn;
2885 struct bgp_table *table;
2886 struct peer *rsclient;
2887 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002888
Paul Jakma64e580a2006-02-21 01:09:01 +00002889 if (peer->clear_node_queue == NULL)
2890 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002891
Paul Jakmaca058a32006-09-14 02:58:49 +00002892 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2893 * Idle until it receives a Clearing_Completed event. This protects
2894 * against peers which flap faster than we can we clear, which could
2895 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002896 *
2897 * a) race with routes from the new session being installed before
2898 * clear_route_node visits the node (to delete the route of that
2899 * peer)
2900 * b) resource exhaustion, clear_route_node likely leads to an entry
2901 * on the process_main queue. Fast-flapping could cause that queue
2902 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002903 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002904 if (!peer->clear_node_queue->thread)
2905 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002906
Chris Caputo228da422009-07-18 05:44:03 +00002907 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002908 {
Chris Caputo228da422009-07-18 05:44:03 +00002909 case BGP_CLEAR_ROUTE_NORMAL:
2910 if (safi != SAFI_MPLS_VPN)
2911 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2912 else
2913 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2914 rn = bgp_route_next (rn))
2915 if ((table = rn->info) != NULL)
2916 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2917
2918 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2919 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2920 PEER_FLAG_RSERVER_CLIENT))
2921 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2922 break;
2923
2924 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2925 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2926 break;
2927
2928 default:
2929 assert (0);
2930 break;
paulfee0f4c2004-09-13 05:12:46 +00002931 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002932
Paul Jakmaca058a32006-09-14 02:58:49 +00002933 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002934 * completion function won't be run by workqueue code - call it here.
2935 * XXX: Actually, this assumption doesn't hold, see
2936 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002937 *
2938 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002939 * really needed if peer state is Established - peers in
2940 * pre-Established states shouldn't have any route-update state
2941 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002942 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002943 * We still can get here in pre-Established though, through
2944 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2945 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002946 *
2947 * At some future point, this check could be move to the top of the
2948 * function, and do a quick early-return when state is
2949 * pre-Established, avoiding above list and table scans. Once we're
2950 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002951 */
2952 if (!peer->clear_node_queue->thread)
2953 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002954}
2955
2956void
2957bgp_clear_route_all (struct peer *peer)
2958{
2959 afi_t afi;
2960 safi_t safi;
2961
2962 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2963 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002964 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002965}
2966
2967void
2968bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2969{
2970 struct bgp_table *table;
2971 struct bgp_node *rn;
2972 struct bgp_adj_in *ain;
2973
2974 table = peer->bgp->rib[afi][safi];
2975
2976 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2977 for (ain = rn->adj_in; ain ; ain = ain->next)
2978 if (ain->peer == peer)
2979 {
2980 bgp_adj_in_remove (rn, ain);
2981 bgp_unlock_node (rn);
2982 break;
2983 }
2984}
hasso93406d82005-02-02 14:40:33 +00002985
2986void
2987bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2988{
2989 struct bgp_node *rn;
2990 struct bgp_info *ri;
2991 struct bgp_table *table;
2992
2993 table = peer->bgp->rib[afi][safi];
2994
2995 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2996 {
2997 for (ri = rn->info; ri; ri = ri->next)
2998 if (ri->peer == peer)
2999 {
3000 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3001 bgp_rib_remove (rn, ri, peer, afi, safi);
3002 break;
3003 }
3004 }
3005}
paul718e3742002-12-13 20:15:29 +00003006
3007/* Delete all kernel routes. */
3008void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003009bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003010{
3011 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003012 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003013 struct bgp_node *rn;
3014 struct bgp_table *table;
3015 struct bgp_info *ri;
3016
paul1eb8ef22005-04-07 07:30:20 +00003017 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003018 {
3019 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3020
3021 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3022 for (ri = rn->info; ri; ri = ri->next)
3023 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3024 && ri->type == ZEBRA_ROUTE_BGP
3025 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003026 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003027
3028 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3029
3030 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3031 for (ri = rn->info; ri; ri = ri->next)
3032 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3033 && ri->type == ZEBRA_ROUTE_BGP
3034 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003035 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003036 }
3037}
3038
3039void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003040bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003041{
3042 vty_reset ();
3043 bgp_zclient_reset ();
3044 access_list_reset ();
3045 prefix_list_reset ();
3046}
3047
3048/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3049 value. */
3050int
3051bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3052{
3053 u_char *pnt;
3054 u_char *lim;
3055 struct prefix p;
3056 int psize;
3057 int ret;
3058
3059 /* Check peer status. */
3060 if (peer->status != Established)
3061 return 0;
3062
3063 pnt = packet->nlri;
3064 lim = pnt + packet->length;
3065
3066 for (; pnt < lim; pnt += psize)
3067 {
3068 /* Clear prefix structure. */
3069 memset (&p, 0, sizeof (struct prefix));
3070
3071 /* Fetch prefix length. */
3072 p.prefixlen = *pnt++;
3073 p.family = afi2family (packet->afi);
3074
3075 /* Already checked in nlri_sanity_check(). We do double check
3076 here. */
3077 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3078 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3079 return -1;
3080
3081 /* Packet size overflow check. */
3082 psize = PSIZE (p.prefixlen);
3083
3084 /* When packet overflow occur return immediately. */
3085 if (pnt + psize > lim)
3086 return -1;
3087
3088 /* Fetch prefix from NLRI packet. */
3089 memcpy (&p.u.prefix, pnt, psize);
3090
3091 /* Check address. */
3092 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3093 {
3094 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3095 {
paulf5ba3872004-07-09 12:11:31 +00003096 /*
3097 * From draft-ietf-idr-bgp4-22, Section 6.3:
3098 * If a BGP router receives an UPDATE message with a
3099 * semantically incorrect NLRI field, in which a prefix is
3100 * semantically incorrect (eg. an unexpected multicast IP
3101 * address), it should ignore the prefix.
3102 */
paul718e3742002-12-13 20:15:29 +00003103 zlog (peer->log, LOG_ERR,
3104 "IPv4 unicast NLRI is multicast address %s",
3105 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003106
paul718e3742002-12-13 20:15:29 +00003107 return -1;
3108 }
3109 }
3110
3111#ifdef HAVE_IPV6
3112 /* Check address. */
3113 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3114 {
3115 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3116 {
3117 char buf[BUFSIZ];
3118
3119 zlog (peer->log, LOG_WARNING,
3120 "IPv6 link-local NLRI received %s ignore this NLRI",
3121 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3122
3123 continue;
3124 }
3125 }
3126#endif /* HAVE_IPV6 */
3127
3128 /* Normal process. */
3129 if (attr)
3130 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3131 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3132 else
3133 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3134 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3135
3136 /* Address family configuration mismatch or maximum-prefix count
3137 overflow. */
3138 if (ret < 0)
3139 return -1;
3140 }
3141
3142 /* Packet length consistency check. */
3143 if (pnt != lim)
3144 return -1;
3145
3146 return 0;
3147}
3148
3149/* NLRI encode syntax check routine. */
3150int
3151bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3152 bgp_size_t length)
3153{
3154 u_char *end;
3155 u_char prefixlen;
3156 int psize;
3157
3158 end = pnt + length;
3159
3160 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3161 syntactic validity. If the field is syntactically incorrect,
3162 then the Error Subcode is set to Invalid Network Field. */
3163
3164 while (pnt < end)
3165 {
3166 prefixlen = *pnt++;
3167
3168 /* Prefix length check. */
3169 if ((afi == AFI_IP && prefixlen > 32)
3170 || (afi == AFI_IP6 && prefixlen > 128))
3171 {
3172 plog_err (peer->log,
3173 "%s [Error] Update packet error (wrong prefix length %d)",
3174 peer->host, prefixlen);
3175 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3176 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3177 return -1;
3178 }
3179
3180 /* Packet size overflow check. */
3181 psize = PSIZE (prefixlen);
3182
3183 if (pnt + psize > end)
3184 {
3185 plog_err (peer->log,
3186 "%s [Error] Update packet error"
3187 " (prefix data overflow prefix size is %d)",
3188 peer->host, psize);
3189 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3190 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3191 return -1;
3192 }
3193
3194 pnt += psize;
3195 }
3196
3197 /* Packet length consistency check. */
3198 if (pnt != end)
3199 {
3200 plog_err (peer->log,
3201 "%s [Error] Update packet error"
3202 " (prefix length mismatch with total length)",
3203 peer->host);
3204 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3205 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3206 return -1;
3207 }
3208 return 0;
3209}
3210
paul94f2b392005-06-28 12:44:16 +00003211static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003212bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003213{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003214 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003215}
3216
paul94f2b392005-06-28 12:44:16 +00003217static void
paul718e3742002-12-13 20:15:29 +00003218bgp_static_free (struct bgp_static *bgp_static)
3219{
3220 if (bgp_static->rmap.name)
3221 free (bgp_static->rmap.name);
3222 XFREE (MTYPE_BGP_STATIC, bgp_static);
3223}
3224
paul94f2b392005-06-28 12:44:16 +00003225static void
paulfee0f4c2004-09-13 05:12:46 +00003226bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3227 struct prefix *p, afi_t afi, safi_t safi)
3228{
3229 struct bgp_node *rn;
3230 struct bgp_info *ri;
3231
3232 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3233
3234 /* Check selected route and self inserted route. */
3235 for (ri = rn->info; ri; ri = ri->next)
3236 if (ri->peer == bgp->peer_self
3237 && ri->type == ZEBRA_ROUTE_BGP
3238 && ri->sub_type == BGP_ROUTE_STATIC)
3239 break;
3240
3241 /* Withdraw static BGP route from routing table. */
3242 if (ri)
3243 {
paulfee0f4c2004-09-13 05:12:46 +00003244 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003245 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003246 }
3247
3248 /* Unlock bgp_node_lookup. */
3249 bgp_unlock_node (rn);
3250}
3251
paul94f2b392005-06-28 12:44:16 +00003252static void
paulfee0f4c2004-09-13 05:12:46 +00003253bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003254 struct bgp_static *bgp_static,
3255 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003256{
3257 struct bgp_node *rn;
3258 struct bgp_info *ri;
3259 struct bgp_info *new;
3260 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003261 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003262 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003263 struct attr new_attr;
3264 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003265 struct bgp *bgp;
3266 int ret;
3267 char buf[SU_ADDRSTRLEN];
3268
3269 bgp = rsclient->bgp;
3270
Paul Jakma06e110f2006-05-12 23:29:22 +00003271 assert (bgp_static);
3272 if (!bgp_static)
3273 return;
3274
paulfee0f4c2004-09-13 05:12:46 +00003275 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3276
3277 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003278
3279 attr.nexthop = bgp_static->igpnexthop;
3280 attr.med = bgp_static->igpmetric;
3281 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003282
Paul Jakma41367172007-08-06 15:24:51 +00003283 if (bgp_static->atomic)
3284 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3285
paulfee0f4c2004-09-13 05:12:46 +00003286 /* Apply network route-map for export to this rsclient. */
3287 if (bgp_static->rmap.name)
3288 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003289 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003290 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003291 info.attr = &attr_tmp;
3292
paulfee0f4c2004-09-13 05:12:46 +00003293 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3294 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3295
3296 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3297
3298 rsclient->rmap_type = 0;
3299
3300 if (ret == RMAP_DENYMATCH)
3301 {
3302 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003303 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003304
3305 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003306 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003307 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003308 bgp_attr_extra_free (&attr);
3309
paulfee0f4c2004-09-13 05:12:46 +00003310 return;
3311 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003312 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003313 }
3314 else
3315 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003316
3317 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003318 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003319
paulfee0f4c2004-09-13 05:12:46 +00003320 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3321
Paul Jakmafb982c22007-05-04 20:15:47 +00003322 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3323 == RMAP_DENY)
3324 {
paulfee0f4c2004-09-13 05:12:46 +00003325 /* This BGP update is filtered. Log the reason then update BGP entry. */
3326 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003327 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003328 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3329 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3330 p->prefixlen, rsclient->host);
3331
3332 bgp->peer_self->rmap_type = 0;
3333
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003334 bgp_attr_unintern (&attr_new);
3335 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003336 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003337
3338 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3339
3340 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 }
paulfee0f4c2004-09-13 05:12:46 +00003342
3343 bgp->peer_self->rmap_type = 0;
3344
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003345 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003346 attr_new = bgp_attr_intern (&new_attr);
3347
3348 for (ri = rn->info; ri; ri = ri->next)
3349 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3350 && ri->sub_type == BGP_ROUTE_STATIC)
3351 break;
3352
3353 if (ri)
3354 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003355 if (attrhash_cmp (ri->attr, attr_new) &&
3356 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003357 {
3358 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003359 bgp_attr_unintern (&attr_new);
3360 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003361 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003362 return;
3363 }
3364 else
3365 {
3366 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003367 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003368
3369 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003370 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3371 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003372 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003373 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003374 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 /* Process change. */
3377 bgp_process (bgp, rn, afi, safi);
3378 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003379 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003380 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003381 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003382 }
paulfee0f4c2004-09-13 05:12:46 +00003383 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003384
paulfee0f4c2004-09-13 05:12:46 +00003385 /* Make new BGP info. */
3386 new = bgp_info_new ();
3387 new->type = ZEBRA_ROUTE_BGP;
3388 new->sub_type = BGP_ROUTE_STATIC;
3389 new->peer = bgp->peer_self;
3390 SET_FLAG (new->flags, BGP_INFO_VALID);
3391 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003392 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003393
3394 /* Register new BGP information. */
3395 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003396
3397 /* route_node_get lock */
3398 bgp_unlock_node (rn);
3399
paulfee0f4c2004-09-13 05:12:46 +00003400 /* Process change. */
3401 bgp_process (bgp, rn, afi, safi);
3402
3403 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003404 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003405 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003406}
3407
paul94f2b392005-06-28 12:44:16 +00003408static void
paulfee0f4c2004-09-13 05:12:46 +00003409bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003410 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3411{
3412 struct bgp_node *rn;
3413 struct bgp_info *ri;
3414 struct bgp_info *new;
3415 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003416 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003417 struct attr *attr_new;
3418 int ret;
3419
Paul Jakmadd8103a2006-05-12 23:27:30 +00003420 assert (bgp_static);
3421 if (!bgp_static)
3422 return;
3423
paulfee0f4c2004-09-13 05:12:46 +00003424 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003425
3426 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003427
3428 attr.nexthop = bgp_static->igpnexthop;
3429 attr.med = bgp_static->igpmetric;
3430 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003431
Paul Jakma41367172007-08-06 15:24:51 +00003432 if (bgp_static->atomic)
3433 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3434
paul718e3742002-12-13 20:15:29 +00003435 /* Apply route-map. */
3436 if (bgp_static->rmap.name)
3437 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003438 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003439 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003440 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003441
paulfee0f4c2004-09-13 05:12:46 +00003442 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3443
paul718e3742002-12-13 20:15:29 +00003444 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003445
paulfee0f4c2004-09-13 05:12:46 +00003446 bgp->peer_self->rmap_type = 0;
3447
paul718e3742002-12-13 20:15:29 +00003448 if (ret == RMAP_DENYMATCH)
3449 {
3450 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003451 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003452
3453 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003454 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003455 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003456 bgp_static_withdraw (bgp, p, afi, safi);
3457 return;
3458 }
paul286e1e72003-08-08 00:24:31 +00003459 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003460 }
paul286e1e72003-08-08 00:24:31 +00003461 else
3462 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003463
3464 for (ri = rn->info; ri; ri = ri->next)
3465 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3466 && ri->sub_type == BGP_ROUTE_STATIC)
3467 break;
3468
3469 if (ri)
3470 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003471 if (attrhash_cmp (ri->attr, attr_new) &&
3472 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003473 {
3474 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003475 bgp_attr_unintern (&attr_new);
3476 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003477 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003478 return;
3479 }
3480 else
3481 {
3482 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003483 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003484
3485 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003486 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3487 bgp_info_restore(rn, ri);
3488 else
3489 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003490 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003491 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003492 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003493
3494 /* Process change. */
3495 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3496 bgp_process (bgp, rn, afi, safi);
3497 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003498 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003500 return;
3501 }
3502 }
3503
3504 /* Make new BGP info. */
3505 new = bgp_info_new ();
3506 new->type = ZEBRA_ROUTE_BGP;
3507 new->sub_type = BGP_ROUTE_STATIC;
3508 new->peer = bgp->peer_self;
3509 SET_FLAG (new->flags, BGP_INFO_VALID);
3510 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003511 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003512
3513 /* Aggregate address increment. */
3514 bgp_aggregate_increment (bgp, p, new, afi, safi);
3515
3516 /* Register new BGP information. */
3517 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003518
3519 /* route_node_get lock */
3520 bgp_unlock_node (rn);
3521
paul718e3742002-12-13 20:15:29 +00003522 /* Process change. */
3523 bgp_process (bgp, rn, afi, safi);
3524
3525 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003526 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003527 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003528}
3529
3530void
paulfee0f4c2004-09-13 05:12:46 +00003531bgp_static_update (struct bgp *bgp, struct prefix *p,
3532 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3533{
3534 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003535 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003536
3537 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3538
paul1eb8ef22005-04-07 07:30:20 +00003539 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003540 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003541 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3542 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003543 }
3544}
3545
paul94f2b392005-06-28 12:44:16 +00003546static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003547bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3548 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003549{
3550 struct bgp_node *rn;
3551 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003552
paulfee0f4c2004-09-13 05:12:46 +00003553 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003554
3555 /* Make new BGP info. */
3556 new = bgp_info_new ();
3557 new->type = ZEBRA_ROUTE_BGP;
3558 new->sub_type = BGP_ROUTE_STATIC;
3559 new->peer = bgp->peer_self;
3560 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3561 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003562 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 new->extra = bgp_info_extra_new();
3564 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003565
3566 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003567 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003568
3569 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003570 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003571
paul200df112005-06-01 11:17:05 +00003572 /* route_node_get lock */
3573 bgp_unlock_node (rn);
3574
paul718e3742002-12-13 20:15:29 +00003575 /* Process change. */
3576 bgp_process (bgp, rn, afi, safi);
3577}
3578
3579void
3580bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3581 safi_t safi)
3582{
3583 struct bgp_node *rn;
3584 struct bgp_info *ri;
3585
paulfee0f4c2004-09-13 05:12:46 +00003586 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003587
3588 /* Check selected route and self inserted route. */
3589 for (ri = rn->info; ri; ri = ri->next)
3590 if (ri->peer == bgp->peer_self
3591 && ri->type == ZEBRA_ROUTE_BGP
3592 && ri->sub_type == BGP_ROUTE_STATIC)
3593 break;
3594
3595 /* Withdraw static BGP route from routing table. */
3596 if (ri)
3597 {
3598 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003599 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003600 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003601 }
3602
3603 /* Unlock bgp_node_lookup. */
3604 bgp_unlock_node (rn);
3605}
3606
3607void
paulfee0f4c2004-09-13 05:12:46 +00003608bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3609{
3610 struct bgp_static *bgp_static;
3611 struct bgp *bgp;
3612 struct bgp_node *rn;
3613 struct prefix *p;
3614
3615 bgp = rsclient->bgp;
3616
3617 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3618 if ((bgp_static = rn->info) != NULL)
3619 {
3620 p = &rn->p;
3621
3622 bgp_static_update_rsclient (rsclient, p, bgp_static,
3623 afi, safi);
3624 }
3625}
3626
paul94f2b392005-06-28 12:44:16 +00003627static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003628bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3629 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003630{
3631 struct bgp_node *rn;
3632 struct bgp_info *ri;
3633
paulfee0f4c2004-09-13 05:12:46 +00003634 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003635
3636 /* Check selected route and self inserted route. */
3637 for (ri = rn->info; ri; ri = ri->next)
3638 if (ri->peer == bgp->peer_self
3639 && ri->type == ZEBRA_ROUTE_BGP
3640 && ri->sub_type == BGP_ROUTE_STATIC)
3641 break;
3642
3643 /* Withdraw static BGP route from routing table. */
3644 if (ri)
3645 {
3646 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003647 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003648 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003649 }
3650
3651 /* Unlock bgp_node_lookup. */
3652 bgp_unlock_node (rn);
3653}
3654
3655/* Configure static BGP network. When user don't run zebra, static
3656 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003657static int
paulfd79ac92004-10-13 05:06:08 +00003658bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003659 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003660{
3661 int ret;
3662 struct prefix p;
3663 struct bgp_static *bgp_static;
3664 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003665 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003666
3667 /* Convert IP prefix string to struct prefix. */
3668 ret = str2prefix (ip_str, &p);
3669 if (! ret)
3670 {
3671 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3672 return CMD_WARNING;
3673 }
3674#ifdef HAVE_IPV6
3675 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3676 {
3677 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3678 VTY_NEWLINE);
3679 return CMD_WARNING;
3680 }
3681#endif /* HAVE_IPV6 */
3682
3683 apply_mask (&p);
3684
3685 /* Set BGP static route configuration. */
3686 rn = bgp_node_get (bgp->route[afi][safi], &p);
3687
3688 if (rn->info)
3689 {
3690 /* Configuration change. */
3691 bgp_static = rn->info;
3692
3693 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003694 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3695 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003696
paul718e3742002-12-13 20:15:29 +00003697 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003698
paul718e3742002-12-13 20:15:29 +00003699 if (rmap)
3700 {
3701 if (bgp_static->rmap.name)
3702 free (bgp_static->rmap.name);
3703 bgp_static->rmap.name = strdup (rmap);
3704 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3705 }
3706 else
3707 {
3708 if (bgp_static->rmap.name)
3709 free (bgp_static->rmap.name);
3710 bgp_static->rmap.name = NULL;
3711 bgp_static->rmap.map = NULL;
3712 bgp_static->valid = 0;
3713 }
3714 bgp_unlock_node (rn);
3715 }
3716 else
3717 {
3718 /* New configuration. */
3719 bgp_static = bgp_static_new ();
3720 bgp_static->backdoor = backdoor;
3721 bgp_static->valid = 0;
3722 bgp_static->igpmetric = 0;
3723 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003724
paul718e3742002-12-13 20:15:29 +00003725 if (rmap)
3726 {
3727 if (bgp_static->rmap.name)
3728 free (bgp_static->rmap.name);
3729 bgp_static->rmap.name = strdup (rmap);
3730 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3731 }
3732 rn->info = bgp_static;
3733 }
3734
3735 /* If BGP scan is not enabled, we should install this route here. */
3736 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3737 {
3738 bgp_static->valid = 1;
3739
3740 if (need_update)
3741 bgp_static_withdraw (bgp, &p, afi, safi);
3742
3743 if (! bgp_static->backdoor)
3744 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3745 }
3746
3747 return CMD_SUCCESS;
3748}
3749
3750/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003751static int
paulfd79ac92004-10-13 05:06:08 +00003752bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003753 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003754{
3755 int ret;
3756 struct prefix p;
3757 struct bgp_static *bgp_static;
3758 struct bgp_node *rn;
3759
3760 /* Convert IP prefix string to struct prefix. */
3761 ret = str2prefix (ip_str, &p);
3762 if (! ret)
3763 {
3764 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3765 return CMD_WARNING;
3766 }
3767#ifdef HAVE_IPV6
3768 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3769 {
3770 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3771 VTY_NEWLINE);
3772 return CMD_WARNING;
3773 }
3774#endif /* HAVE_IPV6 */
3775
3776 apply_mask (&p);
3777
3778 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3779 if (! rn)
3780 {
3781 vty_out (vty, "%% Can't find specified static route configuration.%s",
3782 VTY_NEWLINE);
3783 return CMD_WARNING;
3784 }
3785
3786 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003787
paul718e3742002-12-13 20:15:29 +00003788 /* Update BGP RIB. */
3789 if (! bgp_static->backdoor)
3790 bgp_static_withdraw (bgp, &p, afi, safi);
3791
3792 /* Clear configuration. */
3793 bgp_static_free (bgp_static);
3794 rn->info = NULL;
3795 bgp_unlock_node (rn);
3796 bgp_unlock_node (rn);
3797
3798 return CMD_SUCCESS;
3799}
3800
3801/* Called from bgp_delete(). Delete all static routes from the BGP
3802 instance. */
3803void
3804bgp_static_delete (struct bgp *bgp)
3805{
3806 afi_t afi;
3807 safi_t safi;
3808 struct bgp_node *rn;
3809 struct bgp_node *rm;
3810 struct bgp_table *table;
3811 struct bgp_static *bgp_static;
3812
3813 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3814 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3815 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3816 if (rn->info != NULL)
3817 {
3818 if (safi == SAFI_MPLS_VPN)
3819 {
3820 table = rn->info;
3821
3822 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3823 {
3824 bgp_static = rn->info;
3825 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3826 AFI_IP, SAFI_MPLS_VPN,
3827 (struct prefix_rd *)&rn->p,
3828 bgp_static->tag);
3829 bgp_static_free (bgp_static);
3830 rn->info = NULL;
3831 bgp_unlock_node (rn);
3832 }
3833 }
3834 else
3835 {
3836 bgp_static = rn->info;
3837 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3838 bgp_static_free (bgp_static);
3839 rn->info = NULL;
3840 bgp_unlock_node (rn);
3841 }
3842 }
3843}
3844
3845int
paulfd79ac92004-10-13 05:06:08 +00003846bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3847 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003848{
3849 int ret;
3850 struct prefix p;
3851 struct prefix_rd prd;
3852 struct bgp *bgp;
3853 struct bgp_node *prn;
3854 struct bgp_node *rn;
3855 struct bgp_table *table;
3856 struct bgp_static *bgp_static;
3857 u_char tag[3];
3858
3859 bgp = vty->index;
3860
3861 ret = str2prefix (ip_str, &p);
3862 if (! ret)
3863 {
3864 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3865 return CMD_WARNING;
3866 }
3867 apply_mask (&p);
3868
3869 ret = str2prefix_rd (rd_str, &prd);
3870 if (! ret)
3871 {
3872 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3873 return CMD_WARNING;
3874 }
3875
3876 ret = str2tag (tag_str, tag);
3877 if (! ret)
3878 {
3879 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3880 return CMD_WARNING;
3881 }
3882
3883 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3884 (struct prefix *)&prd);
3885 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003886 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003887 else
3888 bgp_unlock_node (prn);
3889 table = prn->info;
3890
3891 rn = bgp_node_get (table, &p);
3892
3893 if (rn->info)
3894 {
3895 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3896 bgp_unlock_node (rn);
3897 }
3898 else
3899 {
3900 /* New configuration. */
3901 bgp_static = bgp_static_new ();
3902 bgp_static->valid = 1;
3903 memcpy (bgp_static->tag, tag, 3);
3904 rn->info = bgp_static;
3905
3906 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3907 }
3908
3909 return CMD_SUCCESS;
3910}
3911
3912/* Configure static BGP network. */
3913int
paulfd79ac92004-10-13 05:06:08 +00003914bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3915 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003916{
3917 int ret;
3918 struct bgp *bgp;
3919 struct prefix p;
3920 struct prefix_rd prd;
3921 struct bgp_node *prn;
3922 struct bgp_node *rn;
3923 struct bgp_table *table;
3924 struct bgp_static *bgp_static;
3925 u_char tag[3];
3926
3927 bgp = vty->index;
3928
3929 /* Convert IP prefix string to struct prefix. */
3930 ret = str2prefix (ip_str, &p);
3931 if (! ret)
3932 {
3933 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3934 return CMD_WARNING;
3935 }
3936 apply_mask (&p);
3937
3938 ret = str2prefix_rd (rd_str, &prd);
3939 if (! ret)
3940 {
3941 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3942 return CMD_WARNING;
3943 }
3944
3945 ret = str2tag (tag_str, tag);
3946 if (! ret)
3947 {
3948 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3949 return CMD_WARNING;
3950 }
3951
3952 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3953 (struct prefix *)&prd);
3954 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003955 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003956 else
3957 bgp_unlock_node (prn);
3958 table = prn->info;
3959
3960 rn = bgp_node_lookup (table, &p);
3961
3962 if (rn)
3963 {
3964 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3965
3966 bgp_static = rn->info;
3967 bgp_static_free (bgp_static);
3968 rn->info = NULL;
3969 bgp_unlock_node (rn);
3970 bgp_unlock_node (rn);
3971 }
3972 else
3973 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3974
3975 return CMD_SUCCESS;
3976}
3977
3978DEFUN (bgp_network,
3979 bgp_network_cmd,
3980 "network A.B.C.D/M",
3981 "Specify a network to announce via BGP\n"
3982 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3983{
3984 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003985 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003986}
3987
3988DEFUN (bgp_network_route_map,
3989 bgp_network_route_map_cmd,
3990 "network A.B.C.D/M route-map WORD",
3991 "Specify a network to announce via BGP\n"
3992 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3993 "Route-map to modify the attributes\n"
3994 "Name of the route map\n")
3995{
3996 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003997 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003998}
3999
4000DEFUN (bgp_network_backdoor,
4001 bgp_network_backdoor_cmd,
4002 "network A.B.C.D/M backdoor",
4003 "Specify a network to announce via BGP\n"
4004 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4005 "Specify a BGP backdoor route\n")
4006{
Paul Jakma41367172007-08-06 15:24:51 +00004007 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004008 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004009}
4010
4011DEFUN (bgp_network_mask,
4012 bgp_network_mask_cmd,
4013 "network A.B.C.D mask A.B.C.D",
4014 "Specify a network to announce via BGP\n"
4015 "Network number\n"
4016 "Network mask\n"
4017 "Network mask\n")
4018{
4019 int ret;
4020 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004021
paul718e3742002-12-13 20:15:29 +00004022 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4023 if (! ret)
4024 {
4025 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4026 return CMD_WARNING;
4027 }
4028
4029 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004030 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004031}
4032
4033DEFUN (bgp_network_mask_route_map,
4034 bgp_network_mask_route_map_cmd,
4035 "network A.B.C.D mask A.B.C.D route-map WORD",
4036 "Specify a network to announce via BGP\n"
4037 "Network number\n"
4038 "Network mask\n"
4039 "Network mask\n"
4040 "Route-map to modify the attributes\n"
4041 "Name of the route map\n")
4042{
4043 int ret;
4044 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004045
paul718e3742002-12-13 20:15:29 +00004046 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4047 if (! ret)
4048 {
4049 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4050 return CMD_WARNING;
4051 }
4052
4053 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004054 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004055}
4056
4057DEFUN (bgp_network_mask_backdoor,
4058 bgp_network_mask_backdoor_cmd,
4059 "network A.B.C.D mask A.B.C.D backdoor",
4060 "Specify a network to announce via BGP\n"
4061 "Network number\n"
4062 "Network mask\n"
4063 "Network mask\n"
4064 "Specify a BGP backdoor route\n")
4065{
4066 int ret;
4067 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004068
paul718e3742002-12-13 20:15:29 +00004069 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4070 if (! ret)
4071 {
4072 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4073 return CMD_WARNING;
4074 }
4075
Paul Jakma41367172007-08-06 15:24:51 +00004076 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004077 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004078}
4079
4080DEFUN (bgp_network_mask_natural,
4081 bgp_network_mask_natural_cmd,
4082 "network A.B.C.D",
4083 "Specify a network to announce via BGP\n"
4084 "Network number\n")
4085{
4086 int ret;
4087 char prefix_str[BUFSIZ];
4088
4089 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4090 if (! ret)
4091 {
4092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4093 return CMD_WARNING;
4094 }
4095
4096 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004097 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004098}
4099
4100DEFUN (bgp_network_mask_natural_route_map,
4101 bgp_network_mask_natural_route_map_cmd,
4102 "network A.B.C.D route-map WORD",
4103 "Specify a network to announce via BGP\n"
4104 "Network number\n"
4105 "Route-map to modify the attributes\n"
4106 "Name of the route map\n")
4107{
4108 int ret;
4109 char prefix_str[BUFSIZ];
4110
4111 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4112 if (! ret)
4113 {
4114 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4115 return CMD_WARNING;
4116 }
4117
4118 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004119 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004120}
4121
4122DEFUN (bgp_network_mask_natural_backdoor,
4123 bgp_network_mask_natural_backdoor_cmd,
4124 "network A.B.C.D backdoor",
4125 "Specify a network to announce via BGP\n"
4126 "Network number\n"
4127 "Specify a BGP backdoor route\n")
4128{
4129 int ret;
4130 char prefix_str[BUFSIZ];
4131
4132 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4133 if (! ret)
4134 {
4135 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4136 return CMD_WARNING;
4137 }
4138
Paul Jakma41367172007-08-06 15:24:51 +00004139 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004140 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004141}
4142
4143DEFUN (no_bgp_network,
4144 no_bgp_network_cmd,
4145 "no network A.B.C.D/M",
4146 NO_STR
4147 "Specify a network to announce via BGP\n"
4148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4149{
4150 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4151 bgp_node_safi (vty));
4152}
4153
4154ALIAS (no_bgp_network,
4155 no_bgp_network_route_map_cmd,
4156 "no network A.B.C.D/M route-map WORD",
4157 NO_STR
4158 "Specify a network to announce via BGP\n"
4159 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4160 "Route-map to modify the attributes\n"
4161 "Name of the route map\n")
4162
4163ALIAS (no_bgp_network,
4164 no_bgp_network_backdoor_cmd,
4165 "no network A.B.C.D/M backdoor",
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 "Specify a BGP backdoor route\n")
4170
4171DEFUN (no_bgp_network_mask,
4172 no_bgp_network_mask_cmd,
4173 "no network A.B.C.D mask A.B.C.D",
4174 NO_STR
4175 "Specify a network to announce via BGP\n"
4176 "Network number\n"
4177 "Network mask\n"
4178 "Network mask\n")
4179{
4180 int ret;
4181 char prefix_str[BUFSIZ];
4182
4183 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4184 if (! ret)
4185 {
4186 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4187 return CMD_WARNING;
4188 }
4189
4190 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4191 bgp_node_safi (vty));
4192}
4193
4194ALIAS (no_bgp_network_mask,
4195 no_bgp_network_mask_route_map_cmd,
4196 "no network A.B.C.D mask A.B.C.D route-map WORD",
4197 NO_STR
4198 "Specify a network to announce via BGP\n"
4199 "Network number\n"
4200 "Network mask\n"
4201 "Network mask\n"
4202 "Route-map to modify the attributes\n"
4203 "Name of the route map\n")
4204
4205ALIAS (no_bgp_network_mask,
4206 no_bgp_network_mask_backdoor_cmd,
4207 "no network A.B.C.D mask A.B.C.D backdoor",
4208 NO_STR
4209 "Specify a network to announce via BGP\n"
4210 "Network number\n"
4211 "Network mask\n"
4212 "Network mask\n"
4213 "Specify a BGP backdoor route\n")
4214
4215DEFUN (no_bgp_network_mask_natural,
4216 no_bgp_network_mask_natural_cmd,
4217 "no network A.B.C.D",
4218 NO_STR
4219 "Specify a network to announce via BGP\n"
4220 "Network number\n")
4221{
4222 int ret;
4223 char prefix_str[BUFSIZ];
4224
4225 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4226 if (! ret)
4227 {
4228 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4229 return CMD_WARNING;
4230 }
4231
4232 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4233 bgp_node_safi (vty));
4234}
4235
4236ALIAS (no_bgp_network_mask_natural,
4237 no_bgp_network_mask_natural_route_map_cmd,
4238 "no network A.B.C.D route-map WORD",
4239 NO_STR
4240 "Specify a network to announce via BGP\n"
4241 "Network number\n"
4242 "Route-map to modify the attributes\n"
4243 "Name of the route map\n")
4244
4245ALIAS (no_bgp_network_mask_natural,
4246 no_bgp_network_mask_natural_backdoor_cmd,
4247 "no network A.B.C.D backdoor",
4248 NO_STR
4249 "Specify a network to announce via BGP\n"
4250 "Network number\n"
4251 "Specify a BGP backdoor route\n")
4252
4253#ifdef HAVE_IPV6
4254DEFUN (ipv6_bgp_network,
4255 ipv6_bgp_network_cmd,
4256 "network X:X::X:X/M",
4257 "Specify a network to announce via BGP\n"
4258 "IPv6 prefix <network>/<length>\n")
4259{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304260 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004261 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004262}
4263
4264DEFUN (ipv6_bgp_network_route_map,
4265 ipv6_bgp_network_route_map_cmd,
4266 "network X:X::X:X/M route-map WORD",
4267 "Specify a network to announce via BGP\n"
4268 "IPv6 prefix <network>/<length>\n"
4269 "Route-map to modify the attributes\n"
4270 "Name of the route map\n")
4271{
4272 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004273 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004274}
4275
4276DEFUN (no_ipv6_bgp_network,
4277 no_ipv6_bgp_network_cmd,
4278 "no network X:X::X:X/M",
4279 NO_STR
4280 "Specify a network to announce via BGP\n"
4281 "IPv6 prefix <network>/<length>\n")
4282{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304283 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004284}
4285
4286ALIAS (no_ipv6_bgp_network,
4287 no_ipv6_bgp_network_route_map_cmd,
4288 "no network X:X::X:X/M route-map WORD",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "IPv6 prefix <network>/<length>\n"
4292 "Route-map to modify the attributes\n"
4293 "Name of the route map\n")
4294
4295ALIAS (ipv6_bgp_network,
4296 old_ipv6_bgp_network_cmd,
4297 "ipv6 bgp network X:X::X:X/M",
4298 IPV6_STR
4299 BGP_STR
4300 "Specify a network to announce via BGP\n"
4301 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4302
4303ALIAS (no_ipv6_bgp_network,
4304 old_no_ipv6_bgp_network_cmd,
4305 "no ipv6 bgp network X:X::X:X/M",
4306 NO_STR
4307 IPV6_STR
4308 BGP_STR
4309 "Specify a network to announce via BGP\n"
4310 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4311#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004312
4313/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4314ALIAS_DEPRECATED (bgp_network,
4315 bgp_network_ttl_cmd,
4316 "network A.B.C.D/M pathlimit <0-255>",
4317 "Specify a network to announce via BGP\n"
4318 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321ALIAS_DEPRECATED (bgp_network_backdoor,
4322 bgp_network_backdoor_ttl_cmd,
4323 "network A.B.C.D/M backdoor pathlimit <0-255>",
4324 "Specify a network to announce via BGP\n"
4325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4326 "Specify a BGP backdoor route\n"
4327 "AS-Path hopcount limit attribute\n"
4328 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4329ALIAS_DEPRECATED (bgp_network_mask,
4330 bgp_network_mask_ttl_cmd,
4331 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4332 "Specify a network to announce via BGP\n"
4333 "Network number\n"
4334 "Network mask\n"
4335 "Network mask\n"
4336 "AS-Path hopcount limit attribute\n"
4337 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4338ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4339 bgp_network_mask_backdoor_ttl_cmd,
4340 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4341 "Specify a network to announce via BGP\n"
4342 "Network number\n"
4343 "Network mask\n"
4344 "Network mask\n"
4345 "Specify a BGP backdoor route\n"
4346 "AS-Path hopcount limit attribute\n"
4347 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4348ALIAS_DEPRECATED (bgp_network_mask_natural,
4349 bgp_network_mask_natural_ttl_cmd,
4350 "network A.B.C.D pathlimit <0-255>",
4351 "Specify a network to announce via BGP\n"
4352 "Network number\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4356 bgp_network_mask_natural_backdoor_ttl_cmd,
4357 "network A.B.C.D backdoor pathlimit (1-255>",
4358 "Specify a network to announce via BGP\n"
4359 "Network number\n"
4360 "Specify a BGP backdoor route\n"
4361 "AS-Path hopcount limit attribute\n"
4362 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4363ALIAS_DEPRECATED (no_bgp_network,
4364 no_bgp_network_ttl_cmd,
4365 "no network A.B.C.D/M pathlimit <0-255>",
4366 NO_STR
4367 "Specify a network to announce via BGP\n"
4368 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4369 "AS-Path hopcount limit attribute\n"
4370 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4371ALIAS_DEPRECATED (no_bgp_network,
4372 no_bgp_network_backdoor_ttl_cmd,
4373 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4374 NO_STR
4375 "Specify a network to announce via BGP\n"
4376 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4377 "Specify a BGP backdoor route\n"
4378 "AS-Path hopcount limit attribute\n"
4379 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4380ALIAS_DEPRECATED (no_bgp_network,
4381 no_bgp_network_mask_ttl_cmd,
4382 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4383 NO_STR
4384 "Specify a network to announce via BGP\n"
4385 "Network number\n"
4386 "Network mask\n"
4387 "Network mask\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (no_bgp_network_mask,
4391 no_bgp_network_mask_backdoor_ttl_cmd,
4392 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4393 NO_STR
4394 "Specify a network to announce via BGP\n"
4395 "Network number\n"
4396 "Network mask\n"
4397 "Network mask\n"
4398 "Specify a BGP backdoor route\n"
4399 "AS-Path hopcount limit attribute\n"
4400 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4401ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4402 no_bgp_network_mask_natural_ttl_cmd,
4403 "no network A.B.C.D pathlimit <0-255>",
4404 NO_STR
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4410 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4411 "no network A.B.C.D backdoor pathlimit <0-255>",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "Network number\n"
4415 "Specify a BGP backdoor route\n"
4416 "AS-Path hopcount limit attribute\n"
4417 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004418#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004419ALIAS_DEPRECATED (ipv6_bgp_network,
4420 ipv6_bgp_network_ttl_cmd,
4421 "network X:X::X:X/M pathlimit <0-255>",
4422 "Specify a network to announce via BGP\n"
4423 "IPv6 prefix <network>/<length>\n"
4424 "AS-Path hopcount limit attribute\n"
4425 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4426ALIAS_DEPRECATED (no_ipv6_bgp_network,
4427 no_ipv6_bgp_network_ttl_cmd,
4428 "no network X:X::X:X/M pathlimit <0-255>",
4429 NO_STR
4430 "Specify a network to announce via BGP\n"
4431 "IPv6 prefix <network>/<length>\n"
4432 "AS-Path hopcount limit attribute\n"
4433 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004434#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004435
4436/* Aggreagete address:
4437
4438 advertise-map Set condition to advertise attribute
4439 as-set Generate AS set path information
4440 attribute-map Set attributes of aggregate
4441 route-map Set parameters of aggregate
4442 summary-only Filter more specific routes from updates
4443 suppress-map Conditionally filter more specific routes from updates
4444 <cr>
4445 */
4446struct bgp_aggregate
4447{
4448 /* Summary-only flag. */
4449 u_char summary_only;
4450
4451 /* AS set generation. */
4452 u_char as_set;
4453
4454 /* Route-map for aggregated route. */
4455 struct route_map *map;
4456
4457 /* Suppress-count. */
4458 unsigned long count;
4459
4460 /* SAFI configuration. */
4461 safi_t safi;
4462};
4463
paul94f2b392005-06-28 12:44:16 +00004464static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004465bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004466{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004467 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004468}
4469
paul94f2b392005-06-28 12:44:16 +00004470static void
paul718e3742002-12-13 20:15:29 +00004471bgp_aggregate_free (struct bgp_aggregate *aggregate)
4472{
4473 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4474}
4475
paul94f2b392005-06-28 12:44:16 +00004476static void
paul718e3742002-12-13 20:15:29 +00004477bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4478 afi_t afi, safi_t safi, struct bgp_info *del,
4479 struct bgp_aggregate *aggregate)
4480{
4481 struct bgp_table *table;
4482 struct bgp_node *top;
4483 struct bgp_node *rn;
4484 u_char origin;
4485 struct aspath *aspath = NULL;
4486 struct aspath *asmerge = NULL;
4487 struct community *community = NULL;
4488 struct community *commerge = NULL;
4489 struct in_addr nexthop;
4490 u_int32_t med = 0;
4491 struct bgp_info *ri;
4492 struct bgp_info *new;
4493 int first = 1;
4494 unsigned long match = 0;
4495
4496 /* Record adding route's nexthop and med. */
4497 if (rinew)
4498 {
4499 nexthop = rinew->attr->nexthop;
4500 med = rinew->attr->med;
4501 }
4502
4503 /* ORIGIN attribute: If at least one route among routes that are
4504 aggregated has ORIGIN with the value INCOMPLETE, then the
4505 aggregated route must have the ORIGIN attribute with the value
4506 INCOMPLETE. Otherwise, if at least one route among routes that
4507 are aggregated has ORIGIN with the value EGP, then the aggregated
4508 route must have the origin attribute with the value EGP. In all
4509 other case the value of the ORIGIN attribute of the aggregated
4510 route is INTERNAL. */
4511 origin = BGP_ORIGIN_IGP;
4512
4513 table = bgp->rib[afi][safi];
4514
4515 top = bgp_node_get (table, p);
4516 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4517 if (rn->p.prefixlen > p->prefixlen)
4518 {
4519 match = 0;
4520
4521 for (ri = rn->info; ri; ri = ri->next)
4522 {
4523 if (BGP_INFO_HOLDDOWN (ri))
4524 continue;
4525
4526 if (del && ri == del)
4527 continue;
4528
4529 if (! rinew && first)
4530 {
4531 nexthop = ri->attr->nexthop;
4532 med = ri->attr->med;
4533 first = 0;
4534 }
4535
4536#ifdef AGGREGATE_NEXTHOP_CHECK
4537 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4538 || ri->attr->med != med)
4539 {
4540 if (aspath)
4541 aspath_free (aspath);
4542 if (community)
4543 community_free (community);
4544 bgp_unlock_node (rn);
4545 bgp_unlock_node (top);
4546 return;
4547 }
4548#endif /* AGGREGATE_NEXTHOP_CHECK */
4549
4550 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4551 {
4552 if (aggregate->summary_only)
4553 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004554 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004555 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004556 match++;
4557 }
4558
4559 aggregate->count++;
4560
4561 if (aggregate->as_set)
4562 {
4563 if (origin < ri->attr->origin)
4564 origin = ri->attr->origin;
4565
4566 if (aspath)
4567 {
4568 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4569 aspath_free (aspath);
4570 aspath = asmerge;
4571 }
4572 else
4573 aspath = aspath_dup (ri->attr->aspath);
4574
4575 if (ri->attr->community)
4576 {
4577 if (community)
4578 {
4579 commerge = community_merge (community,
4580 ri->attr->community);
4581 community = community_uniq_sort (commerge);
4582 community_free (commerge);
4583 }
4584 else
4585 community = community_dup (ri->attr->community);
4586 }
4587 }
4588 }
4589 }
4590 if (match)
4591 bgp_process (bgp, rn, afi, safi);
4592 }
4593 bgp_unlock_node (top);
4594
4595 if (rinew)
4596 {
4597 aggregate->count++;
4598
4599 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004600 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004601
4602 if (aggregate->as_set)
4603 {
4604 if (origin < rinew->attr->origin)
4605 origin = rinew->attr->origin;
4606
4607 if (aspath)
4608 {
4609 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4610 aspath_free (aspath);
4611 aspath = asmerge;
4612 }
4613 else
4614 aspath = aspath_dup (rinew->attr->aspath);
4615
4616 if (rinew->attr->community)
4617 {
4618 if (community)
4619 {
4620 commerge = community_merge (community,
4621 rinew->attr->community);
4622 community = community_uniq_sort (commerge);
4623 community_free (commerge);
4624 }
4625 else
4626 community = community_dup (rinew->attr->community);
4627 }
4628 }
4629 }
4630
4631 if (aggregate->count > 0)
4632 {
4633 rn = bgp_node_get (table, p);
4634 new = bgp_info_new ();
4635 new->type = ZEBRA_ROUTE_BGP;
4636 new->sub_type = BGP_ROUTE_AGGREGATE;
4637 new->peer = bgp->peer_self;
4638 SET_FLAG (new->flags, BGP_INFO_VALID);
4639 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004640 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004641
4642 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004643 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004644 bgp_process (bgp, rn, afi, safi);
4645 }
4646 else
4647 {
4648 if (aspath)
4649 aspath_free (aspath);
4650 if (community)
4651 community_free (community);
4652 }
4653}
4654
4655void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4656 struct bgp_aggregate *);
4657
4658void
4659bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4660 struct bgp_info *ri, afi_t afi, safi_t safi)
4661{
4662 struct bgp_node *child;
4663 struct bgp_node *rn;
4664 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004665 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004666
4667 /* MPLS-VPN aggregation is not yet supported. */
4668 if (safi == SAFI_MPLS_VPN)
4669 return;
4670
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004671 table = bgp->aggregate[afi][safi];
4672
4673 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004674 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004675 return;
4676
paul718e3742002-12-13 20:15:29 +00004677 if (p->prefixlen == 0)
4678 return;
4679
4680 if (BGP_INFO_HOLDDOWN (ri))
4681 return;
4682
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004683 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004684
4685 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004686 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004687 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4688 {
4689 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004690 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004691 }
4692 bgp_unlock_node (child);
4693}
4694
4695void
4696bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4697 struct bgp_info *del, afi_t afi, safi_t safi)
4698{
4699 struct bgp_node *child;
4700 struct bgp_node *rn;
4701 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004702 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004703
4704 /* MPLS-VPN aggregation is not yet supported. */
4705 if (safi == SAFI_MPLS_VPN)
4706 return;
4707
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004708 table = bgp->aggregate[afi][safi];
4709
4710 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004711 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004712 return;
4713
paul718e3742002-12-13 20:15:29 +00004714 if (p->prefixlen == 0)
4715 return;
4716
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004717 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004718
4719 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004720 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004721 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4722 {
4723 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004724 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004725 }
4726 bgp_unlock_node (child);
4727}
4728
paul94f2b392005-06-28 12:44:16 +00004729static void
paul718e3742002-12-13 20:15:29 +00004730bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4731 struct bgp_aggregate *aggregate)
4732{
4733 struct bgp_table *table;
4734 struct bgp_node *top;
4735 struct bgp_node *rn;
4736 struct bgp_info *new;
4737 struct bgp_info *ri;
4738 unsigned long match;
4739 u_char origin = BGP_ORIGIN_IGP;
4740 struct aspath *aspath = NULL;
4741 struct aspath *asmerge = NULL;
4742 struct community *community = NULL;
4743 struct community *commerge = NULL;
4744
4745 table = bgp->rib[afi][safi];
4746
4747 /* Sanity check. */
4748 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4749 return;
4750 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4751 return;
4752
4753 /* If routes exists below this node, generate aggregate routes. */
4754 top = bgp_node_get (table, p);
4755 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4756 if (rn->p.prefixlen > p->prefixlen)
4757 {
4758 match = 0;
4759
4760 for (ri = rn->info; ri; ri = ri->next)
4761 {
4762 if (BGP_INFO_HOLDDOWN (ri))
4763 continue;
4764
4765 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4766 {
4767 /* summary-only aggregate route suppress aggregated
4768 route announcement. */
4769 if (aggregate->summary_only)
4770 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004771 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004772 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004773 match++;
4774 }
4775 /* as-set aggregate route generate origin, as path,
4776 community aggregation. */
4777 if (aggregate->as_set)
4778 {
4779 if (origin < ri->attr->origin)
4780 origin = ri->attr->origin;
4781
4782 if (aspath)
4783 {
4784 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4785 aspath_free (aspath);
4786 aspath = asmerge;
4787 }
4788 else
4789 aspath = aspath_dup (ri->attr->aspath);
4790
4791 if (ri->attr->community)
4792 {
4793 if (community)
4794 {
4795 commerge = community_merge (community,
4796 ri->attr->community);
4797 community = community_uniq_sort (commerge);
4798 community_free (commerge);
4799 }
4800 else
4801 community = community_dup (ri->attr->community);
4802 }
4803 }
4804 aggregate->count++;
4805 }
4806 }
4807
4808 /* If this node is suppressed, process the change. */
4809 if (match)
4810 bgp_process (bgp, rn, afi, safi);
4811 }
4812 bgp_unlock_node (top);
4813
4814 /* Add aggregate route to BGP table. */
4815 if (aggregate->count)
4816 {
4817 rn = bgp_node_get (table, p);
4818
4819 new = bgp_info_new ();
4820 new->type = ZEBRA_ROUTE_BGP;
4821 new->sub_type = BGP_ROUTE_AGGREGATE;
4822 new->peer = bgp->peer_self;
4823 SET_FLAG (new->flags, BGP_INFO_VALID);
4824 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004825 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004826
4827 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004828 bgp_unlock_node (rn);
4829
paul718e3742002-12-13 20:15:29 +00004830 /* Process change. */
4831 bgp_process (bgp, rn, afi, safi);
4832 }
4833}
4834
4835void
4836bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4837 safi_t safi, struct bgp_aggregate *aggregate)
4838{
4839 struct bgp_table *table;
4840 struct bgp_node *top;
4841 struct bgp_node *rn;
4842 struct bgp_info *ri;
4843 unsigned long match;
4844
4845 table = bgp->rib[afi][safi];
4846
4847 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4848 return;
4849 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4850 return;
4851
4852 /* If routes exists below this node, generate aggregate routes. */
4853 top = bgp_node_get (table, p);
4854 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4855 if (rn->p.prefixlen > p->prefixlen)
4856 {
4857 match = 0;
4858
4859 for (ri = rn->info; ri; ri = ri->next)
4860 {
4861 if (BGP_INFO_HOLDDOWN (ri))
4862 continue;
4863
4864 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4865 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004866 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004867 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004868 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004869
Paul Jakmafb982c22007-05-04 20:15:47 +00004870 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004871 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004872 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004873 match++;
4874 }
4875 }
4876 aggregate->count--;
4877 }
4878 }
4879
Paul Jakmafb982c22007-05-04 20:15:47 +00004880 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004881 if (match)
4882 bgp_process (bgp, rn, afi, safi);
4883 }
4884 bgp_unlock_node (top);
4885
4886 /* Delete aggregate route from BGP table. */
4887 rn = bgp_node_get (table, p);
4888
4889 for (ri = rn->info; ri; ri = ri->next)
4890 if (ri->peer == bgp->peer_self
4891 && ri->type == ZEBRA_ROUTE_BGP
4892 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4893 break;
4894
4895 /* Withdraw static BGP route from routing table. */
4896 if (ri)
4897 {
paul718e3742002-12-13 20:15:29 +00004898 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004899 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004900 }
4901
4902 /* Unlock bgp_node_lookup. */
4903 bgp_unlock_node (rn);
4904}
4905
4906/* Aggregate route attribute. */
4907#define AGGREGATE_SUMMARY_ONLY 1
4908#define AGGREGATE_AS_SET 1
4909
paul94f2b392005-06-28 12:44:16 +00004910static int
Robert Baysf6269b42010-08-05 10:26:28 -07004911bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4912 afi_t afi, safi_t safi)
4913{
4914 int ret;
4915 struct prefix p;
4916 struct bgp_node *rn;
4917 struct bgp *bgp;
4918 struct bgp_aggregate *aggregate;
4919
4920 /* Convert string to prefix structure. */
4921 ret = str2prefix (prefix_str, &p);
4922 if (!ret)
4923 {
4924 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4925 return CMD_WARNING;
4926 }
4927 apply_mask (&p);
4928
4929 /* Get BGP structure. */
4930 bgp = vty->index;
4931
4932 /* Old configuration check. */
4933 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4934 if (! rn)
4935 {
4936 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4937 VTY_NEWLINE);
4938 return CMD_WARNING;
4939 }
4940
4941 aggregate = rn->info;
4942 if (aggregate->safi & SAFI_UNICAST)
4943 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4944 if (aggregate->safi & SAFI_MULTICAST)
4945 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4946
4947 /* Unlock aggregate address configuration. */
4948 rn->info = NULL;
4949 bgp_aggregate_free (aggregate);
4950 bgp_unlock_node (rn);
4951 bgp_unlock_node (rn);
4952
4953 return CMD_SUCCESS;
4954}
4955
4956static int
4957bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004958 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004959 u_char summary_only, u_char as_set)
4960{
4961 int ret;
4962 struct prefix p;
4963 struct bgp_node *rn;
4964 struct bgp *bgp;
4965 struct bgp_aggregate *aggregate;
4966
4967 /* Convert string to prefix structure. */
4968 ret = str2prefix (prefix_str, &p);
4969 if (!ret)
4970 {
4971 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4972 return CMD_WARNING;
4973 }
4974 apply_mask (&p);
4975
4976 /* Get BGP structure. */
4977 bgp = vty->index;
4978
4979 /* Old configuration check. */
4980 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4981
4982 if (rn->info)
4983 {
4984 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004985 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004986 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4987 if (ret)
4988 {
Robert Bays368473f2010-08-05 10:26:29 -07004989 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4990 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004991 return CMD_WARNING;
4992 }
paul718e3742002-12-13 20:15:29 +00004993 }
4994
4995 /* Make aggregate address structure. */
4996 aggregate = bgp_aggregate_new ();
4997 aggregate->summary_only = summary_only;
4998 aggregate->as_set = as_set;
4999 aggregate->safi = safi;
5000 rn->info = aggregate;
5001
5002 /* Aggregate address insert into BGP routing table. */
5003 if (safi & SAFI_UNICAST)
5004 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5005 if (safi & SAFI_MULTICAST)
5006 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5007
5008 return CMD_SUCCESS;
5009}
5010
paul718e3742002-12-13 20:15:29 +00005011DEFUN (aggregate_address,
5012 aggregate_address_cmd,
5013 "aggregate-address A.B.C.D/M",
5014 "Configure BGP aggregate entries\n"
5015 "Aggregate prefix\n")
5016{
5017 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5018}
5019
5020DEFUN (aggregate_address_mask,
5021 aggregate_address_mask_cmd,
5022 "aggregate-address A.B.C.D A.B.C.D",
5023 "Configure BGP aggregate entries\n"
5024 "Aggregate address\n"
5025 "Aggregate mask\n")
5026{
5027 int ret;
5028 char prefix_str[BUFSIZ];
5029
5030 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5031
5032 if (! ret)
5033 {
5034 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5035 return CMD_WARNING;
5036 }
5037
5038 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5039 0, 0);
5040}
5041
5042DEFUN (aggregate_address_summary_only,
5043 aggregate_address_summary_only_cmd,
5044 "aggregate-address A.B.C.D/M summary-only",
5045 "Configure BGP aggregate entries\n"
5046 "Aggregate prefix\n"
5047 "Filter more specific routes from updates\n")
5048{
5049 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5050 AGGREGATE_SUMMARY_ONLY, 0);
5051}
5052
5053DEFUN (aggregate_address_mask_summary_only,
5054 aggregate_address_mask_summary_only_cmd,
5055 "aggregate-address A.B.C.D A.B.C.D summary-only",
5056 "Configure BGP aggregate entries\n"
5057 "Aggregate address\n"
5058 "Aggregate mask\n"
5059 "Filter more specific routes from updates\n")
5060{
5061 int ret;
5062 char prefix_str[BUFSIZ];
5063
5064 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5065
5066 if (! ret)
5067 {
5068 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5069 return CMD_WARNING;
5070 }
5071
5072 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5073 AGGREGATE_SUMMARY_ONLY, 0);
5074}
5075
5076DEFUN (aggregate_address_as_set,
5077 aggregate_address_as_set_cmd,
5078 "aggregate-address A.B.C.D/M as-set",
5079 "Configure BGP aggregate entries\n"
5080 "Aggregate prefix\n"
5081 "Generate AS set path information\n")
5082{
5083 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5084 0, AGGREGATE_AS_SET);
5085}
5086
5087DEFUN (aggregate_address_mask_as_set,
5088 aggregate_address_mask_as_set_cmd,
5089 "aggregate-address A.B.C.D A.B.C.D as-set",
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate address\n"
5092 "Aggregate mask\n"
5093 "Generate AS set path information\n")
5094{
5095 int ret;
5096 char prefix_str[BUFSIZ];
5097
5098 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5099
5100 if (! ret)
5101 {
5102 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5103 return CMD_WARNING;
5104 }
5105
5106 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5107 0, AGGREGATE_AS_SET);
5108}
5109
5110
5111DEFUN (aggregate_address_as_set_summary,
5112 aggregate_address_as_set_summary_cmd,
5113 "aggregate-address A.B.C.D/M as-set summary-only",
5114 "Configure BGP aggregate entries\n"
5115 "Aggregate prefix\n"
5116 "Generate AS set path information\n"
5117 "Filter more specific routes from updates\n")
5118{
5119 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5120 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5121}
5122
5123ALIAS (aggregate_address_as_set_summary,
5124 aggregate_address_summary_as_set_cmd,
5125 "aggregate-address A.B.C.D/M summary-only as-set",
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate prefix\n"
5128 "Filter more specific routes from updates\n"
5129 "Generate AS set path information\n")
5130
5131DEFUN (aggregate_address_mask_as_set_summary,
5132 aggregate_address_mask_as_set_summary_cmd,
5133 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5134 "Configure BGP aggregate entries\n"
5135 "Aggregate address\n"
5136 "Aggregate mask\n"
5137 "Generate AS set path information\n"
5138 "Filter more specific routes from updates\n")
5139{
5140 int ret;
5141 char prefix_str[BUFSIZ];
5142
5143 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5144
5145 if (! ret)
5146 {
5147 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5148 return CMD_WARNING;
5149 }
5150
5151 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5152 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5153}
5154
5155ALIAS (aggregate_address_mask_as_set_summary,
5156 aggregate_address_mask_summary_as_set_cmd,
5157 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5158 "Configure BGP aggregate entries\n"
5159 "Aggregate address\n"
5160 "Aggregate mask\n"
5161 "Filter more specific routes from updates\n"
5162 "Generate AS set path information\n")
5163
5164DEFUN (no_aggregate_address,
5165 no_aggregate_address_cmd,
5166 "no aggregate-address A.B.C.D/M",
5167 NO_STR
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate prefix\n")
5170{
5171 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5172}
5173
5174ALIAS (no_aggregate_address,
5175 no_aggregate_address_summary_only_cmd,
5176 "no aggregate-address A.B.C.D/M summary-only",
5177 NO_STR
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate prefix\n"
5180 "Filter more specific routes from updates\n")
5181
5182ALIAS (no_aggregate_address,
5183 no_aggregate_address_as_set_cmd,
5184 "no aggregate-address A.B.C.D/M as-set",
5185 NO_STR
5186 "Configure BGP aggregate entries\n"
5187 "Aggregate prefix\n"
5188 "Generate AS set path information\n")
5189
5190ALIAS (no_aggregate_address,
5191 no_aggregate_address_as_set_summary_cmd,
5192 "no aggregate-address A.B.C.D/M as-set summary-only",
5193 NO_STR
5194 "Configure BGP aggregate entries\n"
5195 "Aggregate prefix\n"
5196 "Generate AS set path information\n"
5197 "Filter more specific routes from updates\n")
5198
5199ALIAS (no_aggregate_address,
5200 no_aggregate_address_summary_as_set_cmd,
5201 "no aggregate-address A.B.C.D/M summary-only as-set",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate prefix\n"
5205 "Filter more specific routes from updates\n"
5206 "Generate AS set path information\n")
5207
5208DEFUN (no_aggregate_address_mask,
5209 no_aggregate_address_mask_cmd,
5210 "no aggregate-address A.B.C.D A.B.C.D",
5211 NO_STR
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate address\n"
5214 "Aggregate mask\n")
5215{
5216 int ret;
5217 char prefix_str[BUFSIZ];
5218
5219 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5220
5221 if (! ret)
5222 {
5223 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5224 return CMD_WARNING;
5225 }
5226
5227 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5228}
5229
5230ALIAS (no_aggregate_address_mask,
5231 no_aggregate_address_mask_summary_only_cmd,
5232 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5233 NO_STR
5234 "Configure BGP aggregate entries\n"
5235 "Aggregate address\n"
5236 "Aggregate mask\n"
5237 "Filter more specific routes from updates\n")
5238
5239ALIAS (no_aggregate_address_mask,
5240 no_aggregate_address_mask_as_set_cmd,
5241 "no aggregate-address A.B.C.D A.B.C.D as-set",
5242 NO_STR
5243 "Configure BGP aggregate entries\n"
5244 "Aggregate address\n"
5245 "Aggregate mask\n"
5246 "Generate AS set path information\n")
5247
5248ALIAS (no_aggregate_address_mask,
5249 no_aggregate_address_mask_as_set_summary_cmd,
5250 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5251 NO_STR
5252 "Configure BGP aggregate entries\n"
5253 "Aggregate address\n"
5254 "Aggregate mask\n"
5255 "Generate AS set path information\n"
5256 "Filter more specific routes from updates\n")
5257
5258ALIAS (no_aggregate_address_mask,
5259 no_aggregate_address_mask_summary_as_set_cmd,
5260 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5261 NO_STR
5262 "Configure BGP aggregate entries\n"
5263 "Aggregate address\n"
5264 "Aggregate mask\n"
5265 "Filter more specific routes from updates\n"
5266 "Generate AS set path information\n")
5267
5268#ifdef HAVE_IPV6
5269DEFUN (ipv6_aggregate_address,
5270 ipv6_aggregate_address_cmd,
5271 "aggregate-address X:X::X:X/M",
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate prefix\n")
5274{
5275 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5276}
5277
5278DEFUN (ipv6_aggregate_address_summary_only,
5279 ipv6_aggregate_address_summary_only_cmd,
5280 "aggregate-address X:X::X:X/M summary-only",
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate prefix\n"
5283 "Filter more specific routes from updates\n")
5284{
5285 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5286 AGGREGATE_SUMMARY_ONLY, 0);
5287}
5288
5289DEFUN (no_ipv6_aggregate_address,
5290 no_ipv6_aggregate_address_cmd,
5291 "no aggregate-address X:X::X:X/M",
5292 NO_STR
5293 "Configure BGP aggregate entries\n"
5294 "Aggregate prefix\n")
5295{
5296 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5297}
5298
5299DEFUN (no_ipv6_aggregate_address_summary_only,
5300 no_ipv6_aggregate_address_summary_only_cmd,
5301 "no aggregate-address X:X::X:X/M summary-only",
5302 NO_STR
5303 "Configure BGP aggregate entries\n"
5304 "Aggregate prefix\n"
5305 "Filter more specific routes from updates\n")
5306{
5307 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5308}
5309
5310ALIAS (ipv6_aggregate_address,
5311 old_ipv6_aggregate_address_cmd,
5312 "ipv6 bgp aggregate-address X:X::X:X/M",
5313 IPV6_STR
5314 BGP_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate prefix\n")
5317
5318ALIAS (ipv6_aggregate_address_summary_only,
5319 old_ipv6_aggregate_address_summary_only_cmd,
5320 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5321 IPV6_STR
5322 BGP_STR
5323 "Configure BGP aggregate entries\n"
5324 "Aggregate prefix\n"
5325 "Filter more specific routes from updates\n")
5326
5327ALIAS (no_ipv6_aggregate_address,
5328 old_no_ipv6_aggregate_address_cmd,
5329 "no ipv6 bgp aggregate-address X:X::X:X/M",
5330 NO_STR
5331 IPV6_STR
5332 BGP_STR
5333 "Configure BGP aggregate entries\n"
5334 "Aggregate prefix\n")
5335
5336ALIAS (no_ipv6_aggregate_address_summary_only,
5337 old_no_ipv6_aggregate_address_summary_only_cmd,
5338 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5339 NO_STR
5340 IPV6_STR
5341 BGP_STR
5342 "Configure BGP aggregate entries\n"
5343 "Aggregate prefix\n"
5344 "Filter more specific routes from updates\n")
5345#endif /* HAVE_IPV6 */
5346
5347/* Redistribute route treatment. */
5348void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005349bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5350 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005351 u_int32_t metric, u_char type)
5352{
5353 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005354 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005355 struct bgp_info *new;
5356 struct bgp_info *bi;
5357 struct bgp_info info;
5358 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005359 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005360 struct attr *new_attr;
5361 afi_t afi;
5362 int ret;
5363
5364 /* Make default attribute. */
5365 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5366 if (nexthop)
5367 attr.nexthop = *nexthop;
5368
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005369#ifdef HAVE_IPV6
5370 if (nexthop6)
5371 {
5372 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5373 extra->mp_nexthop_global = *nexthop6;
5374 extra->mp_nexthop_len = 16;
5375 }
5376#endif
5377
paul718e3742002-12-13 20:15:29 +00005378 attr.med = metric;
5379 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5380
paul1eb8ef22005-04-07 07:30:20 +00005381 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005382 {
5383 afi = family2afi (p->family);
5384
5385 if (bgp->redist[afi][type])
5386 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005387 struct attr attr_new;
5388 struct attr_extra extra_new;
5389
paul718e3742002-12-13 20:15:29 +00005390 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005391 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005392 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005393
5394 if (bgp->redist_metric_flag[afi][type])
5395 attr_new.med = bgp->redist_metric[afi][type];
5396
5397 /* Apply route-map. */
5398 if (bgp->rmap[afi][type].map)
5399 {
5400 info.peer = bgp->peer_self;
5401 info.attr = &attr_new;
5402
paulfee0f4c2004-09-13 05:12:46 +00005403 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5404
paul718e3742002-12-13 20:15:29 +00005405 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5406 &info);
paulfee0f4c2004-09-13 05:12:46 +00005407
5408 bgp->peer_self->rmap_type = 0;
5409
paul718e3742002-12-13 20:15:29 +00005410 if (ret == RMAP_DENYMATCH)
5411 {
5412 /* Free uninterned attribute. */
5413 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005414
paul718e3742002-12-13 20:15:29 +00005415 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005416 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005418 bgp_redistribute_delete (p, type);
5419 return;
5420 }
5421 }
5422
Paul Jakmafb982c22007-05-04 20:15:47 +00005423 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5424 afi, SAFI_UNICAST, p, NULL);
5425
paul718e3742002-12-13 20:15:29 +00005426 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005427
paul718e3742002-12-13 20:15:29 +00005428 for (bi = bn->info; bi; bi = bi->next)
5429 if (bi->peer == bgp->peer_self
5430 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5431 break;
5432
5433 if (bi)
5434 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005435 if (attrhash_cmp (bi->attr, new_attr) &&
5436 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005437 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005438 bgp_attr_unintern (&new_attr);
5439 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005440 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005441 bgp_unlock_node (bn);
5442 return;
5443 }
5444 else
5445 {
5446 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005447 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005448
5449 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005450 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5451 bgp_info_restore(bn, bi);
5452 else
5453 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005454 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005455 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005456 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005457
5458 /* Process change. */
5459 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5460 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5461 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005462 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005463 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005464 return;
5465 }
5466 }
5467
5468 new = bgp_info_new ();
5469 new->type = type;
5470 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5471 new->peer = bgp->peer_self;
5472 SET_FLAG (new->flags, BGP_INFO_VALID);
5473 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005474 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005475
5476 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5477 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005478 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005479 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5480 }
5481 }
5482
5483 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005484 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005485 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005486}
5487
5488void
5489bgp_redistribute_delete (struct prefix *p, u_char type)
5490{
5491 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005492 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005493 afi_t afi;
5494 struct bgp_node *rn;
5495 struct bgp_info *ri;
5496
paul1eb8ef22005-04-07 07:30:20 +00005497 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005498 {
5499 afi = family2afi (p->family);
5500
5501 if (bgp->redist[afi][type])
5502 {
paulfee0f4c2004-09-13 05:12:46 +00005503 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005504
5505 for (ri = rn->info; ri; ri = ri->next)
5506 if (ri->peer == bgp->peer_self
5507 && ri->type == type)
5508 break;
5509
5510 if (ri)
5511 {
5512 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005513 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005514 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005515 }
5516 bgp_unlock_node (rn);
5517 }
5518 }
5519}
5520
5521/* Withdraw specified route type's route. */
5522void
5523bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5524{
5525 struct bgp_node *rn;
5526 struct bgp_info *ri;
5527 struct bgp_table *table;
5528
5529 table = bgp->rib[afi][SAFI_UNICAST];
5530
5531 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5532 {
5533 for (ri = rn->info; ri; ri = ri->next)
5534 if (ri->peer == bgp->peer_self
5535 && ri->type == type)
5536 break;
5537
5538 if (ri)
5539 {
5540 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005541 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005542 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005543 }
5544 }
5545}
5546
5547/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005548static void
paul718e3742002-12-13 20:15:29 +00005549route_vty_out_route (struct prefix *p, struct vty *vty)
5550{
5551 int len;
5552 u_int32_t destination;
5553 char buf[BUFSIZ];
5554
5555 if (p->family == AF_INET)
5556 {
5557 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5558 destination = ntohl (p->u.prefix4.s_addr);
5559
5560 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5561 || (IN_CLASSB (destination) && p->prefixlen == 16)
5562 || (IN_CLASSA (destination) && p->prefixlen == 8)
5563 || p->u.prefix4.s_addr == 0)
5564 {
5565 /* When mask is natural, mask is not displayed. */
5566 }
5567 else
5568 len += vty_out (vty, "/%d", p->prefixlen);
5569 }
5570 else
5571 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5572 p->prefixlen);
5573
5574 len = 17 - len;
5575 if (len < 1)
5576 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5577 else
5578 vty_out (vty, "%*s", len, " ");
5579}
5580
paul718e3742002-12-13 20:15:29 +00005581enum bgp_display_type
5582{
5583 normal_list,
5584};
5585
paulb40d9392005-08-22 22:34:41 +00005586/* Print the short form route status for a bgp_info */
5587static void
5588route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005589{
paulb40d9392005-08-22 22:34:41 +00005590 /* Route status display. */
5591 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5592 vty_out (vty, "R");
5593 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005594 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005595 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005596 vty_out (vty, "s");
5597 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5598 vty_out (vty, "*");
5599 else
5600 vty_out (vty, " ");
5601
5602 /* Selected */
5603 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5604 vty_out (vty, "h");
5605 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5606 vty_out (vty, "d");
5607 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5608 vty_out (vty, ">");
5609 else
5610 vty_out (vty, " ");
5611
5612 /* Internal route. */
5613 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5614 vty_out (vty, "i");
5615 else
paulb40d9392005-08-22 22:34:41 +00005616 vty_out (vty, " ");
5617}
5618
5619/* called from terminal list command */
5620void
5621route_vty_out (struct vty *vty, struct prefix *p,
5622 struct bgp_info *binfo, int display, safi_t safi)
5623{
5624 struct attr *attr;
5625
5626 /* short status lead text */
5627 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005628
5629 /* print prefix and mask */
5630 if (! display)
5631 route_vty_out_route (p, vty);
5632 else
5633 vty_out (vty, "%*s", 17, " ");
5634
5635 /* Print attribute */
5636 attr = binfo->attr;
5637 if (attr)
5638 {
5639 if (p->family == AF_INET)
5640 {
5641 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005642 vty_out (vty, "%-16s",
5643 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005644 else
5645 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5646 }
5647#ifdef HAVE_IPV6
5648 else if (p->family == AF_INET6)
5649 {
5650 int len;
5651 char buf[BUFSIZ];
5652
5653 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005654 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5655 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005656 len = 16 - len;
5657 if (len < 1)
5658 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5659 else
5660 vty_out (vty, "%*s", len, " ");
5661 }
5662#endif /* HAVE_IPV6 */
5663
5664 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005665 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005666 else
5667 vty_out (vty, " ");
5668
5669 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005670 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005671 else
5672 vty_out (vty, " ");
5673
Paul Jakmafb982c22007-05-04 20:15:47 +00005674 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005675
Paul Jakmab2518c12006-05-12 23:48:40 +00005676 /* Print aspath */
5677 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005678 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005679
Paul Jakmab2518c12006-05-12 23:48:40 +00005680 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005681 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005682 }
paul718e3742002-12-13 20:15:29 +00005683 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005684}
5685
5686/* called from terminal list command */
5687void
5688route_vty_out_tmp (struct vty *vty, struct prefix *p,
5689 struct attr *attr, safi_t safi)
5690{
5691 /* Route status display. */
5692 vty_out (vty, "*");
5693 vty_out (vty, ">");
5694 vty_out (vty, " ");
5695
5696 /* print prefix and mask */
5697 route_vty_out_route (p, vty);
5698
5699 /* Print attribute */
5700 if (attr)
5701 {
5702 if (p->family == AF_INET)
5703 {
5704 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005705 vty_out (vty, "%-16s",
5706 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005707 else
5708 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5709 }
5710#ifdef HAVE_IPV6
5711 else if (p->family == AF_INET6)
5712 {
5713 int len;
5714 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005715
5716 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005717
5718 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005719 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5720 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005721 len = 16 - len;
5722 if (len < 1)
5723 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5724 else
5725 vty_out (vty, "%*s", len, " ");
5726 }
5727#endif /* HAVE_IPV6 */
5728
5729 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005730 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005731 else
5732 vty_out (vty, " ");
5733
5734 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005735 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005736 else
5737 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005738
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005739 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005740
Paul Jakmab2518c12006-05-12 23:48:40 +00005741 /* Print aspath */
5742 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005743 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005744
Paul Jakmab2518c12006-05-12 23:48:40 +00005745 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005746 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005747 }
paul718e3742002-12-13 20:15:29 +00005748
5749 vty_out (vty, "%s", VTY_NEWLINE);
5750}
5751
ajs5a646652004-11-05 01:25:55 +00005752void
paul718e3742002-12-13 20:15:29 +00005753route_vty_out_tag (struct vty *vty, struct prefix *p,
5754 struct bgp_info *binfo, int display, safi_t safi)
5755{
5756 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005757 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005758
5759 if (!binfo->extra)
5760 return;
5761
paulb40d9392005-08-22 22:34:41 +00005762 /* short status lead text */
5763 route_vty_short_status_out (vty, binfo);
5764
paul718e3742002-12-13 20:15:29 +00005765 /* print prefix and mask */
5766 if (! display)
5767 route_vty_out_route (p, vty);
5768 else
5769 vty_out (vty, "%*s", 17, " ");
5770
5771 /* Print attribute */
5772 attr = binfo->attr;
5773 if (attr)
5774 {
5775 if (p->family == AF_INET)
5776 {
5777 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005778 vty_out (vty, "%-16s",
5779 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005780 else
5781 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5782 }
5783#ifdef HAVE_IPV6
5784 else if (p->family == AF_INET6)
5785 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005787 char buf[BUFSIZ];
5788 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005789 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005790 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005791 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5792 buf, BUFSIZ));
5793 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005794 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005795 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5796 buf, BUFSIZ),
5797 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5798 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005799
5800 }
5801#endif /* HAVE_IPV6 */
5802 }
5803
Paul Jakmafb982c22007-05-04 20:15:47 +00005804 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005805
5806 vty_out (vty, "notag/%d", label);
5807
5808 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005809}
5810
5811/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005812static void
paul718e3742002-12-13 20:15:29 +00005813damp_route_vty_out (struct vty *vty, struct prefix *p,
5814 struct bgp_info *binfo, int display, safi_t safi)
5815{
5816 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005817 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005818 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005819
paulb40d9392005-08-22 22:34:41 +00005820 /* short status lead text */
5821 route_vty_short_status_out (vty, binfo);
5822
paul718e3742002-12-13 20:15:29 +00005823 /* print prefix and mask */
5824 if (! display)
5825 route_vty_out_route (p, vty);
5826 else
5827 vty_out (vty, "%*s", 17, " ");
5828
5829 len = vty_out (vty, "%s", binfo->peer->host);
5830 len = 17 - len;
5831 if (len < 1)
5832 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5833 else
5834 vty_out (vty, "%*s", len, " ");
5835
Chris Caputo50aef6f2009-06-23 06:06:49 +00005836 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005837
5838 /* Print attribute */
5839 attr = binfo->attr;
5840 if (attr)
5841 {
5842 /* Print aspath */
5843 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005844 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005845
5846 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005847 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005848 }
5849 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005850}
5851
paul718e3742002-12-13 20:15:29 +00005852/* flap route */
ajs5a646652004-11-05 01:25:55 +00005853static void
paul718e3742002-12-13 20:15:29 +00005854flap_route_vty_out (struct vty *vty, struct prefix *p,
5855 struct bgp_info *binfo, int display, safi_t safi)
5856{
5857 struct attr *attr;
5858 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005859 char timebuf[BGP_UPTIME_LEN];
5860 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005861
5862 if (!binfo->extra)
5863 return;
5864
5865 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005866
paulb40d9392005-08-22 22:34:41 +00005867 /* short status lead text */
5868 route_vty_short_status_out (vty, binfo);
5869
paul718e3742002-12-13 20:15:29 +00005870 /* print prefix and mask */
5871 if (! display)
5872 route_vty_out_route (p, vty);
5873 else
5874 vty_out (vty, "%*s", 17, " ");
5875
5876 len = vty_out (vty, "%s", binfo->peer->host);
5877 len = 16 - len;
5878 if (len < 1)
5879 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5880 else
5881 vty_out (vty, "%*s", len, " ");
5882
5883 len = vty_out (vty, "%d", bdi->flap);
5884 len = 5 - len;
5885 if (len < 1)
5886 vty_out (vty, " ");
5887 else
5888 vty_out (vty, "%*s ", len, " ");
5889
5890 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5891 timebuf, BGP_UPTIME_LEN));
5892
5893 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5894 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005895 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005896 else
5897 vty_out (vty, "%*s ", 8, " ");
5898
5899 /* Print attribute */
5900 attr = binfo->attr;
5901 if (attr)
5902 {
5903 /* Print aspath */
5904 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005905 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005906
5907 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005908 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005909 }
5910 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005911}
5912
paul94f2b392005-06-28 12:44:16 +00005913static void
paul718e3742002-12-13 20:15:29 +00005914route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5915 struct bgp_info *binfo, afi_t afi, safi_t safi)
5916{
5917 char buf[INET6_ADDRSTRLEN];
5918 char buf1[BUFSIZ];
5919 struct attr *attr;
5920 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005921#ifdef HAVE_CLOCK_MONOTONIC
5922 time_t tbuf;
5923#endif
paul718e3742002-12-13 20:15:29 +00005924
5925 attr = binfo->attr;
5926
5927 if (attr)
5928 {
5929 /* Line1 display AS-path, Aggregator */
5930 if (attr->aspath)
5931 {
5932 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005933 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005934 vty_out (vty, "Local");
5935 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005936 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005937 }
5938
paulb40d9392005-08-22 22:34:41 +00005939 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5940 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005941 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5942 vty_out (vty, ", (stale)");
5943 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005944 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005945 attr->extra->aggregator_as,
5946 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005947 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5948 vty_out (vty, ", (Received from a RR-client)");
5949 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5950 vty_out (vty, ", (Received from a RS-client)");
5951 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5952 vty_out (vty, ", (history entry)");
5953 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5954 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005955 vty_out (vty, "%s", VTY_NEWLINE);
5956
5957 /* Line2 display Next-hop, Neighbor, Router-id */
5958 if (p->family == AF_INET)
5959 {
5960 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005961 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005962 inet_ntoa (attr->nexthop));
5963 }
5964#ifdef HAVE_IPV6
5965 else
5966 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005967 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005968 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005969 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005970 buf, INET6_ADDRSTRLEN));
5971 }
5972#endif /* HAVE_IPV6 */
5973
5974 if (binfo->peer == bgp->peer_self)
5975 {
5976 vty_out (vty, " from %s ",
5977 p->family == AF_INET ? "0.0.0.0" : "::");
5978 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5979 }
5980 else
5981 {
5982 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5983 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005984 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005985 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005986 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005987 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005989 else
5990 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5991 }
5992 vty_out (vty, "%s", VTY_NEWLINE);
5993
5994#ifdef HAVE_IPV6
5995 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005996 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005997 {
5998 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005999 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006000 buf, INET6_ADDRSTRLEN),
6001 VTY_NEWLINE);
6002 }
6003#endif /* HAVE_IPV6 */
6004
6005 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6006 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6007
6008 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006009 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006010
6011 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006012 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006013 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006014 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006015
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006017 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006018
6019 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6020 vty_out (vty, ", valid");
6021
6022 if (binfo->peer != bgp->peer_self)
6023 {
6024 if (binfo->peer->as == binfo->peer->local_as)
6025 vty_out (vty, ", internal");
6026 else
6027 vty_out (vty, ", %s",
6028 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6029 }
6030 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6031 vty_out (vty, ", aggregated, local");
6032 else if (binfo->type != ZEBRA_ROUTE_BGP)
6033 vty_out (vty, ", sourced");
6034 else
6035 vty_out (vty, ", sourced, local");
6036
6037 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6038 vty_out (vty, ", atomic-aggregate");
6039
Josh Baileyde8d5df2011-07-20 20:46:01 -07006040 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6041 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6042 bgp_info_mpath_count (binfo)))
6043 vty_out (vty, ", multipath");
6044
paul718e3742002-12-13 20:15:29 +00006045 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6046 vty_out (vty, ", best");
6047
6048 vty_out (vty, "%s", VTY_NEWLINE);
6049
6050 /* Line 4 display Community */
6051 if (attr->community)
6052 vty_out (vty, " Community: %s%s", attr->community->str,
6053 VTY_NEWLINE);
6054
6055 /* Line 5 display Extended-community */
6056 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 vty_out (vty, " Extended Community: %s%s",
6058 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006059
6060 /* Line 6 display Originator, Cluster-id */
6061 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6062 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6063 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006064 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006065 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006066 vty_out (vty, " Originator: %s",
6067 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006068
6069 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6070 {
6071 int i;
6072 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006073 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6074 vty_out (vty, "%s ",
6075 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006076 }
6077 vty_out (vty, "%s", VTY_NEWLINE);
6078 }
Paul Jakma41367172007-08-06 15:24:51 +00006079
Paul Jakmafb982c22007-05-04 20:15:47 +00006080 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006081 bgp_damp_info_vty (vty, binfo);
6082
6083 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006084#ifdef HAVE_CLOCK_MONOTONIC
6085 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006086 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006087#else
6088 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6089#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006090 }
6091 vty_out (vty, "%s", VTY_NEWLINE);
6092}
6093
paulb40d9392005-08-22 22:34:41 +00006094#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 +00006095#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006096#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6097#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6098#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6099
6100enum bgp_show_type
6101{
6102 bgp_show_type_normal,
6103 bgp_show_type_regexp,
6104 bgp_show_type_prefix_list,
6105 bgp_show_type_filter_list,
6106 bgp_show_type_route_map,
6107 bgp_show_type_neighbor,
6108 bgp_show_type_cidr_only,
6109 bgp_show_type_prefix_longer,
6110 bgp_show_type_community_all,
6111 bgp_show_type_community,
6112 bgp_show_type_community_exact,
6113 bgp_show_type_community_list,
6114 bgp_show_type_community_list_exact,
6115 bgp_show_type_flap_statistics,
6116 bgp_show_type_flap_address,
6117 bgp_show_type_flap_prefix,
6118 bgp_show_type_flap_cidr_only,
6119 bgp_show_type_flap_regexp,
6120 bgp_show_type_flap_filter_list,
6121 bgp_show_type_flap_prefix_list,
6122 bgp_show_type_flap_prefix_longer,
6123 bgp_show_type_flap_route_map,
6124 bgp_show_type_flap_neighbor,
6125 bgp_show_type_dampend_paths,
6126 bgp_show_type_damp_neighbor
6127};
6128
ajs5a646652004-11-05 01:25:55 +00006129static int
paulfee0f4c2004-09-13 05:12:46 +00006130bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006131 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006132{
paul718e3742002-12-13 20:15:29 +00006133 struct bgp_info *ri;
6134 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006135 int header = 1;
paul718e3742002-12-13 20:15:29 +00006136 int display;
ajs5a646652004-11-05 01:25:55 +00006137 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006138
6139 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006140 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006141
paul718e3742002-12-13 20:15:29 +00006142 /* Start processing of routes. */
6143 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6144 if (rn->info != NULL)
6145 {
6146 display = 0;
6147
6148 for (ri = rn->info; ri; ri = ri->next)
6149 {
ajs5a646652004-11-05 01:25:55 +00006150 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006151 || type == bgp_show_type_flap_address
6152 || type == bgp_show_type_flap_prefix
6153 || type == bgp_show_type_flap_cidr_only
6154 || type == bgp_show_type_flap_regexp
6155 || type == bgp_show_type_flap_filter_list
6156 || type == bgp_show_type_flap_prefix_list
6157 || type == bgp_show_type_flap_prefix_longer
6158 || type == bgp_show_type_flap_route_map
6159 || type == bgp_show_type_flap_neighbor
6160 || type == bgp_show_type_dampend_paths
6161 || type == bgp_show_type_damp_neighbor)
6162 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006163 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006164 continue;
6165 }
6166 if (type == bgp_show_type_regexp
6167 || type == bgp_show_type_flap_regexp)
6168 {
ajs5a646652004-11-05 01:25:55 +00006169 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006170
6171 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6172 continue;
6173 }
6174 if (type == bgp_show_type_prefix_list
6175 || type == bgp_show_type_flap_prefix_list)
6176 {
ajs5a646652004-11-05 01:25:55 +00006177 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006178
6179 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6180 continue;
6181 }
6182 if (type == bgp_show_type_filter_list
6183 || type == bgp_show_type_flap_filter_list)
6184 {
ajs5a646652004-11-05 01:25:55 +00006185 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006186
6187 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6188 continue;
6189 }
6190 if (type == bgp_show_type_route_map
6191 || type == bgp_show_type_flap_route_map)
6192 {
ajs5a646652004-11-05 01:25:55 +00006193 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006194 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006195 struct attr dummy_attr;
6196 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006197 int ret;
6198
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006199 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006200 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006201
paul718e3742002-12-13 20:15:29 +00006202 binfo.peer = ri->peer;
6203 binfo.attr = &dummy_attr;
6204
6205 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006206 if (ret == RMAP_DENYMATCH)
6207 continue;
6208 }
6209 if (type == bgp_show_type_neighbor
6210 || type == bgp_show_type_flap_neighbor
6211 || type == bgp_show_type_damp_neighbor)
6212 {
ajs5a646652004-11-05 01:25:55 +00006213 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006214
6215 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6216 continue;
6217 }
6218 if (type == bgp_show_type_cidr_only
6219 || type == bgp_show_type_flap_cidr_only)
6220 {
6221 u_int32_t destination;
6222
6223 destination = ntohl (rn->p.u.prefix4.s_addr);
6224 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6225 continue;
6226 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6227 continue;
6228 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6229 continue;
6230 }
6231 if (type == bgp_show_type_prefix_longer
6232 || type == bgp_show_type_flap_prefix_longer)
6233 {
ajs5a646652004-11-05 01:25:55 +00006234 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006235
6236 if (! prefix_match (p, &rn->p))
6237 continue;
6238 }
6239 if (type == bgp_show_type_community_all)
6240 {
6241 if (! ri->attr->community)
6242 continue;
6243 }
6244 if (type == bgp_show_type_community)
6245 {
ajs5a646652004-11-05 01:25:55 +00006246 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006247
6248 if (! ri->attr->community ||
6249 ! community_match (ri->attr->community, com))
6250 continue;
6251 }
6252 if (type == bgp_show_type_community_exact)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (! ri->attr->community ||
6257 ! community_cmp (ri->attr->community, com))
6258 continue;
6259 }
6260 if (type == bgp_show_type_community_list)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006263
6264 if (! community_list_match (ri->attr->community, list))
6265 continue;
6266 }
6267 if (type == bgp_show_type_community_list_exact)
6268 {
ajs5a646652004-11-05 01:25:55 +00006269 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006270
6271 if (! community_list_exact_match (ri->attr->community, list))
6272 continue;
6273 }
6274 if (type == bgp_show_type_flap_address
6275 || type == bgp_show_type_flap_prefix)
6276 {
ajs5a646652004-11-05 01:25:55 +00006277 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006278
6279 if (! prefix_match (&rn->p, p))
6280 continue;
6281
6282 if (type == bgp_show_type_flap_prefix)
6283 if (p->prefixlen != rn->p.prefixlen)
6284 continue;
6285 }
6286 if (type == bgp_show_type_dampend_paths
6287 || type == bgp_show_type_damp_neighbor)
6288 {
6289 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6290 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6291 continue;
6292 }
6293
6294 if (header)
6295 {
hasso93406d82005-02-02 14:40:33 +00006296 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6297 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6298 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006299 if (type == bgp_show_type_dampend_paths
6300 || type == bgp_show_type_damp_neighbor)
6301 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6302 else if (type == bgp_show_type_flap_statistics
6303 || type == bgp_show_type_flap_address
6304 || type == bgp_show_type_flap_prefix
6305 || type == bgp_show_type_flap_cidr_only
6306 || type == bgp_show_type_flap_regexp
6307 || type == bgp_show_type_flap_filter_list
6308 || type == bgp_show_type_flap_prefix_list
6309 || type == bgp_show_type_flap_prefix_longer
6310 || type == bgp_show_type_flap_route_map
6311 || type == bgp_show_type_flap_neighbor)
6312 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6313 else
6314 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006315 header = 0;
6316 }
6317
6318 if (type == bgp_show_type_dampend_paths
6319 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006320 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006321 else if (type == bgp_show_type_flap_statistics
6322 || type == bgp_show_type_flap_address
6323 || type == bgp_show_type_flap_prefix
6324 || type == bgp_show_type_flap_cidr_only
6325 || type == bgp_show_type_flap_regexp
6326 || type == bgp_show_type_flap_filter_list
6327 || type == bgp_show_type_flap_prefix_list
6328 || type == bgp_show_type_flap_prefix_longer
6329 || type == bgp_show_type_flap_route_map
6330 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006331 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006332 else
ajs5a646652004-11-05 01:25:55 +00006333 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006334 display++;
6335 }
6336 if (display)
ajs5a646652004-11-05 01:25:55 +00006337 output_count++;
paul718e3742002-12-13 20:15:29 +00006338 }
6339
6340 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006341 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006342 {
6343 if (type == bgp_show_type_normal)
6344 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6345 }
6346 else
6347 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006348 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006349
6350 return CMD_SUCCESS;
6351}
6352
ajs5a646652004-11-05 01:25:55 +00006353static int
paulfee0f4c2004-09-13 05:12:46 +00006354bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006355 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006356{
6357 struct bgp_table *table;
6358
6359 if (bgp == NULL) {
6360 bgp = bgp_get_default ();
6361 }
6362
6363 if (bgp == NULL)
6364 {
6365 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6366 return CMD_WARNING;
6367 }
6368
6369
6370 table = bgp->rib[afi][safi];
6371
ajs5a646652004-11-05 01:25:55 +00006372 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006373}
6374
paul718e3742002-12-13 20:15:29 +00006375/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006376static void
paul718e3742002-12-13 20:15:29 +00006377route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6378 struct bgp_node *rn,
6379 struct prefix_rd *prd, afi_t afi, safi_t safi)
6380{
6381 struct bgp_info *ri;
6382 struct prefix *p;
6383 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006384 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006385 char buf1[INET6_ADDRSTRLEN];
6386 char buf2[INET6_ADDRSTRLEN];
6387 int count = 0;
6388 int best = 0;
6389 int suppress = 0;
6390 int no_export = 0;
6391 int no_advertise = 0;
6392 int local_as = 0;
6393 int first = 0;
6394
6395 p = &rn->p;
6396 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6397 (safi == SAFI_MPLS_VPN ?
6398 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6399 safi == SAFI_MPLS_VPN ? ":" : "",
6400 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6401 p->prefixlen, VTY_NEWLINE);
6402
6403 for (ri = rn->info; ri; ri = ri->next)
6404 {
6405 count++;
6406 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6407 {
6408 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006409 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006410 suppress = 1;
6411 if (ri->attr->community != NULL)
6412 {
6413 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6414 no_advertise = 1;
6415 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6416 no_export = 1;
6417 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6418 local_as = 1;
6419 }
6420 }
6421 }
6422
6423 vty_out (vty, "Paths: (%d available", count);
6424 if (best)
6425 {
6426 vty_out (vty, ", best #%d", best);
6427 if (safi == SAFI_UNICAST)
6428 vty_out (vty, ", table Default-IP-Routing-Table");
6429 }
6430 else
6431 vty_out (vty, ", no best path");
6432 if (no_advertise)
6433 vty_out (vty, ", not advertised to any peer");
6434 else if (no_export)
6435 vty_out (vty, ", not advertised to EBGP peer");
6436 else if (local_as)
6437 vty_out (vty, ", not advertised outside local AS");
6438 if (suppress)
6439 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6440 vty_out (vty, ")%s", VTY_NEWLINE);
6441
6442 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006443 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006444 {
6445 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6446 {
6447 if (! first)
6448 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6449 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6450 first = 1;
6451 }
6452 }
6453 if (! first)
6454 vty_out (vty, " Not advertised to any peer");
6455 vty_out (vty, "%s", VTY_NEWLINE);
6456}
6457
6458/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006459static int
paulfee0f4c2004-09-13 05:12:46 +00006460bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006461 struct bgp_table *rib, const char *ip_str,
6462 afi_t afi, safi_t safi, struct prefix_rd *prd,
6463 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006464{
6465 int ret;
6466 int header;
6467 int display = 0;
6468 struct prefix match;
6469 struct bgp_node *rn;
6470 struct bgp_node *rm;
6471 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006472 struct bgp_table *table;
6473
paul718e3742002-12-13 20:15:29 +00006474 /* Check IP address argument. */
6475 ret = str2prefix (ip_str, &match);
6476 if (! ret)
6477 {
6478 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6479 return CMD_WARNING;
6480 }
6481
6482 match.family = afi2family (afi);
6483
6484 if (safi == SAFI_MPLS_VPN)
6485 {
paulfee0f4c2004-09-13 05:12:46 +00006486 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006487 {
6488 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6489 continue;
6490
6491 if ((table = rn->info) != NULL)
6492 {
6493 header = 1;
6494
6495 if ((rm = bgp_node_match (table, &match)) != NULL)
6496 {
6497 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006498 {
6499 bgp_unlock_node (rm);
6500 continue;
6501 }
paul718e3742002-12-13 20:15:29 +00006502
6503 for (ri = rm->info; ri; ri = ri->next)
6504 {
6505 if (header)
6506 {
6507 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6508 AFI_IP, SAFI_MPLS_VPN);
6509
6510 header = 0;
6511 }
6512 display++;
6513 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6514 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006515
6516 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006517 }
6518 }
6519 }
6520 }
6521 else
6522 {
6523 header = 1;
6524
paulfee0f4c2004-09-13 05:12:46 +00006525 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006526 {
6527 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6528 {
6529 for (ri = rn->info; ri; ri = ri->next)
6530 {
6531 if (header)
6532 {
6533 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6534 header = 0;
6535 }
6536 display++;
6537 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6538 }
6539 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006540
6541 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006542 }
6543 }
6544
6545 if (! display)
6546 {
6547 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6548 return CMD_WARNING;
6549 }
6550
6551 return CMD_SUCCESS;
6552}
6553
paulfee0f4c2004-09-13 05:12:46 +00006554/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006555static int
paulfd79ac92004-10-13 05:06:08 +00006556bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006557 afi_t afi, safi_t safi, struct prefix_rd *prd,
6558 int prefix_check)
6559{
6560 struct bgp *bgp;
6561
6562 /* BGP structure lookup. */
6563 if (view_name)
6564 {
6565 bgp = bgp_lookup_by_name (view_name);
6566 if (bgp == NULL)
6567 {
6568 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6569 return CMD_WARNING;
6570 }
6571 }
6572 else
6573 {
6574 bgp = bgp_get_default ();
6575 if (bgp == NULL)
6576 {
6577 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6578 return CMD_WARNING;
6579 }
6580 }
6581
6582 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6583 afi, safi, prd, prefix_check);
6584}
6585
paul718e3742002-12-13 20:15:29 +00006586/* BGP route print out function. */
6587DEFUN (show_ip_bgp,
6588 show_ip_bgp_cmd,
6589 "show ip bgp",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR)
6593{
ajs5a646652004-11-05 01:25:55 +00006594 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006595}
6596
6597DEFUN (show_ip_bgp_ipv4,
6598 show_ip_bgp_ipv4_cmd,
6599 "show ip bgp ipv4 (unicast|multicast)",
6600 SHOW_STR
6601 IP_STR
6602 BGP_STR
6603 "Address family\n"
6604 "Address Family modifier\n"
6605 "Address Family modifier\n")
6606{
6607 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006608 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6609 NULL);
paul718e3742002-12-13 20:15:29 +00006610
ajs5a646652004-11-05 01:25:55 +00006611 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006612}
6613
Michael Lambert95cbbd22010-07-23 14:43:04 -04006614ALIAS (show_ip_bgp_ipv4,
6615 show_bgp_ipv4_safi_cmd,
6616 "show bgp ipv4 (unicast|multicast)",
6617 SHOW_STR
6618 BGP_STR
6619 "Address family\n"
6620 "Address Family modifier\n"
6621 "Address Family modifier\n")
6622
paul718e3742002-12-13 20:15:29 +00006623DEFUN (show_ip_bgp_route,
6624 show_ip_bgp_route_cmd,
6625 "show ip bgp A.B.C.D",
6626 SHOW_STR
6627 IP_STR
6628 BGP_STR
6629 "Network in the BGP routing table to display\n")
6630{
6631 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6632}
6633
6634DEFUN (show_ip_bgp_ipv4_route,
6635 show_ip_bgp_ipv4_route_cmd,
6636 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6637 SHOW_STR
6638 IP_STR
6639 BGP_STR
6640 "Address family\n"
6641 "Address Family modifier\n"
6642 "Address Family modifier\n"
6643 "Network in the BGP routing table to display\n")
6644{
6645 if (strncmp (argv[0], "m", 1) == 0)
6646 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6647
6648 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6649}
6650
Michael Lambert95cbbd22010-07-23 14:43:04 -04006651ALIAS (show_ip_bgp_ipv4_route,
6652 show_bgp_ipv4_safi_route_cmd,
6653 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6654 SHOW_STR
6655 BGP_STR
6656 "Address family\n"
6657 "Address Family modifier\n"
6658 "Address Family modifier\n"
6659 "Network in the BGP routing table to display\n")
6660
paul718e3742002-12-13 20:15:29 +00006661DEFUN (show_ip_bgp_vpnv4_all_route,
6662 show_ip_bgp_vpnv4_all_route_cmd,
6663 "show ip bgp vpnv4 all A.B.C.D",
6664 SHOW_STR
6665 IP_STR
6666 BGP_STR
6667 "Display VPNv4 NLRI specific information\n"
6668 "Display information about all VPNv4 NLRIs\n"
6669 "Network in the BGP routing table to display\n")
6670{
6671 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6672}
6673
6674DEFUN (show_ip_bgp_vpnv4_rd_route,
6675 show_ip_bgp_vpnv4_rd_route_cmd,
6676 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6677 SHOW_STR
6678 IP_STR
6679 BGP_STR
6680 "Display VPNv4 NLRI specific information\n"
6681 "Display information for a route distinguisher\n"
6682 "VPN Route Distinguisher\n"
6683 "Network in the BGP routing table to display\n")
6684{
6685 int ret;
6686 struct prefix_rd prd;
6687
6688 ret = str2prefix_rd (argv[0], &prd);
6689 if (! ret)
6690 {
6691 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6692 return CMD_WARNING;
6693 }
6694 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6695}
6696
6697DEFUN (show_ip_bgp_prefix,
6698 show_ip_bgp_prefix_cmd,
6699 "show ip bgp A.B.C.D/M",
6700 SHOW_STR
6701 IP_STR
6702 BGP_STR
6703 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6704{
6705 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6706}
6707
6708DEFUN (show_ip_bgp_ipv4_prefix,
6709 show_ip_bgp_ipv4_prefix_cmd,
6710 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "Address family\n"
6715 "Address Family modifier\n"
6716 "Address Family modifier\n"
6717 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6718{
6719 if (strncmp (argv[0], "m", 1) == 0)
6720 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6721
6722 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6723}
6724
Michael Lambert95cbbd22010-07-23 14:43:04 -04006725ALIAS (show_ip_bgp_ipv4_prefix,
6726 show_bgp_ipv4_safi_prefix_cmd,
6727 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6728 SHOW_STR
6729 BGP_STR
6730 "Address family\n"
6731 "Address Family modifier\n"
6732 "Address Family modifier\n"
6733 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6734
paul718e3742002-12-13 20:15:29 +00006735DEFUN (show_ip_bgp_vpnv4_all_prefix,
6736 show_ip_bgp_vpnv4_all_prefix_cmd,
6737 "show ip bgp vpnv4 all A.B.C.D/M",
6738 SHOW_STR
6739 IP_STR
6740 BGP_STR
6741 "Display VPNv4 NLRI specific information\n"
6742 "Display information about all VPNv4 NLRIs\n"
6743 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6744{
6745 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6746}
6747
6748DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6749 show_ip_bgp_vpnv4_rd_prefix_cmd,
6750 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6751 SHOW_STR
6752 IP_STR
6753 BGP_STR
6754 "Display VPNv4 NLRI specific information\n"
6755 "Display information for a route distinguisher\n"
6756 "VPN Route Distinguisher\n"
6757 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6758{
6759 int ret;
6760 struct prefix_rd prd;
6761
6762 ret = str2prefix_rd (argv[0], &prd);
6763 if (! ret)
6764 {
6765 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6766 return CMD_WARNING;
6767 }
6768 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6769}
6770
6771DEFUN (show_ip_bgp_view,
6772 show_ip_bgp_view_cmd,
6773 "show ip bgp view WORD",
6774 SHOW_STR
6775 IP_STR
6776 BGP_STR
6777 "BGP view\n"
6778 "BGP view name\n")
6779{
paulbb46e942003-10-24 19:02:03 +00006780 struct bgp *bgp;
6781
6782 /* BGP structure lookup. */
6783 bgp = bgp_lookup_by_name (argv[0]);
6784 if (bgp == NULL)
6785 {
6786 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6787 return CMD_WARNING;
6788 }
6789
ajs5a646652004-11-05 01:25:55 +00006790 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006791}
6792
6793DEFUN (show_ip_bgp_view_route,
6794 show_ip_bgp_view_route_cmd,
6795 "show ip bgp view WORD A.B.C.D",
6796 SHOW_STR
6797 IP_STR
6798 BGP_STR
6799 "BGP view\n"
6800 "BGP view name\n"
6801 "Network in the BGP routing table to display\n")
6802{
6803 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6804}
6805
6806DEFUN (show_ip_bgp_view_prefix,
6807 show_ip_bgp_view_prefix_cmd,
6808 "show ip bgp view WORD A.B.C.D/M",
6809 SHOW_STR
6810 IP_STR
6811 BGP_STR
6812 "BGP view\n"
6813 "BGP view name\n"
6814 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6815{
6816 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6817}
6818
6819#ifdef HAVE_IPV6
6820DEFUN (show_bgp,
6821 show_bgp_cmd,
6822 "show bgp",
6823 SHOW_STR
6824 BGP_STR)
6825{
ajs5a646652004-11-05 01:25:55 +00006826 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6827 NULL);
paul718e3742002-12-13 20:15:29 +00006828}
6829
6830ALIAS (show_bgp,
6831 show_bgp_ipv6_cmd,
6832 "show bgp ipv6",
6833 SHOW_STR
6834 BGP_STR
6835 "Address family\n")
6836
Michael Lambert95cbbd22010-07-23 14:43:04 -04006837DEFUN (show_bgp_ipv6_safi,
6838 show_bgp_ipv6_safi_cmd,
6839 "show bgp ipv6 (unicast|multicast)",
6840 SHOW_STR
6841 BGP_STR
6842 "Address family\n"
6843 "Address Family modifier\n"
6844 "Address Family modifier\n")
6845{
6846 if (strncmp (argv[0], "m", 1) == 0)
6847 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6848 NULL);
6849
6850 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6851}
6852
paul718e3742002-12-13 20:15:29 +00006853/* old command */
6854DEFUN (show_ipv6_bgp,
6855 show_ipv6_bgp_cmd,
6856 "show ipv6 bgp",
6857 SHOW_STR
6858 IP_STR
6859 BGP_STR)
6860{
ajs5a646652004-11-05 01:25:55 +00006861 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6862 NULL);
paul718e3742002-12-13 20:15:29 +00006863}
6864
6865DEFUN (show_bgp_route,
6866 show_bgp_route_cmd,
6867 "show bgp X:X::X:X",
6868 SHOW_STR
6869 BGP_STR
6870 "Network in the BGP routing table to display\n")
6871{
6872 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6873}
6874
6875ALIAS (show_bgp_route,
6876 show_bgp_ipv6_route_cmd,
6877 "show bgp ipv6 X:X::X:X",
6878 SHOW_STR
6879 BGP_STR
6880 "Address family\n"
6881 "Network in the BGP routing table to display\n")
6882
Michael Lambert95cbbd22010-07-23 14:43:04 -04006883DEFUN (show_bgp_ipv6_safi_route,
6884 show_bgp_ipv6_safi_route_cmd,
6885 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6886 SHOW_STR
6887 BGP_STR
6888 "Address family\n"
6889 "Address Family modifier\n"
6890 "Address Family modifier\n"
6891 "Network in the BGP routing table to display\n")
6892{
6893 if (strncmp (argv[0], "m", 1) == 0)
6894 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6895
6896 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6897}
6898
paul718e3742002-12-13 20:15:29 +00006899/* old command */
6900DEFUN (show_ipv6_bgp_route,
6901 show_ipv6_bgp_route_cmd,
6902 "show ipv6 bgp X:X::X:X",
6903 SHOW_STR
6904 IP_STR
6905 BGP_STR
6906 "Network in the BGP routing table to display\n")
6907{
6908 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6909}
6910
6911DEFUN (show_bgp_prefix,
6912 show_bgp_prefix_cmd,
6913 "show bgp X:X::X:X/M",
6914 SHOW_STR
6915 BGP_STR
6916 "IPv6 prefix <network>/<length>\n")
6917{
6918 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6919}
6920
6921ALIAS (show_bgp_prefix,
6922 show_bgp_ipv6_prefix_cmd,
6923 "show bgp ipv6 X:X::X:X/M",
6924 SHOW_STR
6925 BGP_STR
6926 "Address family\n"
6927 "IPv6 prefix <network>/<length>\n")
6928
Michael Lambert95cbbd22010-07-23 14:43:04 -04006929DEFUN (show_bgp_ipv6_safi_prefix,
6930 show_bgp_ipv6_safi_prefix_cmd,
6931 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6932 SHOW_STR
6933 BGP_STR
6934 "Address family\n"
6935 "Address Family modifier\n"
6936 "Address Family modifier\n"
6937 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6938{
6939 if (strncmp (argv[0], "m", 1) == 0)
6940 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6941
6942 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6943}
6944
paul718e3742002-12-13 20:15:29 +00006945/* old command */
6946DEFUN (show_ipv6_bgp_prefix,
6947 show_ipv6_bgp_prefix_cmd,
6948 "show ipv6 bgp X:X::X:X/M",
6949 SHOW_STR
6950 IP_STR
6951 BGP_STR
6952 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6953{
6954 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6955}
6956
paulbb46e942003-10-24 19:02:03 +00006957DEFUN (show_bgp_view,
6958 show_bgp_view_cmd,
6959 "show bgp view WORD",
6960 SHOW_STR
6961 BGP_STR
6962 "BGP view\n"
6963 "View name\n")
6964{
6965 struct bgp *bgp;
6966
6967 /* BGP structure lookup. */
6968 bgp = bgp_lookup_by_name (argv[0]);
6969 if (bgp == NULL)
6970 {
6971 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6972 return CMD_WARNING;
6973 }
6974
ajs5a646652004-11-05 01:25:55 +00006975 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006976}
6977
6978ALIAS (show_bgp_view,
6979 show_bgp_view_ipv6_cmd,
6980 "show bgp view WORD ipv6",
6981 SHOW_STR
6982 BGP_STR
6983 "BGP view\n"
6984 "View name\n"
6985 "Address family\n")
6986
6987DEFUN (show_bgp_view_route,
6988 show_bgp_view_route_cmd,
6989 "show bgp view WORD X:X::X:X",
6990 SHOW_STR
6991 BGP_STR
6992 "BGP view\n"
6993 "View name\n"
6994 "Network in the BGP routing table to display\n")
6995{
6996 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6997}
6998
6999ALIAS (show_bgp_view_route,
7000 show_bgp_view_ipv6_route_cmd,
7001 "show bgp view WORD ipv6 X:X::X:X",
7002 SHOW_STR
7003 BGP_STR
7004 "BGP view\n"
7005 "View name\n"
7006 "Address family\n"
7007 "Network in the BGP routing table to display\n")
7008
7009DEFUN (show_bgp_view_prefix,
7010 show_bgp_view_prefix_cmd,
7011 "show bgp view WORD X:X::X:X/M",
7012 SHOW_STR
7013 BGP_STR
7014 "BGP view\n"
7015 "View name\n"
7016 "IPv6 prefix <network>/<length>\n")
7017{
7018 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7019}
7020
7021ALIAS (show_bgp_view_prefix,
7022 show_bgp_view_ipv6_prefix_cmd,
7023 "show bgp view WORD ipv6 X:X::X:X/M",
7024 SHOW_STR
7025 BGP_STR
7026 "BGP view\n"
7027 "View name\n"
7028 "Address family\n"
7029 "IPv6 prefix <network>/<length>\n")
7030
paul718e3742002-12-13 20:15:29 +00007031/* old command */
7032DEFUN (show_ipv6_mbgp,
7033 show_ipv6_mbgp_cmd,
7034 "show ipv6 mbgp",
7035 SHOW_STR
7036 IP_STR
7037 MBGP_STR)
7038{
ajs5a646652004-11-05 01:25:55 +00007039 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7040 NULL);
paul718e3742002-12-13 20:15:29 +00007041}
7042
7043/* old command */
7044DEFUN (show_ipv6_mbgp_route,
7045 show_ipv6_mbgp_route_cmd,
7046 "show ipv6 mbgp X:X::X:X",
7047 SHOW_STR
7048 IP_STR
7049 MBGP_STR
7050 "Network in the MBGP routing table to display\n")
7051{
7052 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7053}
7054
7055/* old command */
7056DEFUN (show_ipv6_mbgp_prefix,
7057 show_ipv6_mbgp_prefix_cmd,
7058 "show ipv6 mbgp X:X::X:X/M",
7059 SHOW_STR
7060 IP_STR
7061 MBGP_STR
7062 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7063{
7064 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7065}
7066#endif
7067
paul718e3742002-12-13 20:15:29 +00007068
paul94f2b392005-06-28 12:44:16 +00007069static int
paulfd79ac92004-10-13 05:06:08 +00007070bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007071 safi_t safi, enum bgp_show_type type)
7072{
7073 int i;
7074 struct buffer *b;
7075 char *regstr;
7076 int first;
7077 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007078 int rc;
paul718e3742002-12-13 20:15:29 +00007079
7080 first = 0;
7081 b = buffer_new (1024);
7082 for (i = 0; i < argc; i++)
7083 {
7084 if (first)
7085 buffer_putc (b, ' ');
7086 else
7087 {
7088 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7089 continue;
7090 first = 1;
7091 }
7092
7093 buffer_putstr (b, argv[i]);
7094 }
7095 buffer_putc (b, '\0');
7096
7097 regstr = buffer_getstr (b);
7098 buffer_free (b);
7099
7100 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007101 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007102 if (! regex)
7103 {
7104 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7105 VTY_NEWLINE);
7106 return CMD_WARNING;
7107 }
7108
ajs5a646652004-11-05 01:25:55 +00007109 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7110 bgp_regex_free (regex);
7111 return rc;
paul718e3742002-12-13 20:15:29 +00007112}
7113
7114DEFUN (show_ip_bgp_regexp,
7115 show_ip_bgp_regexp_cmd,
7116 "show ip bgp regexp .LINE",
7117 SHOW_STR
7118 IP_STR
7119 BGP_STR
7120 "Display routes matching the AS path regular expression\n"
7121 "A regular-expression to match the BGP AS paths\n")
7122{
7123 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7124 bgp_show_type_regexp);
7125}
7126
7127DEFUN (show_ip_bgp_flap_regexp,
7128 show_ip_bgp_flap_regexp_cmd,
7129 "show ip bgp flap-statistics regexp .LINE",
7130 SHOW_STR
7131 IP_STR
7132 BGP_STR
7133 "Display flap statistics of routes\n"
7134 "Display routes matching the AS path regular expression\n"
7135 "A regular-expression to match the BGP AS paths\n")
7136{
7137 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7138 bgp_show_type_flap_regexp);
7139}
7140
7141DEFUN (show_ip_bgp_ipv4_regexp,
7142 show_ip_bgp_ipv4_regexp_cmd,
7143 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7144 SHOW_STR
7145 IP_STR
7146 BGP_STR
7147 "Address family\n"
7148 "Address Family modifier\n"
7149 "Address Family modifier\n"
7150 "Display routes matching the AS path regular expression\n"
7151 "A regular-expression to match the BGP AS paths\n")
7152{
7153 if (strncmp (argv[0], "m", 1) == 0)
7154 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7155 bgp_show_type_regexp);
7156
7157 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7158 bgp_show_type_regexp);
7159}
7160
7161#ifdef HAVE_IPV6
7162DEFUN (show_bgp_regexp,
7163 show_bgp_regexp_cmd,
7164 "show bgp regexp .LINE",
7165 SHOW_STR
7166 BGP_STR
7167 "Display routes matching the AS path regular expression\n"
7168 "A regular-expression to match the BGP AS paths\n")
7169{
7170 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7171 bgp_show_type_regexp);
7172}
7173
7174ALIAS (show_bgp_regexp,
7175 show_bgp_ipv6_regexp_cmd,
7176 "show bgp ipv6 regexp .LINE",
7177 SHOW_STR
7178 BGP_STR
7179 "Address family\n"
7180 "Display routes matching the AS path regular expression\n"
7181 "A regular-expression to match the BGP AS paths\n")
7182
7183/* old command */
7184DEFUN (show_ipv6_bgp_regexp,
7185 show_ipv6_bgp_regexp_cmd,
7186 "show ipv6 bgp regexp .LINE",
7187 SHOW_STR
7188 IP_STR
7189 BGP_STR
7190 "Display routes matching the AS path regular expression\n"
7191 "A regular-expression to match the BGP AS paths\n")
7192{
7193 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7194 bgp_show_type_regexp);
7195}
7196
7197/* old command */
7198DEFUN (show_ipv6_mbgp_regexp,
7199 show_ipv6_mbgp_regexp_cmd,
7200 "show ipv6 mbgp regexp .LINE",
7201 SHOW_STR
7202 IP_STR
7203 BGP_STR
7204 "Display routes matching the AS path regular expression\n"
7205 "A regular-expression to match the MBGP AS paths\n")
7206{
7207 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7208 bgp_show_type_regexp);
7209}
7210#endif /* HAVE_IPV6 */
7211
paul94f2b392005-06-28 12:44:16 +00007212static int
paulfd79ac92004-10-13 05:06:08 +00007213bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007214 safi_t safi, enum bgp_show_type type)
7215{
7216 struct prefix_list *plist;
7217
7218 plist = prefix_list_lookup (afi, prefix_list_str);
7219 if (plist == NULL)
7220 {
7221 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7222 prefix_list_str, VTY_NEWLINE);
7223 return CMD_WARNING;
7224 }
7225
ajs5a646652004-11-05 01:25:55 +00007226 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007227}
7228
7229DEFUN (show_ip_bgp_prefix_list,
7230 show_ip_bgp_prefix_list_cmd,
7231 "show ip bgp prefix-list WORD",
7232 SHOW_STR
7233 IP_STR
7234 BGP_STR
7235 "Display routes conforming to the prefix-list\n"
7236 "IP prefix-list name\n")
7237{
7238 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7239 bgp_show_type_prefix_list);
7240}
7241
7242DEFUN (show_ip_bgp_flap_prefix_list,
7243 show_ip_bgp_flap_prefix_list_cmd,
7244 "show ip bgp flap-statistics prefix-list WORD",
7245 SHOW_STR
7246 IP_STR
7247 BGP_STR
7248 "Display flap statistics of routes\n"
7249 "Display routes conforming to the prefix-list\n"
7250 "IP prefix-list name\n")
7251{
7252 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7253 bgp_show_type_flap_prefix_list);
7254}
7255
7256DEFUN (show_ip_bgp_ipv4_prefix_list,
7257 show_ip_bgp_ipv4_prefix_list_cmd,
7258 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7259 SHOW_STR
7260 IP_STR
7261 BGP_STR
7262 "Address family\n"
7263 "Address Family modifier\n"
7264 "Address Family modifier\n"
7265 "Display routes conforming to the prefix-list\n"
7266 "IP prefix-list name\n")
7267{
7268 if (strncmp (argv[0], "m", 1) == 0)
7269 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7270 bgp_show_type_prefix_list);
7271
7272 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7273 bgp_show_type_prefix_list);
7274}
7275
7276#ifdef HAVE_IPV6
7277DEFUN (show_bgp_prefix_list,
7278 show_bgp_prefix_list_cmd,
7279 "show bgp prefix-list WORD",
7280 SHOW_STR
7281 BGP_STR
7282 "Display routes conforming to the prefix-list\n"
7283 "IPv6 prefix-list name\n")
7284{
7285 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7286 bgp_show_type_prefix_list);
7287}
7288
7289ALIAS (show_bgp_prefix_list,
7290 show_bgp_ipv6_prefix_list_cmd,
7291 "show bgp ipv6 prefix-list WORD",
7292 SHOW_STR
7293 BGP_STR
7294 "Address family\n"
7295 "Display routes conforming to the prefix-list\n"
7296 "IPv6 prefix-list name\n")
7297
7298/* old command */
7299DEFUN (show_ipv6_bgp_prefix_list,
7300 show_ipv6_bgp_prefix_list_cmd,
7301 "show ipv6 bgp prefix-list WORD",
7302 SHOW_STR
7303 IPV6_STR
7304 BGP_STR
7305 "Display routes matching the prefix-list\n"
7306 "IPv6 prefix-list name\n")
7307{
7308 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7309 bgp_show_type_prefix_list);
7310}
7311
7312/* old command */
7313DEFUN (show_ipv6_mbgp_prefix_list,
7314 show_ipv6_mbgp_prefix_list_cmd,
7315 "show ipv6 mbgp prefix-list WORD",
7316 SHOW_STR
7317 IPV6_STR
7318 MBGP_STR
7319 "Display routes matching the prefix-list\n"
7320 "IPv6 prefix-list name\n")
7321{
7322 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7323 bgp_show_type_prefix_list);
7324}
7325#endif /* HAVE_IPV6 */
7326
paul94f2b392005-06-28 12:44:16 +00007327static int
paulfd79ac92004-10-13 05:06:08 +00007328bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007329 safi_t safi, enum bgp_show_type type)
7330{
7331 struct as_list *as_list;
7332
7333 as_list = as_list_lookup (filter);
7334 if (as_list == NULL)
7335 {
7336 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7337 return CMD_WARNING;
7338 }
7339
ajs5a646652004-11-05 01:25:55 +00007340 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007341}
7342
7343DEFUN (show_ip_bgp_filter_list,
7344 show_ip_bgp_filter_list_cmd,
7345 "show ip bgp filter-list WORD",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Display routes conforming to the filter-list\n"
7350 "Regular expression access list name\n")
7351{
7352 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7353 bgp_show_type_filter_list);
7354}
7355
7356DEFUN (show_ip_bgp_flap_filter_list,
7357 show_ip_bgp_flap_filter_list_cmd,
7358 "show ip bgp flap-statistics filter-list WORD",
7359 SHOW_STR
7360 IP_STR
7361 BGP_STR
7362 "Display flap statistics of routes\n"
7363 "Display routes conforming to the filter-list\n"
7364 "Regular expression access list name\n")
7365{
7366 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7367 bgp_show_type_flap_filter_list);
7368}
7369
7370DEFUN (show_ip_bgp_ipv4_filter_list,
7371 show_ip_bgp_ipv4_filter_list_cmd,
7372 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7373 SHOW_STR
7374 IP_STR
7375 BGP_STR
7376 "Address family\n"
7377 "Address Family modifier\n"
7378 "Address Family modifier\n"
7379 "Display routes conforming to the filter-list\n"
7380 "Regular expression access list name\n")
7381{
7382 if (strncmp (argv[0], "m", 1) == 0)
7383 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7384 bgp_show_type_filter_list);
7385
7386 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7387 bgp_show_type_filter_list);
7388}
7389
7390#ifdef HAVE_IPV6
7391DEFUN (show_bgp_filter_list,
7392 show_bgp_filter_list_cmd,
7393 "show bgp filter-list WORD",
7394 SHOW_STR
7395 BGP_STR
7396 "Display routes conforming to the filter-list\n"
7397 "Regular expression access list name\n")
7398{
7399 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7400 bgp_show_type_filter_list);
7401}
7402
7403ALIAS (show_bgp_filter_list,
7404 show_bgp_ipv6_filter_list_cmd,
7405 "show bgp ipv6 filter-list WORD",
7406 SHOW_STR
7407 BGP_STR
7408 "Address family\n"
7409 "Display routes conforming to the filter-list\n"
7410 "Regular expression access list name\n")
7411
7412/* old command */
7413DEFUN (show_ipv6_bgp_filter_list,
7414 show_ipv6_bgp_filter_list_cmd,
7415 "show ipv6 bgp filter-list WORD",
7416 SHOW_STR
7417 IPV6_STR
7418 BGP_STR
7419 "Display routes conforming to the filter-list\n"
7420 "Regular expression access list name\n")
7421{
7422 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7423 bgp_show_type_filter_list);
7424}
7425
7426/* old command */
7427DEFUN (show_ipv6_mbgp_filter_list,
7428 show_ipv6_mbgp_filter_list_cmd,
7429 "show ipv6 mbgp filter-list WORD",
7430 SHOW_STR
7431 IPV6_STR
7432 MBGP_STR
7433 "Display routes conforming to the filter-list\n"
7434 "Regular expression access list name\n")
7435{
7436 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7437 bgp_show_type_filter_list);
7438}
7439#endif /* HAVE_IPV6 */
7440
paul94f2b392005-06-28 12:44:16 +00007441static int
paulfd79ac92004-10-13 05:06:08 +00007442bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007443 safi_t safi, enum bgp_show_type type)
7444{
7445 struct route_map *rmap;
7446
7447 rmap = route_map_lookup_by_name (rmap_str);
7448 if (! rmap)
7449 {
7450 vty_out (vty, "%% %s is not a valid route-map name%s",
7451 rmap_str, VTY_NEWLINE);
7452 return CMD_WARNING;
7453 }
7454
ajs5a646652004-11-05 01:25:55 +00007455 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007456}
7457
7458DEFUN (show_ip_bgp_route_map,
7459 show_ip_bgp_route_map_cmd,
7460 "show ip bgp route-map WORD",
7461 SHOW_STR
7462 IP_STR
7463 BGP_STR
7464 "Display routes matching the route-map\n"
7465 "A route-map to match on\n")
7466{
7467 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7468 bgp_show_type_route_map);
7469}
7470
7471DEFUN (show_ip_bgp_flap_route_map,
7472 show_ip_bgp_flap_route_map_cmd,
7473 "show ip bgp flap-statistics route-map WORD",
7474 SHOW_STR
7475 IP_STR
7476 BGP_STR
7477 "Display flap statistics of routes\n"
7478 "Display routes matching the route-map\n"
7479 "A route-map to match on\n")
7480{
7481 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7482 bgp_show_type_flap_route_map);
7483}
7484
7485DEFUN (show_ip_bgp_ipv4_route_map,
7486 show_ip_bgp_ipv4_route_map_cmd,
7487 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7488 SHOW_STR
7489 IP_STR
7490 BGP_STR
7491 "Address family\n"
7492 "Address Family modifier\n"
7493 "Address Family modifier\n"
7494 "Display routes matching the route-map\n"
7495 "A route-map to match on\n")
7496{
7497 if (strncmp (argv[0], "m", 1) == 0)
7498 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7499 bgp_show_type_route_map);
7500
7501 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7502 bgp_show_type_route_map);
7503}
7504
7505DEFUN (show_bgp_route_map,
7506 show_bgp_route_map_cmd,
7507 "show bgp route-map WORD",
7508 SHOW_STR
7509 BGP_STR
7510 "Display routes matching the route-map\n"
7511 "A route-map to match on\n")
7512{
7513 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7514 bgp_show_type_route_map);
7515}
7516
7517ALIAS (show_bgp_route_map,
7518 show_bgp_ipv6_route_map_cmd,
7519 "show bgp ipv6 route-map WORD",
7520 SHOW_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Display routes matching the route-map\n"
7524 "A route-map to match on\n")
7525
7526DEFUN (show_ip_bgp_cidr_only,
7527 show_ip_bgp_cidr_only_cmd,
7528 "show ip bgp cidr-only",
7529 SHOW_STR
7530 IP_STR
7531 BGP_STR
7532 "Display only routes with non-natural netmasks\n")
7533{
7534 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007535 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007536}
7537
7538DEFUN (show_ip_bgp_flap_cidr_only,
7539 show_ip_bgp_flap_cidr_only_cmd,
7540 "show ip bgp flap-statistics cidr-only",
7541 SHOW_STR
7542 IP_STR
7543 BGP_STR
7544 "Display flap statistics of routes\n"
7545 "Display only routes with non-natural netmasks\n")
7546{
7547 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007548 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007549}
7550
7551DEFUN (show_ip_bgp_ipv4_cidr_only,
7552 show_ip_bgp_ipv4_cidr_only_cmd,
7553 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7554 SHOW_STR
7555 IP_STR
7556 BGP_STR
7557 "Address family\n"
7558 "Address Family modifier\n"
7559 "Address Family modifier\n"
7560 "Display only routes with non-natural netmasks\n")
7561{
7562 if (strncmp (argv[0], "m", 1) == 0)
7563 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007564 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007565
7566 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007567 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007568}
7569
7570DEFUN (show_ip_bgp_community_all,
7571 show_ip_bgp_community_all_cmd,
7572 "show ip bgp community",
7573 SHOW_STR
7574 IP_STR
7575 BGP_STR
7576 "Display routes matching the communities\n")
7577{
7578 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007579 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007580}
7581
7582DEFUN (show_ip_bgp_ipv4_community_all,
7583 show_ip_bgp_ipv4_community_all_cmd,
7584 "show ip bgp ipv4 (unicast|multicast) community",
7585 SHOW_STR
7586 IP_STR
7587 BGP_STR
7588 "Address family\n"
7589 "Address Family modifier\n"
7590 "Address Family modifier\n"
7591 "Display routes matching the communities\n")
7592{
7593 if (strncmp (argv[0], "m", 1) == 0)
7594 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007595 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007596
7597 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007598 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007599}
7600
7601#ifdef HAVE_IPV6
7602DEFUN (show_bgp_community_all,
7603 show_bgp_community_all_cmd,
7604 "show bgp community",
7605 SHOW_STR
7606 BGP_STR
7607 "Display routes matching the communities\n")
7608{
7609 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007610 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007611}
7612
7613ALIAS (show_bgp_community_all,
7614 show_bgp_ipv6_community_all_cmd,
7615 "show bgp ipv6 community",
7616 SHOW_STR
7617 BGP_STR
7618 "Address family\n"
7619 "Display routes matching the communities\n")
7620
7621/* old command */
7622DEFUN (show_ipv6_bgp_community_all,
7623 show_ipv6_bgp_community_all_cmd,
7624 "show ipv6 bgp community",
7625 SHOW_STR
7626 IPV6_STR
7627 BGP_STR
7628 "Display routes matching the communities\n")
7629{
7630 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007631 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007632}
7633
7634/* old command */
7635DEFUN (show_ipv6_mbgp_community_all,
7636 show_ipv6_mbgp_community_all_cmd,
7637 "show ipv6 mbgp community",
7638 SHOW_STR
7639 IPV6_STR
7640 MBGP_STR
7641 "Display routes matching the communities\n")
7642{
7643 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007644 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007645}
7646#endif /* HAVE_IPV6 */
7647
paul94f2b392005-06-28 12:44:16 +00007648static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007649bgp_show_community (struct vty *vty, const char *view_name, int argc,
7650 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007651{
7652 struct community *com;
7653 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007654 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007655 int i;
7656 char *str;
7657 int first = 0;
7658
Michael Lambert95cbbd22010-07-23 14:43:04 -04007659 /* BGP structure lookup */
7660 if (view_name)
7661 {
7662 bgp = bgp_lookup_by_name (view_name);
7663 if (bgp == NULL)
7664 {
7665 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7666 return CMD_WARNING;
7667 }
7668 }
7669 else
7670 {
7671 bgp = bgp_get_default ();
7672 if (bgp == NULL)
7673 {
7674 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7675 return CMD_WARNING;
7676 }
7677 }
7678
paul718e3742002-12-13 20:15:29 +00007679 b = buffer_new (1024);
7680 for (i = 0; i < argc; i++)
7681 {
7682 if (first)
7683 buffer_putc (b, ' ');
7684 else
7685 {
7686 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7687 continue;
7688 first = 1;
7689 }
7690
7691 buffer_putstr (b, argv[i]);
7692 }
7693 buffer_putc (b, '\0');
7694
7695 str = buffer_getstr (b);
7696 buffer_free (b);
7697
7698 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007699 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007700 if (! com)
7701 {
7702 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7703 return CMD_WARNING;
7704 }
7705
Michael Lambert95cbbd22010-07-23 14:43:04 -04007706 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007707 (exact ? bgp_show_type_community_exact :
7708 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007709}
7710
7711DEFUN (show_ip_bgp_community,
7712 show_ip_bgp_community_cmd,
7713 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7714 SHOW_STR
7715 IP_STR
7716 BGP_STR
7717 "Display routes matching the communities\n"
7718 "community number\n"
7719 "Do not send outside local AS (well-known community)\n"
7720 "Do not advertise to any peer (well-known community)\n"
7721 "Do not export to next AS (well-known community)\n")
7722{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007723 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007724}
7725
7726ALIAS (show_ip_bgp_community,
7727 show_ip_bgp_community2_cmd,
7728 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7729 SHOW_STR
7730 IP_STR
7731 BGP_STR
7732 "Display routes matching the communities\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n"
7737 "community number\n"
7738 "Do not send outside local AS (well-known community)\n"
7739 "Do not advertise to any peer (well-known community)\n"
7740 "Do not export to next AS (well-known community)\n")
7741
7742ALIAS (show_ip_bgp_community,
7743 show_ip_bgp_community3_cmd,
7744 "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)",
7745 SHOW_STR
7746 IP_STR
7747 BGP_STR
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
7782 "Do not send outside local AS (well-known community)\n"
7783 "Do not advertise to any peer (well-known community)\n"
7784 "Do not export to next AS (well-known community)\n")
7785
7786DEFUN (show_ip_bgp_ipv4_community,
7787 show_ip_bgp_ipv4_community_cmd,
7788 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7789 SHOW_STR
7790 IP_STR
7791 BGP_STR
7792 "Address family\n"
7793 "Address Family modifier\n"
7794 "Address Family modifier\n"
7795 "Display routes matching the communities\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n")
7800{
7801 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007802 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007803
Michael Lambert95cbbd22010-07-23 14:43:04 -04007804 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007805}
7806
7807ALIAS (show_ip_bgp_ipv4_community,
7808 show_ip_bgp_ipv4_community2_cmd,
7809 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7810 SHOW_STR
7811 IP_STR
7812 BGP_STR
7813 "Address family\n"
7814 "Address Family modifier\n"
7815 "Address Family modifier\n"
7816 "Display routes matching the communities\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n"
7821 "community number\n"
7822 "Do not send outside local AS (well-known community)\n"
7823 "Do not advertise to any peer (well-known community)\n"
7824 "Do not export to next AS (well-known community)\n")
7825
7826ALIAS (show_ip_bgp_ipv4_community,
7827 show_ip_bgp_ipv4_community3_cmd,
7828 "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)",
7829 SHOW_STR
7830 IP_STR
7831 BGP_STR
7832 "Address family\n"
7833 "Address Family modifier\n"
7834 "Address Family modifier\n"
7835 "Display routes matching the communities\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n"
7840 "community number\n"
7841 "Do not send outside local AS (well-known community)\n"
7842 "Do not advertise to any peer (well-known community)\n"
7843 "Do not export to next AS (well-known community)\n"
7844 "community number\n"
7845 "Do not send outside local AS (well-known community)\n"
7846 "Do not advertise to any peer (well-known community)\n"
7847 "Do not export to next AS (well-known community)\n")
7848
7849ALIAS (show_ip_bgp_ipv4_community,
7850 show_ip_bgp_ipv4_community4_cmd,
7851 "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)",
7852 SHOW_STR
7853 IP_STR
7854 BGP_STR
7855 "Address family\n"
7856 "Address Family modifier\n"
7857 "Address Family modifier\n"
7858 "Display routes matching the communities\n"
7859 "community number\n"
7860 "Do not send outside local AS (well-known community)\n"
7861 "Do not advertise to any peer (well-known community)\n"
7862 "Do not export to next AS (well-known community)\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n"
7871 "community number\n"
7872 "Do not send outside local AS (well-known community)\n"
7873 "Do not advertise to any peer (well-known community)\n"
7874 "Do not export to next AS (well-known community)\n")
7875
Michael Lambert95cbbd22010-07-23 14:43:04 -04007876DEFUN (show_bgp_view_afi_safi_community_all,
7877 show_bgp_view_afi_safi_community_all_cmd,
7878#ifdef HAVE_IPV6
7879 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7880#else
7881 "show bgp view WORD ipv4 (unicast|multicast) community",
7882#endif
7883 SHOW_STR
7884 BGP_STR
7885 "BGP view\n"
7886 "BGP view name\n"
7887 "Address family\n"
7888#ifdef HAVE_IPV6
7889 "Address family\n"
7890#endif
7891 "Address Family modifier\n"
7892 "Address Family modifier\n"
7893 "Display routes containing communities\n")
7894{
7895 int afi;
7896 int safi;
7897 struct bgp *bgp;
7898
7899 /* BGP structure lookup. */
7900 bgp = bgp_lookup_by_name (argv[0]);
7901 if (bgp == NULL)
7902 {
7903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7904 return CMD_WARNING;
7905 }
7906
7907#ifdef HAVE_IPV6
7908 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7909 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7910#else
7911 afi = AFI_IP;
7912 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7913#endif
7914 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7915}
7916
7917DEFUN (show_bgp_view_afi_safi_community,
7918 show_bgp_view_afi_safi_community_cmd,
7919#ifdef HAVE_IPV6
7920 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7921#else
7922 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7923#endif
7924 SHOW_STR
7925 BGP_STR
7926 "BGP view\n"
7927 "BGP view name\n"
7928 "Address family\n"
7929#ifdef HAVE_IPV6
7930 "Address family\n"
7931#endif
7932 "Address family modifier\n"
7933 "Address family modifier\n"
7934 "Display routes matching the communities\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n")
7939{
7940 int afi;
7941 int safi;
7942
7943#ifdef HAVE_IPV6
7944 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7945 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7946 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7947#else
7948 afi = AFI_IP;
7949 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7950 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7951#endif
7952}
7953
7954ALIAS (show_bgp_view_afi_safi_community,
7955 show_bgp_view_afi_safi_community2_cmd,
7956#ifdef HAVE_IPV6
7957 "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)",
7958#else
7959 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7960#endif
7961 SHOW_STR
7962 BGP_STR
7963 "BGP view\n"
7964 "BGP view name\n"
7965 "Address family\n"
7966#ifdef HAVE_IPV6
7967 "Address family\n"
7968#endif
7969 "Address family modifier\n"
7970 "Address family modifier\n"
7971 "Display routes matching the communities\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n"
7976 "community number\n"
7977 "Do not send outside local AS (well-known community)\n"
7978 "Do not advertise to any peer (well-known community)\n"
7979 "Do not export to next AS (well-known community)\n")
7980
7981ALIAS (show_bgp_view_afi_safi_community,
7982 show_bgp_view_afi_safi_community3_cmd,
7983#ifdef HAVE_IPV6
7984 "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)",
7985#else
7986 "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)",
7987#endif
7988 SHOW_STR
7989 BGP_STR
7990 "BGP view\n"
7991 "BGP view name\n"
7992 "Address family\n"
7993#ifdef HAVE_IPV6
7994 "Address family\n"
7995#endif
7996 "Address family modifier\n"
7997 "Address family modifier\n"
7998 "Display routes matching the communities\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n"
8003 "community number\n"
8004 "Do not send outside local AS (well-known community)\n"
8005 "Do not advertise to any peer (well-known community)\n"
8006 "Do not export to next AS (well-known community)\n"
8007 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n")
8011
8012ALIAS (show_bgp_view_afi_safi_community,
8013 show_bgp_view_afi_safi_community4_cmd,
8014#ifdef HAVE_IPV6
8015 "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)",
8016#else
8017 "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)",
8018#endif
8019 SHOW_STR
8020 BGP_STR
8021 "BGP view\n"
8022 "BGP view name\n"
8023 "Address family\n"
8024#ifdef HAVE_IPV6
8025 "Address family\n"
8026#endif
8027 "Address family modifier\n"
8028 "Address family modifier\n"
8029 "Display routes matching the communities\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n"
8042 "community number\n"
8043 "Do not send outside local AS (well-known community)\n"
8044 "Do not advertise to any peer (well-known community)\n"
8045 "Do not export to next AS (well-known community)\n")
8046
paul718e3742002-12-13 20:15:29 +00008047DEFUN (show_ip_bgp_community_exact,
8048 show_ip_bgp_community_exact_cmd,
8049 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8050 SHOW_STR
8051 IP_STR
8052 BGP_STR
8053 "Display routes matching the communities\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 "Exact match of the communities")
8059{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008060 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008061}
8062
8063ALIAS (show_ip_bgp_community_exact,
8064 show_ip_bgp_community2_exact_cmd,
8065 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8066 SHOW_STR
8067 IP_STR
8068 BGP_STR
8069 "Display routes matching the communities\n"
8070 "community number\n"
8071 "Do not send outside local AS (well-known community)\n"
8072 "Do not advertise to any peer (well-known community)\n"
8073 "Do not export to next AS (well-known community)\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
8080ALIAS (show_ip_bgp_community_exact,
8081 show_ip_bgp_community3_exact_cmd,
8082 "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",
8083 SHOW_STR
8084 IP_STR
8085 BGP_STR
8086 "Display routes matching the communities\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n"
8099 "Exact match of the communities")
8100
8101ALIAS (show_ip_bgp_community_exact,
8102 show_ip_bgp_community4_exact_cmd,
8103 "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",
8104 SHOW_STR
8105 IP_STR
8106 BGP_STR
8107 "Display routes matching the communities\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n"
8116 "community number\n"
8117 "Do not send outside local AS (well-known community)\n"
8118 "Do not advertise to any peer (well-known community)\n"
8119 "Do not export to next AS (well-known community)\n"
8120 "community number\n"
8121 "Do not send outside local AS (well-known community)\n"
8122 "Do not advertise to any peer (well-known community)\n"
8123 "Do not export to next AS (well-known community)\n"
8124 "Exact match of the communities")
8125
8126DEFUN (show_ip_bgp_ipv4_community_exact,
8127 show_ip_bgp_ipv4_community_exact_cmd,
8128 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8129 SHOW_STR
8130 IP_STR
8131 BGP_STR
8132 "Address family\n"
8133 "Address Family modifier\n"
8134 "Address Family modifier\n"
8135 "Display routes matching the communities\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "Exact match of the communities")
8141{
8142 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008143 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008144
Michael Lambert95cbbd22010-07-23 14:43:04 -04008145 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008146}
8147
8148ALIAS (show_ip_bgp_ipv4_community_exact,
8149 show_ip_bgp_ipv4_community2_exact_cmd,
8150 "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",
8151 SHOW_STR
8152 IP_STR
8153 BGP_STR
8154 "Address family\n"
8155 "Address Family modifier\n"
8156 "Address Family modifier\n"
8157 "Display routes matching the communities\n"
8158 "community number\n"
8159 "Do not send outside local AS (well-known community)\n"
8160 "Do not advertise to any peer (well-known community)\n"
8161 "Do not export to next AS (well-known community)\n"
8162 "community number\n"
8163 "Do not send outside local AS (well-known community)\n"
8164 "Do not advertise to any peer (well-known community)\n"
8165 "Do not export to next AS (well-known community)\n"
8166 "Exact match of the communities")
8167
8168ALIAS (show_ip_bgp_ipv4_community_exact,
8169 show_ip_bgp_ipv4_community3_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) (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 "community number\n"
8187 "Do not send outside local AS (well-known community)\n"
8188 "Do not advertise to any peer (well-known community)\n"
8189 "Do not export to next AS (well-known community)\n"
8190 "Exact match of the communities")
8191
8192ALIAS (show_ip_bgp_ipv4_community_exact,
8193 show_ip_bgp_ipv4_community4_exact_cmd,
8194 "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",
8195 SHOW_STR
8196 IP_STR
8197 BGP_STR
8198 "Address family\n"
8199 "Address Family modifier\n"
8200 "Address Family modifier\n"
8201 "Display routes matching the communities\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 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "Exact match of the communities")
8219
8220#ifdef HAVE_IPV6
8221DEFUN (show_bgp_community,
8222 show_bgp_community_cmd,
8223 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8224 SHOW_STR
8225 BGP_STR
8226 "Display routes matching the communities\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n")
8231{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008232 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008233}
8234
8235ALIAS (show_bgp_community,
8236 show_bgp_ipv6_community_cmd,
8237 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8238 SHOW_STR
8239 BGP_STR
8240 "Address family\n"
8241 "Display routes matching the communities\n"
8242 "community number\n"
8243 "Do not send outside local AS (well-known community)\n"
8244 "Do not advertise to any peer (well-known community)\n"
8245 "Do not export to next AS (well-known community)\n")
8246
8247ALIAS (show_bgp_community,
8248 show_bgp_community2_cmd,
8249 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8250 SHOW_STR
8251 BGP_STR
8252 "Display routes matching the communities\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n"
8257 "community number\n"
8258 "Do not send outside local AS (well-known community)\n"
8259 "Do not advertise to any peer (well-known community)\n"
8260 "Do not export to next AS (well-known community)\n")
8261
8262ALIAS (show_bgp_community,
8263 show_bgp_ipv6_community2_cmd,
8264 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8265 SHOW_STR
8266 BGP_STR
8267 "Address family\n"
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\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
8278ALIAS (show_bgp_community,
8279 show_bgp_community3_cmd,
8280 "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)",
8281 SHOW_STR
8282 BGP_STR
8283 "Display routes matching the communities\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n")
8296
8297ALIAS (show_bgp_community,
8298 show_bgp_ipv6_community3_cmd,
8299 "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)",
8300 SHOW_STR
8301 BGP_STR
8302 "Address family\n"
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_community4_cmd,
8319 "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)",
8320 SHOW_STR
8321 BGP_STR
8322 "Display routes matching the communities\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n")
8339
8340ALIAS (show_bgp_community,
8341 show_bgp_ipv6_community4_cmd,
8342 "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)",
8343 SHOW_STR
8344 BGP_STR
8345 "Address family\n"
8346 "Display routes matching the communities\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 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n")
8363
8364/* old command */
8365DEFUN (show_ipv6_bgp_community,
8366 show_ipv6_bgp_community_cmd,
8367 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8368 SHOW_STR
8369 IPV6_STR
8370 BGP_STR
8371 "Display routes matching the communities\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n")
8376{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008377 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008378}
8379
8380/* old command */
8381ALIAS (show_ipv6_bgp_community,
8382 show_ipv6_bgp_community2_cmd,
8383 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8384 SHOW_STR
8385 IPV6_STR
8386 BGP_STR
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\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
8397/* old command */
8398ALIAS (show_ipv6_bgp_community,
8399 show_ipv6_bgp_community3_cmd,
8400 "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)",
8401 SHOW_STR
8402 IPV6_STR
8403 BGP_STR
8404 "Display routes matching the communities\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n")
8417
8418/* old command */
8419ALIAS (show_ipv6_bgp_community,
8420 show_ipv6_bgp_community4_cmd,
8421 "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)",
8422 SHOW_STR
8423 IPV6_STR
8424 BGP_STR
8425 "Display routes matching the communities\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n")
8442
8443DEFUN (show_bgp_community_exact,
8444 show_bgp_community_exact_cmd,
8445 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8446 SHOW_STR
8447 BGP_STR
8448 "Display routes matching the communities\n"
8449 "community number\n"
8450 "Do not send outside local AS (well-known community)\n"
8451 "Do not advertise to any peer (well-known community)\n"
8452 "Do not export to next AS (well-known community)\n"
8453 "Exact match of the communities")
8454{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008455 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008456}
8457
8458ALIAS (show_bgp_community_exact,
8459 show_bgp_ipv6_community_exact_cmd,
8460 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8461 SHOW_STR
8462 BGP_STR
8463 "Address family\n"
8464 "Display routes matching the communities\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "Exact match of the communities")
8470
8471ALIAS (show_bgp_community_exact,
8472 show_bgp_community2_exact_cmd,
8473 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8474 SHOW_STR
8475 BGP_STR
8476 "Display routes matching the communities\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\n"
8485 "Exact match of the communities")
8486
8487ALIAS (show_bgp_community_exact,
8488 show_bgp_ipv6_community2_exact_cmd,
8489 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8490 SHOW_STR
8491 BGP_STR
8492 "Address family\n"
8493 "Display routes matching the communities\n"
8494 "community number\n"
8495 "Do not send outside local AS (well-known community)\n"
8496 "Do not advertise to any peer (well-known community)\n"
8497 "Do not export to next AS (well-known community)\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "Exact match of the communities")
8503
8504ALIAS (show_bgp_community_exact,
8505 show_bgp_community3_exact_cmd,
8506 "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",
8507 SHOW_STR
8508 BGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "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_ipv6_community3_exact_cmd,
8526 "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",
8527 SHOW_STR
8528 BGP_STR
8529 "Address family\n"
8530 "Display routes matching the communities\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "Exact match of the communities")
8544
8545ALIAS (show_bgp_community_exact,
8546 show_bgp_community4_exact_cmd,
8547 "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",
8548 SHOW_STR
8549 BGP_STR
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 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "Exact match of the communities")
8568
8569ALIAS (show_bgp_community_exact,
8570 show_bgp_ipv6_community4_exact_cmd,
8571 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8572 SHOW_STR
8573 BGP_STR
8574 "Address family\n"
8575 "Display routes matching the communities\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\n"
8592 "Exact match of the communities")
8593
8594/* old command */
8595DEFUN (show_ipv6_bgp_community_exact,
8596 show_ipv6_bgp_community_exact_cmd,
8597 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8598 SHOW_STR
8599 IPV6_STR
8600 BGP_STR
8601 "Display routes matching the communities\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "Exact match of the communities")
8607{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008608 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008609}
8610
8611/* old command */
8612ALIAS (show_ipv6_bgp_community_exact,
8613 show_ipv6_bgp_community2_exact_cmd,
8614 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8615 SHOW_STR
8616 IPV6_STR
8617 BGP_STR
8618 "Display routes matching the communities\n"
8619 "community number\n"
8620 "Do not send outside local AS (well-known community)\n"
8621 "Do not advertise to any peer (well-known community)\n"
8622 "Do not export to next AS (well-known community)\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "Exact match of the communities")
8628
8629/* old command */
8630ALIAS (show_ipv6_bgp_community_exact,
8631 show_ipv6_bgp_community3_exact_cmd,
8632 "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",
8633 SHOW_STR
8634 IPV6_STR
8635 BGP_STR
8636 "Display routes matching the communities\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "community number\n"
8642 "Do not send outside local AS (well-known community)\n"
8643 "Do not advertise to any peer (well-known community)\n"
8644 "Do not export to next AS (well-known community)\n"
8645 "community number\n"
8646 "Do not send outside local AS (well-known community)\n"
8647 "Do not advertise to any peer (well-known community)\n"
8648 "Do not export to next AS (well-known community)\n"
8649 "Exact match of the communities")
8650
8651/* old command */
8652ALIAS (show_ipv6_bgp_community_exact,
8653 show_ipv6_bgp_community4_exact_cmd,
8654 "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",
8655 SHOW_STR
8656 IPV6_STR
8657 BGP_STR
8658 "Display routes matching the communities\n"
8659 "community number\n"
8660 "Do not send outside local AS (well-known community)\n"
8661 "Do not advertise to any peer (well-known community)\n"
8662 "Do not export to next AS (well-known community)\n"
8663 "community number\n"
8664 "Do not send outside local AS (well-known community)\n"
8665 "Do not advertise to any peer (well-known community)\n"
8666 "Do not export to next AS (well-known community)\n"
8667 "community number\n"
8668 "Do not send outside local AS (well-known community)\n"
8669 "Do not advertise to any peer (well-known community)\n"
8670 "Do not export to next AS (well-known community)\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "Exact match of the communities")
8676
8677/* old command */
8678DEFUN (show_ipv6_mbgp_community,
8679 show_ipv6_mbgp_community_cmd,
8680 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8681 SHOW_STR
8682 IPV6_STR
8683 MBGP_STR
8684 "Display routes matching the communities\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n")
8689{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008690 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008691}
8692
8693/* old command */
8694ALIAS (show_ipv6_mbgp_community,
8695 show_ipv6_mbgp_community2_cmd,
8696 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8697 SHOW_STR
8698 IPV6_STR
8699 MBGP_STR
8700 "Display routes matching the communities\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "community number\n"
8706 "Do not send outside local AS (well-known community)\n"
8707 "Do not advertise to any peer (well-known community)\n"
8708 "Do not export to next AS (well-known community)\n")
8709
8710/* old command */
8711ALIAS (show_ipv6_mbgp_community,
8712 show_ipv6_mbgp_community3_cmd,
8713 "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)",
8714 SHOW_STR
8715 IPV6_STR
8716 MBGP_STR
8717 "Display routes matching the communities\n"
8718 "community number\n"
8719 "Do not send outside local AS (well-known community)\n"
8720 "Do not advertise to any peer (well-known community)\n"
8721 "Do not export to next AS (well-known community)\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n")
8730
8731/* old command */
8732ALIAS (show_ipv6_mbgp_community,
8733 show_ipv6_mbgp_community4_cmd,
8734 "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)",
8735 SHOW_STR
8736 IPV6_STR
8737 MBGP_STR
8738 "Display routes matching the communities\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "community number\n"
8744 "Do not send outside local AS (well-known community)\n"
8745 "Do not advertise to any peer (well-known community)\n"
8746 "Do not export to next AS (well-known community)\n"
8747 "community number\n"
8748 "Do not send outside local AS (well-known community)\n"
8749 "Do not advertise to any peer (well-known community)\n"
8750 "Do not export to next AS (well-known community)\n"
8751 "community number\n"
8752 "Do not send outside local AS (well-known community)\n"
8753 "Do not advertise to any peer (well-known community)\n"
8754 "Do not export to next AS (well-known community)\n")
8755
8756/* old command */
8757DEFUN (show_ipv6_mbgp_community_exact,
8758 show_ipv6_mbgp_community_exact_cmd,
8759 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8760 SHOW_STR
8761 IPV6_STR
8762 MBGP_STR
8763 "Display routes matching the communities\n"
8764 "community number\n"
8765 "Do not send outside local AS (well-known community)\n"
8766 "Do not advertise to any peer (well-known community)\n"
8767 "Do not export to next AS (well-known community)\n"
8768 "Exact match of the communities")
8769{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008770 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008771}
8772
8773/* old command */
8774ALIAS (show_ipv6_mbgp_community_exact,
8775 show_ipv6_mbgp_community2_exact_cmd,
8776 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8777 SHOW_STR
8778 IPV6_STR
8779 MBGP_STR
8780 "Display routes matching the communities\n"
8781 "community number\n"
8782 "Do not send outside local AS (well-known community)\n"
8783 "Do not advertise to any peer (well-known community)\n"
8784 "Do not export to next AS (well-known community)\n"
8785 "community number\n"
8786 "Do not send outside local AS (well-known community)\n"
8787 "Do not advertise to any peer (well-known community)\n"
8788 "Do not export to next AS (well-known community)\n"
8789 "Exact match of the communities")
8790
8791/* old command */
8792ALIAS (show_ipv6_mbgp_community_exact,
8793 show_ipv6_mbgp_community3_exact_cmd,
8794 "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",
8795 SHOW_STR
8796 IPV6_STR
8797 MBGP_STR
8798 "Display routes matching the communities\n"
8799 "community number\n"
8800 "Do not send outside local AS (well-known community)\n"
8801 "Do not advertise to any peer (well-known community)\n"
8802 "Do not export to next AS (well-known community)\n"
8803 "community number\n"
8804 "Do not send outside local AS (well-known community)\n"
8805 "Do not advertise to any peer (well-known community)\n"
8806 "Do not export to next AS (well-known community)\n"
8807 "community number\n"
8808 "Do not send outside local AS (well-known community)\n"
8809 "Do not advertise to any peer (well-known community)\n"
8810 "Do not export to next AS (well-known community)\n"
8811 "Exact match of the communities")
8812
8813/* old command */
8814ALIAS (show_ipv6_mbgp_community_exact,
8815 show_ipv6_mbgp_community4_exact_cmd,
8816 "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",
8817 SHOW_STR
8818 IPV6_STR
8819 MBGP_STR
8820 "Display routes matching the communities\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "community number\n"
8826 "Do not send outside local AS (well-known community)\n"
8827 "Do not advertise to any peer (well-known community)\n"
8828 "Do not export to next AS (well-known community)\n"
8829 "community number\n"
8830 "Do not send outside local AS (well-known community)\n"
8831 "Do not advertise to any peer (well-known community)\n"
8832 "Do not export to next AS (well-known community)\n"
8833 "community number\n"
8834 "Do not send outside local AS (well-known community)\n"
8835 "Do not advertise to any peer (well-known community)\n"
8836 "Do not export to next AS (well-known community)\n"
8837 "Exact match of the communities")
8838#endif /* HAVE_IPV6 */
8839
paul94f2b392005-06-28 12:44:16 +00008840static int
paulfd79ac92004-10-13 05:06:08 +00008841bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008842 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008843{
8844 struct community_list *list;
8845
hassofee6e4e2005-02-02 16:29:31 +00008846 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008847 if (list == NULL)
8848 {
8849 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8850 VTY_NEWLINE);
8851 return CMD_WARNING;
8852 }
8853
ajs5a646652004-11-05 01:25:55 +00008854 return bgp_show (vty, NULL, afi, safi,
8855 (exact ? bgp_show_type_community_list_exact :
8856 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008857}
8858
8859DEFUN (show_ip_bgp_community_list,
8860 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008861 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008862 SHOW_STR
8863 IP_STR
8864 BGP_STR
8865 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008866 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008867 "community-list name\n")
8868{
8869 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8870}
8871
8872DEFUN (show_ip_bgp_ipv4_community_list,
8873 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008874 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008875 SHOW_STR
8876 IP_STR
8877 BGP_STR
8878 "Address family\n"
8879 "Address Family modifier\n"
8880 "Address Family modifier\n"
8881 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008882 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008883 "community-list name\n")
8884{
8885 if (strncmp (argv[0], "m", 1) == 0)
8886 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8887
8888 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8889}
8890
8891DEFUN (show_ip_bgp_community_list_exact,
8892 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008893 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008894 SHOW_STR
8895 IP_STR
8896 BGP_STR
8897 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008898 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008899 "community-list name\n"
8900 "Exact match of the communities\n")
8901{
8902 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8903}
8904
8905DEFUN (show_ip_bgp_ipv4_community_list_exact,
8906 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008907 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008908 SHOW_STR
8909 IP_STR
8910 BGP_STR
8911 "Address family\n"
8912 "Address Family modifier\n"
8913 "Address Family modifier\n"
8914 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008915 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008916 "community-list name\n"
8917 "Exact match of the communities\n")
8918{
8919 if (strncmp (argv[0], "m", 1) == 0)
8920 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8921
8922 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8923}
8924
8925#ifdef HAVE_IPV6
8926DEFUN (show_bgp_community_list,
8927 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008928 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008929 SHOW_STR
8930 BGP_STR
8931 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008932 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008933 "community-list name\n")
8934{
8935 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8936}
8937
8938ALIAS (show_bgp_community_list,
8939 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008940 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008941 SHOW_STR
8942 BGP_STR
8943 "Address family\n"
8944 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008945 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008946 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008947
8948/* old command */
8949DEFUN (show_ipv6_bgp_community_list,
8950 show_ipv6_bgp_community_list_cmd,
8951 "show ipv6 bgp community-list WORD",
8952 SHOW_STR
8953 IPV6_STR
8954 BGP_STR
8955 "Display routes matching the community-list\n"
8956 "community-list name\n")
8957{
8958 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8959}
8960
8961/* old command */
8962DEFUN (show_ipv6_mbgp_community_list,
8963 show_ipv6_mbgp_community_list_cmd,
8964 "show ipv6 mbgp community-list WORD",
8965 SHOW_STR
8966 IPV6_STR
8967 MBGP_STR
8968 "Display routes matching the community-list\n"
8969 "community-list name\n")
8970{
8971 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8972}
8973
8974DEFUN (show_bgp_community_list_exact,
8975 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008976 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008977 SHOW_STR
8978 BGP_STR
8979 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008980 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008981 "community-list name\n"
8982 "Exact match of the communities\n")
8983{
8984 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8985}
8986
8987ALIAS (show_bgp_community_list_exact,
8988 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008989 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008990 SHOW_STR
8991 BGP_STR
8992 "Address family\n"
8993 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008994 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008995 "community-list name\n"
8996 "Exact match of the communities\n")
8997
8998/* old command */
8999DEFUN (show_ipv6_bgp_community_list_exact,
9000 show_ipv6_bgp_community_list_exact_cmd,
9001 "show ipv6 bgp community-list WORD exact-match",
9002 SHOW_STR
9003 IPV6_STR
9004 BGP_STR
9005 "Display routes matching the community-list\n"
9006 "community-list name\n"
9007 "Exact match of the communities\n")
9008{
9009 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9010}
9011
9012/* old command */
9013DEFUN (show_ipv6_mbgp_community_list_exact,
9014 show_ipv6_mbgp_community_list_exact_cmd,
9015 "show ipv6 mbgp community-list WORD exact-match",
9016 SHOW_STR
9017 IPV6_STR
9018 MBGP_STR
9019 "Display routes matching the community-list\n"
9020 "community-list name\n"
9021 "Exact match of the communities\n")
9022{
9023 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9024}
9025#endif /* HAVE_IPV6 */
9026
paul94f2b392005-06-28 12:44:16 +00009027static int
paulfd79ac92004-10-13 05:06:08 +00009028bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009029 safi_t safi, enum bgp_show_type type)
9030{
9031 int ret;
9032 struct prefix *p;
9033
9034 p = prefix_new();
9035
9036 ret = str2prefix (prefix, p);
9037 if (! ret)
9038 {
9039 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9040 return CMD_WARNING;
9041 }
9042
ajs5a646652004-11-05 01:25:55 +00009043 ret = bgp_show (vty, NULL, afi, safi, type, p);
9044 prefix_free(p);
9045 return ret;
paul718e3742002-12-13 20:15:29 +00009046}
9047
9048DEFUN (show_ip_bgp_prefix_longer,
9049 show_ip_bgp_prefix_longer_cmd,
9050 "show ip bgp A.B.C.D/M longer-prefixes",
9051 SHOW_STR
9052 IP_STR
9053 BGP_STR
9054 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9055 "Display route and more specific routes\n")
9056{
9057 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9058 bgp_show_type_prefix_longer);
9059}
9060
9061DEFUN (show_ip_bgp_flap_prefix_longer,
9062 show_ip_bgp_flap_prefix_longer_cmd,
9063 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9064 SHOW_STR
9065 IP_STR
9066 BGP_STR
9067 "Display flap statistics of routes\n"
9068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9069 "Display route and more specific routes\n")
9070{
9071 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9072 bgp_show_type_flap_prefix_longer);
9073}
9074
9075DEFUN (show_ip_bgp_ipv4_prefix_longer,
9076 show_ip_bgp_ipv4_prefix_longer_cmd,
9077 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9078 SHOW_STR
9079 IP_STR
9080 BGP_STR
9081 "Address family\n"
9082 "Address Family modifier\n"
9083 "Address Family modifier\n"
9084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9085 "Display route and more specific routes\n")
9086{
9087 if (strncmp (argv[0], "m", 1) == 0)
9088 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9089 bgp_show_type_prefix_longer);
9090
9091 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9092 bgp_show_type_prefix_longer);
9093}
9094
9095DEFUN (show_ip_bgp_flap_address,
9096 show_ip_bgp_flap_address_cmd,
9097 "show ip bgp flap-statistics A.B.C.D",
9098 SHOW_STR
9099 IP_STR
9100 BGP_STR
9101 "Display flap statistics of routes\n"
9102 "Network in the BGP routing table to display\n")
9103{
9104 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9105 bgp_show_type_flap_address);
9106}
9107
9108DEFUN (show_ip_bgp_flap_prefix,
9109 show_ip_bgp_flap_prefix_cmd,
9110 "show ip bgp flap-statistics A.B.C.D/M",
9111 SHOW_STR
9112 IP_STR
9113 BGP_STR
9114 "Display flap statistics of routes\n"
9115 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9116{
9117 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9118 bgp_show_type_flap_prefix);
9119}
9120#ifdef HAVE_IPV6
9121DEFUN (show_bgp_prefix_longer,
9122 show_bgp_prefix_longer_cmd,
9123 "show bgp X:X::X:X/M longer-prefixes",
9124 SHOW_STR
9125 BGP_STR
9126 "IPv6 prefix <network>/<length>\n"
9127 "Display route and more specific routes\n")
9128{
9129 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9130 bgp_show_type_prefix_longer);
9131}
9132
9133ALIAS (show_bgp_prefix_longer,
9134 show_bgp_ipv6_prefix_longer_cmd,
9135 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9136 SHOW_STR
9137 BGP_STR
9138 "Address family\n"
9139 "IPv6 prefix <network>/<length>\n"
9140 "Display route and more specific routes\n")
9141
9142/* old command */
9143DEFUN (show_ipv6_bgp_prefix_longer,
9144 show_ipv6_bgp_prefix_longer_cmd,
9145 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9146 SHOW_STR
9147 IPV6_STR
9148 BGP_STR
9149 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9150 "Display route and more specific routes\n")
9151{
9152 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9153 bgp_show_type_prefix_longer);
9154}
9155
9156/* old command */
9157DEFUN (show_ipv6_mbgp_prefix_longer,
9158 show_ipv6_mbgp_prefix_longer_cmd,
9159 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9160 SHOW_STR
9161 IPV6_STR
9162 MBGP_STR
9163 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9164 "Display route and more specific routes\n")
9165{
9166 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9167 bgp_show_type_prefix_longer);
9168}
9169#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009170
paul94f2b392005-06-28 12:44:16 +00009171static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009172peer_lookup_in_view (struct vty *vty, const char *view_name,
9173 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009174{
9175 int ret;
9176 struct bgp *bgp;
9177 struct peer *peer;
9178 union sockunion su;
9179
9180 /* BGP structure lookup. */
9181 if (view_name)
9182 {
9183 bgp = bgp_lookup_by_name (view_name);
9184 if (! bgp)
9185 {
9186 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9187 return NULL;
9188 }
9189 }
paul5228ad22004-06-04 17:58:18 +00009190 else
paulbb46e942003-10-24 19:02:03 +00009191 {
9192 bgp = bgp_get_default ();
9193 if (! bgp)
9194 {
9195 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9196 return NULL;
9197 }
9198 }
9199
9200 /* Get peer sockunion. */
9201 ret = str2sockunion (ip_str, &su);
9202 if (ret < 0)
9203 {
9204 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9205 return NULL;
9206 }
9207
9208 /* Peer structure lookup. */
9209 peer = peer_lookup (bgp, &su);
9210 if (! peer)
9211 {
9212 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9213 return NULL;
9214 }
9215
9216 return peer;
9217}
Paul Jakma2815e612006-09-14 02:56:07 +00009218
9219enum bgp_stats
9220{
9221 BGP_STATS_MAXBITLEN = 0,
9222 BGP_STATS_RIB,
9223 BGP_STATS_PREFIXES,
9224 BGP_STATS_TOTPLEN,
9225 BGP_STATS_UNAGGREGATEABLE,
9226 BGP_STATS_MAX_AGGREGATEABLE,
9227 BGP_STATS_AGGREGATES,
9228 BGP_STATS_SPACE,
9229 BGP_STATS_ASPATH_COUNT,
9230 BGP_STATS_ASPATH_MAXHOPS,
9231 BGP_STATS_ASPATH_TOTHOPS,
9232 BGP_STATS_ASPATH_MAXSIZE,
9233 BGP_STATS_ASPATH_TOTSIZE,
9234 BGP_STATS_ASN_HIGHEST,
9235 BGP_STATS_MAX,
9236};
paulbb46e942003-10-24 19:02:03 +00009237
Paul Jakma2815e612006-09-14 02:56:07 +00009238static const char *table_stats_strs[] =
9239{
9240 [BGP_STATS_PREFIXES] = "Total Prefixes",
9241 [BGP_STATS_TOTPLEN] = "Average prefix length",
9242 [BGP_STATS_RIB] = "Total Advertisements",
9243 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9244 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9245 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9246 [BGP_STATS_SPACE] = "Address space advertised",
9247 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9248 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9249 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9250 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9251 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9252 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9253 [BGP_STATS_MAX] = NULL,
9254};
9255
9256struct bgp_table_stats
9257{
9258 struct bgp_table *table;
9259 unsigned long long counts[BGP_STATS_MAX];
9260};
9261
9262#if 0
9263#define TALLY_SIGFIG 100000
9264static unsigned long
9265ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9266{
9267 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9268 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9269 unsigned long ret = newtot / count;
9270
9271 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9272 return ret + 1;
9273 else
9274 return ret;
9275}
9276#endif
9277
9278static int
9279bgp_table_stats_walker (struct thread *t)
9280{
9281 struct bgp_node *rn;
9282 struct bgp_node *top;
9283 struct bgp_table_stats *ts = THREAD_ARG (t);
9284 unsigned int space = 0;
9285
Paul Jakma53d9f672006-10-15 23:41:16 +00009286 if (!(top = bgp_table_top (ts->table)))
9287 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009288
9289 switch (top->p.family)
9290 {
9291 case AF_INET:
9292 space = IPV4_MAX_BITLEN;
9293 break;
9294 case AF_INET6:
9295 space = IPV6_MAX_BITLEN;
9296 break;
9297 }
9298
9299 ts->counts[BGP_STATS_MAXBITLEN] = space;
9300
9301 for (rn = top; rn; rn = bgp_route_next (rn))
9302 {
9303 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009304 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009305 unsigned int rinum = 0;
9306
9307 if (rn == top)
9308 continue;
9309
9310 if (!rn->info)
9311 continue;
9312
9313 ts->counts[BGP_STATS_PREFIXES]++;
9314 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9315
9316#if 0
9317 ts->counts[BGP_STATS_AVGPLEN]
9318 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9319 ts->counts[BGP_STATS_AVGPLEN],
9320 rn->p.prefixlen);
9321#endif
9322
9323 /* check if the prefix is included by any other announcements */
9324 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009325 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009326
9327 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009328 {
9329 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9330 /* announced address space */
9331 if (space)
9332 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9333 }
Paul Jakma2815e612006-09-14 02:56:07 +00009334 else if (prn->info)
9335 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9336
Paul Jakma2815e612006-09-14 02:56:07 +00009337 for (ri = rn->info; ri; ri = ri->next)
9338 {
9339 rinum++;
9340 ts->counts[BGP_STATS_RIB]++;
9341
9342 if (ri->attr &&
9343 (CHECK_FLAG (ri->attr->flag,
9344 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9345 ts->counts[BGP_STATS_AGGREGATES]++;
9346
9347 /* as-path stats */
9348 if (ri->attr && ri->attr->aspath)
9349 {
9350 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9351 unsigned int size = aspath_size (ri->attr->aspath);
9352 as_t highest = aspath_highest (ri->attr->aspath);
9353
9354 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9355
9356 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9357 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9358
9359 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9360 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9361
9362 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9363 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9364#if 0
9365 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9366 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9367 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9368 hops);
9369 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9370 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9371 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9372 size);
9373#endif
9374 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9375 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9376 }
9377 }
9378 }
9379 return 0;
9380}
9381
9382static int
9383bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9384{
9385 struct bgp_table_stats ts;
9386 unsigned int i;
9387
9388 if (!bgp->rib[afi][safi])
9389 {
9390 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9391 return CMD_WARNING;
9392 }
9393
9394 memset (&ts, 0, sizeof (ts));
9395 ts.table = bgp->rib[afi][safi];
9396 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9397
9398 vty_out (vty, "BGP %s RIB statistics%s%s",
9399 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9400
9401 for (i = 0; i < BGP_STATS_MAX; i++)
9402 {
9403 if (!table_stats_strs[i])
9404 continue;
9405
9406 switch (i)
9407 {
9408#if 0
9409 case BGP_STATS_ASPATH_AVGHOPS:
9410 case BGP_STATS_ASPATH_AVGSIZE:
9411 case BGP_STATS_AVGPLEN:
9412 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9413 vty_out (vty, "%12.2f",
9414 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9415 break;
9416#endif
9417 case BGP_STATS_ASPATH_TOTHOPS:
9418 case BGP_STATS_ASPATH_TOTSIZE:
9419 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9420 vty_out (vty, "%12.2f",
9421 ts.counts[i] ?
9422 (float)ts.counts[i] /
9423 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9424 : 0);
9425 break;
9426 case BGP_STATS_TOTPLEN:
9427 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9428 vty_out (vty, "%12.2f",
9429 ts.counts[i] ?
9430 (float)ts.counts[i] /
9431 (float)ts.counts[BGP_STATS_PREFIXES]
9432 : 0);
9433 break;
9434 case BGP_STATS_SPACE:
9435 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9436 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9437 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9438 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009439 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009440 vty_out (vty, "%12.2f%s",
9441 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009442 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009443 VTY_NEWLINE);
9444 vty_out (vty, "%30s: ", "/8 equivalent ");
9445 vty_out (vty, "%12.2f%s",
9446 (float)ts.counts[BGP_STATS_SPACE] /
9447 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9448 VTY_NEWLINE);
9449 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9450 break;
9451 vty_out (vty, "%30s: ", "/24 equivalent ");
9452 vty_out (vty, "%12.2f",
9453 (float)ts.counts[BGP_STATS_SPACE] /
9454 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9455 break;
9456 default:
9457 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9458 vty_out (vty, "%12llu", ts.counts[i]);
9459 }
9460
9461 vty_out (vty, "%s", VTY_NEWLINE);
9462 }
9463 return CMD_SUCCESS;
9464}
9465
9466static int
9467bgp_table_stats_vty (struct vty *vty, const char *name,
9468 const char *afi_str, const char *safi_str)
9469{
9470 struct bgp *bgp;
9471 afi_t afi;
9472 safi_t safi;
9473
9474 if (name)
9475 bgp = bgp_lookup_by_name (name);
9476 else
9477 bgp = bgp_get_default ();
9478
9479 if (!bgp)
9480 {
9481 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9482 return CMD_WARNING;
9483 }
9484 if (strncmp (afi_str, "ipv", 3) == 0)
9485 {
9486 if (strncmp (afi_str, "ipv4", 4) == 0)
9487 afi = AFI_IP;
9488 else if (strncmp (afi_str, "ipv6", 4) == 0)
9489 afi = AFI_IP6;
9490 else
9491 {
9492 vty_out (vty, "%% Invalid address family %s%s",
9493 afi_str, VTY_NEWLINE);
9494 return CMD_WARNING;
9495 }
9496 if (strncmp (safi_str, "m", 1) == 0)
9497 safi = SAFI_MULTICAST;
9498 else if (strncmp (safi_str, "u", 1) == 0)
9499 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009500 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9501 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009502 else
9503 {
9504 vty_out (vty, "%% Invalid subsequent address family %s%s",
9505 safi_str, VTY_NEWLINE);
9506 return CMD_WARNING;
9507 }
9508 }
9509 else
9510 {
9511 vty_out (vty, "%% Invalid address family %s%s",
9512 afi_str, VTY_NEWLINE);
9513 return CMD_WARNING;
9514 }
9515
Paul Jakma2815e612006-09-14 02:56:07 +00009516 return bgp_table_stats (vty, bgp, afi, safi);
9517}
9518
9519DEFUN (show_bgp_statistics,
9520 show_bgp_statistics_cmd,
9521 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9522 SHOW_STR
9523 BGP_STR
9524 "Address family\n"
9525 "Address family\n"
9526 "Address Family modifier\n"
9527 "Address Family modifier\n"
9528 "BGP RIB advertisement statistics\n")
9529{
9530 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9531}
9532
9533ALIAS (show_bgp_statistics,
9534 show_bgp_statistics_vpnv4_cmd,
9535 "show bgp (ipv4) (vpnv4) statistics",
9536 SHOW_STR
9537 BGP_STR
9538 "Address family\n"
9539 "Address Family modifier\n"
9540 "BGP RIB advertisement statistics\n")
9541
9542DEFUN (show_bgp_statistics_view,
9543 show_bgp_statistics_view_cmd,
9544 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9545 SHOW_STR
9546 BGP_STR
9547 "BGP view\n"
9548 "Address family\n"
9549 "Address family\n"
9550 "Address Family modifier\n"
9551 "Address Family modifier\n"
9552 "BGP RIB advertisement statistics\n")
9553{
9554 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9555}
9556
9557ALIAS (show_bgp_statistics_view,
9558 show_bgp_statistics_view_vpnv4_cmd,
9559 "show bgp view WORD (ipv4) (vpnv4) statistics",
9560 SHOW_STR
9561 BGP_STR
9562 "BGP view\n"
9563 "Address family\n"
9564 "Address Family modifier\n"
9565 "BGP RIB advertisement statistics\n")
9566
Paul Jakmaff7924f2006-09-04 01:10:36 +00009567enum bgp_pcounts
9568{
9569 PCOUNT_ADJ_IN = 0,
9570 PCOUNT_DAMPED,
9571 PCOUNT_REMOVED,
9572 PCOUNT_HISTORY,
9573 PCOUNT_STALE,
9574 PCOUNT_VALID,
9575 PCOUNT_ALL,
9576 PCOUNT_COUNTED,
9577 PCOUNT_PFCNT, /* the figure we display to users */
9578 PCOUNT_MAX,
9579};
9580
9581static const char *pcount_strs[] =
9582{
9583 [PCOUNT_ADJ_IN] = "Adj-in",
9584 [PCOUNT_DAMPED] = "Damped",
9585 [PCOUNT_REMOVED] = "Removed",
9586 [PCOUNT_HISTORY] = "History",
9587 [PCOUNT_STALE] = "Stale",
9588 [PCOUNT_VALID] = "Valid",
9589 [PCOUNT_ALL] = "All RIB",
9590 [PCOUNT_COUNTED] = "PfxCt counted",
9591 [PCOUNT_PFCNT] = "Useable",
9592 [PCOUNT_MAX] = NULL,
9593};
9594
Paul Jakma2815e612006-09-14 02:56:07 +00009595struct peer_pcounts
9596{
9597 unsigned int count[PCOUNT_MAX];
9598 const struct peer *peer;
9599 const struct bgp_table *table;
9600};
9601
Paul Jakmaff7924f2006-09-04 01:10:36 +00009602static int
Paul Jakma2815e612006-09-14 02:56:07 +00009603bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009604{
9605 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009606 struct peer_pcounts *pc = THREAD_ARG (t);
9607 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608
Paul Jakma2815e612006-09-14 02:56:07 +00009609 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009610 {
9611 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009612 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009613
9614 for (ain = rn->adj_in; ain; ain = ain->next)
9615 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009616 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009617
Paul Jakmaff7924f2006-09-04 01:10:36 +00009618 for (ri = rn->info; ri; ri = ri->next)
9619 {
9620 char buf[SU_ADDRSTRLEN];
9621
9622 if (ri->peer != peer)
9623 continue;
9624
Paul Jakma2815e612006-09-14 02:56:07 +00009625 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009626
9627 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009628 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009630 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009632 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009634 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009635 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009636 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009637 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009638 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009639
9640 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9641 {
Paul Jakma2815e612006-09-14 02:56:07 +00009642 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009643 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009644 plog_warn (peer->log,
9645 "%s [pcount] %s/%d is counted but flags 0x%x",
9646 peer->host,
9647 inet_ntop(rn->p.family, &rn->p.u.prefix,
9648 buf, SU_ADDRSTRLEN),
9649 rn->p.prefixlen,
9650 ri->flags);
9651 }
9652 else
9653 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009654 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009655 plog_warn (peer->log,
9656 "%s [pcount] %s/%d not counted but flags 0x%x",
9657 peer->host,
9658 inet_ntop(rn->p.family, &rn->p.u.prefix,
9659 buf, SU_ADDRSTRLEN),
9660 rn->p.prefixlen,
9661 ri->flags);
9662 }
9663 }
9664 }
Paul Jakma2815e612006-09-14 02:56:07 +00009665 return 0;
9666}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009667
Paul Jakma2815e612006-09-14 02:56:07 +00009668static int
9669bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9670{
9671 struct peer_pcounts pcounts = { .peer = peer };
9672 unsigned int i;
9673
9674 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9675 || !peer->bgp->rib[afi][safi])
9676 {
9677 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9678 return CMD_WARNING;
9679 }
9680
9681 memset (&pcounts, 0, sizeof(pcounts));
9682 pcounts.peer = peer;
9683 pcounts.table = peer->bgp->rib[afi][safi];
9684
9685 /* in-place call via thread subsystem so as to record execution time
9686 * stats for the thread-walk (i.e. ensure this can't be blamed on
9687 * on just vty_read()).
9688 */
9689 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9690
Paul Jakmaff7924f2006-09-04 01:10:36 +00009691 vty_out (vty, "Prefix counts for %s, %s%s",
9692 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9693 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9694 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9695 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9696
9697 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009698 vty_out (vty, "%20s: %-10d%s",
9699 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009700
Paul Jakma2815e612006-09-14 02:56:07 +00009701 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009702 {
9703 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9704 peer->host, VTY_NEWLINE);
9705 vty_out (vty, "Please report this bug, with the above command output%s",
9706 VTY_NEWLINE);
9707 }
9708
9709 return CMD_SUCCESS;
9710}
9711
9712DEFUN (show_ip_bgp_neighbor_prefix_counts,
9713 show_ip_bgp_neighbor_prefix_counts_cmd,
9714 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9715 SHOW_STR
9716 IP_STR
9717 BGP_STR
9718 "Detailed information on TCP and BGP neighbor connections\n"
9719 "Neighbor to display information about\n"
9720 "Neighbor to display information about\n"
9721 "Display detailed prefix count information\n")
9722{
9723 struct peer *peer;
9724
9725 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9726 if (! peer)
9727 return CMD_WARNING;
9728
9729 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9730}
9731
9732DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9733 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9734 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9735 SHOW_STR
9736 BGP_STR
9737 "Address family\n"
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_IP6, SAFI_UNICAST);
9750}
9751
9752DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9753 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9754 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9755 SHOW_STR
9756 IP_STR
9757 BGP_STR
9758 "Address family\n"
9759 "Address Family modifier\n"
9760 "Address Family modifier\n"
9761 "Detailed information on TCP and BGP neighbor connections\n"
9762 "Neighbor to display information about\n"
9763 "Neighbor to display information about\n"
9764 "Display detailed prefix count information\n")
9765{
9766 struct peer *peer;
9767
9768 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9769 if (! peer)
9770 return CMD_WARNING;
9771
9772 if (strncmp (argv[0], "m", 1) == 0)
9773 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9774
9775 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9776}
9777
9778DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9779 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9780 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9781 SHOW_STR
9782 IP_STR
9783 BGP_STR
9784 "Address family\n"
9785 "Address Family modifier\n"
9786 "Address Family modifier\n"
9787 "Detailed information on TCP and BGP neighbor connections\n"
9788 "Neighbor to display information about\n"
9789 "Neighbor to display information about\n"
9790 "Display detailed prefix count information\n")
9791{
9792 struct peer *peer;
9793
9794 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9795 if (! peer)
9796 return CMD_WARNING;
9797
9798 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9799}
9800
9801
paul94f2b392005-06-28 12:44:16 +00009802static void
paul718e3742002-12-13 20:15:29 +00009803show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9804 int in)
9805{
9806 struct bgp_table *table;
9807 struct bgp_adj_in *ain;
9808 struct bgp_adj_out *adj;
9809 unsigned long output_count;
9810 struct bgp_node *rn;
9811 int header1 = 1;
9812 struct bgp *bgp;
9813 int header2 = 1;
9814
paulbb46e942003-10-24 19:02:03 +00009815 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009816
9817 if (! bgp)
9818 return;
9819
9820 table = bgp->rib[afi][safi];
9821
9822 output_count = 0;
9823
9824 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9825 PEER_STATUS_DEFAULT_ORIGINATE))
9826 {
9827 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 +00009828 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9829 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009830
9831 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9832 VTY_NEWLINE, VTY_NEWLINE);
9833 header1 = 0;
9834 }
9835
9836 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9837 if (in)
9838 {
9839 for (ain = rn->adj_in; ain; ain = ain->next)
9840 if (ain->peer == peer)
9841 {
9842 if (header1)
9843 {
9844 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 +00009845 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9846 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009847 header1 = 0;
9848 }
9849 if (header2)
9850 {
9851 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9852 header2 = 0;
9853 }
9854 if (ain->attr)
9855 {
9856 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9857 output_count++;
9858 }
9859 }
9860 }
9861 else
9862 {
9863 for (adj = rn->adj_out; adj; adj = adj->next)
9864 if (adj->peer == peer)
9865 {
9866 if (header1)
9867 {
9868 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 +00009869 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9870 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009871 header1 = 0;
9872 }
9873 if (header2)
9874 {
9875 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9876 header2 = 0;
9877 }
9878 if (adj->attr)
9879 {
9880 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9881 output_count++;
9882 }
9883 }
9884 }
9885
9886 if (output_count != 0)
9887 vty_out (vty, "%sTotal number of prefixes %ld%s",
9888 VTY_NEWLINE, output_count, VTY_NEWLINE);
9889}
9890
paul94f2b392005-06-28 12:44:16 +00009891static int
paulbb46e942003-10-24 19:02:03 +00009892peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9893{
paul718e3742002-12-13 20:15:29 +00009894 if (! peer || ! peer->afc[afi][safi])
9895 {
9896 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9897 return CMD_WARNING;
9898 }
9899
9900 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9901 {
9902 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9903 VTY_NEWLINE);
9904 return CMD_WARNING;
9905 }
9906
9907 show_adj_route (vty, peer, afi, safi, in);
9908
9909 return CMD_SUCCESS;
9910}
9911
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009912DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9913 show_ip_bgp_view_neighbor_advertised_route_cmd,
9914 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9915 SHOW_STR
9916 IP_STR
9917 BGP_STR
9918 "BGP view\n"
9919 "View name\n"
9920 "Detailed information on TCP and BGP neighbor connections\n"
9921 "Neighbor to display information about\n"
9922 "Neighbor to display information about\n"
9923 "Display the routes advertised to a BGP neighbor\n")
9924{
9925 struct peer *peer;
9926
9927 if (argc == 2)
9928 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9929 else
9930 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9931
9932 if (! peer)
9933 return CMD_WARNING;
9934
9935 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9936}
9937
9938ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009939 show_ip_bgp_neighbor_advertised_route_cmd,
9940 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9941 SHOW_STR
9942 IP_STR
9943 BGP_STR
9944 "Detailed information on TCP and BGP neighbor connections\n"
9945 "Neighbor to display information about\n"
9946 "Neighbor to display information about\n"
9947 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009948
9949DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9950 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9951 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9952 SHOW_STR
9953 IP_STR
9954 BGP_STR
9955 "Address family\n"
9956 "Address Family modifier\n"
9957 "Address Family modifier\n"
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display the routes advertised to a BGP neighbor\n")
9962{
paulbb46e942003-10-24 19:02:03 +00009963 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009964
paulbb46e942003-10-24 19:02:03 +00009965 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9966 if (! peer)
9967 return CMD_WARNING;
9968
9969 if (strncmp (argv[0], "m", 1) == 0)
9970 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9971
9972 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009973}
9974
9975#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009976DEFUN (show_bgp_view_neighbor_advertised_route,
9977 show_bgp_view_neighbor_advertised_route_cmd,
9978 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9979 SHOW_STR
9980 BGP_STR
9981 "BGP view\n"
9982 "View name\n"
9983 "Detailed information on TCP and BGP neighbor connections\n"
9984 "Neighbor to display information about\n"
9985 "Neighbor to display information about\n"
9986 "Display the routes advertised to a BGP neighbor\n")
9987{
9988 struct peer *peer;
9989
9990 if (argc == 2)
9991 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9992 else
9993 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9994
9995 if (! peer)
9996 return CMD_WARNING;
9997
9998 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9999}
10000
10001ALIAS (show_bgp_view_neighbor_advertised_route,
10002 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10003 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10004 SHOW_STR
10005 BGP_STR
10006 "BGP view\n"
10007 "View name\n"
10008 "Address family\n"
10009 "Detailed information on TCP and BGP neighbor connections\n"
10010 "Neighbor to display information about\n"
10011 "Neighbor to display information about\n"
10012 "Display the routes advertised to a BGP neighbor\n")
10013
10014DEFUN (show_bgp_view_neighbor_received_routes,
10015 show_bgp_view_neighbor_received_routes_cmd,
10016 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10017 SHOW_STR
10018 BGP_STR
10019 "BGP view\n"
10020 "View name\n"
10021 "Detailed information on TCP and BGP neighbor connections\n"
10022 "Neighbor to display information about\n"
10023 "Neighbor to display information about\n"
10024 "Display the received routes from neighbor\n")
10025{
10026 struct peer *peer;
10027
10028 if (argc == 2)
10029 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10030 else
10031 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10032
10033 if (! peer)
10034 return CMD_WARNING;
10035
10036 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10037}
10038
10039ALIAS (show_bgp_view_neighbor_received_routes,
10040 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10041 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10042 SHOW_STR
10043 BGP_STR
10044 "BGP view\n"
10045 "View name\n"
10046 "Address family\n"
10047 "Detailed information on TCP and BGP neighbor connections\n"
10048 "Neighbor to display information about\n"
10049 "Neighbor to display information about\n"
10050 "Display the received routes from neighbor\n")
10051
10052ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010053 show_bgp_neighbor_advertised_route_cmd,
10054 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10055 SHOW_STR
10056 BGP_STR
10057 "Detailed information on TCP and BGP neighbor connections\n"
10058 "Neighbor to display information about\n"
10059 "Neighbor to display information about\n"
10060 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010061
10062ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010063 show_bgp_ipv6_neighbor_advertised_route_cmd,
10064 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10065 SHOW_STR
10066 BGP_STR
10067 "Address family\n"
10068 "Detailed information on TCP and BGP neighbor connections\n"
10069 "Neighbor to display information about\n"
10070 "Neighbor to display information about\n"
10071 "Display the routes advertised to a BGP neighbor\n")
10072
10073/* old command */
paulbb46e942003-10-24 19:02:03 +000010074ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010075 ipv6_bgp_neighbor_advertised_route_cmd,
10076 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10077 SHOW_STR
10078 IPV6_STR
10079 BGP_STR
10080 "Detailed information on TCP and BGP neighbor connections\n"
10081 "Neighbor to display information about\n"
10082 "Neighbor to display information about\n"
10083 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010084
paul718e3742002-12-13 20:15:29 +000010085/* old command */
10086DEFUN (ipv6_mbgp_neighbor_advertised_route,
10087 ipv6_mbgp_neighbor_advertised_route_cmd,
10088 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10089 SHOW_STR
10090 IPV6_STR
10091 MBGP_STR
10092 "Detailed information on TCP and BGP neighbor connections\n"
10093 "Neighbor to display information about\n"
10094 "Neighbor to display information about\n"
10095 "Display the routes advertised to a BGP neighbor\n")
10096{
paulbb46e942003-10-24 19:02:03 +000010097 struct peer *peer;
10098
10099 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10100 if (! peer)
10101 return CMD_WARNING;
10102
10103 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010104}
10105#endif /* HAVE_IPV6 */
10106
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010107DEFUN (show_ip_bgp_view_neighbor_received_routes,
10108 show_ip_bgp_view_neighbor_received_routes_cmd,
10109 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10110 SHOW_STR
10111 IP_STR
10112 BGP_STR
10113 "BGP view\n"
10114 "View name\n"
10115 "Detailed information on TCP and BGP neighbor connections\n"
10116 "Neighbor to display information about\n"
10117 "Neighbor to display information about\n"
10118 "Display the received routes from neighbor\n")
10119{
10120 struct peer *peer;
10121
10122 if (argc == 2)
10123 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10124 else
10125 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10126
10127 if (! peer)
10128 return CMD_WARNING;
10129
10130 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10131}
10132
10133ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010134 show_ip_bgp_neighbor_received_routes_cmd,
10135 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10136 SHOW_STR
10137 IP_STR
10138 BGP_STR
10139 "Detailed information on TCP and BGP neighbor connections\n"
10140 "Neighbor to display information about\n"
10141 "Neighbor to display information about\n"
10142 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010143
10144DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10145 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10146 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10147 SHOW_STR
10148 IP_STR
10149 BGP_STR
10150 "Address family\n"
10151 "Address Family modifier\n"
10152 "Address Family modifier\n"
10153 "Detailed information on TCP and BGP neighbor connections\n"
10154 "Neighbor to display information about\n"
10155 "Neighbor to display information about\n"
10156 "Display the received routes from neighbor\n")
10157{
paulbb46e942003-10-24 19:02:03 +000010158 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010159
paulbb46e942003-10-24 19:02:03 +000010160 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10161 if (! peer)
10162 return CMD_WARNING;
10163
10164 if (strncmp (argv[0], "m", 1) == 0)
10165 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10166
10167 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010168}
10169
Michael Lambert95cbbd22010-07-23 14:43:04 -040010170DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10171 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10172#ifdef HAVE_IPV6
10173 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10174#else
10175 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10176#endif
10177 SHOW_STR
10178 BGP_STR
10179 "BGP view\n"
10180 "BGP view name\n"
10181 "Address family\n"
10182#ifdef HAVE_IPV6
10183 "Address family\n"
10184#endif
10185 "Address family modifier\n"
10186 "Address family modifier\n"
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display the advertised routes to neighbor\n"
10191 "Display the received routes from neighbor\n")
10192{
10193 int afi;
10194 int safi;
10195 int in;
10196 struct peer *peer;
10197
10198#ifdef HAVE_IPV6
10199 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10200#else
10201 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10202#endif
10203
10204 if (! peer)
10205 return CMD_WARNING;
10206
10207#ifdef HAVE_IPV6
10208 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10209 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10210 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10211#else
10212 afi = AFI_IP;
10213 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10214 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10215#endif
10216
10217 return peer_adj_routes (vty, peer, afi, safi, in);
10218}
10219
paul718e3742002-12-13 20:15:29 +000010220DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10221 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10222 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10223 SHOW_STR
10224 IP_STR
10225 BGP_STR
10226 "Detailed information on TCP and BGP neighbor connections\n"
10227 "Neighbor to display information about\n"
10228 "Neighbor to display information about\n"
10229 "Display information received from a BGP neighbor\n"
10230 "Display the prefixlist filter\n")
10231{
10232 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010233 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010234 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010235 int count, ret;
paul718e3742002-12-13 20:15:29 +000010236
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010237 ret = str2sockunion (argv[0], &su);
10238 if (ret < 0)
10239 {
10240 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10241 return CMD_WARNING;
10242 }
paul718e3742002-12-13 20:15:29 +000010243
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010244 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010245 if (! peer)
10246 return CMD_WARNING;
10247
10248 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10249 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10250 if (count)
10251 {
10252 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10253 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10254 }
10255
10256 return CMD_SUCCESS;
10257}
10258
10259DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10260 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10261 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10262 SHOW_STR
10263 IP_STR
10264 BGP_STR
10265 "Address family\n"
10266 "Address Family modifier\n"
10267 "Address Family modifier\n"
10268 "Detailed information on TCP and BGP neighbor connections\n"
10269 "Neighbor to display information about\n"
10270 "Neighbor to display information about\n"
10271 "Display information received from a BGP neighbor\n"
10272 "Display the prefixlist filter\n")
10273{
10274 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010276 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 int count, ret;
paul718e3742002-12-13 20:15:29 +000010278
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010279 ret = str2sockunion (argv[1], &su);
10280 if (ret < 0)
10281 {
10282 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10283 return CMD_WARNING;
10284 }
paul718e3742002-12-13 20:15:29 +000010285
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010286 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010287 if (! peer)
10288 return CMD_WARNING;
10289
10290 if (strncmp (argv[0], "m", 1) == 0)
10291 {
10292 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10293 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10294 if (count)
10295 {
10296 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10297 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10298 }
10299 }
10300 else
10301 {
10302 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10303 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10304 if (count)
10305 {
10306 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10307 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10308 }
10309 }
10310
10311 return CMD_SUCCESS;
10312}
10313
10314
10315#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010316ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010317 show_bgp_neighbor_received_routes_cmd,
10318 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10319 SHOW_STR
10320 BGP_STR
10321 "Detailed information on TCP and BGP neighbor connections\n"
10322 "Neighbor to display information about\n"
10323 "Neighbor to display information about\n"
10324 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010325
paulbb46e942003-10-24 19:02:03 +000010326ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010327 show_bgp_ipv6_neighbor_received_routes_cmd,
10328 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10329 SHOW_STR
10330 BGP_STR
10331 "Address family\n"
10332 "Detailed information on TCP and BGP neighbor connections\n"
10333 "Neighbor to display information about\n"
10334 "Neighbor to display information about\n"
10335 "Display the received routes from neighbor\n")
10336
10337DEFUN (show_bgp_neighbor_received_prefix_filter,
10338 show_bgp_neighbor_received_prefix_filter_cmd,
10339 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10340 SHOW_STR
10341 BGP_STR
10342 "Detailed information on TCP and BGP neighbor connections\n"
10343 "Neighbor to display information about\n"
10344 "Neighbor to display information about\n"
10345 "Display information received from a BGP neighbor\n"
10346 "Display the prefixlist filter\n")
10347{
10348 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010349 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010350 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010351 int count, ret;
paul718e3742002-12-13 20:15:29 +000010352
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010353 ret = str2sockunion (argv[0], &su);
10354 if (ret < 0)
10355 {
10356 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10357 return CMD_WARNING;
10358 }
paul718e3742002-12-13 20:15:29 +000010359
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010360 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010361 if (! peer)
10362 return CMD_WARNING;
10363
10364 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10365 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10366 if (count)
10367 {
10368 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10369 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10370 }
10371
10372 return CMD_SUCCESS;
10373}
10374
10375ALIAS (show_bgp_neighbor_received_prefix_filter,
10376 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10377 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10378 SHOW_STR
10379 BGP_STR
10380 "Address family\n"
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display information received from a BGP neighbor\n"
10385 "Display the prefixlist filter\n")
10386
10387/* old command */
paulbb46e942003-10-24 19:02:03 +000010388ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010389 ipv6_bgp_neighbor_received_routes_cmd,
10390 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10391 SHOW_STR
10392 IPV6_STR
10393 BGP_STR
10394 "Detailed information on TCP and BGP neighbor connections\n"
10395 "Neighbor to display information about\n"
10396 "Neighbor to display information about\n"
10397 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010398
10399/* old command */
10400DEFUN (ipv6_mbgp_neighbor_received_routes,
10401 ipv6_mbgp_neighbor_received_routes_cmd,
10402 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10403 SHOW_STR
10404 IPV6_STR
10405 MBGP_STR
10406 "Detailed information on TCP and BGP neighbor connections\n"
10407 "Neighbor to display information about\n"
10408 "Neighbor to display information about\n"
10409 "Display the received routes from neighbor\n")
10410{
paulbb46e942003-10-24 19:02:03 +000010411 struct peer *peer;
10412
10413 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10414 if (! peer)
10415 return CMD_WARNING;
10416
10417 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010418}
paulbb46e942003-10-24 19:02:03 +000010419
10420DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10421 show_bgp_view_neighbor_received_prefix_filter_cmd,
10422 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10423 SHOW_STR
10424 BGP_STR
10425 "BGP view\n"
10426 "View name\n"
10427 "Detailed information on TCP and BGP neighbor connections\n"
10428 "Neighbor to display information about\n"
10429 "Neighbor to display information about\n"
10430 "Display information received from a BGP neighbor\n"
10431 "Display the prefixlist filter\n")
10432{
10433 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010434 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010435 struct peer *peer;
10436 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010437 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010438
10439 /* BGP structure lookup. */
10440 bgp = bgp_lookup_by_name (argv[0]);
10441 if (bgp == NULL)
10442 {
10443 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10444 return CMD_WARNING;
10445 }
10446
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010447 ret = str2sockunion (argv[1], &su);
10448 if (ret < 0)
10449 {
10450 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10451 return CMD_WARNING;
10452 }
paulbb46e942003-10-24 19:02:03 +000010453
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010454 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010455 if (! peer)
10456 return CMD_WARNING;
10457
10458 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10459 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10460 if (count)
10461 {
10462 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10463 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10464 }
10465
10466 return CMD_SUCCESS;
10467}
10468
10469ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10470 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10471 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10472 SHOW_STR
10473 BGP_STR
10474 "BGP view\n"
10475 "View name\n"
10476 "Address family\n"
10477 "Detailed information on TCP and BGP neighbor connections\n"
10478 "Neighbor to display information about\n"
10479 "Neighbor to display information about\n"
10480 "Display information received from a BGP neighbor\n"
10481 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010482#endif /* HAVE_IPV6 */
10483
paul94f2b392005-06-28 12:44:16 +000010484static int
paulbb46e942003-10-24 19:02:03 +000010485bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010486 safi_t safi, enum bgp_show_type type)
10487{
paul718e3742002-12-13 20:15:29 +000010488 if (! peer || ! peer->afc[afi][safi])
10489 {
10490 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010491 return CMD_WARNING;
10492 }
10493
ajs5a646652004-11-05 01:25:55 +000010494 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010495}
10496
10497DEFUN (show_ip_bgp_neighbor_routes,
10498 show_ip_bgp_neighbor_routes_cmd,
10499 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10500 SHOW_STR
10501 IP_STR
10502 BGP_STR
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display routes learned from neighbor\n")
10507{
paulbb46e942003-10-24 19:02:03 +000010508 struct peer *peer;
10509
10510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10511 if (! peer)
10512 return CMD_WARNING;
10513
10514 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010515 bgp_show_type_neighbor);
10516}
10517
10518DEFUN (show_ip_bgp_neighbor_flap,
10519 show_ip_bgp_neighbor_flap_cmd,
10520 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10521 SHOW_STR
10522 IP_STR
10523 BGP_STR
10524 "Detailed information on TCP and BGP neighbor connections\n"
10525 "Neighbor to display information about\n"
10526 "Neighbor to display information about\n"
10527 "Display flap statistics of the routes learned from neighbor\n")
10528{
paulbb46e942003-10-24 19:02:03 +000010529 struct peer *peer;
10530
10531 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10532 if (! peer)
10533 return CMD_WARNING;
10534
10535 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010536 bgp_show_type_flap_neighbor);
10537}
10538
10539DEFUN (show_ip_bgp_neighbor_damp,
10540 show_ip_bgp_neighbor_damp_cmd,
10541 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10542 SHOW_STR
10543 IP_STR
10544 BGP_STR
10545 "Detailed information on TCP and BGP neighbor connections\n"
10546 "Neighbor to display information about\n"
10547 "Neighbor to display information about\n"
10548 "Display the dampened routes received from neighbor\n")
10549{
paulbb46e942003-10-24 19:02:03 +000010550 struct peer *peer;
10551
10552 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10553 if (! peer)
10554 return CMD_WARNING;
10555
10556 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010557 bgp_show_type_damp_neighbor);
10558}
10559
10560DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10561 show_ip_bgp_ipv4_neighbor_routes_cmd,
10562 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10563 SHOW_STR
10564 IP_STR
10565 BGP_STR
10566 "Address family\n"
10567 "Address Family modifier\n"
10568 "Address Family modifier\n"
10569 "Detailed information on TCP and BGP neighbor connections\n"
10570 "Neighbor to display information about\n"
10571 "Neighbor to display information about\n"
10572 "Display routes learned from neighbor\n")
10573{
paulbb46e942003-10-24 19:02:03 +000010574 struct peer *peer;
10575
10576 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10577 if (! peer)
10578 return CMD_WARNING;
10579
paul718e3742002-12-13 20:15:29 +000010580 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010581 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010582 bgp_show_type_neighbor);
10583
paulbb46e942003-10-24 19:02:03 +000010584 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010585 bgp_show_type_neighbor);
10586}
paulbb46e942003-10-24 19:02:03 +000010587
paulfee0f4c2004-09-13 05:12:46 +000010588DEFUN (show_ip_bgp_view_rsclient,
10589 show_ip_bgp_view_rsclient_cmd,
10590 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10591 SHOW_STR
10592 IP_STR
10593 BGP_STR
10594 "BGP view\n"
10595 "BGP view name\n"
10596 "Information about Route Server Client\n"
10597 NEIGHBOR_ADDR_STR)
10598{
10599 struct bgp_table *table;
10600 struct peer *peer;
10601
10602 if (argc == 2)
10603 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10604 else
10605 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10606
10607 if (! peer)
10608 return CMD_WARNING;
10609
10610 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10611 {
10612 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10613 VTY_NEWLINE);
10614 return CMD_WARNING;
10615 }
10616
10617 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10618 PEER_FLAG_RSERVER_CLIENT))
10619 {
10620 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10621 VTY_NEWLINE);
10622 return CMD_WARNING;
10623 }
10624
10625 table = peer->rib[AFI_IP][SAFI_UNICAST];
10626
ajs5a646652004-11-05 01:25:55 +000010627 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010628}
10629
10630ALIAS (show_ip_bgp_view_rsclient,
10631 show_ip_bgp_rsclient_cmd,
10632 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10633 SHOW_STR
10634 IP_STR
10635 BGP_STR
10636 "Information about Route Server Client\n"
10637 NEIGHBOR_ADDR_STR)
10638
Michael Lambert95cbbd22010-07-23 14:43:04 -040010639DEFUN (show_bgp_view_ipv4_safi_rsclient,
10640 show_bgp_view_ipv4_safi_rsclient_cmd,
10641 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10642 SHOW_STR
10643 BGP_STR
10644 "BGP view\n"
10645 "BGP view name\n"
10646 "Address family\n"
10647 "Address Family modifier\n"
10648 "Address Family modifier\n"
10649 "Information about Route Server Client\n"
10650 NEIGHBOR_ADDR_STR)
10651{
10652 struct bgp_table *table;
10653 struct peer *peer;
10654 safi_t safi;
10655
10656 if (argc == 3) {
10657 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10658 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10659 } else {
10660 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10661 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10662 }
10663
10664 if (! peer)
10665 return CMD_WARNING;
10666
10667 if (! peer->afc[AFI_IP][safi])
10668 {
10669 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10670 VTY_NEWLINE);
10671 return CMD_WARNING;
10672 }
10673
10674 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10675 PEER_FLAG_RSERVER_CLIENT))
10676 {
10677 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10678 VTY_NEWLINE);
10679 return CMD_WARNING;
10680 }
10681
10682 table = peer->rib[AFI_IP][safi];
10683
10684 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10685}
10686
10687ALIAS (show_bgp_view_ipv4_safi_rsclient,
10688 show_bgp_ipv4_safi_rsclient_cmd,
10689 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10690 SHOW_STR
10691 BGP_STR
10692 "Address family\n"
10693 "Address Family modifier\n"
10694 "Address Family modifier\n"
10695 "Information about Route Server Client\n"
10696 NEIGHBOR_ADDR_STR)
10697
paulfee0f4c2004-09-13 05:12:46 +000010698DEFUN (show_ip_bgp_view_rsclient_route,
10699 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010700 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010701 SHOW_STR
10702 IP_STR
10703 BGP_STR
10704 "BGP view\n"
10705 "BGP view name\n"
10706 "Information about Route Server Client\n"
10707 NEIGHBOR_ADDR_STR
10708 "Network in the BGP routing table to display\n")
10709{
10710 struct bgp *bgp;
10711 struct peer *peer;
10712
10713 /* BGP structure lookup. */
10714 if (argc == 3)
10715 {
10716 bgp = bgp_lookup_by_name (argv[0]);
10717 if (bgp == NULL)
10718 {
10719 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10720 return CMD_WARNING;
10721 }
10722 }
10723 else
10724 {
10725 bgp = bgp_get_default ();
10726 if (bgp == NULL)
10727 {
10728 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10729 return CMD_WARNING;
10730 }
10731 }
10732
10733 if (argc == 3)
10734 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10735 else
10736 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10737
10738 if (! peer)
10739 return CMD_WARNING;
10740
10741 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10742 {
10743 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10744 VTY_NEWLINE);
10745 return CMD_WARNING;
10746}
10747
10748 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10749 PEER_FLAG_RSERVER_CLIENT))
10750 {
10751 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10752 VTY_NEWLINE);
10753 return CMD_WARNING;
10754 }
10755
10756 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10757 (argc == 3) ? argv[2] : argv[1],
10758 AFI_IP, SAFI_UNICAST, NULL, 0);
10759}
10760
10761ALIAS (show_ip_bgp_view_rsclient_route,
10762 show_ip_bgp_rsclient_route_cmd,
10763 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10764 SHOW_STR
10765 IP_STR
10766 BGP_STR
10767 "Information about Route Server Client\n"
10768 NEIGHBOR_ADDR_STR
10769 "Network in the BGP routing table to display\n")
10770
Michael Lambert95cbbd22010-07-23 14:43:04 -040010771DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10772 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10773 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10774 SHOW_STR
10775 BGP_STR
10776 "BGP view\n"
10777 "BGP view name\n"
10778 "Address family\n"
10779 "Address Family modifier\n"
10780 "Address Family modifier\n"
10781 "Information about Route Server Client\n"
10782 NEIGHBOR_ADDR_STR
10783 "Network in the BGP routing table to display\n")
10784{
10785 struct bgp *bgp;
10786 struct peer *peer;
10787 safi_t safi;
10788
10789 /* BGP structure lookup. */
10790 if (argc == 4)
10791 {
10792 bgp = bgp_lookup_by_name (argv[0]);
10793 if (bgp == NULL)
10794 {
10795 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10796 return CMD_WARNING;
10797 }
10798 }
10799 else
10800 {
10801 bgp = bgp_get_default ();
10802 if (bgp == NULL)
10803 {
10804 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10805 return CMD_WARNING;
10806 }
10807 }
10808
10809 if (argc == 4) {
10810 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10811 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10812 } else {
10813 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10814 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10815 }
10816
10817 if (! peer)
10818 return CMD_WARNING;
10819
10820 if (! peer->afc[AFI_IP][safi])
10821 {
10822 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10823 VTY_NEWLINE);
10824 return CMD_WARNING;
10825}
10826
10827 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10828 PEER_FLAG_RSERVER_CLIENT))
10829 {
10830 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10831 VTY_NEWLINE);
10832 return CMD_WARNING;
10833 }
10834
10835 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10836 (argc == 4) ? argv[3] : argv[2],
10837 AFI_IP, safi, NULL, 0);
10838}
10839
10840ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10841 show_bgp_ipv4_safi_rsclient_route_cmd,
10842 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10843 SHOW_STR
10844 BGP_STR
10845 "Address family\n"
10846 "Address Family modifier\n"
10847 "Address Family modifier\n"
10848 "Information about Route Server Client\n"
10849 NEIGHBOR_ADDR_STR
10850 "Network in the BGP routing table to display\n")
10851
paulfee0f4c2004-09-13 05:12:46 +000010852DEFUN (show_ip_bgp_view_rsclient_prefix,
10853 show_ip_bgp_view_rsclient_prefix_cmd,
10854 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10855 SHOW_STR
10856 IP_STR
10857 BGP_STR
10858 "BGP view\n"
10859 "BGP view name\n"
10860 "Information about Route Server Client\n"
10861 NEIGHBOR_ADDR_STR
10862 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10863{
10864 struct bgp *bgp;
10865 struct peer *peer;
10866
10867 /* BGP structure lookup. */
10868 if (argc == 3)
10869 {
10870 bgp = bgp_lookup_by_name (argv[0]);
10871 if (bgp == NULL)
10872 {
10873 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876 }
10877 else
10878 {
10879 bgp = bgp_get_default ();
10880 if (bgp == NULL)
10881 {
10882 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10883 return CMD_WARNING;
10884 }
10885 }
10886
10887 if (argc == 3)
10888 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10889 else
10890 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10891
10892 if (! peer)
10893 return CMD_WARNING;
10894
10895 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10896 {
10897 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10898 VTY_NEWLINE);
10899 return CMD_WARNING;
10900}
10901
10902 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10903 PEER_FLAG_RSERVER_CLIENT))
10904{
10905 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10906 VTY_NEWLINE);
10907 return CMD_WARNING;
10908 }
10909
10910 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10911 (argc == 3) ? argv[2] : argv[1],
10912 AFI_IP, SAFI_UNICAST, NULL, 1);
10913}
10914
10915ALIAS (show_ip_bgp_view_rsclient_prefix,
10916 show_ip_bgp_rsclient_prefix_cmd,
10917 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10918 SHOW_STR
10919 IP_STR
10920 BGP_STR
10921 "Information about Route Server Client\n"
10922 NEIGHBOR_ADDR_STR
10923 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10924
Michael Lambert95cbbd22010-07-23 14:43:04 -040010925DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10926 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10927 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10928 SHOW_STR
10929 BGP_STR
10930 "BGP view\n"
10931 "BGP view name\n"
10932 "Address family\n"
10933 "Address Family modifier\n"
10934 "Address Family modifier\n"
10935 "Information about Route Server Client\n"
10936 NEIGHBOR_ADDR_STR
10937 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10938{
10939 struct bgp *bgp;
10940 struct peer *peer;
10941 safi_t safi;
10942
10943 /* BGP structure lookup. */
10944 if (argc == 4)
10945 {
10946 bgp = bgp_lookup_by_name (argv[0]);
10947 if (bgp == NULL)
10948 {
10949 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10950 return CMD_WARNING;
10951 }
10952 }
10953 else
10954 {
10955 bgp = bgp_get_default ();
10956 if (bgp == NULL)
10957 {
10958 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10959 return CMD_WARNING;
10960 }
10961 }
10962
10963 if (argc == 4) {
10964 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10965 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10966 } else {
10967 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10968 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10969 }
10970
10971 if (! peer)
10972 return CMD_WARNING;
10973
10974 if (! peer->afc[AFI_IP][safi])
10975 {
10976 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10977 VTY_NEWLINE);
10978 return CMD_WARNING;
10979}
10980
10981 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10982 PEER_FLAG_RSERVER_CLIENT))
10983{
10984 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10985 VTY_NEWLINE);
10986 return CMD_WARNING;
10987 }
10988
10989 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10990 (argc == 4) ? argv[3] : argv[2],
10991 AFI_IP, safi, NULL, 1);
10992}
10993
10994ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10995 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10996 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10997 SHOW_STR
10998 BGP_STR
10999 "Address family\n"
11000 "Address Family modifier\n"
11001 "Address Family modifier\n"
11002 "Information about Route Server Client\n"
11003 NEIGHBOR_ADDR_STR
11004 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011005
paul718e3742002-12-13 20:15:29 +000011006#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011007DEFUN (show_bgp_view_neighbor_routes,
11008 show_bgp_view_neighbor_routes_cmd,
11009 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11010 SHOW_STR
11011 BGP_STR
11012 "BGP view\n"
11013 "BGP view name\n"
11014 "Detailed information on TCP and BGP neighbor connections\n"
11015 "Neighbor to display information about\n"
11016 "Neighbor to display information about\n"
11017 "Display routes learned from neighbor\n")
11018{
11019 struct peer *peer;
11020
11021 if (argc == 2)
11022 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11023 else
11024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11025
11026 if (! peer)
11027 return CMD_WARNING;
11028
11029 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11030 bgp_show_type_neighbor);
11031}
11032
11033ALIAS (show_bgp_view_neighbor_routes,
11034 show_bgp_view_ipv6_neighbor_routes_cmd,
11035 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11036 SHOW_STR
11037 BGP_STR
11038 "BGP view\n"
11039 "BGP view name\n"
11040 "Address family\n"
11041 "Detailed information on TCP and BGP neighbor connections\n"
11042 "Neighbor to display information about\n"
11043 "Neighbor to display information about\n"
11044 "Display routes learned from neighbor\n")
11045
11046DEFUN (show_bgp_view_neighbor_damp,
11047 show_bgp_view_neighbor_damp_cmd,
11048 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11049 SHOW_STR
11050 BGP_STR
11051 "BGP view\n"
11052 "BGP view name\n"
11053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display the dampened routes received from neighbor\n")
11057{
11058 struct peer *peer;
11059
11060 if (argc == 2)
11061 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11062 else
11063 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11064
11065 if (! peer)
11066 return CMD_WARNING;
11067
11068 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11069 bgp_show_type_damp_neighbor);
11070}
11071
11072ALIAS (show_bgp_view_neighbor_damp,
11073 show_bgp_view_ipv6_neighbor_damp_cmd,
11074 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11075 SHOW_STR
11076 BGP_STR
11077 "BGP view\n"
11078 "BGP view name\n"
11079 "Address family\n"
11080 "Detailed information on TCP and BGP neighbor connections\n"
11081 "Neighbor to display information about\n"
11082 "Neighbor to display information about\n"
11083 "Display the dampened routes received from neighbor\n")
11084
11085DEFUN (show_bgp_view_neighbor_flap,
11086 show_bgp_view_neighbor_flap_cmd,
11087 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11088 SHOW_STR
11089 BGP_STR
11090 "BGP view\n"
11091 "BGP view name\n"
11092 "Detailed information on TCP and BGP neighbor connections\n"
11093 "Neighbor to display information about\n"
11094 "Neighbor to display information about\n"
11095 "Display flap statistics of the routes learned from neighbor\n")
11096{
11097 struct peer *peer;
11098
11099 if (argc == 2)
11100 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11101 else
11102 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11103
11104 if (! peer)
11105 return CMD_WARNING;
11106
11107 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11108 bgp_show_type_flap_neighbor);
11109}
11110
11111ALIAS (show_bgp_view_neighbor_flap,
11112 show_bgp_view_ipv6_neighbor_flap_cmd,
11113 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11114 SHOW_STR
11115 BGP_STR
11116 "BGP view\n"
11117 "BGP view name\n"
11118 "Address family\n"
11119 "Detailed information on TCP and BGP neighbor connections\n"
11120 "Neighbor to display information about\n"
11121 "Neighbor to display information about\n"
11122 "Display flap statistics of the routes learned from neighbor\n")
11123
11124ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011125 show_bgp_neighbor_routes_cmd,
11126 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11127 SHOW_STR
11128 BGP_STR
11129 "Detailed information on TCP and BGP neighbor connections\n"
11130 "Neighbor to display information about\n"
11131 "Neighbor to display information about\n"
11132 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011133
paulbb46e942003-10-24 19:02:03 +000011134
11135ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011136 show_bgp_ipv6_neighbor_routes_cmd,
11137 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11138 SHOW_STR
11139 BGP_STR
11140 "Address family\n"
11141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Display routes learned from neighbor\n")
11145
11146/* old command */
paulbb46e942003-10-24 19:02:03 +000011147ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011148 ipv6_bgp_neighbor_routes_cmd,
11149 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11150 SHOW_STR
11151 IPV6_STR
11152 BGP_STR
11153 "Detailed information on TCP and BGP neighbor connections\n"
11154 "Neighbor to display information about\n"
11155 "Neighbor to display information about\n"
11156 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011157
11158/* old command */
11159DEFUN (ipv6_mbgp_neighbor_routes,
11160 ipv6_mbgp_neighbor_routes_cmd,
11161 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11162 SHOW_STR
11163 IPV6_STR
11164 MBGP_STR
11165 "Detailed information on TCP and BGP neighbor connections\n"
11166 "Neighbor to display information about\n"
11167 "Neighbor to display information about\n"
11168 "Display routes learned from neighbor\n")
11169{
paulbb46e942003-10-24 19:02:03 +000011170 struct peer *peer;
11171
11172 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11173 if (! peer)
11174 return CMD_WARNING;
11175
11176 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011177 bgp_show_type_neighbor);
11178}
paulbb46e942003-10-24 19:02:03 +000011179
11180ALIAS (show_bgp_view_neighbor_flap,
11181 show_bgp_neighbor_flap_cmd,
11182 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11183 SHOW_STR
11184 BGP_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 flap statistics of the routes learned from neighbor\n")
11189
11190ALIAS (show_bgp_view_neighbor_flap,
11191 show_bgp_ipv6_neighbor_flap_cmd,
11192 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11193 SHOW_STR
11194 BGP_STR
11195 "Address family\n"
11196 "Detailed information on TCP and BGP neighbor connections\n"
11197 "Neighbor to display information about\n"
11198 "Neighbor to display information about\n"
11199 "Display flap statistics of the routes learned from neighbor\n")
11200
11201ALIAS (show_bgp_view_neighbor_damp,
11202 show_bgp_neighbor_damp_cmd,
11203 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11204 SHOW_STR
11205 BGP_STR
11206 "Detailed information on TCP and BGP neighbor connections\n"
11207 "Neighbor to display information about\n"
11208 "Neighbor to display information about\n"
11209 "Display the dampened routes received from neighbor\n")
11210
11211ALIAS (show_bgp_view_neighbor_damp,
11212 show_bgp_ipv6_neighbor_damp_cmd,
11213 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11214 SHOW_STR
11215 BGP_STR
11216 "Address family\n"
11217 "Detailed information on TCP and BGP neighbor connections\n"
11218 "Neighbor to display information about\n"
11219 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011220 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011221
11222DEFUN (show_bgp_view_rsclient,
11223 show_bgp_view_rsclient_cmd,
11224 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11225 SHOW_STR
11226 BGP_STR
11227 "BGP view\n"
11228 "BGP view name\n"
11229 "Information about Route Server Client\n"
11230 NEIGHBOR_ADDR_STR)
11231{
11232 struct bgp_table *table;
11233 struct peer *peer;
11234
11235 if (argc == 2)
11236 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11237 else
11238 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11239
11240 if (! peer)
11241 return CMD_WARNING;
11242
11243 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11244 {
11245 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11246 VTY_NEWLINE);
11247 return CMD_WARNING;
11248 }
11249
11250 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11251 PEER_FLAG_RSERVER_CLIENT))
11252 {
11253 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11254 VTY_NEWLINE);
11255 return CMD_WARNING;
11256 }
11257
11258 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11259
ajs5a646652004-11-05 01:25:55 +000011260 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011261}
11262
11263ALIAS (show_bgp_view_rsclient,
11264 show_bgp_rsclient_cmd,
11265 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11266 SHOW_STR
11267 BGP_STR
11268 "Information about Route Server Client\n"
11269 NEIGHBOR_ADDR_STR)
11270
Michael Lambert95cbbd22010-07-23 14:43:04 -040011271DEFUN (show_bgp_view_ipv6_safi_rsclient,
11272 show_bgp_view_ipv6_safi_rsclient_cmd,
11273 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11274 SHOW_STR
11275 BGP_STR
11276 "BGP view\n"
11277 "BGP view name\n"
11278 "Address family\n"
11279 "Address Family modifier\n"
11280 "Address Family modifier\n"
11281 "Information about Route Server Client\n"
11282 NEIGHBOR_ADDR_STR)
11283{
11284 struct bgp_table *table;
11285 struct peer *peer;
11286 safi_t safi;
11287
11288 if (argc == 3) {
11289 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11290 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11291 } else {
11292 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11293 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11294 }
11295
11296 if (! peer)
11297 return CMD_WARNING;
11298
11299 if (! peer->afc[AFI_IP6][safi])
11300 {
11301 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11302 VTY_NEWLINE);
11303 return CMD_WARNING;
11304 }
11305
11306 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11307 PEER_FLAG_RSERVER_CLIENT))
11308 {
11309 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11310 VTY_NEWLINE);
11311 return CMD_WARNING;
11312 }
11313
11314 table = peer->rib[AFI_IP6][safi];
11315
11316 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11317}
11318
11319ALIAS (show_bgp_view_ipv6_safi_rsclient,
11320 show_bgp_ipv6_safi_rsclient_cmd,
11321 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11322 SHOW_STR
11323 BGP_STR
11324 "Address family\n"
11325 "Address Family modifier\n"
11326 "Address Family modifier\n"
11327 "Information about Route Server Client\n"
11328 NEIGHBOR_ADDR_STR)
11329
paulfee0f4c2004-09-13 05:12:46 +000011330DEFUN (show_bgp_view_rsclient_route,
11331 show_bgp_view_rsclient_route_cmd,
11332 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11333 SHOW_STR
11334 BGP_STR
11335 "BGP view\n"
11336 "BGP view name\n"
11337 "Information about Route Server Client\n"
11338 NEIGHBOR_ADDR_STR
11339 "Network in the BGP routing table to display\n")
11340{
11341 struct bgp *bgp;
11342 struct peer *peer;
11343
11344 /* BGP structure lookup. */
11345 if (argc == 3)
11346 {
11347 bgp = bgp_lookup_by_name (argv[0]);
11348 if (bgp == NULL)
11349 {
11350 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11351 return CMD_WARNING;
11352 }
11353 }
11354 else
11355 {
11356 bgp = bgp_get_default ();
11357 if (bgp == NULL)
11358 {
11359 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362 }
11363
11364 if (argc == 3)
11365 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11366 else
11367 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11368
11369 if (! peer)
11370 return CMD_WARNING;
11371
11372 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11373 {
11374 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11375 VTY_NEWLINE);
11376 return CMD_WARNING;
11377 }
11378
11379 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11380 PEER_FLAG_RSERVER_CLIENT))
11381 {
11382 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11383 VTY_NEWLINE);
11384 return CMD_WARNING;
11385 }
11386
11387 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11388 (argc == 3) ? argv[2] : argv[1],
11389 AFI_IP6, SAFI_UNICAST, NULL, 0);
11390}
11391
11392ALIAS (show_bgp_view_rsclient_route,
11393 show_bgp_rsclient_route_cmd,
11394 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11395 SHOW_STR
11396 BGP_STR
11397 "Information about Route Server Client\n"
11398 NEIGHBOR_ADDR_STR
11399 "Network in the BGP routing table to display\n")
11400
Michael Lambert95cbbd22010-07-23 14:43:04 -040011401DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11402 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11403 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11404 SHOW_STR
11405 BGP_STR
11406 "BGP view\n"
11407 "BGP view name\n"
11408 "Address family\n"
11409 "Address Family modifier\n"
11410 "Address Family modifier\n"
11411 "Information about Route Server Client\n"
11412 NEIGHBOR_ADDR_STR
11413 "Network in the BGP routing table to display\n")
11414{
11415 struct bgp *bgp;
11416 struct peer *peer;
11417 safi_t safi;
11418
11419 /* BGP structure lookup. */
11420 if (argc == 4)
11421 {
11422 bgp = bgp_lookup_by_name (argv[0]);
11423 if (bgp == NULL)
11424 {
11425 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11426 return CMD_WARNING;
11427 }
11428 }
11429 else
11430 {
11431 bgp = bgp_get_default ();
11432 if (bgp == NULL)
11433 {
11434 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11435 return CMD_WARNING;
11436 }
11437 }
11438
11439 if (argc == 4) {
11440 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11441 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11442 } else {
11443 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11444 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11445 }
11446
11447 if (! peer)
11448 return CMD_WARNING;
11449
11450 if (! peer->afc[AFI_IP6][safi])
11451 {
11452 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11453 VTY_NEWLINE);
11454 return CMD_WARNING;
11455}
11456
11457 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11458 PEER_FLAG_RSERVER_CLIENT))
11459 {
11460 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11461 VTY_NEWLINE);
11462 return CMD_WARNING;
11463 }
11464
11465 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11466 (argc == 4) ? argv[3] : argv[2],
11467 AFI_IP6, safi, NULL, 0);
11468}
11469
11470ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11471 show_bgp_ipv6_safi_rsclient_route_cmd,
11472 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11473 SHOW_STR
11474 BGP_STR
11475 "Address family\n"
11476 "Address Family modifier\n"
11477 "Address Family modifier\n"
11478 "Information about Route Server Client\n"
11479 NEIGHBOR_ADDR_STR
11480 "Network in the BGP routing table to display\n")
11481
paulfee0f4c2004-09-13 05:12:46 +000011482DEFUN (show_bgp_view_rsclient_prefix,
11483 show_bgp_view_rsclient_prefix_cmd,
11484 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11485 SHOW_STR
11486 BGP_STR
11487 "BGP view\n"
11488 "BGP view name\n"
11489 "Information about Route Server Client\n"
11490 NEIGHBOR_ADDR_STR
11491 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11492{
11493 struct bgp *bgp;
11494 struct peer *peer;
11495
11496 /* BGP structure lookup. */
11497 if (argc == 3)
11498 {
11499 bgp = bgp_lookup_by_name (argv[0]);
11500 if (bgp == NULL)
11501 {
11502 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11503 return CMD_WARNING;
11504 }
11505 }
11506 else
11507 {
11508 bgp = bgp_get_default ();
11509 if (bgp == NULL)
11510 {
11511 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11512 return CMD_WARNING;
11513 }
11514 }
11515
11516 if (argc == 3)
11517 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11518 else
11519 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11520
11521 if (! peer)
11522 return CMD_WARNING;
11523
11524 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11525 {
11526 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11527 VTY_NEWLINE);
11528 return CMD_WARNING;
11529 }
11530
11531 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11532 PEER_FLAG_RSERVER_CLIENT))
11533 {
11534 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11535 VTY_NEWLINE);
11536 return CMD_WARNING;
11537 }
11538
11539 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11540 (argc == 3) ? argv[2] : argv[1],
11541 AFI_IP6, SAFI_UNICAST, NULL, 1);
11542}
11543
11544ALIAS (show_bgp_view_rsclient_prefix,
11545 show_bgp_rsclient_prefix_cmd,
11546 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11547 SHOW_STR
11548 BGP_STR
11549 "Information about Route Server Client\n"
11550 NEIGHBOR_ADDR_STR
11551 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11552
Michael Lambert95cbbd22010-07-23 14:43:04 -040011553DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11554 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11555 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11556 SHOW_STR
11557 BGP_STR
11558 "BGP view\n"
11559 "BGP view name\n"
11560 "Address family\n"
11561 "Address Family modifier\n"
11562 "Address Family modifier\n"
11563 "Information about Route Server Client\n"
11564 NEIGHBOR_ADDR_STR
11565 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11566{
11567 struct bgp *bgp;
11568 struct peer *peer;
11569 safi_t safi;
11570
11571 /* BGP structure lookup. */
11572 if (argc == 4)
11573 {
11574 bgp = bgp_lookup_by_name (argv[0]);
11575 if (bgp == NULL)
11576 {
11577 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11578 return CMD_WARNING;
11579 }
11580 }
11581 else
11582 {
11583 bgp = bgp_get_default ();
11584 if (bgp == NULL)
11585 {
11586 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11587 return CMD_WARNING;
11588 }
11589 }
11590
11591 if (argc == 4) {
11592 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11593 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11594 } else {
11595 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11596 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11597 }
11598
11599 if (! peer)
11600 return CMD_WARNING;
11601
11602 if (! peer->afc[AFI_IP6][safi])
11603 {
11604 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11605 VTY_NEWLINE);
11606 return CMD_WARNING;
11607}
11608
11609 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11610 PEER_FLAG_RSERVER_CLIENT))
11611{
11612 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11613 VTY_NEWLINE);
11614 return CMD_WARNING;
11615 }
11616
11617 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11618 (argc == 4) ? argv[3] : argv[2],
11619 AFI_IP6, safi, NULL, 1);
11620}
11621
11622ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11623 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11624 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11625 SHOW_STR
11626 BGP_STR
11627 "Address family\n"
11628 "Address Family modifier\n"
11629 "Address Family modifier\n"
11630 "Information about Route Server Client\n"
11631 NEIGHBOR_ADDR_STR
11632 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11633
paul718e3742002-12-13 20:15:29 +000011634#endif /* HAVE_IPV6 */
11635
11636struct bgp_table *bgp_distance_table;
11637
11638struct bgp_distance
11639{
11640 /* Distance value for the IP source prefix. */
11641 u_char distance;
11642
11643 /* Name of the access-list to be matched. */
11644 char *access_list;
11645};
11646
paul94f2b392005-06-28 12:44:16 +000011647static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011648bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011649{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011650 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011651}
11652
paul94f2b392005-06-28 12:44:16 +000011653static void
paul718e3742002-12-13 20:15:29 +000011654bgp_distance_free (struct bgp_distance *bdistance)
11655{
11656 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11657}
11658
paul94f2b392005-06-28 12:44:16 +000011659static int
paulfd79ac92004-10-13 05:06:08 +000011660bgp_distance_set (struct vty *vty, const char *distance_str,
11661 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011662{
11663 int ret;
11664 struct prefix_ipv4 p;
11665 u_char distance;
11666 struct bgp_node *rn;
11667 struct bgp_distance *bdistance;
11668
11669 ret = str2prefix_ipv4 (ip_str, &p);
11670 if (ret == 0)
11671 {
11672 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11673 return CMD_WARNING;
11674 }
11675
11676 distance = atoi (distance_str);
11677
11678 /* Get BGP distance node. */
11679 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11680 if (rn->info)
11681 {
11682 bdistance = rn->info;
11683 bgp_unlock_node (rn);
11684 }
11685 else
11686 {
11687 bdistance = bgp_distance_new ();
11688 rn->info = bdistance;
11689 }
11690
11691 /* Set distance value. */
11692 bdistance->distance = distance;
11693
11694 /* Reset access-list configuration. */
11695 if (bdistance->access_list)
11696 {
11697 free (bdistance->access_list);
11698 bdistance->access_list = NULL;
11699 }
11700 if (access_list_str)
11701 bdistance->access_list = strdup (access_list_str);
11702
11703 return CMD_SUCCESS;
11704}
11705
paul94f2b392005-06-28 12:44:16 +000011706static int
paulfd79ac92004-10-13 05:06:08 +000011707bgp_distance_unset (struct vty *vty, const char *distance_str,
11708 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011709{
11710 int ret;
11711 struct prefix_ipv4 p;
11712 u_char distance;
11713 struct bgp_node *rn;
11714 struct bgp_distance *bdistance;
11715
11716 ret = str2prefix_ipv4 (ip_str, &p);
11717 if (ret == 0)
11718 {
11719 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11720 return CMD_WARNING;
11721 }
11722
11723 distance = atoi (distance_str);
11724
11725 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11726 if (! rn)
11727 {
11728 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11729 return CMD_WARNING;
11730 }
11731
11732 bdistance = rn->info;
11733
11734 if (bdistance->access_list)
11735 free (bdistance->access_list);
11736 bgp_distance_free (bdistance);
11737
11738 rn->info = NULL;
11739 bgp_unlock_node (rn);
11740 bgp_unlock_node (rn);
11741
11742 return CMD_SUCCESS;
11743}
11744
paul718e3742002-12-13 20:15:29 +000011745/* Apply BGP information to distance method. */
11746u_char
11747bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11748{
11749 struct bgp_node *rn;
11750 struct prefix_ipv4 q;
11751 struct peer *peer;
11752 struct bgp_distance *bdistance;
11753 struct access_list *alist;
11754 struct bgp_static *bgp_static;
11755
11756 if (! bgp)
11757 return 0;
11758
11759 if (p->family != AF_INET)
11760 return 0;
11761
11762 peer = rinfo->peer;
11763
11764 if (peer->su.sa.sa_family != AF_INET)
11765 return 0;
11766
11767 memset (&q, 0, sizeof (struct prefix_ipv4));
11768 q.family = AF_INET;
11769 q.prefix = peer->su.sin.sin_addr;
11770 q.prefixlen = IPV4_MAX_BITLEN;
11771
11772 /* Check source address. */
11773 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11774 if (rn)
11775 {
11776 bdistance = rn->info;
11777 bgp_unlock_node (rn);
11778
11779 if (bdistance->access_list)
11780 {
11781 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11782 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11783 return bdistance->distance;
11784 }
11785 else
11786 return bdistance->distance;
11787 }
11788
11789 /* Backdoor check. */
11790 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11791 if (rn)
11792 {
11793 bgp_static = rn->info;
11794 bgp_unlock_node (rn);
11795
11796 if (bgp_static->backdoor)
11797 {
11798 if (bgp->distance_local)
11799 return bgp->distance_local;
11800 else
11801 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11802 }
11803 }
11804
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011805 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011806 {
11807 if (bgp->distance_ebgp)
11808 return bgp->distance_ebgp;
11809 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11810 }
11811 else
11812 {
11813 if (bgp->distance_ibgp)
11814 return bgp->distance_ibgp;
11815 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11816 }
11817}
11818
11819DEFUN (bgp_distance,
11820 bgp_distance_cmd,
11821 "distance bgp <1-255> <1-255> <1-255>",
11822 "Define an administrative distance\n"
11823 "BGP distance\n"
11824 "Distance for routes external to the AS\n"
11825 "Distance for routes internal to the AS\n"
11826 "Distance for local routes\n")
11827{
11828 struct bgp *bgp;
11829
11830 bgp = vty->index;
11831
11832 bgp->distance_ebgp = atoi (argv[0]);
11833 bgp->distance_ibgp = atoi (argv[1]);
11834 bgp->distance_local = atoi (argv[2]);
11835 return CMD_SUCCESS;
11836}
11837
11838DEFUN (no_bgp_distance,
11839 no_bgp_distance_cmd,
11840 "no distance bgp <1-255> <1-255> <1-255>",
11841 NO_STR
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= 0;
11853 bgp->distance_ibgp = 0;
11854 bgp->distance_local = 0;
11855 return CMD_SUCCESS;
11856}
11857
11858ALIAS (no_bgp_distance,
11859 no_bgp_distance2_cmd,
11860 "no distance bgp",
11861 NO_STR
11862 "Define an administrative distance\n"
11863 "BGP distance\n")
11864
11865DEFUN (bgp_distance_source,
11866 bgp_distance_source_cmd,
11867 "distance <1-255> A.B.C.D/M",
11868 "Define an administrative distance\n"
11869 "Administrative distance\n"
11870 "IP source prefix\n")
11871{
11872 bgp_distance_set (vty, argv[0], argv[1], NULL);
11873 return CMD_SUCCESS;
11874}
11875
11876DEFUN (no_bgp_distance_source,
11877 no_bgp_distance_source_cmd,
11878 "no distance <1-255> A.B.C.D/M",
11879 NO_STR
11880 "Define an administrative distance\n"
11881 "Administrative distance\n"
11882 "IP source prefix\n")
11883{
11884 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11885 return CMD_SUCCESS;
11886}
11887
11888DEFUN (bgp_distance_source_access_list,
11889 bgp_distance_source_access_list_cmd,
11890 "distance <1-255> A.B.C.D/M WORD",
11891 "Define an administrative distance\n"
11892 "Administrative distance\n"
11893 "IP source prefix\n"
11894 "Access list name\n")
11895{
11896 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11897 return CMD_SUCCESS;
11898}
11899
11900DEFUN (no_bgp_distance_source_access_list,
11901 no_bgp_distance_source_access_list_cmd,
11902 "no distance <1-255> A.B.C.D/M WORD",
11903 NO_STR
11904 "Define an administrative distance\n"
11905 "Administrative distance\n"
11906 "IP source prefix\n"
11907 "Access list name\n")
11908{
11909 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11910 return CMD_SUCCESS;
11911}
11912
11913DEFUN (bgp_damp_set,
11914 bgp_damp_set_cmd,
11915 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11916 "BGP Specific commands\n"
11917 "Enable route-flap dampening\n"
11918 "Half-life time for the penalty\n"
11919 "Value to start reusing a route\n"
11920 "Value to start suppressing a route\n"
11921 "Maximum duration to suppress a stable route\n")
11922{
11923 struct bgp *bgp;
11924 int half = DEFAULT_HALF_LIFE * 60;
11925 int reuse = DEFAULT_REUSE;
11926 int suppress = DEFAULT_SUPPRESS;
11927 int max = 4 * half;
11928
11929 if (argc == 4)
11930 {
11931 half = atoi (argv[0]) * 60;
11932 reuse = atoi (argv[1]);
11933 suppress = atoi (argv[2]);
11934 max = atoi (argv[3]) * 60;
11935 }
11936 else if (argc == 1)
11937 {
11938 half = atoi (argv[0]) * 60;
11939 max = 4 * half;
11940 }
11941
11942 bgp = vty->index;
11943 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11944 half, reuse, suppress, max);
11945}
11946
11947ALIAS (bgp_damp_set,
11948 bgp_damp_set2_cmd,
11949 "bgp dampening <1-45>",
11950 "BGP Specific commands\n"
11951 "Enable route-flap dampening\n"
11952 "Half-life time for the penalty\n")
11953
11954ALIAS (bgp_damp_set,
11955 bgp_damp_set3_cmd,
11956 "bgp dampening",
11957 "BGP Specific commands\n"
11958 "Enable route-flap dampening\n")
11959
11960DEFUN (bgp_damp_unset,
11961 bgp_damp_unset_cmd,
11962 "no bgp dampening",
11963 NO_STR
11964 "BGP Specific commands\n"
11965 "Enable route-flap dampening\n")
11966{
11967 struct bgp *bgp;
11968
11969 bgp = vty->index;
11970 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11971}
11972
11973ALIAS (bgp_damp_unset,
11974 bgp_damp_unset2_cmd,
11975 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11976 NO_STR
11977 "BGP Specific commands\n"
11978 "Enable route-flap dampening\n"
11979 "Half-life time for the penalty\n"
11980 "Value to start reusing a route\n"
11981 "Value to start suppressing a route\n"
11982 "Maximum duration to suppress a stable route\n")
11983
11984DEFUN (show_ip_bgp_dampened_paths,
11985 show_ip_bgp_dampened_paths_cmd,
11986 "show ip bgp dampened-paths",
11987 SHOW_STR
11988 IP_STR
11989 BGP_STR
11990 "Display paths suppressed due to dampening\n")
11991{
ajs5a646652004-11-05 01:25:55 +000011992 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11993 NULL);
paul718e3742002-12-13 20:15:29 +000011994}
11995
11996DEFUN (show_ip_bgp_flap_statistics,
11997 show_ip_bgp_flap_statistics_cmd,
11998 "show ip bgp flap-statistics",
11999 SHOW_STR
12000 IP_STR
12001 BGP_STR
12002 "Display flap statistics of routes\n")
12003{
ajs5a646652004-11-05 01:25:55 +000012004 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12005 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012006}
12007
12008/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012009static int
paulfd79ac92004-10-13 05:06:08 +000012010bgp_clear_damp_route (struct vty *vty, const char *view_name,
12011 const char *ip_str, afi_t afi, safi_t safi,
12012 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012013{
12014 int ret;
12015 struct prefix match;
12016 struct bgp_node *rn;
12017 struct bgp_node *rm;
12018 struct bgp_info *ri;
12019 struct bgp_info *ri_temp;
12020 struct bgp *bgp;
12021 struct bgp_table *table;
12022
12023 /* BGP structure lookup. */
12024 if (view_name)
12025 {
12026 bgp = bgp_lookup_by_name (view_name);
12027 if (bgp == NULL)
12028 {
12029 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12030 return CMD_WARNING;
12031 }
12032 }
12033 else
12034 {
12035 bgp = bgp_get_default ();
12036 if (bgp == NULL)
12037 {
12038 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12039 return CMD_WARNING;
12040 }
12041 }
12042
12043 /* Check IP address argument. */
12044 ret = str2prefix (ip_str, &match);
12045 if (! ret)
12046 {
12047 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12048 return CMD_WARNING;
12049 }
12050
12051 match.family = afi2family (afi);
12052
12053 if (safi == SAFI_MPLS_VPN)
12054 {
12055 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12056 {
12057 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12058 continue;
12059
12060 if ((table = rn->info) != NULL)
12061 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012062 {
12063 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12064 {
12065 ri = rm->info;
12066 while (ri)
12067 {
12068 if (ri->extra && ri->extra->damp_info)
12069 {
12070 ri_temp = ri->next;
12071 bgp_damp_info_free (ri->extra->damp_info, 1);
12072 ri = ri_temp;
12073 }
12074 else
12075 ri = ri->next;
12076 }
12077 }
12078
12079 bgp_unlock_node (rm);
12080 }
paul718e3742002-12-13 20:15:29 +000012081 }
12082 }
12083 else
12084 {
12085 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012086 {
12087 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12088 {
12089 ri = rn->info;
12090 while (ri)
12091 {
12092 if (ri->extra && ri->extra->damp_info)
12093 {
12094 ri_temp = ri->next;
12095 bgp_damp_info_free (ri->extra->damp_info, 1);
12096 ri = ri_temp;
12097 }
12098 else
12099 ri = ri->next;
12100 }
12101 }
12102
12103 bgp_unlock_node (rn);
12104 }
paul718e3742002-12-13 20:15:29 +000012105 }
12106
12107 return CMD_SUCCESS;
12108}
12109
12110DEFUN (clear_ip_bgp_dampening,
12111 clear_ip_bgp_dampening_cmd,
12112 "clear ip bgp dampening",
12113 CLEAR_STR
12114 IP_STR
12115 BGP_STR
12116 "Clear route flap dampening information\n")
12117{
12118 bgp_damp_info_clean ();
12119 return CMD_SUCCESS;
12120}
12121
12122DEFUN (clear_ip_bgp_dampening_prefix,
12123 clear_ip_bgp_dampening_prefix_cmd,
12124 "clear ip bgp dampening A.B.C.D/M",
12125 CLEAR_STR
12126 IP_STR
12127 BGP_STR
12128 "Clear route flap dampening information\n"
12129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12130{
12131 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12132 SAFI_UNICAST, NULL, 1);
12133}
12134
12135DEFUN (clear_ip_bgp_dampening_address,
12136 clear_ip_bgp_dampening_address_cmd,
12137 "clear ip bgp dampening A.B.C.D",
12138 CLEAR_STR
12139 IP_STR
12140 BGP_STR
12141 "Clear route flap dampening information\n"
12142 "Network to clear damping information\n")
12143{
12144 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12145 SAFI_UNICAST, NULL, 0);
12146}
12147
12148DEFUN (clear_ip_bgp_dampening_address_mask,
12149 clear_ip_bgp_dampening_address_mask_cmd,
12150 "clear ip bgp dampening A.B.C.D A.B.C.D",
12151 CLEAR_STR
12152 IP_STR
12153 BGP_STR
12154 "Clear route flap dampening information\n"
12155 "Network to clear damping information\n"
12156 "Network mask\n")
12157{
12158 int ret;
12159 char prefix_str[BUFSIZ];
12160
12161 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12162 if (! ret)
12163 {
12164 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12165 return CMD_WARNING;
12166 }
12167
12168 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12169 SAFI_UNICAST, NULL, 0);
12170}
12171
paul94f2b392005-06-28 12:44:16 +000012172static int
paul718e3742002-12-13 20:15:29 +000012173bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12174 afi_t afi, safi_t safi, int *write)
12175{
12176 struct bgp_node *prn;
12177 struct bgp_node *rn;
12178 struct bgp_table *table;
12179 struct prefix *p;
12180 struct prefix_rd *prd;
12181 struct bgp_static *bgp_static;
12182 u_int32_t label;
12183 char buf[SU_ADDRSTRLEN];
12184 char rdbuf[RD_ADDRSTRLEN];
12185
12186 /* Network configuration. */
12187 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12188 if ((table = prn->info) != NULL)
12189 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12190 if ((bgp_static = rn->info) != NULL)
12191 {
12192 p = &rn->p;
12193 prd = (struct prefix_rd *) &prn->p;
12194
12195 /* "address-family" display. */
12196 bgp_config_write_family_header (vty, afi, safi, write);
12197
12198 /* "network" configuration display. */
12199 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12200 label = decode_label (bgp_static->tag);
12201
12202 vty_out (vty, " network %s/%d rd %s tag %d",
12203 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12204 p->prefixlen,
12205 rdbuf, label);
12206 vty_out (vty, "%s", VTY_NEWLINE);
12207 }
12208 return 0;
12209}
12210
12211/* Configuration of static route announcement and aggregate
12212 information. */
12213int
12214bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12215 afi_t afi, safi_t safi, int *write)
12216{
12217 struct bgp_node *rn;
12218 struct prefix *p;
12219 struct bgp_static *bgp_static;
12220 struct bgp_aggregate *bgp_aggregate;
12221 char buf[SU_ADDRSTRLEN];
12222
12223 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12224 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12225
12226 /* Network configuration. */
12227 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12228 if ((bgp_static = rn->info) != NULL)
12229 {
12230 p = &rn->p;
12231
12232 /* "address-family" display. */
12233 bgp_config_write_family_header (vty, afi, safi, write);
12234
12235 /* "network" configuration display. */
12236 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12237 {
12238 u_int32_t destination;
12239 struct in_addr netmask;
12240
12241 destination = ntohl (p->u.prefix4.s_addr);
12242 masklen2ip (p->prefixlen, &netmask);
12243 vty_out (vty, " network %s",
12244 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12245
12246 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12247 || (IN_CLASSB (destination) && p->prefixlen == 16)
12248 || (IN_CLASSA (destination) && p->prefixlen == 8)
12249 || p->u.prefix4.s_addr == 0)
12250 {
12251 /* Natural mask is not display. */
12252 }
12253 else
12254 vty_out (vty, " mask %s", inet_ntoa (netmask));
12255 }
12256 else
12257 {
12258 vty_out (vty, " network %s/%d",
12259 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12260 p->prefixlen);
12261 }
12262
12263 if (bgp_static->rmap.name)
12264 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012265 else
12266 {
12267 if (bgp_static->backdoor)
12268 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012269 }
paul718e3742002-12-13 20:15:29 +000012270
12271 vty_out (vty, "%s", VTY_NEWLINE);
12272 }
12273
12274 /* Aggregate-address configuration. */
12275 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12276 if ((bgp_aggregate = rn->info) != NULL)
12277 {
12278 p = &rn->p;
12279
12280 /* "address-family" display. */
12281 bgp_config_write_family_header (vty, afi, safi, write);
12282
12283 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12284 {
12285 struct in_addr netmask;
12286
12287 masklen2ip (p->prefixlen, &netmask);
12288 vty_out (vty, " aggregate-address %s %s",
12289 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12290 inet_ntoa (netmask));
12291 }
12292 else
12293 {
12294 vty_out (vty, " aggregate-address %s/%d",
12295 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12296 p->prefixlen);
12297 }
12298
12299 if (bgp_aggregate->as_set)
12300 vty_out (vty, " as-set");
12301
12302 if (bgp_aggregate->summary_only)
12303 vty_out (vty, " summary-only");
12304
12305 vty_out (vty, "%s", VTY_NEWLINE);
12306 }
12307
12308 return 0;
12309}
12310
12311int
12312bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12313{
12314 struct bgp_node *rn;
12315 struct bgp_distance *bdistance;
12316
12317 /* Distance configuration. */
12318 if (bgp->distance_ebgp
12319 && bgp->distance_ibgp
12320 && bgp->distance_local
12321 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12322 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12323 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12324 vty_out (vty, " distance bgp %d %d %d%s",
12325 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12326 VTY_NEWLINE);
12327
12328 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12329 if ((bdistance = rn->info) != NULL)
12330 {
12331 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12332 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12333 bdistance->access_list ? bdistance->access_list : "",
12334 VTY_NEWLINE);
12335 }
12336
12337 return 0;
12338}
12339
12340/* Allocate routing table structure and install commands. */
12341void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012342bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012343{
12344 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012345 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012346
12347 /* IPv4 BGP commands. */
12348 install_element (BGP_NODE, &bgp_network_cmd);
12349 install_element (BGP_NODE, &bgp_network_mask_cmd);
12350 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12351 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12352 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12353 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12354 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12355 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12356 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_cmd);
12358 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12359 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12360 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12361 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12362 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12363 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12364 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12365 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12366
12367 install_element (BGP_NODE, &aggregate_address_cmd);
12368 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12369 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12370 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12371 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12372 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12373 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12374 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12375 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12376 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12379 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12380 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12381 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12382 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12383 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12384 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12385 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12386 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12387
12388 /* IPv4 unicast configuration. */
12389 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12390 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12391 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12392 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12393 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12394 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012395 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012396 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12397 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12398 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12399 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12400 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012401
paul718e3742002-12-13 20:15:29 +000012402 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12404 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12405 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12406 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12407 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12408 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12409 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12410 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12411 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12414 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12415 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12416 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12417 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12418 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12419 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12420 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12421 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12422
12423 /* IPv4 multicast configuration. */
12424 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12425 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12426 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12427 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12428 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12429 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12431 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12432 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12433 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12434 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12435 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12438 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12439 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12440 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12441 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12442 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12443 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12444 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12445 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12454 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12455 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12456
12457 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012459 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012460 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012462 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012463 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012467 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012468 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012493 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12494 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12495 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12496 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12497 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012498 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012517 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012533 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012535 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012537 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012539 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012541 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012543 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012544 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012545 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012546 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012547
12548 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12550 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012551 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012552 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012556 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12563 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12567 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012568 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12569 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12570 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12571 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12572 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012573 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12581 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012583 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012585 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012587 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012588 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012589
12590 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012592 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012593 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012595 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012596 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012601 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12627 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12628 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12629 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12630 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012631 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012649 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012650 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012666 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012667 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012668 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012670 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012671 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012672 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012674 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012676 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012677 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012678 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012679 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012680
12681 /* BGP dampening clear commands */
12682 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12683 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12684 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12685 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12686
Paul Jakmaff7924f2006-09-04 01:10:36 +000012687 /* prefix count */
12688 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012691#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012692 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12693
paul718e3742002-12-13 20:15:29 +000012694 /* New config IPv6 BGP commands. */
12695 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12696 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12697 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12698 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12699
12700 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12701 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12702 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12703 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12704
G.Balaji73bfe0b2011-09-23 22:36:20 +053012705 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12706 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12707
paul718e3742002-12-13 20:15:29 +000012708 /* Old config IPv6 BGP commands. */
12709 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12710 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12711
12712 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12713 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12714 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12715 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12716
12717 install_element (VIEW_NODE, &show_bgp_cmd);
12718 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012719 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012720 install_element (VIEW_NODE, &show_bgp_route_cmd);
12721 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012723 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12724 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012725 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012726 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12728 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12729 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12730 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12731 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12732 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12734 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12736 install_element (VIEW_NODE, &show_bgp_community_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12738 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12740 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12742 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12744 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12748 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12750 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12752 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12754 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12756 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12758 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12760 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12762 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12764 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012766 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12768 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012770 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012771 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012772 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012773 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012774 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012775 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012776 install_element (VIEW_NODE, &show_bgp_view_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12788 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12789 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12790 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12792 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12793 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012794 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012795 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012796 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012798 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012799 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012800
12801 /* Restricted:
12802 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12803 */
12804 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012807 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012810 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012828 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012830 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012838 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012840
12841 install_element (ENABLE_NODE, &show_bgp_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012843 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012844 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012847 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012850 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012890 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012894 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012895 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012896 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012897 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012898 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012899 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012900 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012918 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012920 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012922 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012924
12925 /* Statistics */
12926 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12930
paul718e3742002-12-13 20:15:29 +000012931 /* old command */
12932 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012968
paul718e3742002-12-13 20:15:29 +000012969 /* old command */
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13006
13007 /* old command */
13008 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13009 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13010 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13011 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13012
13013 /* old command */
13014 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13015 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13016 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13017 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13018
13019 /* old command */
13020 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13021 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13022 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13023 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13024#endif /* HAVE_IPV6 */
13025
13026 install_element (BGP_NODE, &bgp_distance_cmd);
13027 install_element (BGP_NODE, &no_bgp_distance_cmd);
13028 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13029 install_element (BGP_NODE, &bgp_distance_source_cmd);
13030 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13031 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13032 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13033
13034 install_element (BGP_NODE, &bgp_damp_set_cmd);
13035 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13036 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13037 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13038 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13039 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13040 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13041 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13042 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13043 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013044
13045 /* Deprecated AS-Pathlimit commands */
13046 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13047 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13048 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13049 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13050 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13051 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13052
13053 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13054 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13055 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13056 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13057 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13058 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13059
13060 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13064 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13065 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13066
13067 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13068 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13069 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13070 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13071 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13072 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13073
13074 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13078 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13079 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13080
13081 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13082 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13083 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13084 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13085 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13086 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013087
13088#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013089 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13090 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013091#endif
paul718e3742002-12-13 20:15:29 +000013092}
Chris Caputo228da422009-07-18 05:44:03 +000013093
13094void
13095bgp_route_finish (void)
13096{
13097 bgp_table_unlock (bgp_distance_table);
13098 bgp_distance_table = NULL;
13099}