blob: ed8464d27f0c195467ae5bd5233f1acc70d2d87c [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[];
David Lamparter6b0655a2014-06-04 06:53:35 +020062
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}
David Lamparter6b0655a2014-06-04 06:53:35 +020092
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000141 bgp_attr_unintern (&binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 struct bgp_table *table;
244
245 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000246 assert (ri && ri->peer && ri->peer->bgp);
247
Avneesh Sachdev67174042012-08-17 08:19:49 -0700248 table = bgp_node_table (rn);
249
Paul Jakma1a392d42006-09-07 00:24:49 +0000250 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700251 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000252 || ri->peer == ri->peer->bgp->peer_self)
253 return;
254
255 if (BGP_INFO_HOLDDOWN (ri)
256 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
257 {
258
259 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
260
261 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700262 if (ri->peer->pcount[table->afi][table->safi])
263 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000264 else
265 {
266 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
267 __func__, ri->peer->host);
268 zlog_backtrace (LOG_WARNING);
269 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
270 }
271 }
272 else if (!BGP_INFO_HOLDDOWN (ri)
273 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
274 {
275 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700276 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000277 }
278}
279
280
281/* Set/unset bgp_info flags, adjusting any other state as needed.
282 * This is here primarily to keep prefix-count in check.
283 */
284void
285bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
286{
287 SET_FLAG (ri->flags, flag);
288
289 /* early bath if we know it's not a flag that changes useability state */
290 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
291 return;
292
293 bgp_pcount_adjust (rn, ri);
294}
295
296void
297bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
298{
299 UNSET_FLAG (ri->flags, flag);
300
301 /* early bath if we know it's not a flag that changes useability state */
302 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
303 return;
304
305 bgp_pcount_adjust (rn, ri);
306}
307
paul718e3742002-12-13 20:15:29 +0000308/* Get MED value. If MED value is missing and "bgp bestpath
309 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000310static u_int32_t
paul718e3742002-12-13 20:15:29 +0000311bgp_med_value (struct attr *attr, struct bgp *bgp)
312{
313 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
314 return attr->med;
315 else
316 {
317 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000318 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000319 else
320 return 0;
321 }
322}
323
324/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000325static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700326bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
327 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000328{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000329 struct attr *newattr, *existattr;
330 struct attr_extra *newattre, *existattre;
331 bgp_peer_sort_t new_sort;
332 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000333 u_int32_t new_pref;
334 u_int32_t exist_pref;
335 u_int32_t new_med;
336 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000337 u_int32_t new_weight;
338 u_int32_t exist_weight;
339 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000340 struct in_addr new_id;
341 struct in_addr exist_id;
342 int new_cluster;
343 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000344 int internal_as_route;
345 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000346 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700347
348 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000349
350 /* 0. Null check. */
351 if (new == NULL)
352 return 0;
353 if (exist == NULL)
354 return 1;
355
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000356 newattr = new->attr;
357 existattr = exist->attr;
358 newattre = newattr->extra;
359 existattre = existattr->extra;
360
paul718e3742002-12-13 20:15:29 +0000361 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000362 new_weight = exist_weight = 0;
363
364 if (newattre)
365 new_weight = newattre->weight;
366 if (existattre)
367 exist_weight = existattre->weight;
368
Paul Jakmafb982c22007-05-04 20:15:47 +0000369 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000370 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000372 return 0;
373
374 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000375 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000376
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000377 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
378 new_pref = newattr->local_pref;
379 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
380 exist_pref = existattr->local_pref;
381
paul718e3742002-12-13 20:15:29 +0000382 if (new_pref > exist_pref)
383 return 1;
384 if (new_pref < exist_pref)
385 return 0;
386
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000387 /* 3. Local route check. We prefer:
388 * - BGP_ROUTE_STATIC
389 * - BGP_ROUTE_AGGREGATE
390 * - BGP_ROUTE_REDISTRIBUTE
391 */
392 if (! (new->sub_type == BGP_ROUTE_NORMAL))
393 return 1;
394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
395 return 0;
paul718e3742002-12-13 20:15:29 +0000396
397 /* 4. AS path length check. */
398 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
399 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000400 int exist_hops = aspath_count_hops (existattr->aspath);
401 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000402
hasso68118452005-04-08 15:40:36 +0000403 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
404 {
paulfe69a502005-09-10 16:55:02 +0000405 int aspath_hops;
406
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000407 aspath_hops = aspath_count_hops (newattr->aspath);
408 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000409
410 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
415 else
416 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000417 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000418
419 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000420 return 1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000422 return 0;
423 }
paul718e3742002-12-13 20:15:29 +0000424 }
425
426 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000427 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000428 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000430 return 0;
431
432 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000433 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
435 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
436 && aspath_count_confeds (existattr->aspath) > 0
437 && aspath_count_hops (newattr->aspath) == 0
438 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000439
440 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
441 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
442 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000443 || aspath_cmp_left (newattr->aspath, existattr->aspath)
444 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000445 || internal_as_route)
446 {
447 new_med = bgp_med_value (new->attr, bgp);
448 exist_med = bgp_med_value (exist->attr, bgp);
449
450 if (new_med < exist_med)
451 return 1;
452 if (new_med > exist_med)
453 return 0;
454 }
455
456 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000457 new_sort = new->peer->sort;
458 exist_sort = exist->peer->sort;
459
460 if (new_sort == BGP_PEER_EBGP
461 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000462 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 if (exist_sort == BGP_PEER_EBGP
464 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000465 return 0;
466
467 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000468 newm = existm = 0;
469
470 if (new->extra)
471 newm = new->extra->igpmetric;
472 if (exist->extra)
473 existm = exist->extra->igpmetric;
474
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 if (newm < existm)
476 ret = 1;
477 if (newm > existm)
478 ret = 0;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700481 if (newm == existm)
482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
485
486 /*
487 * For the two paths, all comparison steps till IGP metric
488 * have succeeded - including AS_PATH hop count. Since 'bgp
489 * bestpath as-path multipath-relax' knob is on, we don't need
490 * an exact match of AS_PATH. Thus, mark the paths are equal.
491 * That will trigger both these paths to get into the multipath
492 * array.
493 */
494 *paths_eq = 1;
495 }
496 else if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 {
498 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
499 *paths_eq = 1;
500 }
501 else if (new->peer->as == exist->peer->as)
502 *paths_eq = 1;
503 }
504 else
505 {
506 /*
507 * TODO: If unequal cost ibgp multipath is enabled we can
508 * mark the paths as equal here instead of returning
509 */
510 return ret;
511 }
paul718e3742002-12-13 20:15:29 +0000512
513 /* 10. If both paths are external, prefer the path that was received
514 first (the oldest one). This step minimizes route-flap, since a
515 newer path won't displace an older one, even if it was the
516 preferred route based on the additional decision criteria below. */
517 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 && new_sort == BGP_PEER_EBGP
519 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000520 {
521 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
522 return 1;
523 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
524 return 0;
525 }
526
527 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
529 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000530 else
531 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000532 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
533 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000534 else
535 exist_id.s_addr = exist->peer->remote_id.s_addr;
536
537 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
538 return 1;
539 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
540 return 0;
541
542 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000543 new_cluster = exist_cluster = 0;
544
545 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
546 new_cluster = newattre->cluster->length;
547 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
548 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000549
550 if (new_cluster < exist_cluster)
551 return 1;
552 if (new_cluster > exist_cluster)
553 return 0;
554
555 /* 13. Neighbor address comparision. */
556 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
557
558 if (ret == 1)
559 return 0;
560 if (ret == -1)
561 return 1;
562
563 return 1;
564}
565
paul94f2b392005-06-28 12:44:16 +0000566static enum filter_type
paul718e3742002-12-13 20:15:29 +0000567bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
568 afi_t afi, safi_t safi)
569{
570 struct bgp_filter *filter;
571
572 filter = &peer->filter[afi][safi];
573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574#define FILTER_EXIST_WARN(F,f,filter) \
575 if (BGP_DEBUG (update, UPDATE_IN) \
576 && !(F ## _IN (filter))) \
577 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
578 peer->host, #f, F ## _IN_NAME(filter));
579
580 if (DISTRIBUTE_IN_NAME (filter)) {
581 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
582
paul718e3742002-12-13 20:15:29 +0000583 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
584 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 }
paul718e3742002-12-13 20:15:29 +0000586
Paul Jakma650f76c2009-06-25 18:06:31 +0100587 if (PREFIX_LIST_IN_NAME (filter)) {
588 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
589
paul718e3742002-12-13 20:15:29 +0000590 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
591 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 }
paul718e3742002-12-13 20:15:29 +0000593
Paul Jakma650f76c2009-06-25 18:06:31 +0100594 if (FILTER_LIST_IN_NAME (filter)) {
595 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
596
paul718e3742002-12-13 20:15:29 +0000597 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
598 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 }
600
paul718e3742002-12-13 20:15:29 +0000601 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000603}
604
paul94f2b392005-06-28 12:44:16 +0000605static enum filter_type
paul718e3742002-12-13 20:15:29 +0000606bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
607 afi_t afi, safi_t safi)
608{
609 struct bgp_filter *filter;
610
611 filter = &peer->filter[afi][safi];
612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613#define FILTER_EXIST_WARN(F,f,filter) \
614 if (BGP_DEBUG (update, UPDATE_OUT) \
615 && !(F ## _OUT (filter))) \
616 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
617 peer->host, #f, F ## _OUT_NAME(filter));
618
619 if (DISTRIBUTE_OUT_NAME (filter)) {
620 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
621
paul718e3742002-12-13 20:15:29 +0000622 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
623 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624 }
paul718e3742002-12-13 20:15:29 +0000625
Paul Jakma650f76c2009-06-25 18:06:31 +0100626 if (PREFIX_LIST_OUT_NAME (filter)) {
627 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
628
paul718e3742002-12-13 20:15:29 +0000629 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
630 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100631 }
paul718e3742002-12-13 20:15:29 +0000632
Paul Jakma650f76c2009-06-25 18:06:31 +0100633 if (FILTER_LIST_OUT_NAME (filter)) {
634 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
635
paul718e3742002-12-13 20:15:29 +0000636 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
637 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 }
paul718e3742002-12-13 20:15:29 +0000639
640 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000642}
643
644/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000645static int
paul718e3742002-12-13 20:15:29 +0000646bgp_community_filter (struct peer *peer, struct attr *attr)
647{
648 if (attr->community)
649 {
650 /* NO_ADVERTISE check. */
651 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
652 return 1;
653
654 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000655 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000656 community_include (attr->community, COMMUNITY_NO_EXPORT))
657 return 1;
658
659 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000660 if (peer->sort == BGP_PEER_EBGP
661 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000662 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
663 return 1;
664 }
665 return 0;
666}
667
668/* Route reflection loop check. */
669static int
670bgp_cluster_filter (struct peer *peer, struct attr *attr)
671{
672 struct in_addr cluster_id;
673
Paul Jakmafb982c22007-05-04 20:15:47 +0000674 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000675 {
676 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
677 cluster_id = peer->bgp->cluster_id;
678 else
679 cluster_id = peer->bgp->router_id;
680
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000682 return 1;
683 }
684 return 0;
685}
David Lamparter6b0655a2014-06-04 06:53:35 +0200686
paul94f2b392005-06-28 12:44:16 +0000687static int
paul718e3742002-12-13 20:15:29 +0000688bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
689 afi_t afi, safi_t safi)
690{
691 struct bgp_filter *filter;
692 struct bgp_info info;
693 route_map_result_t ret;
694
695 filter = &peer->filter[afi][safi];
696
697 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000698 if (peer->weight)
699 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000700
701 /* Route map apply. */
702 if (ROUTE_MAP_IN_NAME (filter))
703 {
704 /* Duplicate current value to new strucutre for modification. */
705 info.peer = peer;
706 info.attr = attr;
707
paulac41b2a2003-08-12 05:32:27 +0000708 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
709
paul718e3742002-12-13 20:15:29 +0000710 /* Apply BGP route map to the attribute. */
711 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000712
713 peer->rmap_type = 0;
714
paul718e3742002-12-13 20:15:29 +0000715 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200716 /* caller has multiple error paths with bgp_attr_flush() */
717 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000718 }
719 return RMAP_PERMIT;
720}
David Lamparter6b0655a2014-06-04 06:53:35 +0200721
paul94f2b392005-06-28 12:44:16 +0000722static int
paulfee0f4c2004-09-13 05:12:46 +0000723bgp_export_modifier (struct peer *rsclient, struct peer *peer,
724 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
725{
726 struct bgp_filter *filter;
727 struct bgp_info info;
728 route_map_result_t ret;
729
730 filter = &peer->filter[afi][safi];
731
732 /* Route map apply. */
733 if (ROUTE_MAP_EXPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = rsclient;
737 info.attr = attr;
738
739 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
743
744 rsclient->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paulfee0f4c2004-09-13 05:12:46 +0000757bgp_import_modifier (struct peer *rsclient, struct peer *peer,
758 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
759{
760 struct bgp_filter *filter;
761 struct bgp_info info;
762 route_map_result_t ret;
763
764 filter = &rsclient->filter[afi][safi];
765
766 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000767 if (peer->weight)
768 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000769
770 /* Route map apply. */
771 if (ROUTE_MAP_IMPORT_NAME (filter))
772 {
773 /* Duplicate current value to new strucutre for modification. */
774 info.peer = peer;
775 info.attr = attr;
776
777 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
778
779 /* Apply BGP route map to the attribute. */
780 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
781
782 peer->rmap_type = 0;
783
784 if (ret == RMAP_DENYMATCH)
785 {
786 /* Free newly generated AS path and community by route-map. */
787 bgp_attr_flush (attr);
788 return RMAP_DENY;
789 }
790 }
791 return RMAP_PERMIT;
792}
David Lamparter6b0655a2014-06-04 06:53:35 +0200793
paul94f2b392005-06-28 12:44:16 +0000794static int
paul718e3742002-12-13 20:15:29 +0000795bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
796 struct attr *attr, afi_t afi, safi_t safi)
797{
798 int ret;
799 char buf[SU_ADDRSTRLEN];
800 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000801 struct peer *from;
802 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000803 int transparent;
804 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700805 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000806
807 from = ri->peer;
808 filter = &peer->filter[afi][safi];
809 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700810 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000811
Paul Jakma750e8142008-07-22 21:11:48 +0000812 if (DISABLE_BGP_ANNOUNCE)
813 return 0;
paul718e3742002-12-13 20:15:29 +0000814
paulfee0f4c2004-09-13 05:12:46 +0000815 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
816 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
817 return 0;
818
paul718e3742002-12-13 20:15:29 +0000819 /* Do not send back route to sender. */
820 if (from == peer)
821 return 0;
822
823 /* 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
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000955 /* If originator-id is not set and the route is to be reflected,
956 set the originator id */
957 if (peer && from && peer->sort == BGP_PEER_IBGP &&
958 from->sort == BGP_PEER_IBGP &&
959 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
960 {
961 attr->extra = bgp_attr_extra_get(attr);
962 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
963 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
964 }
965
paul718e3742002-12-13 20:15:29 +0000966 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000967 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000968 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
969 {
970 if (ri->peer != bgp->peer_self && ! transparent
971 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
972 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
973 }
974
975 /* next-hop-set */
976 if (transparent || reflect
977 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
978 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000979#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000980 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000981 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000982#endif /* HAVE_IPV6 */
983 )))
paul718e3742002-12-13 20:15:29 +0000984 {
985 /* NEXT-HOP Unchanged. */
986 }
987 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
988 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
989#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000990 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000992#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000993 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000994 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
995 {
996 /* Set IPv4 nexthop. */
997 if (p->family == AF_INET)
998 {
999 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001000 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1001 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001002 else
1003 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1004 }
1005#ifdef HAVE_IPV6
1006 /* Set IPv6 nexthop. */
1007 if (p->family == AF_INET6)
1008 {
1009 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001010 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001011 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001013 }
1014#endif /* HAVE_IPV6 */
1015 }
1016
1017#ifdef HAVE_IPV6
1018 if (p->family == AF_INET6)
1019 {
paulfee0f4c2004-09-13 05:12:46 +00001020 /* Left nexthop_local unchanged if so configured. */
1021 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1022 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1023 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001024 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1025 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001026 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001027 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001028 }
1029
1030 /* Default nexthop_local treatment for non-RS-Clients */
1031 else
1032 {
paul718e3742002-12-13 20:15:29 +00001033 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001034 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001035
1036 /* Set link-local address for shared network peer. */
1037 if (peer->shared_network
1038 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1039 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001040 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001041 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001042 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001043 }
1044
1045 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1046 address.*/
1047 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001048 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001049
1050 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1051 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053 }
paulfee0f4c2004-09-13 05:12:46 +00001054
1055 }
paul718e3742002-12-13 20:15:29 +00001056#endif /* HAVE_IPV6 */
1057
1058 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001059 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001060 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1061 && aspath_private_as_check (attr->aspath))
1062 attr->aspath = aspath_empty_get ();
1063
1064 /* Route map & unsuppress-map apply. */
1065 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001066 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001067 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001068 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001069 struct attr dummy_attr;
1070 struct attr_extra dummy_extra;
1071
1072 dummy_attr.extra = &dummy_extra;
1073
paul718e3742002-12-13 20:15:29 +00001074 info.peer = peer;
1075 info.attr = attr;
1076
1077 /* The route reflector is not allowed to modify the attributes
1078 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001079 if (from->sort == BGP_PEER_IBGP
1080 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001081 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001082 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001083 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001084 }
paulac41b2a2003-08-12 05:32:27 +00001085
1086 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1087
Paul Jakmafb982c22007-05-04 20:15:47 +00001088 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001089 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1090 else
1091 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1092
paulac41b2a2003-08-12 05:32:27 +00001093 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001094
paul718e3742002-12-13 20:15:29 +00001095 if (ret == RMAP_DENYMATCH)
1096 {
1097 bgp_attr_flush (attr);
1098 return 0;
1099 }
1100 }
1101 return 1;
1102}
1103
paul94f2b392005-06-28 12:44:16 +00001104static int
paulfee0f4c2004-09-13 05:12:46 +00001105bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1106 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001107{
paulfee0f4c2004-09-13 05:12:46 +00001108 int ret;
1109 char buf[SU_ADDRSTRLEN];
1110 struct bgp_filter *filter;
1111 struct bgp_info info;
1112 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001113 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001114
1115 from = ri->peer;
1116 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001117 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001118
Paul Jakma750e8142008-07-22 21:11:48 +00001119 if (DISABLE_BGP_ANNOUNCE)
1120 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001121
1122 /* Do not send back route to sender. */
1123 if (from == rsclient)
1124 return 0;
1125
1126 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001127 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001128 if (! UNSUPPRESS_MAP_NAME (filter))
1129 return 0;
1130
1131 /* Default route check. */
1132 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1133 PEER_STATUS_DEFAULT_ORIGINATE))
1134 {
1135 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1136 return 0;
1137#ifdef HAVE_IPV6
1138 else if (p->family == AF_INET6 && p->prefixlen == 0)
1139 return 0;
1140#endif /* HAVE_IPV6 */
1141 }
1142
1143 /* If the attribute has originator-id and it is same as remote
1144 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001145 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001146 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001147 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001148 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001149 {
1150 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001151 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001152 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1153 rsclient->host,
1154 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1155 p->prefixlen);
1156 return 0;
1157 }
1158 }
1159
1160 /* ORF prefix-list filter check */
1161 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1162 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1163 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1164 if (rsclient->orf_plist[afi][safi])
1165 {
1166 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1167 return 0;
1168 }
1169
1170 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001171 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001172 {
1173 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001174 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001175 "%s [Update:SEND] %s/%d is filtered",
1176 rsclient->host,
1177 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1178 p->prefixlen);
1179 return 0;
1180 }
1181
1182#ifdef BGP_SEND_ASPATH_CHECK
1183 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001185 {
1186 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001187 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001188 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001189 rsclient->host, rsclient->as);
1190 return 0;
1191 }
1192#endif /* BGP_SEND_ASPATH_CHECK */
1193
1194 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001195 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001196
1197 /* next-hop-set */
1198 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1199#ifdef HAVE_IPV6
1200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202#endif /* HAVE_IPV6 */
1203 )
1204 {
1205 /* Set IPv4 nexthop. */
1206 if (p->family == AF_INET)
1207 {
1208 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001209 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001210 IPV4_MAX_BYTELEN);
1211 else
1212 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1213 }
1214#ifdef HAVE_IPV6
1215 /* Set IPv6 nexthop. */
1216 if (p->family == AF_INET6)
1217 {
1218 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001220 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001222 }
1223#endif /* HAVE_IPV6 */
1224 }
1225
1226#ifdef HAVE_IPV6
1227 if (p->family == AF_INET6)
1228 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001229 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001230
paulfee0f4c2004-09-13 05:12:46 +00001231 /* Left nexthop_local unchanged if so configured. */
1232 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1233 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1234 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001235 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1236 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001237 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001239 }
1240
1241 /* Default nexthop_local treatment for RS-Clients */
1242 else
1243 {
1244 /* Announcer and RS-Client are both in the same network */
1245 if (rsclient->shared_network && from->shared_network &&
1246 (rsclient->ifindex == from->ifindex))
1247 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001248 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1249 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001250 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001252 }
1253
1254 /* Set link-local address for shared network peer. */
1255 else if (rsclient->shared_network
1256 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1257 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001259 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001265 }
1266
1267 }
1268#endif /* HAVE_IPV6 */
1269
1270
1271 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001272 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001273 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1274 && aspath_private_as_check (attr->aspath))
1275 attr->aspath = aspath_empty_get ();
1276
1277 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001279 {
1280 info.peer = rsclient;
1281 info.attr = attr;
1282
1283 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1284
Paul Jakmafb982c22007-05-04 20:15:47 +00001285 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001286 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1287 else
1288 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1289
1290 rsclient->rmap_type = 0;
1291
1292 if (ret == RMAP_DENYMATCH)
1293 {
1294 bgp_attr_flush (attr);
1295 return 0;
1296 }
1297 }
1298
1299 return 1;
1300}
1301
1302struct bgp_info_pair
1303{
1304 struct bgp_info *old;
1305 struct bgp_info *new;
1306};
1307
paul94f2b392005-06-28 12:44:16 +00001308static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001309bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1310 struct bgp_maxpaths_cfg *mpath_cfg,
1311 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001312{
paul718e3742002-12-13 20:15:29 +00001313 struct bgp_info *new_select;
1314 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001315 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001316 struct bgp_info *ri1;
1317 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001318 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001319 int paths_eq, do_mpath;
1320 struct list mp_list;
1321
1322 bgp_mp_list_init (&mp_list);
1323 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1324 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1325
paul718e3742002-12-13 20:15:29 +00001326 /* bgp deterministic-med */
1327 new_select = NULL;
1328 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1329 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1330 {
1331 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1332 continue;
1333 if (BGP_INFO_HOLDDOWN (ri1))
1334 continue;
1335
1336 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001337 if (do_mpath)
1338 bgp_mp_list_add (&mp_list, ri1);
1339 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001340 if (ri1->next)
1341 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1342 {
1343 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1344 continue;
1345 if (BGP_INFO_HOLDDOWN (ri2))
1346 continue;
1347
1348 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1349 || aspath_cmp_left_confed (ri1->attr->aspath,
1350 ri2->attr->aspath))
1351 {
Josh Bailey6918e742011-07-20 20:48:20 -07001352 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1353 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001354 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001355 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001356 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001357 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001358 if (do_mpath && !paths_eq)
1359 {
1360 bgp_mp_list_clear (&mp_list);
1361 bgp_mp_list_add (&mp_list, ri2);
1362 }
paul718e3742002-12-13 20:15:29 +00001363 }
1364
Josh Bailey6918e742011-07-20 20:48:20 -07001365 if (do_mpath && paths_eq)
1366 bgp_mp_list_add (&mp_list, ri2);
1367
Paul Jakma1a392d42006-09-07 00:24:49 +00001368 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001369 }
1370 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001371 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1372 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001373
1374 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1375 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001376 }
1377
1378 /* Check old selected route and new selected route. */
1379 old_select = NULL;
1380 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001381 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001382 {
1383 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1384 old_select = ri;
1385
1386 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001387 {
1388 /* reap REMOVED routes, if needs be
1389 * selected route must stay for a while longer though
1390 */
1391 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1392 && (ri != old_select))
1393 bgp_info_reap (rn, ri);
1394
1395 continue;
1396 }
paul718e3742002-12-13 20:15:29 +00001397
1398 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1399 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1400 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001401 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001402 continue;
1403 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001404 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1405 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001406
Josh Bailey96450fa2011-07-20 20:45:12 -07001407 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1408 {
Josh Bailey6918e742011-07-20 20:48:20 -07001409 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1410 bgp_mp_dmed_deselect (new_select);
1411
Josh Bailey96450fa2011-07-20 20:45:12 -07001412 new_select = ri;
1413
1414 if (do_mpath && !paths_eq)
1415 {
1416 bgp_mp_list_clear (&mp_list);
1417 bgp_mp_list_add (&mp_list, ri);
1418 }
1419 }
Josh Bailey6918e742011-07-20 20:48:20 -07001420 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1421 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001422
1423 if (do_mpath && paths_eq)
1424 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001425 }
paulb40d9392005-08-22 22:34:41 +00001426
paulfee0f4c2004-09-13 05:12:46 +00001427
Josh Bailey6918e742011-07-20 20:48:20 -07001428 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1429 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001430
Josh Bailey0b597ef2011-07-20 20:49:11 -07001431 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 bgp_mp_list_clear (&mp_list);
1433
1434 result->old = old_select;
1435 result->new = new_select;
1436
1437 return;
paulfee0f4c2004-09-13 05:12:46 +00001438}
1439
paul94f2b392005-06-28 12:44:16 +00001440static int
paulfee0f4c2004-09-13 05:12:46 +00001441bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001442 struct bgp_node *rn, afi_t afi, safi_t safi)
1443{
paulfee0f4c2004-09-13 05:12:46 +00001444 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001445 struct attr attr;
1446 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001447
1448 p = &rn->p;
1449
Paul Jakma9eda90c2007-08-30 13:36:17 +00001450 /* Announce route to Established peer. */
1451 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001452 return 0;
1453
Paul Jakma9eda90c2007-08-30 13:36:17 +00001454 /* Address family configuration check. */
1455 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001456 return 0;
1457
Paul Jakma9eda90c2007-08-30 13:36:17 +00001458 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001459 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1460 PEER_STATUS_ORF_WAIT_REFRESH))
1461 return 0;
1462
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001463 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1464 attr.extra = &extra;
1465
Avneesh Sachdev67174042012-08-17 08:19:49 -07001466 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001467 {
1468 case BGP_TABLE_MAIN:
1469 /* Announcement to peer->conf. If the route is filtered,
1470 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001471 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1472 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001473 else
1474 bgp_adj_out_unset (rn, peer, p, afi, safi);
1475 break;
1476 case BGP_TABLE_RSCLIENT:
1477 /* Announcement to peer->conf. If the route is filtered,
1478 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001479 if (selected &&
1480 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1481 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1482 else
1483 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001484 break;
1485 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486
paulfee0f4c2004-09-13 05:12:46 +00001487 return 0;
paul200df112005-06-01 11:17:05 +00001488}
paulfee0f4c2004-09-13 05:12:46 +00001489
paul200df112005-06-01 11:17:05 +00001490struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001491{
paul200df112005-06-01 11:17:05 +00001492 struct bgp *bgp;
1493 struct bgp_node *rn;
1494 afi_t afi;
1495 safi_t safi;
1496};
1497
1498static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001499bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001500{
paul0fb58d52005-11-14 14:31:49 +00001501 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001502 struct bgp *bgp = pq->bgp;
1503 struct bgp_node *rn = pq->rn;
1504 afi_t afi = pq->afi;
1505 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001506 struct bgp_info *new_select;
1507 struct bgp_info *old_select;
1508 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001509 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001510 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001511
paulfee0f4c2004-09-13 05:12:46 +00001512 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001513 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001514 new_select = old_and_new.new;
1515 old_select = old_and_new.old;
1516
paul200df112005-06-01 11:17:05 +00001517 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1518 {
Chris Caputo228da422009-07-18 05:44:03 +00001519 if (rsclient->group)
1520 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1521 {
1522 /* Nothing to do. */
1523 if (old_select && old_select == new_select)
1524 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1525 continue;
paulfee0f4c2004-09-13 05:12:46 +00001526
Chris Caputo228da422009-07-18 05:44:03 +00001527 if (old_select)
1528 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1529 if (new_select)
1530 {
1531 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1532 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001533 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1534 }
paulfee0f4c2004-09-13 05:12:46 +00001535
Chris Caputo228da422009-07-18 05:44:03 +00001536 bgp_process_announce_selected (rsclient, new_select, rn,
1537 afi, safi);
1538 }
paul200df112005-06-01 11:17:05 +00001539 }
1540 else
1541 {
hassob7395792005-08-26 12:58:38 +00001542 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001543 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001544 if (new_select)
1545 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001546 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1547 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001548 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001549 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001550 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001551 }
paulfee0f4c2004-09-13 05:12:46 +00001552
paulb40d9392005-08-22 22:34:41 +00001553 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1554 bgp_info_reap (rn, old_select);
1555
paul200df112005-06-01 11:17:05 +00001556 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1557 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001558}
1559
paul200df112005-06-01 11:17:05 +00001560static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001561bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001562{
paul0fb58d52005-11-14 14:31:49 +00001563 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001564 struct bgp *bgp = pq->bgp;
1565 struct bgp_node *rn = pq->rn;
1566 afi_t afi = pq->afi;
1567 safi_t safi = pq->safi;
1568 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001569 struct bgp_info *new_select;
1570 struct bgp_info *old_select;
1571 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001572 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001573 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001574
paulfee0f4c2004-09-13 05:12:46 +00001575 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001576 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001577 old_select = old_and_new.old;
1578 new_select = old_and_new.new;
1579
1580 /* Nothing to do. */
1581 if (old_select && old_select == new_select)
1582 {
1583 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001584 {
Josh Bailey8196f132011-07-20 20:47:07 -07001585 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1586 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001587 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001588
Josh Bailey8196f132011-07-20 20:47:07 -07001589 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001590 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1591 return WQ_SUCCESS;
1592 }
paulfee0f4c2004-09-13 05:12:46 +00001593 }
paul718e3742002-12-13 20:15:29 +00001594
hasso338b3422005-02-23 14:27:24 +00001595 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001596 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001597 if (new_select)
1598 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001599 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1600 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001601 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001602 }
1603
1604
paul718e3742002-12-13 20:15:29 +00001605 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001606 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001607 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001608 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001609 }
1610
1611 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001612 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1613 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001614 {
1615 if (new_select
1616 && new_select->type == ZEBRA_ROUTE_BGP
1617 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001618 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001619 else
1620 {
1621 /* Withdraw the route from the kernel. */
1622 if (old_select
1623 && old_select->type == ZEBRA_ROUTE_BGP
1624 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001625 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001626 }
1627 }
paulb40d9392005-08-22 22:34:41 +00001628
1629 /* Reap old select bgp_info, it it has been removed */
1630 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1631 bgp_info_reap (rn, old_select);
1632
paul200df112005-06-01 11:17:05 +00001633 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1634 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001635}
1636
paul200df112005-06-01 11:17:05 +00001637static void
paul0fb58d52005-11-14 14:31:49 +00001638bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001639{
paul0fb58d52005-11-14 14:31:49 +00001640 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001641 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001642
Chris Caputo228da422009-07-18 05:44:03 +00001643 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001644 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001645 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001646 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1647}
1648
1649static void
1650bgp_process_queue_init (void)
1651{
1652 bm->process_main_queue
1653 = work_queue_new (bm->master, "process_main_queue");
1654 bm->process_rsclient_queue
1655 = work_queue_new (bm->master, "process_rsclient_queue");
1656
1657 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1658 {
1659 zlog_err ("%s: Failed to allocate work queue", __func__);
1660 exit (1);
1661 }
1662
1663 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001664 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001665 bm->process_main_queue->spec.max_retries = 0;
1666 bm->process_main_queue->spec.hold = 50;
1667
1668 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1669 sizeof (struct work_queue *));
1670 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001671}
1672
1673void
paulfee0f4c2004-09-13 05:12:46 +00001674bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1675{
paul200df112005-06-01 11:17:05 +00001676 struct bgp_process_queue *pqnode;
1677
1678 /* already scheduled for processing? */
1679 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1680 return;
1681
1682 if ( (bm->process_main_queue == NULL) ||
1683 (bm->process_rsclient_queue == NULL) )
1684 bgp_process_queue_init ();
1685
1686 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1687 sizeof (struct bgp_process_queue));
1688 if (!pqnode)
1689 return;
Chris Caputo228da422009-07-18 05:44:03 +00001690
1691 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001692 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001693 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001694 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001695 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001696 pqnode->afi = afi;
1697 pqnode->safi = safi;
1698
Avneesh Sachdev67174042012-08-17 08:19:49 -07001699 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001700 {
paul200df112005-06-01 11:17:05 +00001701 case BGP_TABLE_MAIN:
1702 work_queue_add (bm->process_main_queue, pqnode);
1703 break;
1704 case BGP_TABLE_RSCLIENT:
1705 work_queue_add (bm->process_rsclient_queue, pqnode);
1706 break;
paulfee0f4c2004-09-13 05:12:46 +00001707 }
paul200df112005-06-01 11:17:05 +00001708
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001709 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001710 return;
paulfee0f4c2004-09-13 05:12:46 +00001711}
hasso0a486e52005-02-01 20:57:17 +00001712
paul94f2b392005-06-28 12:44:16 +00001713static int
hasso0a486e52005-02-01 20:57:17 +00001714bgp_maximum_prefix_restart_timer (struct thread *thread)
1715{
1716 struct peer *peer;
1717
1718 peer = THREAD_ARG (thread);
1719 peer->t_pmax_restart = NULL;
1720
1721 if (BGP_DEBUG (events, EVENTS))
1722 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1723 peer->host);
1724
1725 peer_clear (peer);
1726
1727 return 0;
1728}
1729
paulfee0f4c2004-09-13 05:12:46 +00001730int
paul5228ad22004-06-04 17:58:18 +00001731bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1732 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001733{
hassoe0701b72004-05-20 09:19:34 +00001734 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1735 return 0;
1736
1737 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001738 {
hassoe0701b72004-05-20 09:19:34 +00001739 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1740 && ! always)
1741 return 0;
paul718e3742002-12-13 20:15:29 +00001742
hassoe0701b72004-05-20 09:19:34 +00001743 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001744 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1745 "limit %ld", afi_safi_print (afi, safi), peer->host,
1746 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001747 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001748
hassoe0701b72004-05-20 09:19:34 +00001749 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1750 return 0;
paul718e3742002-12-13 20:15:29 +00001751
hassoe0701b72004-05-20 09:19:34 +00001752 {
paul5228ad22004-06-04 17:58:18 +00001753 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001754
1755 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001756 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001757
1758 ndata[0] = (afi >> 8);
1759 ndata[1] = afi;
1760 ndata[2] = safi;
1761 ndata[3] = (peer->pmax[afi][safi] >> 24);
1762 ndata[4] = (peer->pmax[afi][safi] >> 16);
1763 ndata[5] = (peer->pmax[afi][safi] >> 8);
1764 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001765
1766 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1767 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1768 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1769 }
hasso0a486e52005-02-01 20:57:17 +00001770
1771 /* restart timer start */
1772 if (peer->pmax_restart[afi][safi])
1773 {
1774 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1775
1776 if (BGP_DEBUG (events, EVENTS))
1777 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1778 peer->host, peer->v_pmax_restart);
1779
1780 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1781 peer->v_pmax_restart);
1782 }
1783
hassoe0701b72004-05-20 09:19:34 +00001784 return 1;
paul718e3742002-12-13 20:15:29 +00001785 }
hassoe0701b72004-05-20 09:19:34 +00001786 else
1787 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1788
1789 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1790 {
1791 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1792 && ! always)
1793 return 0;
1794
1795 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001796 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1797 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1798 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001799 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1800 }
1801 else
1802 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001803 return 0;
1804}
1805
paulb40d9392005-08-22 22:34:41 +00001806/* Unconditionally remove the route from the RIB, without taking
1807 * damping into consideration (eg, because the session went down)
1808 */
paul94f2b392005-06-28 12:44:16 +00001809static void
paul718e3742002-12-13 20:15:29 +00001810bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1811 afi_t afi, safi_t safi)
1812{
paul902212c2006-02-05 17:51:19 +00001813 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1814
1815 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1816 bgp_info_delete (rn, ri); /* keep historical info */
1817
paulb40d9392005-08-22 22:34:41 +00001818 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001819}
1820
paul94f2b392005-06-28 12:44:16 +00001821static void
paul718e3742002-12-13 20:15:29 +00001822bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001823 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001824{
paul718e3742002-12-13 20:15:29 +00001825 int status = BGP_DAMP_NONE;
1826
paulb40d9392005-08-22 22:34:41 +00001827 /* apply dampening, if result is suppressed, we'll be retaining
1828 * the bgp_info in the RIB for historical reference.
1829 */
1830 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001831 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001832 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1833 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001834 {
paul902212c2006-02-05 17:51:19 +00001835 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1836 return;
1837 }
1838
1839 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001840}
1841
paul94f2b392005-06-28 12:44:16 +00001842static void
paulfee0f4c2004-09-13 05:12:46 +00001843bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1844 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1845 int sub_type, struct prefix_rd *prd, u_char *tag)
1846{
1847 struct bgp_node *rn;
1848 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001849 struct attr new_attr;
1850 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001851 struct attr *attr_new;
1852 struct attr *attr_new2;
1853 struct bgp_info *ri;
1854 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001855 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001856 char buf[SU_ADDRSTRLEN];
1857
1858 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1859 if (peer == rsclient)
1860 return;
1861
1862 bgp = peer->bgp;
1863 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1864
1865 /* Check previously received route. */
1866 for (ri = rn->info; ri; ri = ri->next)
1867 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1868 break;
1869
1870 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001871 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001872 {
1873 reason = "as-path contains our own AS;";
1874 goto filtered;
1875 }
1876
1877 /* Route reflector originator ID check. */
1878 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001879 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001880 {
1881 reason = "originator is us;";
1882 goto filtered;
1883 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001884
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001885 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001886 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001887
1888 /* Apply export policy. */
1889 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1890 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1891 {
1892 reason = "export-policy;";
1893 goto filtered;
1894 }
1895
1896 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001897
paulfee0f4c2004-09-13 05:12:46 +00001898 /* Apply import policy. */
1899 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1900 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001901 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001902
1903 reason = "import-policy;";
1904 goto filtered;
1905 }
1906
1907 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001908 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001909
1910 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001911 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001912 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001913 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001914 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001915 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001916 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001917 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001918
1919 reason = "martian next-hop;";
1920 goto filtered;
1921 }
1922 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001923
paulfee0f4c2004-09-13 05:12:46 +00001924 /* If the update is implicit withdraw. */
1925 if (ri)
1926 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001927 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001928
1929 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001930 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1931 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001932 {
1933
Paul Jakma1a392d42006-09-07 00:24:49 +00001934 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001937 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001938 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1939 peer->host,
1940 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1941 p->prefixlen, rsclient->host);
1942
Chris Caputo228da422009-07-18 05:44:03 +00001943 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001944 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001945
Chris Caputo228da422009-07-18 05:44:03 +00001946 return;
paulfee0f4c2004-09-13 05:12:46 +00001947 }
1948
Paul Jakma16d2e242007-04-10 19:32:10 +00001949 /* Withdraw/Announce before we fully processed the withdraw */
1950 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1951 bgp_info_restore (rn, ri);
1952
paulfee0f4c2004-09-13 05:12:46 +00001953 /* Received Logging. */
1954 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001955 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001956 peer->host,
1957 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1958 p->prefixlen, rsclient->host);
1959
1960 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001961 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001962
1963 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001964 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001965 ri->attr = attr_new;
1966
1967 /* Update MPLS tag. */
1968 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001969 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001970
Paul Jakma1a392d42006-09-07 00:24:49 +00001971 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001972
1973 /* Process change. */
1974 bgp_process (bgp, rn, afi, safi);
1975 bgp_unlock_node (rn);
1976
1977 return;
1978 }
1979
1980 /* Received Logging. */
1981 if (BGP_DEBUG (update, UPDATE_IN))
1982 {
ajsd2c1f162004-12-08 21:10:20 +00001983 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001984 peer->host,
1985 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1986 p->prefixlen, rsclient->host);
1987 }
1988
1989 /* Make new BGP info. */
1990 new = bgp_info_new ();
1991 new->type = type;
1992 new->sub_type = sub_type;
1993 new->peer = peer;
1994 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001995 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001996
1997 /* Update MPLS tag. */
1998 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001999 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002000
Paul Jakma1a392d42006-09-07 00:24:49 +00002001 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002002
2003 /* Register new BGP information. */
2004 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002005
2006 /* route_node_get lock */
2007 bgp_unlock_node (rn);
2008
paulfee0f4c2004-09-13 05:12:46 +00002009 /* Process change. */
2010 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002011
paulfee0f4c2004-09-13 05:12:46 +00002012 return;
2013
2014 filtered:
2015
2016 /* This BGP update is filtered. Log the reason then update BGP entry. */
2017 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002018 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002019 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2020 peer->host,
2021 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2022 p->prefixlen, rsclient->host, reason);
2023
2024 if (ri)
paulb40d9392005-08-22 22:34:41 +00002025 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002026
2027 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002028
paulfee0f4c2004-09-13 05:12:46 +00002029 return;
2030}
2031
paul94f2b392005-06-28 12:44:16 +00002032static void
paulfee0f4c2004-09-13 05:12:46 +00002033bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2034 struct peer *peer, struct prefix *p, int type, int sub_type,
2035 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002036{
paulfee0f4c2004-09-13 05:12:46 +00002037 struct bgp_node *rn;
2038 struct bgp_info *ri;
2039 char buf[SU_ADDRSTRLEN];
2040
2041 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002042 return;
paulfee0f4c2004-09-13 05:12:46 +00002043
2044 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2045
2046 /* Lookup withdrawn route. */
2047 for (ri = rn->info; ri; ri = ri->next)
2048 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2049 break;
2050
2051 /* Withdraw specified route from routing table. */
2052 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002053 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002054 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002055 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002056 "%s Can't find the route %s/%d", peer->host,
2057 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2058 p->prefixlen);
2059
2060 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002061 bgp_unlock_node (rn);
2062}
paulfee0f4c2004-09-13 05:12:46 +00002063
paul94f2b392005-06-28 12:44:16 +00002064static int
paulfee0f4c2004-09-13 05:12:46 +00002065bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002066 afi_t afi, safi_t safi, int type, int sub_type,
2067 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2068{
2069 int ret;
2070 int aspath_loop_count = 0;
2071 struct bgp_node *rn;
2072 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002073 struct attr new_attr;
2074 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002075 struct attr *attr_new;
2076 struct bgp_info *ri;
2077 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002078 const char *reason;
paul718e3742002-12-13 20:15:29 +00002079 char buf[SU_ADDRSTRLEN];
2080
2081 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002082 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002083
paul718e3742002-12-13 20:15:29 +00002084 /* When peer's soft reconfiguration enabled. Record input packet in
2085 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002086 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2087 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002088 bgp_adj_in_set (rn, peer, attr);
2089
2090 /* Check previously received route. */
2091 for (ri = rn->info; ri; ri = ri->next)
2092 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2093 break;
2094
2095 /* AS path local-as loop check. */
2096 if (peer->change_local_as)
2097 {
2098 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2099 aspath_loop_count = 1;
2100
2101 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2102 {
2103 reason = "as-path contains our own AS;";
2104 goto filtered;
2105 }
2106 }
2107
2108 /* AS path loop check. */
2109 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2110 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2111 && aspath_loop_check(attr->aspath, bgp->confed_id)
2112 > peer->allowas_in[afi][safi]))
2113 {
2114 reason = "as-path contains our own AS;";
2115 goto filtered;
2116 }
2117
2118 /* Route reflector originator ID check. */
2119 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002120 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002121 {
2122 reason = "originator is us;";
2123 goto filtered;
2124 }
2125
2126 /* Route reflector cluster ID check. */
2127 if (bgp_cluster_filter (peer, attr))
2128 {
2129 reason = "reflected from the same cluster;";
2130 goto filtered;
2131 }
2132
2133 /* Apply incoming filter. */
2134 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2135 {
2136 reason = "filter;";
2137 goto filtered;
2138 }
2139
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002140 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002141 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002142
David Lamparterc460e572014-06-04 00:54:58 +02002143 /* Apply incoming route-map.
2144 * NB: new_attr may now contain newly allocated values from route-map "set"
2145 * commands, so we need bgp_attr_flush in the error paths, until we intern
2146 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002147 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2148 {
2149 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002150 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002151 goto filtered;
2152 }
2153
2154 /* IPv4 unicast next hop check. */
2155 if (afi == AFI_IP && safi == SAFI_UNICAST)
2156 {
2157 /* If the peer is EBGP and nexthop is not on connected route,
2158 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002159 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002160 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002161 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002162 {
2163 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002164 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002165 goto filtered;
2166 }
2167
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002168 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002169 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002170 if (new_attr.nexthop.s_addr == 0
2171 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2172 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002173 {
2174 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002175 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002176 goto filtered;
2177 }
2178 }
2179
2180 attr_new = bgp_attr_intern (&new_attr);
2181
2182 /* If the update is implicit withdraw. */
2183 if (ri)
2184 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002185 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002186
2187 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002188 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2189 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002190 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002191 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002192
2193 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002194 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002195 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2196 {
2197 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002198 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002199 peer->host,
2200 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2201 p->prefixlen);
2202
paul902212c2006-02-05 17:51:19 +00002203 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2204 {
2205 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2206 bgp_process (bgp, rn, afi, safi);
2207 }
paul718e3742002-12-13 20:15:29 +00002208 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002209 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002210 {
2211 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002212 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002213 "%s rcvd %s/%d...duplicate ignored",
2214 peer->host,
2215 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2216 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002217
2218 /* graceful restart STALE flag unset. */
2219 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2220 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002221 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002222 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002223 }
paul718e3742002-12-13 20:15:29 +00002224 }
2225
2226 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002227 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002228
paul718e3742002-12-13 20:15:29 +00002229 return 0;
2230 }
2231
Paul Jakma16d2e242007-04-10 19:32:10 +00002232 /* Withdraw/Announce before we fully processed the withdraw */
2233 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2234 {
2235 if (BGP_DEBUG (update, UPDATE_IN))
2236 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2237 peer->host,
2238 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2239 p->prefixlen);
2240 bgp_info_restore (rn, ri);
2241 }
2242
paul718e3742002-12-13 20:15:29 +00002243 /* Received Logging. */
2244 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002245 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002246 peer->host,
2247 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2248 p->prefixlen);
2249
hasso93406d82005-02-02 14:40:33 +00002250 /* graceful restart STALE flag unset. */
2251 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002252 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002253
paul718e3742002-12-13 20:15:29 +00002254 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002256
2257 /* implicit withdraw, decrement aggregate and pcount here.
2258 * only if update is accepted, they'll increment below.
2259 */
paul902212c2006-02-05 17:51:19 +00002260 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2261
paul718e3742002-12-13 20:15:29 +00002262 /* Update bgp route dampening information. */
2263 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002264 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002265 {
2266 /* This is implicit withdraw so we should update dampening
2267 information. */
2268 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2269 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002270 }
2271
paul718e3742002-12-13 20:15:29 +00002272 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002273 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002274 ri->attr = attr_new;
2275
2276 /* Update MPLS tag. */
2277 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002278 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002279
2280 /* Update bgp route dampening information. */
2281 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002282 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002283 {
2284 /* Now we do normal update dampening. */
2285 ret = bgp_damp_update (ri, rn, afi, safi);
2286 if (ret == BGP_DAMP_SUPPRESSED)
2287 {
2288 bgp_unlock_node (rn);
2289 return 0;
2290 }
2291 }
2292
2293 /* Nexthop reachability check. */
2294 if ((afi == AFI_IP || afi == AFI_IP6)
2295 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002296 && (peer->sort == BGP_PEER_IBGP
2297 || peer->sort == BGP_PEER_CONFED
2298 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002299 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002300 {
2301 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002302 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002303 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002305 }
2306 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002307 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002308
2309 /* Process change. */
2310 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2311
2312 bgp_process (bgp, rn, afi, safi);
2313 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002314
paul718e3742002-12-13 20:15:29 +00002315 return 0;
2316 }
2317
2318 /* Received Logging. */
2319 if (BGP_DEBUG (update, UPDATE_IN))
2320 {
ajsd2c1f162004-12-08 21:10:20 +00002321 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002322 peer->host,
2323 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2324 p->prefixlen);
2325 }
2326
paul718e3742002-12-13 20:15:29 +00002327 /* Make new BGP info. */
2328 new = bgp_info_new ();
2329 new->type = type;
2330 new->sub_type = sub_type;
2331 new->peer = peer;
2332 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002333 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002334
2335 /* Update MPLS tag. */
2336 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002337 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002338
2339 /* Nexthop reachability check. */
2340 if ((afi == AFI_IP || afi == AFI_IP6)
2341 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002342 && (peer->sort == BGP_PEER_IBGP
2343 || peer->sort == BGP_PEER_CONFED
2344 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002345 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002346 {
2347 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002348 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002349 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002350 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002351 }
2352 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002353 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002354
paul902212c2006-02-05 17:51:19 +00002355 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002356 bgp_aggregate_increment (bgp, p, new, afi, safi);
2357
2358 /* Register new BGP information. */
2359 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002360
2361 /* route_node_get lock */
2362 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002363
paul718e3742002-12-13 20:15:29 +00002364 /* If maximum prefix count is configured and current prefix
2365 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002366 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2367 return -1;
paul718e3742002-12-13 20:15:29 +00002368
2369 /* Process change. */
2370 bgp_process (bgp, rn, afi, safi);
2371
2372 return 0;
2373
2374 /* This BGP update is filtered. Log the reason then update BGP
2375 entry. */
2376 filtered:
2377 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002378 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002379 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2380 peer->host,
2381 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2382 p->prefixlen, reason);
2383
2384 if (ri)
paulb40d9392005-08-22 22:34:41 +00002385 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002386
2387 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002388
paul718e3742002-12-13 20:15:29 +00002389 return 0;
2390}
2391
2392int
paulfee0f4c2004-09-13 05:12:46 +00002393bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2394 afi_t afi, safi_t safi, int type, int sub_type,
2395 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2396{
2397 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002398 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002399 struct bgp *bgp;
2400 int ret;
2401
2402 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2403 soft_reconfig);
2404
2405 bgp = peer->bgp;
2406
2407 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002408 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002409 {
2410 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2411 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2412 sub_type, prd, tag);
2413 }
2414
2415 return ret;
2416}
2417
2418int
paul718e3742002-12-13 20:15:29 +00002419bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002420 afi_t afi, safi_t safi, int type, int sub_type,
2421 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002422{
2423 struct bgp *bgp;
2424 char buf[SU_ADDRSTRLEN];
2425 struct bgp_node *rn;
2426 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002427 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002428 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002429
2430 bgp = peer->bgp;
2431
paulfee0f4c2004-09-13 05:12:46 +00002432 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002433 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002434 {
2435 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2436 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2437 }
2438
paul718e3742002-12-13 20:15:29 +00002439 /* Logging. */
2440 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002441 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002442 peer->host,
2443 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2444 p->prefixlen);
2445
2446 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002447 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002448
2449 /* If peer is soft reconfiguration enabled. Record input packet for
2450 further calculation. */
2451 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2452 && peer != bgp->peer_self)
2453 bgp_adj_in_unset (rn, peer);
2454
2455 /* Lookup withdrawn route. */
2456 for (ri = rn->info; ri; ri = ri->next)
2457 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2458 break;
2459
2460 /* Withdraw specified route from routing table. */
2461 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002462 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002463 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002464 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002465 "%s Can't find the route %s/%d", peer->host,
2466 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2467 p->prefixlen);
2468
2469 /* Unlock bgp_node_get() lock. */
2470 bgp_unlock_node (rn);
2471
2472 return 0;
2473}
David Lamparter6b0655a2014-06-04 06:53:35 +02002474
paul718e3742002-12-13 20:15:29 +00002475void
2476bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2477{
2478 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002479 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002480 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002481 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002482 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002483 struct bgp_node *rn;
2484 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002485 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002486
Paul Jakmab2497022007-06-14 11:17:58 +00002487 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002488 return;
2489
paul718e3742002-12-13 20:15:29 +00002490 bgp = peer->bgp;
2491 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002492
paul718e3742002-12-13 20:15:29 +00002493 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2494 aspath = attr.aspath;
2495 attr.local_pref = bgp->default_local_pref;
2496 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2497
2498 if (afi == AFI_IP)
2499 str2prefix ("0.0.0.0/0", &p);
2500#ifdef HAVE_IPV6
2501 else if (afi == AFI_IP6)
2502 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002503 struct attr_extra *ae = attr.extra;
2504
paul718e3742002-12-13 20:15:29 +00002505 str2prefix ("::/0", &p);
2506
2507 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002508 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002509 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002510 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002511
2512 /* If the peer is on shared nextwork and we have link-local
2513 nexthop set it. */
2514 if (peer->shared_network
2515 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2516 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002517 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002518 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002519 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002520 }
2521 }
2522#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002523
2524 if (peer->default_rmap[afi][safi].name)
2525 {
paulfee0f4c2004-09-13 05:12:46 +00002526 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002527 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2528 {
2529 for (ri = rn->info; ri; ri = ri->next)
2530 {
2531 struct attr dummy_attr;
2532 struct attr_extra dummy_extra;
2533 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002534
Christian Frankedcab1bb2012-12-07 16:45:52 +00002535 /* Provide dummy so the route-map can't modify the attributes */
2536 dummy_attr.extra = &dummy_extra;
2537 bgp_attr_dup(&dummy_attr, ri->attr);
2538 info.peer = ri->peer;
2539 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002540
Christian Frankedcab1bb2012-12-07 16:45:52 +00002541 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2542 RMAP_BGP, &info);
2543
2544 /* The route map might have set attributes. If we don't flush them
2545 * here, they will be leaked. */
2546 bgp_attr_flush(&dummy_attr);
2547 if (ret != RMAP_DENYMATCH)
2548 break;
2549 }
2550 if (ret != RMAP_DENYMATCH)
2551 break;
2552 }
paulfee0f4c2004-09-13 05:12:46 +00002553 bgp->peer_self->rmap_type = 0;
2554
paul718e3742002-12-13 20:15:29 +00002555 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002556 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002557 }
2558
2559 if (withdraw)
2560 {
2561 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2562 bgp_default_withdraw_send (peer, afi, safi);
2563 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2564 }
2565 else
2566 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2568 {
2569 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2570 bgp_default_update_send (peer, &attr, afi, safi, from);
2571 }
paul718e3742002-12-13 20:15:29 +00002572 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002573
2574 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002575 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002576}
David Lamparter6b0655a2014-06-04 06:53:35 +02002577
paul718e3742002-12-13 20:15:29 +00002578static void
2579bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002580 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002581{
2582 struct bgp_node *rn;
2583 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002584 struct attr attr;
2585 struct attr_extra extra;
2586
paul718e3742002-12-13 20:15:29 +00002587 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002588 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002589
2590 if (safi != SAFI_MPLS_VPN
2591 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2592 bgp_default_originate (peer, afi, safi, 0);
2593
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002594 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2595 attr.extra = &extra;
2596
paul718e3742002-12-13 20:15:29 +00002597 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2598 for (ri = rn->info; ri; ri = ri->next)
2599 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2600 {
paulfee0f4c2004-09-13 05:12:46 +00002601 if ( (rsclient) ?
2602 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2603 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002604 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2605 else
2606 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2607 }
2608}
2609
2610void
2611bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2612{
2613 struct bgp_node *rn;
2614 struct bgp_table *table;
2615
2616 if (peer->status != Established)
2617 return;
2618
2619 if (! peer->afc_nego[afi][safi])
2620 return;
2621
2622 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2623 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2624 return;
2625
2626 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002627 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002628 else
2629 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2630 rn = bgp_route_next(rn))
2631 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002632 bgp_announce_table (peer, afi, safi, table, 0);
2633
2634 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2635 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002636}
2637
2638void
2639bgp_announce_route_all (struct peer *peer)
2640{
2641 afi_t afi;
2642 safi_t safi;
2643
2644 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2645 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2646 bgp_announce_route (peer, afi, safi);
2647}
David Lamparter6b0655a2014-06-04 06:53:35 +02002648
paul718e3742002-12-13 20:15:29 +00002649static void
paulfee0f4c2004-09-13 05:12:46 +00002650bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002651 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002652{
2653 struct bgp_node *rn;
2654 struct bgp_adj_in *ain;
2655
2656 if (! table)
2657 table = rsclient->bgp->rib[afi][safi];
2658
2659 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2660 for (ain = rn->adj_in; ain; ain = ain->next)
2661 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002662 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002663 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002664
paulfee0f4c2004-09-13 05:12:46 +00002665 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002666 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002667 }
2668}
2669
2670void
2671bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2672{
2673 struct bgp_table *table;
2674 struct bgp_node *rn;
2675
2676 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002677 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002678
2679 else
2680 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2681 rn = bgp_route_next (rn))
2682 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002683 {
2684 struct prefix_rd prd;
2685 prd.family = AF_UNSPEC;
2686 prd.prefixlen = 64;
2687 memcpy(&prd.val, rn->p.u.val, 8);
2688
2689 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2690 }
paulfee0f4c2004-09-13 05:12:46 +00002691}
David Lamparter6b0655a2014-06-04 06:53:35 +02002692
paulfee0f4c2004-09-13 05:12:46 +00002693static void
paul718e3742002-12-13 20:15:29 +00002694bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002695 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002696{
2697 int ret;
2698 struct bgp_node *rn;
2699 struct bgp_adj_in *ain;
2700
2701 if (! table)
2702 table = peer->bgp->rib[afi][safi];
2703
2704 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2705 for (ain = rn->adj_in; ain; ain = ain->next)
2706 {
2707 if (ain->peer == peer)
2708 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002710 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002711
paul718e3742002-12-13 20:15:29 +00002712 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2713 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002714 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002715
paul718e3742002-12-13 20:15:29 +00002716 if (ret < 0)
2717 {
2718 bgp_unlock_node (rn);
2719 return;
2720 }
2721 continue;
2722 }
2723 }
2724}
2725
2726void
2727bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2728{
2729 struct bgp_node *rn;
2730 struct bgp_table *table;
2731
2732 if (peer->status != Established)
2733 return;
2734
2735 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002736 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002737 else
2738 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2739 rn = bgp_route_next (rn))
2740 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002741 {
2742 struct prefix_rd prd;
2743 prd.family = AF_UNSPEC;
2744 prd.prefixlen = 64;
2745 memcpy(&prd.val, rn->p.u.val, 8);
2746
2747 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2748 }
paul718e3742002-12-13 20:15:29 +00002749}
David Lamparter6b0655a2014-06-04 06:53:35 +02002750
Chris Caputo228da422009-07-18 05:44:03 +00002751
2752struct bgp_clear_node_queue
2753{
2754 struct bgp_node *rn;
2755 enum bgp_clear_route_type purpose;
2756};
2757
paul200df112005-06-01 11:17:05 +00002758static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002759bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002760{
Chris Caputo228da422009-07-18 05:44:03 +00002761 struct bgp_clear_node_queue *cnq = data;
2762 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002763 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002764 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002765 afi_t afi = bgp_node_table (rn)->afi;
2766 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002767
Paul Jakma64e580a2006-02-21 01:09:01 +00002768 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002769
Paul Jakma64e580a2006-02-21 01:09:01 +00002770 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002771 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002772 {
2773 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002774 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2775 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002776 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002777 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2778 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002779 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002780 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002781 break;
2782 }
paul200df112005-06-01 11:17:05 +00002783 return WQ_SUCCESS;
2784}
2785
2786static void
paul0fb58d52005-11-14 14:31:49 +00002787bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002788{
Chris Caputo228da422009-07-18 05:44:03 +00002789 struct bgp_clear_node_queue *cnq = data;
2790 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002791 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002792
2793 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002794 bgp_table_unlock (table);
2795 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002796}
2797
2798static void
paul94f2b392005-06-28 12:44:16 +00002799bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002800{
Paul Jakma64e580a2006-02-21 01:09:01 +00002801 struct peer *peer = wq->spec.data;
2802
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002803 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002804 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002805
2806 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002807}
2808
2809static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002810bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002811{
Paul Jakmaa2943652009-07-21 14:02:04 +01002812 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002813
Paul Jakmaa2943652009-07-21 14:02:04 +01002814 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002815#undef CLEAR_QUEUE_NAME_LEN
2816
2817 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002818 {
2819 zlog_err ("%s: Failed to allocate work queue", __func__);
2820 exit (1);
2821 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002822 peer->clear_node_queue->spec.hold = 10;
2823 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2824 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2825 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2826 peer->clear_node_queue->spec.max_retries = 0;
2827
2828 /* we only 'lock' this peer reference when the queue is actually active */
2829 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002830}
2831
paul718e3742002-12-13 20:15:29 +00002832static void
2833bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_table *table, struct peer *rsclient,
2835 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002836{
2837 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002838
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002839
paul718e3742002-12-13 20:15:29 +00002840 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002841 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002842
hasso6cf159b2005-03-21 10:28:14 +00002843 /* If still no table => afi/safi isn't configured at all or smth. */
2844 if (! table)
2845 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002846
2847 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2848 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002849 struct bgp_info *ri;
2850 struct bgp_adj_in *ain;
2851 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002852
2853 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2854 * queued for every clearing peer, regardless of whether it is
2855 * relevant to the peer at hand.
2856 *
2857 * Overview: There are 3 different indices which need to be
2858 * scrubbed, potentially, when a peer is removed:
2859 *
2860 * 1 peer's routes visible via the RIB (ie accepted routes)
2861 * 2 peer's routes visible by the (optional) peer's adj-in index
2862 * 3 other routes visible by the peer's adj-out index
2863 *
2864 * 3 there is no hurry in scrubbing, once the struct peer is
2865 * removed from bgp->peer, we could just GC such deleted peer's
2866 * adj-outs at our leisure.
2867 *
2868 * 1 and 2 must be 'scrubbed' in some way, at least made
2869 * invisible via RIB index before peer session is allowed to be
2870 * brought back up. So one needs to know when such a 'search' is
2871 * complete.
2872 *
2873 * Ideally:
2874 *
2875 * - there'd be a single global queue or a single RIB walker
2876 * - rather than tracking which route_nodes still need to be
2877 * examined on a peer basis, we'd track which peers still
2878 * aren't cleared
2879 *
2880 * Given that our per-peer prefix-counts now should be reliable,
2881 * this may actually be achievable. It doesn't seem to be a huge
2882 * problem at this time,
2883 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002884 for (ain = rn->adj_in; ain; ain = ain->next)
2885 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2886 {
2887 bgp_adj_in_remove (rn, ain);
2888 bgp_unlock_node (rn);
2889 break;
2890 }
2891 for (aout = rn->adj_out; aout; aout = aout->next)
2892 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2893 {
2894 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2895 bgp_unlock_node (rn);
2896 break;
2897 }
2898
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002899 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002900 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002901 {
Chris Caputo228da422009-07-18 05:44:03 +00002902 struct bgp_clear_node_queue *cnq;
2903
2904 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002905 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002906 bgp_lock_node (rn);
2907 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2908 sizeof (struct bgp_clear_node_queue));
2909 cnq->rn = rn;
2910 cnq->purpose = purpose;
2911 work_queue_add (peer->clear_node_queue, cnq);
2912 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002913 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002914 }
2915 return;
2916}
2917
2918void
Chris Caputo228da422009-07-18 05:44:03 +00002919bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2920 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002921{
2922 struct bgp_node *rn;
2923 struct bgp_table *table;
2924 struct peer *rsclient;
2925 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002926
Paul Jakma64e580a2006-02-21 01:09:01 +00002927 if (peer->clear_node_queue == NULL)
2928 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002929
Paul Jakmaca058a32006-09-14 02:58:49 +00002930 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2931 * Idle until it receives a Clearing_Completed event. This protects
2932 * against peers which flap faster than we can we clear, which could
2933 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002934 *
2935 * a) race with routes from the new session being installed before
2936 * clear_route_node visits the node (to delete the route of that
2937 * peer)
2938 * b) resource exhaustion, clear_route_node likely leads to an entry
2939 * on the process_main queue. Fast-flapping could cause that queue
2940 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002941 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002942 if (!peer->clear_node_queue->thread)
2943 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002944
Chris Caputo228da422009-07-18 05:44:03 +00002945 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002946 {
Chris Caputo228da422009-07-18 05:44:03 +00002947 case BGP_CLEAR_ROUTE_NORMAL:
2948 if (safi != SAFI_MPLS_VPN)
2949 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2950 else
2951 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2952 rn = bgp_route_next (rn))
2953 if ((table = rn->info) != NULL)
2954 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2955
2956 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2957 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2958 PEER_FLAG_RSERVER_CLIENT))
2959 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2960 break;
2961
2962 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2963 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2964 break;
2965
2966 default:
2967 assert (0);
2968 break;
paulfee0f4c2004-09-13 05:12:46 +00002969 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002970
Paul Jakmaca058a32006-09-14 02:58:49 +00002971 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002972 * completion function won't be run by workqueue code - call it here.
2973 * XXX: Actually, this assumption doesn't hold, see
2974 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002975 *
2976 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002977 * really needed if peer state is Established - peers in
2978 * pre-Established states shouldn't have any route-update state
2979 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002980 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002981 * We still can get here in pre-Established though, through
2982 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2983 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002984 *
2985 * At some future point, this check could be move to the top of the
2986 * function, and do a quick early-return when state is
2987 * pre-Established, avoiding above list and table scans. Once we're
2988 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002989 */
2990 if (!peer->clear_node_queue->thread)
2991 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002992}
2993
2994void
2995bgp_clear_route_all (struct peer *peer)
2996{
2997 afi_t afi;
2998 safi_t safi;
2999
3000 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3001 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003002 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003003}
3004
3005void
3006bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3007{
3008 struct bgp_table *table;
3009 struct bgp_node *rn;
3010 struct bgp_adj_in *ain;
3011
3012 table = peer->bgp->rib[afi][safi];
3013
3014 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3015 for (ain = rn->adj_in; ain ; ain = ain->next)
3016 if (ain->peer == peer)
3017 {
3018 bgp_adj_in_remove (rn, ain);
3019 bgp_unlock_node (rn);
3020 break;
3021 }
3022}
hasso93406d82005-02-02 14:40:33 +00003023
3024void
3025bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3026{
3027 struct bgp_node *rn;
3028 struct bgp_info *ri;
3029 struct bgp_table *table;
3030
3031 table = peer->bgp->rib[afi][safi];
3032
3033 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3034 {
3035 for (ri = rn->info; ri; ri = ri->next)
3036 if (ri->peer == peer)
3037 {
3038 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3039 bgp_rib_remove (rn, ri, peer, afi, safi);
3040 break;
3041 }
3042 }
3043}
David Lamparter6b0655a2014-06-04 06:53:35 +02003044
paul718e3742002-12-13 20:15:29 +00003045/* Delete all kernel routes. */
3046void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003047bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003048{
3049 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003050 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003051 struct bgp_node *rn;
3052 struct bgp_table *table;
3053 struct bgp_info *ri;
3054
paul1eb8ef22005-04-07 07:30:20 +00003055 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003056 {
3057 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3058
3059 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3060 for (ri = rn->info; ri; ri = ri->next)
3061 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3062 && ri->type == ZEBRA_ROUTE_BGP
3063 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003064 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003065
3066 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3067
3068 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3069 for (ri = rn->info; ri; ri = ri->next)
3070 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3071 && ri->type == ZEBRA_ROUTE_BGP
3072 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003073 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003074 }
3075}
3076
3077void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003078bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003079{
3080 vty_reset ();
3081 bgp_zclient_reset ();
3082 access_list_reset ();
3083 prefix_list_reset ();
3084}
David Lamparter6b0655a2014-06-04 06:53:35 +02003085
paul718e3742002-12-13 20:15:29 +00003086/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3087 value. */
3088int
3089bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3090{
3091 u_char *pnt;
3092 u_char *lim;
3093 struct prefix p;
3094 int psize;
3095 int ret;
3096
3097 /* Check peer status. */
3098 if (peer->status != Established)
3099 return 0;
3100
3101 pnt = packet->nlri;
3102 lim = pnt + packet->length;
3103
3104 for (; pnt < lim; pnt += psize)
3105 {
3106 /* Clear prefix structure. */
3107 memset (&p, 0, sizeof (struct prefix));
3108
3109 /* Fetch prefix length. */
3110 p.prefixlen = *pnt++;
3111 p.family = afi2family (packet->afi);
3112
3113 /* Already checked in nlri_sanity_check(). We do double check
3114 here. */
3115 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3116 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3117 return -1;
3118
3119 /* Packet size overflow check. */
3120 psize = PSIZE (p.prefixlen);
3121
3122 /* When packet overflow occur return immediately. */
3123 if (pnt + psize > lim)
3124 return -1;
3125
3126 /* Fetch prefix from NLRI packet. */
3127 memcpy (&p.u.prefix, pnt, psize);
3128
3129 /* Check address. */
3130 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3131 {
3132 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3133 {
paulf5ba3872004-07-09 12:11:31 +00003134 /*
3135 * From draft-ietf-idr-bgp4-22, Section 6.3:
3136 * If a BGP router receives an UPDATE message with a
3137 * semantically incorrect NLRI field, in which a prefix is
3138 * semantically incorrect (eg. an unexpected multicast IP
3139 * address), it should ignore the prefix.
3140 */
paul718e3742002-12-13 20:15:29 +00003141 zlog (peer->log, LOG_ERR,
3142 "IPv4 unicast NLRI is multicast address %s",
3143 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003144
paul718e3742002-12-13 20:15:29 +00003145 return -1;
3146 }
3147 }
3148
3149#ifdef HAVE_IPV6
3150 /* Check address. */
3151 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3152 {
3153 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3154 {
3155 char buf[BUFSIZ];
3156
3157 zlog (peer->log, LOG_WARNING,
3158 "IPv6 link-local NLRI received %s ignore this NLRI",
3159 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3160
3161 continue;
3162 }
3163 }
3164#endif /* HAVE_IPV6 */
3165
3166 /* Normal process. */
3167 if (attr)
3168 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3169 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3170 else
3171 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3172 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3173
3174 /* Address family configuration mismatch or maximum-prefix count
3175 overflow. */
3176 if (ret < 0)
3177 return -1;
3178 }
3179
3180 /* Packet length consistency check. */
3181 if (pnt != lim)
3182 return -1;
3183
3184 return 0;
3185}
3186
3187/* NLRI encode syntax check routine. */
3188int
3189bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3190 bgp_size_t length)
3191{
3192 u_char *end;
3193 u_char prefixlen;
3194 int psize;
3195
3196 end = pnt + length;
3197
3198 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3199 syntactic validity. If the field is syntactically incorrect,
3200 then the Error Subcode is set to Invalid Network Field. */
3201
3202 while (pnt < end)
3203 {
3204 prefixlen = *pnt++;
3205
3206 /* Prefix length check. */
3207 if ((afi == AFI_IP && prefixlen > 32)
3208 || (afi == AFI_IP6 && prefixlen > 128))
3209 {
3210 plog_err (peer->log,
3211 "%s [Error] Update packet error (wrong prefix length %d)",
3212 peer->host, prefixlen);
3213 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3214 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3215 return -1;
3216 }
3217
3218 /* Packet size overflow check. */
3219 psize = PSIZE (prefixlen);
3220
3221 if (pnt + psize > end)
3222 {
3223 plog_err (peer->log,
3224 "%s [Error] Update packet error"
3225 " (prefix data overflow prefix size is %d)",
3226 peer->host, psize);
3227 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3228 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3229 return -1;
3230 }
3231
3232 pnt += psize;
3233 }
3234
3235 /* Packet length consistency check. */
3236 if (pnt != end)
3237 {
3238 plog_err (peer->log,
3239 "%s [Error] Update packet error"
3240 " (prefix length mismatch with total length)",
3241 peer->host);
3242 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3243 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3244 return -1;
3245 }
3246 return 0;
3247}
David Lamparter6b0655a2014-06-04 06:53:35 +02003248
paul94f2b392005-06-28 12:44:16 +00003249static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003250bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003251{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003252 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003253}
3254
paul94f2b392005-06-28 12:44:16 +00003255static void
paul718e3742002-12-13 20:15:29 +00003256bgp_static_free (struct bgp_static *bgp_static)
3257{
3258 if (bgp_static->rmap.name)
3259 free (bgp_static->rmap.name);
3260 XFREE (MTYPE_BGP_STATIC, bgp_static);
3261}
3262
paul94f2b392005-06-28 12:44:16 +00003263static void
paulfee0f4c2004-09-13 05:12:46 +00003264bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3265 struct prefix *p, afi_t afi, safi_t safi)
3266{
3267 struct bgp_node *rn;
3268 struct bgp_info *ri;
3269
3270 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3271
3272 /* Check selected route and self inserted route. */
3273 for (ri = rn->info; ri; ri = ri->next)
3274 if (ri->peer == bgp->peer_self
3275 && ri->type == ZEBRA_ROUTE_BGP
3276 && ri->sub_type == BGP_ROUTE_STATIC)
3277 break;
3278
3279 /* Withdraw static BGP route from routing table. */
3280 if (ri)
3281 {
paulfee0f4c2004-09-13 05:12:46 +00003282 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003283 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003284 }
3285
3286 /* Unlock bgp_node_lookup. */
3287 bgp_unlock_node (rn);
3288}
3289
paul94f2b392005-06-28 12:44:16 +00003290static void
paulfee0f4c2004-09-13 05:12:46 +00003291bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 struct bgp_static *bgp_static,
3293 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003294{
3295 struct bgp_node *rn;
3296 struct bgp_info *ri;
3297 struct bgp_info *new;
3298 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003299 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003300 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003301 struct attr new_attr;
3302 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003303 struct bgp *bgp;
3304 int ret;
3305 char buf[SU_ADDRSTRLEN];
3306
3307 bgp = rsclient->bgp;
3308
Paul Jakma06e110f2006-05-12 23:29:22 +00003309 assert (bgp_static);
3310 if (!bgp_static)
3311 return;
3312
paulfee0f4c2004-09-13 05:12:46 +00003313 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3314
3315 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003316
3317 attr.nexthop = bgp_static->igpnexthop;
3318 attr.med = bgp_static->igpmetric;
3319 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003320
Paul Jakma41367172007-08-06 15:24:51 +00003321 if (bgp_static->atomic)
3322 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3323
paulfee0f4c2004-09-13 05:12:46 +00003324 /* Apply network route-map for export to this rsclient. */
3325 if (bgp_static->rmap.name)
3326 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003328 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003329 info.attr = &attr_tmp;
3330
paulfee0f4c2004-09-13 05:12:46 +00003331 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3332 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3333
3334 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3335
3336 rsclient->rmap_type = 0;
3337
3338 if (ret == RMAP_DENYMATCH)
3339 {
3340 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003342
3343 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003344 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003345 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 bgp_attr_extra_free (&attr);
3347
paulfee0f4c2004-09-13 05:12:46 +00003348 return;
3349 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003350 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003351 }
3352 else
3353 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003354
3355 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003356 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003357
paulfee0f4c2004-09-13 05:12:46 +00003358 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3359
Paul Jakmafb982c22007-05-04 20:15:47 +00003360 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3361 == RMAP_DENY)
3362 {
paulfee0f4c2004-09-13 05:12:46 +00003363 /* This BGP update is filtered. Log the reason then update BGP entry. */
3364 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003365 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003366 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3367 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3368 p->prefixlen, rsclient->host);
3369
3370 bgp->peer_self->rmap_type = 0;
3371
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003372 bgp_attr_unintern (&attr_new);
3373 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003374 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3377
3378 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003379 }
paulfee0f4c2004-09-13 05:12:46 +00003380
3381 bgp->peer_self->rmap_type = 0;
3382
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003383 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003384 attr_new = bgp_attr_intern (&new_attr);
3385
3386 for (ri = rn->info; ri; ri = ri->next)
3387 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3388 && ri->sub_type == BGP_ROUTE_STATIC)
3389 break;
3390
3391 if (ri)
3392 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003393 if (attrhash_cmp (ri->attr, attr_new) &&
3394 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003395 {
3396 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003397 bgp_attr_unintern (&attr_new);
3398 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003399 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003400 return;
3401 }
3402 else
3403 {
3404 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003405 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003406
3407 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003408 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3409 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003410 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003411 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003412 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003413
3414 /* Process change. */
3415 bgp_process (bgp, rn, afi, safi);
3416 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003417 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003418 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003419 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003420 }
paulfee0f4c2004-09-13 05:12:46 +00003421 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003422
paulfee0f4c2004-09-13 05:12:46 +00003423 /* Make new BGP info. */
3424 new = bgp_info_new ();
3425 new->type = ZEBRA_ROUTE_BGP;
3426 new->sub_type = BGP_ROUTE_STATIC;
3427 new->peer = bgp->peer_self;
3428 SET_FLAG (new->flags, BGP_INFO_VALID);
3429 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003430 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003431
3432 /* Register new BGP information. */
3433 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003434
3435 /* route_node_get lock */
3436 bgp_unlock_node (rn);
3437
paulfee0f4c2004-09-13 05:12:46 +00003438 /* Process change. */
3439 bgp_process (bgp, rn, afi, safi);
3440
3441 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003442 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003443 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003444}
3445
paul94f2b392005-06-28 12:44:16 +00003446static void
paulfee0f4c2004-09-13 05:12:46 +00003447bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003448 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3449{
3450 struct bgp_node *rn;
3451 struct bgp_info *ri;
3452 struct bgp_info *new;
3453 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003454 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003455 struct attr *attr_new;
3456 int ret;
3457
Paul Jakmadd8103a2006-05-12 23:27:30 +00003458 assert (bgp_static);
3459 if (!bgp_static)
3460 return;
3461
paulfee0f4c2004-09-13 05:12:46 +00003462 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003463
3464 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003465
3466 attr.nexthop = bgp_static->igpnexthop;
3467 attr.med = bgp_static->igpmetric;
3468 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003469
Paul Jakma41367172007-08-06 15:24:51 +00003470 if (bgp_static->atomic)
3471 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3472
paul718e3742002-12-13 20:15:29 +00003473 /* Apply route-map. */
3474 if (bgp_static->rmap.name)
3475 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003476 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003477 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003478 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003479
paulfee0f4c2004-09-13 05:12:46 +00003480 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3481
paul718e3742002-12-13 20:15:29 +00003482 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003483
paulfee0f4c2004-09-13 05:12:46 +00003484 bgp->peer_self->rmap_type = 0;
3485
paul718e3742002-12-13 20:15:29 +00003486 if (ret == RMAP_DENYMATCH)
3487 {
3488 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003489 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003490
3491 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003492 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003493 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003494 bgp_static_withdraw (bgp, p, afi, safi);
3495 return;
3496 }
paul286e1e72003-08-08 00:24:31 +00003497 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003498 }
paul286e1e72003-08-08 00:24:31 +00003499 else
3500 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003501
3502 for (ri = rn->info; ri; ri = ri->next)
3503 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3504 && ri->sub_type == BGP_ROUTE_STATIC)
3505 break;
3506
3507 if (ri)
3508 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003509 if (attrhash_cmp (ri->attr, attr_new) &&
3510 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003511 {
3512 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003513 bgp_attr_unintern (&attr_new);
3514 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003515 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003516 return;
3517 }
3518 else
3519 {
3520 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003521 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003522
3523 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003524 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3525 bgp_info_restore(rn, ri);
3526 else
3527 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003528 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003529 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003530 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003531
3532 /* Process change. */
3533 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3534 bgp_process (bgp, rn, afi, safi);
3535 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003536 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003537 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003538 return;
3539 }
3540 }
3541
3542 /* Make new BGP info. */
3543 new = bgp_info_new ();
3544 new->type = ZEBRA_ROUTE_BGP;
3545 new->sub_type = BGP_ROUTE_STATIC;
3546 new->peer = bgp->peer_self;
3547 SET_FLAG (new->flags, BGP_INFO_VALID);
3548 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003549 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003550
3551 /* Aggregate address increment. */
3552 bgp_aggregate_increment (bgp, p, new, afi, safi);
3553
3554 /* Register new BGP information. */
3555 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003556
3557 /* route_node_get lock */
3558 bgp_unlock_node (rn);
3559
paul718e3742002-12-13 20:15:29 +00003560 /* Process change. */
3561 bgp_process (bgp, rn, afi, safi);
3562
3563 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003564 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003565 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003566}
3567
3568void
paulfee0f4c2004-09-13 05:12:46 +00003569bgp_static_update (struct bgp *bgp, struct prefix *p,
3570 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3571{
3572 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003573 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003574
3575 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3576
paul1eb8ef22005-04-07 07:30:20 +00003577 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003578 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003579 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3580 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003581 }
3582}
3583
paul94f2b392005-06-28 12:44:16 +00003584static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003585bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3586 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003587{
3588 struct bgp_node *rn;
3589 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003590
paulfee0f4c2004-09-13 05:12:46 +00003591 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003592
3593 /* Make new BGP info. */
3594 new = bgp_info_new ();
3595 new->type = ZEBRA_ROUTE_BGP;
3596 new->sub_type = BGP_ROUTE_STATIC;
3597 new->peer = bgp->peer_self;
3598 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3599 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003600 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003601 new->extra = bgp_info_extra_new();
3602 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003603
3604 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003605 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003606
3607 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003608 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003609
paul200df112005-06-01 11:17:05 +00003610 /* route_node_get lock */
3611 bgp_unlock_node (rn);
3612
paul718e3742002-12-13 20:15:29 +00003613 /* Process change. */
3614 bgp_process (bgp, rn, afi, safi);
3615}
3616
3617void
3618bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3619 safi_t safi)
3620{
3621 struct bgp_node *rn;
3622 struct bgp_info *ri;
3623
paulfee0f4c2004-09-13 05:12:46 +00003624 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003625
3626 /* Check selected route and self inserted route. */
3627 for (ri = rn->info; ri; ri = ri->next)
3628 if (ri->peer == bgp->peer_self
3629 && ri->type == ZEBRA_ROUTE_BGP
3630 && ri->sub_type == BGP_ROUTE_STATIC)
3631 break;
3632
3633 /* Withdraw static BGP route from routing table. */
3634 if (ri)
3635 {
3636 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003637 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003638 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003639 }
3640
3641 /* Unlock bgp_node_lookup. */
3642 bgp_unlock_node (rn);
3643}
3644
3645void
paulfee0f4c2004-09-13 05:12:46 +00003646bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3647{
3648 struct bgp_static *bgp_static;
3649 struct bgp *bgp;
3650 struct bgp_node *rn;
3651 struct prefix *p;
3652
3653 bgp = rsclient->bgp;
3654
3655 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3656 if ((bgp_static = rn->info) != NULL)
3657 {
3658 p = &rn->p;
3659
3660 bgp_static_update_rsclient (rsclient, p, bgp_static,
3661 afi, safi);
3662 }
3663}
3664
paul94f2b392005-06-28 12:44:16 +00003665static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003666bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3667 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003668{
3669 struct bgp_node *rn;
3670 struct bgp_info *ri;
3671
paulfee0f4c2004-09-13 05:12:46 +00003672 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003673
3674 /* Check selected route and self inserted route. */
3675 for (ri = rn->info; ri; ri = ri->next)
3676 if (ri->peer == bgp->peer_self
3677 && ri->type == ZEBRA_ROUTE_BGP
3678 && ri->sub_type == BGP_ROUTE_STATIC)
3679 break;
3680
3681 /* Withdraw static BGP route from routing table. */
3682 if (ri)
3683 {
3684 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003685 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003686 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003687 }
3688
3689 /* Unlock bgp_node_lookup. */
3690 bgp_unlock_node (rn);
3691}
3692
3693/* Configure static BGP network. When user don't run zebra, static
3694 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003695static int
paulfd79ac92004-10-13 05:06:08 +00003696bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003697 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003698{
3699 int ret;
3700 struct prefix p;
3701 struct bgp_static *bgp_static;
3702 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003703 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003704
3705 /* Convert IP prefix string to struct prefix. */
3706 ret = str2prefix (ip_str, &p);
3707 if (! ret)
3708 {
3709 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3710 return CMD_WARNING;
3711 }
3712#ifdef HAVE_IPV6
3713 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3714 {
3715 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3716 VTY_NEWLINE);
3717 return CMD_WARNING;
3718 }
3719#endif /* HAVE_IPV6 */
3720
3721 apply_mask (&p);
3722
3723 /* Set BGP static route configuration. */
3724 rn = bgp_node_get (bgp->route[afi][safi], &p);
3725
3726 if (rn->info)
3727 {
3728 /* Configuration change. */
3729 bgp_static = rn->info;
3730
3731 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003732 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3733 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003734
paul718e3742002-12-13 20:15:29 +00003735 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003736
paul718e3742002-12-13 20:15:29 +00003737 if (rmap)
3738 {
3739 if (bgp_static->rmap.name)
3740 free (bgp_static->rmap.name);
3741 bgp_static->rmap.name = strdup (rmap);
3742 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3743 }
3744 else
3745 {
3746 if (bgp_static->rmap.name)
3747 free (bgp_static->rmap.name);
3748 bgp_static->rmap.name = NULL;
3749 bgp_static->rmap.map = NULL;
3750 bgp_static->valid = 0;
3751 }
3752 bgp_unlock_node (rn);
3753 }
3754 else
3755 {
3756 /* New configuration. */
3757 bgp_static = bgp_static_new ();
3758 bgp_static->backdoor = backdoor;
3759 bgp_static->valid = 0;
3760 bgp_static->igpmetric = 0;
3761 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003762
paul718e3742002-12-13 20:15:29 +00003763 if (rmap)
3764 {
3765 if (bgp_static->rmap.name)
3766 free (bgp_static->rmap.name);
3767 bgp_static->rmap.name = strdup (rmap);
3768 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3769 }
3770 rn->info = bgp_static;
3771 }
3772
3773 /* If BGP scan is not enabled, we should install this route here. */
3774 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3775 {
3776 bgp_static->valid = 1;
3777
3778 if (need_update)
3779 bgp_static_withdraw (bgp, &p, afi, safi);
3780
3781 if (! bgp_static->backdoor)
3782 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3783 }
3784
3785 return CMD_SUCCESS;
3786}
3787
3788/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003789static int
paulfd79ac92004-10-13 05:06:08 +00003790bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003791 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003792{
3793 int ret;
3794 struct prefix p;
3795 struct bgp_static *bgp_static;
3796 struct bgp_node *rn;
3797
3798 /* Convert IP prefix string to struct prefix. */
3799 ret = str2prefix (ip_str, &p);
3800 if (! ret)
3801 {
3802 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3803 return CMD_WARNING;
3804 }
3805#ifdef HAVE_IPV6
3806 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3807 {
3808 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3809 VTY_NEWLINE);
3810 return CMD_WARNING;
3811 }
3812#endif /* HAVE_IPV6 */
3813
3814 apply_mask (&p);
3815
3816 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3817 if (! rn)
3818 {
3819 vty_out (vty, "%% Can't find specified static route configuration.%s",
3820 VTY_NEWLINE);
3821 return CMD_WARNING;
3822 }
3823
3824 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003825
paul718e3742002-12-13 20:15:29 +00003826 /* Update BGP RIB. */
3827 if (! bgp_static->backdoor)
3828 bgp_static_withdraw (bgp, &p, afi, safi);
3829
3830 /* Clear configuration. */
3831 bgp_static_free (bgp_static);
3832 rn->info = NULL;
3833 bgp_unlock_node (rn);
3834 bgp_unlock_node (rn);
3835
3836 return CMD_SUCCESS;
3837}
3838
3839/* Called from bgp_delete(). Delete all static routes from the BGP
3840 instance. */
3841void
3842bgp_static_delete (struct bgp *bgp)
3843{
3844 afi_t afi;
3845 safi_t safi;
3846 struct bgp_node *rn;
3847 struct bgp_node *rm;
3848 struct bgp_table *table;
3849 struct bgp_static *bgp_static;
3850
3851 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3852 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3853 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3854 if (rn->info != NULL)
3855 {
3856 if (safi == SAFI_MPLS_VPN)
3857 {
3858 table = rn->info;
3859
3860 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3861 {
3862 bgp_static = rn->info;
3863 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3864 AFI_IP, SAFI_MPLS_VPN,
3865 (struct prefix_rd *)&rn->p,
3866 bgp_static->tag);
3867 bgp_static_free (bgp_static);
3868 rn->info = NULL;
3869 bgp_unlock_node (rn);
3870 }
3871 }
3872 else
3873 {
3874 bgp_static = rn->info;
3875 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3876 bgp_static_free (bgp_static);
3877 rn->info = NULL;
3878 bgp_unlock_node (rn);
3879 }
3880 }
3881}
3882
3883int
paulfd79ac92004-10-13 05:06:08 +00003884bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3885 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003886{
3887 int ret;
3888 struct prefix p;
3889 struct prefix_rd prd;
3890 struct bgp *bgp;
3891 struct bgp_node *prn;
3892 struct bgp_node *rn;
3893 struct bgp_table *table;
3894 struct bgp_static *bgp_static;
3895 u_char tag[3];
3896
3897 bgp = vty->index;
3898
3899 ret = str2prefix (ip_str, &p);
3900 if (! ret)
3901 {
3902 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3903 return CMD_WARNING;
3904 }
3905 apply_mask (&p);
3906
3907 ret = str2prefix_rd (rd_str, &prd);
3908 if (! ret)
3909 {
3910 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3911 return CMD_WARNING;
3912 }
3913
3914 ret = str2tag (tag_str, tag);
3915 if (! ret)
3916 {
3917 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3918 return CMD_WARNING;
3919 }
3920
3921 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3922 (struct prefix *)&prd);
3923 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003924 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003925 else
3926 bgp_unlock_node (prn);
3927 table = prn->info;
3928
3929 rn = bgp_node_get (table, &p);
3930
3931 if (rn->info)
3932 {
3933 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3934 bgp_unlock_node (rn);
3935 }
3936 else
3937 {
3938 /* New configuration. */
3939 bgp_static = bgp_static_new ();
3940 bgp_static->valid = 1;
3941 memcpy (bgp_static->tag, tag, 3);
3942 rn->info = bgp_static;
3943
3944 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3945 }
3946
3947 return CMD_SUCCESS;
3948}
3949
3950/* Configure static BGP network. */
3951int
paulfd79ac92004-10-13 05:06:08 +00003952bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3953 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003954{
3955 int ret;
3956 struct bgp *bgp;
3957 struct prefix p;
3958 struct prefix_rd prd;
3959 struct bgp_node *prn;
3960 struct bgp_node *rn;
3961 struct bgp_table *table;
3962 struct bgp_static *bgp_static;
3963 u_char tag[3];
3964
3965 bgp = vty->index;
3966
3967 /* Convert IP prefix string to struct prefix. */
3968 ret = str2prefix (ip_str, &p);
3969 if (! ret)
3970 {
3971 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3972 return CMD_WARNING;
3973 }
3974 apply_mask (&p);
3975
3976 ret = str2prefix_rd (rd_str, &prd);
3977 if (! ret)
3978 {
3979 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3980 return CMD_WARNING;
3981 }
3982
3983 ret = str2tag (tag_str, tag);
3984 if (! ret)
3985 {
3986 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3987 return CMD_WARNING;
3988 }
3989
3990 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3991 (struct prefix *)&prd);
3992 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003993 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003994 else
3995 bgp_unlock_node (prn);
3996 table = prn->info;
3997
3998 rn = bgp_node_lookup (table, &p);
3999
4000 if (rn)
4001 {
4002 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4003
4004 bgp_static = rn->info;
4005 bgp_static_free (bgp_static);
4006 rn->info = NULL;
4007 bgp_unlock_node (rn);
4008 bgp_unlock_node (rn);
4009 }
4010 else
4011 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4012
4013 return CMD_SUCCESS;
4014}
David Lamparter6b0655a2014-06-04 06:53:35 +02004015
paul718e3742002-12-13 20:15:29 +00004016DEFUN (bgp_network,
4017 bgp_network_cmd,
4018 "network A.B.C.D/M",
4019 "Specify a network to announce via BGP\n"
4020 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4021{
4022 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004023 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004024}
4025
4026DEFUN (bgp_network_route_map,
4027 bgp_network_route_map_cmd,
4028 "network A.B.C.D/M route-map WORD",
4029 "Specify a network to announce via BGP\n"
4030 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4031 "Route-map to modify the attributes\n"
4032 "Name of the route map\n")
4033{
4034 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004035 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004036}
4037
4038DEFUN (bgp_network_backdoor,
4039 bgp_network_backdoor_cmd,
4040 "network A.B.C.D/M backdoor",
4041 "Specify a network to announce via BGP\n"
4042 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4043 "Specify a BGP backdoor route\n")
4044{
Paul Jakma41367172007-08-06 15:24:51 +00004045 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004046 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004047}
4048
4049DEFUN (bgp_network_mask,
4050 bgp_network_mask_cmd,
4051 "network A.B.C.D mask A.B.C.D",
4052 "Specify a network to announce via BGP\n"
4053 "Network number\n"
4054 "Network mask\n"
4055 "Network mask\n")
4056{
4057 int ret;
4058 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004059
paul718e3742002-12-13 20:15:29 +00004060 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4061 if (! ret)
4062 {
4063 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4064 return CMD_WARNING;
4065 }
4066
4067 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004068 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004069}
4070
4071DEFUN (bgp_network_mask_route_map,
4072 bgp_network_mask_route_map_cmd,
4073 "network A.B.C.D mask A.B.C.D route-map WORD",
4074 "Specify a network to announce via BGP\n"
4075 "Network number\n"
4076 "Network mask\n"
4077 "Network mask\n"
4078 "Route-map to modify the attributes\n"
4079 "Name of the route map\n")
4080{
4081 int ret;
4082 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004083
paul718e3742002-12-13 20:15:29 +00004084 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4085 if (! ret)
4086 {
4087 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4088 return CMD_WARNING;
4089 }
4090
4091 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004092 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004093}
4094
4095DEFUN (bgp_network_mask_backdoor,
4096 bgp_network_mask_backdoor_cmd,
4097 "network A.B.C.D mask A.B.C.D backdoor",
4098 "Specify a network to announce via BGP\n"
4099 "Network number\n"
4100 "Network mask\n"
4101 "Network mask\n"
4102 "Specify a BGP backdoor route\n")
4103{
4104 int ret;
4105 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004106
paul718e3742002-12-13 20:15:29 +00004107 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4108 if (! ret)
4109 {
4110 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4111 return CMD_WARNING;
4112 }
4113
Paul Jakma41367172007-08-06 15:24:51 +00004114 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004115 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004116}
4117
4118DEFUN (bgp_network_mask_natural,
4119 bgp_network_mask_natural_cmd,
4120 "network A.B.C.D",
4121 "Specify a network to announce via BGP\n"
4122 "Network number\n")
4123{
4124 int ret;
4125 char prefix_str[BUFSIZ];
4126
4127 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4128 if (! ret)
4129 {
4130 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4131 return CMD_WARNING;
4132 }
4133
4134 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004135 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004136}
4137
4138DEFUN (bgp_network_mask_natural_route_map,
4139 bgp_network_mask_natural_route_map_cmd,
4140 "network A.B.C.D route-map WORD",
4141 "Specify a network to announce via BGP\n"
4142 "Network number\n"
4143 "Route-map to modify the attributes\n"
4144 "Name of the route map\n")
4145{
4146 int ret;
4147 char prefix_str[BUFSIZ];
4148
4149 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4150 if (! ret)
4151 {
4152 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4153 return CMD_WARNING;
4154 }
4155
4156 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004157 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004158}
4159
4160DEFUN (bgp_network_mask_natural_backdoor,
4161 bgp_network_mask_natural_backdoor_cmd,
4162 "network A.B.C.D backdoor",
4163 "Specify a network to announce via BGP\n"
4164 "Network number\n"
4165 "Specify a BGP backdoor route\n")
4166{
4167 int ret;
4168 char prefix_str[BUFSIZ];
4169
4170 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4171 if (! ret)
4172 {
4173 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4174 return CMD_WARNING;
4175 }
4176
Paul Jakma41367172007-08-06 15:24:51 +00004177 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004178 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004179}
4180
4181DEFUN (no_bgp_network,
4182 no_bgp_network_cmd,
4183 "no network A.B.C.D/M",
4184 NO_STR
4185 "Specify a network to announce via BGP\n"
4186 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4187{
4188 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4189 bgp_node_safi (vty));
4190}
4191
4192ALIAS (no_bgp_network,
4193 no_bgp_network_route_map_cmd,
4194 "no network A.B.C.D/M route-map WORD",
4195 NO_STR
4196 "Specify a network to announce via BGP\n"
4197 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4198 "Route-map to modify the attributes\n"
4199 "Name of the route map\n")
4200
4201ALIAS (no_bgp_network,
4202 no_bgp_network_backdoor_cmd,
4203 "no network A.B.C.D/M backdoor",
4204 NO_STR
4205 "Specify a network to announce via BGP\n"
4206 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4207 "Specify a BGP backdoor route\n")
4208
4209DEFUN (no_bgp_network_mask,
4210 no_bgp_network_mask_cmd,
4211 "no network A.B.C.D mask A.B.C.D",
4212 NO_STR
4213 "Specify a network to announce via BGP\n"
4214 "Network number\n"
4215 "Network mask\n"
4216 "Network mask\n")
4217{
4218 int ret;
4219 char prefix_str[BUFSIZ];
4220
4221 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4222 if (! ret)
4223 {
4224 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4225 return CMD_WARNING;
4226 }
4227
4228 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4229 bgp_node_safi (vty));
4230}
4231
4232ALIAS (no_bgp_network_mask,
4233 no_bgp_network_mask_route_map_cmd,
4234 "no network A.B.C.D mask A.B.C.D route-map WORD",
4235 NO_STR
4236 "Specify a network to announce via BGP\n"
4237 "Network number\n"
4238 "Network mask\n"
4239 "Network mask\n"
4240 "Route-map to modify the attributes\n"
4241 "Name of the route map\n")
4242
4243ALIAS (no_bgp_network_mask,
4244 no_bgp_network_mask_backdoor_cmd,
4245 "no network A.B.C.D mask A.B.C.D backdoor",
4246 NO_STR
4247 "Specify a network to announce via BGP\n"
4248 "Network number\n"
4249 "Network mask\n"
4250 "Network mask\n"
4251 "Specify a BGP backdoor route\n")
4252
4253DEFUN (no_bgp_network_mask_natural,
4254 no_bgp_network_mask_natural_cmd,
4255 "no network A.B.C.D",
4256 NO_STR
4257 "Specify a network to announce via BGP\n"
4258 "Network number\n")
4259{
4260 int ret;
4261 char prefix_str[BUFSIZ];
4262
4263 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4264 if (! ret)
4265 {
4266 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4267 return CMD_WARNING;
4268 }
4269
4270 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4271 bgp_node_safi (vty));
4272}
4273
4274ALIAS (no_bgp_network_mask_natural,
4275 no_bgp_network_mask_natural_route_map_cmd,
4276 "no network A.B.C.D route-map WORD",
4277 NO_STR
4278 "Specify a network to announce via BGP\n"
4279 "Network number\n"
4280 "Route-map to modify the attributes\n"
4281 "Name of the route map\n")
4282
4283ALIAS (no_bgp_network_mask_natural,
4284 no_bgp_network_mask_natural_backdoor_cmd,
4285 "no network A.B.C.D backdoor",
4286 NO_STR
4287 "Specify a network to announce via BGP\n"
4288 "Network number\n"
4289 "Specify a BGP backdoor route\n")
4290
4291#ifdef HAVE_IPV6
4292DEFUN (ipv6_bgp_network,
4293 ipv6_bgp_network_cmd,
4294 "network X:X::X:X/M",
4295 "Specify a network to announce via BGP\n"
4296 "IPv6 prefix <network>/<length>\n")
4297{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304298 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004299 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004300}
4301
4302DEFUN (ipv6_bgp_network_route_map,
4303 ipv6_bgp_network_route_map_cmd,
4304 "network X:X::X:X/M route-map WORD",
4305 "Specify a network to announce via BGP\n"
4306 "IPv6 prefix <network>/<length>\n"
4307 "Route-map to modify the attributes\n"
4308 "Name of the route map\n")
4309{
4310 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004311 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004312}
4313
4314DEFUN (no_ipv6_bgp_network,
4315 no_ipv6_bgp_network_cmd,
4316 "no network X:X::X:X/M",
4317 NO_STR
4318 "Specify a network to announce via BGP\n"
4319 "IPv6 prefix <network>/<length>\n")
4320{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304321 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004322}
4323
4324ALIAS (no_ipv6_bgp_network,
4325 no_ipv6_bgp_network_route_map_cmd,
4326 "no network X:X::X:X/M route-map WORD",
4327 NO_STR
4328 "Specify a network to announce via BGP\n"
4329 "IPv6 prefix <network>/<length>\n"
4330 "Route-map to modify the attributes\n"
4331 "Name of the route map\n")
4332
4333ALIAS (ipv6_bgp_network,
4334 old_ipv6_bgp_network_cmd,
4335 "ipv6 bgp network X:X::X:X/M",
4336 IPV6_STR
4337 BGP_STR
4338 "Specify a network to announce via BGP\n"
4339 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4340
4341ALIAS (no_ipv6_bgp_network,
4342 old_no_ipv6_bgp_network_cmd,
4343 "no ipv6 bgp network X:X::X:X/M",
4344 NO_STR
4345 IPV6_STR
4346 BGP_STR
4347 "Specify a network to announce via BGP\n"
4348 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4349#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004350
4351/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4352ALIAS_DEPRECATED (bgp_network,
4353 bgp_network_ttl_cmd,
4354 "network A.B.C.D/M pathlimit <0-255>",
4355 "Specify a network to announce via BGP\n"
4356 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4357 "AS-Path hopcount limit attribute\n"
4358 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4359ALIAS_DEPRECATED (bgp_network_backdoor,
4360 bgp_network_backdoor_ttl_cmd,
4361 "network A.B.C.D/M backdoor pathlimit <0-255>",
4362 "Specify a network to announce via BGP\n"
4363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4364 "Specify a BGP backdoor route\n"
4365 "AS-Path hopcount limit attribute\n"
4366 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4367ALIAS_DEPRECATED (bgp_network_mask,
4368 bgp_network_mask_ttl_cmd,
4369 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4370 "Specify a network to announce via BGP\n"
4371 "Network number\n"
4372 "Network mask\n"
4373 "Network mask\n"
4374 "AS-Path hopcount limit attribute\n"
4375 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4376ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4377 bgp_network_mask_backdoor_ttl_cmd,
4378 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4379 "Specify a network to announce via BGP\n"
4380 "Network number\n"
4381 "Network mask\n"
4382 "Network mask\n"
4383 "Specify a BGP backdoor route\n"
4384 "AS-Path hopcount limit attribute\n"
4385 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4386ALIAS_DEPRECATED (bgp_network_mask_natural,
4387 bgp_network_mask_natural_ttl_cmd,
4388 "network A.B.C.D pathlimit <0-255>",
4389 "Specify a network to announce via BGP\n"
4390 "Network number\n"
4391 "AS-Path hopcount limit attribute\n"
4392 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4393ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4394 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004395 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004396 "Specify a network to announce via BGP\n"
4397 "Network number\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,
4402 no_bgp_network_ttl_cmd,
4403 "no network A.B.C.D/M pathlimit <0-255>",
4404 NO_STR
4405 "Specify a network to announce via BGP\n"
4406 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (no_bgp_network,
4410 no_bgp_network_backdoor_ttl_cmd,
4411 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\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")
4418ALIAS_DEPRECATED (no_bgp_network,
4419 no_bgp_network_mask_ttl_cmd,
4420 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4421 NO_STR
4422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "Network mask\n"
4425 "Network mask\n"
4426 "AS-Path hopcount limit attribute\n"
4427 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4428ALIAS_DEPRECATED (no_bgp_network_mask,
4429 no_bgp_network_mask_backdoor_ttl_cmd,
4430 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4431 NO_STR
4432 "Specify a network to announce via BGP\n"
4433 "Network number\n"
4434 "Network mask\n"
4435 "Network mask\n"
4436 "Specify a BGP backdoor route\n"
4437 "AS-Path hopcount limit attribute\n"
4438 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4439ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4440 no_bgp_network_mask_natural_ttl_cmd,
4441 "no network A.B.C.D pathlimit <0-255>",
4442 NO_STR
4443 "Specify a network to announce via BGP\n"
4444 "Network number\n"
4445 "AS-Path hopcount limit attribute\n"
4446 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4447ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4448 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4449 "no network A.B.C.D backdoor pathlimit <0-255>",
4450 NO_STR
4451 "Specify a network to announce via BGP\n"
4452 "Network number\n"
4453 "Specify a BGP backdoor route\n"
4454 "AS-Path hopcount limit attribute\n"
4455 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004456#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004457ALIAS_DEPRECATED (ipv6_bgp_network,
4458 ipv6_bgp_network_ttl_cmd,
4459 "network X:X::X:X/M pathlimit <0-255>",
4460 "Specify a network to announce via BGP\n"
4461 "IPv6 prefix <network>/<length>\n"
4462 "AS-Path hopcount limit attribute\n"
4463 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4464ALIAS_DEPRECATED (no_ipv6_bgp_network,
4465 no_ipv6_bgp_network_ttl_cmd,
4466 "no network X:X::X:X/M pathlimit <0-255>",
4467 NO_STR
4468 "Specify a network to announce via BGP\n"
4469 "IPv6 prefix <network>/<length>\n"
4470 "AS-Path hopcount limit attribute\n"
4471 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004472#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004473
paul718e3742002-12-13 20:15:29 +00004474/* Aggreagete address:
4475
4476 advertise-map Set condition to advertise attribute
4477 as-set Generate AS set path information
4478 attribute-map Set attributes of aggregate
4479 route-map Set parameters of aggregate
4480 summary-only Filter more specific routes from updates
4481 suppress-map Conditionally filter more specific routes from updates
4482 <cr>
4483 */
4484struct bgp_aggregate
4485{
4486 /* Summary-only flag. */
4487 u_char summary_only;
4488
4489 /* AS set generation. */
4490 u_char as_set;
4491
4492 /* Route-map for aggregated route. */
4493 struct route_map *map;
4494
4495 /* Suppress-count. */
4496 unsigned long count;
4497
4498 /* SAFI configuration. */
4499 safi_t safi;
4500};
4501
paul94f2b392005-06-28 12:44:16 +00004502static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004503bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004504{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004505 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004506}
4507
paul94f2b392005-06-28 12:44:16 +00004508static void
paul718e3742002-12-13 20:15:29 +00004509bgp_aggregate_free (struct bgp_aggregate *aggregate)
4510{
4511 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4512}
4513
paul94f2b392005-06-28 12:44:16 +00004514static void
paul718e3742002-12-13 20:15:29 +00004515bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4516 afi_t afi, safi_t safi, struct bgp_info *del,
4517 struct bgp_aggregate *aggregate)
4518{
4519 struct bgp_table *table;
4520 struct bgp_node *top;
4521 struct bgp_node *rn;
4522 u_char origin;
4523 struct aspath *aspath = NULL;
4524 struct aspath *asmerge = NULL;
4525 struct community *community = NULL;
4526 struct community *commerge = NULL;
4527 struct in_addr nexthop;
4528 u_int32_t med = 0;
4529 struct bgp_info *ri;
4530 struct bgp_info *new;
4531 int first = 1;
4532 unsigned long match = 0;
4533
4534 /* Record adding route's nexthop and med. */
4535 if (rinew)
4536 {
4537 nexthop = rinew->attr->nexthop;
4538 med = rinew->attr->med;
4539 }
4540
4541 /* ORIGIN attribute: If at least one route among routes that are
4542 aggregated has ORIGIN with the value INCOMPLETE, then the
4543 aggregated route must have the ORIGIN attribute with the value
4544 INCOMPLETE. Otherwise, if at least one route among routes that
4545 are aggregated has ORIGIN with the value EGP, then the aggregated
4546 route must have the origin attribute with the value EGP. In all
4547 other case the value of the ORIGIN attribute of the aggregated
4548 route is INTERNAL. */
4549 origin = BGP_ORIGIN_IGP;
4550
4551 table = bgp->rib[afi][safi];
4552
4553 top = bgp_node_get (table, p);
4554 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4555 if (rn->p.prefixlen > p->prefixlen)
4556 {
4557 match = 0;
4558
4559 for (ri = rn->info; ri; ri = ri->next)
4560 {
4561 if (BGP_INFO_HOLDDOWN (ri))
4562 continue;
4563
4564 if (del && ri == del)
4565 continue;
4566
4567 if (! rinew && first)
4568 {
4569 nexthop = ri->attr->nexthop;
4570 med = ri->attr->med;
4571 first = 0;
4572 }
4573
4574#ifdef AGGREGATE_NEXTHOP_CHECK
4575 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4576 || ri->attr->med != med)
4577 {
4578 if (aspath)
4579 aspath_free (aspath);
4580 if (community)
4581 community_free (community);
4582 bgp_unlock_node (rn);
4583 bgp_unlock_node (top);
4584 return;
4585 }
4586#endif /* AGGREGATE_NEXTHOP_CHECK */
4587
4588 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4589 {
4590 if (aggregate->summary_only)
4591 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004592 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004593 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004594 match++;
4595 }
4596
4597 aggregate->count++;
4598
4599 if (aggregate->as_set)
4600 {
4601 if (origin < ri->attr->origin)
4602 origin = ri->attr->origin;
4603
4604 if (aspath)
4605 {
4606 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4607 aspath_free (aspath);
4608 aspath = asmerge;
4609 }
4610 else
4611 aspath = aspath_dup (ri->attr->aspath);
4612
4613 if (ri->attr->community)
4614 {
4615 if (community)
4616 {
4617 commerge = community_merge (community,
4618 ri->attr->community);
4619 community = community_uniq_sort (commerge);
4620 community_free (commerge);
4621 }
4622 else
4623 community = community_dup (ri->attr->community);
4624 }
4625 }
4626 }
4627 }
4628 if (match)
4629 bgp_process (bgp, rn, afi, safi);
4630 }
4631 bgp_unlock_node (top);
4632
4633 if (rinew)
4634 {
4635 aggregate->count++;
4636
4637 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004638 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004639
4640 if (aggregate->as_set)
4641 {
4642 if (origin < rinew->attr->origin)
4643 origin = rinew->attr->origin;
4644
4645 if (aspath)
4646 {
4647 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4648 aspath_free (aspath);
4649 aspath = asmerge;
4650 }
4651 else
4652 aspath = aspath_dup (rinew->attr->aspath);
4653
4654 if (rinew->attr->community)
4655 {
4656 if (community)
4657 {
4658 commerge = community_merge (community,
4659 rinew->attr->community);
4660 community = community_uniq_sort (commerge);
4661 community_free (commerge);
4662 }
4663 else
4664 community = community_dup (rinew->attr->community);
4665 }
4666 }
4667 }
4668
4669 if (aggregate->count > 0)
4670 {
4671 rn = bgp_node_get (table, p);
4672 new = bgp_info_new ();
4673 new->type = ZEBRA_ROUTE_BGP;
4674 new->sub_type = BGP_ROUTE_AGGREGATE;
4675 new->peer = bgp->peer_self;
4676 SET_FLAG (new->flags, BGP_INFO_VALID);
4677 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004678 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004679
4680 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004681 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004682 bgp_process (bgp, rn, afi, safi);
4683 }
4684 else
4685 {
4686 if (aspath)
4687 aspath_free (aspath);
4688 if (community)
4689 community_free (community);
4690 }
4691}
4692
4693void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4694 struct bgp_aggregate *);
4695
4696void
4697bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4698 struct bgp_info *ri, afi_t afi, safi_t safi)
4699{
4700 struct bgp_node *child;
4701 struct bgp_node *rn;
4702 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004703 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004704
4705 /* MPLS-VPN aggregation is not yet supported. */
4706 if (safi == SAFI_MPLS_VPN)
4707 return;
4708
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004709 table = bgp->aggregate[afi][safi];
4710
4711 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004712 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004713 return;
4714
paul718e3742002-12-13 20:15:29 +00004715 if (p->prefixlen == 0)
4716 return;
4717
4718 if (BGP_INFO_HOLDDOWN (ri))
4719 return;
4720
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004721 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004722
4723 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004724 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004725 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4726 {
4727 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004728 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004729 }
4730 bgp_unlock_node (child);
4731}
4732
4733void
4734bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4735 struct bgp_info *del, afi_t afi, safi_t safi)
4736{
4737 struct bgp_node *child;
4738 struct bgp_node *rn;
4739 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004740 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004741
4742 /* MPLS-VPN aggregation is not yet supported. */
4743 if (safi == SAFI_MPLS_VPN)
4744 return;
4745
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004746 table = bgp->aggregate[afi][safi];
4747
4748 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004749 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004750 return;
4751
paul718e3742002-12-13 20:15:29 +00004752 if (p->prefixlen == 0)
4753 return;
4754
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004755 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004756
4757 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004758 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004759 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4760 {
4761 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004762 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004763 }
4764 bgp_unlock_node (child);
4765}
4766
paul94f2b392005-06-28 12:44:16 +00004767static void
paul718e3742002-12-13 20:15:29 +00004768bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4769 struct bgp_aggregate *aggregate)
4770{
4771 struct bgp_table *table;
4772 struct bgp_node *top;
4773 struct bgp_node *rn;
4774 struct bgp_info *new;
4775 struct bgp_info *ri;
4776 unsigned long match;
4777 u_char origin = BGP_ORIGIN_IGP;
4778 struct aspath *aspath = NULL;
4779 struct aspath *asmerge = NULL;
4780 struct community *community = NULL;
4781 struct community *commerge = NULL;
4782
4783 table = bgp->rib[afi][safi];
4784
4785 /* Sanity check. */
4786 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4787 return;
4788 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4789 return;
4790
4791 /* If routes exists below this node, generate aggregate routes. */
4792 top = bgp_node_get (table, p);
4793 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4794 if (rn->p.prefixlen > p->prefixlen)
4795 {
4796 match = 0;
4797
4798 for (ri = rn->info; ri; ri = ri->next)
4799 {
4800 if (BGP_INFO_HOLDDOWN (ri))
4801 continue;
4802
4803 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4804 {
4805 /* summary-only aggregate route suppress aggregated
4806 route announcement. */
4807 if (aggregate->summary_only)
4808 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004809 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004810 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004811 match++;
4812 }
4813 /* as-set aggregate route generate origin, as path,
4814 community aggregation. */
4815 if (aggregate->as_set)
4816 {
4817 if (origin < ri->attr->origin)
4818 origin = ri->attr->origin;
4819
4820 if (aspath)
4821 {
4822 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4823 aspath_free (aspath);
4824 aspath = asmerge;
4825 }
4826 else
4827 aspath = aspath_dup (ri->attr->aspath);
4828
4829 if (ri->attr->community)
4830 {
4831 if (community)
4832 {
4833 commerge = community_merge (community,
4834 ri->attr->community);
4835 community = community_uniq_sort (commerge);
4836 community_free (commerge);
4837 }
4838 else
4839 community = community_dup (ri->attr->community);
4840 }
4841 }
4842 aggregate->count++;
4843 }
4844 }
4845
4846 /* If this node is suppressed, process the change. */
4847 if (match)
4848 bgp_process (bgp, rn, afi, safi);
4849 }
4850 bgp_unlock_node (top);
4851
4852 /* Add aggregate route to BGP table. */
4853 if (aggregate->count)
4854 {
4855 rn = bgp_node_get (table, p);
4856
4857 new = bgp_info_new ();
4858 new->type = ZEBRA_ROUTE_BGP;
4859 new->sub_type = BGP_ROUTE_AGGREGATE;
4860 new->peer = bgp->peer_self;
4861 SET_FLAG (new->flags, BGP_INFO_VALID);
4862 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004863 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004864
4865 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004866 bgp_unlock_node (rn);
4867
paul718e3742002-12-13 20:15:29 +00004868 /* Process change. */
4869 bgp_process (bgp, rn, afi, safi);
4870 }
4871}
4872
4873void
4874bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4875 safi_t safi, struct bgp_aggregate *aggregate)
4876{
4877 struct bgp_table *table;
4878 struct bgp_node *top;
4879 struct bgp_node *rn;
4880 struct bgp_info *ri;
4881 unsigned long match;
4882
4883 table = bgp->rib[afi][safi];
4884
4885 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4886 return;
4887 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4888 return;
4889
4890 /* If routes exists below this node, generate aggregate routes. */
4891 top = bgp_node_get (table, p);
4892 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4893 if (rn->p.prefixlen > p->prefixlen)
4894 {
4895 match = 0;
4896
4897 for (ri = rn->info; ri; ri = ri->next)
4898 {
4899 if (BGP_INFO_HOLDDOWN (ri))
4900 continue;
4901
4902 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4903 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004904 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004905 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004906 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004907
Paul Jakmafb982c22007-05-04 20:15:47 +00004908 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004909 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004910 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004911 match++;
4912 }
4913 }
4914 aggregate->count--;
4915 }
4916 }
4917
Paul Jakmafb982c22007-05-04 20:15:47 +00004918 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004919 if (match)
4920 bgp_process (bgp, rn, afi, safi);
4921 }
4922 bgp_unlock_node (top);
4923
4924 /* Delete aggregate route from BGP table. */
4925 rn = bgp_node_get (table, p);
4926
4927 for (ri = rn->info; ri; ri = ri->next)
4928 if (ri->peer == bgp->peer_self
4929 && ri->type == ZEBRA_ROUTE_BGP
4930 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4931 break;
4932
4933 /* Withdraw static BGP route from routing table. */
4934 if (ri)
4935 {
paul718e3742002-12-13 20:15:29 +00004936 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004937 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004938 }
4939
4940 /* Unlock bgp_node_lookup. */
4941 bgp_unlock_node (rn);
4942}
4943
4944/* Aggregate route attribute. */
4945#define AGGREGATE_SUMMARY_ONLY 1
4946#define AGGREGATE_AS_SET 1
4947
paul94f2b392005-06-28 12:44:16 +00004948static int
Robert Baysf6269b42010-08-05 10:26:28 -07004949bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4950 afi_t afi, safi_t safi)
4951{
4952 int ret;
4953 struct prefix p;
4954 struct bgp_node *rn;
4955 struct bgp *bgp;
4956 struct bgp_aggregate *aggregate;
4957
4958 /* Convert string to prefix structure. */
4959 ret = str2prefix (prefix_str, &p);
4960 if (!ret)
4961 {
4962 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4963 return CMD_WARNING;
4964 }
4965 apply_mask (&p);
4966
4967 /* Get BGP structure. */
4968 bgp = vty->index;
4969
4970 /* Old configuration check. */
4971 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4972 if (! rn)
4973 {
4974 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4975 VTY_NEWLINE);
4976 return CMD_WARNING;
4977 }
4978
4979 aggregate = rn->info;
4980 if (aggregate->safi & SAFI_UNICAST)
4981 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4982 if (aggregate->safi & SAFI_MULTICAST)
4983 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4984
4985 /* Unlock aggregate address configuration. */
4986 rn->info = NULL;
4987 bgp_aggregate_free (aggregate);
4988 bgp_unlock_node (rn);
4989 bgp_unlock_node (rn);
4990
4991 return CMD_SUCCESS;
4992}
4993
4994static int
4995bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004996 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004997 u_char summary_only, u_char as_set)
4998{
4999 int ret;
5000 struct prefix p;
5001 struct bgp_node *rn;
5002 struct bgp *bgp;
5003 struct bgp_aggregate *aggregate;
5004
5005 /* Convert string to prefix structure. */
5006 ret = str2prefix (prefix_str, &p);
5007 if (!ret)
5008 {
5009 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5010 return CMD_WARNING;
5011 }
5012 apply_mask (&p);
5013
5014 /* Get BGP structure. */
5015 bgp = vty->index;
5016
5017 /* Old configuration check. */
5018 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5019
5020 if (rn->info)
5021 {
5022 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005023 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005024 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5025 if (ret)
5026 {
Robert Bays368473f2010-08-05 10:26:29 -07005027 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5028 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005029 return CMD_WARNING;
5030 }
paul718e3742002-12-13 20:15:29 +00005031 }
5032
5033 /* Make aggregate address structure. */
5034 aggregate = bgp_aggregate_new ();
5035 aggregate->summary_only = summary_only;
5036 aggregate->as_set = as_set;
5037 aggregate->safi = safi;
5038 rn->info = aggregate;
5039
5040 /* Aggregate address insert into BGP routing table. */
5041 if (safi & SAFI_UNICAST)
5042 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5043 if (safi & SAFI_MULTICAST)
5044 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5045
5046 return CMD_SUCCESS;
5047}
5048
paul718e3742002-12-13 20:15:29 +00005049DEFUN (aggregate_address,
5050 aggregate_address_cmd,
5051 "aggregate-address A.B.C.D/M",
5052 "Configure BGP aggregate entries\n"
5053 "Aggregate prefix\n")
5054{
5055 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5056}
5057
5058DEFUN (aggregate_address_mask,
5059 aggregate_address_mask_cmd,
5060 "aggregate-address A.B.C.D A.B.C.D",
5061 "Configure BGP aggregate entries\n"
5062 "Aggregate address\n"
5063 "Aggregate mask\n")
5064{
5065 int ret;
5066 char prefix_str[BUFSIZ];
5067
5068 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5069
5070 if (! ret)
5071 {
5072 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5073 return CMD_WARNING;
5074 }
5075
5076 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5077 0, 0);
5078}
5079
5080DEFUN (aggregate_address_summary_only,
5081 aggregate_address_summary_only_cmd,
5082 "aggregate-address A.B.C.D/M summary-only",
5083 "Configure BGP aggregate entries\n"
5084 "Aggregate prefix\n"
5085 "Filter more specific routes from updates\n")
5086{
5087 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5088 AGGREGATE_SUMMARY_ONLY, 0);
5089}
5090
5091DEFUN (aggregate_address_mask_summary_only,
5092 aggregate_address_mask_summary_only_cmd,
5093 "aggregate-address A.B.C.D A.B.C.D summary-only",
5094 "Configure BGP aggregate entries\n"
5095 "Aggregate address\n"
5096 "Aggregate mask\n"
5097 "Filter more specific routes from updates\n")
5098{
5099 int ret;
5100 char prefix_str[BUFSIZ];
5101
5102 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5103
5104 if (! ret)
5105 {
5106 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5107 return CMD_WARNING;
5108 }
5109
5110 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5111 AGGREGATE_SUMMARY_ONLY, 0);
5112}
5113
5114DEFUN (aggregate_address_as_set,
5115 aggregate_address_as_set_cmd,
5116 "aggregate-address A.B.C.D/M as-set",
5117 "Configure BGP aggregate entries\n"
5118 "Aggregate prefix\n"
5119 "Generate AS set path information\n")
5120{
5121 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5122 0, AGGREGATE_AS_SET);
5123}
5124
5125DEFUN (aggregate_address_mask_as_set,
5126 aggregate_address_mask_as_set_cmd,
5127 "aggregate-address A.B.C.D A.B.C.D as-set",
5128 "Configure BGP aggregate entries\n"
5129 "Aggregate address\n"
5130 "Aggregate mask\n"
5131 "Generate AS set path information\n")
5132{
5133 int ret;
5134 char prefix_str[BUFSIZ];
5135
5136 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5137
5138 if (! ret)
5139 {
5140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5141 return CMD_WARNING;
5142 }
5143
5144 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5145 0, AGGREGATE_AS_SET);
5146}
5147
5148
5149DEFUN (aggregate_address_as_set_summary,
5150 aggregate_address_as_set_summary_cmd,
5151 "aggregate-address A.B.C.D/M as-set summary-only",
5152 "Configure BGP aggregate entries\n"
5153 "Aggregate prefix\n"
5154 "Generate AS set path information\n"
5155 "Filter more specific routes from updates\n")
5156{
5157 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5158 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5159}
5160
5161ALIAS (aggregate_address_as_set_summary,
5162 aggregate_address_summary_as_set_cmd,
5163 "aggregate-address A.B.C.D/M summary-only as-set",
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate prefix\n"
5166 "Filter more specific routes from updates\n"
5167 "Generate AS set path information\n")
5168
5169DEFUN (aggregate_address_mask_as_set_summary,
5170 aggregate_address_mask_as_set_summary_cmd,
5171 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5172 "Configure BGP aggregate entries\n"
5173 "Aggregate address\n"
5174 "Aggregate mask\n"
5175 "Generate AS set path information\n"
5176 "Filter more specific routes from updates\n")
5177{
5178 int ret;
5179 char prefix_str[BUFSIZ];
5180
5181 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5182
5183 if (! ret)
5184 {
5185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5186 return CMD_WARNING;
5187 }
5188
5189 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5190 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5191}
5192
5193ALIAS (aggregate_address_mask_as_set_summary,
5194 aggregate_address_mask_summary_as_set_cmd,
5195 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5196 "Configure BGP aggregate entries\n"
5197 "Aggregate address\n"
5198 "Aggregate mask\n"
5199 "Filter more specific routes from updates\n"
5200 "Generate AS set path information\n")
5201
5202DEFUN (no_aggregate_address,
5203 no_aggregate_address_cmd,
5204 "no aggregate-address A.B.C.D/M",
5205 NO_STR
5206 "Configure BGP aggregate entries\n"
5207 "Aggregate prefix\n")
5208{
5209 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5210}
5211
5212ALIAS (no_aggregate_address,
5213 no_aggregate_address_summary_only_cmd,
5214 "no aggregate-address A.B.C.D/M summary-only",
5215 NO_STR
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate prefix\n"
5218 "Filter more specific routes from updates\n")
5219
5220ALIAS (no_aggregate_address,
5221 no_aggregate_address_as_set_cmd,
5222 "no aggregate-address A.B.C.D/M as-set",
5223 NO_STR
5224 "Configure BGP aggregate entries\n"
5225 "Aggregate prefix\n"
5226 "Generate AS set path information\n")
5227
5228ALIAS (no_aggregate_address,
5229 no_aggregate_address_as_set_summary_cmd,
5230 "no aggregate-address A.B.C.D/M as-set summary-only",
5231 NO_STR
5232 "Configure BGP aggregate entries\n"
5233 "Aggregate prefix\n"
5234 "Generate AS set path information\n"
5235 "Filter more specific routes from updates\n")
5236
5237ALIAS (no_aggregate_address,
5238 no_aggregate_address_summary_as_set_cmd,
5239 "no aggregate-address A.B.C.D/M summary-only as-set",
5240 NO_STR
5241 "Configure BGP aggregate entries\n"
5242 "Aggregate prefix\n"
5243 "Filter more specific routes from updates\n"
5244 "Generate AS set path information\n")
5245
5246DEFUN (no_aggregate_address_mask,
5247 no_aggregate_address_mask_cmd,
5248 "no aggregate-address A.B.C.D A.B.C.D",
5249 NO_STR
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate address\n"
5252 "Aggregate mask\n")
5253{
5254 int ret;
5255 char prefix_str[BUFSIZ];
5256
5257 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5258
5259 if (! ret)
5260 {
5261 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5262 return CMD_WARNING;
5263 }
5264
5265 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5266}
5267
5268ALIAS (no_aggregate_address_mask,
5269 no_aggregate_address_mask_summary_only_cmd,
5270 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5271 NO_STR
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate address\n"
5274 "Aggregate mask\n"
5275 "Filter more specific routes from updates\n")
5276
5277ALIAS (no_aggregate_address_mask,
5278 no_aggregate_address_mask_as_set_cmd,
5279 "no aggregate-address A.B.C.D A.B.C.D as-set",
5280 NO_STR
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate address\n"
5283 "Aggregate mask\n"
5284 "Generate AS set path information\n")
5285
5286ALIAS (no_aggregate_address_mask,
5287 no_aggregate_address_mask_as_set_summary_cmd,
5288 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5289 NO_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate address\n"
5292 "Aggregate mask\n"
5293 "Generate AS set path information\n"
5294 "Filter more specific routes from updates\n")
5295
5296ALIAS (no_aggregate_address_mask,
5297 no_aggregate_address_mask_summary_as_set_cmd,
5298 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5299 NO_STR
5300 "Configure BGP aggregate entries\n"
5301 "Aggregate address\n"
5302 "Aggregate mask\n"
5303 "Filter more specific routes from updates\n"
5304 "Generate AS set path information\n")
5305
5306#ifdef HAVE_IPV6
5307DEFUN (ipv6_aggregate_address,
5308 ipv6_aggregate_address_cmd,
5309 "aggregate-address X:X::X:X/M",
5310 "Configure BGP aggregate entries\n"
5311 "Aggregate prefix\n")
5312{
5313 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5314}
5315
5316DEFUN (ipv6_aggregate_address_summary_only,
5317 ipv6_aggregate_address_summary_only_cmd,
5318 "aggregate-address X:X::X:X/M summary-only",
5319 "Configure BGP aggregate entries\n"
5320 "Aggregate prefix\n"
5321 "Filter more specific routes from updates\n")
5322{
5323 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5324 AGGREGATE_SUMMARY_ONLY, 0);
5325}
5326
5327DEFUN (no_ipv6_aggregate_address,
5328 no_ipv6_aggregate_address_cmd,
5329 "no aggregate-address X:X::X:X/M",
5330 NO_STR
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate prefix\n")
5333{
5334 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5335}
5336
5337DEFUN (no_ipv6_aggregate_address_summary_only,
5338 no_ipv6_aggregate_address_summary_only_cmd,
5339 "no aggregate-address X:X::X:X/M summary-only",
5340 NO_STR
5341 "Configure BGP aggregate entries\n"
5342 "Aggregate prefix\n"
5343 "Filter more specific routes from updates\n")
5344{
5345 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5346}
5347
5348ALIAS (ipv6_aggregate_address,
5349 old_ipv6_aggregate_address_cmd,
5350 "ipv6 bgp aggregate-address X:X::X:X/M",
5351 IPV6_STR
5352 BGP_STR
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n")
5355
5356ALIAS (ipv6_aggregate_address_summary_only,
5357 old_ipv6_aggregate_address_summary_only_cmd,
5358 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5359 IPV6_STR
5360 BGP_STR
5361 "Configure BGP aggregate entries\n"
5362 "Aggregate prefix\n"
5363 "Filter more specific routes from updates\n")
5364
5365ALIAS (no_ipv6_aggregate_address,
5366 old_no_ipv6_aggregate_address_cmd,
5367 "no ipv6 bgp aggregate-address X:X::X:X/M",
5368 NO_STR
5369 IPV6_STR
5370 BGP_STR
5371 "Configure BGP aggregate entries\n"
5372 "Aggregate prefix\n")
5373
5374ALIAS (no_ipv6_aggregate_address_summary_only,
5375 old_no_ipv6_aggregate_address_summary_only_cmd,
5376 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5377 NO_STR
5378 IPV6_STR
5379 BGP_STR
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n"
5382 "Filter more specific routes from updates\n")
5383#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005384
paul718e3742002-12-13 20:15:29 +00005385/* Redistribute route treatment. */
5386void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005387bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5388 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005389 u_int32_t metric, u_char type)
5390{
5391 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005392 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005393 struct bgp_info *new;
5394 struct bgp_info *bi;
5395 struct bgp_info info;
5396 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005397 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005398 struct attr *new_attr;
5399 afi_t afi;
5400 int ret;
5401
5402 /* Make default attribute. */
5403 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5404 if (nexthop)
5405 attr.nexthop = *nexthop;
5406
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005407#ifdef HAVE_IPV6
5408 if (nexthop6)
5409 {
5410 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5411 extra->mp_nexthop_global = *nexthop6;
5412 extra->mp_nexthop_len = 16;
5413 }
5414#endif
5415
paul718e3742002-12-13 20:15:29 +00005416 attr.med = metric;
5417 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5418
paul1eb8ef22005-04-07 07:30:20 +00005419 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005420 {
5421 afi = family2afi (p->family);
5422
5423 if (bgp->redist[afi][type])
5424 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005425 struct attr attr_new;
5426 struct attr_extra extra_new;
5427
paul718e3742002-12-13 20:15:29 +00005428 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005429 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005430 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005431
5432 if (bgp->redist_metric_flag[afi][type])
5433 attr_new.med = bgp->redist_metric[afi][type];
5434
5435 /* Apply route-map. */
5436 if (bgp->rmap[afi][type].map)
5437 {
5438 info.peer = bgp->peer_self;
5439 info.attr = &attr_new;
5440
paulfee0f4c2004-09-13 05:12:46 +00005441 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5442
paul718e3742002-12-13 20:15:29 +00005443 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5444 &info);
paulfee0f4c2004-09-13 05:12:46 +00005445
5446 bgp->peer_self->rmap_type = 0;
5447
paul718e3742002-12-13 20:15:29 +00005448 if (ret == RMAP_DENYMATCH)
5449 {
5450 /* Free uninterned attribute. */
5451 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005452
paul718e3742002-12-13 20:15:29 +00005453 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005454 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005455 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005456 bgp_redistribute_delete (p, type);
5457 return;
5458 }
5459 }
5460
Paul Jakmafb982c22007-05-04 20:15:47 +00005461 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5462 afi, SAFI_UNICAST, p, NULL);
5463
paul718e3742002-12-13 20:15:29 +00005464 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005465
paul718e3742002-12-13 20:15:29 +00005466 for (bi = bn->info; bi; bi = bi->next)
5467 if (bi->peer == bgp->peer_self
5468 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5469 break;
5470
5471 if (bi)
5472 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005473 if (attrhash_cmp (bi->attr, new_attr) &&
5474 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005475 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005476 bgp_attr_unintern (&new_attr);
5477 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005478 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005479 bgp_unlock_node (bn);
5480 return;
5481 }
5482 else
5483 {
5484 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005485 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005486
5487 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005488 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5489 bgp_info_restore(bn, bi);
5490 else
5491 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005492 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005493 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005494 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005495
5496 /* Process change. */
5497 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5498 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5499 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005500 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005501 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005502 return;
5503 }
5504 }
5505
5506 new = bgp_info_new ();
5507 new->type = type;
5508 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5509 new->peer = bgp->peer_self;
5510 SET_FLAG (new->flags, BGP_INFO_VALID);
5511 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005512 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005513
5514 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5515 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005516 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005517 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5518 }
5519 }
5520
5521 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005522 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005523 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005524}
5525
5526void
5527bgp_redistribute_delete (struct prefix *p, u_char type)
5528{
5529 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005530 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005531 afi_t afi;
5532 struct bgp_node *rn;
5533 struct bgp_info *ri;
5534
paul1eb8ef22005-04-07 07:30:20 +00005535 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005536 {
5537 afi = family2afi (p->family);
5538
5539 if (bgp->redist[afi][type])
5540 {
paulfee0f4c2004-09-13 05:12:46 +00005541 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005542
5543 for (ri = rn->info; ri; ri = ri->next)
5544 if (ri->peer == bgp->peer_self
5545 && ri->type == type)
5546 break;
5547
5548 if (ri)
5549 {
5550 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005551 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005552 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005553 }
5554 bgp_unlock_node (rn);
5555 }
5556 }
5557}
5558
5559/* Withdraw specified route type's route. */
5560void
5561bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5562{
5563 struct bgp_node *rn;
5564 struct bgp_info *ri;
5565 struct bgp_table *table;
5566
5567 table = bgp->rib[afi][SAFI_UNICAST];
5568
5569 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5570 {
5571 for (ri = rn->info; ri; ri = ri->next)
5572 if (ri->peer == bgp->peer_self
5573 && ri->type == type)
5574 break;
5575
5576 if (ri)
5577 {
5578 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005579 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005580 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005581 }
5582 }
5583}
David Lamparter6b0655a2014-06-04 06:53:35 +02005584
paul718e3742002-12-13 20:15:29 +00005585/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005586static void
paul718e3742002-12-13 20:15:29 +00005587route_vty_out_route (struct prefix *p, struct vty *vty)
5588{
5589 int len;
5590 u_int32_t destination;
5591 char buf[BUFSIZ];
5592
5593 if (p->family == AF_INET)
5594 {
5595 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5596 destination = ntohl (p->u.prefix4.s_addr);
5597
5598 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5599 || (IN_CLASSB (destination) && p->prefixlen == 16)
5600 || (IN_CLASSA (destination) && p->prefixlen == 8)
5601 || p->u.prefix4.s_addr == 0)
5602 {
5603 /* When mask is natural, mask is not displayed. */
5604 }
5605 else
5606 len += vty_out (vty, "/%d", p->prefixlen);
5607 }
5608 else
5609 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5610 p->prefixlen);
5611
5612 len = 17 - len;
5613 if (len < 1)
5614 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5615 else
5616 vty_out (vty, "%*s", len, " ");
5617}
5618
paul718e3742002-12-13 20:15:29 +00005619enum bgp_display_type
5620{
5621 normal_list,
5622};
5623
paulb40d9392005-08-22 22:34:41 +00005624/* Print the short form route status for a bgp_info */
5625static void
5626route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005627{
paulb40d9392005-08-22 22:34:41 +00005628 /* Route status display. */
5629 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5630 vty_out (vty, "R");
5631 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005632 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005633 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005634 vty_out (vty, "s");
5635 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5636 vty_out (vty, "*");
5637 else
5638 vty_out (vty, " ");
5639
5640 /* Selected */
5641 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5642 vty_out (vty, "h");
5643 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5644 vty_out (vty, "d");
5645 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5646 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005647 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5648 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005649 else
5650 vty_out (vty, " ");
5651
5652 /* Internal route. */
5653 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5654 vty_out (vty, "i");
5655 else
paulb40d9392005-08-22 22:34:41 +00005656 vty_out (vty, " ");
5657}
5658
5659/* called from terminal list command */
5660void
5661route_vty_out (struct vty *vty, struct prefix *p,
5662 struct bgp_info *binfo, int display, safi_t safi)
5663{
5664 struct attr *attr;
5665
5666 /* short status lead text */
5667 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005668
5669 /* print prefix and mask */
5670 if (! display)
5671 route_vty_out_route (p, vty);
5672 else
5673 vty_out (vty, "%*s", 17, " ");
5674
5675 /* Print attribute */
5676 attr = binfo->attr;
5677 if (attr)
5678 {
5679 if (p->family == AF_INET)
5680 {
5681 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005682 vty_out (vty, "%-16s",
5683 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005684 else
5685 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5686 }
5687#ifdef HAVE_IPV6
5688 else if (p->family == AF_INET6)
5689 {
5690 int len;
5691 char buf[BUFSIZ];
5692
5693 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005694 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5695 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005696 len = 16 - len;
5697 if (len < 1)
5698 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5699 else
5700 vty_out (vty, "%*s", len, " ");
5701 }
5702#endif /* HAVE_IPV6 */
5703
5704 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005705 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005706 else
5707 vty_out (vty, " ");
5708
5709 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005710 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005711 else
5712 vty_out (vty, " ");
5713
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005715
Paul Jakmab2518c12006-05-12 23:48:40 +00005716 /* Print aspath */
5717 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005718 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005719
Paul Jakmab2518c12006-05-12 23:48:40 +00005720 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005721 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005722 }
paul718e3742002-12-13 20:15:29 +00005723 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005724}
5725
5726/* called from terminal list command */
5727void
5728route_vty_out_tmp (struct vty *vty, struct prefix *p,
5729 struct attr *attr, safi_t safi)
5730{
5731 /* Route status display. */
5732 vty_out (vty, "*");
5733 vty_out (vty, ">");
5734 vty_out (vty, " ");
5735
5736 /* print prefix and mask */
5737 route_vty_out_route (p, vty);
5738
5739 /* Print attribute */
5740 if (attr)
5741 {
5742 if (p->family == AF_INET)
5743 {
5744 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005745 vty_out (vty, "%-16s",
5746 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005747 else
5748 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5749 }
5750#ifdef HAVE_IPV6
5751 else if (p->family == AF_INET6)
5752 {
5753 int len;
5754 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005755
5756 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005757
5758 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005759 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5760 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005761 len = 16 - len;
5762 if (len < 1)
5763 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5764 else
5765 vty_out (vty, "%*s", len, " ");
5766 }
5767#endif /* HAVE_IPV6 */
5768
5769 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005770 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005771 else
5772 vty_out (vty, " ");
5773
5774 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005775 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005776 else
5777 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005778
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005779 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005780
Paul Jakmab2518c12006-05-12 23:48:40 +00005781 /* Print aspath */
5782 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005783 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005784
Paul Jakmab2518c12006-05-12 23:48:40 +00005785 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005786 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005787 }
paul718e3742002-12-13 20:15:29 +00005788
5789 vty_out (vty, "%s", VTY_NEWLINE);
5790}
5791
ajs5a646652004-11-05 01:25:55 +00005792void
paul718e3742002-12-13 20:15:29 +00005793route_vty_out_tag (struct vty *vty, struct prefix *p,
5794 struct bgp_info *binfo, int display, safi_t safi)
5795{
5796 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005797 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005798
5799 if (!binfo->extra)
5800 return;
5801
paulb40d9392005-08-22 22:34:41 +00005802 /* short status lead text */
5803 route_vty_short_status_out (vty, binfo);
5804
paul718e3742002-12-13 20:15:29 +00005805 /* print prefix and mask */
5806 if (! display)
5807 route_vty_out_route (p, vty);
5808 else
5809 vty_out (vty, "%*s", 17, " ");
5810
5811 /* Print attribute */
5812 attr = binfo->attr;
5813 if (attr)
5814 {
5815 if (p->family == AF_INET)
5816 {
5817 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005818 vty_out (vty, "%-16s",
5819 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005820 else
5821 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5822 }
5823#ifdef HAVE_IPV6
5824 else if (p->family == AF_INET6)
5825 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005826 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005827 char buf[BUFSIZ];
5828 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005829 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005830 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005831 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5832 buf, BUFSIZ));
5833 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005834 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005835 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5836 buf, BUFSIZ),
5837 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5838 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005839
5840 }
5841#endif /* HAVE_IPV6 */
5842 }
5843
Paul Jakmafb982c22007-05-04 20:15:47 +00005844 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005845
5846 vty_out (vty, "notag/%d", label);
5847
5848 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005849}
5850
5851/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005852static void
paul718e3742002-12-13 20:15:29 +00005853damp_route_vty_out (struct vty *vty, struct prefix *p,
5854 struct bgp_info *binfo, int display, safi_t safi)
5855{
5856 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005857 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005858 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005859
paulb40d9392005-08-22 22:34:41 +00005860 /* short status lead text */
5861 route_vty_short_status_out (vty, binfo);
5862
paul718e3742002-12-13 20:15:29 +00005863 /* print prefix and mask */
5864 if (! display)
5865 route_vty_out_route (p, vty);
5866 else
5867 vty_out (vty, "%*s", 17, " ");
5868
5869 len = vty_out (vty, "%s", binfo->peer->host);
5870 len = 17 - len;
5871 if (len < 1)
5872 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5873 else
5874 vty_out (vty, "%*s", len, " ");
5875
Chris Caputo50aef6f2009-06-23 06:06:49 +00005876 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005877
5878 /* Print attribute */
5879 attr = binfo->attr;
5880 if (attr)
5881 {
5882 /* Print aspath */
5883 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005884 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005885
5886 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005887 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005888 }
5889 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005890}
5891
paul718e3742002-12-13 20:15:29 +00005892/* flap route */
ajs5a646652004-11-05 01:25:55 +00005893static void
paul718e3742002-12-13 20:15:29 +00005894flap_route_vty_out (struct vty *vty, struct prefix *p,
5895 struct bgp_info *binfo, int display, safi_t safi)
5896{
5897 struct attr *attr;
5898 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005899 char timebuf[BGP_UPTIME_LEN];
5900 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005901
5902 if (!binfo->extra)
5903 return;
5904
5905 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005906
paulb40d9392005-08-22 22:34:41 +00005907 /* short status lead text */
5908 route_vty_short_status_out (vty, binfo);
5909
paul718e3742002-12-13 20:15:29 +00005910 /* print prefix and mask */
5911 if (! display)
5912 route_vty_out_route (p, vty);
5913 else
5914 vty_out (vty, "%*s", 17, " ");
5915
5916 len = vty_out (vty, "%s", binfo->peer->host);
5917 len = 16 - len;
5918 if (len < 1)
5919 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5920 else
5921 vty_out (vty, "%*s", len, " ");
5922
5923 len = vty_out (vty, "%d", bdi->flap);
5924 len = 5 - len;
5925 if (len < 1)
5926 vty_out (vty, " ");
5927 else
5928 vty_out (vty, "%*s ", len, " ");
5929
5930 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5931 timebuf, BGP_UPTIME_LEN));
5932
5933 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5934 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005935 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005936 else
5937 vty_out (vty, "%*s ", 8, " ");
5938
5939 /* Print attribute */
5940 attr = binfo->attr;
5941 if (attr)
5942 {
5943 /* Print aspath */
5944 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005945 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005946
5947 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005948 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005949 }
5950 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005951}
5952
paul94f2b392005-06-28 12:44:16 +00005953static void
paul718e3742002-12-13 20:15:29 +00005954route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5955 struct bgp_info *binfo, afi_t afi, safi_t safi)
5956{
5957 char buf[INET6_ADDRSTRLEN];
5958 char buf1[BUFSIZ];
5959 struct attr *attr;
5960 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005961#ifdef HAVE_CLOCK_MONOTONIC
5962 time_t tbuf;
5963#endif
paul718e3742002-12-13 20:15:29 +00005964
5965 attr = binfo->attr;
5966
5967 if (attr)
5968 {
5969 /* Line1 display AS-path, Aggregator */
5970 if (attr->aspath)
5971 {
5972 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005973 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005974 vty_out (vty, "Local");
5975 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005976 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005977 }
5978
paulb40d9392005-08-22 22:34:41 +00005979 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5980 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005981 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5982 vty_out (vty, ", (stale)");
5983 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005984 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005985 attr->extra->aggregator_as,
5986 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005987 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5988 vty_out (vty, ", (Received from a RR-client)");
5989 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5990 vty_out (vty, ", (Received from a RS-client)");
5991 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5992 vty_out (vty, ", (history entry)");
5993 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5994 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005995 vty_out (vty, "%s", VTY_NEWLINE);
5996
5997 /* Line2 display Next-hop, Neighbor, Router-id */
5998 if (p->family == AF_INET)
5999 {
6000 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006002 inet_ntoa (attr->nexthop));
6003 }
6004#ifdef HAVE_IPV6
6005 else
6006 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006007 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006008 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006009 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006010 buf, INET6_ADDRSTRLEN));
6011 }
6012#endif /* HAVE_IPV6 */
6013
6014 if (binfo->peer == bgp->peer_self)
6015 {
6016 vty_out (vty, " from %s ",
6017 p->family == AF_INET ? "0.0.0.0" : "::");
6018 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6019 }
6020 else
6021 {
6022 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6023 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006024 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006025 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006026 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006027 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006029 else
6030 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6031 }
6032 vty_out (vty, "%s", VTY_NEWLINE);
6033
6034#ifdef HAVE_IPV6
6035 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006037 {
6038 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006039 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006040 buf, INET6_ADDRSTRLEN),
6041 VTY_NEWLINE);
6042 }
6043#endif /* HAVE_IPV6 */
6044
6045 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6046 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6047
6048 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006049 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006050
6051 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006052 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006053 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006054 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006055
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006057 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006058
6059 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6060 vty_out (vty, ", valid");
6061
6062 if (binfo->peer != bgp->peer_self)
6063 {
6064 if (binfo->peer->as == binfo->peer->local_as)
6065 vty_out (vty, ", internal");
6066 else
6067 vty_out (vty, ", %s",
6068 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6069 }
6070 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6071 vty_out (vty, ", aggregated, local");
6072 else if (binfo->type != ZEBRA_ROUTE_BGP)
6073 vty_out (vty, ", sourced");
6074 else
6075 vty_out (vty, ", sourced, local");
6076
6077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6078 vty_out (vty, ", atomic-aggregate");
6079
Josh Baileyde8d5df2011-07-20 20:46:01 -07006080 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6081 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6082 bgp_info_mpath_count (binfo)))
6083 vty_out (vty, ", multipath");
6084
paul718e3742002-12-13 20:15:29 +00006085 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6086 vty_out (vty, ", best");
6087
6088 vty_out (vty, "%s", VTY_NEWLINE);
6089
6090 /* Line 4 display Community */
6091 if (attr->community)
6092 vty_out (vty, " Community: %s%s", attr->community->str,
6093 VTY_NEWLINE);
6094
6095 /* Line 5 display Extended-community */
6096 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006097 vty_out (vty, " Extended Community: %s%s",
6098 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006099
6100 /* Line 6 display Originator, Cluster-id */
6101 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6102 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6103 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006104 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006105 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006106 vty_out (vty, " Originator: %s",
6107 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006108
6109 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6110 {
6111 int i;
6112 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006113 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6114 vty_out (vty, "%s ",
6115 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006116 }
6117 vty_out (vty, "%s", VTY_NEWLINE);
6118 }
Paul Jakma41367172007-08-06 15:24:51 +00006119
Paul Jakmafb982c22007-05-04 20:15:47 +00006120 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006121 bgp_damp_info_vty (vty, binfo);
6122
6123 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006124#ifdef HAVE_CLOCK_MONOTONIC
6125 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006126 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006127#else
6128 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6129#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006130 }
6131 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006132}
6133
6134#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6135 "h history, * valid, > best, = multipath,%s"\
6136 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006137#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006138#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6139#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6140#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6141
6142enum bgp_show_type
6143{
6144 bgp_show_type_normal,
6145 bgp_show_type_regexp,
6146 bgp_show_type_prefix_list,
6147 bgp_show_type_filter_list,
6148 bgp_show_type_route_map,
6149 bgp_show_type_neighbor,
6150 bgp_show_type_cidr_only,
6151 bgp_show_type_prefix_longer,
6152 bgp_show_type_community_all,
6153 bgp_show_type_community,
6154 bgp_show_type_community_exact,
6155 bgp_show_type_community_list,
6156 bgp_show_type_community_list_exact,
6157 bgp_show_type_flap_statistics,
6158 bgp_show_type_flap_address,
6159 bgp_show_type_flap_prefix,
6160 bgp_show_type_flap_cidr_only,
6161 bgp_show_type_flap_regexp,
6162 bgp_show_type_flap_filter_list,
6163 bgp_show_type_flap_prefix_list,
6164 bgp_show_type_flap_prefix_longer,
6165 bgp_show_type_flap_route_map,
6166 bgp_show_type_flap_neighbor,
6167 bgp_show_type_dampend_paths,
6168 bgp_show_type_damp_neighbor
6169};
6170
ajs5a646652004-11-05 01:25:55 +00006171static int
paulfee0f4c2004-09-13 05:12:46 +00006172bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006173 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006174{
paul718e3742002-12-13 20:15:29 +00006175 struct bgp_info *ri;
6176 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006177 int header = 1;
paul718e3742002-12-13 20:15:29 +00006178 int display;
ajs5a646652004-11-05 01:25:55 +00006179 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006180
6181 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006182 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006183
paul718e3742002-12-13 20:15:29 +00006184 /* Start processing of routes. */
6185 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6186 if (rn->info != NULL)
6187 {
6188 display = 0;
6189
6190 for (ri = rn->info; ri; ri = ri->next)
6191 {
ajs5a646652004-11-05 01:25:55 +00006192 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006193 || type == bgp_show_type_flap_address
6194 || type == bgp_show_type_flap_prefix
6195 || type == bgp_show_type_flap_cidr_only
6196 || type == bgp_show_type_flap_regexp
6197 || type == bgp_show_type_flap_filter_list
6198 || type == bgp_show_type_flap_prefix_list
6199 || type == bgp_show_type_flap_prefix_longer
6200 || type == bgp_show_type_flap_route_map
6201 || type == bgp_show_type_flap_neighbor
6202 || type == bgp_show_type_dampend_paths
6203 || type == bgp_show_type_damp_neighbor)
6204 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006205 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006206 continue;
6207 }
6208 if (type == bgp_show_type_regexp
6209 || type == bgp_show_type_flap_regexp)
6210 {
ajs5a646652004-11-05 01:25:55 +00006211 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006212
6213 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6214 continue;
6215 }
6216 if (type == bgp_show_type_prefix_list
6217 || type == bgp_show_type_flap_prefix_list)
6218 {
ajs5a646652004-11-05 01:25:55 +00006219 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006220
6221 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6222 continue;
6223 }
6224 if (type == bgp_show_type_filter_list
6225 || type == bgp_show_type_flap_filter_list)
6226 {
ajs5a646652004-11-05 01:25:55 +00006227 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006228
6229 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6230 continue;
6231 }
6232 if (type == bgp_show_type_route_map
6233 || type == bgp_show_type_flap_route_map)
6234 {
ajs5a646652004-11-05 01:25:55 +00006235 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006236 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006237 struct attr dummy_attr;
6238 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006239 int ret;
6240
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006241 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006242 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006243
paul718e3742002-12-13 20:15:29 +00006244 binfo.peer = ri->peer;
6245 binfo.attr = &dummy_attr;
6246
6247 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006248 if (ret == RMAP_DENYMATCH)
6249 continue;
6250 }
6251 if (type == bgp_show_type_neighbor
6252 || type == bgp_show_type_flap_neighbor
6253 || type == bgp_show_type_damp_neighbor)
6254 {
ajs5a646652004-11-05 01:25:55 +00006255 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006256
6257 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6258 continue;
6259 }
6260 if (type == bgp_show_type_cidr_only
6261 || type == bgp_show_type_flap_cidr_only)
6262 {
6263 u_int32_t destination;
6264
6265 destination = ntohl (rn->p.u.prefix4.s_addr);
6266 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6267 continue;
6268 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6269 continue;
6270 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6271 continue;
6272 }
6273 if (type == bgp_show_type_prefix_longer
6274 || type == bgp_show_type_flap_prefix_longer)
6275 {
ajs5a646652004-11-05 01:25:55 +00006276 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006277
6278 if (! prefix_match (p, &rn->p))
6279 continue;
6280 }
6281 if (type == bgp_show_type_community_all)
6282 {
6283 if (! ri->attr->community)
6284 continue;
6285 }
6286 if (type == bgp_show_type_community)
6287 {
ajs5a646652004-11-05 01:25:55 +00006288 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006289
6290 if (! ri->attr->community ||
6291 ! community_match (ri->attr->community, com))
6292 continue;
6293 }
6294 if (type == bgp_show_type_community_exact)
6295 {
ajs5a646652004-11-05 01:25:55 +00006296 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006297
6298 if (! ri->attr->community ||
6299 ! community_cmp (ri->attr->community, com))
6300 continue;
6301 }
6302 if (type == bgp_show_type_community_list)
6303 {
ajs5a646652004-11-05 01:25:55 +00006304 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006305
6306 if (! community_list_match (ri->attr->community, list))
6307 continue;
6308 }
6309 if (type == bgp_show_type_community_list_exact)
6310 {
ajs5a646652004-11-05 01:25:55 +00006311 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006312
6313 if (! community_list_exact_match (ri->attr->community, list))
6314 continue;
6315 }
6316 if (type == bgp_show_type_flap_address
6317 || type == bgp_show_type_flap_prefix)
6318 {
ajs5a646652004-11-05 01:25:55 +00006319 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006320
6321 if (! prefix_match (&rn->p, p))
6322 continue;
6323
6324 if (type == bgp_show_type_flap_prefix)
6325 if (p->prefixlen != rn->p.prefixlen)
6326 continue;
6327 }
6328 if (type == bgp_show_type_dampend_paths
6329 || type == bgp_show_type_damp_neighbor)
6330 {
6331 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6332 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6333 continue;
6334 }
6335
6336 if (header)
6337 {
hasso93406d82005-02-02 14:40:33 +00006338 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6339 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6340 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006341 if (type == bgp_show_type_dampend_paths
6342 || type == bgp_show_type_damp_neighbor)
6343 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6344 else if (type == bgp_show_type_flap_statistics
6345 || type == bgp_show_type_flap_address
6346 || type == bgp_show_type_flap_prefix
6347 || type == bgp_show_type_flap_cidr_only
6348 || type == bgp_show_type_flap_regexp
6349 || type == bgp_show_type_flap_filter_list
6350 || type == bgp_show_type_flap_prefix_list
6351 || type == bgp_show_type_flap_prefix_longer
6352 || type == bgp_show_type_flap_route_map
6353 || type == bgp_show_type_flap_neighbor)
6354 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6355 else
6356 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006357 header = 0;
6358 }
6359
6360 if (type == bgp_show_type_dampend_paths
6361 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006362 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006363 else if (type == bgp_show_type_flap_statistics
6364 || type == bgp_show_type_flap_address
6365 || type == bgp_show_type_flap_prefix
6366 || type == bgp_show_type_flap_cidr_only
6367 || type == bgp_show_type_flap_regexp
6368 || type == bgp_show_type_flap_filter_list
6369 || type == bgp_show_type_flap_prefix_list
6370 || type == bgp_show_type_flap_prefix_longer
6371 || type == bgp_show_type_flap_route_map
6372 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006373 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006374 else
ajs5a646652004-11-05 01:25:55 +00006375 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006376 display++;
6377 }
6378 if (display)
ajs5a646652004-11-05 01:25:55 +00006379 output_count++;
paul718e3742002-12-13 20:15:29 +00006380 }
6381
6382 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006383 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006384 {
6385 if (type == bgp_show_type_normal)
6386 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6387 }
6388 else
6389 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006390 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006391
6392 return CMD_SUCCESS;
6393}
6394
ajs5a646652004-11-05 01:25:55 +00006395static int
paulfee0f4c2004-09-13 05:12:46 +00006396bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006397 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006398{
6399 struct bgp_table *table;
6400
6401 if (bgp == NULL) {
6402 bgp = bgp_get_default ();
6403 }
6404
6405 if (bgp == NULL)
6406 {
6407 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6408 return CMD_WARNING;
6409 }
6410
6411
6412 table = bgp->rib[afi][safi];
6413
ajs5a646652004-11-05 01:25:55 +00006414 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006415}
6416
paul718e3742002-12-13 20:15:29 +00006417/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006418static void
paul718e3742002-12-13 20:15:29 +00006419route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6420 struct bgp_node *rn,
6421 struct prefix_rd *prd, afi_t afi, safi_t safi)
6422{
6423 struct bgp_info *ri;
6424 struct prefix *p;
6425 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006426 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006427 char buf1[INET6_ADDRSTRLEN];
6428 char buf2[INET6_ADDRSTRLEN];
6429 int count = 0;
6430 int best = 0;
6431 int suppress = 0;
6432 int no_export = 0;
6433 int no_advertise = 0;
6434 int local_as = 0;
6435 int first = 0;
6436
6437 p = &rn->p;
6438 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6439 (safi == SAFI_MPLS_VPN ?
6440 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6441 safi == SAFI_MPLS_VPN ? ":" : "",
6442 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6443 p->prefixlen, VTY_NEWLINE);
6444
6445 for (ri = rn->info; ri; ri = ri->next)
6446 {
6447 count++;
6448 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6449 {
6450 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006451 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006452 suppress = 1;
6453 if (ri->attr->community != NULL)
6454 {
6455 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6456 no_advertise = 1;
6457 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6458 no_export = 1;
6459 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6460 local_as = 1;
6461 }
6462 }
6463 }
6464
6465 vty_out (vty, "Paths: (%d available", count);
6466 if (best)
6467 {
6468 vty_out (vty, ", best #%d", best);
6469 if (safi == SAFI_UNICAST)
6470 vty_out (vty, ", table Default-IP-Routing-Table");
6471 }
6472 else
6473 vty_out (vty, ", no best path");
6474 if (no_advertise)
6475 vty_out (vty, ", not advertised to any peer");
6476 else if (no_export)
6477 vty_out (vty, ", not advertised to EBGP peer");
6478 else if (local_as)
6479 vty_out (vty, ", not advertised outside local AS");
6480 if (suppress)
6481 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6482 vty_out (vty, ")%s", VTY_NEWLINE);
6483
6484 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006485 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006486 {
6487 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6488 {
6489 if (! first)
6490 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6491 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6492 first = 1;
6493 }
6494 }
6495 if (! first)
6496 vty_out (vty, " Not advertised to any peer");
6497 vty_out (vty, "%s", VTY_NEWLINE);
6498}
6499
6500/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006501static int
paulfee0f4c2004-09-13 05:12:46 +00006502bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006503 struct bgp_table *rib, const char *ip_str,
6504 afi_t afi, safi_t safi, struct prefix_rd *prd,
6505 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006506{
6507 int ret;
6508 int header;
6509 int display = 0;
6510 struct prefix match;
6511 struct bgp_node *rn;
6512 struct bgp_node *rm;
6513 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006514 struct bgp_table *table;
6515
paul718e3742002-12-13 20:15:29 +00006516 /* Check IP address argument. */
6517 ret = str2prefix (ip_str, &match);
6518 if (! ret)
6519 {
6520 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6521 return CMD_WARNING;
6522 }
6523
6524 match.family = afi2family (afi);
6525
6526 if (safi == SAFI_MPLS_VPN)
6527 {
paulfee0f4c2004-09-13 05:12:46 +00006528 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006529 {
6530 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6531 continue;
6532
6533 if ((table = rn->info) != NULL)
6534 {
6535 header = 1;
6536
6537 if ((rm = bgp_node_match (table, &match)) != NULL)
6538 {
6539 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006540 {
6541 bgp_unlock_node (rm);
6542 continue;
6543 }
paul718e3742002-12-13 20:15:29 +00006544
6545 for (ri = rm->info; ri; ri = ri->next)
6546 {
6547 if (header)
6548 {
6549 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6550 AFI_IP, SAFI_MPLS_VPN);
6551
6552 header = 0;
6553 }
6554 display++;
6555 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6556 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006557
6558 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006559 }
6560 }
6561 }
6562 }
6563 else
6564 {
6565 header = 1;
6566
paulfee0f4c2004-09-13 05:12:46 +00006567 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006568 {
6569 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6570 {
6571 for (ri = rn->info; ri; ri = ri->next)
6572 {
6573 if (header)
6574 {
6575 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6576 header = 0;
6577 }
6578 display++;
6579 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6580 }
6581 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006582
6583 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006584 }
6585 }
6586
6587 if (! display)
6588 {
6589 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6590 return CMD_WARNING;
6591 }
6592
6593 return CMD_SUCCESS;
6594}
6595
paulfee0f4c2004-09-13 05:12:46 +00006596/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006597static int
paulfd79ac92004-10-13 05:06:08 +00006598bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006599 afi_t afi, safi_t safi, struct prefix_rd *prd,
6600 int prefix_check)
6601{
6602 struct bgp *bgp;
6603
6604 /* BGP structure lookup. */
6605 if (view_name)
6606 {
6607 bgp = bgp_lookup_by_name (view_name);
6608 if (bgp == NULL)
6609 {
6610 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6611 return CMD_WARNING;
6612 }
6613 }
6614 else
6615 {
6616 bgp = bgp_get_default ();
6617 if (bgp == NULL)
6618 {
6619 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6620 return CMD_WARNING;
6621 }
6622 }
6623
6624 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6625 afi, safi, prd, prefix_check);
6626}
6627
paul718e3742002-12-13 20:15:29 +00006628/* BGP route print out function. */
6629DEFUN (show_ip_bgp,
6630 show_ip_bgp_cmd,
6631 "show ip bgp",
6632 SHOW_STR
6633 IP_STR
6634 BGP_STR)
6635{
ajs5a646652004-11-05 01:25:55 +00006636 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006637}
6638
6639DEFUN (show_ip_bgp_ipv4,
6640 show_ip_bgp_ipv4_cmd,
6641 "show ip bgp ipv4 (unicast|multicast)",
6642 SHOW_STR
6643 IP_STR
6644 BGP_STR
6645 "Address family\n"
6646 "Address Family modifier\n"
6647 "Address Family modifier\n")
6648{
6649 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006650 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6651 NULL);
paul718e3742002-12-13 20:15:29 +00006652
ajs5a646652004-11-05 01:25:55 +00006653 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006654}
6655
Michael Lambert95cbbd22010-07-23 14:43:04 -04006656ALIAS (show_ip_bgp_ipv4,
6657 show_bgp_ipv4_safi_cmd,
6658 "show bgp ipv4 (unicast|multicast)",
6659 SHOW_STR
6660 BGP_STR
6661 "Address family\n"
6662 "Address Family modifier\n"
6663 "Address Family modifier\n")
6664
paul718e3742002-12-13 20:15:29 +00006665DEFUN (show_ip_bgp_route,
6666 show_ip_bgp_route_cmd,
6667 "show ip bgp A.B.C.D",
6668 SHOW_STR
6669 IP_STR
6670 BGP_STR
6671 "Network in the BGP routing table to display\n")
6672{
6673 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6674}
6675
6676DEFUN (show_ip_bgp_ipv4_route,
6677 show_ip_bgp_ipv4_route_cmd,
6678 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6679 SHOW_STR
6680 IP_STR
6681 BGP_STR
6682 "Address family\n"
6683 "Address Family modifier\n"
6684 "Address Family modifier\n"
6685 "Network in the BGP routing table to display\n")
6686{
6687 if (strncmp (argv[0], "m", 1) == 0)
6688 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6689
6690 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6691}
6692
Michael Lambert95cbbd22010-07-23 14:43:04 -04006693ALIAS (show_ip_bgp_ipv4_route,
6694 show_bgp_ipv4_safi_route_cmd,
6695 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6696 SHOW_STR
6697 BGP_STR
6698 "Address family\n"
6699 "Address Family modifier\n"
6700 "Address Family modifier\n"
6701 "Network in the BGP routing table to display\n")
6702
paul718e3742002-12-13 20:15:29 +00006703DEFUN (show_ip_bgp_vpnv4_all_route,
6704 show_ip_bgp_vpnv4_all_route_cmd,
6705 "show ip bgp vpnv4 all A.B.C.D",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Display VPNv4 NLRI specific information\n"
6710 "Display information about all VPNv4 NLRIs\n"
6711 "Network in the BGP routing table to display\n")
6712{
6713 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6714}
6715
6716DEFUN (show_ip_bgp_vpnv4_rd_route,
6717 show_ip_bgp_vpnv4_rd_route_cmd,
6718 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6719 SHOW_STR
6720 IP_STR
6721 BGP_STR
6722 "Display VPNv4 NLRI specific information\n"
6723 "Display information for a route distinguisher\n"
6724 "VPN Route Distinguisher\n"
6725 "Network in the BGP routing table to display\n")
6726{
6727 int ret;
6728 struct prefix_rd prd;
6729
6730 ret = str2prefix_rd (argv[0], &prd);
6731 if (! ret)
6732 {
6733 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6734 return CMD_WARNING;
6735 }
6736 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6737}
6738
6739DEFUN (show_ip_bgp_prefix,
6740 show_ip_bgp_prefix_cmd,
6741 "show ip bgp A.B.C.D/M",
6742 SHOW_STR
6743 IP_STR
6744 BGP_STR
6745 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6746{
6747 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6748}
6749
6750DEFUN (show_ip_bgp_ipv4_prefix,
6751 show_ip_bgp_ipv4_prefix_cmd,
6752 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6753 SHOW_STR
6754 IP_STR
6755 BGP_STR
6756 "Address family\n"
6757 "Address Family modifier\n"
6758 "Address Family modifier\n"
6759 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6760{
6761 if (strncmp (argv[0], "m", 1) == 0)
6762 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6763
6764 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6765}
6766
Michael Lambert95cbbd22010-07-23 14:43:04 -04006767ALIAS (show_ip_bgp_ipv4_prefix,
6768 show_bgp_ipv4_safi_prefix_cmd,
6769 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6770 SHOW_STR
6771 BGP_STR
6772 "Address family\n"
6773 "Address Family modifier\n"
6774 "Address Family modifier\n"
6775 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6776
paul718e3742002-12-13 20:15:29 +00006777DEFUN (show_ip_bgp_vpnv4_all_prefix,
6778 show_ip_bgp_vpnv4_all_prefix_cmd,
6779 "show ip bgp vpnv4 all A.B.C.D/M",
6780 SHOW_STR
6781 IP_STR
6782 BGP_STR
6783 "Display VPNv4 NLRI specific information\n"
6784 "Display information about all VPNv4 NLRIs\n"
6785 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6786{
6787 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6788}
6789
6790DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6791 show_ip_bgp_vpnv4_rd_prefix_cmd,
6792 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6793 SHOW_STR
6794 IP_STR
6795 BGP_STR
6796 "Display VPNv4 NLRI specific information\n"
6797 "Display information for a route distinguisher\n"
6798 "VPN Route Distinguisher\n"
6799 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6800{
6801 int ret;
6802 struct prefix_rd prd;
6803
6804 ret = str2prefix_rd (argv[0], &prd);
6805 if (! ret)
6806 {
6807 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6808 return CMD_WARNING;
6809 }
6810 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6811}
6812
6813DEFUN (show_ip_bgp_view,
6814 show_ip_bgp_view_cmd,
6815 "show ip bgp view WORD",
6816 SHOW_STR
6817 IP_STR
6818 BGP_STR
6819 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006820 "View name\n")
paul718e3742002-12-13 20:15:29 +00006821{
paulbb46e942003-10-24 19:02:03 +00006822 struct bgp *bgp;
6823
6824 /* BGP structure lookup. */
6825 bgp = bgp_lookup_by_name (argv[0]);
6826 if (bgp == NULL)
6827 {
6828 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6829 return CMD_WARNING;
6830 }
6831
ajs5a646652004-11-05 01:25:55 +00006832 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006833}
6834
6835DEFUN (show_ip_bgp_view_route,
6836 show_ip_bgp_view_route_cmd,
6837 "show ip bgp view WORD A.B.C.D",
6838 SHOW_STR
6839 IP_STR
6840 BGP_STR
6841 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006842 "View name\n"
paul718e3742002-12-13 20:15:29 +00006843 "Network in the BGP routing table to display\n")
6844{
6845 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6846}
6847
6848DEFUN (show_ip_bgp_view_prefix,
6849 show_ip_bgp_view_prefix_cmd,
6850 "show ip bgp view WORD A.B.C.D/M",
6851 SHOW_STR
6852 IP_STR
6853 BGP_STR
6854 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006855 "View name\n"
paul718e3742002-12-13 20:15:29 +00006856 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6857{
6858 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6859}
6860
6861#ifdef HAVE_IPV6
6862DEFUN (show_bgp,
6863 show_bgp_cmd,
6864 "show bgp",
6865 SHOW_STR
6866 BGP_STR)
6867{
ajs5a646652004-11-05 01:25:55 +00006868 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6869 NULL);
paul718e3742002-12-13 20:15:29 +00006870}
6871
6872ALIAS (show_bgp,
6873 show_bgp_ipv6_cmd,
6874 "show bgp ipv6",
6875 SHOW_STR
6876 BGP_STR
6877 "Address family\n")
6878
Michael Lambert95cbbd22010-07-23 14:43:04 -04006879DEFUN (show_bgp_ipv6_safi,
6880 show_bgp_ipv6_safi_cmd,
6881 "show bgp ipv6 (unicast|multicast)",
6882 SHOW_STR
6883 BGP_STR
6884 "Address family\n"
6885 "Address Family modifier\n"
6886 "Address Family modifier\n")
6887{
6888 if (strncmp (argv[0], "m", 1) == 0)
6889 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6890 NULL);
6891
6892 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6893}
6894
paul718e3742002-12-13 20:15:29 +00006895/* old command */
6896DEFUN (show_ipv6_bgp,
6897 show_ipv6_bgp_cmd,
6898 "show ipv6 bgp",
6899 SHOW_STR
6900 IP_STR
6901 BGP_STR)
6902{
ajs5a646652004-11-05 01:25:55 +00006903 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6904 NULL);
paul718e3742002-12-13 20:15:29 +00006905}
6906
6907DEFUN (show_bgp_route,
6908 show_bgp_route_cmd,
6909 "show bgp X:X::X:X",
6910 SHOW_STR
6911 BGP_STR
6912 "Network in the BGP routing table to display\n")
6913{
6914 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6915}
6916
6917ALIAS (show_bgp_route,
6918 show_bgp_ipv6_route_cmd,
6919 "show bgp ipv6 X:X::X:X",
6920 SHOW_STR
6921 BGP_STR
6922 "Address family\n"
6923 "Network in the BGP routing table to display\n")
6924
Michael Lambert95cbbd22010-07-23 14:43:04 -04006925DEFUN (show_bgp_ipv6_safi_route,
6926 show_bgp_ipv6_safi_route_cmd,
6927 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6928 SHOW_STR
6929 BGP_STR
6930 "Address family\n"
6931 "Address Family modifier\n"
6932 "Address Family modifier\n"
6933 "Network in the BGP routing table to display\n")
6934{
6935 if (strncmp (argv[0], "m", 1) == 0)
6936 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6937
6938 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6939}
6940
paul718e3742002-12-13 20:15:29 +00006941/* old command */
6942DEFUN (show_ipv6_bgp_route,
6943 show_ipv6_bgp_route_cmd,
6944 "show ipv6 bgp X:X::X:X",
6945 SHOW_STR
6946 IP_STR
6947 BGP_STR
6948 "Network in the BGP routing table to display\n")
6949{
6950 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6951}
6952
6953DEFUN (show_bgp_prefix,
6954 show_bgp_prefix_cmd,
6955 "show bgp X:X::X:X/M",
6956 SHOW_STR
6957 BGP_STR
6958 "IPv6 prefix <network>/<length>\n")
6959{
6960 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6961}
6962
6963ALIAS (show_bgp_prefix,
6964 show_bgp_ipv6_prefix_cmd,
6965 "show bgp ipv6 X:X::X:X/M",
6966 SHOW_STR
6967 BGP_STR
6968 "Address family\n"
6969 "IPv6 prefix <network>/<length>\n")
6970
Michael Lambert95cbbd22010-07-23 14:43:04 -04006971DEFUN (show_bgp_ipv6_safi_prefix,
6972 show_bgp_ipv6_safi_prefix_cmd,
6973 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6974 SHOW_STR
6975 BGP_STR
6976 "Address family\n"
6977 "Address Family modifier\n"
6978 "Address Family modifier\n"
6979 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6980{
6981 if (strncmp (argv[0], "m", 1) == 0)
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6983
6984 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6985}
6986
paul718e3742002-12-13 20:15:29 +00006987/* old command */
6988DEFUN (show_ipv6_bgp_prefix,
6989 show_ipv6_bgp_prefix_cmd,
6990 "show ipv6 bgp X:X::X:X/M",
6991 SHOW_STR
6992 IP_STR
6993 BGP_STR
6994 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6995{
6996 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6997}
6998
paulbb46e942003-10-24 19:02:03 +00006999DEFUN (show_bgp_view,
7000 show_bgp_view_cmd,
7001 "show bgp view WORD",
7002 SHOW_STR
7003 BGP_STR
7004 "BGP view\n"
7005 "View name\n")
7006{
7007 struct bgp *bgp;
7008
7009 /* BGP structure lookup. */
7010 bgp = bgp_lookup_by_name (argv[0]);
7011 if (bgp == NULL)
7012 {
7013 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7014 return CMD_WARNING;
7015 }
7016
ajs5a646652004-11-05 01:25:55 +00007017 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007018}
7019
7020ALIAS (show_bgp_view,
7021 show_bgp_view_ipv6_cmd,
7022 "show bgp view WORD ipv6",
7023 SHOW_STR
7024 BGP_STR
7025 "BGP view\n"
7026 "View name\n"
7027 "Address family\n")
7028
7029DEFUN (show_bgp_view_route,
7030 show_bgp_view_route_cmd,
7031 "show bgp view WORD X:X::X:X",
7032 SHOW_STR
7033 BGP_STR
7034 "BGP view\n"
7035 "View name\n"
7036 "Network in the BGP routing table to display\n")
7037{
7038 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7039}
7040
7041ALIAS (show_bgp_view_route,
7042 show_bgp_view_ipv6_route_cmd,
7043 "show bgp view WORD ipv6 X:X::X:X",
7044 SHOW_STR
7045 BGP_STR
7046 "BGP view\n"
7047 "View name\n"
7048 "Address family\n"
7049 "Network in the BGP routing table to display\n")
7050
7051DEFUN (show_bgp_view_prefix,
7052 show_bgp_view_prefix_cmd,
7053 "show bgp view WORD X:X::X:X/M",
7054 SHOW_STR
7055 BGP_STR
7056 "BGP view\n"
7057 "View name\n"
7058 "IPv6 prefix <network>/<length>\n")
7059{
7060 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7061}
7062
7063ALIAS (show_bgp_view_prefix,
7064 show_bgp_view_ipv6_prefix_cmd,
7065 "show bgp view WORD ipv6 X:X::X:X/M",
7066 SHOW_STR
7067 BGP_STR
7068 "BGP view\n"
7069 "View name\n"
7070 "Address family\n"
7071 "IPv6 prefix <network>/<length>\n")
7072
paul718e3742002-12-13 20:15:29 +00007073/* old command */
7074DEFUN (show_ipv6_mbgp,
7075 show_ipv6_mbgp_cmd,
7076 "show ipv6 mbgp",
7077 SHOW_STR
7078 IP_STR
7079 MBGP_STR)
7080{
ajs5a646652004-11-05 01:25:55 +00007081 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7082 NULL);
paul718e3742002-12-13 20:15:29 +00007083}
7084
7085/* old command */
7086DEFUN (show_ipv6_mbgp_route,
7087 show_ipv6_mbgp_route_cmd,
7088 "show ipv6 mbgp X:X::X:X",
7089 SHOW_STR
7090 IP_STR
7091 MBGP_STR
7092 "Network in the MBGP routing table to display\n")
7093{
7094 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7095}
7096
7097/* old command */
7098DEFUN (show_ipv6_mbgp_prefix,
7099 show_ipv6_mbgp_prefix_cmd,
7100 "show ipv6 mbgp X:X::X:X/M",
7101 SHOW_STR
7102 IP_STR
7103 MBGP_STR
7104 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7105{
7106 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7107}
7108#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007109
paul718e3742002-12-13 20:15:29 +00007110
paul94f2b392005-06-28 12:44:16 +00007111static int
paulfd79ac92004-10-13 05:06:08 +00007112bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007113 safi_t safi, enum bgp_show_type type)
7114{
7115 int i;
7116 struct buffer *b;
7117 char *regstr;
7118 int first;
7119 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007120 int rc;
paul718e3742002-12-13 20:15:29 +00007121
7122 first = 0;
7123 b = buffer_new (1024);
7124 for (i = 0; i < argc; i++)
7125 {
7126 if (first)
7127 buffer_putc (b, ' ');
7128 else
7129 {
7130 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7131 continue;
7132 first = 1;
7133 }
7134
7135 buffer_putstr (b, argv[i]);
7136 }
7137 buffer_putc (b, '\0');
7138
7139 regstr = buffer_getstr (b);
7140 buffer_free (b);
7141
7142 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007143 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007144 if (! regex)
7145 {
7146 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7147 VTY_NEWLINE);
7148 return CMD_WARNING;
7149 }
7150
ajs5a646652004-11-05 01:25:55 +00007151 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7152 bgp_regex_free (regex);
7153 return rc;
paul718e3742002-12-13 20:15:29 +00007154}
7155
7156DEFUN (show_ip_bgp_regexp,
7157 show_ip_bgp_regexp_cmd,
7158 "show ip bgp regexp .LINE",
7159 SHOW_STR
7160 IP_STR
7161 BGP_STR
7162 "Display routes matching the AS path regular expression\n"
7163 "A regular-expression to match the BGP AS paths\n")
7164{
7165 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7166 bgp_show_type_regexp);
7167}
7168
7169DEFUN (show_ip_bgp_flap_regexp,
7170 show_ip_bgp_flap_regexp_cmd,
7171 "show ip bgp flap-statistics regexp .LINE",
7172 SHOW_STR
7173 IP_STR
7174 BGP_STR
7175 "Display flap statistics of routes\n"
7176 "Display routes matching the AS path regular expression\n"
7177 "A regular-expression to match the BGP AS paths\n")
7178{
7179 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7180 bgp_show_type_flap_regexp);
7181}
7182
7183DEFUN (show_ip_bgp_ipv4_regexp,
7184 show_ip_bgp_ipv4_regexp_cmd,
7185 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "Address family\n"
7190 "Address Family modifier\n"
7191 "Address Family modifier\n"
7192 "Display routes matching the AS path regular expression\n"
7193 "A regular-expression to match the BGP AS paths\n")
7194{
7195 if (strncmp (argv[0], "m", 1) == 0)
7196 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7197 bgp_show_type_regexp);
7198
7199 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7200 bgp_show_type_regexp);
7201}
7202
7203#ifdef HAVE_IPV6
7204DEFUN (show_bgp_regexp,
7205 show_bgp_regexp_cmd,
7206 "show bgp regexp .LINE",
7207 SHOW_STR
7208 BGP_STR
7209 "Display routes matching the AS path regular expression\n"
7210 "A regular-expression to match the BGP AS paths\n")
7211{
7212 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7213 bgp_show_type_regexp);
7214}
7215
7216ALIAS (show_bgp_regexp,
7217 show_bgp_ipv6_regexp_cmd,
7218 "show bgp ipv6 regexp .LINE",
7219 SHOW_STR
7220 BGP_STR
7221 "Address family\n"
7222 "Display routes matching the AS path regular expression\n"
7223 "A regular-expression to match the BGP AS paths\n")
7224
7225/* old command */
7226DEFUN (show_ipv6_bgp_regexp,
7227 show_ipv6_bgp_regexp_cmd,
7228 "show ipv6 bgp regexp .LINE",
7229 SHOW_STR
7230 IP_STR
7231 BGP_STR
7232 "Display routes matching the AS path regular expression\n"
7233 "A regular-expression to match the BGP AS paths\n")
7234{
7235 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7236 bgp_show_type_regexp);
7237}
7238
7239/* old command */
7240DEFUN (show_ipv6_mbgp_regexp,
7241 show_ipv6_mbgp_regexp_cmd,
7242 "show ipv6 mbgp regexp .LINE",
7243 SHOW_STR
7244 IP_STR
7245 BGP_STR
7246 "Display routes matching the AS path regular expression\n"
7247 "A regular-expression to match the MBGP AS paths\n")
7248{
7249 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7250 bgp_show_type_regexp);
7251}
7252#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007253
paul94f2b392005-06-28 12:44:16 +00007254static int
paulfd79ac92004-10-13 05:06:08 +00007255bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007256 safi_t safi, enum bgp_show_type type)
7257{
7258 struct prefix_list *plist;
7259
7260 plist = prefix_list_lookup (afi, prefix_list_str);
7261 if (plist == NULL)
7262 {
7263 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7264 prefix_list_str, VTY_NEWLINE);
7265 return CMD_WARNING;
7266 }
7267
ajs5a646652004-11-05 01:25:55 +00007268 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007269}
7270
7271DEFUN (show_ip_bgp_prefix_list,
7272 show_ip_bgp_prefix_list_cmd,
7273 "show ip bgp prefix-list WORD",
7274 SHOW_STR
7275 IP_STR
7276 BGP_STR
7277 "Display routes conforming to the prefix-list\n"
7278 "IP prefix-list name\n")
7279{
7280 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7281 bgp_show_type_prefix_list);
7282}
7283
7284DEFUN (show_ip_bgp_flap_prefix_list,
7285 show_ip_bgp_flap_prefix_list_cmd,
7286 "show ip bgp flap-statistics prefix-list WORD",
7287 SHOW_STR
7288 IP_STR
7289 BGP_STR
7290 "Display flap statistics of routes\n"
7291 "Display routes conforming to the prefix-list\n"
7292 "IP prefix-list name\n")
7293{
7294 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7295 bgp_show_type_flap_prefix_list);
7296}
7297
7298DEFUN (show_ip_bgp_ipv4_prefix_list,
7299 show_ip_bgp_ipv4_prefix_list_cmd,
7300 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7301 SHOW_STR
7302 IP_STR
7303 BGP_STR
7304 "Address family\n"
7305 "Address Family modifier\n"
7306 "Address Family modifier\n"
7307 "Display routes conforming to the prefix-list\n"
7308 "IP prefix-list name\n")
7309{
7310 if (strncmp (argv[0], "m", 1) == 0)
7311 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7312 bgp_show_type_prefix_list);
7313
7314 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7315 bgp_show_type_prefix_list);
7316}
7317
7318#ifdef HAVE_IPV6
7319DEFUN (show_bgp_prefix_list,
7320 show_bgp_prefix_list_cmd,
7321 "show bgp prefix-list WORD",
7322 SHOW_STR
7323 BGP_STR
7324 "Display routes conforming to the prefix-list\n"
7325 "IPv6 prefix-list name\n")
7326{
7327 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7328 bgp_show_type_prefix_list);
7329}
7330
7331ALIAS (show_bgp_prefix_list,
7332 show_bgp_ipv6_prefix_list_cmd,
7333 "show bgp ipv6 prefix-list WORD",
7334 SHOW_STR
7335 BGP_STR
7336 "Address family\n"
7337 "Display routes conforming to the prefix-list\n"
7338 "IPv6 prefix-list name\n")
7339
7340/* old command */
7341DEFUN (show_ipv6_bgp_prefix_list,
7342 show_ipv6_bgp_prefix_list_cmd,
7343 "show ipv6 bgp prefix-list WORD",
7344 SHOW_STR
7345 IPV6_STR
7346 BGP_STR
7347 "Display routes matching the prefix-list\n"
7348 "IPv6 prefix-list name\n")
7349{
7350 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7351 bgp_show_type_prefix_list);
7352}
7353
7354/* old command */
7355DEFUN (show_ipv6_mbgp_prefix_list,
7356 show_ipv6_mbgp_prefix_list_cmd,
7357 "show ipv6 mbgp prefix-list WORD",
7358 SHOW_STR
7359 IPV6_STR
7360 MBGP_STR
7361 "Display routes matching the prefix-list\n"
7362 "IPv6 prefix-list name\n")
7363{
7364 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7365 bgp_show_type_prefix_list);
7366}
7367#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007368
paul94f2b392005-06-28 12:44:16 +00007369static int
paulfd79ac92004-10-13 05:06:08 +00007370bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007371 safi_t safi, enum bgp_show_type type)
7372{
7373 struct as_list *as_list;
7374
7375 as_list = as_list_lookup (filter);
7376 if (as_list == NULL)
7377 {
7378 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7379 return CMD_WARNING;
7380 }
7381
ajs5a646652004-11-05 01:25:55 +00007382 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007383}
7384
7385DEFUN (show_ip_bgp_filter_list,
7386 show_ip_bgp_filter_list_cmd,
7387 "show ip bgp filter-list WORD",
7388 SHOW_STR
7389 IP_STR
7390 BGP_STR
7391 "Display routes conforming to the filter-list\n"
7392 "Regular expression access list name\n")
7393{
7394 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7395 bgp_show_type_filter_list);
7396}
7397
7398DEFUN (show_ip_bgp_flap_filter_list,
7399 show_ip_bgp_flap_filter_list_cmd,
7400 "show ip bgp flap-statistics filter-list WORD",
7401 SHOW_STR
7402 IP_STR
7403 BGP_STR
7404 "Display flap statistics of routes\n"
7405 "Display routes conforming to the filter-list\n"
7406 "Regular expression access list name\n")
7407{
7408 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7409 bgp_show_type_flap_filter_list);
7410}
7411
7412DEFUN (show_ip_bgp_ipv4_filter_list,
7413 show_ip_bgp_ipv4_filter_list_cmd,
7414 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7415 SHOW_STR
7416 IP_STR
7417 BGP_STR
7418 "Address family\n"
7419 "Address Family modifier\n"
7420 "Address Family modifier\n"
7421 "Display routes conforming to the filter-list\n"
7422 "Regular expression access list name\n")
7423{
7424 if (strncmp (argv[0], "m", 1) == 0)
7425 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7426 bgp_show_type_filter_list);
7427
7428 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7429 bgp_show_type_filter_list);
7430}
7431
7432#ifdef HAVE_IPV6
7433DEFUN (show_bgp_filter_list,
7434 show_bgp_filter_list_cmd,
7435 "show bgp filter-list WORD",
7436 SHOW_STR
7437 BGP_STR
7438 "Display routes conforming to the filter-list\n"
7439 "Regular expression access list name\n")
7440{
7441 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7442 bgp_show_type_filter_list);
7443}
7444
7445ALIAS (show_bgp_filter_list,
7446 show_bgp_ipv6_filter_list_cmd,
7447 "show bgp ipv6 filter-list WORD",
7448 SHOW_STR
7449 BGP_STR
7450 "Address family\n"
7451 "Display routes conforming to the filter-list\n"
7452 "Regular expression access list name\n")
7453
7454/* old command */
7455DEFUN (show_ipv6_bgp_filter_list,
7456 show_ipv6_bgp_filter_list_cmd,
7457 "show ipv6 bgp filter-list WORD",
7458 SHOW_STR
7459 IPV6_STR
7460 BGP_STR
7461 "Display routes conforming to the filter-list\n"
7462 "Regular expression access list name\n")
7463{
7464 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7465 bgp_show_type_filter_list);
7466}
7467
7468/* old command */
7469DEFUN (show_ipv6_mbgp_filter_list,
7470 show_ipv6_mbgp_filter_list_cmd,
7471 "show ipv6 mbgp filter-list WORD",
7472 SHOW_STR
7473 IPV6_STR
7474 MBGP_STR
7475 "Display routes conforming to the filter-list\n"
7476 "Regular expression access list name\n")
7477{
7478 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7479 bgp_show_type_filter_list);
7480}
7481#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007482
paul94f2b392005-06-28 12:44:16 +00007483static int
paulfd79ac92004-10-13 05:06:08 +00007484bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007485 safi_t safi, enum bgp_show_type type)
7486{
7487 struct route_map *rmap;
7488
7489 rmap = route_map_lookup_by_name (rmap_str);
7490 if (! rmap)
7491 {
7492 vty_out (vty, "%% %s is not a valid route-map name%s",
7493 rmap_str, VTY_NEWLINE);
7494 return CMD_WARNING;
7495 }
7496
ajs5a646652004-11-05 01:25:55 +00007497 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007498}
7499
7500DEFUN (show_ip_bgp_route_map,
7501 show_ip_bgp_route_map_cmd,
7502 "show ip bgp route-map WORD",
7503 SHOW_STR
7504 IP_STR
7505 BGP_STR
7506 "Display routes matching the route-map\n"
7507 "A route-map to match on\n")
7508{
7509 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7510 bgp_show_type_route_map);
7511}
7512
7513DEFUN (show_ip_bgp_flap_route_map,
7514 show_ip_bgp_flap_route_map_cmd,
7515 "show ip bgp flap-statistics route-map WORD",
7516 SHOW_STR
7517 IP_STR
7518 BGP_STR
7519 "Display flap statistics of routes\n"
7520 "Display routes matching the route-map\n"
7521 "A route-map to match on\n")
7522{
7523 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7524 bgp_show_type_flap_route_map);
7525}
7526
7527DEFUN (show_ip_bgp_ipv4_route_map,
7528 show_ip_bgp_ipv4_route_map_cmd,
7529 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7530 SHOW_STR
7531 IP_STR
7532 BGP_STR
7533 "Address family\n"
7534 "Address Family modifier\n"
7535 "Address Family modifier\n"
7536 "Display routes matching the route-map\n"
7537 "A route-map to match on\n")
7538{
7539 if (strncmp (argv[0], "m", 1) == 0)
7540 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7541 bgp_show_type_route_map);
7542
7543 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7544 bgp_show_type_route_map);
7545}
7546
7547DEFUN (show_bgp_route_map,
7548 show_bgp_route_map_cmd,
7549 "show bgp route-map WORD",
7550 SHOW_STR
7551 BGP_STR
7552 "Display routes matching the route-map\n"
7553 "A route-map to match on\n")
7554{
7555 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7556 bgp_show_type_route_map);
7557}
7558
7559ALIAS (show_bgp_route_map,
7560 show_bgp_ipv6_route_map_cmd,
7561 "show bgp ipv6 route-map WORD",
7562 SHOW_STR
7563 BGP_STR
7564 "Address family\n"
7565 "Display routes matching the route-map\n"
7566 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007567
paul718e3742002-12-13 20:15:29 +00007568DEFUN (show_ip_bgp_cidr_only,
7569 show_ip_bgp_cidr_only_cmd,
7570 "show ip bgp cidr-only",
7571 SHOW_STR
7572 IP_STR
7573 BGP_STR
7574 "Display only routes with non-natural netmasks\n")
7575{
7576 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007577 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007578}
7579
7580DEFUN (show_ip_bgp_flap_cidr_only,
7581 show_ip_bgp_flap_cidr_only_cmd,
7582 "show ip bgp flap-statistics cidr-only",
7583 SHOW_STR
7584 IP_STR
7585 BGP_STR
7586 "Display flap statistics of routes\n"
7587 "Display only routes with non-natural netmasks\n")
7588{
7589 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007591}
7592
7593DEFUN (show_ip_bgp_ipv4_cidr_only,
7594 show_ip_bgp_ipv4_cidr_only_cmd,
7595 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7596 SHOW_STR
7597 IP_STR
7598 BGP_STR
7599 "Address family\n"
7600 "Address Family modifier\n"
7601 "Address Family modifier\n"
7602 "Display only routes with non-natural netmasks\n")
7603{
7604 if (strncmp (argv[0], "m", 1) == 0)
7605 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007606 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007607
7608 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007609 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007610}
David Lamparter6b0655a2014-06-04 06:53:35 +02007611
paul718e3742002-12-13 20:15:29 +00007612DEFUN (show_ip_bgp_community_all,
7613 show_ip_bgp_community_all_cmd,
7614 "show ip bgp community",
7615 SHOW_STR
7616 IP_STR
7617 BGP_STR
7618 "Display routes matching the communities\n")
7619{
7620 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007621 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007622}
7623
7624DEFUN (show_ip_bgp_ipv4_community_all,
7625 show_ip_bgp_ipv4_community_all_cmd,
7626 "show ip bgp ipv4 (unicast|multicast) community",
7627 SHOW_STR
7628 IP_STR
7629 BGP_STR
7630 "Address family\n"
7631 "Address Family modifier\n"
7632 "Address Family modifier\n"
7633 "Display routes matching the communities\n")
7634{
7635 if (strncmp (argv[0], "m", 1) == 0)
7636 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007637 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007638
7639 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007640 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007641}
7642
7643#ifdef HAVE_IPV6
7644DEFUN (show_bgp_community_all,
7645 show_bgp_community_all_cmd,
7646 "show bgp community",
7647 SHOW_STR
7648 BGP_STR
7649 "Display routes matching the communities\n")
7650{
7651 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007652 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007653}
7654
7655ALIAS (show_bgp_community_all,
7656 show_bgp_ipv6_community_all_cmd,
7657 "show bgp ipv6 community",
7658 SHOW_STR
7659 BGP_STR
7660 "Address family\n"
7661 "Display routes matching the communities\n")
7662
7663/* old command */
7664DEFUN (show_ipv6_bgp_community_all,
7665 show_ipv6_bgp_community_all_cmd,
7666 "show ipv6 bgp community",
7667 SHOW_STR
7668 IPV6_STR
7669 BGP_STR
7670 "Display routes matching the communities\n")
7671{
7672 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007673 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007674}
7675
7676/* old command */
7677DEFUN (show_ipv6_mbgp_community_all,
7678 show_ipv6_mbgp_community_all_cmd,
7679 "show ipv6 mbgp community",
7680 SHOW_STR
7681 IPV6_STR
7682 MBGP_STR
7683 "Display routes matching the communities\n")
7684{
7685 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007686 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007687}
7688#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007689
paul94f2b392005-06-28 12:44:16 +00007690static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007691bgp_show_community (struct vty *vty, const char *view_name, int argc,
7692 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007693{
7694 struct community *com;
7695 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007696 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007697 int i;
7698 char *str;
7699 int first = 0;
7700
Michael Lambert95cbbd22010-07-23 14:43:04 -04007701 /* BGP structure lookup */
7702 if (view_name)
7703 {
7704 bgp = bgp_lookup_by_name (view_name);
7705 if (bgp == NULL)
7706 {
7707 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7708 return CMD_WARNING;
7709 }
7710 }
7711 else
7712 {
7713 bgp = bgp_get_default ();
7714 if (bgp == NULL)
7715 {
7716 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7717 return CMD_WARNING;
7718 }
7719 }
7720
paul718e3742002-12-13 20:15:29 +00007721 b = buffer_new (1024);
7722 for (i = 0; i < argc; i++)
7723 {
7724 if (first)
7725 buffer_putc (b, ' ');
7726 else
7727 {
7728 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7729 continue;
7730 first = 1;
7731 }
7732
7733 buffer_putstr (b, argv[i]);
7734 }
7735 buffer_putc (b, '\0');
7736
7737 str = buffer_getstr (b);
7738 buffer_free (b);
7739
7740 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007741 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007742 if (! com)
7743 {
7744 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7745 return CMD_WARNING;
7746 }
7747
Michael Lambert95cbbd22010-07-23 14:43:04 -04007748 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007749 (exact ? bgp_show_type_community_exact :
7750 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007751}
7752
7753DEFUN (show_ip_bgp_community,
7754 show_ip_bgp_community_cmd,
7755 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7756 SHOW_STR
7757 IP_STR
7758 BGP_STR
7759 "Display routes matching the communities\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n")
7764{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007765 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007766}
7767
7768ALIAS (show_ip_bgp_community,
7769 show_ip_bgp_community2_cmd,
7770 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7771 SHOW_STR
7772 IP_STR
7773 BGP_STR
7774 "Display routes matching the communities\n"
7775 "community number\n"
7776 "Do not send outside local AS (well-known community)\n"
7777 "Do not advertise to any peer (well-known community)\n"
7778 "Do not export to next AS (well-known community)\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n")
7783
7784ALIAS (show_ip_bgp_community,
7785 show_ip_bgp_community3_cmd,
7786 "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)",
7787 SHOW_STR
7788 IP_STR
7789 BGP_STR
7790 "Display routes matching the communities\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n")
7803
7804ALIAS (show_ip_bgp_community,
7805 show_ip_bgp_community4_cmd,
7806 "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)",
7807 SHOW_STR
7808 IP_STR
7809 BGP_STR
7810 "Display routes matching the communities\n"
7811 "community number\n"
7812 "Do not send outside local AS (well-known community)\n"
7813 "Do not advertise to any peer (well-known community)\n"
7814 "Do not export to next AS (well-known community)\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n"
7823 "community number\n"
7824 "Do not send outside local AS (well-known community)\n"
7825 "Do not advertise to any peer (well-known community)\n"
7826 "Do not export to next AS (well-known community)\n")
7827
7828DEFUN (show_ip_bgp_ipv4_community,
7829 show_ip_bgp_ipv4_community_cmd,
7830 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7831 SHOW_STR
7832 IP_STR
7833 BGP_STR
7834 "Address family\n"
7835 "Address Family modifier\n"
7836 "Address Family modifier\n"
7837 "Display routes matching the communities\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n")
7842{
7843 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007844 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007845
Michael Lambert95cbbd22010-07-23 14:43:04 -04007846 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007847}
7848
7849ALIAS (show_ip_bgp_ipv4_community,
7850 show_ip_bgp_ipv4_community2_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)",
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
7868ALIAS (show_ip_bgp_ipv4_community,
7869 show_ip_bgp_ipv4_community3_cmd,
7870 "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)",
7871 SHOW_STR
7872 IP_STR
7873 BGP_STR
7874 "Address family\n"
7875 "Address Family modifier\n"
7876 "Address Family modifier\n"
7877 "Display routes matching the communities\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n"
7882 "community number\n"
7883 "Do not send outside local AS (well-known community)\n"
7884 "Do not advertise to any peer (well-known community)\n"
7885 "Do not export to next AS (well-known community)\n"
7886 "community number\n"
7887 "Do not send outside local AS (well-known community)\n"
7888 "Do not advertise to any peer (well-known community)\n"
7889 "Do not export to next AS (well-known community)\n")
7890
7891ALIAS (show_ip_bgp_ipv4_community,
7892 show_ip_bgp_ipv4_community4_cmd,
7893 "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)",
7894 SHOW_STR
7895 IP_STR
7896 BGP_STR
7897 "Address family\n"
7898 "Address Family modifier\n"
7899 "Address Family modifier\n"
7900 "Display routes matching the communities\n"
7901 "community number\n"
7902 "Do not send outside local AS (well-known community)\n"
7903 "Do not advertise to any peer (well-known community)\n"
7904 "Do not export to next AS (well-known community)\n"
7905 "community number\n"
7906 "Do not send outside local AS (well-known community)\n"
7907 "Do not advertise to any peer (well-known community)\n"
7908 "Do not export to next AS (well-known community)\n"
7909 "community number\n"
7910 "Do not send outside local AS (well-known community)\n"
7911 "Do not advertise to any peer (well-known community)\n"
7912 "Do not export to next AS (well-known community)\n"
7913 "community number\n"
7914 "Do not send outside local AS (well-known community)\n"
7915 "Do not advertise to any peer (well-known community)\n"
7916 "Do not export to next AS (well-known community)\n")
7917
Michael Lambert95cbbd22010-07-23 14:43:04 -04007918DEFUN (show_bgp_view_afi_safi_community_all,
7919 show_bgp_view_afi_safi_community_all_cmd,
7920#ifdef HAVE_IPV6
7921 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7922#else
7923 "show bgp view WORD ipv4 (unicast|multicast) community",
7924#endif
7925 SHOW_STR
7926 BGP_STR
7927 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007928 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007929 "Address family\n"
7930#ifdef HAVE_IPV6
7931 "Address family\n"
7932#endif
7933 "Address Family modifier\n"
7934 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007935 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007936{
7937 int afi;
7938 int safi;
7939 struct bgp *bgp;
7940
7941 /* BGP structure lookup. */
7942 bgp = bgp_lookup_by_name (argv[0]);
7943 if (bgp == NULL)
7944 {
7945 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7946 return CMD_WARNING;
7947 }
7948
7949#ifdef HAVE_IPV6
7950 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7951 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7952#else
7953 afi = AFI_IP;
7954 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7955#endif
7956 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7957}
7958
7959DEFUN (show_bgp_view_afi_safi_community,
7960 show_bgp_view_afi_safi_community_cmd,
7961#ifdef HAVE_IPV6
7962 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7963#else
7964 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7965#endif
7966 SHOW_STR
7967 BGP_STR
7968 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007969 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 "Address family\n"
7971#ifdef HAVE_IPV6
7972 "Address family\n"
7973#endif
7974 "Address family modifier\n"
7975 "Address family modifier\n"
7976 "Display routes matching the communities\n"
7977 "community number\n"
7978 "Do not send outside local AS (well-known community)\n"
7979 "Do not advertise to any peer (well-known community)\n"
7980 "Do not export to next AS (well-known community)\n")
7981{
7982 int afi;
7983 int safi;
7984
7985#ifdef HAVE_IPV6
7986 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7987 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7988 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7989#else
7990 afi = AFI_IP;
7991 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7992 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7993#endif
7994}
7995
7996ALIAS (show_bgp_view_afi_safi_community,
7997 show_bgp_view_afi_safi_community2_cmd,
7998#ifdef HAVE_IPV6
7999 "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)",
8000#else
8001 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8002#endif
8003 SHOW_STR
8004 BGP_STR
8005 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008006 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008007 "Address family\n"
8008#ifdef HAVE_IPV6
8009 "Address family\n"
8010#endif
8011 "Address family modifier\n"
8012 "Address family modifier\n"
8013 "Display routes matching the communities\n"
8014 "community number\n"
8015 "Do not send outside local AS (well-known community)\n"
8016 "Do not advertise to any peer (well-known community)\n"
8017 "Do not export to next AS (well-known community)\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n")
8022
8023ALIAS (show_bgp_view_afi_safi_community,
8024 show_bgp_view_afi_safi_community3_cmd,
8025#ifdef HAVE_IPV6
8026 "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)",
8027#else
8028 "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)",
8029#endif
8030 SHOW_STR
8031 BGP_STR
8032 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008033 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008034 "Address family\n"
8035#ifdef HAVE_IPV6
8036 "Address family\n"
8037#endif
8038 "Address family modifier\n"
8039 "Address family modifier\n"
8040 "Display routes matching the communities\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n")
8053
8054ALIAS (show_bgp_view_afi_safi_community,
8055 show_bgp_view_afi_safi_community4_cmd,
8056#ifdef HAVE_IPV6
8057 "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)",
8058#else
8059 "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)",
8060#endif
8061 SHOW_STR
8062 BGP_STR
8063 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008064 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008065 "Address family\n"
8066#ifdef HAVE_IPV6
8067 "Address family\n"
8068#endif
8069 "Address family modifier\n"
8070 "Address family modifier\n"
8071 "Display routes matching the communities\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "community number\n"
8081 "Do not send outside local AS (well-known community)\n"
8082 "Do not advertise to any peer (well-known community)\n"
8083 "Do not export to next AS (well-known community)\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n")
8088
paul718e3742002-12-13 20:15:29 +00008089DEFUN (show_ip_bgp_community_exact,
8090 show_ip_bgp_community_exact_cmd,
8091 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8092 SHOW_STR
8093 IP_STR
8094 BGP_STR
8095 "Display routes matching the communities\n"
8096 "community number\n"
8097 "Do not send outside local AS (well-known community)\n"
8098 "Do not advertise to any peer (well-known community)\n"
8099 "Do not export to next AS (well-known community)\n"
8100 "Exact match of the communities")
8101{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008102 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008103}
8104
8105ALIAS (show_ip_bgp_community_exact,
8106 show_ip_bgp_community2_exact_cmd,
8107 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8108 SHOW_STR
8109 IP_STR
8110 BGP_STR
8111 "Display routes matching the communities\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 "Exact match of the communities")
8121
8122ALIAS (show_ip_bgp_community_exact,
8123 show_ip_bgp_community3_exact_cmd,
8124 "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",
8125 SHOW_STR
8126 IP_STR
8127 BGP_STR
8128 "Display routes matching the communities\n"
8129 "community number\n"
8130 "Do not send outside local AS (well-known community)\n"
8131 "Do not advertise to any peer (well-known community)\n"
8132 "Do not export to next AS (well-known community)\n"
8133 "community number\n"
8134 "Do not send outside local AS (well-known community)\n"
8135 "Do not advertise to any peer (well-known community)\n"
8136 "Do not export to next AS (well-known community)\n"
8137 "community number\n"
8138 "Do not send outside local AS (well-known community)\n"
8139 "Do not advertise to any peer (well-known community)\n"
8140 "Do not export to next AS (well-known community)\n"
8141 "Exact match of the communities")
8142
8143ALIAS (show_ip_bgp_community_exact,
8144 show_ip_bgp_community4_exact_cmd,
8145 "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",
8146 SHOW_STR
8147 IP_STR
8148 BGP_STR
8149 "Display routes matching the communities\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "community number\n"
8155 "Do not send outside local AS (well-known community)\n"
8156 "Do not advertise to any peer (well-known community)\n"
8157 "Do not export to next AS (well-known community)\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
8168DEFUN (show_ip_bgp_ipv4_community_exact,
8169 show_ip_bgp_ipv4_community_exact_cmd,
8170 "show ip bgp ipv4 (unicast|multicast) community (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 "Exact match of the communities")
8183{
8184 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008185 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008186
Michael Lambert95cbbd22010-07-23 14:43:04 -04008187 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008188}
8189
8190ALIAS (show_ip_bgp_ipv4_community_exact,
8191 show_ip_bgp_ipv4_community2_exact_cmd,
8192 "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",
8193 SHOW_STR
8194 IP_STR
8195 BGP_STR
8196 "Address family\n"
8197 "Address Family modifier\n"
8198 "Address Family modifier\n"
8199 "Display routes matching the communities\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\n"
8204 "community number\n"
8205 "Do not send outside local AS (well-known community)\n"
8206 "Do not advertise to any peer (well-known community)\n"
8207 "Do not export to next AS (well-known community)\n"
8208 "Exact match of the communities")
8209
8210ALIAS (show_ip_bgp_ipv4_community_exact,
8211 show_ip_bgp_ipv4_community3_exact_cmd,
8212 "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",
8213 SHOW_STR
8214 IP_STR
8215 BGP_STR
8216 "Address family\n"
8217 "Address Family modifier\n"
8218 "Address Family modifier\n"
8219 "Display routes matching the communities\n"
8220 "community number\n"
8221 "Do not send outside local AS (well-known community)\n"
8222 "Do not advertise to any peer (well-known community)\n"
8223 "Do not export to next AS (well-known community)\n"
8224 "community number\n"
8225 "Do not send outside local AS (well-known community)\n"
8226 "Do not advertise to any peer (well-known community)\n"
8227 "Do not export to next AS (well-known community)\n"
8228 "community number\n"
8229 "Do not send outside local AS (well-known community)\n"
8230 "Do not advertise to any peer (well-known community)\n"
8231 "Do not export to next AS (well-known community)\n"
8232 "Exact match of the communities")
8233
8234ALIAS (show_ip_bgp_ipv4_community_exact,
8235 show_ip_bgp_ipv4_community4_exact_cmd,
8236 "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",
8237 SHOW_STR
8238 IP_STR
8239 BGP_STR
8240 "Address family\n"
8241 "Address Family modifier\n"
8242 "Address Family modifier\n"
8243 "Display routes matching the communities\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n"
8260 "Exact match of the communities")
8261
8262#ifdef HAVE_IPV6
8263DEFUN (show_bgp_community,
8264 show_bgp_community_cmd,
8265 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8266 SHOW_STR
8267 BGP_STR
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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008274 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008275}
8276
8277ALIAS (show_bgp_community,
8278 show_bgp_ipv6_community_cmd,
8279 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8280 SHOW_STR
8281 BGP_STR
8282 "Address family\n"
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
8289ALIAS (show_bgp_community,
8290 show_bgp_community2_cmd,
8291 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8292 SHOW_STR
8293 BGP_STR
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n")
8303
8304ALIAS (show_bgp_community,
8305 show_bgp_ipv6_community2_cmd,
8306 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8307 SHOW_STR
8308 BGP_STR
8309 "Address family\n"
8310 "Display routes matching the communities\n"
8311 "community number\n"
8312 "Do not send outside local AS (well-known community)\n"
8313 "Do not advertise to any peer (well-known community)\n"
8314 "Do not export to next AS (well-known community)\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n")
8319
8320ALIAS (show_bgp_community,
8321 show_bgp_community3_cmd,
8322 "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)",
8323 SHOW_STR
8324 BGP_STR
8325 "Display routes matching the communities\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n"
8330 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n"
8334 "community number\n"
8335 "Do not send outside local AS (well-known community)\n"
8336 "Do not advertise to any peer (well-known community)\n"
8337 "Do not export to next AS (well-known community)\n")
8338
8339ALIAS (show_bgp_community,
8340 show_bgp_ipv6_community3_cmd,
8341 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8342 SHOW_STR
8343 BGP_STR
8344 "Address family\n"
8345 "Display routes matching the communities\n"
8346 "community number\n"
8347 "Do not send outside local AS (well-known community)\n"
8348 "Do not advertise to any peer (well-known community)\n"
8349 "Do not export to next AS (well-known community)\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n")
8358
8359ALIAS (show_bgp_community,
8360 show_bgp_community4_cmd,
8361 "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)",
8362 SHOW_STR
8363 BGP_STR
8364 "Display routes matching the communities\n"
8365 "community number\n"
8366 "Do not send outside local AS (well-known community)\n"
8367 "Do not advertise to any peer (well-known community)\n"
8368 "Do not export to next AS (well-known community)\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n"
8373 "community number\n"
8374 "Do not send outside local AS (well-known community)\n"
8375 "Do not advertise to any peer (well-known community)\n"
8376 "Do not export to next AS (well-known community)\n"
8377 "community number\n"
8378 "Do not send outside local AS (well-known community)\n"
8379 "Do not advertise to any peer (well-known community)\n"
8380 "Do not export to next AS (well-known community)\n")
8381
8382ALIAS (show_bgp_community,
8383 show_bgp_ipv6_community4_cmd,
8384 "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)",
8385 SHOW_STR
8386 BGP_STR
8387 "Address family\n"
8388 "Display routes matching the communities\n"
8389 "community number\n"
8390 "Do not send outside local AS (well-known community)\n"
8391 "Do not advertise to any peer (well-known community)\n"
8392 "Do not export to next AS (well-known community)\n"
8393 "community number\n"
8394 "Do not send outside local AS (well-known community)\n"
8395 "Do not advertise to any peer (well-known community)\n"
8396 "Do not export to next AS (well-known community)\n"
8397 "community number\n"
8398 "Do not send outside local AS (well-known community)\n"
8399 "Do not advertise to any peer (well-known community)\n"
8400 "Do not export to next AS (well-known community)\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n")
8405
8406/* old command */
8407DEFUN (show_ipv6_bgp_community,
8408 show_ipv6_bgp_community_cmd,
8409 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8410 SHOW_STR
8411 IPV6_STR
8412 BGP_STR
8413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n")
8418{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008419 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008420}
8421
8422/* old command */
8423ALIAS (show_ipv6_bgp_community,
8424 show_ipv6_bgp_community2_cmd,
8425 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8426 SHOW_STR
8427 IPV6_STR
8428 BGP_STR
8429 "Display routes matching the communities\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
8439/* old command */
8440ALIAS (show_ipv6_bgp_community,
8441 show_ipv6_bgp_community3_cmd,
8442 "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)",
8443 SHOW_STR
8444 IPV6_STR
8445 BGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n")
8459
8460/* old command */
8461ALIAS (show_ipv6_bgp_community,
8462 show_ipv6_bgp_community4_cmd,
8463 "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)",
8464 SHOW_STR
8465 IPV6_STR
8466 BGP_STR
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "community number\n"
8481 "Do not send outside local AS (well-known community)\n"
8482 "Do not advertise to any peer (well-known community)\n"
8483 "Do not export to next AS (well-known community)\n")
8484
8485DEFUN (show_bgp_community_exact,
8486 show_bgp_community_exact_cmd,
8487 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8488 SHOW_STR
8489 BGP_STR
8490 "Display routes matching the communities\n"
8491 "community number\n"
8492 "Do not send outside local AS (well-known community)\n"
8493 "Do not advertise to any peer (well-known community)\n"
8494 "Do not export to next AS (well-known community)\n"
8495 "Exact match of the communities")
8496{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008497 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008498}
8499
8500ALIAS (show_bgp_community_exact,
8501 show_bgp_ipv6_community_exact_cmd,
8502 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8503 SHOW_STR
8504 BGP_STR
8505 "Address family\n"
8506 "Display routes matching the communities\n"
8507 "community number\n"
8508 "Do not send outside local AS (well-known community)\n"
8509 "Do not advertise to any peer (well-known community)\n"
8510 "Do not export to next AS (well-known community)\n"
8511 "Exact match of the communities")
8512
8513ALIAS (show_bgp_community_exact,
8514 show_bgp_community2_exact_cmd,
8515 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8516 SHOW_STR
8517 BGP_STR
8518 "Display routes matching the communities\n"
8519 "community number\n"
8520 "Do not send outside local AS (well-known community)\n"
8521 "Do not advertise to any peer (well-known community)\n"
8522 "Do not export to next AS (well-known community)\n"
8523 "community number\n"
8524 "Do not send outside local AS (well-known community)\n"
8525 "Do not advertise to any peer (well-known community)\n"
8526 "Do not export to next AS (well-known community)\n"
8527 "Exact match of the communities")
8528
8529ALIAS (show_bgp_community_exact,
8530 show_bgp_ipv6_community2_exact_cmd,
8531 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8532 SHOW_STR
8533 BGP_STR
8534 "Address family\n"
8535 "Display routes matching the communities\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n"
8540 "community number\n"
8541 "Do not send outside local AS (well-known community)\n"
8542 "Do not advertise to any peer (well-known community)\n"
8543 "Do not export to next AS (well-known community)\n"
8544 "Exact match of the communities")
8545
8546ALIAS (show_bgp_community_exact,
8547 show_bgp_community3_exact_cmd,
8548 "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",
8549 SHOW_STR
8550 BGP_STR
8551 "Display routes matching the communities\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "community number\n"
8557 "Do not send outside local AS (well-known community)\n"
8558 "Do not advertise to any peer (well-known community)\n"
8559 "Do not export to next AS (well-known community)\n"
8560 "community number\n"
8561 "Do not send outside local AS (well-known community)\n"
8562 "Do not advertise to any peer (well-known community)\n"
8563 "Do not export to next AS (well-known community)\n"
8564 "Exact match of the communities")
8565
8566ALIAS (show_bgp_community_exact,
8567 show_bgp_ipv6_community3_exact_cmd,
8568 "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",
8569 SHOW_STR
8570 BGP_STR
8571 "Address family\n"
8572 "Display routes matching the communities\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "community number\n"
8578 "Do not send outside local AS (well-known community)\n"
8579 "Do not advertise to any peer (well-known community)\n"
8580 "Do not export to next AS (well-known community)\n"
8581 "community number\n"
8582 "Do not send outside local AS (well-known community)\n"
8583 "Do not advertise to any peer (well-known community)\n"
8584 "Do not export to next AS (well-known community)\n"
8585 "Exact match of the communities")
8586
8587ALIAS (show_bgp_community_exact,
8588 show_bgp_community4_exact_cmd,
8589 "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",
8590 SHOW_STR
8591 BGP_STR
8592 "Display routes matching the communities\n"
8593 "community number\n"
8594 "Do not send outside local AS (well-known community)\n"
8595 "Do not advertise to any peer (well-known community)\n"
8596 "Do not export to next AS (well-known community)\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "Exact match of the communities")
8610
8611ALIAS (show_bgp_community_exact,
8612 show_bgp_ipv6_community4_exact_cmd,
8613 "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",
8614 SHOW_STR
8615 BGP_STR
8616 "Address family\n"
8617 "Display routes matching the communities\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n"
8626 "community number\n"
8627 "Do not send outside local AS (well-known community)\n"
8628 "Do not advertise to any peer (well-known community)\n"
8629 "Do not export to next AS (well-known community)\n"
8630 "community number\n"
8631 "Do not send outside local AS (well-known community)\n"
8632 "Do not advertise to any peer (well-known community)\n"
8633 "Do not export to next AS (well-known community)\n"
8634 "Exact match of the communities")
8635
8636/* old command */
8637DEFUN (show_ipv6_bgp_community_exact,
8638 show_ipv6_bgp_community_exact_cmd,
8639 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8640 SHOW_STR
8641 IPV6_STR
8642 BGP_STR
8643 "Display routes matching the communities\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "Exact match of the communities")
8649{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008650 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008651}
8652
8653/* old command */
8654ALIAS (show_ipv6_bgp_community_exact,
8655 show_ipv6_bgp_community2_exact_cmd,
8656 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8657 SHOW_STR
8658 IPV6_STR
8659 BGP_STR
8660 "Display routes matching the communities\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "Exact match of the communities")
8670
8671/* old command */
8672ALIAS (show_ipv6_bgp_community_exact,
8673 show_ipv6_bgp_community3_exact_cmd,
8674 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8675 SHOW_STR
8676 IPV6_STR
8677 BGP_STR
8678 "Display routes matching the communities\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n"
8687 "community number\n"
8688 "Do not send outside local AS (well-known community)\n"
8689 "Do not advertise to any peer (well-known community)\n"
8690 "Do not export to next AS (well-known community)\n"
8691 "Exact match of the communities")
8692
8693/* old command */
8694ALIAS (show_ipv6_bgp_community_exact,
8695 show_ipv6_bgp_community4_exact_cmd,
8696 "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",
8697 SHOW_STR
8698 IPV6_STR
8699 BGP_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 "community number\n"
8710 "Do not send outside local AS (well-known community)\n"
8711 "Do not advertise to any peer (well-known community)\n"
8712 "Do not export to next AS (well-known community)\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\n"
8717 "Exact match of the communities")
8718
8719/* old command */
8720DEFUN (show_ipv6_mbgp_community,
8721 show_ipv6_mbgp_community_cmd,
8722 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8723 SHOW_STR
8724 IPV6_STR
8725 MBGP_STR
8726 "Display routes matching the communities\n"
8727 "community number\n"
8728 "Do not send outside local AS (well-known community)\n"
8729 "Do not advertise to any peer (well-known community)\n"
8730 "Do not export to next AS (well-known community)\n")
8731{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008732 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008733}
8734
8735/* old command */
8736ALIAS (show_ipv6_mbgp_community,
8737 show_ipv6_mbgp_community2_cmd,
8738 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8739 SHOW_STR
8740 IPV6_STR
8741 MBGP_STR
8742 "Display routes matching the communities\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
8752/* old command */
8753ALIAS (show_ipv6_mbgp_community,
8754 show_ipv6_mbgp_community3_cmd,
8755 "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)",
8756 SHOW_STR
8757 IPV6_STR
8758 MBGP_STR
8759 "Display routes matching the communities\n"
8760 "community number\n"
8761 "Do not send outside local AS (well-known community)\n"
8762 "Do not advertise to any peer (well-known community)\n"
8763 "Do not export to next AS (well-known community)\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 "community number\n"
8769 "Do not send outside local AS (well-known community)\n"
8770 "Do not advertise to any peer (well-known community)\n"
8771 "Do not export to next AS (well-known community)\n")
8772
8773/* old command */
8774ALIAS (show_ipv6_mbgp_community,
8775 show_ipv6_mbgp_community4_cmd,
8776 "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)",
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 "community number\n"
8790 "Do not send outside local AS (well-known community)\n"
8791 "Do not advertise to any peer (well-known community)\n"
8792 "Do not export to next AS (well-known community)\n"
8793 "community number\n"
8794 "Do not send outside local AS (well-known community)\n"
8795 "Do not advertise to any peer (well-known community)\n"
8796 "Do not export to next AS (well-known community)\n")
8797
8798/* old command */
8799DEFUN (show_ipv6_mbgp_community_exact,
8800 show_ipv6_mbgp_community_exact_cmd,
8801 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8802 SHOW_STR
8803 IPV6_STR
8804 MBGP_STR
8805 "Display routes matching the communities\n"
8806 "community number\n"
8807 "Do not send outside local AS (well-known community)\n"
8808 "Do not advertise to any peer (well-known community)\n"
8809 "Do not export to next AS (well-known community)\n"
8810 "Exact match of the communities")
8811{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008812 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008813}
8814
8815/* old command */
8816ALIAS (show_ipv6_mbgp_community_exact,
8817 show_ipv6_mbgp_community2_exact_cmd,
8818 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8819 SHOW_STR
8820 IPV6_STR
8821 MBGP_STR
8822 "Display routes matching the communities\n"
8823 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\n"
8831 "Exact match of the communities")
8832
8833/* old command */
8834ALIAS (show_ipv6_mbgp_community_exact,
8835 show_ipv6_mbgp_community3_exact_cmd,
8836 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8837 SHOW_STR
8838 IPV6_STR
8839 MBGP_STR
8840 "Display routes matching the communities\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "community number\n"
8846 "Do not send outside local AS (well-known community)\n"
8847 "Do not advertise to any peer (well-known community)\n"
8848 "Do not export to next AS (well-known community)\n"
8849 "community number\n"
8850 "Do not send outside local AS (well-known community)\n"
8851 "Do not advertise to any peer (well-known community)\n"
8852 "Do not export to next AS (well-known community)\n"
8853 "Exact match of the communities")
8854
8855/* old command */
8856ALIAS (show_ipv6_mbgp_community_exact,
8857 show_ipv6_mbgp_community4_exact_cmd,
8858 "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",
8859 SHOW_STR
8860 IPV6_STR
8861 MBGP_STR
8862 "Display routes matching the communities\n"
8863 "community number\n"
8864 "Do not send outside local AS (well-known community)\n"
8865 "Do not advertise to any peer (well-known community)\n"
8866 "Do not export to next AS (well-known community)\n"
8867 "community number\n"
8868 "Do not send outside local AS (well-known community)\n"
8869 "Do not advertise to any peer (well-known community)\n"
8870 "Do not export to next AS (well-known community)\n"
8871 "community number\n"
8872 "Do not send outside local AS (well-known community)\n"
8873 "Do not advertise to any peer (well-known community)\n"
8874 "Do not export to next AS (well-known community)\n"
8875 "community number\n"
8876 "Do not send outside local AS (well-known community)\n"
8877 "Do not advertise to any peer (well-known community)\n"
8878 "Do not export to next AS (well-known community)\n"
8879 "Exact match of the communities")
8880#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008881
paul94f2b392005-06-28 12:44:16 +00008882static int
paulfd79ac92004-10-13 05:06:08 +00008883bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008884 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008885{
8886 struct community_list *list;
8887
hassofee6e4e2005-02-02 16:29:31 +00008888 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008889 if (list == NULL)
8890 {
8891 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8892 VTY_NEWLINE);
8893 return CMD_WARNING;
8894 }
8895
ajs5a646652004-11-05 01:25:55 +00008896 return bgp_show (vty, NULL, afi, safi,
8897 (exact ? bgp_show_type_community_list_exact :
8898 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008899}
8900
8901DEFUN (show_ip_bgp_community_list,
8902 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008903 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008904 SHOW_STR
8905 IP_STR
8906 BGP_STR
8907 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008908 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008909 "community-list name\n")
8910{
8911 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8912}
8913
8914DEFUN (show_ip_bgp_ipv4_community_list,
8915 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008916 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008917 SHOW_STR
8918 IP_STR
8919 BGP_STR
8920 "Address family\n"
8921 "Address Family modifier\n"
8922 "Address Family modifier\n"
8923 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008924 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008925 "community-list name\n")
8926{
8927 if (strncmp (argv[0], "m", 1) == 0)
8928 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8929
8930 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8931}
8932
8933DEFUN (show_ip_bgp_community_list_exact,
8934 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008935 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008936 SHOW_STR
8937 IP_STR
8938 BGP_STR
8939 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008940 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008941 "community-list name\n"
8942 "Exact match of the communities\n")
8943{
8944 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8945}
8946
8947DEFUN (show_ip_bgp_ipv4_community_list_exact,
8948 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008949 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008950 SHOW_STR
8951 IP_STR
8952 BGP_STR
8953 "Address family\n"
8954 "Address Family modifier\n"
8955 "Address Family modifier\n"
8956 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008957 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008958 "community-list name\n"
8959 "Exact match of the communities\n")
8960{
8961 if (strncmp (argv[0], "m", 1) == 0)
8962 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8963
8964 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8965}
8966
8967#ifdef HAVE_IPV6
8968DEFUN (show_bgp_community_list,
8969 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008970 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008971 SHOW_STR
8972 BGP_STR
8973 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008974 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008975 "community-list name\n")
8976{
8977 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8978}
8979
8980ALIAS (show_bgp_community_list,
8981 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008982 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008983 SHOW_STR
8984 BGP_STR
8985 "Address family\n"
8986 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008987 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008988 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008989
8990/* old command */
8991DEFUN (show_ipv6_bgp_community_list,
8992 show_ipv6_bgp_community_list_cmd,
8993 "show ipv6 bgp community-list WORD",
8994 SHOW_STR
8995 IPV6_STR
8996 BGP_STR
8997 "Display routes matching the community-list\n"
8998 "community-list name\n")
8999{
9000 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9001}
9002
9003/* old command */
9004DEFUN (show_ipv6_mbgp_community_list,
9005 show_ipv6_mbgp_community_list_cmd,
9006 "show ipv6 mbgp community-list WORD",
9007 SHOW_STR
9008 IPV6_STR
9009 MBGP_STR
9010 "Display routes matching the community-list\n"
9011 "community-list name\n")
9012{
9013 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9014}
9015
9016DEFUN (show_bgp_community_list_exact,
9017 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009018 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009019 SHOW_STR
9020 BGP_STR
9021 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009022 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009023 "community-list name\n"
9024 "Exact match of the communities\n")
9025{
9026 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9027}
9028
9029ALIAS (show_bgp_community_list_exact,
9030 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009031 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009032 SHOW_STR
9033 BGP_STR
9034 "Address family\n"
9035 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009036 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009037 "community-list name\n"
9038 "Exact match of the communities\n")
9039
9040/* old command */
9041DEFUN (show_ipv6_bgp_community_list_exact,
9042 show_ipv6_bgp_community_list_exact_cmd,
9043 "show ipv6 bgp community-list WORD exact-match",
9044 SHOW_STR
9045 IPV6_STR
9046 BGP_STR
9047 "Display routes matching the community-list\n"
9048 "community-list name\n"
9049 "Exact match of the communities\n")
9050{
9051 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9052}
9053
9054/* old command */
9055DEFUN (show_ipv6_mbgp_community_list_exact,
9056 show_ipv6_mbgp_community_list_exact_cmd,
9057 "show ipv6 mbgp community-list WORD exact-match",
9058 SHOW_STR
9059 IPV6_STR
9060 MBGP_STR
9061 "Display routes matching the community-list\n"
9062 "community-list name\n"
9063 "Exact match of the communities\n")
9064{
9065 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9066}
9067#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009068
paul94f2b392005-06-28 12:44:16 +00009069static int
paulfd79ac92004-10-13 05:06:08 +00009070bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009071 safi_t safi, enum bgp_show_type type)
9072{
9073 int ret;
9074 struct prefix *p;
9075
9076 p = prefix_new();
9077
9078 ret = str2prefix (prefix, p);
9079 if (! ret)
9080 {
9081 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9082 return CMD_WARNING;
9083 }
9084
ajs5a646652004-11-05 01:25:55 +00009085 ret = bgp_show (vty, NULL, afi, safi, type, p);
9086 prefix_free(p);
9087 return ret;
paul718e3742002-12-13 20:15:29 +00009088}
9089
9090DEFUN (show_ip_bgp_prefix_longer,
9091 show_ip_bgp_prefix_longer_cmd,
9092 "show ip bgp A.B.C.D/M longer-prefixes",
9093 SHOW_STR
9094 IP_STR
9095 BGP_STR
9096 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9097 "Display route and more specific routes\n")
9098{
9099 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9100 bgp_show_type_prefix_longer);
9101}
9102
9103DEFUN (show_ip_bgp_flap_prefix_longer,
9104 show_ip_bgp_flap_prefix_longer_cmd,
9105 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9106 SHOW_STR
9107 IP_STR
9108 BGP_STR
9109 "Display flap statistics of routes\n"
9110 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9111 "Display route and more specific routes\n")
9112{
9113 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9114 bgp_show_type_flap_prefix_longer);
9115}
9116
9117DEFUN (show_ip_bgp_ipv4_prefix_longer,
9118 show_ip_bgp_ipv4_prefix_longer_cmd,
9119 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9120 SHOW_STR
9121 IP_STR
9122 BGP_STR
9123 "Address family\n"
9124 "Address Family modifier\n"
9125 "Address Family modifier\n"
9126 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9127 "Display route and more specific routes\n")
9128{
9129 if (strncmp (argv[0], "m", 1) == 0)
9130 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9131 bgp_show_type_prefix_longer);
9132
9133 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9134 bgp_show_type_prefix_longer);
9135}
9136
9137DEFUN (show_ip_bgp_flap_address,
9138 show_ip_bgp_flap_address_cmd,
9139 "show ip bgp flap-statistics A.B.C.D",
9140 SHOW_STR
9141 IP_STR
9142 BGP_STR
9143 "Display flap statistics of routes\n"
9144 "Network in the BGP routing table to display\n")
9145{
9146 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9147 bgp_show_type_flap_address);
9148}
9149
9150DEFUN (show_ip_bgp_flap_prefix,
9151 show_ip_bgp_flap_prefix_cmd,
9152 "show ip bgp flap-statistics A.B.C.D/M",
9153 SHOW_STR
9154 IP_STR
9155 BGP_STR
9156 "Display flap statistics of routes\n"
9157 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9158{
9159 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9160 bgp_show_type_flap_prefix);
9161}
9162#ifdef HAVE_IPV6
9163DEFUN (show_bgp_prefix_longer,
9164 show_bgp_prefix_longer_cmd,
9165 "show bgp X:X::X:X/M longer-prefixes",
9166 SHOW_STR
9167 BGP_STR
9168 "IPv6 prefix <network>/<length>\n"
9169 "Display route and more specific routes\n")
9170{
9171 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9172 bgp_show_type_prefix_longer);
9173}
9174
9175ALIAS (show_bgp_prefix_longer,
9176 show_bgp_ipv6_prefix_longer_cmd,
9177 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9178 SHOW_STR
9179 BGP_STR
9180 "Address family\n"
9181 "IPv6 prefix <network>/<length>\n"
9182 "Display route and more specific routes\n")
9183
9184/* old command */
9185DEFUN (show_ipv6_bgp_prefix_longer,
9186 show_ipv6_bgp_prefix_longer_cmd,
9187 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9188 SHOW_STR
9189 IPV6_STR
9190 BGP_STR
9191 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9192 "Display route and more specific routes\n")
9193{
9194 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9195 bgp_show_type_prefix_longer);
9196}
9197
9198/* old command */
9199DEFUN (show_ipv6_mbgp_prefix_longer,
9200 show_ipv6_mbgp_prefix_longer_cmd,
9201 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9202 SHOW_STR
9203 IPV6_STR
9204 MBGP_STR
9205 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9206 "Display route and more specific routes\n")
9207{
9208 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9209 bgp_show_type_prefix_longer);
9210}
9211#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009212
paul94f2b392005-06-28 12:44:16 +00009213static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009214peer_lookup_in_view (struct vty *vty, const char *view_name,
9215 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009216{
9217 int ret;
9218 struct bgp *bgp;
9219 struct peer *peer;
9220 union sockunion su;
9221
9222 /* BGP structure lookup. */
9223 if (view_name)
9224 {
9225 bgp = bgp_lookup_by_name (view_name);
9226 if (! bgp)
9227 {
9228 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9229 return NULL;
9230 }
9231 }
paul5228ad22004-06-04 17:58:18 +00009232 else
paulbb46e942003-10-24 19:02:03 +00009233 {
9234 bgp = bgp_get_default ();
9235 if (! bgp)
9236 {
9237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9238 return NULL;
9239 }
9240 }
9241
9242 /* Get peer sockunion. */
9243 ret = str2sockunion (ip_str, &su);
9244 if (ret < 0)
9245 {
9246 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9247 return NULL;
9248 }
9249
9250 /* Peer structure lookup. */
9251 peer = peer_lookup (bgp, &su);
9252 if (! peer)
9253 {
9254 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9255 return NULL;
9256 }
9257
9258 return peer;
9259}
David Lamparter6b0655a2014-06-04 06:53:35 +02009260
Paul Jakma2815e612006-09-14 02:56:07 +00009261enum bgp_stats
9262{
9263 BGP_STATS_MAXBITLEN = 0,
9264 BGP_STATS_RIB,
9265 BGP_STATS_PREFIXES,
9266 BGP_STATS_TOTPLEN,
9267 BGP_STATS_UNAGGREGATEABLE,
9268 BGP_STATS_MAX_AGGREGATEABLE,
9269 BGP_STATS_AGGREGATES,
9270 BGP_STATS_SPACE,
9271 BGP_STATS_ASPATH_COUNT,
9272 BGP_STATS_ASPATH_MAXHOPS,
9273 BGP_STATS_ASPATH_TOTHOPS,
9274 BGP_STATS_ASPATH_MAXSIZE,
9275 BGP_STATS_ASPATH_TOTSIZE,
9276 BGP_STATS_ASN_HIGHEST,
9277 BGP_STATS_MAX,
9278};
paulbb46e942003-10-24 19:02:03 +00009279
Paul Jakma2815e612006-09-14 02:56:07 +00009280static const char *table_stats_strs[] =
9281{
9282 [BGP_STATS_PREFIXES] = "Total Prefixes",
9283 [BGP_STATS_TOTPLEN] = "Average prefix length",
9284 [BGP_STATS_RIB] = "Total Advertisements",
9285 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9286 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9287 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9288 [BGP_STATS_SPACE] = "Address space advertised",
9289 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9290 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9291 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9292 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9293 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9294 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9295 [BGP_STATS_MAX] = NULL,
9296};
9297
9298struct bgp_table_stats
9299{
9300 struct bgp_table *table;
9301 unsigned long long counts[BGP_STATS_MAX];
9302};
9303
9304#if 0
9305#define TALLY_SIGFIG 100000
9306static unsigned long
9307ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9308{
9309 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9310 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9311 unsigned long ret = newtot / count;
9312
9313 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9314 return ret + 1;
9315 else
9316 return ret;
9317}
9318#endif
9319
9320static int
9321bgp_table_stats_walker (struct thread *t)
9322{
9323 struct bgp_node *rn;
9324 struct bgp_node *top;
9325 struct bgp_table_stats *ts = THREAD_ARG (t);
9326 unsigned int space = 0;
9327
Paul Jakma53d9f672006-10-15 23:41:16 +00009328 if (!(top = bgp_table_top (ts->table)))
9329 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009330
9331 switch (top->p.family)
9332 {
9333 case AF_INET:
9334 space = IPV4_MAX_BITLEN;
9335 break;
9336 case AF_INET6:
9337 space = IPV6_MAX_BITLEN;
9338 break;
9339 }
9340
9341 ts->counts[BGP_STATS_MAXBITLEN] = space;
9342
9343 for (rn = top; rn; rn = bgp_route_next (rn))
9344 {
9345 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009346 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009347 unsigned int rinum = 0;
9348
9349 if (rn == top)
9350 continue;
9351
9352 if (!rn->info)
9353 continue;
9354
9355 ts->counts[BGP_STATS_PREFIXES]++;
9356 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9357
9358#if 0
9359 ts->counts[BGP_STATS_AVGPLEN]
9360 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9361 ts->counts[BGP_STATS_AVGPLEN],
9362 rn->p.prefixlen);
9363#endif
9364
9365 /* check if the prefix is included by any other announcements */
9366 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009367 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009368
9369 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009370 {
9371 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9372 /* announced address space */
9373 if (space)
9374 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9375 }
Paul Jakma2815e612006-09-14 02:56:07 +00009376 else if (prn->info)
9377 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9378
Paul Jakma2815e612006-09-14 02:56:07 +00009379 for (ri = rn->info; ri; ri = ri->next)
9380 {
9381 rinum++;
9382 ts->counts[BGP_STATS_RIB]++;
9383
9384 if (ri->attr &&
9385 (CHECK_FLAG (ri->attr->flag,
9386 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9387 ts->counts[BGP_STATS_AGGREGATES]++;
9388
9389 /* as-path stats */
9390 if (ri->attr && ri->attr->aspath)
9391 {
9392 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9393 unsigned int size = aspath_size (ri->attr->aspath);
9394 as_t highest = aspath_highest (ri->attr->aspath);
9395
9396 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9397
9398 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9399 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9400
9401 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9402 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9403
9404 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9405 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9406#if 0
9407 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9408 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9409 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9410 hops);
9411 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9412 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9413 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9414 size);
9415#endif
9416 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9417 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9418 }
9419 }
9420 }
9421 return 0;
9422}
9423
9424static int
9425bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9426{
9427 struct bgp_table_stats ts;
9428 unsigned int i;
9429
9430 if (!bgp->rib[afi][safi])
9431 {
9432 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9433 return CMD_WARNING;
9434 }
9435
9436 memset (&ts, 0, sizeof (ts));
9437 ts.table = bgp->rib[afi][safi];
9438 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9439
9440 vty_out (vty, "BGP %s RIB statistics%s%s",
9441 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9442
9443 for (i = 0; i < BGP_STATS_MAX; i++)
9444 {
9445 if (!table_stats_strs[i])
9446 continue;
9447
9448 switch (i)
9449 {
9450#if 0
9451 case BGP_STATS_ASPATH_AVGHOPS:
9452 case BGP_STATS_ASPATH_AVGSIZE:
9453 case BGP_STATS_AVGPLEN:
9454 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9455 vty_out (vty, "%12.2f",
9456 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9457 break;
9458#endif
9459 case BGP_STATS_ASPATH_TOTHOPS:
9460 case BGP_STATS_ASPATH_TOTSIZE:
9461 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9462 vty_out (vty, "%12.2f",
9463 ts.counts[i] ?
9464 (float)ts.counts[i] /
9465 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9466 : 0);
9467 break;
9468 case BGP_STATS_TOTPLEN:
9469 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9470 vty_out (vty, "%12.2f",
9471 ts.counts[i] ?
9472 (float)ts.counts[i] /
9473 (float)ts.counts[BGP_STATS_PREFIXES]
9474 : 0);
9475 break;
9476 case BGP_STATS_SPACE:
9477 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9478 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9479 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9480 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009481 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009482 vty_out (vty, "%12.2f%s",
9483 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009484 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009485 VTY_NEWLINE);
9486 vty_out (vty, "%30s: ", "/8 equivalent ");
9487 vty_out (vty, "%12.2f%s",
9488 (float)ts.counts[BGP_STATS_SPACE] /
9489 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9490 VTY_NEWLINE);
9491 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9492 break;
9493 vty_out (vty, "%30s: ", "/24 equivalent ");
9494 vty_out (vty, "%12.2f",
9495 (float)ts.counts[BGP_STATS_SPACE] /
9496 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9497 break;
9498 default:
9499 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9500 vty_out (vty, "%12llu", ts.counts[i]);
9501 }
9502
9503 vty_out (vty, "%s", VTY_NEWLINE);
9504 }
9505 return CMD_SUCCESS;
9506}
9507
9508static int
9509bgp_table_stats_vty (struct vty *vty, const char *name,
9510 const char *afi_str, const char *safi_str)
9511{
9512 struct bgp *bgp;
9513 afi_t afi;
9514 safi_t safi;
9515
9516 if (name)
9517 bgp = bgp_lookup_by_name (name);
9518 else
9519 bgp = bgp_get_default ();
9520
9521 if (!bgp)
9522 {
9523 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9524 return CMD_WARNING;
9525 }
9526 if (strncmp (afi_str, "ipv", 3) == 0)
9527 {
9528 if (strncmp (afi_str, "ipv4", 4) == 0)
9529 afi = AFI_IP;
9530 else if (strncmp (afi_str, "ipv6", 4) == 0)
9531 afi = AFI_IP6;
9532 else
9533 {
9534 vty_out (vty, "%% Invalid address family %s%s",
9535 afi_str, VTY_NEWLINE);
9536 return CMD_WARNING;
9537 }
9538 if (strncmp (safi_str, "m", 1) == 0)
9539 safi = SAFI_MULTICAST;
9540 else if (strncmp (safi_str, "u", 1) == 0)
9541 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009542 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9543 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009544 else
9545 {
9546 vty_out (vty, "%% Invalid subsequent address family %s%s",
9547 safi_str, VTY_NEWLINE);
9548 return CMD_WARNING;
9549 }
9550 }
9551 else
9552 {
9553 vty_out (vty, "%% Invalid address family %s%s",
9554 afi_str, VTY_NEWLINE);
9555 return CMD_WARNING;
9556 }
9557
Paul Jakma2815e612006-09-14 02:56:07 +00009558 return bgp_table_stats (vty, bgp, afi, safi);
9559}
9560
9561DEFUN (show_bgp_statistics,
9562 show_bgp_statistics_cmd,
9563 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9564 SHOW_STR
9565 BGP_STR
9566 "Address family\n"
9567 "Address family\n"
9568 "Address Family modifier\n"
9569 "Address Family modifier\n"
9570 "BGP RIB advertisement statistics\n")
9571{
9572 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9573}
9574
9575ALIAS (show_bgp_statistics,
9576 show_bgp_statistics_vpnv4_cmd,
9577 "show bgp (ipv4) (vpnv4) statistics",
9578 SHOW_STR
9579 BGP_STR
9580 "Address family\n"
9581 "Address Family modifier\n"
9582 "BGP RIB advertisement statistics\n")
9583
9584DEFUN (show_bgp_statistics_view,
9585 show_bgp_statistics_view_cmd,
9586 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9587 SHOW_STR
9588 BGP_STR
9589 "BGP view\n"
9590 "Address family\n"
9591 "Address family\n"
9592 "Address Family modifier\n"
9593 "Address Family modifier\n"
9594 "BGP RIB advertisement statistics\n")
9595{
9596 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9597}
9598
9599ALIAS (show_bgp_statistics_view,
9600 show_bgp_statistics_view_vpnv4_cmd,
9601 "show bgp view WORD (ipv4) (vpnv4) statistics",
9602 SHOW_STR
9603 BGP_STR
9604 "BGP view\n"
9605 "Address family\n"
9606 "Address Family modifier\n"
9607 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009608
Paul Jakmaff7924f2006-09-04 01:10:36 +00009609enum bgp_pcounts
9610{
9611 PCOUNT_ADJ_IN = 0,
9612 PCOUNT_DAMPED,
9613 PCOUNT_REMOVED,
9614 PCOUNT_HISTORY,
9615 PCOUNT_STALE,
9616 PCOUNT_VALID,
9617 PCOUNT_ALL,
9618 PCOUNT_COUNTED,
9619 PCOUNT_PFCNT, /* the figure we display to users */
9620 PCOUNT_MAX,
9621};
9622
9623static const char *pcount_strs[] =
9624{
9625 [PCOUNT_ADJ_IN] = "Adj-in",
9626 [PCOUNT_DAMPED] = "Damped",
9627 [PCOUNT_REMOVED] = "Removed",
9628 [PCOUNT_HISTORY] = "History",
9629 [PCOUNT_STALE] = "Stale",
9630 [PCOUNT_VALID] = "Valid",
9631 [PCOUNT_ALL] = "All RIB",
9632 [PCOUNT_COUNTED] = "PfxCt counted",
9633 [PCOUNT_PFCNT] = "Useable",
9634 [PCOUNT_MAX] = NULL,
9635};
9636
Paul Jakma2815e612006-09-14 02:56:07 +00009637struct peer_pcounts
9638{
9639 unsigned int count[PCOUNT_MAX];
9640 const struct peer *peer;
9641 const struct bgp_table *table;
9642};
9643
Paul Jakmaff7924f2006-09-04 01:10:36 +00009644static int
Paul Jakma2815e612006-09-14 02:56:07 +00009645bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646{
9647 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009648 struct peer_pcounts *pc = THREAD_ARG (t);
9649 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009650
Paul Jakma2815e612006-09-14 02:56:07 +00009651 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009652 {
9653 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009654 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009655
9656 for (ain = rn->adj_in; ain; ain = ain->next)
9657 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009658 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659
Paul Jakmaff7924f2006-09-04 01:10:36 +00009660 for (ri = rn->info; ri; ri = ri->next)
9661 {
9662 char buf[SU_ADDRSTRLEN];
9663
9664 if (ri->peer != peer)
9665 continue;
9666
Paul Jakma2815e612006-09-14 02:56:07 +00009667 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009668
9669 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009670 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009671 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009672 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009673 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009674 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009676 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009677 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009678 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009679 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009680 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009681
9682 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9683 {
Paul Jakma2815e612006-09-14 02:56:07 +00009684 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009685 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009686 plog_warn (peer->log,
9687 "%s [pcount] %s/%d is counted but flags 0x%x",
9688 peer->host,
9689 inet_ntop(rn->p.family, &rn->p.u.prefix,
9690 buf, SU_ADDRSTRLEN),
9691 rn->p.prefixlen,
9692 ri->flags);
9693 }
9694 else
9695 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009696 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009697 plog_warn (peer->log,
9698 "%s [pcount] %s/%d not counted but flags 0x%x",
9699 peer->host,
9700 inet_ntop(rn->p.family, &rn->p.u.prefix,
9701 buf, SU_ADDRSTRLEN),
9702 rn->p.prefixlen,
9703 ri->flags);
9704 }
9705 }
9706 }
Paul Jakma2815e612006-09-14 02:56:07 +00009707 return 0;
9708}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009709
Paul Jakma2815e612006-09-14 02:56:07 +00009710static int
9711bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9712{
9713 struct peer_pcounts pcounts = { .peer = peer };
9714 unsigned int i;
9715
9716 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9717 || !peer->bgp->rib[afi][safi])
9718 {
9719 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9720 return CMD_WARNING;
9721 }
9722
9723 memset (&pcounts, 0, sizeof(pcounts));
9724 pcounts.peer = peer;
9725 pcounts.table = peer->bgp->rib[afi][safi];
9726
9727 /* in-place call via thread subsystem so as to record execution time
9728 * stats for the thread-walk (i.e. ensure this can't be blamed on
9729 * on just vty_read()).
9730 */
9731 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9732
Paul Jakmaff7924f2006-09-04 01:10:36 +00009733 vty_out (vty, "Prefix counts for %s, %s%s",
9734 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9735 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9736 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9737 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9738
9739 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009740 vty_out (vty, "%20s: %-10d%s",
9741 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009742
Paul Jakma2815e612006-09-14 02:56:07 +00009743 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009744 {
9745 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9746 peer->host, VTY_NEWLINE);
9747 vty_out (vty, "Please report this bug, with the above command output%s",
9748 VTY_NEWLINE);
9749 }
9750
9751 return CMD_SUCCESS;
9752}
9753
9754DEFUN (show_ip_bgp_neighbor_prefix_counts,
9755 show_ip_bgp_neighbor_prefix_counts_cmd,
9756 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9757 SHOW_STR
9758 IP_STR
9759 BGP_STR
9760 "Detailed information on TCP and BGP neighbor connections\n"
9761 "Neighbor to display information about\n"
9762 "Neighbor to display information about\n"
9763 "Display detailed prefix count information\n")
9764{
9765 struct peer *peer;
9766
9767 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9768 if (! peer)
9769 return CMD_WARNING;
9770
9771 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9772}
9773
9774DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9775 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9776 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9777 SHOW_STR
9778 BGP_STR
9779 "Address family\n"
9780 "Detailed information on TCP and BGP neighbor connections\n"
9781 "Neighbor to display information about\n"
9782 "Neighbor to display information about\n"
9783 "Display detailed prefix count information\n")
9784{
9785 struct peer *peer;
9786
9787 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9788 if (! peer)
9789 return CMD_WARNING;
9790
9791 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9792}
9793
9794DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9795 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9796 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9797 SHOW_STR
9798 IP_STR
9799 BGP_STR
9800 "Address family\n"
9801 "Address Family modifier\n"
9802 "Address Family modifier\n"
9803 "Detailed information on TCP and BGP neighbor connections\n"
9804 "Neighbor to display information about\n"
9805 "Neighbor to display information about\n"
9806 "Display detailed prefix count information\n")
9807{
9808 struct peer *peer;
9809
9810 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9811 if (! peer)
9812 return CMD_WARNING;
9813
9814 if (strncmp (argv[0], "m", 1) == 0)
9815 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9816
9817 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9818}
9819
9820DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9821 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9822 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9823 SHOW_STR
9824 IP_STR
9825 BGP_STR
9826 "Address family\n"
9827 "Address Family modifier\n"
9828 "Address Family modifier\n"
9829 "Detailed information on TCP and BGP neighbor connections\n"
9830 "Neighbor to display information about\n"
9831 "Neighbor to display information about\n"
9832 "Display detailed prefix count information\n")
9833{
9834 struct peer *peer;
9835
9836 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9837 if (! peer)
9838 return CMD_WARNING;
9839
9840 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9841}
9842
9843
paul94f2b392005-06-28 12:44:16 +00009844static void
paul718e3742002-12-13 20:15:29 +00009845show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9846 int in)
9847{
9848 struct bgp_table *table;
9849 struct bgp_adj_in *ain;
9850 struct bgp_adj_out *adj;
9851 unsigned long output_count;
9852 struct bgp_node *rn;
9853 int header1 = 1;
9854 struct bgp *bgp;
9855 int header2 = 1;
9856
paulbb46e942003-10-24 19:02:03 +00009857 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009858
9859 if (! bgp)
9860 return;
9861
9862 table = bgp->rib[afi][safi];
9863
9864 output_count = 0;
9865
9866 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9867 PEER_STATUS_DEFAULT_ORIGINATE))
9868 {
9869 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 +00009870 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9871 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009872
9873 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9874 VTY_NEWLINE, VTY_NEWLINE);
9875 header1 = 0;
9876 }
9877
9878 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9879 if (in)
9880 {
9881 for (ain = rn->adj_in; ain; ain = ain->next)
9882 if (ain->peer == peer)
9883 {
9884 if (header1)
9885 {
9886 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 +00009887 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9888 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009889 header1 = 0;
9890 }
9891 if (header2)
9892 {
9893 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9894 header2 = 0;
9895 }
9896 if (ain->attr)
9897 {
9898 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9899 output_count++;
9900 }
9901 }
9902 }
9903 else
9904 {
9905 for (adj = rn->adj_out; adj; adj = adj->next)
9906 if (adj->peer == peer)
9907 {
9908 if (header1)
9909 {
9910 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 +00009911 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9912 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009913 header1 = 0;
9914 }
9915 if (header2)
9916 {
9917 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9918 header2 = 0;
9919 }
9920 if (adj->attr)
9921 {
9922 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9923 output_count++;
9924 }
9925 }
9926 }
9927
9928 if (output_count != 0)
9929 vty_out (vty, "%sTotal number of prefixes %ld%s",
9930 VTY_NEWLINE, output_count, VTY_NEWLINE);
9931}
9932
paul94f2b392005-06-28 12:44:16 +00009933static int
paulbb46e942003-10-24 19:02:03 +00009934peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9935{
paul718e3742002-12-13 20:15:29 +00009936 if (! peer || ! peer->afc[afi][safi])
9937 {
9938 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9939 return CMD_WARNING;
9940 }
9941
9942 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9943 {
9944 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9945 VTY_NEWLINE);
9946 return CMD_WARNING;
9947 }
9948
9949 show_adj_route (vty, peer, afi, safi, in);
9950
9951 return CMD_SUCCESS;
9952}
9953
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009954DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9955 show_ip_bgp_view_neighbor_advertised_route_cmd,
9956 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9957 SHOW_STR
9958 IP_STR
9959 BGP_STR
9960 "BGP view\n"
9961 "View name\n"
9962 "Detailed information on TCP and BGP neighbor connections\n"
9963 "Neighbor to display information about\n"
9964 "Neighbor to display information about\n"
9965 "Display the routes advertised to a BGP neighbor\n")
9966{
9967 struct peer *peer;
9968
9969 if (argc == 2)
9970 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9971 else
9972 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9973
9974 if (! peer)
9975 return CMD_WARNING;
9976
9977 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9978}
9979
9980ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009981 show_ip_bgp_neighbor_advertised_route_cmd,
9982 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9983 SHOW_STR
9984 IP_STR
9985 BGP_STR
9986 "Detailed information on TCP and BGP neighbor connections\n"
9987 "Neighbor to display information about\n"
9988 "Neighbor to display information about\n"
9989 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009990
9991DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9992 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9993 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9994 SHOW_STR
9995 IP_STR
9996 BGP_STR
9997 "Address family\n"
9998 "Address Family modifier\n"
9999 "Address Family modifier\n"
10000 "Detailed information on TCP and BGP neighbor connections\n"
10001 "Neighbor to display information about\n"
10002 "Neighbor to display information about\n"
10003 "Display the routes advertised to a BGP neighbor\n")
10004{
paulbb46e942003-10-24 19:02:03 +000010005 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010006
paulbb46e942003-10-24 19:02:03 +000010007 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10008 if (! peer)
10009 return CMD_WARNING;
10010
10011 if (strncmp (argv[0], "m", 1) == 0)
10012 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10013
10014 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010015}
10016
10017#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010018DEFUN (show_bgp_view_neighbor_advertised_route,
10019 show_bgp_view_neighbor_advertised_route_cmd,
10020 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10021 SHOW_STR
10022 BGP_STR
10023 "BGP view\n"
10024 "View name\n"
10025 "Detailed information on TCP and BGP neighbor connections\n"
10026 "Neighbor to display information about\n"
10027 "Neighbor to display information about\n"
10028 "Display the routes advertised to a BGP neighbor\n")
10029{
10030 struct peer *peer;
10031
10032 if (argc == 2)
10033 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10034 else
10035 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10036
10037 if (! peer)
10038 return CMD_WARNING;
10039
10040 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10041}
10042
10043ALIAS (show_bgp_view_neighbor_advertised_route,
10044 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10045 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10046 SHOW_STR
10047 BGP_STR
10048 "BGP view\n"
10049 "View name\n"
10050 "Address family\n"
10051 "Detailed information on TCP and BGP neighbor connections\n"
10052 "Neighbor to display information about\n"
10053 "Neighbor to display information about\n"
10054 "Display the routes advertised to a BGP neighbor\n")
10055
10056DEFUN (show_bgp_view_neighbor_received_routes,
10057 show_bgp_view_neighbor_received_routes_cmd,
10058 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10059 SHOW_STR
10060 BGP_STR
10061 "BGP view\n"
10062 "View name\n"
10063 "Detailed information on TCP and BGP neighbor connections\n"
10064 "Neighbor to display information about\n"
10065 "Neighbor to display information about\n"
10066 "Display the received routes from neighbor\n")
10067{
10068 struct peer *peer;
10069
10070 if (argc == 2)
10071 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10072 else
10073 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10074
10075 if (! peer)
10076 return CMD_WARNING;
10077
10078 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10079}
10080
10081ALIAS (show_bgp_view_neighbor_received_routes,
10082 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10083 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10084 SHOW_STR
10085 BGP_STR
10086 "BGP view\n"
10087 "View name\n"
10088 "Address family\n"
10089 "Detailed information on TCP and BGP neighbor connections\n"
10090 "Neighbor to display information about\n"
10091 "Neighbor to display information about\n"
10092 "Display the received routes from neighbor\n")
10093
10094ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010095 show_bgp_neighbor_advertised_route_cmd,
10096 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10097 SHOW_STR
10098 BGP_STR
10099 "Detailed information on TCP and BGP neighbor connections\n"
10100 "Neighbor to display information about\n"
10101 "Neighbor to display information about\n"
10102 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010103
10104ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010105 show_bgp_ipv6_neighbor_advertised_route_cmd,
10106 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10107 SHOW_STR
10108 BGP_STR
10109 "Address family\n"
10110 "Detailed information on TCP and BGP neighbor connections\n"
10111 "Neighbor to display information about\n"
10112 "Neighbor to display information about\n"
10113 "Display the routes advertised to a BGP neighbor\n")
10114
10115/* old command */
paulbb46e942003-10-24 19:02:03 +000010116ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010117 ipv6_bgp_neighbor_advertised_route_cmd,
10118 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10119 SHOW_STR
10120 IPV6_STR
10121 BGP_STR
10122 "Detailed information on TCP and BGP neighbor connections\n"
10123 "Neighbor to display information about\n"
10124 "Neighbor to display information about\n"
10125 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010126
paul718e3742002-12-13 20:15:29 +000010127/* old command */
10128DEFUN (ipv6_mbgp_neighbor_advertised_route,
10129 ipv6_mbgp_neighbor_advertised_route_cmd,
10130 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10131 SHOW_STR
10132 IPV6_STR
10133 MBGP_STR
10134 "Detailed information on TCP and BGP neighbor connections\n"
10135 "Neighbor to display information about\n"
10136 "Neighbor to display information about\n"
10137 "Display the routes advertised to a BGP neighbor\n")
10138{
paulbb46e942003-10-24 19:02:03 +000010139 struct peer *peer;
10140
10141 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10142 if (! peer)
10143 return CMD_WARNING;
10144
10145 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010146}
10147#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010148
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010149DEFUN (show_ip_bgp_view_neighbor_received_routes,
10150 show_ip_bgp_view_neighbor_received_routes_cmd,
10151 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10152 SHOW_STR
10153 IP_STR
10154 BGP_STR
10155 "BGP view\n"
10156 "View name\n"
10157 "Detailed information on TCP and BGP neighbor connections\n"
10158 "Neighbor to display information about\n"
10159 "Neighbor to display information about\n"
10160 "Display the received routes from neighbor\n")
10161{
10162 struct peer *peer;
10163
10164 if (argc == 2)
10165 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10166 else
10167 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10168
10169 if (! peer)
10170 return CMD_WARNING;
10171
10172 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10173}
10174
10175ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010176 show_ip_bgp_neighbor_received_routes_cmd,
10177 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10178 SHOW_STR
10179 IP_STR
10180 BGP_STR
10181 "Detailed information on TCP and BGP neighbor connections\n"
10182 "Neighbor to display information about\n"
10183 "Neighbor to display information about\n"
10184 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010185
10186DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10187 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10188 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10189 SHOW_STR
10190 IP_STR
10191 BGP_STR
10192 "Address family\n"
10193 "Address Family modifier\n"
10194 "Address Family modifier\n"
10195 "Detailed information on TCP and BGP neighbor connections\n"
10196 "Neighbor to display information about\n"
10197 "Neighbor to display information about\n"
10198 "Display the received routes from neighbor\n")
10199{
paulbb46e942003-10-24 19:02:03 +000010200 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010201
paulbb46e942003-10-24 19:02:03 +000010202 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10203 if (! peer)
10204 return CMD_WARNING;
10205
10206 if (strncmp (argv[0], "m", 1) == 0)
10207 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10208
10209 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010210}
10211
Michael Lambert95cbbd22010-07-23 14:43:04 -040010212DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10213 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10214#ifdef HAVE_IPV6
10215 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10216#else
10217 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10218#endif
10219 SHOW_STR
10220 BGP_STR
10221 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010222 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010223 "Address family\n"
10224#ifdef HAVE_IPV6
10225 "Address family\n"
10226#endif
10227 "Address family modifier\n"
10228 "Address family modifier\n"
10229 "Detailed information on TCP and BGP neighbor connections\n"
10230 "Neighbor to display information about\n"
10231 "Neighbor to display information about\n"
10232 "Display the advertised routes to neighbor\n"
10233 "Display the received routes from neighbor\n")
10234{
10235 int afi;
10236 int safi;
10237 int in;
10238 struct peer *peer;
10239
10240#ifdef HAVE_IPV6
10241 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10242#else
10243 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10244#endif
10245
10246 if (! peer)
10247 return CMD_WARNING;
10248
10249#ifdef HAVE_IPV6
10250 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10251 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10252 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10253#else
10254 afi = AFI_IP;
10255 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10256 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10257#endif
10258
10259 return peer_adj_routes (vty, peer, afi, safi, in);
10260}
10261
paul718e3742002-12-13 20:15:29 +000010262DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10263 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10264 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10265 SHOW_STR
10266 IP_STR
10267 BGP_STR
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[0], &su);
10280 if (ret < 0)
10281 {
10282 vty_out (vty, "Malformed address: %s%s", argv[0], 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 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10291 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10292 if (count)
10293 {
10294 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10295 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10296 }
10297
10298 return CMD_SUCCESS;
10299}
10300
10301DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10302 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10303 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10304 SHOW_STR
10305 IP_STR
10306 BGP_STR
10307 "Address family\n"
10308 "Address Family modifier\n"
10309 "Address Family modifier\n"
10310 "Detailed information on TCP and BGP neighbor connections\n"
10311 "Neighbor to display information about\n"
10312 "Neighbor to display information about\n"
10313 "Display information received from a BGP neighbor\n"
10314 "Display the prefixlist filter\n")
10315{
10316 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010317 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010318 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010319 int count, ret;
paul718e3742002-12-13 20:15:29 +000010320
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010321 ret = str2sockunion (argv[1], &su);
10322 if (ret < 0)
10323 {
10324 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
paul718e3742002-12-13 20:15:29 +000010327
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010328 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010329 if (! peer)
10330 return CMD_WARNING;
10331
10332 if (strncmp (argv[0], "m", 1) == 0)
10333 {
10334 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10335 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10336 if (count)
10337 {
10338 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10339 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10340 }
10341 }
10342 else
10343 {
10344 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10345 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10346 if (count)
10347 {
10348 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10349 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10350 }
10351 }
10352
10353 return CMD_SUCCESS;
10354}
10355
10356
10357#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010358ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010359 show_bgp_neighbor_received_routes_cmd,
10360 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10361 SHOW_STR
10362 BGP_STR
10363 "Detailed information on TCP and BGP neighbor connections\n"
10364 "Neighbor to display information about\n"
10365 "Neighbor to display information about\n"
10366 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010367
paulbb46e942003-10-24 19:02:03 +000010368ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010369 show_bgp_ipv6_neighbor_received_routes_cmd,
10370 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10371 SHOW_STR
10372 BGP_STR
10373 "Address family\n"
10374 "Detailed information on TCP and BGP neighbor connections\n"
10375 "Neighbor to display information about\n"
10376 "Neighbor to display information about\n"
10377 "Display the received routes from neighbor\n")
10378
10379DEFUN (show_bgp_neighbor_received_prefix_filter,
10380 show_bgp_neighbor_received_prefix_filter_cmd,
10381 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10382 SHOW_STR
10383 BGP_STR
10384 "Detailed information on TCP and BGP neighbor connections\n"
10385 "Neighbor to display information about\n"
10386 "Neighbor to display information about\n"
10387 "Display information received from a BGP neighbor\n"
10388 "Display the prefixlist filter\n")
10389{
10390 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010391 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010392 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010393 int count, ret;
paul718e3742002-12-13 20:15:29 +000010394
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010395 ret = str2sockunion (argv[0], &su);
10396 if (ret < 0)
10397 {
10398 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10399 return CMD_WARNING;
10400 }
paul718e3742002-12-13 20:15:29 +000010401
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010402 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010403 if (! peer)
10404 return CMD_WARNING;
10405
10406 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10407 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10408 if (count)
10409 {
10410 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10411 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10412 }
10413
10414 return CMD_SUCCESS;
10415}
10416
10417ALIAS (show_bgp_neighbor_received_prefix_filter,
10418 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10419 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10420 SHOW_STR
10421 BGP_STR
10422 "Address family\n"
10423 "Detailed information on TCP and BGP neighbor connections\n"
10424 "Neighbor to display information about\n"
10425 "Neighbor to display information about\n"
10426 "Display information received from a BGP neighbor\n"
10427 "Display the prefixlist filter\n")
10428
10429/* old command */
paulbb46e942003-10-24 19:02:03 +000010430ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010431 ipv6_bgp_neighbor_received_routes_cmd,
10432 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10433 SHOW_STR
10434 IPV6_STR
10435 BGP_STR
10436 "Detailed information on TCP and BGP neighbor connections\n"
10437 "Neighbor to display information about\n"
10438 "Neighbor to display information about\n"
10439 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010440
10441/* old command */
10442DEFUN (ipv6_mbgp_neighbor_received_routes,
10443 ipv6_mbgp_neighbor_received_routes_cmd,
10444 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10445 SHOW_STR
10446 IPV6_STR
10447 MBGP_STR
10448 "Detailed information on TCP and BGP neighbor connections\n"
10449 "Neighbor to display information about\n"
10450 "Neighbor to display information about\n"
10451 "Display the received routes from neighbor\n")
10452{
paulbb46e942003-10-24 19:02:03 +000010453 struct peer *peer;
10454
10455 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10456 if (! peer)
10457 return CMD_WARNING;
10458
10459 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010460}
paulbb46e942003-10-24 19:02:03 +000010461
10462DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10463 show_bgp_view_neighbor_received_prefix_filter_cmd,
10464 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10465 SHOW_STR
10466 BGP_STR
10467 "BGP view\n"
10468 "View name\n"
10469 "Detailed information on TCP and BGP neighbor connections\n"
10470 "Neighbor to display information about\n"
10471 "Neighbor to display information about\n"
10472 "Display information received from a BGP neighbor\n"
10473 "Display the prefixlist filter\n")
10474{
10475 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010476 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010477 struct peer *peer;
10478 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010479 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010480
10481 /* BGP structure lookup. */
10482 bgp = bgp_lookup_by_name (argv[0]);
10483 if (bgp == NULL)
10484 {
10485 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10486 return CMD_WARNING;
10487 }
10488
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010489 ret = str2sockunion (argv[1], &su);
10490 if (ret < 0)
10491 {
10492 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10493 return CMD_WARNING;
10494 }
paulbb46e942003-10-24 19:02:03 +000010495
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010496 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010497 if (! peer)
10498 return CMD_WARNING;
10499
10500 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10501 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10502 if (count)
10503 {
10504 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10505 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10506 }
10507
10508 return CMD_SUCCESS;
10509}
10510
10511ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10512 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10513 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10514 SHOW_STR
10515 BGP_STR
10516 "BGP view\n"
10517 "View name\n"
10518 "Address family\n"
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Display information received from a BGP neighbor\n"
10523 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010524#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010525
paul94f2b392005-06-28 12:44:16 +000010526static int
paulbb46e942003-10-24 19:02:03 +000010527bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010528 safi_t safi, enum bgp_show_type type)
10529{
paul718e3742002-12-13 20:15:29 +000010530 if (! peer || ! peer->afc[afi][safi])
10531 {
10532 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010533 return CMD_WARNING;
10534 }
10535
ajs5a646652004-11-05 01:25:55 +000010536 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010537}
10538
10539DEFUN (show_ip_bgp_neighbor_routes,
10540 show_ip_bgp_neighbor_routes_cmd,
10541 "show ip bgp neighbors (A.B.C.D|X:X::X:X) 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 routes learned 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_neighbor);
10558}
10559
10560DEFUN (show_ip_bgp_neighbor_flap,
10561 show_ip_bgp_neighbor_flap_cmd,
10562 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10563 SHOW_STR
10564 IP_STR
10565 BGP_STR
10566 "Detailed information on TCP and BGP neighbor connections\n"
10567 "Neighbor to display information about\n"
10568 "Neighbor to display information about\n"
10569 "Display flap statistics of the routes learned from neighbor\n")
10570{
paulbb46e942003-10-24 19:02:03 +000010571 struct peer *peer;
10572
10573 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10574 if (! peer)
10575 return CMD_WARNING;
10576
10577 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010578 bgp_show_type_flap_neighbor);
10579}
10580
10581DEFUN (show_ip_bgp_neighbor_damp,
10582 show_ip_bgp_neighbor_damp_cmd,
10583 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10584 SHOW_STR
10585 IP_STR
10586 BGP_STR
10587 "Detailed information on TCP and BGP neighbor connections\n"
10588 "Neighbor to display information about\n"
10589 "Neighbor to display information about\n"
10590 "Display the dampened routes received from neighbor\n")
10591{
paulbb46e942003-10-24 19:02:03 +000010592 struct peer *peer;
10593
10594 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10595 if (! peer)
10596 return CMD_WARNING;
10597
10598 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010599 bgp_show_type_damp_neighbor);
10600}
10601
10602DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10603 show_ip_bgp_ipv4_neighbor_routes_cmd,
10604 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10605 SHOW_STR
10606 IP_STR
10607 BGP_STR
10608 "Address family\n"
10609 "Address Family modifier\n"
10610 "Address Family modifier\n"
10611 "Detailed information on TCP and BGP neighbor connections\n"
10612 "Neighbor to display information about\n"
10613 "Neighbor to display information about\n"
10614 "Display routes learned from neighbor\n")
10615{
paulbb46e942003-10-24 19:02:03 +000010616 struct peer *peer;
10617
10618 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10619 if (! peer)
10620 return CMD_WARNING;
10621
paul718e3742002-12-13 20:15:29 +000010622 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010623 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010624 bgp_show_type_neighbor);
10625
paulbb46e942003-10-24 19:02:03 +000010626 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010627 bgp_show_type_neighbor);
10628}
paulbb46e942003-10-24 19:02:03 +000010629
paulfee0f4c2004-09-13 05:12:46 +000010630DEFUN (show_ip_bgp_view_rsclient,
10631 show_ip_bgp_view_rsclient_cmd,
10632 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10633 SHOW_STR
10634 IP_STR
10635 BGP_STR
10636 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010637 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010638 "Information about Route Server Client\n"
10639 NEIGHBOR_ADDR_STR)
10640{
10641 struct bgp_table *table;
10642 struct peer *peer;
10643
10644 if (argc == 2)
10645 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10646 else
10647 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10648
10649 if (! peer)
10650 return CMD_WARNING;
10651
10652 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10653 {
10654 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10655 VTY_NEWLINE);
10656 return CMD_WARNING;
10657 }
10658
10659 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10660 PEER_FLAG_RSERVER_CLIENT))
10661 {
10662 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10663 VTY_NEWLINE);
10664 return CMD_WARNING;
10665 }
10666
10667 table = peer->rib[AFI_IP][SAFI_UNICAST];
10668
ajs5a646652004-11-05 01:25:55 +000010669 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010670}
10671
10672ALIAS (show_ip_bgp_view_rsclient,
10673 show_ip_bgp_rsclient_cmd,
10674 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10675 SHOW_STR
10676 IP_STR
10677 BGP_STR
10678 "Information about Route Server Client\n"
10679 NEIGHBOR_ADDR_STR)
10680
Michael Lambert95cbbd22010-07-23 14:43:04 -040010681DEFUN (show_bgp_view_ipv4_safi_rsclient,
10682 show_bgp_view_ipv4_safi_rsclient_cmd,
10683 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10684 SHOW_STR
10685 BGP_STR
10686 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010687 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010688 "Address family\n"
10689 "Address Family modifier\n"
10690 "Address Family modifier\n"
10691 "Information about Route Server Client\n"
10692 NEIGHBOR_ADDR_STR)
10693{
10694 struct bgp_table *table;
10695 struct peer *peer;
10696 safi_t safi;
10697
10698 if (argc == 3) {
10699 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10700 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10701 } else {
10702 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10703 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10704 }
10705
10706 if (! peer)
10707 return CMD_WARNING;
10708
10709 if (! peer->afc[AFI_IP][safi])
10710 {
10711 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10712 VTY_NEWLINE);
10713 return CMD_WARNING;
10714 }
10715
10716 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10717 PEER_FLAG_RSERVER_CLIENT))
10718 {
10719 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10720 VTY_NEWLINE);
10721 return CMD_WARNING;
10722 }
10723
10724 table = peer->rib[AFI_IP][safi];
10725
10726 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10727}
10728
10729ALIAS (show_bgp_view_ipv4_safi_rsclient,
10730 show_bgp_ipv4_safi_rsclient_cmd,
10731 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10732 SHOW_STR
10733 BGP_STR
10734 "Address family\n"
10735 "Address Family modifier\n"
10736 "Address Family modifier\n"
10737 "Information about Route Server Client\n"
10738 NEIGHBOR_ADDR_STR)
10739
paulfee0f4c2004-09-13 05:12:46 +000010740DEFUN (show_ip_bgp_view_rsclient_route,
10741 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010742 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010743 SHOW_STR
10744 IP_STR
10745 BGP_STR
10746 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010747 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010748 "Information about Route Server Client\n"
10749 NEIGHBOR_ADDR_STR
10750 "Network in the BGP routing table to display\n")
10751{
10752 struct bgp *bgp;
10753 struct peer *peer;
10754
10755 /* BGP structure lookup. */
10756 if (argc == 3)
10757 {
10758 bgp = bgp_lookup_by_name (argv[0]);
10759 if (bgp == NULL)
10760 {
10761 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10762 return CMD_WARNING;
10763 }
10764 }
10765 else
10766 {
10767 bgp = bgp_get_default ();
10768 if (bgp == NULL)
10769 {
10770 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10771 return CMD_WARNING;
10772 }
10773 }
10774
10775 if (argc == 3)
10776 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10777 else
10778 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10779
10780 if (! peer)
10781 return CMD_WARNING;
10782
10783 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10784 {
10785 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10786 VTY_NEWLINE);
10787 return CMD_WARNING;
10788}
10789
10790 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10791 PEER_FLAG_RSERVER_CLIENT))
10792 {
10793 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10794 VTY_NEWLINE);
10795 return CMD_WARNING;
10796 }
10797
10798 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10799 (argc == 3) ? argv[2] : argv[1],
10800 AFI_IP, SAFI_UNICAST, NULL, 0);
10801}
10802
10803ALIAS (show_ip_bgp_view_rsclient_route,
10804 show_ip_bgp_rsclient_route_cmd,
10805 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10806 SHOW_STR
10807 IP_STR
10808 BGP_STR
10809 "Information about Route Server Client\n"
10810 NEIGHBOR_ADDR_STR
10811 "Network in the BGP routing table to display\n")
10812
Michael Lambert95cbbd22010-07-23 14:43:04 -040010813DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10814 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10815 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10816 SHOW_STR
10817 BGP_STR
10818 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010819 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010820 "Address family\n"
10821 "Address Family modifier\n"
10822 "Address Family modifier\n"
10823 "Information about Route Server Client\n"
10824 NEIGHBOR_ADDR_STR
10825 "Network in the BGP routing table to display\n")
10826{
10827 struct bgp *bgp;
10828 struct peer *peer;
10829 safi_t safi;
10830
10831 /* BGP structure lookup. */
10832 if (argc == 4)
10833 {
10834 bgp = bgp_lookup_by_name (argv[0]);
10835 if (bgp == NULL)
10836 {
10837 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10838 return CMD_WARNING;
10839 }
10840 }
10841 else
10842 {
10843 bgp = bgp_get_default ();
10844 if (bgp == NULL)
10845 {
10846 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10847 return CMD_WARNING;
10848 }
10849 }
10850
10851 if (argc == 4) {
10852 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10853 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10854 } else {
10855 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10856 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10857 }
10858
10859 if (! peer)
10860 return CMD_WARNING;
10861
10862 if (! peer->afc[AFI_IP][safi])
10863 {
10864 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10865 VTY_NEWLINE);
10866 return CMD_WARNING;
10867}
10868
10869 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10870 PEER_FLAG_RSERVER_CLIENT))
10871 {
10872 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10873 VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876
10877 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10878 (argc == 4) ? argv[3] : argv[2],
10879 AFI_IP, safi, NULL, 0);
10880}
10881
10882ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10883 show_bgp_ipv4_safi_rsclient_route_cmd,
10884 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10885 SHOW_STR
10886 BGP_STR
10887 "Address family\n"
10888 "Address Family modifier\n"
10889 "Address Family modifier\n"
10890 "Information about Route Server Client\n"
10891 NEIGHBOR_ADDR_STR
10892 "Network in the BGP routing table to display\n")
10893
paulfee0f4c2004-09-13 05:12:46 +000010894DEFUN (show_ip_bgp_view_rsclient_prefix,
10895 show_ip_bgp_view_rsclient_prefix_cmd,
10896 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10897 SHOW_STR
10898 IP_STR
10899 BGP_STR
10900 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010901 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010902 "Information about Route Server Client\n"
10903 NEIGHBOR_ADDR_STR
10904 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10905{
10906 struct bgp *bgp;
10907 struct peer *peer;
10908
10909 /* BGP structure lookup. */
10910 if (argc == 3)
10911 {
10912 bgp = bgp_lookup_by_name (argv[0]);
10913 if (bgp == NULL)
10914 {
10915 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10916 return CMD_WARNING;
10917 }
10918 }
10919 else
10920 {
10921 bgp = bgp_get_default ();
10922 if (bgp == NULL)
10923 {
10924 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10925 return CMD_WARNING;
10926 }
10927 }
10928
10929 if (argc == 3)
10930 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10931 else
10932 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10933
10934 if (! peer)
10935 return CMD_WARNING;
10936
10937 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10938 {
10939 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10940 VTY_NEWLINE);
10941 return CMD_WARNING;
10942}
10943
10944 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10945 PEER_FLAG_RSERVER_CLIENT))
10946{
10947 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10948 VTY_NEWLINE);
10949 return CMD_WARNING;
10950 }
10951
10952 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10953 (argc == 3) ? argv[2] : argv[1],
10954 AFI_IP, SAFI_UNICAST, NULL, 1);
10955}
10956
10957ALIAS (show_ip_bgp_view_rsclient_prefix,
10958 show_ip_bgp_rsclient_prefix_cmd,
10959 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10960 SHOW_STR
10961 IP_STR
10962 BGP_STR
10963 "Information about Route Server Client\n"
10964 NEIGHBOR_ADDR_STR
10965 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10966
Michael Lambert95cbbd22010-07-23 14:43:04 -040010967DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10968 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10969 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10970 SHOW_STR
10971 BGP_STR
10972 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010973 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010974 "Address family\n"
10975 "Address Family modifier\n"
10976 "Address Family modifier\n"
10977 "Information about Route Server Client\n"
10978 NEIGHBOR_ADDR_STR
10979 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10980{
10981 struct bgp *bgp;
10982 struct peer *peer;
10983 safi_t safi;
10984
10985 /* BGP structure lookup. */
10986 if (argc == 4)
10987 {
10988 bgp = bgp_lookup_by_name (argv[0]);
10989 if (bgp == NULL)
10990 {
10991 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10992 return CMD_WARNING;
10993 }
10994 }
10995 else
10996 {
10997 bgp = bgp_get_default ();
10998 if (bgp == NULL)
10999 {
11000 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11001 return CMD_WARNING;
11002 }
11003 }
11004
11005 if (argc == 4) {
11006 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11007 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11008 } else {
11009 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11010 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11011 }
11012
11013 if (! peer)
11014 return CMD_WARNING;
11015
11016 if (! peer->afc[AFI_IP][safi])
11017 {
11018 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11019 VTY_NEWLINE);
11020 return CMD_WARNING;
11021}
11022
11023 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11024 PEER_FLAG_RSERVER_CLIENT))
11025{
11026 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11027 VTY_NEWLINE);
11028 return CMD_WARNING;
11029 }
11030
11031 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11032 (argc == 4) ? argv[3] : argv[2],
11033 AFI_IP, safi, NULL, 1);
11034}
11035
11036ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11037 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11038 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11039 SHOW_STR
11040 BGP_STR
11041 "Address family\n"
11042 "Address Family modifier\n"
11043 "Address Family modifier\n"
11044 "Information about Route Server Client\n"
11045 NEIGHBOR_ADDR_STR
11046 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011047
paul718e3742002-12-13 20:15:29 +000011048#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011049DEFUN (show_bgp_view_neighbor_routes,
11050 show_bgp_view_neighbor_routes_cmd,
11051 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11052 SHOW_STR
11053 BGP_STR
11054 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011055 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011056 "Detailed information on TCP and BGP neighbor connections\n"
11057 "Neighbor to display information about\n"
11058 "Neighbor to display information about\n"
11059 "Display routes learned from neighbor\n")
11060{
11061 struct peer *peer;
11062
11063 if (argc == 2)
11064 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11065 else
11066 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11067
11068 if (! peer)
11069 return CMD_WARNING;
11070
11071 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11072 bgp_show_type_neighbor);
11073}
11074
11075ALIAS (show_bgp_view_neighbor_routes,
11076 show_bgp_view_ipv6_neighbor_routes_cmd,
11077 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11078 SHOW_STR
11079 BGP_STR
11080 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011081 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011082 "Address family\n"
11083 "Detailed information on TCP and BGP neighbor connections\n"
11084 "Neighbor to display information about\n"
11085 "Neighbor to display information about\n"
11086 "Display routes learned from neighbor\n")
11087
11088DEFUN (show_bgp_view_neighbor_damp,
11089 show_bgp_view_neighbor_damp_cmd,
11090 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11091 SHOW_STR
11092 BGP_STR
11093 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011094 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011095 "Detailed information on TCP and BGP neighbor connections\n"
11096 "Neighbor to display information about\n"
11097 "Neighbor to display information about\n"
11098 "Display the dampened routes received from neighbor\n")
11099{
11100 struct peer *peer;
11101
11102 if (argc == 2)
11103 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11104 else
11105 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11106
11107 if (! peer)
11108 return CMD_WARNING;
11109
11110 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11111 bgp_show_type_damp_neighbor);
11112}
11113
11114ALIAS (show_bgp_view_neighbor_damp,
11115 show_bgp_view_ipv6_neighbor_damp_cmd,
11116 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11117 SHOW_STR
11118 BGP_STR
11119 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011120 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011121 "Address family\n"
11122 "Detailed information on TCP and BGP neighbor connections\n"
11123 "Neighbor to display information about\n"
11124 "Neighbor to display information about\n"
11125 "Display the dampened routes received from neighbor\n")
11126
11127DEFUN (show_bgp_view_neighbor_flap,
11128 show_bgp_view_neighbor_flap_cmd,
11129 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11130 SHOW_STR
11131 BGP_STR
11132 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011133 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011134 "Detailed information on TCP and BGP neighbor connections\n"
11135 "Neighbor to display information about\n"
11136 "Neighbor to display information about\n"
11137 "Display flap statistics of the routes learned from neighbor\n")
11138{
11139 struct peer *peer;
11140
11141 if (argc == 2)
11142 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11143 else
11144 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11145
11146 if (! peer)
11147 return CMD_WARNING;
11148
11149 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11150 bgp_show_type_flap_neighbor);
11151}
11152
11153ALIAS (show_bgp_view_neighbor_flap,
11154 show_bgp_view_ipv6_neighbor_flap_cmd,
11155 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11156 SHOW_STR
11157 BGP_STR
11158 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011159 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011160 "Address family\n"
11161 "Detailed information on TCP and BGP neighbor connections\n"
11162 "Neighbor to display information about\n"
11163 "Neighbor to display information about\n"
11164 "Display flap statistics of the routes learned from neighbor\n")
11165
11166ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011167 show_bgp_neighbor_routes_cmd,
11168 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11169 SHOW_STR
11170 BGP_STR
11171 "Detailed information on TCP and BGP neighbor connections\n"
11172 "Neighbor to display information about\n"
11173 "Neighbor to display information about\n"
11174 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011175
paulbb46e942003-10-24 19:02:03 +000011176
11177ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011178 show_bgp_ipv6_neighbor_routes_cmd,
11179 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11180 SHOW_STR
11181 BGP_STR
11182 "Address family\n"
11183 "Detailed information on TCP and BGP neighbor connections\n"
11184 "Neighbor to display information about\n"
11185 "Neighbor to display information about\n"
11186 "Display routes learned from neighbor\n")
11187
11188/* old command */
paulbb46e942003-10-24 19:02:03 +000011189ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011190 ipv6_bgp_neighbor_routes_cmd,
11191 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11192 SHOW_STR
11193 IPV6_STR
11194 BGP_STR
11195 "Detailed information on TCP and BGP neighbor connections\n"
11196 "Neighbor to display information about\n"
11197 "Neighbor to display information about\n"
11198 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011199
11200/* old command */
11201DEFUN (ipv6_mbgp_neighbor_routes,
11202 ipv6_mbgp_neighbor_routes_cmd,
11203 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11204 SHOW_STR
11205 IPV6_STR
11206 MBGP_STR
11207 "Detailed information on TCP and BGP neighbor connections\n"
11208 "Neighbor to display information about\n"
11209 "Neighbor to display information about\n"
11210 "Display routes learned from neighbor\n")
11211{
paulbb46e942003-10-24 19:02:03 +000011212 struct peer *peer;
11213
11214 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11215 if (! peer)
11216 return CMD_WARNING;
11217
11218 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011219 bgp_show_type_neighbor);
11220}
paulbb46e942003-10-24 19:02:03 +000011221
11222ALIAS (show_bgp_view_neighbor_flap,
11223 show_bgp_neighbor_flap_cmd,
11224 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11225 SHOW_STR
11226 BGP_STR
11227 "Detailed information on TCP and BGP neighbor connections\n"
11228 "Neighbor to display information about\n"
11229 "Neighbor to display information about\n"
11230 "Display flap statistics of the routes learned from neighbor\n")
11231
11232ALIAS (show_bgp_view_neighbor_flap,
11233 show_bgp_ipv6_neighbor_flap_cmd,
11234 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11235 SHOW_STR
11236 BGP_STR
11237 "Address family\n"
11238 "Detailed information on TCP and BGP neighbor connections\n"
11239 "Neighbor to display information about\n"
11240 "Neighbor to display information about\n"
11241 "Display flap statistics of the routes learned from neighbor\n")
11242
11243ALIAS (show_bgp_view_neighbor_damp,
11244 show_bgp_neighbor_damp_cmd,
11245 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11246 SHOW_STR
11247 BGP_STR
11248 "Detailed information on TCP and BGP neighbor connections\n"
11249 "Neighbor to display information about\n"
11250 "Neighbor to display information about\n"
11251 "Display the dampened routes received from neighbor\n")
11252
11253ALIAS (show_bgp_view_neighbor_damp,
11254 show_bgp_ipv6_neighbor_damp_cmd,
11255 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11256 SHOW_STR
11257 BGP_STR
11258 "Address family\n"
11259 "Detailed information on TCP and BGP neighbor connections\n"
11260 "Neighbor to display information about\n"
11261 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011262 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011263
11264DEFUN (show_bgp_view_rsclient,
11265 show_bgp_view_rsclient_cmd,
11266 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11267 SHOW_STR
11268 BGP_STR
11269 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011270 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011271 "Information about Route Server Client\n"
11272 NEIGHBOR_ADDR_STR)
11273{
11274 struct bgp_table *table;
11275 struct peer *peer;
11276
11277 if (argc == 2)
11278 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11279 else
11280 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11281
11282 if (! peer)
11283 return CMD_WARNING;
11284
11285 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11286 {
11287 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11288 VTY_NEWLINE);
11289 return CMD_WARNING;
11290 }
11291
11292 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11293 PEER_FLAG_RSERVER_CLIENT))
11294 {
11295 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11296 VTY_NEWLINE);
11297 return CMD_WARNING;
11298 }
11299
11300 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11301
ajs5a646652004-11-05 01:25:55 +000011302 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011303}
11304
11305ALIAS (show_bgp_view_rsclient,
11306 show_bgp_rsclient_cmd,
11307 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11308 SHOW_STR
11309 BGP_STR
11310 "Information about Route Server Client\n"
11311 NEIGHBOR_ADDR_STR)
11312
Michael Lambert95cbbd22010-07-23 14:43:04 -040011313DEFUN (show_bgp_view_ipv6_safi_rsclient,
11314 show_bgp_view_ipv6_safi_rsclient_cmd,
11315 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11316 SHOW_STR
11317 BGP_STR
11318 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011319 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011320 "Address family\n"
11321 "Address Family modifier\n"
11322 "Address Family modifier\n"
11323 "Information about Route Server Client\n"
11324 NEIGHBOR_ADDR_STR)
11325{
11326 struct bgp_table *table;
11327 struct peer *peer;
11328 safi_t safi;
11329
11330 if (argc == 3) {
11331 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11332 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11333 } else {
11334 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11335 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11336 }
11337
11338 if (! peer)
11339 return CMD_WARNING;
11340
11341 if (! peer->afc[AFI_IP6][safi])
11342 {
11343 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11344 VTY_NEWLINE);
11345 return CMD_WARNING;
11346 }
11347
11348 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11349 PEER_FLAG_RSERVER_CLIENT))
11350 {
11351 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11352 VTY_NEWLINE);
11353 return CMD_WARNING;
11354 }
11355
11356 table = peer->rib[AFI_IP6][safi];
11357
11358 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11359}
11360
11361ALIAS (show_bgp_view_ipv6_safi_rsclient,
11362 show_bgp_ipv6_safi_rsclient_cmd,
11363 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11364 SHOW_STR
11365 BGP_STR
11366 "Address family\n"
11367 "Address Family modifier\n"
11368 "Address Family modifier\n"
11369 "Information about Route Server Client\n"
11370 NEIGHBOR_ADDR_STR)
11371
paulfee0f4c2004-09-13 05:12:46 +000011372DEFUN (show_bgp_view_rsclient_route,
11373 show_bgp_view_rsclient_route_cmd,
11374 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11375 SHOW_STR
11376 BGP_STR
11377 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011378 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011379 "Information about Route Server Client\n"
11380 NEIGHBOR_ADDR_STR
11381 "Network in the BGP routing table to display\n")
11382{
11383 struct bgp *bgp;
11384 struct peer *peer;
11385
11386 /* BGP structure lookup. */
11387 if (argc == 3)
11388 {
11389 bgp = bgp_lookup_by_name (argv[0]);
11390 if (bgp == NULL)
11391 {
11392 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11393 return CMD_WARNING;
11394 }
11395 }
11396 else
11397 {
11398 bgp = bgp_get_default ();
11399 if (bgp == NULL)
11400 {
11401 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11402 return CMD_WARNING;
11403 }
11404 }
11405
11406 if (argc == 3)
11407 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11408 else
11409 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11410
11411 if (! peer)
11412 return CMD_WARNING;
11413
11414 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11415 {
11416 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11417 VTY_NEWLINE);
11418 return CMD_WARNING;
11419 }
11420
11421 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11422 PEER_FLAG_RSERVER_CLIENT))
11423 {
11424 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11425 VTY_NEWLINE);
11426 return CMD_WARNING;
11427 }
11428
11429 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11430 (argc == 3) ? argv[2] : argv[1],
11431 AFI_IP6, SAFI_UNICAST, NULL, 0);
11432}
11433
11434ALIAS (show_bgp_view_rsclient_route,
11435 show_bgp_rsclient_route_cmd,
11436 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11437 SHOW_STR
11438 BGP_STR
11439 "Information about Route Server Client\n"
11440 NEIGHBOR_ADDR_STR
11441 "Network in the BGP routing table to display\n")
11442
Michael Lambert95cbbd22010-07-23 14:43:04 -040011443DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11444 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11445 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11446 SHOW_STR
11447 BGP_STR
11448 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011449 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011450 "Address family\n"
11451 "Address Family modifier\n"
11452 "Address Family modifier\n"
11453 "Information about Route Server Client\n"
11454 NEIGHBOR_ADDR_STR
11455 "Network in the BGP routing table to display\n")
11456{
11457 struct bgp *bgp;
11458 struct peer *peer;
11459 safi_t safi;
11460
11461 /* BGP structure lookup. */
11462 if (argc == 4)
11463 {
11464 bgp = bgp_lookup_by_name (argv[0]);
11465 if (bgp == NULL)
11466 {
11467 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11468 return CMD_WARNING;
11469 }
11470 }
11471 else
11472 {
11473 bgp = bgp_get_default ();
11474 if (bgp == NULL)
11475 {
11476 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11477 return CMD_WARNING;
11478 }
11479 }
11480
11481 if (argc == 4) {
11482 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11483 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11484 } else {
11485 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11486 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11487 }
11488
11489 if (! peer)
11490 return CMD_WARNING;
11491
11492 if (! peer->afc[AFI_IP6][safi])
11493 {
11494 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11495 VTY_NEWLINE);
11496 return CMD_WARNING;
11497}
11498
11499 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11500 PEER_FLAG_RSERVER_CLIENT))
11501 {
11502 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11503 VTY_NEWLINE);
11504 return CMD_WARNING;
11505 }
11506
11507 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11508 (argc == 4) ? argv[3] : argv[2],
11509 AFI_IP6, safi, NULL, 0);
11510}
11511
11512ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11513 show_bgp_ipv6_safi_rsclient_route_cmd,
11514 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11515 SHOW_STR
11516 BGP_STR
11517 "Address family\n"
11518 "Address Family modifier\n"
11519 "Address Family modifier\n"
11520 "Information about Route Server Client\n"
11521 NEIGHBOR_ADDR_STR
11522 "Network in the BGP routing table to display\n")
11523
paulfee0f4c2004-09-13 05:12:46 +000011524DEFUN (show_bgp_view_rsclient_prefix,
11525 show_bgp_view_rsclient_prefix_cmd,
11526 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11527 SHOW_STR
11528 BGP_STR
11529 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011530 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011531 "Information about Route Server Client\n"
11532 NEIGHBOR_ADDR_STR
11533 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11534{
11535 struct bgp *bgp;
11536 struct peer *peer;
11537
11538 /* BGP structure lookup. */
11539 if (argc == 3)
11540 {
11541 bgp = bgp_lookup_by_name (argv[0]);
11542 if (bgp == NULL)
11543 {
11544 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11545 return CMD_WARNING;
11546 }
11547 }
11548 else
11549 {
11550 bgp = bgp_get_default ();
11551 if (bgp == NULL)
11552 {
11553 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11554 return CMD_WARNING;
11555 }
11556 }
11557
11558 if (argc == 3)
11559 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11560 else
11561 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11562
11563 if (! peer)
11564 return CMD_WARNING;
11565
11566 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11567 {
11568 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11569 VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572
11573 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11574 PEER_FLAG_RSERVER_CLIENT))
11575 {
11576 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11577 VTY_NEWLINE);
11578 return CMD_WARNING;
11579 }
11580
11581 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11582 (argc == 3) ? argv[2] : argv[1],
11583 AFI_IP6, SAFI_UNICAST, NULL, 1);
11584}
11585
11586ALIAS (show_bgp_view_rsclient_prefix,
11587 show_bgp_rsclient_prefix_cmd,
11588 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11589 SHOW_STR
11590 BGP_STR
11591 "Information about Route Server Client\n"
11592 NEIGHBOR_ADDR_STR
11593 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11594
Michael Lambert95cbbd22010-07-23 14:43:04 -040011595DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11596 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11597 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11598 SHOW_STR
11599 BGP_STR
11600 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011601 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011602 "Address family\n"
11603 "Address Family modifier\n"
11604 "Address Family modifier\n"
11605 "Information about Route Server Client\n"
11606 NEIGHBOR_ADDR_STR
11607 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11608{
11609 struct bgp *bgp;
11610 struct peer *peer;
11611 safi_t safi;
11612
11613 /* BGP structure lookup. */
11614 if (argc == 4)
11615 {
11616 bgp = bgp_lookup_by_name (argv[0]);
11617 if (bgp == NULL)
11618 {
11619 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11620 return CMD_WARNING;
11621 }
11622 }
11623 else
11624 {
11625 bgp = bgp_get_default ();
11626 if (bgp == NULL)
11627 {
11628 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11629 return CMD_WARNING;
11630 }
11631 }
11632
11633 if (argc == 4) {
11634 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11635 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11636 } else {
11637 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11638 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11639 }
11640
11641 if (! peer)
11642 return CMD_WARNING;
11643
11644 if (! peer->afc[AFI_IP6][safi])
11645 {
11646 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11647 VTY_NEWLINE);
11648 return CMD_WARNING;
11649}
11650
11651 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11652 PEER_FLAG_RSERVER_CLIENT))
11653{
11654 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11655 VTY_NEWLINE);
11656 return CMD_WARNING;
11657 }
11658
11659 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11660 (argc == 4) ? argv[3] : argv[2],
11661 AFI_IP6, safi, NULL, 1);
11662}
11663
11664ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11665 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11666 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11667 SHOW_STR
11668 BGP_STR
11669 "Address family\n"
11670 "Address Family modifier\n"
11671 "Address Family modifier\n"
11672 "Information about Route Server Client\n"
11673 NEIGHBOR_ADDR_STR
11674 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11675
paul718e3742002-12-13 20:15:29 +000011676#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011677
paul718e3742002-12-13 20:15:29 +000011678struct bgp_table *bgp_distance_table;
11679
11680struct bgp_distance
11681{
11682 /* Distance value for the IP source prefix. */
11683 u_char distance;
11684
11685 /* Name of the access-list to be matched. */
11686 char *access_list;
11687};
11688
paul94f2b392005-06-28 12:44:16 +000011689static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011690bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011691{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011692 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011693}
11694
paul94f2b392005-06-28 12:44:16 +000011695static void
paul718e3742002-12-13 20:15:29 +000011696bgp_distance_free (struct bgp_distance *bdistance)
11697{
11698 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11699}
11700
paul94f2b392005-06-28 12:44:16 +000011701static int
paulfd79ac92004-10-13 05:06:08 +000011702bgp_distance_set (struct vty *vty, const char *distance_str,
11703 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011704{
11705 int ret;
11706 struct prefix_ipv4 p;
11707 u_char distance;
11708 struct bgp_node *rn;
11709 struct bgp_distance *bdistance;
11710
11711 ret = str2prefix_ipv4 (ip_str, &p);
11712 if (ret == 0)
11713 {
11714 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11715 return CMD_WARNING;
11716 }
11717
11718 distance = atoi (distance_str);
11719
11720 /* Get BGP distance node. */
11721 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11722 if (rn->info)
11723 {
11724 bdistance = rn->info;
11725 bgp_unlock_node (rn);
11726 }
11727 else
11728 {
11729 bdistance = bgp_distance_new ();
11730 rn->info = bdistance;
11731 }
11732
11733 /* Set distance value. */
11734 bdistance->distance = distance;
11735
11736 /* Reset access-list configuration. */
11737 if (bdistance->access_list)
11738 {
11739 free (bdistance->access_list);
11740 bdistance->access_list = NULL;
11741 }
11742 if (access_list_str)
11743 bdistance->access_list = strdup (access_list_str);
11744
11745 return CMD_SUCCESS;
11746}
11747
paul94f2b392005-06-28 12:44:16 +000011748static int
paulfd79ac92004-10-13 05:06:08 +000011749bgp_distance_unset (struct vty *vty, const char *distance_str,
11750 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011751{
11752 int ret;
11753 struct prefix_ipv4 p;
11754 u_char distance;
11755 struct bgp_node *rn;
11756 struct bgp_distance *bdistance;
11757
11758 ret = str2prefix_ipv4 (ip_str, &p);
11759 if (ret == 0)
11760 {
11761 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11762 return CMD_WARNING;
11763 }
11764
11765 distance = atoi (distance_str);
11766
11767 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11768 if (! rn)
11769 {
11770 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11771 return CMD_WARNING;
11772 }
11773
11774 bdistance = rn->info;
11775
11776 if (bdistance->access_list)
11777 free (bdistance->access_list);
11778 bgp_distance_free (bdistance);
11779
11780 rn->info = NULL;
11781 bgp_unlock_node (rn);
11782 bgp_unlock_node (rn);
11783
11784 return CMD_SUCCESS;
11785}
11786
paul718e3742002-12-13 20:15:29 +000011787/* Apply BGP information to distance method. */
11788u_char
11789bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11790{
11791 struct bgp_node *rn;
11792 struct prefix_ipv4 q;
11793 struct peer *peer;
11794 struct bgp_distance *bdistance;
11795 struct access_list *alist;
11796 struct bgp_static *bgp_static;
11797
11798 if (! bgp)
11799 return 0;
11800
11801 if (p->family != AF_INET)
11802 return 0;
11803
11804 peer = rinfo->peer;
11805
11806 if (peer->su.sa.sa_family != AF_INET)
11807 return 0;
11808
11809 memset (&q, 0, sizeof (struct prefix_ipv4));
11810 q.family = AF_INET;
11811 q.prefix = peer->su.sin.sin_addr;
11812 q.prefixlen = IPV4_MAX_BITLEN;
11813
11814 /* Check source address. */
11815 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11816 if (rn)
11817 {
11818 bdistance = rn->info;
11819 bgp_unlock_node (rn);
11820
11821 if (bdistance->access_list)
11822 {
11823 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11824 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11825 return bdistance->distance;
11826 }
11827 else
11828 return bdistance->distance;
11829 }
11830
11831 /* Backdoor check. */
11832 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11833 if (rn)
11834 {
11835 bgp_static = rn->info;
11836 bgp_unlock_node (rn);
11837
11838 if (bgp_static->backdoor)
11839 {
11840 if (bgp->distance_local)
11841 return bgp->distance_local;
11842 else
11843 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11844 }
11845 }
11846
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011847 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011848 {
11849 if (bgp->distance_ebgp)
11850 return bgp->distance_ebgp;
11851 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11852 }
11853 else
11854 {
11855 if (bgp->distance_ibgp)
11856 return bgp->distance_ibgp;
11857 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11858 }
11859}
11860
11861DEFUN (bgp_distance,
11862 bgp_distance_cmd,
11863 "distance bgp <1-255> <1-255> <1-255>",
11864 "Define an administrative distance\n"
11865 "BGP distance\n"
11866 "Distance for routes external to the AS\n"
11867 "Distance for routes internal to the AS\n"
11868 "Distance for local routes\n")
11869{
11870 struct bgp *bgp;
11871
11872 bgp = vty->index;
11873
11874 bgp->distance_ebgp = atoi (argv[0]);
11875 bgp->distance_ibgp = atoi (argv[1]);
11876 bgp->distance_local = atoi (argv[2]);
11877 return CMD_SUCCESS;
11878}
11879
11880DEFUN (no_bgp_distance,
11881 no_bgp_distance_cmd,
11882 "no distance bgp <1-255> <1-255> <1-255>",
11883 NO_STR
11884 "Define an administrative distance\n"
11885 "BGP distance\n"
11886 "Distance for routes external to the AS\n"
11887 "Distance for routes internal to the AS\n"
11888 "Distance for local routes\n")
11889{
11890 struct bgp *bgp;
11891
11892 bgp = vty->index;
11893
11894 bgp->distance_ebgp= 0;
11895 bgp->distance_ibgp = 0;
11896 bgp->distance_local = 0;
11897 return CMD_SUCCESS;
11898}
11899
11900ALIAS (no_bgp_distance,
11901 no_bgp_distance2_cmd,
11902 "no distance bgp",
11903 NO_STR
11904 "Define an administrative distance\n"
11905 "BGP distance\n")
11906
11907DEFUN (bgp_distance_source,
11908 bgp_distance_source_cmd,
11909 "distance <1-255> A.B.C.D/M",
11910 "Define an administrative distance\n"
11911 "Administrative distance\n"
11912 "IP source prefix\n")
11913{
11914 bgp_distance_set (vty, argv[0], argv[1], NULL);
11915 return CMD_SUCCESS;
11916}
11917
11918DEFUN (no_bgp_distance_source,
11919 no_bgp_distance_source_cmd,
11920 "no distance <1-255> A.B.C.D/M",
11921 NO_STR
11922 "Define an administrative distance\n"
11923 "Administrative distance\n"
11924 "IP source prefix\n")
11925{
11926 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11927 return CMD_SUCCESS;
11928}
11929
11930DEFUN (bgp_distance_source_access_list,
11931 bgp_distance_source_access_list_cmd,
11932 "distance <1-255> A.B.C.D/M WORD",
11933 "Define an administrative distance\n"
11934 "Administrative distance\n"
11935 "IP source prefix\n"
11936 "Access list name\n")
11937{
11938 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11939 return CMD_SUCCESS;
11940}
11941
11942DEFUN (no_bgp_distance_source_access_list,
11943 no_bgp_distance_source_access_list_cmd,
11944 "no distance <1-255> A.B.C.D/M WORD",
11945 NO_STR
11946 "Define an administrative distance\n"
11947 "Administrative distance\n"
11948 "IP source prefix\n"
11949 "Access list name\n")
11950{
11951 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11952 return CMD_SUCCESS;
11953}
David Lamparter6b0655a2014-06-04 06:53:35 +020011954
paul718e3742002-12-13 20:15:29 +000011955DEFUN (bgp_damp_set,
11956 bgp_damp_set_cmd,
11957 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11958 "BGP Specific commands\n"
11959 "Enable route-flap dampening\n"
11960 "Half-life time for the penalty\n"
11961 "Value to start reusing a route\n"
11962 "Value to start suppressing a route\n"
11963 "Maximum duration to suppress a stable route\n")
11964{
11965 struct bgp *bgp;
11966 int half = DEFAULT_HALF_LIFE * 60;
11967 int reuse = DEFAULT_REUSE;
11968 int suppress = DEFAULT_SUPPRESS;
11969 int max = 4 * half;
11970
11971 if (argc == 4)
11972 {
11973 half = atoi (argv[0]) * 60;
11974 reuse = atoi (argv[1]);
11975 suppress = atoi (argv[2]);
11976 max = atoi (argv[3]) * 60;
11977 }
11978 else if (argc == 1)
11979 {
11980 half = atoi (argv[0]) * 60;
11981 max = 4 * half;
11982 }
11983
11984 bgp = vty->index;
11985 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11986 half, reuse, suppress, max);
11987}
11988
11989ALIAS (bgp_damp_set,
11990 bgp_damp_set2_cmd,
11991 "bgp dampening <1-45>",
11992 "BGP Specific commands\n"
11993 "Enable route-flap dampening\n"
11994 "Half-life time for the penalty\n")
11995
11996ALIAS (bgp_damp_set,
11997 bgp_damp_set3_cmd,
11998 "bgp dampening",
11999 "BGP Specific commands\n"
12000 "Enable route-flap dampening\n")
12001
12002DEFUN (bgp_damp_unset,
12003 bgp_damp_unset_cmd,
12004 "no bgp dampening",
12005 NO_STR
12006 "BGP Specific commands\n"
12007 "Enable route-flap dampening\n")
12008{
12009 struct bgp *bgp;
12010
12011 bgp = vty->index;
12012 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12013}
12014
12015ALIAS (bgp_damp_unset,
12016 bgp_damp_unset2_cmd,
12017 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12018 NO_STR
12019 "BGP Specific commands\n"
12020 "Enable route-flap dampening\n"
12021 "Half-life time for the penalty\n"
12022 "Value to start reusing a route\n"
12023 "Value to start suppressing a route\n"
12024 "Maximum duration to suppress a stable route\n")
12025
12026DEFUN (show_ip_bgp_dampened_paths,
12027 show_ip_bgp_dampened_paths_cmd,
12028 "show ip bgp dampened-paths",
12029 SHOW_STR
12030 IP_STR
12031 BGP_STR
12032 "Display paths suppressed due to dampening\n")
12033{
ajs5a646652004-11-05 01:25:55 +000012034 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12035 NULL);
paul718e3742002-12-13 20:15:29 +000012036}
12037
12038DEFUN (show_ip_bgp_flap_statistics,
12039 show_ip_bgp_flap_statistics_cmd,
12040 "show ip bgp flap-statistics",
12041 SHOW_STR
12042 IP_STR
12043 BGP_STR
12044 "Display flap statistics of routes\n")
12045{
ajs5a646652004-11-05 01:25:55 +000012046 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12047 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012048}
David Lamparter6b0655a2014-06-04 06:53:35 +020012049
paul718e3742002-12-13 20:15:29 +000012050/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012051static int
paulfd79ac92004-10-13 05:06:08 +000012052bgp_clear_damp_route (struct vty *vty, const char *view_name,
12053 const char *ip_str, afi_t afi, safi_t safi,
12054 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012055{
12056 int ret;
12057 struct prefix match;
12058 struct bgp_node *rn;
12059 struct bgp_node *rm;
12060 struct bgp_info *ri;
12061 struct bgp_info *ri_temp;
12062 struct bgp *bgp;
12063 struct bgp_table *table;
12064
12065 /* BGP structure lookup. */
12066 if (view_name)
12067 {
12068 bgp = bgp_lookup_by_name (view_name);
12069 if (bgp == NULL)
12070 {
12071 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12072 return CMD_WARNING;
12073 }
12074 }
12075 else
12076 {
12077 bgp = bgp_get_default ();
12078 if (bgp == NULL)
12079 {
12080 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12081 return CMD_WARNING;
12082 }
12083 }
12084
12085 /* Check IP address argument. */
12086 ret = str2prefix (ip_str, &match);
12087 if (! ret)
12088 {
12089 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12090 return CMD_WARNING;
12091 }
12092
12093 match.family = afi2family (afi);
12094
12095 if (safi == SAFI_MPLS_VPN)
12096 {
12097 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12098 {
12099 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12100 continue;
12101
12102 if ((table = rn->info) != NULL)
12103 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012104 {
12105 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12106 {
12107 ri = rm->info;
12108 while (ri)
12109 {
12110 if (ri->extra && ri->extra->damp_info)
12111 {
12112 ri_temp = ri->next;
12113 bgp_damp_info_free (ri->extra->damp_info, 1);
12114 ri = ri_temp;
12115 }
12116 else
12117 ri = ri->next;
12118 }
12119 }
12120
12121 bgp_unlock_node (rm);
12122 }
paul718e3742002-12-13 20:15:29 +000012123 }
12124 }
12125 else
12126 {
12127 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012128 {
12129 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12130 {
12131 ri = rn->info;
12132 while (ri)
12133 {
12134 if (ri->extra && ri->extra->damp_info)
12135 {
12136 ri_temp = ri->next;
12137 bgp_damp_info_free (ri->extra->damp_info, 1);
12138 ri = ri_temp;
12139 }
12140 else
12141 ri = ri->next;
12142 }
12143 }
12144
12145 bgp_unlock_node (rn);
12146 }
paul718e3742002-12-13 20:15:29 +000012147 }
12148
12149 return CMD_SUCCESS;
12150}
12151
12152DEFUN (clear_ip_bgp_dampening,
12153 clear_ip_bgp_dampening_cmd,
12154 "clear ip bgp dampening",
12155 CLEAR_STR
12156 IP_STR
12157 BGP_STR
12158 "Clear route flap dampening information\n")
12159{
12160 bgp_damp_info_clean ();
12161 return CMD_SUCCESS;
12162}
12163
12164DEFUN (clear_ip_bgp_dampening_prefix,
12165 clear_ip_bgp_dampening_prefix_cmd,
12166 "clear ip bgp dampening A.B.C.D/M",
12167 CLEAR_STR
12168 IP_STR
12169 BGP_STR
12170 "Clear route flap dampening information\n"
12171 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12172{
12173 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12174 SAFI_UNICAST, NULL, 1);
12175}
12176
12177DEFUN (clear_ip_bgp_dampening_address,
12178 clear_ip_bgp_dampening_address_cmd,
12179 "clear ip bgp dampening A.B.C.D",
12180 CLEAR_STR
12181 IP_STR
12182 BGP_STR
12183 "Clear route flap dampening information\n"
12184 "Network to clear damping information\n")
12185{
12186 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12187 SAFI_UNICAST, NULL, 0);
12188}
12189
12190DEFUN (clear_ip_bgp_dampening_address_mask,
12191 clear_ip_bgp_dampening_address_mask_cmd,
12192 "clear ip bgp dampening A.B.C.D A.B.C.D",
12193 CLEAR_STR
12194 IP_STR
12195 BGP_STR
12196 "Clear route flap dampening information\n"
12197 "Network to clear damping information\n"
12198 "Network mask\n")
12199{
12200 int ret;
12201 char prefix_str[BUFSIZ];
12202
12203 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12204 if (! ret)
12205 {
12206 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12207 return CMD_WARNING;
12208 }
12209
12210 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12211 SAFI_UNICAST, NULL, 0);
12212}
David Lamparter6b0655a2014-06-04 06:53:35 +020012213
paul94f2b392005-06-28 12:44:16 +000012214static int
paul718e3742002-12-13 20:15:29 +000012215bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12216 afi_t afi, safi_t safi, int *write)
12217{
12218 struct bgp_node *prn;
12219 struct bgp_node *rn;
12220 struct bgp_table *table;
12221 struct prefix *p;
12222 struct prefix_rd *prd;
12223 struct bgp_static *bgp_static;
12224 u_int32_t label;
12225 char buf[SU_ADDRSTRLEN];
12226 char rdbuf[RD_ADDRSTRLEN];
12227
12228 /* Network configuration. */
12229 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12230 if ((table = prn->info) != NULL)
12231 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12232 if ((bgp_static = rn->info) != NULL)
12233 {
12234 p = &rn->p;
12235 prd = (struct prefix_rd *) &prn->p;
12236
12237 /* "address-family" display. */
12238 bgp_config_write_family_header (vty, afi, safi, write);
12239
12240 /* "network" configuration display. */
12241 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12242 label = decode_label (bgp_static->tag);
12243
12244 vty_out (vty, " network %s/%d rd %s tag %d",
12245 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12246 p->prefixlen,
12247 rdbuf, label);
12248 vty_out (vty, "%s", VTY_NEWLINE);
12249 }
12250 return 0;
12251}
12252
12253/* Configuration of static route announcement and aggregate
12254 information. */
12255int
12256bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12257 afi_t afi, safi_t safi, int *write)
12258{
12259 struct bgp_node *rn;
12260 struct prefix *p;
12261 struct bgp_static *bgp_static;
12262 struct bgp_aggregate *bgp_aggregate;
12263 char buf[SU_ADDRSTRLEN];
12264
12265 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12266 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12267
12268 /* Network configuration. */
12269 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12270 if ((bgp_static = rn->info) != NULL)
12271 {
12272 p = &rn->p;
12273
12274 /* "address-family" display. */
12275 bgp_config_write_family_header (vty, afi, safi, write);
12276
12277 /* "network" configuration display. */
12278 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12279 {
12280 u_int32_t destination;
12281 struct in_addr netmask;
12282
12283 destination = ntohl (p->u.prefix4.s_addr);
12284 masklen2ip (p->prefixlen, &netmask);
12285 vty_out (vty, " network %s",
12286 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12287
12288 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12289 || (IN_CLASSB (destination) && p->prefixlen == 16)
12290 || (IN_CLASSA (destination) && p->prefixlen == 8)
12291 || p->u.prefix4.s_addr == 0)
12292 {
12293 /* Natural mask is not display. */
12294 }
12295 else
12296 vty_out (vty, " mask %s", inet_ntoa (netmask));
12297 }
12298 else
12299 {
12300 vty_out (vty, " network %s/%d",
12301 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12302 p->prefixlen);
12303 }
12304
12305 if (bgp_static->rmap.name)
12306 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012307 else
12308 {
12309 if (bgp_static->backdoor)
12310 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012311 }
paul718e3742002-12-13 20:15:29 +000012312
12313 vty_out (vty, "%s", VTY_NEWLINE);
12314 }
12315
12316 /* Aggregate-address configuration. */
12317 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12318 if ((bgp_aggregate = rn->info) != NULL)
12319 {
12320 p = &rn->p;
12321
12322 /* "address-family" display. */
12323 bgp_config_write_family_header (vty, afi, safi, write);
12324
12325 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12326 {
12327 struct in_addr netmask;
12328
12329 masklen2ip (p->prefixlen, &netmask);
12330 vty_out (vty, " aggregate-address %s %s",
12331 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12332 inet_ntoa (netmask));
12333 }
12334 else
12335 {
12336 vty_out (vty, " aggregate-address %s/%d",
12337 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12338 p->prefixlen);
12339 }
12340
12341 if (bgp_aggregate->as_set)
12342 vty_out (vty, " as-set");
12343
12344 if (bgp_aggregate->summary_only)
12345 vty_out (vty, " summary-only");
12346
12347 vty_out (vty, "%s", VTY_NEWLINE);
12348 }
12349
12350 return 0;
12351}
12352
12353int
12354bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12355{
12356 struct bgp_node *rn;
12357 struct bgp_distance *bdistance;
12358
12359 /* Distance configuration. */
12360 if (bgp->distance_ebgp
12361 && bgp->distance_ibgp
12362 && bgp->distance_local
12363 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12364 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12365 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12366 vty_out (vty, " distance bgp %d %d %d%s",
12367 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12368 VTY_NEWLINE);
12369
12370 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12371 if ((bdistance = rn->info) != NULL)
12372 {
12373 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12374 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12375 bdistance->access_list ? bdistance->access_list : "",
12376 VTY_NEWLINE);
12377 }
12378
12379 return 0;
12380}
12381
12382/* Allocate routing table structure and install commands. */
12383void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012384bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012385{
12386 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012387 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012388
12389 /* IPv4 BGP commands. */
12390 install_element (BGP_NODE, &bgp_network_cmd);
12391 install_element (BGP_NODE, &bgp_network_mask_cmd);
12392 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12393 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12394 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12395 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12396 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12397 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12398 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12399 install_element (BGP_NODE, &no_bgp_network_cmd);
12400 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12401 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12402 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12403 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12404 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12405 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12406 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12407 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12408
12409 install_element (BGP_NODE, &aggregate_address_cmd);
12410 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12411 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12412 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12413 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12414 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12415 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12416 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12417 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12418 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12419 install_element (BGP_NODE, &no_aggregate_address_cmd);
12420 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12421 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12422 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12423 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12424 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12425 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12426 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12427 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12428 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12429
12430 /* IPv4 unicast configuration. */
12431 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12432 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12433 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12434 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12435 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12436 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012437 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012438 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12439 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12440 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12441 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12442 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012443
paul718e3742002-12-13 20:15:29 +000012444 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12445 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12446 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12447 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12448 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12449 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12450 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12451 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12452 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12453 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12454 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12455 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12456 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12457 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12458 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12459 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12460 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12461 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12462 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12463 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12464
12465 /* IPv4 multicast configuration. */
12466 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12467 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12468 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12469 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12470 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12471 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12476 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12477 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12478 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12479 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12480 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12481 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12482 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12483 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12484 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12485 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12486 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12487 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12488 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12489 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12490 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12491 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12492 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12493 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12494 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12495 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12496 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12497 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12498
12499 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012501 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012502 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012504 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012505 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012509 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012510 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012535 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12536 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12537 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12538 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12539 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012540 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012558 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012559 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12561 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12563 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12564 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12565 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12567 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12568 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12569 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12570 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12571 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12572 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12573 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12574 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012575 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012577 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012578 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012579 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012581 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12582 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012583 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012585 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012587 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012588 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012589
12590 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012593 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012594 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12595 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12596 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012597 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012598 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12599 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12608 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12609 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012610 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12611 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12612 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12613 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12614 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012615 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12616 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12617 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12618 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12619 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12620 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12621 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12622 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12623 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012624 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012625 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012627 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012628 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012629 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012630 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012631
12632 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012634 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012635 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012637 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012638 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012642 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012643 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012668 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12669 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12670 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12671 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12672 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012673 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012691 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012692 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12694 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12696 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12697 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12698 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12700 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12703 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12704 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12705 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12706 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12707 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012708 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012709 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012710 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012711 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012712 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012713 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012714 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12715 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012716 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012717 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012718 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012719 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012720 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012721 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012722
12723 /* BGP dampening clear commands */
12724 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12725 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12726 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12727 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12728
Paul Jakmaff7924f2006-09-04 01:10:36 +000012729 /* prefix count */
12730 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12731 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12732 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012733#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012734 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12735
paul718e3742002-12-13 20:15:29 +000012736 /* New config IPv6 BGP commands. */
12737 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12738 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12739 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12740 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12741
12742 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12743 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12744 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12745 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12746
G.Balaji73bfe0b2011-09-23 22:36:20 +053012747 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12748 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12749
paul718e3742002-12-13 20:15:29 +000012750 /* Old config IPv6 BGP commands. */
12751 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12752 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12753
12754 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12755 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12756 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12757 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12758
12759 install_element (VIEW_NODE, &show_bgp_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012761 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012762 install_element (VIEW_NODE, &show_bgp_route_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012764 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012765 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12766 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012767 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012768 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12770 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12772 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12774 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12776 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12778 install_element (VIEW_NODE, &show_bgp_community_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12780 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12782 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12784 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12786 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12788 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12790 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12792 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12794 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12796 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12797 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12798 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12799 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12800 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12801 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12802 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12803 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12804 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12805 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12806 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12807 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012808 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12809 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12810 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12811 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012812 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012813 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012814 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012815 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012816 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012817 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012818 install_element (VIEW_NODE, &show_bgp_view_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12820 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12821 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12822 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12823 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12824 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12825 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12830 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12831 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12832 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12833 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12834 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12835 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012836 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012838 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012840 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012842
12843 /* Restricted:
12844 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12845 */
12846 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012849 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012852 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12854 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12856 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12863 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12864 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12865 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12866 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12867 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12868 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012869 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012870 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012871 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012872 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12873 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12874 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12875 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12876 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12877 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12878 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012879 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012880 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012881 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012882
12883 install_element (ENABLE_NODE, &show_bgp_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012885 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012886 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012889 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012891 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012892 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012932 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012936 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012937 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012938 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012939 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012940 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012941 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012942 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12944 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12945 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12946 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12947 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12948 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12949 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12950 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12951 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12952 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12956 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12957 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12958 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12959 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012960 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012961 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012962 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012963 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012964 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012965 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012966
12967 /* Statistics */
12968 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12969 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12970 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12971 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12972
paul718e3742002-12-13 20:15:29 +000012973 /* old command */
12974 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12994 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12995 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12996 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12997 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12998 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12999 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13000 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13001 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13002 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13003 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13004 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13005 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13006 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13007 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13008 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13009 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013010
paul718e3742002-12-13 20:15:29 +000013011 /* old command */
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13032 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13033 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13034 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13035 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13036 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13037 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13038 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13039 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13040 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13041 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13042 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13045 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13046 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13047 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13048
13049 /* old command */
13050 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13051 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13052 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13053 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13054
13055 /* old command */
13056 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13057 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13058 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13059 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13060
13061 /* old command */
13062 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13063 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13064 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13065 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13066#endif /* HAVE_IPV6 */
13067
13068 install_element (BGP_NODE, &bgp_distance_cmd);
13069 install_element (BGP_NODE, &no_bgp_distance_cmd);
13070 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13071 install_element (BGP_NODE, &bgp_distance_source_cmd);
13072 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13073 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13074 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13075
13076 install_element (BGP_NODE, &bgp_damp_set_cmd);
13077 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13078 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13079 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13080 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13081 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13082 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13083 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13084 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13085 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013086
13087 /* Deprecated AS-Pathlimit commands */
13088 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13089 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13090 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13091 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13092 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13093 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13094
13095 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13096 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13097 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13098 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13099 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13100 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13101
13102 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13103 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13104 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13105 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13106 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13107 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13108
13109 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13110 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13111 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13112 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13113 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13114 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13115
13116 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13117 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13118 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13119 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13120 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13121 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13122
13123 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13124 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13125 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13126 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13127 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13128 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013129
13130#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013131 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13132 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013133#endif
paul718e3742002-12-13 20:15:29 +000013134}
Chris Caputo228da422009-07-18 05:44:03 +000013135
13136void
13137bgp_route_finish (void)
13138{
13139 bgp_table_unlock (bgp_distance_table);
13140 bgp_distance_table = NULL;
13141}