blob: 93c613fa14f59554777fc9121cf5eb3cbd3901f6 [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
Lou Berger298cc2f2016-01-12 13:42:02 -050074 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000075 {
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
Lou Berger298cc2f2016-01-12 13:42:02 -050087 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000088 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
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
325 * is preferred, or 0 if they are the same (usually will only occur if
326 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000327static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700328bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000329 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000330{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000331 struct attr *newattr, *existattr;
332 struct attr_extra *newattre, *existattre;
333 bgp_peer_sort_t new_sort;
334 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000335 u_int32_t new_pref;
336 u_int32_t exist_pref;
337 u_int32_t new_med;
338 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000339 u_int32_t new_weight;
340 u_int32_t exist_weight;
341 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000342 struct in_addr new_id;
343 struct in_addr exist_id;
344 int new_cluster;
345 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000346 int internal_as_route;
347 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000348 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700349
paul718e3742002-12-13 20:15:29 +0000350 /* 0. Null check. */
351 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000352 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000353 if (exist == NULL)
354 return -1;
paul718e3742002-12-13 20:15:29 +0000355
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000370 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000372 return 1;
paul718e3742002-12-13 20:15:29 +0000373
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000383 return -1;
paul718e3742002-12-13 20:15:29 +0000384 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000385 return 1;
paul718e3742002-12-13 20:15:29 +0000386
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000393 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000395 return 1;
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000411 return -1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000413 return 1;
hasso68118452005-04-08 15:40:36 +0000414 }
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000420 return -1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000422 return 1;
hasso68118452005-04-08 15:40:36 +0000423 }
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000428 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000430 return 1;
paul718e3742002-12-13 20:15:29 +0000431
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000451 return -1;
paul718e3742002-12-13 20:15:29 +0000452 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000453 return 1;
paul718e3742002-12-13 20:15:29 +0000454 }
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000465 return 1;
paul718e3742002-12-13 20:15:29 +0000466
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000478 return 1;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000481 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000485 /*
486 * For the two paths, all comparison steps till IGP metric
487 * have succeeded - including AS_PATH hop count. Since 'bgp
488 * bestpath as-path multipath-relax' knob is on, we don't need
489 * an exact match of AS_PATH. Thus, mark the paths are equal.
490 * That will trigger both these paths to get into the multipath
491 * array.
492 */
493 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000494 }
495 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 {
497 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
498 return 0;
499 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700500 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000501 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700502 }
paul718e3742002-12-13 20:15:29 +0000503
504 /* 10. If both paths are external, prefer the path that was received
505 first (the oldest one). This step minimizes route-flap, since a
506 newer path won't displace an older one, even if it was the
507 preferred route based on the additional decision criteria below. */
508 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000509 && new_sort == BGP_PEER_EBGP
510 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000511 {
512 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000513 return -1;
paul718e3742002-12-13 20:15:29 +0000514 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000515 return 1;
paul718e3742002-12-13 20:15:29 +0000516 }
517
vivekbd4b7f12014-09-30 15:54:45 -0700518 /* 11. Router-ID comparision. */
519 /* If one of the paths is "stale", the corresponding peer router-id will
520 * be 0 and would always win over the other path. If originator id is
521 * used for the comparision, it will decide which path is better.
522 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000523 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
524 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000525 else
526 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000527 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
528 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000529 else
530 exist_id.s_addr = exist->peer->remote_id.s_addr;
531
532 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000533 return -1;
paul718e3742002-12-13 20:15:29 +0000534 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000535 return 1;
paul718e3742002-12-13 20:15:29 +0000536
537 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000538 new_cluster = exist_cluster = 0;
539
540 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
541 new_cluster = newattre->cluster->length;
542 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
543 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000544
545 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000546 return -1;
paul718e3742002-12-13 20:15:29 +0000547 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000548 return 1;
paul718e3742002-12-13 20:15:29 +0000549
550 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700551 /* Do this only if neither path is "stale" as stale paths do not have
552 * valid peer information (as the connection may or may not be up).
553 */
554 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000555 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700556 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000557 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558 /* locally configured routes to advertise do not have su_remote */
559 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300560 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000561 if (exist->peer->su_remote == NULL)
562 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300563
paul718e3742002-12-13 20:15:29 +0000564 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
565
566 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000567 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000568 if (ret == -1)
569 return -1;
paul718e3742002-12-13 20:15:29 +0000570
Paul Jakma6d4742b2015-11-25 17:14:37 +0000571 return -1;
paul718e3742002-12-13 20:15:29 +0000572}
573
paul94f2b392005-06-28 12:44:16 +0000574static enum filter_type
paul718e3742002-12-13 20:15:29 +0000575bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
576 afi_t afi, safi_t safi)
577{
578 struct bgp_filter *filter;
579
580 filter = &peer->filter[afi][safi];
581
Paul Jakma650f76c2009-06-25 18:06:31 +0100582#define FILTER_EXIST_WARN(F,f,filter) \
583 if (BGP_DEBUG (update, UPDATE_IN) \
584 && !(F ## _IN (filter))) \
585 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
586 peer->host, #f, F ## _IN_NAME(filter));
587
588 if (DISTRIBUTE_IN_NAME (filter)) {
589 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
590
paul718e3742002-12-13 20:15:29 +0000591 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
592 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100593 }
paul718e3742002-12-13 20:15:29 +0000594
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 if (PREFIX_LIST_IN_NAME (filter)) {
596 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
597
paul718e3742002-12-13 20:15:29 +0000598 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
599 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600 }
paul718e3742002-12-13 20:15:29 +0000601
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 if (FILTER_LIST_IN_NAME (filter)) {
603 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
604
paul718e3742002-12-13 20:15:29 +0000605 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
606 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100607 }
608
paul718e3742002-12-13 20:15:29 +0000609 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100610#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000611}
612
paul94f2b392005-06-28 12:44:16 +0000613static enum filter_type
paul718e3742002-12-13 20:15:29 +0000614bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
615 afi_t afi, safi_t safi)
616{
617 struct bgp_filter *filter;
618
619 filter = &peer->filter[afi][safi];
620
Paul Jakma650f76c2009-06-25 18:06:31 +0100621#define FILTER_EXIST_WARN(F,f,filter) \
622 if (BGP_DEBUG (update, UPDATE_OUT) \
623 && !(F ## _OUT (filter))) \
624 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
625 peer->host, #f, F ## _OUT_NAME(filter));
626
627 if (DISTRIBUTE_OUT_NAME (filter)) {
628 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
629
paul718e3742002-12-13 20:15:29 +0000630 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
631 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100632 }
paul718e3742002-12-13 20:15:29 +0000633
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 if (PREFIX_LIST_OUT_NAME (filter)) {
635 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
636
paul718e3742002-12-13 20:15:29 +0000637 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
638 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100639 }
paul718e3742002-12-13 20:15:29 +0000640
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 if (FILTER_LIST_OUT_NAME (filter)) {
642 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
643
paul718e3742002-12-13 20:15:29 +0000644 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
645 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100646 }
paul718e3742002-12-13 20:15:29 +0000647
648 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100649#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000650}
651
652/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000653static int
paul718e3742002-12-13 20:15:29 +0000654bgp_community_filter (struct peer *peer, struct attr *attr)
655{
656 if (attr->community)
657 {
658 /* NO_ADVERTISE check. */
659 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
660 return 1;
661
662 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000664 community_include (attr->community, COMMUNITY_NO_EXPORT))
665 return 1;
666
667 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000668 if (peer->sort == BGP_PEER_EBGP
669 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000670 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
671 return 1;
672 }
673 return 0;
674}
675
676/* Route reflection loop check. */
677static int
678bgp_cluster_filter (struct peer *peer, struct attr *attr)
679{
680 struct in_addr cluster_id;
681
Paul Jakmafb982c22007-05-04 20:15:47 +0000682 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000683 {
684 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
685 cluster_id = peer->bgp->cluster_id;
686 else
687 cluster_id = peer->bgp->router_id;
688
Paul Jakmafb982c22007-05-04 20:15:47 +0000689 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000690 return 1;
691 }
692 return 0;
693}
David Lamparter6b0655a2014-06-04 06:53:35 +0200694
paul94f2b392005-06-28 12:44:16 +0000695static int
paul718e3742002-12-13 20:15:29 +0000696bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
697 afi_t afi, safi_t safi)
698{
699 struct bgp_filter *filter;
700 struct bgp_info info;
701 route_map_result_t ret;
702
703 filter = &peer->filter[afi][safi];
704
705 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000706 if (peer->weight)
707 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000708
709 /* Route map apply. */
710 if (ROUTE_MAP_IN_NAME (filter))
711 {
712 /* Duplicate current value to new strucutre for modification. */
713 info.peer = peer;
714 info.attr = attr;
715
paulac41b2a2003-08-12 05:32:27 +0000716 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
717
paul718e3742002-12-13 20:15:29 +0000718 /* Apply BGP route map to the attribute. */
719 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000720
721 peer->rmap_type = 0;
722
paul718e3742002-12-13 20:15:29 +0000723 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200724 /* caller has multiple error paths with bgp_attr_flush() */
725 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000726 }
727 return RMAP_PERMIT;
728}
David Lamparter6b0655a2014-06-04 06:53:35 +0200729
paul94f2b392005-06-28 12:44:16 +0000730static int
paulfee0f4c2004-09-13 05:12:46 +0000731bgp_export_modifier (struct peer *rsclient, struct peer *peer,
732 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
733{
734 struct bgp_filter *filter;
735 struct bgp_info info;
736 route_map_result_t ret;
737
738 filter = &peer->filter[afi][safi];
739
740 /* Route map apply. */
741 if (ROUTE_MAP_EXPORT_NAME (filter))
742 {
743 /* Duplicate current value to new strucutre for modification. */
744 info.peer = rsclient;
745 info.attr = attr;
746
747 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
748
749 /* Apply BGP route map to the attribute. */
750 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
751
752 rsclient->rmap_type = 0;
753
754 if (ret == RMAP_DENYMATCH)
755 {
756 /* Free newly generated AS path and community by route-map. */
757 bgp_attr_flush (attr);
758 return RMAP_DENY;
759 }
760 }
761 return RMAP_PERMIT;
762}
763
paul94f2b392005-06-28 12:44:16 +0000764static int
paulfee0f4c2004-09-13 05:12:46 +0000765bgp_import_modifier (struct peer *rsclient, struct peer *peer,
766 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
767{
768 struct bgp_filter *filter;
769 struct bgp_info info;
770 route_map_result_t ret;
771
772 filter = &rsclient->filter[afi][safi];
773
774 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000775 if (peer->weight)
776 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000777
778 /* Route map apply. */
779 if (ROUTE_MAP_IMPORT_NAME (filter))
780 {
781 /* Duplicate current value to new strucutre for modification. */
782 info.peer = peer;
783 info.attr = attr;
784
785 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
786
787 /* Apply BGP route map to the attribute. */
788 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
789
790 peer->rmap_type = 0;
791
792 if (ret == RMAP_DENYMATCH)
793 {
794 /* Free newly generated AS path and community by route-map. */
795 bgp_attr_flush (attr);
796 return RMAP_DENY;
797 }
798 }
799 return RMAP_PERMIT;
800}
David Lamparter6b0655a2014-06-04 06:53:35 +0200801
paul94f2b392005-06-28 12:44:16 +0000802static int
paul718e3742002-12-13 20:15:29 +0000803bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
804 struct attr *attr, afi_t afi, safi_t safi)
805{
806 int ret;
807 char buf[SU_ADDRSTRLEN];
808 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000809 struct peer *from;
810 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000811 int transparent;
812 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000814
815 from = ri->peer;
816 filter = &peer->filter[afi][safi];
817 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700818 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000819
Paul Jakma750e8142008-07-22 21:11:48 +0000820 if (DISABLE_BGP_ANNOUNCE)
821 return 0;
paul718e3742002-12-13 20:15:29 +0000822
paulfee0f4c2004-09-13 05:12:46 +0000823 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
824 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
825 return 0;
826
paul718e3742002-12-13 20:15:29 +0000827 /* Do not send back route to sender. */
828 if (from == peer)
829 return 0;
830
831 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000832 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000833 if (! UNSUPPRESS_MAP_NAME (filter))
834 return 0;
835
836 /* Default route check. */
837 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
838 {
839 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
840 return 0;
841#ifdef HAVE_IPV6
842 else if (p->family == AF_INET6 && p->prefixlen == 0)
843 return 0;
844#endif /* HAVE_IPV6 */
845 }
846
paul286e1e72003-08-08 00:24:31 +0000847 /* Transparency check. */
848 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
849 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
850 transparent = 1;
851 else
852 transparent = 0;
853
paul718e3742002-12-13 20:15:29 +0000854 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000856 return 0;
857
858 /* If the attribute has originator-id and it is same as remote
859 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700860 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000861 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700862 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000863 {
864 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000865 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000866 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
867 peer->host,
868 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
869 p->prefixlen);
870 return 0;
871 }
872 }
873
874 /* ORF prefix-list filter check */
875 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
876 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
877 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
878 if (peer->orf_plist[afi][safi])
879 {
880 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
881 return 0;
882 }
883
884 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700885 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000886 {
887 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000888 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000889 "%s [Update:SEND] %s/%d is filtered",
890 peer->host,
891 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
892 p->prefixlen);
893 return 0;
894 }
895
896#ifdef BGP_SEND_ASPATH_CHECK
897 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700898 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000899 {
900 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000901 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400902 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000903 peer->host, peer->as);
904 return 0;
905 }
906#endif /* BGP_SEND_ASPATH_CHECK */
907
908 /* If we're a CONFED we need to loop check the CONFED ID too */
909 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
910 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700911 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000912 {
913 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000914 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400915 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000916 peer->host,
917 bgp->confed_id);
918 return 0;
919 }
920 }
921
922 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000923 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000924 reflect = 1;
925 else
926 reflect = 0;
927
928 /* IBGP reflection check. */
929 if (reflect)
930 {
931 /* A route from a Client peer. */
932 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 {
934 /* Reflect to all the Non-Client peers and also to the
935 Client peers other than the originator. Originator check
936 is already done. So there is noting to do. */
937 /* no bgp client-to-client reflection check. */
938 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
939 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 else
943 {
944 /* A route from a Non-client peer. Reflect to all other
945 clients. */
946 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
947 return 0;
948 }
949 }
Paul Jakma41367172007-08-06 15:24:51 +0000950
paul718e3742002-12-13 20:15:29 +0000951 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700952 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000953
paul718e3742002-12-13 20:15:29 +0000954 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000955 if ((peer->sort == BGP_PEER_IBGP
956 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000957 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
958 {
959 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
960 attr->local_pref = bgp->default_local_pref;
961 }
962
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000963 /* If originator-id is not set and the route is to be reflected,
964 set the originator id */
965 if (peer && from && peer->sort == BGP_PEER_IBGP &&
966 from->sort == BGP_PEER_IBGP &&
967 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
968 {
969 attr->extra = bgp_attr_extra_get(attr);
970 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
971 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
972 }
973
paul718e3742002-12-13 20:15:29 +0000974 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000975 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000976 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
977 {
978 if (ri->peer != bgp->peer_self && ! transparent
979 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
980 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
981 }
982
Lou Berger298cc2f2016-01-12 13:42:02 -0500983
984#define NEXTHOP_IS_V4 (\
985 (safi != SAFI_ENCAP && p->family == AF_INET) || \
986 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
987
988#ifdef HAVE_IPV6
989#define NEXTHOP_IS_V6 (\
990 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
991 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
992#endif
993
paul718e3742002-12-13 20:15:29 +0000994 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300995 if (transparent
996 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000997 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000999#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001000 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001002#endif /* HAVE_IPV6 */
1003 )))
paul718e3742002-12-13 20:15:29 +00001004 {
1005 /* NEXT-HOP Unchanged. */
1006 }
1007 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -05001008 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
paul718e3742002-12-13 20:15:29 +00001009#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001010 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001012#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001013 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001014 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1015 {
1016 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001017 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001018 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001019 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1021 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001022 else
1023 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1024 }
1025#ifdef HAVE_IPV6
1026 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001027 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001028 {
1029 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001031 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001032 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001033 }
1034#endif /* HAVE_IPV6 */
1035 }
1036
1037#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001038 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001039 {
paulfee0f4c2004-09-13 05:12:46 +00001040 /* Left nexthop_local unchanged if so configured. */
1041 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1042 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1045 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001046 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001048 }
1049
1050 /* Default nexthop_local treatment for non-RS-Clients */
1051 else
1052 {
paul718e3742002-12-13 20:15:29 +00001053 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001054 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001055
1056 /* Set link-local address for shared network peer. */
1057 if (peer->shared_network
1058 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1059 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001061 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001062 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001063 }
1064
1065 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1066 address.*/
1067 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001068 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001069
1070 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1071 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001072 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001073 }
paulfee0f4c2004-09-13 05:12:46 +00001074
1075 }
paul718e3742002-12-13 20:15:29 +00001076#endif /* HAVE_IPV6 */
1077
1078 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001079 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001080 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1081 && aspath_private_as_check (attr->aspath))
1082 attr->aspath = aspath_empty_get ();
1083
1084 /* Route map & unsuppress-map apply. */
1085 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001087 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001088 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001089 struct attr dummy_attr;
1090 struct attr_extra dummy_extra;
1091
1092 dummy_attr.extra = &dummy_extra;
1093
paul718e3742002-12-13 20:15:29 +00001094 info.peer = peer;
1095 info.attr = attr;
1096
1097 /* The route reflector is not allowed to modify the attributes
1098 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001099 if (from->sort == BGP_PEER_IBGP
1100 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001101 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001102 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001103 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001104 }
paulac41b2a2003-08-12 05:32:27 +00001105
1106 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1107
Paul Jakmafb982c22007-05-04 20:15:47 +00001108 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001109 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1110 else
1111 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1112
paulac41b2a2003-08-12 05:32:27 +00001113 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001114
paul718e3742002-12-13 20:15:29 +00001115 if (ret == RMAP_DENYMATCH)
1116 {
1117 bgp_attr_flush (attr);
1118 return 0;
1119 }
1120 }
1121 return 1;
1122}
1123
paul94f2b392005-06-28 12:44:16 +00001124static int
paulfee0f4c2004-09-13 05:12:46 +00001125bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1126 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001127{
paulfee0f4c2004-09-13 05:12:46 +00001128 int ret;
1129 char buf[SU_ADDRSTRLEN];
1130 struct bgp_filter *filter;
1131 struct bgp_info info;
1132 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001133 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 from = ri->peer;
1136 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001138
Paul Jakma750e8142008-07-22 21:11:48 +00001139 if (DISABLE_BGP_ANNOUNCE)
1140 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001141
1142 /* Do not send back route to sender. */
1143 if (from == rsclient)
1144 return 0;
1145
1146 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001147 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001148 if (! UNSUPPRESS_MAP_NAME (filter))
1149 return 0;
1150
1151 /* Default route check. */
1152 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1153 PEER_STATUS_DEFAULT_ORIGINATE))
1154 {
1155 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1156 return 0;
1157#ifdef HAVE_IPV6
1158 else if (p->family == AF_INET6 && p->prefixlen == 0)
1159 return 0;
1160#endif /* HAVE_IPV6 */
1161 }
1162
1163 /* If the attribute has originator-id and it is same as remote
1164 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001165 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001166 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001167 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001168 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001169 {
1170 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001171 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001172 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1173 rsclient->host,
1174 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1175 p->prefixlen);
1176 return 0;
1177 }
1178 }
1179
1180 /* ORF prefix-list filter check */
1181 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1182 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1183 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1184 if (rsclient->orf_plist[afi][safi])
1185 {
1186 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1187 return 0;
1188 }
1189
1190 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001191 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001192 {
1193 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001194 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001195 "%s [Update:SEND] %s/%d is filtered",
1196 rsclient->host,
1197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1198 p->prefixlen);
1199 return 0;
1200 }
1201
1202#ifdef BGP_SEND_ASPATH_CHECK
1203 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001204 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001205 {
1206 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001207 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001208 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001209 rsclient->host, rsclient->as);
1210 return 0;
1211 }
1212#endif /* BGP_SEND_ASPATH_CHECK */
1213
1214 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001215 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001216
1217 /* next-hop-set */
1218 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1219#ifdef HAVE_IPV6
1220 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001222#endif /* HAVE_IPV6 */
1223 )
1224 {
1225 /* Set IPv4 nexthop. */
1226 if (p->family == AF_INET)
1227 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001228 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001229 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001230 IPV4_MAX_BYTELEN);
1231 else
1232 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1233 }
1234#ifdef HAVE_IPV6
1235 /* Set IPv6 nexthop. */
1236 if (p->family == AF_INET6)
1237 {
1238 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001240 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001241 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001242 }
1243#endif /* HAVE_IPV6 */
1244 }
1245
1246#ifdef HAVE_IPV6
1247 if (p->family == AF_INET6)
1248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001250
paulfee0f4c2004-09-13 05:12:46 +00001251 /* Left nexthop_local unchanged if so configured. */
1252 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1253 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1256 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001257 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001259 }
1260
1261 /* Default nexthop_local treatment for RS-Clients */
1262 else
1263 {
1264 /* Announcer and RS-Client are both in the same network */
1265 if (rsclient->shared_network && from->shared_network &&
1266 (rsclient->ifindex == from->ifindex))
1267 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001268 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1269 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001270 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001272 }
1273
1274 /* Set link-local address for shared network peer. */
1275 else if (rsclient->shared_network
1276 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1277 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001279 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001280 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001281 }
1282
1283 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001284 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001285 }
1286
1287 }
1288#endif /* HAVE_IPV6 */
1289
1290
1291 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001292 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001293 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1294 && aspath_private_as_check (attr->aspath))
1295 attr->aspath = aspath_empty_get ();
1296
1297 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001299 {
1300 info.peer = rsclient;
1301 info.attr = attr;
1302
1303 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1304
Paul Jakmafb982c22007-05-04 20:15:47 +00001305 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001306 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1307 else
1308 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1309
1310 rsclient->rmap_type = 0;
1311
1312 if (ret == RMAP_DENYMATCH)
1313 {
1314 bgp_attr_flush (attr);
1315 return 0;
1316 }
1317 }
1318
1319 return 1;
1320}
1321
1322struct bgp_info_pair
1323{
1324 struct bgp_info *old;
1325 struct bgp_info *new;
1326};
1327
paul94f2b392005-06-28 12:44:16 +00001328static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001329bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001330 struct bgp_info_pair *result,
1331 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001332{
paul718e3742002-12-13 20:15:29 +00001333 struct bgp_info *new_select;
1334 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001335 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001336 struct bgp_info *ri1;
1337 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001338 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001339 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001340 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001341
1342 result->old = result->new = NULL;
1343
1344 if (rn->info == NULL)
1345 {
1346 char buf[PREFIX_STRLEN];
1347 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1348 __func__,
1349 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1350 return;
1351 }
1352
Josh Bailey96450fa2011-07-20 20:45:12 -07001353 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001354 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001355
paul718e3742002-12-13 20:15:29 +00001356 /* bgp deterministic-med */
1357 new_select = NULL;
1358 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1359 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1360 {
1361 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1362 continue;
1363 if (BGP_INFO_HOLDDOWN (ri1))
1364 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001365 if (ri1->peer && ri1->peer != bgp->peer_self)
1366 if (ri1->peer->status != Established)
1367 continue;
paul718e3742002-12-13 20:15:29 +00001368
1369 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001370 if (do_mpath)
1371 bgp_mp_list_add (&mp_list, ri1);
1372 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001373 if (ri1->next)
1374 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1375 {
1376 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1377 continue;
1378 if (BGP_INFO_HOLDDOWN (ri2))
1379 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001380 if (ri2->peer &&
1381 ri2->peer != bgp->peer_self &&
1382 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1383 if (ri2->peer->status != Established)
1384 continue;
paul718e3742002-12-13 20:15:29 +00001385
1386 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1387 || aspath_cmp_left_confed (ri1->attr->aspath,
1388 ri2->attr->aspath))
1389 {
Josh Bailey6918e742011-07-20 20:48:20 -07001390 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1391 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001392 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1393 == -1)
paul718e3742002-12-13 20:15:29 +00001394 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001395 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001396 new_select = ri2;
1397 }
1398
Paul Jakma6d4742b2015-11-25 17:14:37 +00001399 if (do_mpath)
1400 {
1401 if (cmpret != 0)
1402 bgp_mp_list_clear (&mp_list);
1403
1404 if (cmpret == 0 || cmpret == -1)
1405 bgp_mp_list_add (&mp_list, ri2);
1406 }
Josh Bailey6918e742011-07-20 20:48:20 -07001407
Paul Jakma1a392d42006-09-07 00:24:49 +00001408 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001409 }
1410 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001411 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1412 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001413
Paul Jakma6d4742b2015-11-25 17:14:37 +00001414 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001415 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001416 }
1417
1418 /* Check old selected route and new selected route. */
1419 old_select = NULL;
1420 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001421 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001422 {
1423 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1424 old_select = ri;
1425
1426 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001427 {
1428 /* reap REMOVED routes, if needs be
1429 * selected route must stay for a while longer though
1430 */
1431 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1432 && (ri != old_select))
1433 bgp_info_reap (rn, ri);
1434
1435 continue;
1436 }
paul718e3742002-12-13 20:15:29 +00001437
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001438 if (ri->peer &&
1439 ri->peer != bgp->peer_self &&
1440 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1441 if (ri->peer->status != Established)
1442 continue;
1443
paul718e3742002-12-13 20:15:29 +00001444 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1445 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1446 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001447 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001448 continue;
1449 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001450 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1451 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001452
Paul Jakma6d4742b2015-11-25 17:14:37 +00001453 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001454 {
Josh Bailey6918e742011-07-20 20:48:20 -07001455 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1456 bgp_mp_dmed_deselect (new_select);
1457
Josh Bailey96450fa2011-07-20 20:45:12 -07001458 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001459 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001460 else if (cmpret == 1 && do_mpath
1461 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001462 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001463
Paul Jakma6d4742b2015-11-25 17:14:37 +00001464 if (do_mpath)
1465 {
1466 if (cmpret != 0)
1467 bgp_mp_list_clear (&mp_list);
1468
1469 if (cmpret == 0 || cmpret == -1)
1470 bgp_mp_list_add (&mp_list, ri);
1471 }
paul718e3742002-12-13 20:15:29 +00001472 }
paulfee0f4c2004-09-13 05:12:46 +00001473
Josh Bailey6918e742011-07-20 20:48:20 -07001474 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001475 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001476
Josh Bailey0b597ef2011-07-20 20:49:11 -07001477 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001478 bgp_mp_list_clear (&mp_list);
1479
1480 result->old = old_select;
1481 result->new = new_select;
1482
1483 return;
paulfee0f4c2004-09-13 05:12:46 +00001484}
1485
paul94f2b392005-06-28 12:44:16 +00001486static int
paulfee0f4c2004-09-13 05:12:46 +00001487bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001488 struct bgp_node *rn, afi_t afi, safi_t safi)
1489{
paulfee0f4c2004-09-13 05:12:46 +00001490 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001491 struct attr attr;
1492 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001493
Lou Berger050defe2016-01-12 13:41:59 -05001494 memset (&attr, 0, sizeof(struct attr));
1495 memset (&extra, 0, sizeof(struct attr_extra));
1496
paulfee0f4c2004-09-13 05:12:46 +00001497 p = &rn->p;
1498
Paul Jakma9eda90c2007-08-30 13:36:17 +00001499 /* Announce route to Established peer. */
1500 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001501 return 0;
1502
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 /* Address family configuration check. */
1504 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001505 return 0;
1506
Paul Jakma9eda90c2007-08-30 13:36:17 +00001507 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001508 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1509 PEER_STATUS_ORF_WAIT_REFRESH))
1510 return 0;
1511
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001512 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1513 attr.extra = &extra;
1514
Avneesh Sachdev67174042012-08-17 08:19:49 -07001515 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001516 {
1517 case BGP_TABLE_MAIN:
1518 /* Announcement to peer->conf. If the route is filtered,
1519 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001520 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1521 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001522 else
1523 bgp_adj_out_unset (rn, peer, p, afi, safi);
1524 break;
1525 case BGP_TABLE_RSCLIENT:
1526 /* Announcement to peer->conf. If the route is filtered,
1527 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001528 if (selected &&
1529 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1530 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1531 else
1532 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001533 break;
1534 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001535
Lou Berger050defe2016-01-12 13:41:59 -05001536 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001537 return 0;
paul200df112005-06-01 11:17:05 +00001538}
paulfee0f4c2004-09-13 05:12:46 +00001539
paul200df112005-06-01 11:17:05 +00001540struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001541{
paul200df112005-06-01 11:17:05 +00001542 struct bgp *bgp;
1543 struct bgp_node *rn;
1544 afi_t afi;
1545 safi_t safi;
1546};
1547
1548static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001549bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001550{
paul0fb58d52005-11-14 14:31:49 +00001551 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001552 struct bgp *bgp = pq->bgp;
1553 struct bgp_node *rn = pq->rn;
1554 afi_t afi = pq->afi;
1555 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001556 struct bgp_info *new_select;
1557 struct bgp_info *old_select;
1558 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001559 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001560 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001561
paulfee0f4c2004-09-13 05:12:46 +00001562 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001563 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001564 new_select = old_and_new.new;
1565 old_select = old_and_new.old;
1566
paul200df112005-06-01 11:17:05 +00001567 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1568 {
Chris Caputo228da422009-07-18 05:44:03 +00001569 if (rsclient->group)
1570 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1571 {
1572 /* Nothing to do. */
1573 if (old_select && old_select == new_select)
1574 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1575 continue;
paulfee0f4c2004-09-13 05:12:46 +00001576
Chris Caputo228da422009-07-18 05:44:03 +00001577 if (old_select)
1578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1579 if (new_select)
1580 {
1581 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1582 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001583 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1584 }
paulfee0f4c2004-09-13 05:12:46 +00001585
Chris Caputo228da422009-07-18 05:44:03 +00001586 bgp_process_announce_selected (rsclient, new_select, rn,
1587 afi, safi);
1588 }
paul200df112005-06-01 11:17:05 +00001589 }
1590 else
1591 {
hassob7395792005-08-26 12:58:38 +00001592 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001593 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001594 if (new_select)
1595 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001596 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1597 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001598 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001599 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001600 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001601 }
paulfee0f4c2004-09-13 05:12:46 +00001602
paulb40d9392005-08-22 22:34:41 +00001603 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1604 bgp_info_reap (rn, old_select);
1605
paul200df112005-06-01 11:17:05 +00001606 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1607 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001608}
1609
paul200df112005-06-01 11:17:05 +00001610static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001611bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001612{
paul0fb58d52005-11-14 14:31:49 +00001613 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001614 struct bgp *bgp = pq->bgp;
1615 struct bgp_node *rn = pq->rn;
1616 afi_t afi = pq->afi;
1617 safi_t safi = pq->safi;
1618 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001619 struct bgp_info *new_select;
1620 struct bgp_info *old_select;
1621 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001622 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001623 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001624
paulfee0f4c2004-09-13 05:12:46 +00001625 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001626 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001627 old_select = old_and_new.old;
1628 new_select = old_and_new.new;
1629
1630 /* Nothing to do. */
1631 if (old_select && old_select == new_select)
1632 {
1633 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001634 {
Josh Bailey8196f132011-07-20 20:47:07 -07001635 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1636 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001637 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001638
Josh Bailey8196f132011-07-20 20:47:07 -07001639 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001640 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1641 return WQ_SUCCESS;
1642 }
paulfee0f4c2004-09-13 05:12:46 +00001643 }
paul718e3742002-12-13 20:15:29 +00001644
hasso338b3422005-02-23 14:27:24 +00001645 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001646 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001647 if (new_select)
1648 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001649 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1650 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001651 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001652 }
1653
1654
paul718e3742002-12-13 20:15:29 +00001655 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001656 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001657 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001658 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001659 }
1660
1661 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001662 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1663 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001664 {
1665 if (new_select
1666 && new_select->type == ZEBRA_ROUTE_BGP
1667 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001668 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001669 else
1670 {
1671 /* Withdraw the route from the kernel. */
1672 if (old_select
1673 && old_select->type == ZEBRA_ROUTE_BGP
1674 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001675 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001676 }
1677 }
paulb40d9392005-08-22 22:34:41 +00001678
Lou Berger050defe2016-01-12 13:41:59 -05001679 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001680 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1681 bgp_info_reap (rn, old_select);
1682
paul200df112005-06-01 11:17:05 +00001683 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1684 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001685}
1686
paul200df112005-06-01 11:17:05 +00001687static void
paul0fb58d52005-11-14 14:31:49 +00001688bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001689{
paul0fb58d52005-11-14 14:31:49 +00001690 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001691 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001692
Chris Caputo228da422009-07-18 05:44:03 +00001693 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001694 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001695 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001696 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1697}
1698
1699static void
1700bgp_process_queue_init (void)
1701{
1702 bm->process_main_queue
1703 = work_queue_new (bm->master, "process_main_queue");
1704 bm->process_rsclient_queue
1705 = work_queue_new (bm->master, "process_rsclient_queue");
1706
1707 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1708 {
1709 zlog_err ("%s: Failed to allocate work queue", __func__);
1710 exit (1);
1711 }
1712
1713 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001714 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001715 bm->process_main_queue->spec.max_retries = 0;
1716 bm->process_main_queue->spec.hold = 50;
1717
Paul Jakma838bbde2010-01-08 14:05:32 +00001718 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001719 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1720 bm->process_rsclient_queue->spec.max_retries = 0;
1721 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001722}
1723
1724void
paulfee0f4c2004-09-13 05:12:46 +00001725bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1726{
paul200df112005-06-01 11:17:05 +00001727 struct bgp_process_queue *pqnode;
1728
1729 /* already scheduled for processing? */
1730 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1731 return;
1732
Paul Jakma91b9e852015-12-01 14:32:11 +00001733 if (rn->info == NULL)
1734 {
1735 /* XXX: Perhaps remove before next release, after we've flushed out
1736 * any obvious cases
1737 */
1738 assert (rn->info != NULL);
1739 char buf[PREFIX_STRLEN];
1740 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1741 __func__,
1742 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1743 return;
1744 }
1745
paul200df112005-06-01 11:17:05 +00001746 if ( (bm->process_main_queue == NULL) ||
1747 (bm->process_rsclient_queue == NULL) )
1748 bgp_process_queue_init ();
1749
1750 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1751 sizeof (struct bgp_process_queue));
1752 if (!pqnode)
1753 return;
Chris Caputo228da422009-07-18 05:44:03 +00001754
1755 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001756 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001757 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001758 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001759 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001760 pqnode->afi = afi;
1761 pqnode->safi = safi;
1762
Avneesh Sachdev67174042012-08-17 08:19:49 -07001763 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001764 {
paul200df112005-06-01 11:17:05 +00001765 case BGP_TABLE_MAIN:
1766 work_queue_add (bm->process_main_queue, pqnode);
1767 break;
1768 case BGP_TABLE_RSCLIENT:
1769 work_queue_add (bm->process_rsclient_queue, pqnode);
1770 break;
paulfee0f4c2004-09-13 05:12:46 +00001771 }
paul200df112005-06-01 11:17:05 +00001772
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001773 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001774 return;
paulfee0f4c2004-09-13 05:12:46 +00001775}
hasso0a486e52005-02-01 20:57:17 +00001776
paul94f2b392005-06-28 12:44:16 +00001777static int
hasso0a486e52005-02-01 20:57:17 +00001778bgp_maximum_prefix_restart_timer (struct thread *thread)
1779{
1780 struct peer *peer;
1781
1782 peer = THREAD_ARG (thread);
1783 peer->t_pmax_restart = NULL;
1784
1785 if (BGP_DEBUG (events, EVENTS))
1786 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1787 peer->host);
1788
1789 peer_clear (peer);
1790
1791 return 0;
1792}
1793
paulfee0f4c2004-09-13 05:12:46 +00001794int
paul5228ad22004-06-04 17:58:18 +00001795bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1796 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001797{
hassoe0701b72004-05-20 09:19:34 +00001798 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1799 return 0;
1800
1801 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001802 {
hassoe0701b72004-05-20 09:19:34 +00001803 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1804 && ! always)
1805 return 0;
paul718e3742002-12-13 20:15:29 +00001806
hassoe0701b72004-05-20 09:19:34 +00001807 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001808 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1809 "limit %ld", afi_safi_print (afi, safi), peer->host,
1810 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001811 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001812
hassoe0701b72004-05-20 09:19:34 +00001813 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1814 return 0;
paul718e3742002-12-13 20:15:29 +00001815
hassoe0701b72004-05-20 09:19:34 +00001816 {
paul5228ad22004-06-04 17:58:18 +00001817 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001818
1819 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001820 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001821
1822 ndata[0] = (afi >> 8);
1823 ndata[1] = afi;
1824 ndata[2] = safi;
1825 ndata[3] = (peer->pmax[afi][safi] >> 24);
1826 ndata[4] = (peer->pmax[afi][safi] >> 16);
1827 ndata[5] = (peer->pmax[afi][safi] >> 8);
1828 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001829
1830 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1831 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1832 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1833 }
hasso0a486e52005-02-01 20:57:17 +00001834
1835 /* restart timer start */
1836 if (peer->pmax_restart[afi][safi])
1837 {
1838 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1839
1840 if (BGP_DEBUG (events, EVENTS))
1841 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1842 peer->host, peer->v_pmax_restart);
1843
1844 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1845 peer->v_pmax_restart);
1846 }
1847
hassoe0701b72004-05-20 09:19:34 +00001848 return 1;
paul718e3742002-12-13 20:15:29 +00001849 }
hassoe0701b72004-05-20 09:19:34 +00001850 else
1851 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1852
1853 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1854 {
1855 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1856 && ! always)
1857 return 0;
1858
1859 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001860 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1861 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1862 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001863 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1864 }
1865 else
1866 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001867 return 0;
1868}
1869
paulb40d9392005-08-22 22:34:41 +00001870/* Unconditionally remove the route from the RIB, without taking
1871 * damping into consideration (eg, because the session went down)
1872 */
paul94f2b392005-06-28 12:44:16 +00001873static void
paul718e3742002-12-13 20:15:29 +00001874bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1875 afi_t afi, safi_t safi)
1876{
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878
1879 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1880 bgp_info_delete (rn, ri); /* keep historical info */
1881
paulb40d9392005-08-22 22:34:41 +00001882 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001883}
1884
paul94f2b392005-06-28 12:44:16 +00001885static void
paul718e3742002-12-13 20:15:29 +00001886bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001887 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001888{
paul718e3742002-12-13 20:15:29 +00001889 int status = BGP_DAMP_NONE;
1890
paulb40d9392005-08-22 22:34:41 +00001891 /* apply dampening, if result is suppressed, we'll be retaining
1892 * the bgp_info in the RIB for historical reference.
1893 */
1894 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001895 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001896 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1897 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001898 {
paul902212c2006-02-05 17:51:19 +00001899 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1900 return;
1901 }
1902
1903 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001904}
1905
paul94f2b392005-06-28 12:44:16 +00001906static void
paulfee0f4c2004-09-13 05:12:46 +00001907bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1908 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1909 int sub_type, struct prefix_rd *prd, u_char *tag)
1910{
1911 struct bgp_node *rn;
1912 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001913 struct attr new_attr;
1914 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001915 struct attr *attr_new;
1916 struct attr *attr_new2;
1917 struct bgp_info *ri;
1918 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001919 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001920 char buf[SU_ADDRSTRLEN];
1921
1922 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1923 if (peer == rsclient)
1924 return;
1925
1926 bgp = peer->bgp;
1927 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1928
1929 /* Check previously received route. */
1930 for (ri = rn->info; ri; ri = ri->next)
1931 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1932 break;
1933
1934 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001935 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001936 {
1937 reason = "as-path contains our own AS;";
1938 goto filtered;
1939 }
1940
1941 /* Route reflector originator ID check. */
1942 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001943 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001944 {
1945 reason = "originator is us;";
1946 goto filtered;
1947 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001948
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001949 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001950 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Apply export policy. */
1953 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1954 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1955 {
1956 reason = "export-policy;";
1957 goto filtered;
1958 }
1959
1960 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001961
paulfee0f4c2004-09-13 05:12:46 +00001962 /* Apply import policy. */
1963 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1964 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001965 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001966
1967 reason = "import-policy;";
1968 goto filtered;
1969 }
1970
1971 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001975 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001976 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001977 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001978 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001979 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001980 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001981 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001982
1983 reason = "martian next-hop;";
1984 goto filtered;
1985 }
1986 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001987
paulfee0f4c2004-09-13 05:12:46 +00001988 /* If the update is implicit withdraw. */
1989 if (ri)
1990 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001991 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001992
1993 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001994 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1995 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001996 {
1997
Paul Jakma1a392d42006-09-07 00:24:49 +00001998 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001999
2000 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002001 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002002 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
2003 peer->host,
2004 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2005 p->prefixlen, rsclient->host);
2006
Chris Caputo228da422009-07-18 05:44:03 +00002007 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002008 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002009 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002010 return;
paulfee0f4c2004-09-13 05:12:46 +00002011 }
2012
Paul Jakma16d2e242007-04-10 19:32:10 +00002013 /* Withdraw/Announce before we fully processed the withdraw */
2014 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2015 bgp_info_restore (rn, ri);
2016
paulfee0f4c2004-09-13 05:12:46 +00002017 /* Received Logging. */
2018 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002019 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002020 peer->host,
2021 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2022 p->prefixlen, rsclient->host);
2023
2024 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002025 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002026
2027 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002028 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002029 ri->attr = attr_new;
2030
2031 /* Update MPLS tag. */
2032 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002033 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002034
Paul Jakma1a392d42006-09-07 00:24:49 +00002035 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002036
2037 /* Process change. */
2038 bgp_process (bgp, rn, afi, safi);
2039 bgp_unlock_node (rn);
2040
2041 return;
2042 }
2043
2044 /* Received Logging. */
2045 if (BGP_DEBUG (update, UPDATE_IN))
2046 {
ajsd2c1f162004-12-08 21:10:20 +00002047 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002048 peer->host,
2049 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2050 p->prefixlen, rsclient->host);
2051 }
2052
2053 /* Make new BGP info. */
2054 new = bgp_info_new ();
2055 new->type = type;
2056 new->sub_type = sub_type;
2057 new->peer = peer;
2058 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002059 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002060
2061 /* Update MPLS tag. */
2062 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002063 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002064
Paul Jakma1a392d42006-09-07 00:24:49 +00002065 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002066
2067 /* Register new BGP information. */
2068 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002069
2070 /* route_node_get lock */
2071 bgp_unlock_node (rn);
2072
paulfee0f4c2004-09-13 05:12:46 +00002073 /* Process change. */
2074 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075
paulfee0f4c2004-09-13 05:12:46 +00002076 return;
2077
2078 filtered:
2079
2080 /* This BGP update is filtered. Log the reason then update BGP entry. */
2081 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002082 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002083 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2084 peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen, rsclient->host, reason);
2087
2088 if (ri)
paulb40d9392005-08-22 22:34:41 +00002089 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002090
2091 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002092
paulfee0f4c2004-09-13 05:12:46 +00002093 return;
2094}
2095
paul94f2b392005-06-28 12:44:16 +00002096static void
paulfee0f4c2004-09-13 05:12:46 +00002097bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2098 struct peer *peer, struct prefix *p, int type, int sub_type,
2099 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002100{
paulfee0f4c2004-09-13 05:12:46 +00002101 struct bgp_node *rn;
2102 struct bgp_info *ri;
2103 char buf[SU_ADDRSTRLEN];
2104
2105 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002106 return;
paulfee0f4c2004-09-13 05:12:46 +00002107
2108 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2109
2110 /* Lookup withdrawn route. */
2111 for (ri = rn->info; ri; ri = ri->next)
2112 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2113 break;
2114
2115 /* Withdraw specified route from routing table. */
2116 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002117 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002118 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002119 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002120 "%s Can't find the route %s/%d", peer->host,
2121 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2122 p->prefixlen);
2123
2124 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002125 bgp_unlock_node (rn);
2126}
paulfee0f4c2004-09-13 05:12:46 +00002127
paul94f2b392005-06-28 12:44:16 +00002128static int
paulfee0f4c2004-09-13 05:12:46 +00002129bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002130 afi_t afi, safi_t safi, int type, int sub_type,
2131 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2132{
2133 int ret;
2134 int aspath_loop_count = 0;
2135 struct bgp_node *rn;
2136 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002137 struct attr new_attr;
2138 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002139 struct attr *attr_new;
2140 struct bgp_info *ri;
2141 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002142 const char *reason;
paul718e3742002-12-13 20:15:29 +00002143 char buf[SU_ADDRSTRLEN];
2144
2145 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002146 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002147
paul718e3742002-12-13 20:15:29 +00002148 /* When peer's soft reconfiguration enabled. Record input packet in
2149 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002150 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2151 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002152 bgp_adj_in_set (rn, peer, attr);
2153
2154 /* Check previously received route. */
2155 for (ri = rn->info; ri; ri = ri->next)
2156 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2157 break;
2158
2159 /* AS path local-as loop check. */
2160 if (peer->change_local_as)
2161 {
2162 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2163 aspath_loop_count = 1;
2164
2165 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2166 {
2167 reason = "as-path contains our own AS;";
2168 goto filtered;
2169 }
2170 }
2171
2172 /* AS path loop check. */
2173 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2174 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2175 && aspath_loop_check(attr->aspath, bgp->confed_id)
2176 > peer->allowas_in[afi][safi]))
2177 {
2178 reason = "as-path contains our own AS;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector originator ID check. */
2183 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002184 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002185 {
2186 reason = "originator is us;";
2187 goto filtered;
2188 }
2189
2190 /* Route reflector cluster ID check. */
2191 if (bgp_cluster_filter (peer, attr))
2192 {
2193 reason = "reflected from the same cluster;";
2194 goto filtered;
2195 }
2196
2197 /* Apply incoming filter. */
2198 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2199 {
2200 reason = "filter;";
2201 goto filtered;
2202 }
2203
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002204 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002205 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002206
David Lamparterc460e572014-06-04 00:54:58 +02002207 /* Apply incoming route-map.
2208 * NB: new_attr may now contain newly allocated values from route-map "set"
2209 * commands, so we need bgp_attr_flush in the error paths, until we intern
2210 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002211 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2212 {
2213 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002214 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002215 goto filtered;
2216 }
2217
2218 /* IPv4 unicast next hop check. */
2219 if (afi == AFI_IP && safi == SAFI_UNICAST)
2220 {
2221 /* If the peer is EBGP and nexthop is not on connected route,
2222 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002223 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002224 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002225 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002226 {
2227 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002228 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002229 goto filtered;
2230 }
2231
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002232 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002233 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002234 if (new_attr.nexthop.s_addr == 0
2235 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2236 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002237 {
2238 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002239 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002240 goto filtered;
2241 }
2242 }
2243
2244 attr_new = bgp_attr_intern (&new_attr);
2245
2246 /* If the update is implicit withdraw. */
2247 if (ri)
2248 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002249 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002250
2251 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002252 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2253 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002254 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002256
2257 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002258 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002259 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2260 {
2261 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002262 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen);
2266
paul902212c2006-02-05 17:51:19 +00002267 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2268 {
2269 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2270 bgp_process (bgp, rn, afi, safi);
2271 }
paul718e3742002-12-13 20:15:29 +00002272 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002273 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002274 {
2275 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002276 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002277 "%s rcvd %s/%d...duplicate ignored",
2278 peer->host,
2279 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2280 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002281
2282 /* graceful restart STALE flag unset. */
2283 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2284 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002286 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002287 }
paul718e3742002-12-13 20:15:29 +00002288 }
2289
2290 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002291 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002292 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002293
paul718e3742002-12-13 20:15:29 +00002294 return 0;
2295 }
2296
Paul Jakma16d2e242007-04-10 19:32:10 +00002297 /* Withdraw/Announce before we fully processed the withdraw */
2298 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2299 {
2300 if (BGP_DEBUG (update, UPDATE_IN))
2301 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2302 peer->host,
2303 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen);
2305 bgp_info_restore (rn, ri);
2306 }
2307
paul718e3742002-12-13 20:15:29 +00002308 /* Received Logging. */
2309 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002310 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002311 peer->host,
2312 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2313 p->prefixlen);
2314
hasso93406d82005-02-02 14:40:33 +00002315 /* graceful restart STALE flag unset. */
2316 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002317 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002318
paul718e3742002-12-13 20:15:29 +00002319 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002320 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002321
2322 /* implicit withdraw, decrement aggregate and pcount here.
2323 * only if update is accepted, they'll increment below.
2324 */
paul902212c2006-02-05 17:51:19 +00002325 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2326
paul718e3742002-12-13 20:15:29 +00002327 /* Update bgp route dampening information. */
2328 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002330 {
2331 /* This is implicit withdraw so we should update dampening
2332 information. */
2333 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2334 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002335 }
2336
paul718e3742002-12-13 20:15:29 +00002337 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002338 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002339 ri->attr = attr_new;
2340
2341 /* Update MPLS tag. */
2342 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002343 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002344
Lou Berger050defe2016-01-12 13:41:59 -05002345 bgp_attr_flush (&new_attr);
2346
paul718e3742002-12-13 20:15:29 +00002347 /* Update bgp route dampening information. */
2348 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002349 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002350 {
2351 /* Now we do normal update dampening. */
2352 ret = bgp_damp_update (ri, rn, afi, safi);
2353 if (ret == BGP_DAMP_SUPPRESSED)
2354 {
2355 bgp_unlock_node (rn);
2356 return 0;
2357 }
2358 }
2359
2360 /* Nexthop reachability check. */
2361 if ((afi == AFI_IP || afi == AFI_IP6)
2362 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002363 && (peer->sort == BGP_PEER_IBGP
2364 || peer->sort == BGP_PEER_CONFED
2365 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002366 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002367 {
2368 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002369 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002370 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002371 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002372 }
2373 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002374 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002375
Lou Berger050defe2016-01-12 13:41:59 -05002376 bgp_attr_flush (&new_attr);
2377
paul718e3742002-12-13 20:15:29 +00002378 /* Process change. */
2379 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2380
2381 bgp_process (bgp, rn, afi, safi);
2382 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002383
paul718e3742002-12-13 20:15:29 +00002384 return 0;
2385 }
2386
2387 /* Received Logging. */
2388 if (BGP_DEBUG (update, UPDATE_IN))
2389 {
ajsd2c1f162004-12-08 21:10:20 +00002390 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002391 peer->host,
2392 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2393 p->prefixlen);
2394 }
2395
paul718e3742002-12-13 20:15:29 +00002396 /* Make new BGP info. */
2397 new = bgp_info_new ();
2398 new->type = type;
2399 new->sub_type = sub_type;
2400 new->peer = peer;
2401 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002402 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002403
2404 /* Update MPLS tag. */
2405 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002406 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002407
2408 /* Nexthop reachability check. */
2409 if ((afi == AFI_IP || afi == AFI_IP6)
2410 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002411 && (peer->sort == BGP_PEER_IBGP
2412 || peer->sort == BGP_PEER_CONFED
2413 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002414 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002415 {
2416 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002417 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002418 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002419 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002420 }
2421 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002422 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002423
paul902212c2006-02-05 17:51:19 +00002424 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002425 bgp_aggregate_increment (bgp, p, new, afi, safi);
2426
2427 /* Register new BGP information. */
2428 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002429
2430 /* route_node_get lock */
2431 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002432
Lou Berger050defe2016-01-12 13:41:59 -05002433 bgp_attr_flush (&new_attr);
2434
paul718e3742002-12-13 20:15:29 +00002435 /* If maximum prefix count is configured and current prefix
2436 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002437 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2438 return -1;
paul718e3742002-12-13 20:15:29 +00002439
2440 /* Process change. */
2441 bgp_process (bgp, rn, afi, safi);
2442
2443 return 0;
2444
2445 /* This BGP update is filtered. Log the reason then update BGP
2446 entry. */
2447 filtered:
2448 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002449 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002450 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2451 peer->host,
2452 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2453 p->prefixlen, reason);
2454
2455 if (ri)
paulb40d9392005-08-22 22:34:41 +00002456 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002457
2458 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002459 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002460
paul718e3742002-12-13 20:15:29 +00002461 return 0;
2462}
2463
2464int
paulfee0f4c2004-09-13 05:12:46 +00002465bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2466 afi_t afi, safi_t safi, int type, int sub_type,
2467 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2468{
2469 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002470 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002471 struct bgp *bgp;
2472 int ret;
2473
2474 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2475 soft_reconfig);
2476
2477 bgp = peer->bgp;
2478
2479 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002480 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002481 {
2482 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2483 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2484 sub_type, prd, tag);
2485 }
2486
2487 return ret;
2488}
2489
2490int
paul718e3742002-12-13 20:15:29 +00002491bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002492 afi_t afi, safi_t safi, int type, int sub_type,
2493 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002494{
2495 struct bgp *bgp;
2496 char buf[SU_ADDRSTRLEN];
2497 struct bgp_node *rn;
2498 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002499 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002500 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002501
2502 bgp = peer->bgp;
2503
David Lamparter4584c232015-04-13 09:50:00 +02002504 /* Lookup node. */
2505 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2506
2507 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2508 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2509 * the iteration over all RS clients.
2510 * Since we need to remove the entry from adj_in anyway, do that first and
2511 * if there was no entry, we don't need to do anything more. */
2512 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2513 && peer != bgp->peer_self)
2514 if (!bgp_adj_in_unset (rn, peer))
2515 {
2516 if (BGP_DEBUG (update, UPDATE_IN))
2517 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2518 "not in adj-in", peer->host,
2519 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2520 p->prefixlen);
2521 bgp_unlock_node (rn);
2522 return 0;
2523 }
2524
paulfee0f4c2004-09-13 05:12:46 +00002525 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002526 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002527 {
2528 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2529 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2530 }
2531
paul718e3742002-12-13 20:15:29 +00002532 /* Logging. */
2533 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002534 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002535 peer->host,
2536 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2537 p->prefixlen);
2538
paul718e3742002-12-13 20:15:29 +00002539 /* Lookup withdrawn route. */
2540 for (ri = rn->info; ri; ri = ri->next)
2541 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2542 break;
2543
2544 /* Withdraw specified route from routing table. */
2545 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002546 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002547 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002548 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002549 "%s Can't find the route %s/%d", peer->host,
2550 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2551 p->prefixlen);
2552
2553 /* Unlock bgp_node_get() lock. */
2554 bgp_unlock_node (rn);
2555
2556 return 0;
2557}
David Lamparter6b0655a2014-06-04 06:53:35 +02002558
paul718e3742002-12-13 20:15:29 +00002559void
2560bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2561{
2562 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002563 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002564 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002565 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002566 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 struct bgp_node *rn;
2568 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002569 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002570
Paul Jakmab2497022007-06-14 11:17:58 +00002571 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002572 return;
2573
paul718e3742002-12-13 20:15:29 +00002574 bgp = peer->bgp;
2575 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002576
paul718e3742002-12-13 20:15:29 +00002577 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2578 aspath = attr.aspath;
2579 attr.local_pref = bgp->default_local_pref;
2580 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2581
2582 if (afi == AFI_IP)
2583 str2prefix ("0.0.0.0/0", &p);
2584#ifdef HAVE_IPV6
2585 else if (afi == AFI_IP6)
2586 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002587 struct attr_extra *ae = attr.extra;
2588
paul718e3742002-12-13 20:15:29 +00002589 str2prefix ("::/0", &p);
2590
2591 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002592 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002593 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002594 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002595
2596 /* If the peer is on shared nextwork and we have link-local
2597 nexthop set it. */
2598 if (peer->shared_network
2599 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2600 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002601 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002602 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002603 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002604 }
2605 }
2606#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002607
2608 if (peer->default_rmap[afi][safi].name)
2609 {
paulfee0f4c2004-09-13 05:12:46 +00002610 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002611 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2612 {
2613 for (ri = rn->info; ri; ri = ri->next)
2614 {
2615 struct attr dummy_attr;
2616 struct attr_extra dummy_extra;
2617 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002618
Christian Frankedcab1bb2012-12-07 16:45:52 +00002619 /* Provide dummy so the route-map can't modify the attributes */
2620 dummy_attr.extra = &dummy_extra;
2621 bgp_attr_dup(&dummy_attr, ri->attr);
2622 info.peer = ri->peer;
2623 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002624
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2626 RMAP_BGP, &info);
2627
2628 /* The route map might have set attributes. If we don't flush them
2629 * here, they will be leaked. */
2630 bgp_attr_flush(&dummy_attr);
2631 if (ret != RMAP_DENYMATCH)
2632 break;
2633 }
2634 if (ret != RMAP_DENYMATCH)
2635 break;
2636 }
paulfee0f4c2004-09-13 05:12:46 +00002637 bgp->peer_self->rmap_type = 0;
2638
paul718e3742002-12-13 20:15:29 +00002639 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002640 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002641 }
2642
2643 if (withdraw)
2644 {
2645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2646 bgp_default_withdraw_send (peer, afi, safi);
2647 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2648 }
2649 else
2650 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002651 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2652 {
2653 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2654 bgp_default_update_send (peer, &attr, afi, safi, from);
2655 }
paul718e3742002-12-13 20:15:29 +00002656 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002657
2658 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002659 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002660}
David Lamparter6b0655a2014-06-04 06:53:35 +02002661
paul718e3742002-12-13 20:15:29 +00002662static void
2663bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002664 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002665{
2666 struct bgp_node *rn;
2667 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002668 struct attr attr;
2669 struct attr_extra extra;
2670
Lou Berger298cc2f2016-01-12 13:42:02 -05002671 memset(&extra, 0, sizeof(extra));
2672
paul718e3742002-12-13 20:15:29 +00002673 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002674 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002675
Lou Berger298cc2f2016-01-12 13:42:02 -05002676 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002677 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2678 bgp_default_originate (peer, afi, safi, 0);
2679
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002680 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2681 attr.extra = &extra;
2682
paul718e3742002-12-13 20:15:29 +00002683 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2684 for (ri = rn->info; ri; ri = ri->next)
2685 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2686 {
paulfee0f4c2004-09-13 05:12:46 +00002687 if ( (rsclient) ?
2688 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2689 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002690 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2691 else
2692 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2693 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002694
2695 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002696}
2697
2698void
2699bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2700{
2701 struct bgp_node *rn;
2702 struct bgp_table *table;
2703
2704 if (peer->status != Established)
2705 return;
2706
2707 if (! peer->afc_nego[afi][safi])
2708 return;
2709
2710 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2711 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2712 return;
2713
Lou Berger298cc2f2016-01-12 13:42:02 -05002714 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002715 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002716 else
2717 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2718 rn = bgp_route_next(rn))
2719 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002720 bgp_announce_table (peer, afi, safi, table, 0);
2721
2722 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2723 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002724}
2725
2726void
2727bgp_announce_route_all (struct peer *peer)
2728{
2729 afi_t afi;
2730 safi_t safi;
2731
2732 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2733 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2734 bgp_announce_route (peer, afi, safi);
2735}
David Lamparter6b0655a2014-06-04 06:53:35 +02002736
paul718e3742002-12-13 20:15:29 +00002737static void
paulfee0f4c2004-09-13 05:12:46 +00002738bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002739 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002740{
2741 struct bgp_node *rn;
2742 struct bgp_adj_in *ain;
2743
2744 if (! table)
2745 table = rsclient->bgp->rib[afi][safi];
2746
2747 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2748 for (ain = rn->adj_in; ain; ain = ain->next)
2749 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002751 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002752
paulfee0f4c2004-09-13 05:12:46 +00002753 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002754 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002755 }
2756}
2757
2758void
2759bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2760{
2761 struct bgp_table *table;
2762 struct bgp_node *rn;
2763
Lou Berger298cc2f2016-01-12 13:42:02 -05002764 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002765 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002766
2767 else
2768 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2769 rn = bgp_route_next (rn))
2770 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002771 {
2772 struct prefix_rd prd;
2773 prd.family = AF_UNSPEC;
2774 prd.prefixlen = 64;
2775 memcpy(&prd.val, rn->p.u.val, 8);
2776
2777 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2778 }
paulfee0f4c2004-09-13 05:12:46 +00002779}
David Lamparter6b0655a2014-06-04 06:53:35 +02002780
paulfee0f4c2004-09-13 05:12:46 +00002781static void
paul718e3742002-12-13 20:15:29 +00002782bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002783 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002784{
2785 int ret;
2786 struct bgp_node *rn;
2787 struct bgp_adj_in *ain;
2788
2789 if (! table)
2790 table = peer->bgp->rib[afi][safi];
2791
2792 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2793 for (ain = rn->adj_in; ain; ain = ain->next)
2794 {
2795 if (ain->peer == peer)
2796 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002797 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002798 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002799
paul718e3742002-12-13 20:15:29 +00002800 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2801 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002802 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002803
paul718e3742002-12-13 20:15:29 +00002804 if (ret < 0)
2805 {
2806 bgp_unlock_node (rn);
2807 return;
2808 }
2809 continue;
2810 }
2811 }
2812}
2813
2814void
2815bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2816{
2817 struct bgp_node *rn;
2818 struct bgp_table *table;
2819
2820 if (peer->status != Established)
2821 return;
2822
Lou Berger298cc2f2016-01-12 13:42:02 -05002823 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002824 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002825 else
2826 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2827 rn = bgp_route_next (rn))
2828 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002829 {
2830 struct prefix_rd prd;
2831 prd.family = AF_UNSPEC;
2832 prd.prefixlen = 64;
2833 memcpy(&prd.val, rn->p.u.val, 8);
2834
2835 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2836 }
paul718e3742002-12-13 20:15:29 +00002837}
David Lamparter6b0655a2014-06-04 06:53:35 +02002838
Chris Caputo228da422009-07-18 05:44:03 +00002839
2840struct bgp_clear_node_queue
2841{
2842 struct bgp_node *rn;
2843 enum bgp_clear_route_type purpose;
2844};
2845
paul200df112005-06-01 11:17:05 +00002846static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002847bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002848{
Chris Caputo228da422009-07-18 05:44:03 +00002849 struct bgp_clear_node_queue *cnq = data;
2850 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002851 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002852 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002853 afi_t afi = bgp_node_table (rn)->afi;
2854 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002855
Paul Jakma64e580a2006-02-21 01:09:01 +00002856 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002857
Paul Jakma64e580a2006-02-21 01:09:01 +00002858 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002859 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002860 {
2861 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2863 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002864 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002865 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2866 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002867 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002868 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002869 break;
2870 }
paul200df112005-06-01 11:17:05 +00002871 return WQ_SUCCESS;
2872}
2873
2874static void
paul0fb58d52005-11-14 14:31:49 +00002875bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002876{
Chris Caputo228da422009-07-18 05:44:03 +00002877 struct bgp_clear_node_queue *cnq = data;
2878 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002879 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002880
2881 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002882 bgp_table_unlock (table);
2883 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002884}
2885
2886static void
paul94f2b392005-06-28 12:44:16 +00002887bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002888{
Paul Jakma64e580a2006-02-21 01:09:01 +00002889 struct peer *peer = wq->spec.data;
2890
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002891 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002892 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002893
2894 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002895}
2896
2897static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002898bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002899{
Paul Jakmaa2943652009-07-21 14:02:04 +01002900 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002901
Paul Jakmaa2943652009-07-21 14:02:04 +01002902 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002903#undef CLEAR_QUEUE_NAME_LEN
2904
2905 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002906 {
2907 zlog_err ("%s: Failed to allocate work queue", __func__);
2908 exit (1);
2909 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002910 peer->clear_node_queue->spec.hold = 10;
2911 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2912 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2913 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2914 peer->clear_node_queue->spec.max_retries = 0;
2915
2916 /* we only 'lock' this peer reference when the queue is actually active */
2917 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002918}
2919
paul718e3742002-12-13 20:15:29 +00002920static void
2921bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002922 struct bgp_table *table, struct peer *rsclient,
2923 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002924{
2925 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002926
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927
paul718e3742002-12-13 20:15:29 +00002928 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002929 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002930
hasso6cf159b2005-03-21 10:28:14 +00002931 /* If still no table => afi/safi isn't configured at all or smth. */
2932 if (! table)
2933 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002937 struct bgp_info *ri;
2938 struct bgp_adj_in *ain;
2939 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002940
2941 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2942 * queued for every clearing peer, regardless of whether it is
2943 * relevant to the peer at hand.
2944 *
2945 * Overview: There are 3 different indices which need to be
2946 * scrubbed, potentially, when a peer is removed:
2947 *
2948 * 1 peer's routes visible via the RIB (ie accepted routes)
2949 * 2 peer's routes visible by the (optional) peer's adj-in index
2950 * 3 other routes visible by the peer's adj-out index
2951 *
2952 * 3 there is no hurry in scrubbing, once the struct peer is
2953 * removed from bgp->peer, we could just GC such deleted peer's
2954 * adj-outs at our leisure.
2955 *
2956 * 1 and 2 must be 'scrubbed' in some way, at least made
2957 * invisible via RIB index before peer session is allowed to be
2958 * brought back up. So one needs to know when such a 'search' is
2959 * complete.
2960 *
2961 * Ideally:
2962 *
2963 * - there'd be a single global queue or a single RIB walker
2964 * - rather than tracking which route_nodes still need to be
2965 * examined on a peer basis, we'd track which peers still
2966 * aren't cleared
2967 *
2968 * Given that our per-peer prefix-counts now should be reliable,
2969 * this may actually be achievable. It doesn't seem to be a huge
2970 * problem at this time,
2971 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002972 for (ain = rn->adj_in; ain; ain = ain->next)
2973 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2974 {
2975 bgp_adj_in_remove (rn, ain);
2976 bgp_unlock_node (rn);
2977 break;
2978 }
2979 for (aout = rn->adj_out; aout; aout = aout->next)
2980 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2981 {
2982 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2983 bgp_unlock_node (rn);
2984 break;
2985 }
2986
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002987 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002988 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002989 {
Chris Caputo228da422009-07-18 05:44:03 +00002990 struct bgp_clear_node_queue *cnq;
2991
2992 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002993 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002994 bgp_lock_node (rn);
2995 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2996 sizeof (struct bgp_clear_node_queue));
2997 cnq->rn = rn;
2998 cnq->purpose = purpose;
2999 work_queue_add (peer->clear_node_queue, cnq);
3000 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003001 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00003002 }
3003 return;
3004}
3005
3006void
Chris Caputo228da422009-07-18 05:44:03 +00003007bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3008 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00003009{
3010 struct bgp_node *rn;
3011 struct bgp_table *table;
3012 struct peer *rsclient;
3013 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00003014
Paul Jakma64e580a2006-02-21 01:09:01 +00003015 if (peer->clear_node_queue == NULL)
3016 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003017
Paul Jakmaca058a32006-09-14 02:58:49 +00003018 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3019 * Idle until it receives a Clearing_Completed event. This protects
3020 * against peers which flap faster than we can we clear, which could
3021 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003022 *
3023 * a) race with routes from the new session being installed before
3024 * clear_route_node visits the node (to delete the route of that
3025 * peer)
3026 * b) resource exhaustion, clear_route_node likely leads to an entry
3027 * on the process_main queue. Fast-flapping could cause that queue
3028 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003029 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003030
3031 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3032 * the unlock will happen upon work-queue completion; other wise, the
3033 * unlock happens at the end of this function.
3034 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003035 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003036 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003037 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003038 {
Chris Caputo228da422009-07-18 05:44:03 +00003039 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003040 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003041 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3042 else
3043 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3044 rn = bgp_route_next (rn))
3045 if ((table = rn->info) != NULL)
3046 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3047
3048 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3049 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3050 PEER_FLAG_RSERVER_CLIENT))
3051 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3052 break;
3053
3054 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003055 /*
3056 * gpz 091009: TBD why don't we have special handling for
3057 * SAFI_MPLS_VPN here in the original quagga code?
3058 * (and, by extension, for SAFI_ENCAP)
3059 */
Chris Caputo228da422009-07-18 05:44:03 +00003060 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3061 break;
3062
3063 default:
3064 assert (0);
3065 break;
paulfee0f4c2004-09-13 05:12:46 +00003066 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003067
3068 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003069 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003070 peer_unlock (peer);
3071
paul718e3742002-12-13 20:15:29 +00003072}
3073
3074void
3075bgp_clear_route_all (struct peer *peer)
3076{
3077 afi_t afi;
3078 safi_t safi;
3079
3080 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3081 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003082 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003083}
3084
Lou Berger82dd7072016-01-12 13:41:57 -05003085/*
3086 * Finish freeing things when exiting
3087 */
3088static void
3089bgp_drain_workqueue_immediate (struct work_queue *wq)
3090{
3091 if (!wq)
3092 return;
3093
3094 if (!wq->thread)
3095 {
3096 /*
3097 * no thread implies no queued items
3098 */
3099 assert(!wq->items->count);
3100 return;
3101 }
3102
3103 while (wq->items->count)
3104 {
3105 if (wq->thread)
3106 thread_cancel(wq->thread);
3107 work_queue_run(wq->thread);
3108 }
3109}
3110
3111/*
3112 * Special function to process clear node queue when bgpd is exiting
3113 * and the thread scheduler is no longer running.
3114 */
3115void
3116bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3117{
3118 if (!peer)
3119 return;
3120
3121 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3122}
3123
3124/*
3125 * The work queues are not specific to a BGP instance, but the
3126 * items in them refer to BGP instances, so this should be called
3127 * before each BGP instance is deleted.
3128 */
3129void
3130bgp_process_queues_drain_immediate(void)
3131{
3132 bgp_drain_workqueue_immediate(bm->process_main_queue);
3133 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3134}
3135
paul718e3742002-12-13 20:15:29 +00003136void
3137bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3138{
3139 struct bgp_table *table;
3140 struct bgp_node *rn;
3141 struct bgp_adj_in *ain;
3142
3143 table = peer->bgp->rib[afi][safi];
3144
3145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3146 for (ain = rn->adj_in; ain ; ain = ain->next)
3147 if (ain->peer == peer)
3148 {
3149 bgp_adj_in_remove (rn, ain);
3150 bgp_unlock_node (rn);
3151 break;
3152 }
3153}
hasso93406d82005-02-02 14:40:33 +00003154
3155void
3156bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3157{
3158 struct bgp_node *rn;
3159 struct bgp_info *ri;
3160 struct bgp_table *table;
3161
3162 table = peer->bgp->rib[afi][safi];
3163
3164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3165 {
3166 for (ri = rn->info; ri; ri = ri->next)
3167 if (ri->peer == peer)
3168 {
3169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3170 bgp_rib_remove (rn, ri, peer, afi, safi);
3171 break;
3172 }
3173 }
3174}
David Lamparter6b0655a2014-06-04 06:53:35 +02003175
Lou Berger82dd7072016-01-12 13:41:57 -05003176static void
3177bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3178{
3179 struct bgp_node *rn;
3180 struct bgp_info *ri;
3181 struct bgp_info *next;
3182
3183 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3184 for (ri = rn->info; ri; ri = next)
3185 {
3186 next = ri->next;
3187 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3188 && ri->type == ZEBRA_ROUTE_BGP
3189 && ri->sub_type == BGP_ROUTE_NORMAL)
3190 bgp_zebra_withdraw (&rn->p, ri, safi);
3191 }
3192}
3193
paul718e3742002-12-13 20:15:29 +00003194/* Delete all kernel routes. */
3195void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003196bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003197{
3198 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003199 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003200 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003201
paul1eb8ef22005-04-07 07:30:20 +00003202 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003203 {
Lou Berger82dd7072016-01-12 13:41:57 -05003204 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3205 {
3206 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003207
Lou Berger82dd7072016-01-12 13:41:57 -05003208 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003209
Lou Berger82dd7072016-01-12 13:41:57 -05003210 /*
3211 * VPN and ENCAP tables are two-level (RD is top level)
3212 */
3213 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3214 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003215 {
3216 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003217 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003218 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3219 bgp_table_finish ((struct bgp_table **)&(rn->info));
3220 rn->info = NULL;
3221 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003222 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003223 }
3224
3225 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3226 rn = bgp_route_next (rn))
3227 {
3228 if (rn->info)
3229 {
3230 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3231 bgp_table_finish ((struct bgp_table **)&(rn->info));
3232 rn->info = NULL;
3233 bgp_unlock_node(rn);
3234 }
3235 }
Lou Berger82dd7072016-01-12 13:41:57 -05003236 }
paul718e3742002-12-13 20:15:29 +00003237 }
3238}
3239
3240void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003241bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003242{
3243 vty_reset ();
3244 bgp_zclient_reset ();
3245 access_list_reset ();
3246 prefix_list_reset ();
3247}
David Lamparter6b0655a2014-06-04 06:53:35 +02003248
paul718e3742002-12-13 20:15:29 +00003249/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3250 value. */
3251int
3252bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3253{
3254 u_char *pnt;
3255 u_char *lim;
3256 struct prefix p;
3257 int psize;
3258 int ret;
3259
3260 /* Check peer status. */
3261 if (peer->status != Established)
3262 return 0;
3263
3264 pnt = packet->nlri;
3265 lim = pnt + packet->length;
3266
3267 for (; pnt < lim; pnt += psize)
3268 {
3269 /* Clear prefix structure. */
3270 memset (&p, 0, sizeof (struct prefix));
3271
3272 /* Fetch prefix length. */
3273 p.prefixlen = *pnt++;
3274 p.family = afi2family (packet->afi);
3275
3276 /* Already checked in nlri_sanity_check(). We do double check
3277 here. */
3278 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3279 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3280 return -1;
3281
3282 /* Packet size overflow check. */
3283 psize = PSIZE (p.prefixlen);
3284
3285 /* When packet overflow occur return immediately. */
3286 if (pnt + psize > lim)
3287 return -1;
3288
3289 /* Fetch prefix from NLRI packet. */
3290 memcpy (&p.u.prefix, pnt, psize);
3291
3292 /* Check address. */
3293 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3294 {
3295 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3296 {
paulf5ba3872004-07-09 12:11:31 +00003297 /*
3298 * From draft-ietf-idr-bgp4-22, Section 6.3:
3299 * If a BGP router receives an UPDATE message with a
3300 * semantically incorrect NLRI field, in which a prefix is
3301 * semantically incorrect (eg. an unexpected multicast IP
3302 * address), it should ignore the prefix.
3303 */
paul718e3742002-12-13 20:15:29 +00003304 zlog (peer->log, LOG_ERR,
3305 "IPv4 unicast NLRI is multicast address %s",
3306 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003307
paul718e3742002-12-13 20:15:29 +00003308 return -1;
3309 }
3310 }
3311
3312#ifdef HAVE_IPV6
3313 /* Check address. */
3314 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3315 {
3316 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3317 {
3318 char buf[BUFSIZ];
3319
3320 zlog (peer->log, LOG_WARNING,
3321 "IPv6 link-local NLRI received %s ignore this NLRI",
3322 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3323
3324 continue;
3325 }
3326 }
3327#endif /* HAVE_IPV6 */
3328
3329 /* Normal process. */
3330 if (attr)
3331 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3332 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3333 else
3334 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3335 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3336
3337 /* Address family configuration mismatch or maximum-prefix count
3338 overflow. */
3339 if (ret < 0)
3340 return -1;
3341 }
3342
3343 /* Packet length consistency check. */
3344 if (pnt != lim)
3345 return -1;
3346
3347 return 0;
3348}
3349
3350/* NLRI encode syntax check routine. */
3351int
Lou Berger050defe2016-01-12 13:41:59 -05003352bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi,
3353 u_char *pnt, bgp_size_t length)
paul718e3742002-12-13 20:15:29 +00003354{
3355 u_char *end;
3356 u_char prefixlen;
3357 int psize;
3358
3359 end = pnt + length;
3360
3361 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3362 syntactic validity. If the field is syntactically incorrect,
3363 then the Error Subcode is set to Invalid Network Field. */
3364
3365 while (pnt < end)
3366 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003367 int badlength;
paul718e3742002-12-13 20:15:29 +00003368 prefixlen = *pnt++;
3369
3370 /* Prefix length check. */
Lou Berger298cc2f2016-01-12 13:42:02 -05003371 badlength = 0;
3372 if (safi == SAFI_ENCAP) {
3373 if (prefixlen > 128)
3374 badlength = 1;
3375 } else {
3376 if ((afi == AFI_IP && prefixlen > 32) ||
3377 (afi == AFI_IP6 && prefixlen > 128)) {
3378
3379 badlength = 1;
3380 }
3381 }
3382 if (badlength)
paul718e3742002-12-13 20:15:29 +00003383 {
3384 plog_err (peer->log,
3385 "%s [Error] Update packet error (wrong prefix length %d)",
3386 peer->host, prefixlen);
3387 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3388 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3389 return -1;
3390 }
3391
3392 /* Packet size overflow check. */
3393 psize = PSIZE (prefixlen);
3394
3395 if (pnt + psize > end)
3396 {
3397 plog_err (peer->log,
3398 "%s [Error] Update packet error"
3399 " (prefix data overflow prefix size is %d)",
3400 peer->host, psize);
3401 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3402 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3403 return -1;
3404 }
3405
3406 pnt += psize;
3407 }
3408
3409 /* Packet length consistency check. */
3410 if (pnt != end)
3411 {
3412 plog_err (peer->log,
3413 "%s [Error] Update packet error"
3414 " (prefix length mismatch with total length)",
3415 peer->host);
3416 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3417 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3418 return -1;
3419 }
3420 return 0;
3421}
David Lamparter6b0655a2014-06-04 06:53:35 +02003422
paul94f2b392005-06-28 12:44:16 +00003423static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003424bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003425{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003426 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003427}
3428
paul94f2b392005-06-28 12:44:16 +00003429static void
paul718e3742002-12-13 20:15:29 +00003430bgp_static_free (struct bgp_static *bgp_static)
3431{
3432 if (bgp_static->rmap.name)
3433 free (bgp_static->rmap.name);
3434 XFREE (MTYPE_BGP_STATIC, bgp_static);
3435}
3436
paul94f2b392005-06-28 12:44:16 +00003437static void
paulfee0f4c2004-09-13 05:12:46 +00003438bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3439 struct prefix *p, afi_t afi, safi_t safi)
3440{
3441 struct bgp_node *rn;
3442 struct bgp_info *ri;
3443
3444 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3445
3446 /* Check selected route and self inserted route. */
3447 for (ri = rn->info; ri; ri = ri->next)
3448 if (ri->peer == bgp->peer_self
3449 && ri->type == ZEBRA_ROUTE_BGP
3450 && ri->sub_type == BGP_ROUTE_STATIC)
3451 break;
3452
3453 /* Withdraw static BGP route from routing table. */
3454 if (ri)
3455 {
paulfee0f4c2004-09-13 05:12:46 +00003456 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003457 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003458 }
3459
3460 /* Unlock bgp_node_lookup. */
3461 bgp_unlock_node (rn);
3462}
3463
paul94f2b392005-06-28 12:44:16 +00003464static void
paulfee0f4c2004-09-13 05:12:46 +00003465bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 struct bgp_static *bgp_static,
3467 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003468{
3469 struct bgp_node *rn;
3470 struct bgp_info *ri;
3471 struct bgp_info *new;
3472 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003473 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003474 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003475 struct attr new_attr;
3476 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003477 struct bgp *bgp;
3478 int ret;
3479 char buf[SU_ADDRSTRLEN];
3480
3481 bgp = rsclient->bgp;
3482
Paul Jakma06e110f2006-05-12 23:29:22 +00003483 assert (bgp_static);
3484 if (!bgp_static)
3485 return;
3486
paulfee0f4c2004-09-13 05:12:46 +00003487 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3488
3489 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003490
3491 attr.nexthop = bgp_static->igpnexthop;
3492 attr.med = bgp_static->igpmetric;
3493 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003494
Paul Jakma41367172007-08-06 15:24:51 +00003495 if (bgp_static->atomic)
3496 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3497
paulfee0f4c2004-09-13 05:12:46 +00003498 /* Apply network route-map for export to this rsclient. */
3499 if (bgp_static->rmap.name)
3500 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003501 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003502 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 info.attr = &attr_tmp;
3504
paulfee0f4c2004-09-13 05:12:46 +00003505 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3506 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3507
3508 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3509
3510 rsclient->rmap_type = 0;
3511
3512 if (ret == RMAP_DENYMATCH)
3513 {
3514 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003515 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003516
3517 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003519 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 bgp_attr_extra_free (&attr);
3521
paulfee0f4c2004-09-13 05:12:46 +00003522 return;
3523 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003524 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003525 }
3526 else
3527 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003528
3529 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003530 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003531
paulfee0f4c2004-09-13 05:12:46 +00003532 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3533
Paul Jakmafb982c22007-05-04 20:15:47 +00003534 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3535 == RMAP_DENY)
3536 {
paulfee0f4c2004-09-13 05:12:46 +00003537 /* This BGP update is filtered. Log the reason then update BGP entry. */
3538 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003539 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003540 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3541 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3542 p->prefixlen, rsclient->host);
3543
3544 bgp->peer_self->rmap_type = 0;
3545
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003549
3550 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3551
3552 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003553 }
paulfee0f4c2004-09-13 05:12:46 +00003554
3555 bgp->peer_self->rmap_type = 0;
3556
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003557 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003558 attr_new = bgp_attr_intern (&new_attr);
3559
3560 for (ri = rn->info; ri; ri = ri->next)
3561 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3562 && ri->sub_type == BGP_ROUTE_STATIC)
3563 break;
3564
3565 if (ri)
3566 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003567 if (attrhash_cmp (ri->attr, attr_new) &&
3568 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003569 {
3570 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003571 bgp_attr_unintern (&attr_new);
3572 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003573 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003574 return;
3575 }
3576 else
3577 {
3578 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003579 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003580
3581 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003582 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3583 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003584 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003585 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003586 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003587
3588 /* Process change. */
3589 bgp_process (bgp, rn, afi, safi);
3590 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003591 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003592 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003593 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003594 }
paulfee0f4c2004-09-13 05:12:46 +00003595 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003596
paulfee0f4c2004-09-13 05:12:46 +00003597 /* Make new BGP info. */
3598 new = bgp_info_new ();
3599 new->type = ZEBRA_ROUTE_BGP;
3600 new->sub_type = BGP_ROUTE_STATIC;
3601 new->peer = bgp->peer_self;
3602 SET_FLAG (new->flags, BGP_INFO_VALID);
3603 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003604 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003605
3606 /* Register new BGP information. */
3607 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003608
3609 /* route_node_get lock */
3610 bgp_unlock_node (rn);
3611
paulfee0f4c2004-09-13 05:12:46 +00003612 /* Process change. */
3613 bgp_process (bgp, rn, afi, safi);
3614
3615 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003616 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003617 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003618}
3619
paul94f2b392005-06-28 12:44:16 +00003620static void
paulfee0f4c2004-09-13 05:12:46 +00003621bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003622 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3623{
3624 struct bgp_node *rn;
3625 struct bgp_info *ri;
3626 struct bgp_info *new;
3627 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003628 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003629 struct attr *attr_new;
3630 int ret;
3631
Paul Jakmadd8103a2006-05-12 23:27:30 +00003632 assert (bgp_static);
3633 if (!bgp_static)
3634 return;
3635
paulfee0f4c2004-09-13 05:12:46 +00003636 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003637
3638 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003639
3640 attr.nexthop = bgp_static->igpnexthop;
3641 attr.med = bgp_static->igpmetric;
3642 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003643
Paul Jakma41367172007-08-06 15:24:51 +00003644 if (bgp_static->atomic)
3645 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3646
paul718e3742002-12-13 20:15:29 +00003647 /* Apply route-map. */
3648 if (bgp_static->rmap.name)
3649 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003650 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003651 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003652 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003653
paulfee0f4c2004-09-13 05:12:46 +00003654 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3655
paul718e3742002-12-13 20:15:29 +00003656 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003657
paulfee0f4c2004-09-13 05:12:46 +00003658 bgp->peer_self->rmap_type = 0;
3659
paul718e3742002-12-13 20:15:29 +00003660 if (ret == RMAP_DENYMATCH)
3661 {
3662 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003663 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003664
3665 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003666 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003667 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003668 bgp_static_withdraw (bgp, p, afi, safi);
3669 return;
3670 }
paul286e1e72003-08-08 00:24:31 +00003671 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003672 }
paul286e1e72003-08-08 00:24:31 +00003673 else
3674 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003675
3676 for (ri = rn->info; ri; ri = ri->next)
3677 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3678 && ri->sub_type == BGP_ROUTE_STATIC)
3679 break;
3680
3681 if (ri)
3682 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003683 if (attrhash_cmp (ri->attr, attr_new) &&
3684 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003685 {
3686 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003687 bgp_attr_unintern (&attr_new);
3688 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003689 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003690 return;
3691 }
3692 else
3693 {
3694 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003695 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003696
3697 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003698 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3699 bgp_info_restore(rn, ri);
3700 else
3701 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003702 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003703 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003704 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003705
3706 /* Process change. */
3707 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3708 bgp_process (bgp, rn, afi, safi);
3709 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003710 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003711 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003712 return;
3713 }
3714 }
3715
3716 /* Make new BGP info. */
3717 new = bgp_info_new ();
3718 new->type = ZEBRA_ROUTE_BGP;
3719 new->sub_type = BGP_ROUTE_STATIC;
3720 new->peer = bgp->peer_self;
3721 SET_FLAG (new->flags, BGP_INFO_VALID);
3722 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003723 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003724
3725 /* Aggregate address increment. */
3726 bgp_aggregate_increment (bgp, p, new, afi, safi);
3727
3728 /* Register new BGP information. */
3729 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003730
3731 /* route_node_get lock */
3732 bgp_unlock_node (rn);
3733
paul718e3742002-12-13 20:15:29 +00003734 /* Process change. */
3735 bgp_process (bgp, rn, afi, safi);
3736
3737 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003738 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003739 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003740}
3741
3742void
paulfee0f4c2004-09-13 05:12:46 +00003743bgp_static_update (struct bgp *bgp, struct prefix *p,
3744 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3745{
3746 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003747 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003748
3749 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3750
paul1eb8ef22005-04-07 07:30:20 +00003751 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003752 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003753 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3754 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003755 }
3756}
3757
paul718e3742002-12-13 20:15:29 +00003758void
3759bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3760 safi_t safi)
3761{
3762 struct bgp_node *rn;
3763 struct bgp_info *ri;
3764
paulfee0f4c2004-09-13 05:12:46 +00003765 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003766
3767 /* Check selected route and self inserted route. */
3768 for (ri = rn->info; ri; ri = ri->next)
3769 if (ri->peer == bgp->peer_self
3770 && ri->type == ZEBRA_ROUTE_BGP
3771 && ri->sub_type == BGP_ROUTE_STATIC)
3772 break;
3773
3774 /* Withdraw static BGP route from routing table. */
3775 if (ri)
3776 {
3777 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003778 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003779 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003780 }
3781
3782 /* Unlock bgp_node_lookup. */
3783 bgp_unlock_node (rn);
3784}
3785
3786void
paulfee0f4c2004-09-13 05:12:46 +00003787bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3788{
3789 struct bgp_static *bgp_static;
3790 struct bgp *bgp;
3791 struct bgp_node *rn;
3792 struct prefix *p;
3793
3794 bgp = rsclient->bgp;
3795
3796 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3797 if ((bgp_static = rn->info) != NULL)
3798 {
3799 p = &rn->p;
3800
3801 bgp_static_update_rsclient (rsclient, p, bgp_static,
3802 afi, safi);
3803 }
3804}
3805
Lou Bergera76d9ca2016-01-12 13:41:53 -05003806/*
3807 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3808 */
paul94f2b392005-06-28 12:44:16 +00003809static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003810bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3811 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003812{
3813 struct bgp_node *rn;
3814 struct bgp_info *ri;
3815
paulfee0f4c2004-09-13 05:12:46 +00003816 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003817
3818 /* Check selected route and self inserted route. */
3819 for (ri = rn->info; ri; ri = ri->next)
3820 if (ri->peer == bgp->peer_self
3821 && ri->type == ZEBRA_ROUTE_BGP
3822 && ri->sub_type == BGP_ROUTE_STATIC)
3823 break;
3824
3825 /* Withdraw static BGP route from routing table. */
3826 if (ri)
3827 {
3828 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003829 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003830 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003831 }
3832
3833 /* Unlock bgp_node_lookup. */
3834 bgp_unlock_node (rn);
3835}
3836
Lou Bergera76d9ca2016-01-12 13:41:53 -05003837static void
3838bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3839 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3840{
3841 struct bgp_node *rn;
3842 struct bgp_info *new;
3843 struct attr *attr_new;
3844 struct attr attr = { 0 };
3845 struct bgp_info *ri;
3846
3847 assert (bgp_static);
3848
3849 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3850
3851 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3852
3853 attr.nexthop = bgp_static->igpnexthop;
3854 attr.med = bgp_static->igpmetric;
3855 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3856
3857 /* Apply route-map. */
3858 if (bgp_static->rmap.name)
3859 {
3860 struct attr attr_tmp = attr;
3861 struct bgp_info info;
3862 int ret;
3863
3864 info.peer = bgp->peer_self;
3865 info.attr = &attr_tmp;
3866
3867 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3868
3869 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3870
3871 bgp->peer_self->rmap_type = 0;
3872
3873 if (ret == RMAP_DENYMATCH)
3874 {
3875 /* Free uninterned attribute. */
3876 bgp_attr_flush (&attr_tmp);
3877
3878 /* Unintern original. */
3879 aspath_unintern (&attr.aspath);
3880 bgp_attr_extra_free (&attr);
3881 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3882 bgp_static->tag);
3883 return;
3884 }
3885
3886 attr_new = bgp_attr_intern (&attr_tmp);
3887 }
3888 else
3889 {
3890 attr_new = bgp_attr_intern (&attr);
3891 }
3892
3893 for (ri = rn->info; ri; ri = ri->next)
3894 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3895 && ri->sub_type == BGP_ROUTE_STATIC)
3896 break;
3897
3898 if (ri)
3899 {
3900 if (attrhash_cmp (ri->attr, attr_new) &&
3901 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3902 {
3903 bgp_unlock_node (rn);
3904 bgp_attr_unintern (&attr_new);
3905 aspath_unintern (&attr.aspath);
3906 bgp_attr_extra_free (&attr);
3907 return;
3908 }
3909 else
3910 {
3911 /* The attribute is changed. */
3912 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3913
3914 /* Rewrite BGP route information. */
3915 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3916 bgp_info_restore(rn, ri);
3917 else
3918 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3919 bgp_attr_unintern (&ri->attr);
3920 ri->attr = attr_new;
3921 ri->uptime = bgp_clock ();
3922
3923 /* Process change. */
3924 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3925 bgp_process (bgp, rn, afi, safi);
3926 bgp_unlock_node (rn);
3927 aspath_unintern (&attr.aspath);
3928 bgp_attr_extra_free (&attr);
3929 return;
3930 }
3931 }
3932
3933
3934 /* Make new BGP info. */
3935 new = bgp_info_new ();
3936 new->type = ZEBRA_ROUTE_BGP;
3937 new->sub_type = BGP_ROUTE_STATIC;
3938 new->peer = bgp->peer_self;
3939 new->attr = attr_new;
3940 SET_FLAG (new->flags, BGP_INFO_VALID);
3941 new->uptime = bgp_clock ();
3942 new->extra = bgp_info_extra_new();
3943 memcpy (new->extra->tag, bgp_static->tag, 3);
3944
3945 /* Aggregate address increment. */
3946 bgp_aggregate_increment (bgp, p, new, afi, safi);
3947
3948 /* Register new BGP information. */
3949 bgp_info_add (rn, new);
3950
3951 /* route_node_get lock */
3952 bgp_unlock_node (rn);
3953
3954 /* Process change. */
3955 bgp_process (bgp, rn, afi, safi);
3956
3957 /* Unintern original. */
3958 aspath_unintern (&attr.aspath);
3959 bgp_attr_extra_free (&attr);
3960}
3961
paul718e3742002-12-13 20:15:29 +00003962/* Configure static BGP network. When user don't run zebra, static
3963 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003964static int
paulfd79ac92004-10-13 05:06:08 +00003965bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003966 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003967{
3968 int ret;
3969 struct prefix p;
3970 struct bgp_static *bgp_static;
3971 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003972 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003973
3974 /* Convert IP prefix string to struct prefix. */
3975 ret = str2prefix (ip_str, &p);
3976 if (! ret)
3977 {
3978 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3979 return CMD_WARNING;
3980 }
3981#ifdef HAVE_IPV6
3982 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3983 {
3984 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3985 VTY_NEWLINE);
3986 return CMD_WARNING;
3987 }
3988#endif /* HAVE_IPV6 */
3989
3990 apply_mask (&p);
3991
3992 /* Set BGP static route configuration. */
3993 rn = bgp_node_get (bgp->route[afi][safi], &p);
3994
3995 if (rn->info)
3996 {
3997 /* Configuration change. */
3998 bgp_static = rn->info;
3999
4000 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004001 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4002 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00004003
paul718e3742002-12-13 20:15:29 +00004004 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00004005
paul718e3742002-12-13 20:15:29 +00004006 if (rmap)
4007 {
4008 if (bgp_static->rmap.name)
4009 free (bgp_static->rmap.name);
4010 bgp_static->rmap.name = strdup (rmap);
4011 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4012 }
4013 else
4014 {
4015 if (bgp_static->rmap.name)
4016 free (bgp_static->rmap.name);
4017 bgp_static->rmap.name = NULL;
4018 bgp_static->rmap.map = NULL;
4019 bgp_static->valid = 0;
4020 }
4021 bgp_unlock_node (rn);
4022 }
4023 else
4024 {
4025 /* New configuration. */
4026 bgp_static = bgp_static_new ();
4027 bgp_static->backdoor = backdoor;
4028 bgp_static->valid = 0;
4029 bgp_static->igpmetric = 0;
4030 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00004031
paul718e3742002-12-13 20:15:29 +00004032 if (rmap)
4033 {
4034 if (bgp_static->rmap.name)
4035 free (bgp_static->rmap.name);
4036 bgp_static->rmap.name = strdup (rmap);
4037 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4038 }
4039 rn->info = bgp_static;
4040 }
4041
4042 /* If BGP scan is not enabled, we should install this route here. */
4043 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4044 {
4045 bgp_static->valid = 1;
4046
4047 if (need_update)
4048 bgp_static_withdraw (bgp, &p, afi, safi);
4049
4050 if (! bgp_static->backdoor)
4051 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4052 }
4053
4054 return CMD_SUCCESS;
4055}
4056
4057/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004058static int
paulfd79ac92004-10-13 05:06:08 +00004059bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004060 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004061{
4062 int ret;
4063 struct prefix p;
4064 struct bgp_static *bgp_static;
4065 struct bgp_node *rn;
4066
4067 /* Convert IP prefix string to struct prefix. */
4068 ret = str2prefix (ip_str, &p);
4069 if (! ret)
4070 {
4071 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4072 return CMD_WARNING;
4073 }
4074#ifdef HAVE_IPV6
4075 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4076 {
4077 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4078 VTY_NEWLINE);
4079 return CMD_WARNING;
4080 }
4081#endif /* HAVE_IPV6 */
4082
4083 apply_mask (&p);
4084
4085 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4086 if (! rn)
4087 {
4088 vty_out (vty, "%% Can't find specified static route configuration.%s",
4089 VTY_NEWLINE);
4090 return CMD_WARNING;
4091 }
4092
4093 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004094
paul718e3742002-12-13 20:15:29 +00004095 /* Update BGP RIB. */
4096 if (! bgp_static->backdoor)
4097 bgp_static_withdraw (bgp, &p, afi, safi);
4098
4099 /* Clear configuration. */
4100 bgp_static_free (bgp_static);
4101 rn->info = NULL;
4102 bgp_unlock_node (rn);
4103 bgp_unlock_node (rn);
4104
4105 return CMD_SUCCESS;
4106}
4107
4108/* Called from bgp_delete(). Delete all static routes from the BGP
4109 instance. */
4110void
4111bgp_static_delete (struct bgp *bgp)
4112{
4113 afi_t afi;
4114 safi_t safi;
4115 struct bgp_node *rn;
4116 struct bgp_node *rm;
4117 struct bgp_table *table;
4118 struct bgp_static *bgp_static;
4119
4120 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4121 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4122 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4123 if (rn->info != NULL)
4124 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004125 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004126 {
4127 table = rn->info;
4128
4129 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4130 {
4131 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004132 bgp_static_withdraw_safi (bgp, &rm->p,
4133 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004134 (struct prefix_rd *)&rn->p,
4135 bgp_static->tag);
4136 bgp_static_free (bgp_static);
4137 rn->info = NULL;
4138 bgp_unlock_node (rn);
4139 }
4140 }
4141 else
4142 {
4143 bgp_static = rn->info;
4144 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4145 bgp_static_free (bgp_static);
4146 rn->info = NULL;
4147 bgp_unlock_node (rn);
4148 }
4149 }
4150}
4151
Lou Bergera76d9ca2016-01-12 13:41:53 -05004152/*
4153 * gpz 110624
4154 * Currently this is used to set static routes for VPN and ENCAP.
4155 * I think it can probably be factored with bgp_static_set.
4156 */
paul718e3742002-12-13 20:15:29 +00004157int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004158bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4159 const char *rd_str, const char *tag_str,
4160 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004161{
4162 int ret;
4163 struct prefix p;
4164 struct prefix_rd prd;
4165 struct bgp *bgp;
4166 struct bgp_node *prn;
4167 struct bgp_node *rn;
4168 struct bgp_table *table;
4169 struct bgp_static *bgp_static;
4170 u_char tag[3];
4171
4172 bgp = vty->index;
4173
4174 ret = str2prefix (ip_str, &p);
4175 if (! ret)
4176 {
4177 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4178 return CMD_WARNING;
4179 }
4180 apply_mask (&p);
4181
4182 ret = str2prefix_rd (rd_str, &prd);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 ret = str2tag (tag_str, tag);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
Lou Bergera76d9ca2016-01-12 13:41:53 -05004196 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004197 (struct prefix *)&prd);
4198 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004199 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004200 else
4201 bgp_unlock_node (prn);
4202 table = prn->info;
4203
4204 rn = bgp_node_get (table, &p);
4205
4206 if (rn->info)
4207 {
4208 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4209 bgp_unlock_node (rn);
4210 }
4211 else
4212 {
4213 /* New configuration. */
4214 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004215 bgp_static->backdoor = 0;
4216 bgp_static->valid = 0;
4217 bgp_static->igpmetric = 0;
4218 bgp_static->igpnexthop.s_addr = 0;
4219 memcpy(bgp_static->tag, tag, 3);
4220 bgp_static->prd = prd;
4221
4222 if (rmap_str)
4223 {
4224 if (bgp_static->rmap.name)
4225 free (bgp_static->rmap.name);
4226 bgp_static->rmap.name = strdup (rmap_str);
4227 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4228 }
paul718e3742002-12-13 20:15:29 +00004229 rn->info = bgp_static;
4230
Lou Bergera76d9ca2016-01-12 13:41:53 -05004231 bgp_static->valid = 1;
4232 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004233 }
4234
4235 return CMD_SUCCESS;
4236}
4237
4238/* Configure static BGP network. */
4239int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004240bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4241 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004242{
4243 int ret;
4244 struct bgp *bgp;
4245 struct prefix p;
4246 struct prefix_rd prd;
4247 struct bgp_node *prn;
4248 struct bgp_node *rn;
4249 struct bgp_table *table;
4250 struct bgp_static *bgp_static;
4251 u_char tag[3];
4252
4253 bgp = vty->index;
4254
4255 /* Convert IP prefix string to struct prefix. */
4256 ret = str2prefix (ip_str, &p);
4257 if (! ret)
4258 {
4259 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4260 return CMD_WARNING;
4261 }
4262 apply_mask (&p);
4263
4264 ret = str2prefix_rd (rd_str, &prd);
4265 if (! ret)
4266 {
4267 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4268 return CMD_WARNING;
4269 }
4270
4271 ret = str2tag (tag_str, tag);
4272 if (! ret)
4273 {
4274 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4275 return CMD_WARNING;
4276 }
4277
Lou Bergera76d9ca2016-01-12 13:41:53 -05004278 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004279 (struct prefix *)&prd);
4280 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004281 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004282 else
4283 bgp_unlock_node (prn);
4284 table = prn->info;
4285
4286 rn = bgp_node_lookup (table, &p);
4287
4288 if (rn)
4289 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004290 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004291
4292 bgp_static = rn->info;
4293 bgp_static_free (bgp_static);
4294 rn->info = NULL;
4295 bgp_unlock_node (rn);
4296 bgp_unlock_node (rn);
4297 }
4298 else
4299 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4300
4301 return CMD_SUCCESS;
4302}
David Lamparter6b0655a2014-06-04 06:53:35 +02004303
paul718e3742002-12-13 20:15:29 +00004304DEFUN (bgp_network,
4305 bgp_network_cmd,
4306 "network A.B.C.D/M",
4307 "Specify a network to announce via BGP\n"
4308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4309{
4310 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004311 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004312}
4313
4314DEFUN (bgp_network_route_map,
4315 bgp_network_route_map_cmd,
4316 "network A.B.C.D/M route-map WORD",
4317 "Specify a network to announce via BGP\n"
4318 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4319 "Route-map to modify the attributes\n"
4320 "Name of the route map\n")
4321{
4322 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004323 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004324}
4325
4326DEFUN (bgp_network_backdoor,
4327 bgp_network_backdoor_cmd,
4328 "network A.B.C.D/M backdoor",
4329 "Specify a network to announce via BGP\n"
4330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4331 "Specify a BGP backdoor route\n")
4332{
Paul Jakma41367172007-08-06 15:24:51 +00004333 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004334 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004335}
4336
4337DEFUN (bgp_network_mask,
4338 bgp_network_mask_cmd,
4339 "network A.B.C.D mask A.B.C.D",
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "Network mask\n"
4343 "Network mask\n")
4344{
4345 int ret;
4346 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004347
paul718e3742002-12-13 20:15:29 +00004348 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4349 if (! ret)
4350 {
4351 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4352 return CMD_WARNING;
4353 }
4354
4355 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004356 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004357}
4358
4359DEFUN (bgp_network_mask_route_map,
4360 bgp_network_mask_route_map_cmd,
4361 "network A.B.C.D mask A.B.C.D route-map WORD",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Route-map to modify the attributes\n"
4367 "Name of the route map\n")
4368{
4369 int ret;
4370 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004371
paul718e3742002-12-13 20:15:29 +00004372 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4373 if (! ret)
4374 {
4375 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4376 return CMD_WARNING;
4377 }
4378
4379 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004380 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004381}
4382
4383DEFUN (bgp_network_mask_backdoor,
4384 bgp_network_mask_backdoor_cmd,
4385 "network A.B.C.D mask A.B.C.D backdoor",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "Network mask\n"
4389 "Network mask\n"
4390 "Specify a BGP backdoor route\n")
4391{
4392 int ret;
4393 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004394
paul718e3742002-12-13 20:15:29 +00004395 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4396 if (! ret)
4397 {
4398 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4399 return CMD_WARNING;
4400 }
4401
Paul Jakma41367172007-08-06 15:24:51 +00004402 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004404}
4405
4406DEFUN (bgp_network_mask_natural,
4407 bgp_network_mask_natural_cmd,
4408 "network A.B.C.D",
4409 "Specify a network to announce via BGP\n"
4410 "Network number\n")
4411{
4412 int ret;
4413 char prefix_str[BUFSIZ];
4414
4415 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4416 if (! ret)
4417 {
4418 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4419 return CMD_WARNING;
4420 }
4421
4422 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004423 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004424}
4425
4426DEFUN (bgp_network_mask_natural_route_map,
4427 bgp_network_mask_natural_route_map_cmd,
4428 "network A.B.C.D route-map WORD",
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Route-map to modify the attributes\n"
4432 "Name of the route map\n")
4433{
4434 int ret;
4435 char prefix_str[BUFSIZ];
4436
4437 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4438 if (! ret)
4439 {
4440 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4441 return CMD_WARNING;
4442 }
4443
4444 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004445 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004446}
4447
4448DEFUN (bgp_network_mask_natural_backdoor,
4449 bgp_network_mask_natural_backdoor_cmd,
4450 "network A.B.C.D backdoor",
4451 "Specify a network to announce via BGP\n"
4452 "Network number\n"
4453 "Specify a BGP backdoor route\n")
4454{
4455 int ret;
4456 char prefix_str[BUFSIZ];
4457
4458 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4459 if (! ret)
4460 {
4461 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4462 return CMD_WARNING;
4463 }
4464
Paul Jakma41367172007-08-06 15:24:51 +00004465 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004466 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004467}
4468
4469DEFUN (no_bgp_network,
4470 no_bgp_network_cmd,
4471 "no network A.B.C.D/M",
4472 NO_STR
4473 "Specify a network to announce via BGP\n"
4474 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4475{
4476 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4477 bgp_node_safi (vty));
4478}
4479
4480ALIAS (no_bgp_network,
4481 no_bgp_network_route_map_cmd,
4482 "no network A.B.C.D/M route-map WORD",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4486 "Route-map to modify the attributes\n"
4487 "Name of the route map\n")
4488
4489ALIAS (no_bgp_network,
4490 no_bgp_network_backdoor_cmd,
4491 "no network A.B.C.D/M backdoor",
4492 NO_STR
4493 "Specify a network to announce via BGP\n"
4494 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4495 "Specify a BGP backdoor route\n")
4496
4497DEFUN (no_bgp_network_mask,
4498 no_bgp_network_mask_cmd,
4499 "no network A.B.C.D mask A.B.C.D",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "Network number\n"
4503 "Network mask\n"
4504 "Network mask\n")
4505{
4506 int ret;
4507 char prefix_str[BUFSIZ];
4508
4509 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4510 if (! ret)
4511 {
4512 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4513 return CMD_WARNING;
4514 }
4515
4516 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4517 bgp_node_safi (vty));
4518}
4519
4520ALIAS (no_bgp_network_mask,
4521 no_bgp_network_mask_route_map_cmd,
4522 "no network A.B.C.D mask A.B.C.D route-map WORD",
4523 NO_STR
4524 "Specify a network to announce via BGP\n"
4525 "Network number\n"
4526 "Network mask\n"
4527 "Network mask\n"
4528 "Route-map to modify the attributes\n"
4529 "Name of the route map\n")
4530
4531ALIAS (no_bgp_network_mask,
4532 no_bgp_network_mask_backdoor_cmd,
4533 "no network A.B.C.D mask A.B.C.D backdoor",
4534 NO_STR
4535 "Specify a network to announce via BGP\n"
4536 "Network number\n"
4537 "Network mask\n"
4538 "Network mask\n"
4539 "Specify a BGP backdoor route\n")
4540
4541DEFUN (no_bgp_network_mask_natural,
4542 no_bgp_network_mask_natural_cmd,
4543 "no network A.B.C.D",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "Network number\n")
4547{
4548 int ret;
4549 char prefix_str[BUFSIZ];
4550
4551 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4552 if (! ret)
4553 {
4554 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4555 return CMD_WARNING;
4556 }
4557
4558 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4559 bgp_node_safi (vty));
4560}
4561
4562ALIAS (no_bgp_network_mask_natural,
4563 no_bgp_network_mask_natural_route_map_cmd,
4564 "no network A.B.C.D route-map WORD",
4565 NO_STR
4566 "Specify a network to announce via BGP\n"
4567 "Network number\n"
4568 "Route-map to modify the attributes\n"
4569 "Name of the route map\n")
4570
4571ALIAS (no_bgp_network_mask_natural,
4572 no_bgp_network_mask_natural_backdoor_cmd,
4573 "no network A.B.C.D backdoor",
4574 NO_STR
4575 "Specify a network to announce via BGP\n"
4576 "Network number\n"
4577 "Specify a BGP backdoor route\n")
4578
4579#ifdef HAVE_IPV6
4580DEFUN (ipv6_bgp_network,
4581 ipv6_bgp_network_cmd,
4582 "network X:X::X:X/M",
4583 "Specify a network to announce via BGP\n"
4584 "IPv6 prefix <network>/<length>\n")
4585{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304586 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004587 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004588}
4589
4590DEFUN (ipv6_bgp_network_route_map,
4591 ipv6_bgp_network_route_map_cmd,
4592 "network X:X::X:X/M route-map WORD",
4593 "Specify a network to announce via BGP\n"
4594 "IPv6 prefix <network>/<length>\n"
4595 "Route-map to modify the attributes\n"
4596 "Name of the route map\n")
4597{
4598 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004599 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004600}
4601
4602DEFUN (no_ipv6_bgp_network,
4603 no_ipv6_bgp_network_cmd,
4604 "no network X:X::X:X/M",
4605 NO_STR
4606 "Specify a network to announce via BGP\n"
4607 "IPv6 prefix <network>/<length>\n")
4608{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304609 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004610}
4611
4612ALIAS (no_ipv6_bgp_network,
4613 no_ipv6_bgp_network_route_map_cmd,
4614 "no network X:X::X:X/M route-map WORD",
4615 NO_STR
4616 "Specify a network to announce via BGP\n"
4617 "IPv6 prefix <network>/<length>\n"
4618 "Route-map to modify the attributes\n"
4619 "Name of the route map\n")
4620
4621ALIAS (ipv6_bgp_network,
4622 old_ipv6_bgp_network_cmd,
4623 "ipv6 bgp network X:X::X:X/M",
4624 IPV6_STR
4625 BGP_STR
4626 "Specify a network to announce via BGP\n"
4627 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4628
4629ALIAS (no_ipv6_bgp_network,
4630 old_no_ipv6_bgp_network_cmd,
4631 "no ipv6 bgp network X:X::X:X/M",
4632 NO_STR
4633 IPV6_STR
4634 BGP_STR
4635 "Specify a network to announce via BGP\n"
4636 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4637#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004638
4639/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4640ALIAS_DEPRECATED (bgp_network,
4641 bgp_network_ttl_cmd,
4642 "network A.B.C.D/M pathlimit <0-255>",
4643 "Specify a network to announce via BGP\n"
4644 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4645 "AS-Path hopcount limit attribute\n"
4646 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4647ALIAS_DEPRECATED (bgp_network_backdoor,
4648 bgp_network_backdoor_ttl_cmd,
4649 "network A.B.C.D/M backdoor pathlimit <0-255>",
4650 "Specify a network to announce via BGP\n"
4651 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4652 "Specify a BGP backdoor route\n"
4653 "AS-Path hopcount limit attribute\n"
4654 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4655ALIAS_DEPRECATED (bgp_network_mask,
4656 bgp_network_mask_ttl_cmd,
4657 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "AS-Path hopcount limit attribute\n"
4663 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4664ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4665 bgp_network_mask_backdoor_ttl_cmd,
4666 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4667 "Specify a network to announce via BGP\n"
4668 "Network number\n"
4669 "Network mask\n"
4670 "Network mask\n"
4671 "Specify a BGP backdoor route\n"
4672 "AS-Path hopcount limit attribute\n"
4673 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4674ALIAS_DEPRECATED (bgp_network_mask_natural,
4675 bgp_network_mask_natural_ttl_cmd,
4676 "network A.B.C.D pathlimit <0-255>",
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "AS-Path hopcount limit attribute\n"
4680 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4681ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4682 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004683 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004684 "Specify a network to announce via BGP\n"
4685 "Network number\n"
4686 "Specify a BGP backdoor route\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_bgp_network,
4690 no_bgp_network_ttl_cmd,
4691 "no network A.B.C.D/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4697ALIAS_DEPRECATED (no_bgp_network,
4698 no_bgp_network_backdoor_ttl_cmd,
4699 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4700 NO_STR
4701 "Specify a network to announce via BGP\n"
4702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4703 "Specify a BGP backdoor route\n"
4704 "AS-Path hopcount limit attribute\n"
4705 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4706ALIAS_DEPRECATED (no_bgp_network,
4707 no_bgp_network_mask_ttl_cmd,
4708 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4709 NO_STR
4710 "Specify a network to announce via BGP\n"
4711 "Network number\n"
4712 "Network mask\n"
4713 "Network mask\n"
4714 "AS-Path hopcount limit attribute\n"
4715 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4716ALIAS_DEPRECATED (no_bgp_network_mask,
4717 no_bgp_network_mask_backdoor_ttl_cmd,
4718 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4719 NO_STR
4720 "Specify a network to announce via BGP\n"
4721 "Network number\n"
4722 "Network mask\n"
4723 "Network mask\n"
4724 "Specify a BGP backdoor route\n"
4725 "AS-Path hopcount limit attribute\n"
4726 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4727ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4728 no_bgp_network_mask_natural_ttl_cmd,
4729 "no network A.B.C.D pathlimit <0-255>",
4730 NO_STR
4731 "Specify a network to announce via BGP\n"
4732 "Network number\n"
4733 "AS-Path hopcount limit attribute\n"
4734 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4735ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4736 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4737 "no network A.B.C.D backdoor pathlimit <0-255>",
4738 NO_STR
4739 "Specify a network to announce via BGP\n"
4740 "Network number\n"
4741 "Specify a BGP backdoor route\n"
4742 "AS-Path hopcount limit attribute\n"
4743 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004744#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004745ALIAS_DEPRECATED (ipv6_bgp_network,
4746 ipv6_bgp_network_ttl_cmd,
4747 "network X:X::X:X/M pathlimit <0-255>",
4748 "Specify a network to announce via BGP\n"
4749 "IPv6 prefix <network>/<length>\n"
4750 "AS-Path hopcount limit attribute\n"
4751 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4752ALIAS_DEPRECATED (no_ipv6_bgp_network,
4753 no_ipv6_bgp_network_ttl_cmd,
4754 "no network X:X::X:X/M pathlimit <0-255>",
4755 NO_STR
4756 "Specify a network to announce via BGP\n"
4757 "IPv6 prefix <network>/<length>\n"
4758 "AS-Path hopcount limit attribute\n"
4759 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004760#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004761
paul718e3742002-12-13 20:15:29 +00004762/* Aggreagete address:
4763
4764 advertise-map Set condition to advertise attribute
4765 as-set Generate AS set path information
4766 attribute-map Set attributes of aggregate
4767 route-map Set parameters of aggregate
4768 summary-only Filter more specific routes from updates
4769 suppress-map Conditionally filter more specific routes from updates
4770 <cr>
4771 */
4772struct bgp_aggregate
4773{
4774 /* Summary-only flag. */
4775 u_char summary_only;
4776
4777 /* AS set generation. */
4778 u_char as_set;
4779
4780 /* Route-map for aggregated route. */
4781 struct route_map *map;
4782
4783 /* Suppress-count. */
4784 unsigned long count;
4785
4786 /* SAFI configuration. */
4787 safi_t safi;
4788};
4789
paul94f2b392005-06-28 12:44:16 +00004790static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004791bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004792{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004793 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004794}
4795
paul94f2b392005-06-28 12:44:16 +00004796static void
paul718e3742002-12-13 20:15:29 +00004797bgp_aggregate_free (struct bgp_aggregate *aggregate)
4798{
4799 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4800}
4801
paul94f2b392005-06-28 12:44:16 +00004802static void
paul718e3742002-12-13 20:15:29 +00004803bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4804 afi_t afi, safi_t safi, struct bgp_info *del,
4805 struct bgp_aggregate *aggregate)
4806{
4807 struct bgp_table *table;
4808 struct bgp_node *top;
4809 struct bgp_node *rn;
4810 u_char origin;
4811 struct aspath *aspath = NULL;
4812 struct aspath *asmerge = NULL;
4813 struct community *community = NULL;
4814 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004815 struct bgp_info *ri;
4816 struct bgp_info *new;
4817 int first = 1;
4818 unsigned long match = 0;
4819
paul718e3742002-12-13 20:15:29 +00004820 /* ORIGIN attribute: If at least one route among routes that are
4821 aggregated has ORIGIN with the value INCOMPLETE, then the
4822 aggregated route must have the ORIGIN attribute with the value
4823 INCOMPLETE. Otherwise, if at least one route among routes that
4824 are aggregated has ORIGIN with the value EGP, then the aggregated
4825 route must have the origin attribute with the value EGP. In all
4826 other case the value of the ORIGIN attribute of the aggregated
4827 route is INTERNAL. */
4828 origin = BGP_ORIGIN_IGP;
4829
4830 table = bgp->rib[afi][safi];
4831
4832 top = bgp_node_get (table, p);
4833 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4834 if (rn->p.prefixlen > p->prefixlen)
4835 {
4836 match = 0;
4837
4838 for (ri = rn->info; ri; ri = ri->next)
4839 {
4840 if (BGP_INFO_HOLDDOWN (ri))
4841 continue;
4842
4843 if (del && ri == del)
4844 continue;
4845
4846 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004847 first = 0;
paul718e3742002-12-13 20:15:29 +00004848
4849#ifdef AGGREGATE_NEXTHOP_CHECK
4850 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4851 || ri->attr->med != med)
4852 {
4853 if (aspath)
4854 aspath_free (aspath);
4855 if (community)
4856 community_free (community);
4857 bgp_unlock_node (rn);
4858 bgp_unlock_node (top);
4859 return;
4860 }
4861#endif /* AGGREGATE_NEXTHOP_CHECK */
4862
4863 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4864 {
4865 if (aggregate->summary_only)
4866 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004867 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004869 match++;
4870 }
4871
4872 aggregate->count++;
4873
4874 if (aggregate->as_set)
4875 {
4876 if (origin < ri->attr->origin)
4877 origin = ri->attr->origin;
4878
4879 if (aspath)
4880 {
4881 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4882 aspath_free (aspath);
4883 aspath = asmerge;
4884 }
4885 else
4886 aspath = aspath_dup (ri->attr->aspath);
4887
4888 if (ri->attr->community)
4889 {
4890 if (community)
4891 {
4892 commerge = community_merge (community,
4893 ri->attr->community);
4894 community = community_uniq_sort (commerge);
4895 community_free (commerge);
4896 }
4897 else
4898 community = community_dup (ri->attr->community);
4899 }
4900 }
4901 }
4902 }
4903 if (match)
4904 bgp_process (bgp, rn, afi, safi);
4905 }
4906 bgp_unlock_node (top);
4907
4908 if (rinew)
4909 {
4910 aggregate->count++;
4911
4912 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004913 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004914
4915 if (aggregate->as_set)
4916 {
4917 if (origin < rinew->attr->origin)
4918 origin = rinew->attr->origin;
4919
4920 if (aspath)
4921 {
4922 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4923 aspath_free (aspath);
4924 aspath = asmerge;
4925 }
4926 else
4927 aspath = aspath_dup (rinew->attr->aspath);
4928
4929 if (rinew->attr->community)
4930 {
4931 if (community)
4932 {
4933 commerge = community_merge (community,
4934 rinew->attr->community);
4935 community = community_uniq_sort (commerge);
4936 community_free (commerge);
4937 }
4938 else
4939 community = community_dup (rinew->attr->community);
4940 }
4941 }
4942 }
4943
4944 if (aggregate->count > 0)
4945 {
4946 rn = bgp_node_get (table, p);
4947 new = bgp_info_new ();
4948 new->type = ZEBRA_ROUTE_BGP;
4949 new->sub_type = BGP_ROUTE_AGGREGATE;
4950 new->peer = bgp->peer_self;
4951 SET_FLAG (new->flags, BGP_INFO_VALID);
4952 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004953 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004954
4955 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004956 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004957 bgp_process (bgp, rn, afi, safi);
4958 }
4959 else
4960 {
4961 if (aspath)
4962 aspath_free (aspath);
4963 if (community)
4964 community_free (community);
4965 }
4966}
4967
4968void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4969 struct bgp_aggregate *);
4970
4971void
4972bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4973 struct bgp_info *ri, afi_t afi, safi_t safi)
4974{
4975 struct bgp_node *child;
4976 struct bgp_node *rn;
4977 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004978 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004979
4980 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004981 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004982 return;
4983
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004984 table = bgp->aggregate[afi][safi];
4985
4986 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004987 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004988 return;
4989
paul718e3742002-12-13 20:15:29 +00004990 if (p->prefixlen == 0)
4991 return;
4992
4993 if (BGP_INFO_HOLDDOWN (ri))
4994 return;
4995
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004996 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004997
4998 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004999 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005000 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5001 {
5002 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005003 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00005004 }
5005 bgp_unlock_node (child);
5006}
5007
5008void
5009bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5010 struct bgp_info *del, afi_t afi, safi_t safi)
5011{
5012 struct bgp_node *child;
5013 struct bgp_node *rn;
5014 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005015 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00005016
5017 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05005018 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00005019 return;
5020
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005021 table = bgp->aggregate[afi][safi];
5022
5023 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005024 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005025 return;
5026
paul718e3742002-12-13 20:15:29 +00005027 if (p->prefixlen == 0)
5028 return;
5029
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02005030 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00005031
5032 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005033 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005034 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5035 {
5036 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005037 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00005038 }
5039 bgp_unlock_node (child);
5040}
5041
paul94f2b392005-06-28 12:44:16 +00005042static void
paul718e3742002-12-13 20:15:29 +00005043bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5044 struct bgp_aggregate *aggregate)
5045{
5046 struct bgp_table *table;
5047 struct bgp_node *top;
5048 struct bgp_node *rn;
5049 struct bgp_info *new;
5050 struct bgp_info *ri;
5051 unsigned long match;
5052 u_char origin = BGP_ORIGIN_IGP;
5053 struct aspath *aspath = NULL;
5054 struct aspath *asmerge = NULL;
5055 struct community *community = NULL;
5056 struct community *commerge = NULL;
5057
5058 table = bgp->rib[afi][safi];
5059
5060 /* Sanity check. */
5061 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5062 return;
5063 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5064 return;
5065
5066 /* If routes exists below this node, generate aggregate routes. */
5067 top = bgp_node_get (table, p);
5068 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5069 if (rn->p.prefixlen > p->prefixlen)
5070 {
5071 match = 0;
5072
5073 for (ri = rn->info; ri; ri = ri->next)
5074 {
5075 if (BGP_INFO_HOLDDOWN (ri))
5076 continue;
5077
5078 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5079 {
5080 /* summary-only aggregate route suppress aggregated
5081 route announcement. */
5082 if (aggregate->summary_only)
5083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005084 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005085 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005086 match++;
5087 }
5088 /* as-set aggregate route generate origin, as path,
5089 community aggregation. */
5090 if (aggregate->as_set)
5091 {
5092 if (origin < ri->attr->origin)
5093 origin = ri->attr->origin;
5094
5095 if (aspath)
5096 {
5097 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5098 aspath_free (aspath);
5099 aspath = asmerge;
5100 }
5101 else
5102 aspath = aspath_dup (ri->attr->aspath);
5103
5104 if (ri->attr->community)
5105 {
5106 if (community)
5107 {
5108 commerge = community_merge (community,
5109 ri->attr->community);
5110 community = community_uniq_sort (commerge);
5111 community_free (commerge);
5112 }
5113 else
5114 community = community_dup (ri->attr->community);
5115 }
5116 }
5117 aggregate->count++;
5118 }
5119 }
5120
5121 /* If this node is suppressed, process the change. */
5122 if (match)
5123 bgp_process (bgp, rn, afi, safi);
5124 }
5125 bgp_unlock_node (top);
5126
5127 /* Add aggregate route to BGP table. */
5128 if (aggregate->count)
5129 {
5130 rn = bgp_node_get (table, p);
5131
5132 new = bgp_info_new ();
5133 new->type = ZEBRA_ROUTE_BGP;
5134 new->sub_type = BGP_ROUTE_AGGREGATE;
5135 new->peer = bgp->peer_self;
5136 SET_FLAG (new->flags, BGP_INFO_VALID);
5137 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005138 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005139
5140 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005141 bgp_unlock_node (rn);
5142
paul718e3742002-12-13 20:15:29 +00005143 /* Process change. */
5144 bgp_process (bgp, rn, afi, safi);
5145 }
Denil Virae2a92582015-08-11 13:34:59 -07005146 else
5147 {
5148 if (aspath)
5149 aspath_free (aspath);
5150 if (community)
5151 community_free (community);
5152 }
paul718e3742002-12-13 20:15:29 +00005153}
5154
5155void
5156bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5157 safi_t safi, struct bgp_aggregate *aggregate)
5158{
5159 struct bgp_table *table;
5160 struct bgp_node *top;
5161 struct bgp_node *rn;
5162 struct bgp_info *ri;
5163 unsigned long match;
5164
5165 table = bgp->rib[afi][safi];
5166
5167 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5168 return;
5169 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5170 return;
5171
5172 /* If routes exists below this node, generate aggregate routes. */
5173 top = bgp_node_get (table, p);
5174 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5175 if (rn->p.prefixlen > p->prefixlen)
5176 {
5177 match = 0;
5178
5179 for (ri = rn->info; ri; ri = ri->next)
5180 {
5181 if (BGP_INFO_HOLDDOWN (ri))
5182 continue;
5183
5184 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5185 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005186 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005188 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005189
Paul Jakmafb982c22007-05-04 20:15:47 +00005190 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005191 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005192 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005193 match++;
5194 }
5195 }
5196 aggregate->count--;
5197 }
5198 }
5199
Paul Jakmafb982c22007-05-04 20:15:47 +00005200 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005201 if (match)
5202 bgp_process (bgp, rn, afi, safi);
5203 }
5204 bgp_unlock_node (top);
5205
5206 /* Delete aggregate route from BGP table. */
5207 rn = bgp_node_get (table, p);
5208
5209 for (ri = rn->info; ri; ri = ri->next)
5210 if (ri->peer == bgp->peer_self
5211 && ri->type == ZEBRA_ROUTE_BGP
5212 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5213 break;
5214
5215 /* Withdraw static BGP route from routing table. */
5216 if (ri)
5217 {
paul718e3742002-12-13 20:15:29 +00005218 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005219 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005220 }
5221
5222 /* Unlock bgp_node_lookup. */
5223 bgp_unlock_node (rn);
5224}
5225
5226/* Aggregate route attribute. */
5227#define AGGREGATE_SUMMARY_ONLY 1
5228#define AGGREGATE_AS_SET 1
5229
paul94f2b392005-06-28 12:44:16 +00005230static int
Robert Baysf6269b42010-08-05 10:26:28 -07005231bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5232 afi_t afi, safi_t safi)
5233{
5234 int ret;
5235 struct prefix p;
5236 struct bgp_node *rn;
5237 struct bgp *bgp;
5238 struct bgp_aggregate *aggregate;
5239
5240 /* Convert string to prefix structure. */
5241 ret = str2prefix (prefix_str, &p);
5242 if (!ret)
5243 {
5244 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5245 return CMD_WARNING;
5246 }
5247 apply_mask (&p);
5248
5249 /* Get BGP structure. */
5250 bgp = vty->index;
5251
5252 /* Old configuration check. */
5253 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5254 if (! rn)
5255 {
5256 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5257 VTY_NEWLINE);
5258 return CMD_WARNING;
5259 }
5260
5261 aggregate = rn->info;
5262 if (aggregate->safi & SAFI_UNICAST)
5263 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (aggregate->safi & SAFI_MULTICAST)
5265 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 /* Unlock aggregate address configuration. */
5268 rn->info = NULL;
5269 bgp_aggregate_free (aggregate);
5270 bgp_unlock_node (rn);
5271 bgp_unlock_node (rn);
5272
5273 return CMD_SUCCESS;
5274}
5275
5276static int
5277bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005278 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005279 u_char summary_only, u_char as_set)
5280{
5281 int ret;
5282 struct prefix p;
5283 struct bgp_node *rn;
5284 struct bgp *bgp;
5285 struct bgp_aggregate *aggregate;
5286
5287 /* Convert string to prefix structure. */
5288 ret = str2prefix (prefix_str, &p);
5289 if (!ret)
5290 {
5291 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5292 return CMD_WARNING;
5293 }
5294 apply_mask (&p);
5295
5296 /* Get BGP structure. */
5297 bgp = vty->index;
5298
5299 /* Old configuration check. */
5300 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5301
5302 if (rn->info)
5303 {
5304 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005305 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005306 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5307 if (ret)
5308 {
Robert Bays368473f2010-08-05 10:26:29 -07005309 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5310 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005311 return CMD_WARNING;
5312 }
paul718e3742002-12-13 20:15:29 +00005313 }
5314
5315 /* Make aggregate address structure. */
5316 aggregate = bgp_aggregate_new ();
5317 aggregate->summary_only = summary_only;
5318 aggregate->as_set = as_set;
5319 aggregate->safi = safi;
5320 rn->info = aggregate;
5321
5322 /* Aggregate address insert into BGP routing table. */
5323 if (safi & SAFI_UNICAST)
5324 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5325 if (safi & SAFI_MULTICAST)
5326 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5327
5328 return CMD_SUCCESS;
5329}
5330
paul718e3742002-12-13 20:15:29 +00005331DEFUN (aggregate_address,
5332 aggregate_address_cmd,
5333 "aggregate-address A.B.C.D/M",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n")
5336{
5337 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5338}
5339
5340DEFUN (aggregate_address_mask,
5341 aggregate_address_mask_cmd,
5342 "aggregate-address A.B.C.D A.B.C.D",
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate address\n"
5345 "Aggregate mask\n")
5346{
5347 int ret;
5348 char prefix_str[BUFSIZ];
5349
5350 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5351
5352 if (! ret)
5353 {
5354 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5355 return CMD_WARNING;
5356 }
5357
5358 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5359 0, 0);
5360}
5361
5362DEFUN (aggregate_address_summary_only,
5363 aggregate_address_summary_only_cmd,
5364 "aggregate-address A.B.C.D/M summary-only",
5365 "Configure BGP aggregate entries\n"
5366 "Aggregate prefix\n"
5367 "Filter more specific routes from updates\n")
5368{
5369 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5370 AGGREGATE_SUMMARY_ONLY, 0);
5371}
5372
5373DEFUN (aggregate_address_mask_summary_only,
5374 aggregate_address_mask_summary_only_cmd,
5375 "aggregate-address A.B.C.D A.B.C.D summary-only",
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate address\n"
5378 "Aggregate mask\n"
5379 "Filter more specific routes from updates\n")
5380{
5381 int ret;
5382 char prefix_str[BUFSIZ];
5383
5384 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5385
5386 if (! ret)
5387 {
5388 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5389 return CMD_WARNING;
5390 }
5391
5392 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5393 AGGREGATE_SUMMARY_ONLY, 0);
5394}
5395
5396DEFUN (aggregate_address_as_set,
5397 aggregate_address_as_set_cmd,
5398 "aggregate-address A.B.C.D/M as-set",
5399 "Configure BGP aggregate entries\n"
5400 "Aggregate prefix\n"
5401 "Generate AS set path information\n")
5402{
5403 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5404 0, AGGREGATE_AS_SET);
5405}
5406
5407DEFUN (aggregate_address_mask_as_set,
5408 aggregate_address_mask_as_set_cmd,
5409 "aggregate-address A.B.C.D A.B.C.D as-set",
5410 "Configure BGP aggregate entries\n"
5411 "Aggregate address\n"
5412 "Aggregate mask\n"
5413 "Generate AS set path information\n")
5414{
5415 int ret;
5416 char prefix_str[BUFSIZ];
5417
5418 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5419
5420 if (! ret)
5421 {
5422 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5423 return CMD_WARNING;
5424 }
5425
5426 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5427 0, AGGREGATE_AS_SET);
5428}
5429
5430
5431DEFUN (aggregate_address_as_set_summary,
5432 aggregate_address_as_set_summary_cmd,
5433 "aggregate-address A.B.C.D/M as-set summary-only",
5434 "Configure BGP aggregate entries\n"
5435 "Aggregate prefix\n"
5436 "Generate AS set path information\n"
5437 "Filter more specific routes from updates\n")
5438{
5439 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5440 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5441}
5442
5443ALIAS (aggregate_address_as_set_summary,
5444 aggregate_address_summary_as_set_cmd,
5445 "aggregate-address A.B.C.D/M summary-only as-set",
5446 "Configure BGP aggregate entries\n"
5447 "Aggregate prefix\n"
5448 "Filter more specific routes from updates\n"
5449 "Generate AS set path information\n")
5450
5451DEFUN (aggregate_address_mask_as_set_summary,
5452 aggregate_address_mask_as_set_summary_cmd,
5453 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5454 "Configure BGP aggregate entries\n"
5455 "Aggregate address\n"
5456 "Aggregate mask\n"
5457 "Generate AS set path information\n"
5458 "Filter more specific routes from updates\n")
5459{
5460 int ret;
5461 char prefix_str[BUFSIZ];
5462
5463 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5464
5465 if (! ret)
5466 {
5467 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5468 return CMD_WARNING;
5469 }
5470
5471 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5472 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5473}
5474
5475ALIAS (aggregate_address_mask_as_set_summary,
5476 aggregate_address_mask_summary_as_set_cmd,
5477 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5478 "Configure BGP aggregate entries\n"
5479 "Aggregate address\n"
5480 "Aggregate mask\n"
5481 "Filter more specific routes from updates\n"
5482 "Generate AS set path information\n")
5483
5484DEFUN (no_aggregate_address,
5485 no_aggregate_address_cmd,
5486 "no aggregate-address A.B.C.D/M",
5487 NO_STR
5488 "Configure BGP aggregate entries\n"
5489 "Aggregate prefix\n")
5490{
5491 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5492}
5493
5494ALIAS (no_aggregate_address,
5495 no_aggregate_address_summary_only_cmd,
5496 "no aggregate-address A.B.C.D/M summary-only",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate prefix\n"
5500 "Filter more specific routes from updates\n")
5501
5502ALIAS (no_aggregate_address,
5503 no_aggregate_address_as_set_cmd,
5504 "no aggregate-address A.B.C.D/M as-set",
5505 NO_STR
5506 "Configure BGP aggregate entries\n"
5507 "Aggregate prefix\n"
5508 "Generate AS set path information\n")
5509
5510ALIAS (no_aggregate_address,
5511 no_aggregate_address_as_set_summary_cmd,
5512 "no aggregate-address A.B.C.D/M as-set summary-only",
5513 NO_STR
5514 "Configure BGP aggregate entries\n"
5515 "Aggregate prefix\n"
5516 "Generate AS set path information\n"
5517 "Filter more specific routes from updates\n")
5518
5519ALIAS (no_aggregate_address,
5520 no_aggregate_address_summary_as_set_cmd,
5521 "no aggregate-address A.B.C.D/M summary-only as-set",
5522 NO_STR
5523 "Configure BGP aggregate entries\n"
5524 "Aggregate prefix\n"
5525 "Filter more specific routes from updates\n"
5526 "Generate AS set path information\n")
5527
5528DEFUN (no_aggregate_address_mask,
5529 no_aggregate_address_mask_cmd,
5530 "no aggregate-address A.B.C.D A.B.C.D",
5531 NO_STR
5532 "Configure BGP aggregate entries\n"
5533 "Aggregate address\n"
5534 "Aggregate mask\n")
5535{
5536 int ret;
5537 char prefix_str[BUFSIZ];
5538
5539 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5540
5541 if (! ret)
5542 {
5543 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5544 return CMD_WARNING;
5545 }
5546
5547 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5548}
5549
5550ALIAS (no_aggregate_address_mask,
5551 no_aggregate_address_mask_summary_only_cmd,
5552 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5553 NO_STR
5554 "Configure BGP aggregate entries\n"
5555 "Aggregate address\n"
5556 "Aggregate mask\n"
5557 "Filter more specific routes from updates\n")
5558
5559ALIAS (no_aggregate_address_mask,
5560 no_aggregate_address_mask_as_set_cmd,
5561 "no aggregate-address A.B.C.D A.B.C.D as-set",
5562 NO_STR
5563 "Configure BGP aggregate entries\n"
5564 "Aggregate address\n"
5565 "Aggregate mask\n"
5566 "Generate AS set path information\n")
5567
5568ALIAS (no_aggregate_address_mask,
5569 no_aggregate_address_mask_as_set_summary_cmd,
5570 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5571 NO_STR
5572 "Configure BGP aggregate entries\n"
5573 "Aggregate address\n"
5574 "Aggregate mask\n"
5575 "Generate AS set path information\n"
5576 "Filter more specific routes from updates\n")
5577
5578ALIAS (no_aggregate_address_mask,
5579 no_aggregate_address_mask_summary_as_set_cmd,
5580 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5581 NO_STR
5582 "Configure BGP aggregate entries\n"
5583 "Aggregate address\n"
5584 "Aggregate mask\n"
5585 "Filter more specific routes from updates\n"
5586 "Generate AS set path information\n")
5587
5588#ifdef HAVE_IPV6
5589DEFUN (ipv6_aggregate_address,
5590 ipv6_aggregate_address_cmd,
5591 "aggregate-address X:X::X:X/M",
5592 "Configure BGP aggregate entries\n"
5593 "Aggregate prefix\n")
5594{
5595 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5596}
5597
5598DEFUN (ipv6_aggregate_address_summary_only,
5599 ipv6_aggregate_address_summary_only_cmd,
5600 "aggregate-address X:X::X:X/M summary-only",
5601 "Configure BGP aggregate entries\n"
5602 "Aggregate prefix\n"
5603 "Filter more specific routes from updates\n")
5604{
5605 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5606 AGGREGATE_SUMMARY_ONLY, 0);
5607}
5608
5609DEFUN (no_ipv6_aggregate_address,
5610 no_ipv6_aggregate_address_cmd,
5611 "no aggregate-address X:X::X:X/M",
5612 NO_STR
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate prefix\n")
5615{
5616 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5617}
5618
5619DEFUN (no_ipv6_aggregate_address_summary_only,
5620 no_ipv6_aggregate_address_summary_only_cmd,
5621 "no aggregate-address X:X::X:X/M summary-only",
5622 NO_STR
5623 "Configure BGP aggregate entries\n"
5624 "Aggregate prefix\n"
5625 "Filter more specific routes from updates\n")
5626{
5627 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5628}
5629
5630ALIAS (ipv6_aggregate_address,
5631 old_ipv6_aggregate_address_cmd,
5632 "ipv6 bgp aggregate-address X:X::X:X/M",
5633 IPV6_STR
5634 BGP_STR
5635 "Configure BGP aggregate entries\n"
5636 "Aggregate prefix\n")
5637
5638ALIAS (ipv6_aggregate_address_summary_only,
5639 old_ipv6_aggregate_address_summary_only_cmd,
5640 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5641 IPV6_STR
5642 BGP_STR
5643 "Configure BGP aggregate entries\n"
5644 "Aggregate prefix\n"
5645 "Filter more specific routes from updates\n")
5646
5647ALIAS (no_ipv6_aggregate_address,
5648 old_no_ipv6_aggregate_address_cmd,
5649 "no ipv6 bgp aggregate-address X:X::X:X/M",
5650 NO_STR
5651 IPV6_STR
5652 BGP_STR
5653 "Configure BGP aggregate entries\n"
5654 "Aggregate prefix\n")
5655
5656ALIAS (no_ipv6_aggregate_address_summary_only,
5657 old_no_ipv6_aggregate_address_summary_only_cmd,
5658 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5659 NO_STR
5660 IPV6_STR
5661 BGP_STR
5662 "Configure BGP aggregate entries\n"
5663 "Aggregate prefix\n"
5664 "Filter more specific routes from updates\n")
5665#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005666
paul718e3742002-12-13 20:15:29 +00005667/* Redistribute route treatment. */
5668void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005669bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5670 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005671 u_int32_t metric, u_char type)
5672{
5673 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005674 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005675 struct bgp_info *new;
5676 struct bgp_info *bi;
5677 struct bgp_info info;
5678 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005679 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005680 struct attr *new_attr;
5681 afi_t afi;
5682 int ret;
5683
5684 /* Make default attribute. */
5685 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5686 if (nexthop)
5687 attr.nexthop = *nexthop;
5688
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005689#ifdef HAVE_IPV6
5690 if (nexthop6)
5691 {
5692 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5693 extra->mp_nexthop_global = *nexthop6;
5694 extra->mp_nexthop_len = 16;
5695 }
5696#endif
5697
paul718e3742002-12-13 20:15:29 +00005698 attr.med = metric;
5699 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5700
paul1eb8ef22005-04-07 07:30:20 +00005701 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005702 {
5703 afi = family2afi (p->family);
5704
5705 if (bgp->redist[afi][type])
5706 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005707 struct attr attr_new;
5708 struct attr_extra extra_new;
5709
paul718e3742002-12-13 20:15:29 +00005710 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005711 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005712 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005713
5714 if (bgp->redist_metric_flag[afi][type])
5715 attr_new.med = bgp->redist_metric[afi][type];
5716
5717 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005718 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005719 {
5720 info.peer = bgp->peer_self;
5721 info.attr = &attr_new;
5722
paulfee0f4c2004-09-13 05:12:46 +00005723 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5724
paul718e3742002-12-13 20:15:29 +00005725 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5726 &info);
paulfee0f4c2004-09-13 05:12:46 +00005727
5728 bgp->peer_self->rmap_type = 0;
5729
paul718e3742002-12-13 20:15:29 +00005730 if (ret == RMAP_DENYMATCH)
5731 {
5732 /* Free uninterned attribute. */
5733 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005734
paul718e3742002-12-13 20:15:29 +00005735 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005736 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005738 bgp_redistribute_delete (p, type);
5739 return;
5740 }
5741 }
5742
Paul Jakmafb982c22007-05-04 20:15:47 +00005743 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5744 afi, SAFI_UNICAST, p, NULL);
5745
paul718e3742002-12-13 20:15:29 +00005746 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005747
paul718e3742002-12-13 20:15:29 +00005748 for (bi = bn->info; bi; bi = bi->next)
5749 if (bi->peer == bgp->peer_self
5750 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5751 break;
5752
5753 if (bi)
5754 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005755 if (attrhash_cmp (bi->attr, new_attr) &&
5756 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005757 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005758 bgp_attr_unintern (&new_attr);
5759 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005760 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005761 bgp_unlock_node (bn);
5762 return;
5763 }
5764 else
5765 {
5766 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005767 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005768
5769 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005770 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5771 bgp_info_restore(bn, bi);
5772 else
5773 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005774 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005775 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005776 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005777
5778 /* Process change. */
5779 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5780 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5781 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005782 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005783 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005784 return;
5785 }
5786 }
5787
5788 new = bgp_info_new ();
5789 new->type = type;
5790 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5791 new->peer = bgp->peer_self;
5792 SET_FLAG (new->flags, BGP_INFO_VALID);
5793 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005794 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005795
5796 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5797 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005798 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005799 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5800 }
5801 }
5802
5803 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005804 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005805 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005806}
5807
5808void
5809bgp_redistribute_delete (struct prefix *p, u_char type)
5810{
5811 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005812 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005813 afi_t afi;
5814 struct bgp_node *rn;
5815 struct bgp_info *ri;
5816
paul1eb8ef22005-04-07 07:30:20 +00005817 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005818 {
5819 afi = family2afi (p->family);
5820
5821 if (bgp->redist[afi][type])
5822 {
paulfee0f4c2004-09-13 05:12:46 +00005823 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005824
5825 for (ri = rn->info; ri; ri = ri->next)
5826 if (ri->peer == bgp->peer_self
5827 && ri->type == type)
5828 break;
5829
5830 if (ri)
5831 {
5832 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005833 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005834 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005835 }
5836 bgp_unlock_node (rn);
5837 }
5838 }
5839}
5840
5841/* Withdraw specified route type's route. */
5842void
5843bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5844{
5845 struct bgp_node *rn;
5846 struct bgp_info *ri;
5847 struct bgp_table *table;
5848
5849 table = bgp->rib[afi][SAFI_UNICAST];
5850
5851 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5852 {
5853 for (ri = rn->info; ri; ri = ri->next)
5854 if (ri->peer == bgp->peer_self
5855 && ri->type == type)
5856 break;
5857
5858 if (ri)
5859 {
5860 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005861 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005862 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005863 }
5864 }
5865}
David Lamparter6b0655a2014-06-04 06:53:35 +02005866
paul718e3742002-12-13 20:15:29 +00005867/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005868static void
paul718e3742002-12-13 20:15:29 +00005869route_vty_out_route (struct prefix *p, struct vty *vty)
5870{
5871 int len;
5872 u_int32_t destination;
5873 char buf[BUFSIZ];
5874
5875 if (p->family == AF_INET)
5876 {
5877 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5878 destination = ntohl (p->u.prefix4.s_addr);
5879
5880 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5881 || (IN_CLASSB (destination) && p->prefixlen == 16)
5882 || (IN_CLASSA (destination) && p->prefixlen == 8)
5883 || p->u.prefix4.s_addr == 0)
5884 {
5885 /* When mask is natural, mask is not displayed. */
5886 }
5887 else
5888 len += vty_out (vty, "/%d", p->prefixlen);
5889 }
5890 else
5891 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5892 p->prefixlen);
5893
5894 len = 17 - len;
5895 if (len < 1)
5896 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5897 else
5898 vty_out (vty, "%*s", len, " ");
5899}
5900
paul718e3742002-12-13 20:15:29 +00005901enum bgp_display_type
5902{
5903 normal_list,
5904};
5905
paulb40d9392005-08-22 22:34:41 +00005906/* Print the short form route status for a bgp_info */
5907static void
5908route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005909{
paulb40d9392005-08-22 22:34:41 +00005910 /* Route status display. */
5911 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5912 vty_out (vty, "R");
5913 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005914 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005915 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005916 vty_out (vty, "s");
5917 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5918 vty_out (vty, "*");
5919 else
5920 vty_out (vty, " ");
5921
5922 /* Selected */
5923 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5924 vty_out (vty, "h");
5925 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5926 vty_out (vty, "d");
5927 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5928 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005929 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5930 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005931 else
5932 vty_out (vty, " ");
5933
5934 /* Internal route. */
5935 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5936 vty_out (vty, "i");
5937 else
paulb40d9392005-08-22 22:34:41 +00005938 vty_out (vty, " ");
5939}
5940
5941/* called from terminal list command */
5942void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005943route_vty_out(
5944 struct vty *vty,
5945 struct prefix *p,
5946 struct bgp_info *binfo,
5947 int display,
5948 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005949{
5950 struct attr *attr;
5951
5952 /* short status lead text */
5953 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005954
5955 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005956 if (!display)
paul718e3742002-12-13 20:15:29 +00005957 route_vty_out_route (p, vty);
5958 else
5959 vty_out (vty, "%*s", 17, " ");
5960
5961 /* Print attribute */
5962 attr = binfo->attr;
5963 if (attr)
5964 {
paul718e3742002-12-13 20:15:29 +00005965
Lou Berger298cc2f2016-01-12 13:42:02 -05005966 /*
5967 * NEXTHOP start
5968 */
5969
5970 /*
5971 * For ENCAP routes, nexthop address family is not
5972 * neccessarily the same as the prefix address family.
5973 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5974 */
5975 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5976 if (attr->extra) {
5977 char buf[BUFSIZ];
5978 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5979
5980 switch (af) {
5981 case AF_INET:
5982 vty_out (vty, "%s", inet_ntop(af,
5983 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5984 break;
5985#if HAVE_IPV6
5986 case AF_INET6:
5987 vty_out (vty, "%s", inet_ntop(af,
5988 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5989 break;
5990#endif
5991
5992 default:
5993 vty_out(vty, "?");
5994 }
5995 } else {
5996 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005997 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005998 } else {
5999
6000 if (p->family == AF_INET)
6001 {
6002 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6003 }
6004#ifdef HAVE_IPV6
6005 else if (p->family == AF_INET6)
6006 {
6007 int len;
6008 char buf[BUFSIZ];
6009
6010 len = vty_out (vty, "%s",
6011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6012 buf, BUFSIZ));
6013 len = 16 - len;
6014 if (len < 1)
6015 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6016 else
6017 vty_out (vty, "%*s", len, " ");
6018 }
paul718e3742002-12-13 20:15:29 +00006019#endif /* HAVE_IPV6 */
Lou Berger298cc2f2016-01-12 13:42:02 -05006020 else
6021 {
6022 vty_out(vty, "?");
6023 }
6024 }
6025
6026 /*
6027 * NEXTHOP end
6028 */
6029
paul718e3742002-12-13 20:15:29 +00006030
6031 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006032 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006033 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006034 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00006035
6036 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006037 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006038 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006039 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00006040
Paul Jakmafb982c22007-05-04 20:15:47 +00006041 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00006042
Paul Jakmab2518c12006-05-12 23:48:40 +00006043 /* Print aspath */
6044 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006045 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006046
Paul Jakmab2518c12006-05-12 23:48:40 +00006047 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006048 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006049 }
paul718e3742002-12-13 20:15:29 +00006050 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006051}
6052
6053/* called from terminal list command */
6054void
6055route_vty_out_tmp (struct vty *vty, struct prefix *p,
6056 struct attr *attr, safi_t safi)
6057{
6058 /* Route status display. */
6059 vty_out (vty, "*");
6060 vty_out (vty, ">");
6061 vty_out (vty, " ");
6062
6063 /* print prefix and mask */
6064 route_vty_out_route (p, vty);
6065
6066 /* Print attribute */
6067 if (attr)
6068 {
6069 if (p->family == AF_INET)
6070 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006071 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 vty_out (vty, "%-16s",
6073 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006074 else
6075 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6076 }
6077#ifdef HAVE_IPV6
6078 else if (p->family == AF_INET6)
6079 {
6080 int len;
6081 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006082
6083 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006084
6085 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6087 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006088 len = 16 - len;
6089 if (len < 1)
6090 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6091 else
6092 vty_out (vty, "%*s", len, " ");
6093 }
6094#endif /* HAVE_IPV6 */
6095
6096 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006097 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006098 else
6099 vty_out (vty, " ");
6100
6101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006102 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006103 else
6104 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006105
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006106 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006107
Paul Jakmab2518c12006-05-12 23:48:40 +00006108 /* Print aspath */
6109 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006110 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006111
Paul Jakmab2518c12006-05-12 23:48:40 +00006112 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006113 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006114 }
paul718e3742002-12-13 20:15:29 +00006115
6116 vty_out (vty, "%s", VTY_NEWLINE);
6117}
6118
ajs5a646652004-11-05 01:25:55 +00006119void
paul718e3742002-12-13 20:15:29 +00006120route_vty_out_tag (struct vty *vty, struct prefix *p,
6121 struct bgp_info *binfo, int display, safi_t safi)
6122{
6123 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006124 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006125
6126 if (!binfo->extra)
6127 return;
6128
paulb40d9392005-08-22 22:34:41 +00006129 /* short status lead text */
6130 route_vty_short_status_out (vty, binfo);
6131
paul718e3742002-12-13 20:15:29 +00006132 /* print prefix and mask */
6133 if (! display)
6134 route_vty_out_route (p, vty);
6135 else
6136 vty_out (vty, "%*s", 17, " ");
6137
6138 /* Print attribute */
6139 attr = binfo->attr;
6140 if (attr)
6141 {
6142 if (p->family == AF_INET)
6143 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006144 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006145 vty_out (vty, "%-16s",
6146 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006147 else
6148 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6149 }
6150#ifdef HAVE_IPV6
6151 else if (p->family == AF_INET6)
6152 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006153 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006154 char buf[BUFSIZ];
6155 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006156 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006157 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6159 buf, BUFSIZ));
6160 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006161 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006162 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6163 buf, BUFSIZ),
6164 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6165 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006166
6167 }
6168#endif /* HAVE_IPV6 */
6169 }
6170
Paul Jakmafb982c22007-05-04 20:15:47 +00006171 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006172
6173 vty_out (vty, "notag/%d", label);
6174
6175 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006176}
6177
6178/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006179static void
paul718e3742002-12-13 20:15:29 +00006180damp_route_vty_out (struct vty *vty, struct prefix *p,
6181 struct bgp_info *binfo, int display, safi_t safi)
6182{
6183 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006184 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006185 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006186
paulb40d9392005-08-22 22:34:41 +00006187 /* short status lead text */
6188 route_vty_short_status_out (vty, binfo);
6189
paul718e3742002-12-13 20:15:29 +00006190 /* print prefix and mask */
6191 if (! display)
6192 route_vty_out_route (p, vty);
6193 else
6194 vty_out (vty, "%*s", 17, " ");
6195
6196 len = vty_out (vty, "%s", binfo->peer->host);
6197 len = 17 - len;
6198 if (len < 1)
6199 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6200 else
6201 vty_out (vty, "%*s", len, " ");
6202
Chris Caputo50aef6f2009-06-23 06:06:49 +00006203 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006204
6205 /* Print attribute */
6206 attr = binfo->attr;
6207 if (attr)
6208 {
6209 /* Print aspath */
6210 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006211 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006212
6213 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006214 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006215 }
6216 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006217}
6218
paul718e3742002-12-13 20:15:29 +00006219/* flap route */
ajs5a646652004-11-05 01:25:55 +00006220static void
paul718e3742002-12-13 20:15:29 +00006221flap_route_vty_out (struct vty *vty, struct prefix *p,
6222 struct bgp_info *binfo, int display, safi_t safi)
6223{
6224 struct attr *attr;
6225 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006226 char timebuf[BGP_UPTIME_LEN];
6227 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006228
6229 if (!binfo->extra)
6230 return;
6231
6232 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006233
paulb40d9392005-08-22 22:34:41 +00006234 /* short status lead text */
6235 route_vty_short_status_out (vty, binfo);
6236
paul718e3742002-12-13 20:15:29 +00006237 /* print prefix and mask */
6238 if (! display)
6239 route_vty_out_route (p, vty);
6240 else
6241 vty_out (vty, "%*s", 17, " ");
6242
6243 len = vty_out (vty, "%s", binfo->peer->host);
6244 len = 16 - len;
6245 if (len < 1)
6246 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6247 else
6248 vty_out (vty, "%*s", len, " ");
6249
6250 len = vty_out (vty, "%d", bdi->flap);
6251 len = 5 - len;
6252 if (len < 1)
6253 vty_out (vty, " ");
6254 else
6255 vty_out (vty, "%*s ", len, " ");
6256
6257 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6258 timebuf, BGP_UPTIME_LEN));
6259
6260 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6261 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006262 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006263 else
6264 vty_out (vty, "%*s ", 8, " ");
6265
6266 /* Print attribute */
6267 attr = binfo->attr;
6268 if (attr)
6269 {
6270 /* Print aspath */
6271 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006272 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006273
6274 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006275 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006276 }
6277 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006278}
6279
paul94f2b392005-06-28 12:44:16 +00006280static void
paul718e3742002-12-13 20:15:29 +00006281route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6282 struct bgp_info *binfo, afi_t afi, safi_t safi)
6283{
6284 char buf[INET6_ADDRSTRLEN];
6285 char buf1[BUFSIZ];
6286 struct attr *attr;
6287 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006288#ifdef HAVE_CLOCK_MONOTONIC
6289 time_t tbuf;
6290#endif
paul718e3742002-12-13 20:15:29 +00006291
6292 attr = binfo->attr;
6293
6294 if (attr)
6295 {
6296 /* Line1 display AS-path, Aggregator */
6297 if (attr->aspath)
6298 {
6299 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006300 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006301 vty_out (vty, "Local");
6302 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006303 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006304 }
6305
paulb40d9392005-08-22 22:34:41 +00006306 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6307 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006308 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6309 vty_out (vty, ", (stale)");
6310 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006311 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006312 attr->extra->aggregator_as,
6313 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006314 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6315 vty_out (vty, ", (Received from a RR-client)");
6316 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6317 vty_out (vty, ", (Received from a RS-client)");
6318 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6319 vty_out (vty, ", (history entry)");
6320 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6321 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006322 vty_out (vty, "%s", VTY_NEWLINE);
6323
6324 /* Line2 display Next-hop, Neighbor, Router-id */
6325 if (p->family == AF_INET)
6326 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006327 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006328 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006329 inet_ntoa (attr->nexthop));
6330 }
6331#ifdef HAVE_IPV6
6332 else
6333 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006334 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006335 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006336 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006337 buf, INET6_ADDRSTRLEN));
6338 }
6339#endif /* HAVE_IPV6 */
6340
6341 if (binfo->peer == bgp->peer_self)
6342 {
6343 vty_out (vty, " from %s ",
6344 p->family == AF_INET ? "0.0.0.0" : "::");
6345 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6346 }
6347 else
6348 {
6349 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6350 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006351 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006352 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006353 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6354 buf[0] = '?';
6355 buf[1] = 0;
6356 }
6357 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006358 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006359 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006360 else
6361 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6362 }
6363 vty_out (vty, "%s", VTY_NEWLINE);
6364
6365#ifdef HAVE_IPV6
6366 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006367 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006368 {
6369 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006370 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006371 buf, INET6_ADDRSTRLEN),
6372 VTY_NEWLINE);
6373 }
6374#endif /* HAVE_IPV6 */
6375
6376 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6377 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6378
6379 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006380 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006381
6382 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006383 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006384 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006385 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006386
Paul Jakmafb982c22007-05-04 20:15:47 +00006387 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006388 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006389
6390 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6391 vty_out (vty, ", valid");
6392
6393 if (binfo->peer != bgp->peer_self)
6394 {
6395 if (binfo->peer->as == binfo->peer->local_as)
6396 vty_out (vty, ", internal");
6397 else
6398 vty_out (vty, ", %s",
6399 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6400 }
6401 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6402 vty_out (vty, ", aggregated, local");
6403 else if (binfo->type != ZEBRA_ROUTE_BGP)
6404 vty_out (vty, ", sourced");
6405 else
6406 vty_out (vty, ", sourced, local");
6407
6408 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6409 vty_out (vty, ", atomic-aggregate");
6410
Josh Baileyde8d5df2011-07-20 20:46:01 -07006411 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6412 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6413 bgp_info_mpath_count (binfo)))
6414 vty_out (vty, ", multipath");
6415
paul718e3742002-12-13 20:15:29 +00006416 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6417 vty_out (vty, ", best");
6418
6419 vty_out (vty, "%s", VTY_NEWLINE);
6420
6421 /* Line 4 display Community */
6422 if (attr->community)
6423 vty_out (vty, " Community: %s%s", attr->community->str,
6424 VTY_NEWLINE);
6425
6426 /* Line 5 display Extended-community */
6427 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006428 vty_out (vty, " Extended Community: %s%s",
6429 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006430
6431 /* Line 6 display Originator, Cluster-id */
6432 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6433 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6434 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006435 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006436 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006437 vty_out (vty, " Originator: %s",
6438 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006439
6440 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6441 {
6442 int i;
6443 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006444 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6445 vty_out (vty, "%s ",
6446 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006447 }
6448 vty_out (vty, "%s", VTY_NEWLINE);
6449 }
Paul Jakma41367172007-08-06 15:24:51 +00006450
Paul Jakmafb982c22007-05-04 20:15:47 +00006451 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006452 bgp_damp_info_vty (vty, binfo);
6453
6454 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006455#ifdef HAVE_CLOCK_MONOTONIC
6456 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006457 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006458#else
6459 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6460#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006461 }
6462 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006463}
6464
6465#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6466 "h history, * valid, > best, = multipath,%s"\
6467 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006468#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006469#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6470#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6471#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6472
6473enum bgp_show_type
6474{
6475 bgp_show_type_normal,
6476 bgp_show_type_regexp,
6477 bgp_show_type_prefix_list,
6478 bgp_show_type_filter_list,
6479 bgp_show_type_route_map,
6480 bgp_show_type_neighbor,
6481 bgp_show_type_cidr_only,
6482 bgp_show_type_prefix_longer,
6483 bgp_show_type_community_all,
6484 bgp_show_type_community,
6485 bgp_show_type_community_exact,
6486 bgp_show_type_community_list,
6487 bgp_show_type_community_list_exact,
6488 bgp_show_type_flap_statistics,
6489 bgp_show_type_flap_address,
6490 bgp_show_type_flap_prefix,
6491 bgp_show_type_flap_cidr_only,
6492 bgp_show_type_flap_regexp,
6493 bgp_show_type_flap_filter_list,
6494 bgp_show_type_flap_prefix_list,
6495 bgp_show_type_flap_prefix_longer,
6496 bgp_show_type_flap_route_map,
6497 bgp_show_type_flap_neighbor,
6498 bgp_show_type_dampend_paths,
6499 bgp_show_type_damp_neighbor
6500};
6501
ajs5a646652004-11-05 01:25:55 +00006502static int
paulfee0f4c2004-09-13 05:12:46 +00006503bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006504 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006505{
paul718e3742002-12-13 20:15:29 +00006506 struct bgp_info *ri;
6507 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006508 int header = 1;
paul718e3742002-12-13 20:15:29 +00006509 int display;
ajs5a646652004-11-05 01:25:55 +00006510 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006511 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006512
6513 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006514 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006515 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006516
paul718e3742002-12-13 20:15:29 +00006517 /* Start processing of routes. */
6518 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6519 if (rn->info != NULL)
6520 {
6521 display = 0;
6522
6523 for (ri = rn->info; ri; ri = ri->next)
6524 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006525 total_count++;
ajs5a646652004-11-05 01:25:55 +00006526 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006527 || type == bgp_show_type_flap_address
6528 || type == bgp_show_type_flap_prefix
6529 || type == bgp_show_type_flap_cidr_only
6530 || type == bgp_show_type_flap_regexp
6531 || type == bgp_show_type_flap_filter_list
6532 || type == bgp_show_type_flap_prefix_list
6533 || type == bgp_show_type_flap_prefix_longer
6534 || type == bgp_show_type_flap_route_map
6535 || type == bgp_show_type_flap_neighbor
6536 || type == bgp_show_type_dampend_paths
6537 || type == bgp_show_type_damp_neighbor)
6538 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006539 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006540 continue;
6541 }
6542 if (type == bgp_show_type_regexp
6543 || type == bgp_show_type_flap_regexp)
6544 {
ajs5a646652004-11-05 01:25:55 +00006545 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006546
6547 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6548 continue;
6549 }
6550 if (type == bgp_show_type_prefix_list
6551 || type == bgp_show_type_flap_prefix_list)
6552 {
ajs5a646652004-11-05 01:25:55 +00006553 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006554
6555 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6556 continue;
6557 }
6558 if (type == bgp_show_type_filter_list
6559 || type == bgp_show_type_flap_filter_list)
6560 {
ajs5a646652004-11-05 01:25:55 +00006561 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006562
6563 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6564 continue;
6565 }
6566 if (type == bgp_show_type_route_map
6567 || type == bgp_show_type_flap_route_map)
6568 {
ajs5a646652004-11-05 01:25:55 +00006569 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006570 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006571 struct attr dummy_attr;
6572 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006573 int ret;
6574
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006575 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006576 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006577
paul718e3742002-12-13 20:15:29 +00006578 binfo.peer = ri->peer;
6579 binfo.attr = &dummy_attr;
6580
6581 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006582 if (ret == RMAP_DENYMATCH)
6583 continue;
6584 }
6585 if (type == bgp_show_type_neighbor
6586 || type == bgp_show_type_flap_neighbor
6587 || type == bgp_show_type_damp_neighbor)
6588 {
ajs5a646652004-11-05 01:25:55 +00006589 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006590
6591 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6592 continue;
6593 }
6594 if (type == bgp_show_type_cidr_only
6595 || type == bgp_show_type_flap_cidr_only)
6596 {
6597 u_int32_t destination;
6598
6599 destination = ntohl (rn->p.u.prefix4.s_addr);
6600 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6601 continue;
6602 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6603 continue;
6604 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6605 continue;
6606 }
6607 if (type == bgp_show_type_prefix_longer
6608 || type == bgp_show_type_flap_prefix_longer)
6609 {
ajs5a646652004-11-05 01:25:55 +00006610 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006611
6612 if (! prefix_match (p, &rn->p))
6613 continue;
6614 }
6615 if (type == bgp_show_type_community_all)
6616 {
6617 if (! ri->attr->community)
6618 continue;
6619 }
6620 if (type == bgp_show_type_community)
6621 {
ajs5a646652004-11-05 01:25:55 +00006622 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006623
6624 if (! ri->attr->community ||
6625 ! community_match (ri->attr->community, com))
6626 continue;
6627 }
6628 if (type == bgp_show_type_community_exact)
6629 {
ajs5a646652004-11-05 01:25:55 +00006630 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006631
6632 if (! ri->attr->community ||
6633 ! community_cmp (ri->attr->community, com))
6634 continue;
6635 }
6636 if (type == bgp_show_type_community_list)
6637 {
ajs5a646652004-11-05 01:25:55 +00006638 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006639
6640 if (! community_list_match (ri->attr->community, list))
6641 continue;
6642 }
6643 if (type == bgp_show_type_community_list_exact)
6644 {
ajs5a646652004-11-05 01:25:55 +00006645 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006646
6647 if (! community_list_exact_match (ri->attr->community, list))
6648 continue;
6649 }
6650 if (type == bgp_show_type_flap_address
6651 || type == bgp_show_type_flap_prefix)
6652 {
ajs5a646652004-11-05 01:25:55 +00006653 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006654
6655 if (! prefix_match (&rn->p, p))
6656 continue;
6657
6658 if (type == bgp_show_type_flap_prefix)
6659 if (p->prefixlen != rn->p.prefixlen)
6660 continue;
6661 }
6662 if (type == bgp_show_type_dampend_paths
6663 || type == bgp_show_type_damp_neighbor)
6664 {
6665 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6666 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6667 continue;
6668 }
6669
6670 if (header)
6671 {
hasso93406d82005-02-02 14:40:33 +00006672 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6673 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6674 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006675 if (type == bgp_show_type_dampend_paths
6676 || type == bgp_show_type_damp_neighbor)
6677 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6678 else if (type == bgp_show_type_flap_statistics
6679 || type == bgp_show_type_flap_address
6680 || type == bgp_show_type_flap_prefix
6681 || type == bgp_show_type_flap_cidr_only
6682 || type == bgp_show_type_flap_regexp
6683 || type == bgp_show_type_flap_filter_list
6684 || type == bgp_show_type_flap_prefix_list
6685 || type == bgp_show_type_flap_prefix_longer
6686 || type == bgp_show_type_flap_route_map
6687 || type == bgp_show_type_flap_neighbor)
6688 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6689 else
6690 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006691 header = 0;
6692 }
6693
6694 if (type == bgp_show_type_dampend_paths
6695 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006696 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006697 else if (type == bgp_show_type_flap_statistics
6698 || type == bgp_show_type_flap_address
6699 || type == bgp_show_type_flap_prefix
6700 || type == bgp_show_type_flap_cidr_only
6701 || type == bgp_show_type_flap_regexp
6702 || type == bgp_show_type_flap_filter_list
6703 || type == bgp_show_type_flap_prefix_list
6704 || type == bgp_show_type_flap_prefix_longer
6705 || type == bgp_show_type_flap_route_map
6706 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006707 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006708 else
ajs5a646652004-11-05 01:25:55 +00006709 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006710 display++;
6711 }
6712 if (display)
ajs5a646652004-11-05 01:25:55 +00006713 output_count++;
paul718e3742002-12-13 20:15:29 +00006714 }
6715
6716 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006717 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006718 {
6719 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006720 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006721 }
6722 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006723 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6724 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006725
6726 return CMD_SUCCESS;
6727}
6728
ajs5a646652004-11-05 01:25:55 +00006729static int
paulfee0f4c2004-09-13 05:12:46 +00006730bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006731 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006732{
6733 struct bgp_table *table;
6734
6735 if (bgp == NULL) {
6736 bgp = bgp_get_default ();
6737 }
6738
6739 if (bgp == NULL)
6740 {
6741 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6742 return CMD_WARNING;
6743 }
6744
6745
6746 table = bgp->rib[afi][safi];
6747
ajs5a646652004-11-05 01:25:55 +00006748 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006749}
6750
paul718e3742002-12-13 20:15:29 +00006751/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006752static void
paul718e3742002-12-13 20:15:29 +00006753route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6754 struct bgp_node *rn,
6755 struct prefix_rd *prd, afi_t afi, safi_t safi)
6756{
6757 struct bgp_info *ri;
6758 struct prefix *p;
6759 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006760 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006761 char buf1[INET6_ADDRSTRLEN];
6762 char buf2[INET6_ADDRSTRLEN];
6763 int count = 0;
6764 int best = 0;
6765 int suppress = 0;
6766 int no_export = 0;
6767 int no_advertise = 0;
6768 int local_as = 0;
6769 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006770 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006771
6772 p = &rn->p;
6773 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006774 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6775 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006776 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6777 p->prefixlen, VTY_NEWLINE);
6778
6779 for (ri = rn->info; ri; ri = ri->next)
6780 {
6781 count++;
6782 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6783 {
6784 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006785 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006786 suppress = 1;
6787 if (ri->attr->community != NULL)
6788 {
6789 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6790 no_advertise = 1;
6791 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6792 no_export = 1;
6793 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6794 local_as = 1;
6795 }
6796 }
6797 }
6798
6799 vty_out (vty, "Paths: (%d available", count);
6800 if (best)
6801 {
6802 vty_out (vty, ", best #%d", best);
6803 if (safi == SAFI_UNICAST)
6804 vty_out (vty, ", table Default-IP-Routing-Table");
6805 }
6806 else
6807 vty_out (vty, ", no best path");
6808 if (no_advertise)
6809 vty_out (vty, ", not advertised to any peer");
6810 else if (no_export)
6811 vty_out (vty, ", not advertised to EBGP peer");
6812 else if (local_as)
6813 vty_out (vty, ", not advertised outside local AS");
6814 if (suppress)
6815 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6816 vty_out (vty, ")%s", VTY_NEWLINE);
6817
6818 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006819 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006820 {
6821 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6822 {
6823 if (! first)
6824 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6825 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6826 first = 1;
6827 }
6828 }
6829 if (! first)
6830 vty_out (vty, " Not advertised to any peer");
6831 vty_out (vty, "%s", VTY_NEWLINE);
6832}
6833
6834/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006835static int
paulfee0f4c2004-09-13 05:12:46 +00006836bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006837 struct bgp_table *rib, const char *ip_str,
6838 afi_t afi, safi_t safi, struct prefix_rd *prd,
6839 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006840{
6841 int ret;
6842 int header;
6843 int display = 0;
6844 struct prefix match;
6845 struct bgp_node *rn;
6846 struct bgp_node *rm;
6847 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006848 struct bgp_table *table;
6849
Lou Berger050defe2016-01-12 13:41:59 -05006850 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006851 /* Check IP address argument. */
6852 ret = str2prefix (ip_str, &match);
6853 if (! ret)
6854 {
6855 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6856 return CMD_WARNING;
6857 }
6858
6859 match.family = afi2family (afi);
6860
Lou Berger298cc2f2016-01-12 13:42:02 -05006861 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006862 {
paulfee0f4c2004-09-13 05:12:46 +00006863 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006864 {
6865 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6866 continue;
6867
6868 if ((table = rn->info) != NULL)
6869 {
6870 header = 1;
6871
6872 if ((rm = bgp_node_match (table, &match)) != NULL)
6873 {
6874 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006875 {
6876 bgp_unlock_node (rm);
6877 continue;
6878 }
paul718e3742002-12-13 20:15:29 +00006879
6880 for (ri = rm->info; ri; ri = ri->next)
6881 {
6882 if (header)
6883 {
6884 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006885 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006886
6887 header = 0;
6888 }
6889 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006890 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006891 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006892
6893 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006894 }
6895 }
6896 }
6897 }
6898 else
6899 {
6900 header = 1;
6901
paulfee0f4c2004-09-13 05:12:46 +00006902 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006903 {
6904 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6905 {
6906 for (ri = rn->info; ri; ri = ri->next)
6907 {
6908 if (header)
6909 {
6910 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6911 header = 0;
6912 }
6913 display++;
6914 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6915 }
6916 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006917
6918 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006919 }
6920 }
6921
6922 if (! display)
6923 {
6924 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6925 return CMD_WARNING;
6926 }
6927
6928 return CMD_SUCCESS;
6929}
6930
paulfee0f4c2004-09-13 05:12:46 +00006931/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006932static int
paulfd79ac92004-10-13 05:06:08 +00006933bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006934 afi_t afi, safi_t safi, struct prefix_rd *prd,
6935 int prefix_check)
6936{
6937 struct bgp *bgp;
6938
6939 /* BGP structure lookup. */
6940 if (view_name)
6941 {
6942 bgp = bgp_lookup_by_name (view_name);
6943 if (bgp == NULL)
6944 {
6945 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6946 return CMD_WARNING;
6947 }
6948 }
6949 else
6950 {
6951 bgp = bgp_get_default ();
6952 if (bgp == NULL)
6953 {
6954 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6955 return CMD_WARNING;
6956 }
6957 }
6958
6959 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6960 afi, safi, prd, prefix_check);
6961}
6962
paul718e3742002-12-13 20:15:29 +00006963/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006964DEFUN (show_ip_bgp,
6965 show_ip_bgp_cmd,
6966 "show ip bgp",
6967 SHOW_STR
6968 IP_STR
6969 BGP_STR)
6970{
6971 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6972}
6973
6974DEFUN (show_ip_bgp_ipv4,
6975 show_ip_bgp_ipv4_cmd,
6976 "show ip bgp ipv4 (unicast|multicast)",
6977 SHOW_STR
6978 IP_STR
6979 BGP_STR
6980 "Address family\n"
6981 "Address Family modifier\n"
6982 "Address Family modifier\n")
6983{
6984 if (strncmp (argv[0], "m", 1) == 0)
6985 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6986 NULL);
6987
6988 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6989}
6990
6991DEFUN (show_ip_bgp_route,
6992 show_ip_bgp_route_cmd,
6993 "show ip bgp A.B.C.D",
6994 SHOW_STR
6995 IP_STR
6996 BGP_STR
6997 "Network in the BGP routing table to display\n")
6998{
6999 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
7000}
7001
7002DEFUN (show_ip_bgp_ipv4_route,
7003 show_ip_bgp_ipv4_route_cmd,
7004 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7005 SHOW_STR
7006 IP_STR
7007 BGP_STR
7008 "Address family\n"
7009 "Address Family modifier\n"
7010 "Address Family modifier\n"
7011 "Network in the BGP routing table to display\n")
7012{
7013 if (strncmp (argv[0], "m", 1) == 0)
7014 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7015
7016 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7017}
7018
7019DEFUN (show_ip_bgp_vpnv4_all_route,
7020 show_ip_bgp_vpnv4_all_route_cmd,
7021 "show ip bgp vpnv4 all A.B.C.D",
7022 SHOW_STR
7023 IP_STR
7024 BGP_STR
7025 "Display VPNv4 NLRI specific information\n"
7026 "Display information about all VPNv4 NLRIs\n"
7027 "Network in the BGP routing table to display\n")
7028{
7029 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7030}
7031
7032DEFUN (show_ip_bgp_vpnv4_rd_route,
7033 show_ip_bgp_vpnv4_rd_route_cmd,
7034 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7035 SHOW_STR
7036 IP_STR
7037 BGP_STR
7038 "Display VPNv4 NLRI specific information\n"
7039 "Display information for a route distinguisher\n"
7040 "VPN Route Distinguisher\n"
7041 "Network in the BGP routing table to display\n")
7042{
7043 int ret;
7044 struct prefix_rd prd;
7045
7046 ret = str2prefix_rd (argv[0], &prd);
7047 if (! ret)
7048 {
7049 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7050 return CMD_WARNING;
7051 }
7052 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7053}
7054
7055DEFUN (show_ip_bgp_prefix,
7056 show_ip_bgp_prefix_cmd,
7057 "show ip bgp A.B.C.D/M",
7058 SHOW_STR
7059 IP_STR
7060 BGP_STR
7061 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7062{
7063 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
7064}
7065
7066DEFUN (show_ip_bgp_ipv4_prefix,
7067 show_ip_bgp_ipv4_prefix_cmd,
7068 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7069 SHOW_STR
7070 IP_STR
7071 BGP_STR
7072 "Address family\n"
7073 "Address Family modifier\n"
7074 "Address Family modifier\n"
7075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7076{
7077 if (strncmp (argv[0], "m", 1) == 0)
7078 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
7079
7080 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7081}
7082
7083DEFUN (show_ip_bgp_vpnv4_all_prefix,
7084 show_ip_bgp_vpnv4_all_prefix_cmd,
7085 "show ip bgp vpnv4 all A.B.C.D/M",
7086 SHOW_STR
7087 IP_STR
7088 BGP_STR
7089 "Display VPNv4 NLRI specific information\n"
7090 "Display information about all VPNv4 NLRIs\n"
7091 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7092{
7093 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7094}
7095
7096DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7097 show_ip_bgp_vpnv4_rd_prefix_cmd,
7098 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7099 SHOW_STR
7100 IP_STR
7101 BGP_STR
7102 "Display VPNv4 NLRI specific information\n"
7103 "Display information for a route distinguisher\n"
7104 "VPN Route Distinguisher\n"
7105 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7106{
7107 int ret;
7108 struct prefix_rd prd;
7109
7110 ret = str2prefix_rd (argv[0], &prd);
7111 if (! ret)
7112 {
7113 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7114 return CMD_WARNING;
7115 }
7116 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7117}
7118
7119DEFUN (show_ip_bgp_view,
7120 show_ip_bgp_view_cmd,
7121 "show ip bgp view WORD",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "BGP view\n"
7126 "View name\n")
7127{
7128 struct bgp *bgp;
7129
7130 /* BGP structure lookup. */
7131 bgp = bgp_lookup_by_name (argv[0]);
7132 if (bgp == NULL)
7133 {
7134 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7135 return CMD_WARNING;
7136 }
7137
7138 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7139}
7140
7141DEFUN (show_ip_bgp_view_route,
7142 show_ip_bgp_view_route_cmd,
7143 "show ip bgp view WORD A.B.C.D",
7144 SHOW_STR
7145 IP_STR
7146 BGP_STR
7147 "BGP view\n"
7148 "View name\n"
7149 "Network in the BGP routing table to display\n")
7150{
7151 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7152}
7153
7154DEFUN (show_ip_bgp_view_prefix,
7155 show_ip_bgp_view_prefix_cmd,
7156 "show ip bgp view WORD A.B.C.D/M",
7157 SHOW_STR
7158 IP_STR
7159 BGP_STR
7160 "BGP view\n"
7161 "View name\n"
7162 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7163{
7164 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7165}
7166
7167DEFUN (show_bgp,
7168 show_bgp_cmd,
7169 "show bgp",
7170 SHOW_STR
7171 BGP_STR)
7172{
7173 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7174 NULL);
7175}
7176
7177ALIAS (show_bgp,
7178 show_bgp_ipv6_cmd,
7179 "show bgp ipv6",
7180 SHOW_STR
7181 BGP_STR
7182 "Address family\n")
7183
7184/* old command */
7185DEFUN (show_ipv6_bgp,
7186 show_ipv6_bgp_cmd,
7187 "show ipv6 bgp",
7188 SHOW_STR
7189 IP_STR
7190 BGP_STR)
7191{
7192 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7193 NULL);
7194}
7195
7196DEFUN (show_bgp_route,
7197 show_bgp_route_cmd,
7198 "show bgp X:X::X:X",
7199 SHOW_STR
7200 BGP_STR
7201 "Network in the BGP routing table to display\n")
7202{
7203 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7204}
7205
Lou Berger35c36862016-01-12 13:42:06 -05007206DEFUN (show_bgp_ipv4_safi,
7207 show_bgp_ipv4_safi_cmd,
7208 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007209 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007210 BGP_STR
7211 "Address family\n"
7212 "Address Family modifier\n"
7213 "Address Family modifier\n")
7214{
7215 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007216 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7217 NULL);
paul718e3742002-12-13 20:15:29 +00007218
ajs5a646652004-11-05 01:25:55 +00007219 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007220}
7221
Lou Berger35c36862016-01-12 13:42:06 -05007222DEFUN (show_bgp_ipv4_safi_route,
7223 show_bgp_ipv4_safi_route_cmd,
7224 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007225 SHOW_STR
7226 BGP_STR
7227 "Address family\n"
7228 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007229 "Address Family modifier\n"
7230 "Network in the BGP routing table to display\n")
7231{
7232 if (strncmp (argv[0], "m", 1) == 0)
7233 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7234
7235 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7236}
7237
Lou Berger35c36862016-01-12 13:42:06 -05007238DEFUN (show_bgp_ipv4_vpn_route,
7239 show_bgp_ipv4_vpn_route_cmd,
7240 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007241 SHOW_STR
7242 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007243 "Address Family\n"
7244 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007245 "Network in the BGP routing table to display\n")
7246{
7247 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7248}
7249
Lou Berger35c36862016-01-12 13:42:06 -05007250#ifdef HAVE_IPV6
7251DEFUN (show_bgp_ipv6_vpn_route,
7252 show_bgp_ipv6_vpn_route_cmd,
7253 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007254 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007255 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007256 "Address Family\n"
7257 "Display VPN NLRI specific information\n"
7258 "Network in the BGP routing table to display\n")
7259{
7260 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7261}
7262#endif
7263
7264DEFUN (show_bgp_ipv4_vpn_rd_route,
7265 show_bgp_ipv4_vpn_rd_route_cmd,
7266 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7267 SHOW_STR
7268 BGP_STR
7269 IP_STR
7270 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007271 "Display information for a route distinguisher\n"
7272 "VPN Route Distinguisher\n"
7273 "Network in the BGP routing table to display\n")
7274{
7275 int ret;
7276 struct prefix_rd prd;
7277
7278 ret = str2prefix_rd (argv[0], &prd);
7279 if (! ret)
7280 {
7281 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7282 return CMD_WARNING;
7283 }
7284 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7285}
7286
Lou Berger35c36862016-01-12 13:42:06 -05007287DEFUN (show_bgp_ipv6_vpn_rd_route,
7288 show_bgp_ipv6_vpn_rd_route_cmd,
7289 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007290 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007291 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007292 "Address Family\n"
7293 "Display VPN NLRI specific information\n"
7294 "Display information for a route distinguisher\n"
7295 "VPN Route Distinguisher\n"
7296 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007297{
Lou Berger35c36862016-01-12 13:42:06 -05007298 int ret;
7299 struct prefix_rd prd;
7300
7301 ret = str2prefix_rd (argv[0], &prd);
7302 if (! ret)
7303 {
7304 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7305 return CMD_WARNING;
7306 }
7307 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007308}
7309
Lou Berger651b4022016-01-12 13:42:07 -05007310DEFUN (show_bgp_ipv4_encap_route,
7311 show_bgp_ipv4_encap_route_cmd,
7312 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007313 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007314 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007315 IP_STR
7316 "Display ENCAP NLRI specific information\n"
7317 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007318{
Lou Berger651b4022016-01-12 13:42:07 -05007319 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007320}
7321
Lou Berger651b4022016-01-12 13:42:07 -05007322#ifdef HAVE_IPV6
7323DEFUN (show_bgp_ipv6_encap_route,
7324 show_bgp_ipv6_encap_route_cmd,
7325 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007326 SHOW_STR
7327 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007328 IP6_STR
7329 "Display ENCAP NLRI specific information\n"
7330 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007331{
Lou Berger651b4022016-01-12 13:42:07 -05007332 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007333}
Lou Berger651b4022016-01-12 13:42:07 -05007334#endif
paul718e3742002-12-13 20:15:29 +00007335
Lou Berger651b4022016-01-12 13:42:07 -05007336DEFUN (show_bgp_ipv4_safi_rd_route,
7337 show_bgp_ipv4_safi_rd_route_cmd,
7338 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007339 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007340 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007341 "Address Family\n"
7342 "Address Family Modifier\n"
7343 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007344 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007345 "ENCAP Route Distinguisher\n"
7346 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007347{
7348 int ret;
7349 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007350 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007351
Lou Berger651b4022016-01-12 13:42:07 -05007352 if (bgp_parse_safi(argv[0], &safi)) {
7353 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7354 return CMD_WARNING;
7355 }
7356 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007357 if (! ret)
7358 {
7359 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7360 return CMD_WARNING;
7361 }
Lou Berger651b4022016-01-12 13:42:07 -05007362 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007363}
7364
Lou Berger651b4022016-01-12 13:42:07 -05007365#ifdef HAVE_IPV6
7366DEFUN (show_bgp_ipv6_safi_rd_route,
7367 show_bgp_ipv6_safi_rd_route_cmd,
7368 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007369 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007370 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007371 "Address Family\n"
7372 "Address Family Modifier\n"
7373 "Address Family Modifier\n"
7374 "Display information for a route distinguisher\n"
7375 "ENCAP Route Distinguisher\n"
7376 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007377{
Lou Berger651b4022016-01-12 13:42:07 -05007378 int ret;
7379 struct prefix_rd prd;
7380 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007381
Lou Berger651b4022016-01-12 13:42:07 -05007382 if (bgp_parse_safi(argv[0], &safi)) {
7383 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7384 return CMD_WARNING;
7385 }
7386 ret = str2prefix_rd (argv[1], &prd);
7387 if (! ret)
7388 {
7389 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7390 return CMD_WARNING;
7391 }
7392 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007393}
Lou Berger651b4022016-01-12 13:42:07 -05007394#endif
paul718e3742002-12-13 20:15:29 +00007395
Lou Berger35c36862016-01-12 13:42:06 -05007396DEFUN (show_bgp_ipv4_prefix,
7397 show_bgp_ipv4_prefix_cmd,
7398 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007399 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007400 BGP_STR
paul718e3742002-12-13 20:15:29 +00007401 IP_STR
paul718e3742002-12-13 20:15:29 +00007402 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7403{
Lou Berger35c36862016-01-12 13:42:06 -05007404 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007405}
7406
Lou Berger35c36862016-01-12 13:42:06 -05007407DEFUN (show_bgp_ipv4_safi_prefix,
7408 show_bgp_ipv4_safi_prefix_cmd,
7409 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007410 SHOW_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007414 "Address Family modifier\n"
7415 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007416{
7417 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007418 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007419
Lou Berger35c36862016-01-12 13:42:06 -05007420 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007421}
7422
Lou Berger35c36862016-01-12 13:42:06 -05007423DEFUN (show_bgp_ipv4_vpn_prefix,
7424 show_bgp_ipv4_vpn_prefix_cmd,
7425 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007426 SHOW_STR
7427 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007428 IP_STR
7429 "Display VPN NLRI specific information\n"
7430 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007431{
Lou Berger35c36862016-01-12 13:42:06 -05007432 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007433}
7434
Lou Berger35c36862016-01-12 13:42:06 -05007435#ifdef HAVE_IPV6
7436DEFUN (show_bgp_ipv6_vpn_prefix,
7437 show_bgp_ipv6_vpn_prefix_cmd,
7438 "show bgp ipv6 vpn X:X::X:X/M",
7439 SHOW_STR
7440 BGP_STR
7441 "Address Family\n"
7442 "Display VPN NLRI specific information\n"
7443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7444{
7445 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7446}
7447#endif
7448
Lou Berger651b4022016-01-12 13:42:07 -05007449DEFUN (show_bgp_ipv4_encap_prefix,
7450 show_bgp_ipv4_encap_prefix_cmd,
7451 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007452 SHOW_STR
7453 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007454 IP_STR
7455 "Display ENCAP NLRI specific information\n"
7456 "Display information about ENCAP NLRIs\n"
7457 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7458{
7459 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1);
7460}
paul718e3742002-12-13 20:15:29 +00007461
Lou Berger651b4022016-01-12 13:42:07 -05007462#ifdef HAVE_IPV6
7463DEFUN (show_bgp_ipv6_encap_prefix,
7464 show_bgp_ipv6_encap_prefix_cmd,
7465 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007466 SHOW_STR
7467 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007468 IP_STR
7469 "Display ENCAP NLRI specific information\n"
7470 "Display information about ENCAP NLRIs\n"
7471 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7472{
7473 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1);
7474}
7475#endif
7476
7477DEFUN (show_bgp_ipv4_safi_rd_prefix,
7478 show_bgp_ipv4_safi_rd_prefix_cmd,
7479 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7480 SHOW_STR
7481 BGP_STR
7482 "Address Family\n"
7483 "Address Family Modifier\n"
7484 "Address Family Modifier\n"
7485 "Display information for a route distinguisher\n"
7486 "ENCAP Route Distinguisher\n"
7487 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7488{
7489 int ret;
7490 struct prefix_rd prd;
7491 safi_t safi;
7492
7493 if (bgp_parse_safi(argv[0], &safi)) {
7494 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7495 return CMD_WARNING;
7496 }
7497
7498 ret = str2prefix_rd (argv[1], &prd);
7499 if (! ret)
7500 {
7501 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7502 return CMD_WARNING;
7503 }
7504 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1);
7505}
7506
7507#ifdef HAVE_IPV6
7508DEFUN (show_bgp_ipv6_safi_rd_prefix,
7509 show_bgp_ipv6_safi_rd_prefix_cmd,
7510 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7511 SHOW_STR
7512 BGP_STR
7513 "Address Family\n"
7514 "Address Family Modifier\n"
7515 "Address Family Modifier\n"
7516 "Display information for a route distinguisher\n"
7517 "ENCAP Route Distinguisher\n"
7518 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7519{
7520 int ret;
7521 struct prefix_rd prd;
7522 safi_t safi;
7523
7524 if (bgp_parse_safi(argv[0], &safi)) {
7525 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7526 return CMD_WARNING;
7527 }
7528
7529 ret = str2prefix_rd (argv[1], &prd);
7530 if (! ret)
7531 {
7532 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7533 return CMD_WARNING;
7534 }
7535 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1);
7536}
7537#endif
7538
7539DEFUN (show_bgp_afi_safi_view,
7540 show_bgp_afi_safi_view_cmd,
7541 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7542 SHOW_STR
7543 BGP_STR
7544 "BGP view\n"
7545 "BGP view name\n"
7546 "Address Family\n"
7547 "Address Family\n"
7548 "Address Family Modifier\n"
7549 "Address Family Modifier\n"
7550 "Address Family Modifier\n"
7551 "Address Family Modifier\n"
7552 )
7553{
7554 struct bgp *bgp;
7555 safi_t safi;
7556 afi_t afi;
7557
7558 if (bgp_parse_afi(argv[1], &afi)) {
7559 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7560 return CMD_WARNING;
7561 }
7562 if (bgp_parse_safi(argv[2], &safi)) {
7563 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7564 return CMD_WARNING;
7565 }
7566
7567 /* BGP structure lookup. */
7568 bgp = bgp_lookup_by_name (argv[0]);
7569 if (bgp == NULL)
7570 {
7571 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7572 return CMD_WARNING;
7573 }
7574
7575 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7576}
7577
7578DEFUN (show_bgp_view_afi_safi_route,
7579 show_bgp_view_afi_safi_route_cmd,
7580 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7581 SHOW_STR
7582 BGP_STR
7583 "BGP view\n"
7584 "View name\n"
7585 "Address Family\n"
7586 "Address Family\n"
7587 "Address Family Modifier\n"
7588 "Address Family Modifier\n"
7589 "Address Family Modifier\n"
7590 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007591 "Network in the BGP routing table to display\n")
7592{
Lou Berger651b4022016-01-12 13:42:07 -05007593 safi_t safi;
7594 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007595
Lou Berger651b4022016-01-12 13:42:07 -05007596 if (bgp_parse_afi(argv[1], &afi)) {
7597 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7598 return CMD_WARNING;
7599 }
7600 if (bgp_parse_safi(argv[2], &safi)) {
7601 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7602 return CMD_WARNING;
7603 }
7604 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0);
7605}
7606
7607DEFUN (show_bgp_view_afi_safi_prefix,
7608 show_bgp_view_afi_safi_prefix_cmd,
7609 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7610 SHOW_STR
7611 BGP_STR
7612 "BGP view\n"
7613 "View name\n"
7614 "Address Family\n"
7615 "Address Family\n"
7616 "Address Family Modifier\n"
7617 "Address Family Modifier\n"
7618 "Address Family Modifier\n"
7619 "Address Family Modifier\n"
7620 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7621{
7622 safi_t safi;
7623 afi_t afi;
7624
7625 if (bgp_parse_afi(argv[1], &afi)) {
7626 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7627 return CMD_WARNING;
7628 }
7629 if (bgp_parse_safi(argv[2], &safi)) {
7630 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7631 return CMD_WARNING;
7632 }
7633 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1);
7634}
7635
7636/* new001 */
7637DEFUN (show_bgp_afi,
7638 show_bgp_afi_cmd,
7639 "show bgp (ipv4|ipv6)",
7640 SHOW_STR
7641 BGP_STR
7642 "Address family\n"
7643 "Address family\n")
7644{
7645 afi_t afi;
7646
7647 if (bgp_parse_afi(argv[0], &afi)) {
7648 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7649 return CMD_WARNING;
7650 }
7651 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7652 NULL);
7653}
7654
7655#ifdef HAVE_IPV6
7656DEFUN (show_bgp_ipv6_safi,
7657 show_bgp_ipv6_safi_cmd,
7658 "show bgp ipv6 (unicast|multicast)",
7659 SHOW_STR
7660 BGP_STR
7661 "Address family\n"
7662 "Address Family modifier\n"
7663 "Address Family modifier\n")
7664{
7665 if (strncmp (argv[0], "m", 1) == 0)
7666 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7667 NULL);
7668
7669 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007670}
7671
Lou Berger35c36862016-01-12 13:42:06 -05007672DEFUN (show_bgp_ipv6_route,
7673 show_bgp_ipv6_route_cmd,
7674 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007675 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007676 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007677 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007678 "Network in the BGP routing table to display\n")
7679{
7680 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7681}
7682
Lou Berger35c36862016-01-12 13:42:06 -05007683DEFUN (show_bgp_ipv6_safi_route,
7684 show_bgp_ipv6_safi_route_cmd,
7685 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007686 SHOW_STR
7687 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007688 "Address family\n"
7689 "Address Family modifier\n"
7690 "Address Family modifier\n"
7691 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007692{
Lou Berger35c36862016-01-12 13:42:06 -05007693 if (strncmp (argv[0], "m", 1) == 0)
7694 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7695
7696 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007697}
7698
Lou Bergerf9b6c392016-01-12 13:42:09 -05007699/* old command */
7700DEFUN (show_ipv6_bgp_route,
7701 show_ipv6_bgp_route_cmd,
7702 "show ipv6 bgp X:X::X:X",
7703 SHOW_STR
7704 IP_STR
7705 BGP_STR
7706 "Network in the BGP routing table to display\n")
7707{
7708 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7709}
7710
7711DEFUN (show_bgp_prefix,
7712 show_bgp_prefix_cmd,
7713 "show bgp X:X::X:X/M",
7714 SHOW_STR
7715 BGP_STR
7716 "IPv6 prefix <network>/<length>\n")
7717{
7718 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7719}
7720
7721
Lou Berger35c36862016-01-12 13:42:06 -05007722/* new002 */
7723DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007724 show_bgp_ipv6_prefix_cmd,
7725 "show bgp ipv6 X:X::X:X/M",
7726 SHOW_STR
7727 BGP_STR
7728 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007729 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7730{
7731 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7732}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007733DEFUN (show_bgp_ipv6_safi_prefix,
7734 show_bgp_ipv6_safi_prefix_cmd,
7735 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7736 SHOW_STR
7737 BGP_STR
7738 "Address family\n"
7739 "Address Family modifier\n"
7740 "Address Family modifier\n"
7741 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7742{
7743 if (strncmp (argv[0], "m", 1) == 0)
7744 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7745
7746 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7747}
7748
Lou Bergerf9b6c392016-01-12 13:42:09 -05007749/* old command */
7750DEFUN (show_ipv6_bgp_prefix,
7751 show_ipv6_bgp_prefix_cmd,
7752 "show ipv6 bgp X:X::X:X/M",
7753 SHOW_STR
7754 IP_STR
7755 BGP_STR
7756 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7757{
7758 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7759}
7760
paulbb46e942003-10-24 19:02:03 +00007761DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007762 show_bgp_view_cmd,
7763 "show bgp view WORD",
7764 SHOW_STR
7765 BGP_STR
7766 "BGP view\n"
7767 "View name\n")
7768{
7769 struct bgp *bgp;
7770
7771 /* BGP structure lookup. */
7772 bgp = bgp_lookup_by_name (argv[0]);
7773 if (bgp == NULL)
7774 {
7775 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7776 return CMD_WARNING;
7777 }
7778
7779 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7780}
7781
7782DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007783 show_bgp_view_ipv6_cmd,
7784 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007785 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007786 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007787 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007788 "View name\n"
7789 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007790{
7791 struct bgp *bgp;
7792
7793 /* BGP structure lookup. */
7794 bgp = bgp_lookup_by_name (argv[0]);
7795 if (bgp == NULL)
7796 {
7797 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7798 return CMD_WARNING;
7799 }
7800
ajs5a646652004-11-05 01:25:55 +00007801 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007802}
paulbb46e942003-10-24 19:02:03 +00007803
7804DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007805 show_bgp_view_route_cmd,
7806 "show bgp view WORD X:X::X:X",
7807 SHOW_STR
7808 BGP_STR
7809 "BGP view\n"
7810 "View name\n"
7811 "Network in the BGP routing table to display\n")
7812{
7813 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7814}
7815
7816DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007817 show_bgp_view_ipv6_route_cmd,
7818 "show bgp view WORD ipv6 X:X::X:X",
7819 SHOW_STR
7820 BGP_STR
7821 "BGP view\n"
7822 "View name\n"
7823 "Address family\n"
7824 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007825{
Lou Berger35c36862016-01-12 13:42:06 -05007826 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007827}
7828
Lou Bergerf9b6c392016-01-12 13:42:09 -05007829/* old command */
7830DEFUN (show_ipv6_mbgp,
7831 show_ipv6_mbgp_cmd,
7832 "show ipv6 mbgp",
7833 SHOW_STR
7834 IP_STR
7835 MBGP_STR)
7836{
7837 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7838 NULL);
7839}
7840
7841/* old command */
7842DEFUN (show_ipv6_mbgp_route,
7843 show_ipv6_mbgp_route_cmd,
7844 "show ipv6 mbgp X:X::X:X",
7845 SHOW_STR
7846 IP_STR
7847 MBGP_STR
7848 "Network in the MBGP routing table to display\n")
7849{
7850 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7851}
7852
7853/* old command */
7854DEFUN (show_ipv6_mbgp_prefix,
7855 show_ipv6_mbgp_prefix_cmd,
7856 "show ipv6 mbgp X:X::X:X/M",
7857 SHOW_STR
7858 IP_STR
7859 MBGP_STR
7860 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7861{
7862 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7863}
7864
Lou Berger35c36862016-01-12 13:42:06 -05007865DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007866 show_bgp_view_prefix_cmd,
7867 "show bgp view WORD X:X::X:X/M",
7868 SHOW_STR
7869 BGP_STR
7870 "BGP view\n"
7871 "View name\n"
7872 "IPv6 prefix <network>/<length>\n")
7873{
7874 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7875}
7876
7877DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007878 show_bgp_view_ipv6_prefix_cmd,
7879 "show bgp view WORD ipv6 X:X::X:X/M",
7880 SHOW_STR
7881 BGP_STR
7882 "BGP view\n"
7883 "View name\n"
7884 "Address family\n"
7885 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007886{
Lou Berger35c36862016-01-12 13:42:06 -05007887 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007888}
7889
paul718e3742002-12-13 20:15:29 +00007890#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007891
paul718e3742002-12-13 20:15:29 +00007892
paul94f2b392005-06-28 12:44:16 +00007893static int
paulfd79ac92004-10-13 05:06:08 +00007894bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007895 safi_t safi, enum bgp_show_type type)
7896{
7897 int i;
7898 struct buffer *b;
7899 char *regstr;
7900 int first;
7901 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007902 int rc;
paul718e3742002-12-13 20:15:29 +00007903
7904 first = 0;
7905 b = buffer_new (1024);
7906 for (i = 0; i < argc; i++)
7907 {
7908 if (first)
7909 buffer_putc (b, ' ');
7910 else
7911 {
7912 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7913 continue;
7914 first = 1;
7915 }
7916
7917 buffer_putstr (b, argv[i]);
7918 }
7919 buffer_putc (b, '\0');
7920
7921 regstr = buffer_getstr (b);
7922 buffer_free (b);
7923
7924 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007925 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007926 if (! regex)
7927 {
7928 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7929 VTY_NEWLINE);
7930 return CMD_WARNING;
7931 }
7932
ajs5a646652004-11-05 01:25:55 +00007933 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7934 bgp_regex_free (regex);
7935 return rc;
paul718e3742002-12-13 20:15:29 +00007936}
7937
Lou Bergerf9b6c392016-01-12 13:42:09 -05007938
7939DEFUN (show_ip_bgp_regexp,
7940 show_ip_bgp_regexp_cmd,
7941 "show ip bgp regexp .LINE",
7942 SHOW_STR
7943 IP_STR
7944 BGP_STR
7945 "Display routes matching the AS path regular expression\n"
7946 "A regular-expression to match the BGP AS paths\n")
7947{
7948 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7949 bgp_show_type_regexp);
7950}
7951
7952DEFUN (show_ip_bgp_flap_regexp,
7953 show_ip_bgp_flap_regexp_cmd,
7954 "show ip bgp flap-statistics regexp .LINE",
7955 SHOW_STR
7956 IP_STR
7957 BGP_STR
7958 "Display flap statistics of routes\n"
7959 "Display routes matching the AS path regular expression\n"
7960 "A regular-expression to match the BGP AS paths\n")
7961{
7962 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7963 bgp_show_type_flap_regexp);
7964}
7965
7966ALIAS (show_ip_bgp_flap_regexp,
7967 show_ip_bgp_damp_flap_regexp_cmd,
7968 "show ip bgp dampening flap-statistics regexp .LINE",
7969 SHOW_STR
7970 IP_STR
7971 BGP_STR
7972 "Display detailed information about dampening\n"
7973 "Display flap statistics of routes\n"
7974 "Display routes matching the AS path regular expression\n"
7975 "A regular-expression to match the BGP AS paths\n")
7976
7977DEFUN (show_ip_bgp_ipv4_regexp,
7978 show_ip_bgp_ipv4_regexp_cmd,
7979 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7980 SHOW_STR
7981 IP_STR
7982 BGP_STR
7983 "Address family\n"
7984 "Address Family modifier\n"
7985 "Address Family modifier\n"
7986 "Display routes matching the AS path regular expression\n"
7987 "A regular-expression to match the BGP AS paths\n")
7988{
7989 if (strncmp (argv[0], "m", 1) == 0)
7990 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7991 bgp_show_type_regexp);
7992
7993 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7994 bgp_show_type_regexp);
7995}
7996
7997#ifdef HAVE_IPV6
7998DEFUN (show_bgp_regexp,
7999 show_bgp_regexp_cmd,
8000 "show bgp regexp .LINE",
8001 SHOW_STR
8002 BGP_STR
8003 "Display routes matching the AS path regular expression\n"
8004 "A regular-expression to match the BGP AS paths\n")
8005{
8006 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8007 bgp_show_type_regexp);
8008}
8009
8010/* old command */
8011DEFUN (show_ipv6_bgp_regexp,
8012 show_ipv6_bgp_regexp_cmd,
8013 "show ipv6 bgp regexp .LINE",
8014 SHOW_STR
8015 IP_STR
8016 BGP_STR
8017 "Display routes matching the AS path regular expression\n"
8018 "A regular-expression to match the BGP AS paths\n")
8019{
8020 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8021 bgp_show_type_regexp);
8022}
8023
8024/* old command */
8025DEFUN (show_ipv6_mbgp_regexp,
8026 show_ipv6_mbgp_regexp_cmd,
8027 "show ipv6 mbgp regexp .LINE",
8028 SHOW_STR
8029 IP_STR
8030 BGP_STR
8031 "Display routes matching the AS path regular expression\n"
8032 "A regular-expression to match the MBGP AS paths\n")
8033{
8034 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8035 bgp_show_type_regexp);
8036}
8037#endif /* HAVE_IPV6 */
8038
Lou Berger651b4022016-01-12 13:42:07 -05008039DEFUN (show_bgp_ipv4_safi_flap_regexp,
8040 show_bgp_ipv4_safi_flap_regexp_cmd,
8041 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008042 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008043 BGP_STR
paul718e3742002-12-13 20:15:29 +00008044 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008045 "Address Family Modifier\n"
8046 "Address Family Modifier\n"
8047 "Address Family Modifier\n"
8048 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008049 "Display flap statistics of routes\n"
8050 "Display routes matching the AS path regular expression\n"
8051 "A regular-expression to match the BGP AS paths\n")
8052{
Lou Berger651b4022016-01-12 13:42:07 -05008053 safi_t safi;
8054
8055 if (bgp_parse_safi(argv[0], &safi)) {
8056 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8057 return CMD_WARNING;
8058 }
8059 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8060 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008061}
8062
Lou Berger651b4022016-01-12 13:42:07 -05008063ALIAS (show_bgp_ipv4_safi_flap_regexp,
8064 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8065 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308066 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308067 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008068 IP_STR
8069 "Address Family Modifier\n"
8070 "Address Family Modifier\n"
8071 "Address Family Modifier\n"
8072 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308073 "Display detailed information about dampening\n"
8074 "Display flap statistics of routes\n"
8075 "Display routes matching the AS path regular expression\n"
8076 "A regular-expression to match the BGP AS paths\n")
8077
Lou Berger651b4022016-01-12 13:42:07 -05008078#ifdef HAVE_IPV6
8079DEFUN (show_bgp_ipv6_safi_flap_regexp,
8080 show_bgp_ipv6_safi_flap_regexp_cmd,
8081 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008082 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008083 BGP_STR
8084 IPV6_STR
8085 "Address Family Modifier\n"
8086 "Address Family Modifier\n"
8087 "Address Family Modifier\n"
8088 "Address Family Modifier\n"
8089 "Display flap statistics of routes\n"
8090 "Display routes matching the AS path regular expression\n"
8091 "A regular-expression to match the BGP AS paths\n")
8092{
8093 safi_t safi;
8094
8095 if (bgp_parse_safi(argv[0], &safi)) {
8096 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8097 return CMD_WARNING;
8098 }
8099 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8100 bgp_show_type_flap_regexp);
8101}
8102
8103ALIAS (show_bgp_ipv6_safi_flap_regexp,
8104 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8105 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8106 SHOW_STR
8107 BGP_STR
8108 IPV6_STR
8109 "Address Family Modifier\n"
8110 "Address Family Modifier\n"
8111 "Address Family Modifier\n"
8112 "Address Family Modifier\n"
8113 "Display detailed information about dampening\n"
8114 "Display flap statistics of routes\n"
8115 "Display routes matching the AS path regular expression\n"
8116 "A regular-expression to match the BGP AS paths\n")
8117#endif
8118
8119DEFUN (show_bgp_ipv4_safi_regexp,
8120 show_bgp_ipv4_safi_regexp_cmd,
8121 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8122 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008123 BGP_STR
8124 "Address family\n"
8125 "Address Family modifier\n"
8126 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008127 "Address Family modifier\n"
8128 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008129 "Display routes matching the AS path regular expression\n"
8130 "A regular-expression to match the BGP AS paths\n")
8131{
Lou Berger651b4022016-01-12 13:42:07 -05008132 safi_t safi;
8133 if (bgp_parse_safi(argv[0], &safi)) {
8134 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8135 return CMD_WARNING;
8136 }
paul718e3742002-12-13 20:15:29 +00008137
Lou Berger651b4022016-01-12 13:42:07 -05008138 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008139 bgp_show_type_regexp);
8140}
paul718e3742002-12-13 20:15:29 +00008141#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008142DEFUN (show_bgp_ipv6_safi_regexp,
8143 show_bgp_ipv6_safi_regexp_cmd,
8144 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008145 SHOW_STR
8146 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008147 "Address family\n"
8148 "Address Family modifier\n"
8149 "Address Family modifier\n"
8150 "Address Family modifier\n"
8151 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008152 "Display routes matching the AS path regular expression\n"
8153 "A regular-expression to match the BGP AS paths\n")
8154{
Lou Berger651b4022016-01-12 13:42:07 -05008155 safi_t safi;
8156 if (bgp_parse_safi(argv[0], &safi)) {
8157 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8158 return CMD_WARNING;
8159 }
8160
8161 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008162 bgp_show_type_regexp);
8163}
8164
Lou Berger651b4022016-01-12 13:42:07 -05008165DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008166 show_bgp_ipv6_regexp_cmd,
8167 "show bgp ipv6 regexp .LINE",
8168 SHOW_STR
8169 BGP_STR
8170 "Address family\n"
8171 "Display routes matching the AS path regular expression\n"
8172 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008173{
8174 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8175 bgp_show_type_regexp);
8176}
8177
paul718e3742002-12-13 20:15:29 +00008178#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008179
paul94f2b392005-06-28 12:44:16 +00008180static int
paulfd79ac92004-10-13 05:06:08 +00008181bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008182 safi_t safi, enum bgp_show_type type)
8183{
8184 struct prefix_list *plist;
8185
8186 plist = prefix_list_lookup (afi, prefix_list_str);
8187 if (plist == NULL)
8188 {
8189 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8190 prefix_list_str, VTY_NEWLINE);
8191 return CMD_WARNING;
8192 }
8193
ajs5a646652004-11-05 01:25:55 +00008194 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008195}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008196DEFUN (show_ip_bgp_prefix_list,
8197 show_ip_bgp_prefix_list_cmd,
8198 "show ip bgp prefix-list WORD",
8199 SHOW_STR
8200 IP_STR
8201 BGP_STR
8202 "Display routes conforming to the prefix-list\n"
8203 "IP prefix-list name\n")
8204{
8205 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8206 bgp_show_type_prefix_list);
8207}
8208
8209DEFUN (show_ip_bgp_flap_prefix_list,
8210 show_ip_bgp_flap_prefix_list_cmd,
8211 "show ip bgp flap-statistics prefix-list WORD",
8212 SHOW_STR
8213 IP_STR
8214 BGP_STR
8215 "Display flap statistics of routes\n"
8216 "Display routes conforming to the prefix-list\n"
8217 "IP prefix-list name\n")
8218{
8219 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8220 bgp_show_type_flap_prefix_list);
8221}
8222
8223ALIAS (show_ip_bgp_flap_prefix_list,
8224 show_ip_bgp_damp_flap_prefix_list_cmd,
8225 "show ip bgp dampening flap-statistics prefix-list WORD",
8226 SHOW_STR
8227 IP_STR
8228 BGP_STR
8229 "Display detailed information about dampening\n"
8230 "Display flap statistics of routes\n"
8231 "Display routes conforming to the prefix-list\n"
8232 "IP prefix-list name\n")
8233
8234DEFUN (show_ip_bgp_ipv4_prefix_list,
8235 show_ip_bgp_ipv4_prefix_list_cmd,
8236 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
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 conforming to the prefix-list\n"
8244 "IP prefix-list name\n")
8245{
8246 if (strncmp (argv[0], "m", 1) == 0)
8247 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8248 bgp_show_type_prefix_list);
8249
8250 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8251 bgp_show_type_prefix_list);
8252}
8253
8254#ifdef HAVE_IPV6
8255DEFUN (show_bgp_prefix_list,
8256 show_bgp_prefix_list_cmd,
8257 "show bgp prefix-list WORD",
8258 SHOW_STR
8259 BGP_STR
8260 "Display routes conforming to the prefix-list\n"
8261 "IPv6 prefix-list name\n")
8262{
8263 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8264 bgp_show_type_prefix_list);
8265}
8266
8267ALIAS (show_bgp_prefix_list,
8268 show_bgp_ipv6_prefix_list_cmd,
8269 "show bgp ipv6 prefix-list WORD",
8270 SHOW_STR
8271 BGP_STR
8272 "Address family\n"
8273 "Display routes conforming to the prefix-list\n"
8274 "IPv6 prefix-list name\n")
8275
8276/* old command */
8277DEFUN (show_ipv6_bgp_prefix_list,
8278 show_ipv6_bgp_prefix_list_cmd,
8279 "show ipv6 bgp prefix-list WORD",
8280 SHOW_STR
8281 IPV6_STR
8282 BGP_STR
8283 "Display routes matching the prefix-list\n"
8284 "IPv6 prefix-list name\n")
8285{
8286 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8287 bgp_show_type_prefix_list);
8288}
8289
8290/* old command */
8291DEFUN (show_ipv6_mbgp_prefix_list,
8292 show_ipv6_mbgp_prefix_list_cmd,
8293 "show ipv6 mbgp prefix-list WORD",
8294 SHOW_STR
8295 IPV6_STR
8296 MBGP_STR
8297 "Display routes matching the prefix-list\n"
8298 "IPv6 prefix-list name\n")
8299{
8300 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8301 bgp_show_type_prefix_list);
8302}
8303#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00008304
Lou Berger35c36862016-01-12 13:42:06 -05008305DEFUN (show_bgp_ipv4_prefix_list,
8306 show_bgp_ipv4_prefix_list_cmd,
8307 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008308 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008309 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008310 IP_STR
paul718e3742002-12-13 20:15:29 +00008311 "Display routes conforming to the prefix-list\n"
8312 "IP prefix-list name\n")
8313{
8314 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8315 bgp_show_type_prefix_list);
8316}
8317
Lou Berger651b4022016-01-12 13:42:07 -05008318DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8319 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8320 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008321 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008322 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008323 IP_STR
8324 "Address Family Modifier\n"
8325 "Address Family Modifier\n"
8326 "Address Family Modifier\n"
8327 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008328 "Display flap statistics of routes\n"
8329 "Display routes conforming to the prefix-list\n"
8330 "IP prefix-list name\n")
8331{
Lou Berger651b4022016-01-12 13:42:07 -05008332 safi_t safi;
8333 if (bgp_parse_safi(argv[0], &safi)) {
8334 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8335 return CMD_WARNING;
8336 }
8337 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008338 bgp_show_type_flap_prefix_list);
8339}
8340
Lou Berger651b4022016-01-12 13:42:07 -05008341ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8342 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8343 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308344 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308345 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008346 IP_STR
8347 "Address Family Modifier\n"
8348 "Address Family Modifier\n"
8349 "Address Family Modifier\n"
8350 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308351 "Display detailed information about dampening\n"
8352 "Display flap statistics of routes\n"
8353 "Display routes conforming to the prefix-list\n"
8354 "IP prefix-list name\n")
8355
Lou Berger651b4022016-01-12 13:42:07 -05008356#ifdef HAVE_IPV6
8357DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8358 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8359 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008360 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008361 BGP_STR
8362 IPV6_STR
8363 "Address Family Modifier\n"
8364 "Address Family Modifier\n"
8365 "Address Family Modifier\n"
8366 "Address Family Modifier\n"
8367 "Display flap statistics of routes\n"
8368 "Display routes conforming to the prefix-list\n"
8369 "IP prefix-list name\n")
8370{
8371 safi_t safi;
8372 if (bgp_parse_safi(argv[0], &safi)) {
8373 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8374 return CMD_WARNING;
8375 }
8376 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8377 bgp_show_type_flap_prefix_list);
8378}
8379ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8380 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8381 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8382 SHOW_STR
8383 BGP_STR
8384 IPV6_STR
8385 "Address Family Modifier\n"
8386 "Address Family Modifier\n"
8387 "Address Family Modifier\n"
8388 "Address Family Modifier\n"
8389 "Display detailed information about dampening\n"
8390 "Display flap statistics of routes\n"
8391 "Display routes conforming to the prefix-list\n"
8392 "IP prefix-list name\n")
8393#endif
8394
8395DEFUN (show_bgp_ipv4_safi_prefix_list,
8396 show_bgp_ipv4_safi_prefix_list_cmd,
8397 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8398 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008399 BGP_STR
8400 "Address family\n"
8401 "Address Family modifier\n"
8402 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008403 "Address Family modifier\n"
8404 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008405 "Display routes conforming to the prefix-list\n"
8406 "IP prefix-list name\n")
8407{
Lou Berger651b4022016-01-12 13:42:07 -05008408 safi_t safi;
8409 if (bgp_parse_safi(argv[0], &safi)) {
8410 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8411 return CMD_WARNING;
8412 }
8413 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008414 bgp_show_type_prefix_list);
8415}
paul718e3742002-12-13 20:15:29 +00008416#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008417DEFUN (show_bgp_ipv6_safi_prefix_list,
8418 show_bgp_ipv6_safi_prefix_list_cmd,
8419 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008420 SHOW_STR
8421 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008422 "Address family\n"
8423 "Address Family modifier\n"
8424 "Address Family modifier\n"
8425 "Address Family modifier\n"
8426 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008427 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008428 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008429{
Lou Berger651b4022016-01-12 13:42:07 -05008430 safi_t safi;
8431 if (bgp_parse_safi(argv[0], &safi)) {
8432 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8433 return CMD_WARNING;
8434 }
8435 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008436 bgp_show_type_prefix_list);
8437}
8438
paul718e3742002-12-13 20:15:29 +00008439#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008440
paul94f2b392005-06-28 12:44:16 +00008441static int
paulfd79ac92004-10-13 05:06:08 +00008442bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008443 safi_t safi, enum bgp_show_type type)
8444{
8445 struct as_list *as_list;
8446
8447 as_list = as_list_lookup (filter);
8448 if (as_list == NULL)
8449 {
8450 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8451 return CMD_WARNING;
8452 }
8453
ajs5a646652004-11-05 01:25:55 +00008454 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008455}
8456
Lou Bergerf9b6c392016-01-12 13:42:09 -05008457DEFUN (show_ip_bgp_filter_list,
8458 show_ip_bgp_filter_list_cmd,
8459 "show ip bgp filter-list WORD",
8460 SHOW_STR
8461 IP_STR
8462 BGP_STR
8463 "Display routes conforming to the filter-list\n"
8464 "Regular expression access list name\n")
8465{
8466 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8467 bgp_show_type_filter_list);
8468}
8469
8470DEFUN (show_ip_bgp_flap_filter_list,
8471 show_ip_bgp_flap_filter_list_cmd,
8472 "show ip bgp flap-statistics filter-list WORD",
8473 SHOW_STR
8474 IP_STR
8475 BGP_STR
8476 "Display flap statistics of routes\n"
8477 "Display routes conforming to the filter-list\n"
8478 "Regular expression access list name\n")
8479{
8480 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8481 bgp_show_type_flap_filter_list);
8482}
8483
8484ALIAS (show_ip_bgp_flap_filter_list,
8485 show_ip_bgp_damp_flap_filter_list_cmd,
8486 "show ip bgp dampening flap-statistics filter-list WORD",
8487 SHOW_STR
8488 IP_STR
8489 BGP_STR
8490 "Display detailed information about dampening\n"
8491 "Display flap statistics of routes\n"
8492 "Display routes conforming to the filter-list\n"
8493 "Regular expression access list name\n")
8494
8495DEFUN (show_ip_bgp_ipv4_filter_list,
8496 show_ip_bgp_ipv4_filter_list_cmd,
8497 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8498 SHOW_STR
8499 IP_STR
8500 BGP_STR
8501 "Address family\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
8504 "Display routes conforming to the filter-list\n"
8505 "Regular expression access list name\n")
8506{
8507 if (strncmp (argv[0], "m", 1) == 0)
8508 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8509 bgp_show_type_filter_list);
8510
8511 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8512 bgp_show_type_filter_list);
8513}
8514
8515#ifdef HAVE_IPV6
8516DEFUN (show_bgp_filter_list,
8517 show_bgp_filter_list_cmd,
8518 "show bgp filter-list WORD",
8519 SHOW_STR
8520 BGP_STR
8521 "Display routes conforming to the filter-list\n"
8522 "Regular expression access list name\n")
8523{
8524 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8525 bgp_show_type_filter_list);
8526}
8527
8528/* old command */
8529DEFUN (show_ipv6_bgp_filter_list,
8530 show_ipv6_bgp_filter_list_cmd,
8531 "show ipv6 bgp filter-list WORD",
8532 SHOW_STR
8533 IPV6_STR
8534 BGP_STR
8535 "Display routes conforming to the filter-list\n"
8536 "Regular expression access list name\n")
8537{
8538 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8539 bgp_show_type_filter_list);
8540}
8541
8542/* old command */
8543DEFUN (show_ipv6_mbgp_filter_list,
8544 show_ipv6_mbgp_filter_list_cmd,
8545 "show ipv6 mbgp filter-list WORD",
8546 SHOW_STR
8547 IPV6_STR
8548 MBGP_STR
8549 "Display routes conforming to the filter-list\n"
8550 "Regular expression access list name\n")
8551{
8552 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8553 bgp_show_type_filter_list);
8554}
8555#endif /* HAVE_IPV6 */
8556
8557DEFUN (show_ip_bgp_dampening_info,
8558 show_ip_bgp_dampening_params_cmd,
8559 "show ip bgp dampening parameters",
8560 SHOW_STR
8561 IP_STR
8562 BGP_STR
8563 "Display detailed information about dampening\n"
8564 "Display detail of configured dampening parameters\n")
8565{
8566 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8567}
8568
Lou Berger651b4022016-01-12 13:42:07 -05008569DEFUN (show_bgp_ipv4_filter_list,
8570 show_bgp_ipv4_filter_list_cmd,
8571 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008572 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008573 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008574 IP_STR
paul718e3742002-12-13 20:15:29 +00008575 "Display routes conforming to the filter-list\n"
8576 "Regular expression access list name\n")
8577{
8578 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8579 bgp_show_type_filter_list);
8580}
8581
Lou Berger651b4022016-01-12 13:42:07 -05008582DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8583 show_bgp_ipv4_safi_flap_filter_list_cmd,
8584 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008585 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008586 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008587 IP_STR
8588 "Address Family modifier\n"
8589 "Address Family modifier\n"
8590 "Address Family modifier\n"
8591 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008592 "Display flap statistics of routes\n"
8593 "Display routes conforming to the filter-list\n"
8594 "Regular expression access list name\n")
8595{
Lou Berger651b4022016-01-12 13:42:07 -05008596 safi_t safi;
8597
8598 if (bgp_parse_safi(argv[0], &safi)) {
8599 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8600 return CMD_WARNING;
8601 }
8602 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008603 bgp_show_type_flap_filter_list);
8604}
8605
Lou Berger651b4022016-01-12 13:42:07 -05008606ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8607 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8608 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308609 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308610 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008611 IP_STR
8612 "Address Family modifier\n"
8613 "Address Family modifier\n"
8614 "Address Family modifier\n"
8615 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308616 "Display detailed information about dampening\n"
8617 "Display flap statistics of routes\n"
8618 "Display routes conforming to the filter-list\n"
8619 "Regular expression access list name\n")
8620
paul718e3742002-12-13 20:15:29 +00008621#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05008622DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8623 show_bgp_ipv6_safi_flap_filter_list_cmd,
8624 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008625 SHOW_STR
8626 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008627 IPV6_STR
8628 "Address Family modifier\n"
8629 "Address Family modifier\n"
8630 "Address Family modifier\n"
8631 "Address Family modifier\n"
8632 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008633 "Display routes conforming to the filter-list\n"
8634 "Regular expression access list name\n")
8635{
Lou Berger651b4022016-01-12 13:42:07 -05008636 safi_t safi;
8637
8638 if (bgp_parse_safi(argv[0], &safi)) {
8639 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8640 return CMD_WARNING;
8641 }
8642 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8643 bgp_show_type_flap_filter_list);
8644}
8645ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8646 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8647 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8648 SHOW_STR
8649 BGP_STR
8650 IPV6_STR
8651 "Address Family modifier\n"
8652 "Address Family modifier\n"
8653 "Address Family modifier\n"
8654 "Address Family modifier\n"
8655 "Display detailed information about dampening\n"
8656 "Display flap statistics of routes\n"
8657 "Display routes conforming to the filter-list\n"
8658 "Regular expression access list name\n")
8659#endif
8660
8661DEFUN (show_bgp_ipv4_safi_filter_list,
8662 show_bgp_ipv4_safi_filter_list_cmd,
8663 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8664 SHOW_STR
8665 BGP_STR
8666 "Address Family modifier\n"
8667 "Address Family modifier\n"
8668 "Address Family modifier\n"
8669 "Address Family modifier\n"
8670 "Display routes conforming to the filter-list\n"
8671 "Regular expression access list name\n")
8672{
8673 safi_t safi;
8674
8675 if (bgp_parse_safi(argv[0], &safi)) {
8676 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8677 return CMD_WARNING;
8678 }
8679 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8680 bgp_show_type_filter_list);
8681}
8682#ifdef HAVE_IPV6
8683DEFUN (show_bgp_ipv6_safi_filter_list,
8684 show_bgp_ipv6_safi_filter_list_cmd,
8685 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8686 SHOW_STR
8687 BGP_STR
8688 "Address Family modifier\n"
8689 "Address Family modifier\n"
8690 "Address Family modifier\n"
8691 "Address Family modifier\n"
8692 "Display routes conforming to the filter-list\n"
8693 "Regular expression access list name\n")
8694{
8695 safi_t safi;
8696
8697 if (bgp_parse_safi(argv[0], &safi)) {
8698 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8699 return CMD_WARNING;
8700 }
8701 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8702 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008703}
8704
Lou Bergerf9b6c392016-01-12 13:42:09 -05008705DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008706 show_bgp_ipv6_filter_list_cmd,
8707 "show bgp ipv6 filter-list WORD",
8708 SHOW_STR
8709 BGP_STR
8710 "Address family\n"
8711 "Display routes conforming to the filter-list\n"
8712 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008713{
8714 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8715 bgp_show_type_filter_list);
8716}
8717
paul718e3742002-12-13 20:15:29 +00008718#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008719
paul94f2b392005-06-28 12:44:16 +00008720static int
paulfd79ac92004-10-13 05:06:08 +00008721bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008722 safi_t safi, enum bgp_show_type type)
8723{
8724 struct route_map *rmap;
8725
8726 rmap = route_map_lookup_by_name (rmap_str);
8727 if (! rmap)
8728 {
8729 vty_out (vty, "%% %s is not a valid route-map name%s",
8730 rmap_str, VTY_NEWLINE);
8731 return CMD_WARNING;
8732 }
8733
ajs5a646652004-11-05 01:25:55 +00008734 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008735}
8736
Lou Bergerf9b6c392016-01-12 13:42:09 -05008737DEFUN (show_ip_bgp_route_map,
8738 show_ip_bgp_route_map_cmd,
8739 "show ip bgp route-map WORD",
8740 SHOW_STR
8741 IP_STR
8742 BGP_STR
8743 "Display routes matching the route-map\n"
8744 "A route-map to match on\n")
8745{
8746 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8747 bgp_show_type_route_map);
8748}
8749
8750DEFUN (show_ip_bgp_flap_route_map,
8751 show_ip_bgp_flap_route_map_cmd,
8752 "show ip bgp flap-statistics route-map WORD",
8753 SHOW_STR
8754 IP_STR
8755 BGP_STR
8756 "Display flap statistics of routes\n"
8757 "Display routes matching the route-map\n"
8758 "A route-map to match on\n")
8759{
8760 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8761 bgp_show_type_flap_route_map);
8762}
8763
8764ALIAS (show_ip_bgp_flap_route_map,
8765 show_ip_bgp_damp_flap_route_map_cmd,
8766 "show ip bgp dampening flap-statistics route-map WORD",
8767 SHOW_STR
8768 IP_STR
8769 BGP_STR
8770 "Display detailed information about dampening\n"
8771 "Display flap statistics of routes\n"
8772 "Display routes matching the route-map\n"
8773 "A route-map to match on\n")
8774
8775DEFUN (show_ip_bgp_ipv4_route_map,
8776 show_ip_bgp_ipv4_route_map_cmd,
8777 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8778 SHOW_STR
8779 IP_STR
8780 BGP_STR
8781 "Address family\n"
8782 "Address Family modifier\n"
8783 "Address Family modifier\n"
8784 "Display routes matching the route-map\n"
8785 "A route-map to match on\n")
8786{
8787 if (strncmp (argv[0], "m", 1) == 0)
8788 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8789 bgp_show_type_route_map);
8790
8791 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8792 bgp_show_type_route_map);
8793}
8794
8795DEFUN (show_bgp_route_map,
8796 show_bgp_route_map_cmd,
8797 "show bgp route-map WORD",
8798 SHOW_STR
8799 BGP_STR
8800 "Display routes matching the route-map\n"
8801 "A route-map to match on\n")
8802{
8803 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8804 bgp_show_type_route_map);
8805}
8806
8807DEFUN (show_ip_bgp_cidr_only,
8808 show_ip_bgp_cidr_only_cmd,
8809 "show ip bgp cidr-only",
8810 SHOW_STR
8811 IP_STR
8812 BGP_STR
8813 "Display only routes with non-natural netmasks\n")
8814{
8815 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8816 bgp_show_type_cidr_only, NULL);
8817}
8818
8819DEFUN (show_ip_bgp_flap_cidr_only,
8820 show_ip_bgp_flap_cidr_only_cmd,
8821 "show ip bgp flap-statistics cidr-only",
8822 SHOW_STR
8823 IP_STR
8824 BGP_STR
8825 "Display flap statistics of routes\n"
8826 "Display only routes with non-natural netmasks\n")
8827{
8828 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8829 bgp_show_type_flap_cidr_only, NULL);
8830}
8831
8832ALIAS (show_ip_bgp_flap_cidr_only,
8833 show_ip_bgp_damp_flap_cidr_only_cmd,
8834 "show ip bgp dampening flap-statistics cidr-only",
8835 SHOW_STR
8836 IP_STR
8837 BGP_STR
8838 "Display detailed information about dampening\n"
8839 "Display flap statistics of routes\n"
8840 "Display only routes with non-natural netmasks\n")
8841
8842DEFUN (show_ip_bgp_ipv4_cidr_only,
8843 show_ip_bgp_ipv4_cidr_only_cmd,
8844 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8845 SHOW_STR
8846 IP_STR
8847 BGP_STR
8848 "Address family\n"
8849 "Address Family modifier\n"
8850 "Address Family modifier\n"
8851 "Display only routes with non-natural netmasks\n")
8852{
8853 if (strncmp (argv[0], "m", 1) == 0)
8854 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8855 bgp_show_type_cidr_only, NULL);
8856
8857 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8858 bgp_show_type_cidr_only, NULL);
8859}
8860
8861DEFUN (show_ip_bgp_community_all,
8862 show_ip_bgp_community_all_cmd,
8863 "show ip bgp community",
8864 SHOW_STR
8865 IP_STR
8866 BGP_STR
8867 "Display routes matching the communities\n")
8868{
8869 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8870 bgp_show_type_community_all, NULL);
8871}
8872
8873DEFUN (show_ip_bgp_ipv4_community_all,
8874 show_ip_bgp_ipv4_community_all_cmd,
8875 "show ip bgp ipv4 (unicast|multicast) community",
8876 SHOW_STR
8877 IP_STR
8878 BGP_STR
8879 "Address family\n"
8880 "Address Family modifier\n"
8881 "Address Family modifier\n"
8882 "Display routes matching the communities\n")
8883{
8884 if (strncmp (argv[0], "m", 1) == 0)
8885 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8886 bgp_show_type_community_all, NULL);
8887
8888 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8889 bgp_show_type_community_all, NULL);
8890}
8891
8892#ifdef HAVE_IPV6
8893DEFUN (show_bgp_community_all,
8894 show_bgp_community_all_cmd,
8895 "show bgp community",
8896 SHOW_STR
8897 BGP_STR
8898 "Display routes matching the communities\n")
8899{
8900 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8901 bgp_show_type_community_all, NULL);
8902}
8903
8904ALIAS (show_bgp_community_all,
8905 show_bgp_ipv6_community_all_cmd,
8906 "show bgp ipv6 community",
8907 SHOW_STR
8908 BGP_STR
8909 "Address family\n"
8910 "Display routes matching the communities\n")
8911
8912/* old command */
8913DEFUN (show_ipv6_bgp_community_all,
8914 show_ipv6_bgp_community_all_cmd,
8915 "show ipv6 bgp community",
8916 SHOW_STR
8917 IPV6_STR
8918 BGP_STR
8919 "Display routes matching the communities\n")
8920{
8921 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
8922 bgp_show_type_community_all, NULL);
8923}
8924
8925/* old command */
8926DEFUN (show_ipv6_mbgp_community_all,
8927 show_ipv6_mbgp_community_all_cmd,
8928 "show ipv6 mbgp community",
8929 SHOW_STR
8930 IPV6_STR
8931 MBGP_STR
8932 "Display routes matching the communities\n")
8933{
8934 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
8935 bgp_show_type_community_all, NULL);
8936}
8937#endif /* HAVE_IPV6 */
8938
Lou Berger651b4022016-01-12 13:42:07 -05008939DEFUN (show_bgp_ipv4_route_map,
8940 show_bgp_ipv4_route_map_cmd,
8941 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00008942 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008943 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008944 IP_STR
paul718e3742002-12-13 20:15:29 +00008945 "Display routes matching the route-map\n"
8946 "A route-map to match on\n")
8947{
8948 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8949 bgp_show_type_route_map);
8950}
8951
Lou Berger651b4022016-01-12 13:42:07 -05008952DEFUN (show_bgp_ipv4_safi_flap_route_map,
8953 show_bgp_ipv4_safi_flap_route_map_cmd,
8954 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008955 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008956 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008957 IP_STR
8958 "Address Family Modifier\n"
8959 "Address Family Modifier\n"
8960 "Address Family Modifier\n"
8961 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008962 "Display flap statistics of routes\n"
8963 "Display routes matching the route-map\n"
8964 "A route-map to match on\n")
8965{
Lou Berger651b4022016-01-12 13:42:07 -05008966 safi_t safi;
8967 if (bgp_parse_safi(argv[0], &safi)) {
8968 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8969 return CMD_WARNING;
8970 }
8971 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008972 bgp_show_type_flap_route_map);
8973}
8974
Lou Berger651b4022016-01-12 13:42:07 -05008975ALIAS (show_bgp_ipv4_safi_flap_route_map,
8976 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
8977 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05308978 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308979 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008980 IP_STR
8981 "Address Family Modifier\n"
8982 "Address Family Modifier\n"
8983 "Address Family Modifier\n"
8984 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308985 "Display detailed information about dampening\n"
8986 "Display flap statistics of routes\n"
8987 "Display routes matching the route-map\n"
8988 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05008989#ifdef HAVE_IPV6
8990DEFUN (show_bgp_ipv6_safi_flap_route_map,
8991 show_bgp_ipv6_safi_flap_route_map_cmd,
8992 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00008993 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008994 BGP_STR
8995 IPV6_STR
8996 "Address Family Modifier\n"
8997 "Address Family Modifier\n"
8998 "Address Family Modifier\n"
8999 "Address Family Modifier\n"
9000 "Display flap statistics of routes\n"
9001 "Display routes matching the route-map\n"
9002 "A route-map to match on\n")
9003{
9004 safi_t safi;
9005 if (bgp_parse_safi(argv[0], &safi)) {
9006 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9007 return CMD_WARNING;
9008 }
9009 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9010 bgp_show_type_flap_route_map);
9011}
9012ALIAS (show_bgp_ipv6_safi_flap_route_map,
9013 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9014 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9015 SHOW_STR
9016 BGP_STR
9017 IPV6_STR
9018 "Address Family Modifier\n"
9019 "Address Family Modifier\n"
9020 "Address Family Modifier\n"
9021 "Address Family Modifier\n"
9022 "Display detailed information about dampening\n"
9023 "Display flap statistics of routes\n"
9024 "Display routes matching the route-map\n"
9025 "A route-map to match on\n")
9026#endif
9027
9028DEFUN (show_bgp_ipv4_safi_route_map,
9029 show_bgp_ipv4_safi_route_map_cmd,
9030 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9031 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009032 BGP_STR
9033 "Address family\n"
9034 "Address Family modifier\n"
9035 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009036 "Address Family modifier\n"
9037 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009038 "Display routes matching the route-map\n"
9039 "A route-map to match on\n")
9040{
Lou Berger651b4022016-01-12 13:42:07 -05009041 safi_t safi;
9042 if (bgp_parse_safi(argv[0], &safi)) {
9043 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9044 return CMD_WARNING;
9045 }
9046 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009047 bgp_show_type_route_map);
9048}
Lou Berger651b4022016-01-12 13:42:07 -05009049#ifdef HAVE_IPV6
9050DEFUN (show_bgp_ipv6_safi_route_map,
9051 show_bgp_ipv6_safi_route_map_cmd,
9052 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009053 SHOW_STR
9054 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009055 "Address family\n"
9056 "Address Family modifier\n"
9057 "Address Family modifier\n"
9058 "Address Family modifier\n"
9059 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009060 "Display routes matching the route-map\n"
9061 "A route-map to match on\n")
9062{
Lou Berger651b4022016-01-12 13:42:07 -05009063 safi_t safi;
9064 if (bgp_parse_safi(argv[0], &safi)) {
9065 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9066 return CMD_WARNING;
9067 }
9068 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009069 bgp_show_type_route_map);
9070}
9071
Lou Berger651b4022016-01-12 13:42:07 -05009072DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009073 show_bgp_ipv6_route_map_cmd,
9074 "show bgp ipv6 route-map WORD",
9075 SHOW_STR
9076 BGP_STR
9077 "Address family\n"
9078 "Display routes matching the route-map\n"
9079 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009080{
9081 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9082 bgp_show_type_route_map);
9083}
9084#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02009085
Lou Berger651b4022016-01-12 13:42:07 -05009086DEFUN (show_bgp_ipv4_cidr_only,
9087 show_bgp_ipv4_cidr_only_cmd,
9088 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009089 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009090 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009091 IP_STR
paul718e3742002-12-13 20:15:29 +00009092 "Display only routes with non-natural netmasks\n")
9093{
9094 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009095 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009096}
9097
Lou Berger651b4022016-01-12 13:42:07 -05009098DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9099 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9100 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009101 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009102 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009103 "Address Family\n"
9104 "Address Family Modifier\n"
9105 "Address Family Modifier\n"
9106 "Address Family Modifier\n"
9107 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009108 "Display flap statistics of routes\n"
9109 "Display only routes with non-natural netmasks\n")
9110{
Lou Berger651b4022016-01-12 13:42:07 -05009111 safi_t safi;
9112
9113 if (bgp_parse_safi(argv[0], &safi)) {
9114 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9115 return CMD_WARNING;
9116 }
9117 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009118}
9119
Lou Berger651b4022016-01-12 13:42:07 -05009120ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9121 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9122 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309123 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309124 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009125 "Address Family\n"
9126 "Address Family Modifier\n"
9127 "Address Family Modifier\n"
9128 "Address Family Modifier\n"
9129 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309130 "Display detailed information about dampening\n"
9131 "Display flap statistics of routes\n"
9132 "Display only routes with non-natural netmasks\n")
9133
Lou Berger651b4022016-01-12 13:42:07 -05009134DEFUN (show_bgp_ipv4_safi_cidr_only,
9135 show_bgp_ipv4_safi_cidr_only_cmd,
9136 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009137 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009138 BGP_STR
9139 "Address family\n"
9140 "Address Family modifier\n"
9141 "Address Family modifier\n"
9142 "Display only routes with non-natural netmasks\n")
9143{
9144 if (strncmp (argv[0], "m", 1) == 0)
9145 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009146 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009147
9148 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009149 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009150}
David Lamparter6b0655a2014-06-04 06:53:35 +02009151
Lou Berger651b4022016-01-12 13:42:07 -05009152/* new046 */
9153DEFUN (show_bgp_afi_safi_community_all,
9154 show_bgp_afi_safi_community_all_cmd,
paul718e3742002-12-13 20:15:29 +00009155#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -05009156 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
9157#else
9158 "show bgp ipv4 (encap|multicast|unicast|vpn) community",
9159#endif
paul718e3742002-12-13 20:15:29 +00009160 SHOW_STR
9161 BGP_STR
9162 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009163#ifdef HAVE_IPV6
9164 "Address family\n"
9165#endif
9166 "Address Family modifier\n"
9167 "Address Family modifier\n"
9168 "Address Family modifier\n"
9169 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009170 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009171{
9172 safi_t safi;
9173 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009174
Lou Berger651b4022016-01-12 13:42:07 -05009175 if (bgp_parse_afi(argv[0], &afi)) {
9176 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9177 return CMD_WARNING;
9178 }
9179 if (bgp_parse_safi(argv[1], &safi)) {
9180 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9181 return CMD_WARNING;
9182 }
9183
9184 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9185}
9186DEFUN (show_bgp_afi_community_all,
9187 show_bgp_afi_community_all_cmd,
9188#ifdef HAVE_IPV6
9189 "show bgp (ipv4|ipv6) community",
9190#else
9191 "show bgp ipv4 community",
9192#endif
paul718e3742002-12-13 20:15:29 +00009193 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009194 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009195 "Address family\n"
9196#ifdef HAVE_IPV6
9197 "Address family\n"
9198#endif
paul718e3742002-12-13 20:15:29 +00009199 "Display routes matching the communities\n")
9200{
Lou Berger651b4022016-01-12 13:42:07 -05009201 afi_t afi;
9202 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009203
Lou Berger651b4022016-01-12 13:42:07 -05009204 if (bgp_parse_afi(argv[0], &afi)) {
9205 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9206 return CMD_WARNING;
9207 }
9208 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009209}
David Lamparter6b0655a2014-06-04 06:53:35 +02009210
paul94f2b392005-06-28 12:44:16 +00009211static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009212bgp_show_community (struct vty *vty, const char *view_name, int argc,
9213 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009214{
9215 struct community *com;
9216 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009217 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009218 int i;
9219 char *str;
9220 int first = 0;
9221
Michael Lambert95cbbd22010-07-23 14:43:04 -04009222 /* BGP structure lookup */
9223 if (view_name)
9224 {
9225 bgp = bgp_lookup_by_name (view_name);
9226 if (bgp == NULL)
9227 {
9228 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9229 return CMD_WARNING;
9230 }
9231 }
9232 else
9233 {
9234 bgp = bgp_get_default ();
9235 if (bgp == NULL)
9236 {
9237 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9238 return CMD_WARNING;
9239 }
9240 }
9241
paul718e3742002-12-13 20:15:29 +00009242 b = buffer_new (1024);
9243 for (i = 0; i < argc; i++)
9244 {
9245 if (first)
9246 buffer_putc (b, ' ');
9247 else
9248 {
9249 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9250 continue;
9251 first = 1;
9252 }
9253
9254 buffer_putstr (b, argv[i]);
9255 }
9256 buffer_putc (b, '\0');
9257
9258 str = buffer_getstr (b);
9259 buffer_free (b);
9260
9261 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009262 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009263 if (! com)
9264 {
9265 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9266 return CMD_WARNING;
9267 }
9268
Michael Lambert95cbbd22010-07-23 14:43:04 -04009269 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009270 (exact ? bgp_show_type_community_exact :
9271 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009272}
9273
Lou Bergerf9b6c392016-01-12 13:42:09 -05009274DEFUN (show_ip_bgp_community,
9275 show_ip_bgp_community_cmd,
9276 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9277 SHOW_STR
9278 IP_STR
9279 BGP_STR
9280 "Display routes matching the communities\n"
9281 "community number\n"
9282 "Do not send outside local AS (well-known community)\n"
9283 "Do not advertise to any peer (well-known community)\n"
9284 "Do not export to next AS (well-known community)\n")
9285{
9286 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9287}
9288
9289ALIAS (show_ip_bgp_community,
9290 show_ip_bgp_community2_cmd,
9291 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9292 SHOW_STR
9293 IP_STR
9294 BGP_STR
9295 "Display routes matching the communities\n"
9296 "community number\n"
9297 "Do not send outside local AS (well-known community)\n"
9298 "Do not advertise to any peer (well-known community)\n"
9299 "Do not export to next AS (well-known community)\n"
9300 "community number\n"
9301 "Do not send outside local AS (well-known community)\n"
9302 "Do not advertise to any peer (well-known community)\n"
9303 "Do not export to next AS (well-known community)\n")
9304
9305ALIAS (show_ip_bgp_community,
9306 show_ip_bgp_community3_cmd,
9307 "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)",
9308 SHOW_STR
9309 IP_STR
9310 BGP_STR
9311 "Display routes matching the communities\n"
9312 "community number\n"
9313 "Do not send outside local AS (well-known community)\n"
9314 "Do not advertise to any peer (well-known community)\n"
9315 "Do not export to next AS (well-known community)\n"
9316 "community number\n"
9317 "Do not send outside local AS (well-known community)\n"
9318 "Do not advertise to any peer (well-known community)\n"
9319 "Do not export to next AS (well-known community)\n"
9320 "community number\n"
9321 "Do not send outside local AS (well-known community)\n"
9322 "Do not advertise to any peer (well-known community)\n"
9323 "Do not export to next AS (well-known community)\n")
9324
9325ALIAS (show_ip_bgp_community,
9326 show_ip_bgp_community4_cmd,
9327 "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)",
9328 SHOW_STR
9329 IP_STR
9330 BGP_STR
9331 "Display routes matching the communities\n"
9332 "community number\n"
9333 "Do not send outside local AS (well-known community)\n"
9334 "Do not advertise to any peer (well-known community)\n"
9335 "Do not export to next AS (well-known community)\n"
9336 "community number\n"
9337 "Do not send outside local AS (well-known community)\n"
9338 "Do not advertise to any peer (well-known community)\n"
9339 "Do not export to next AS (well-known community)\n"
9340 "community number\n"
9341 "Do not send outside local AS (well-known community)\n"
9342 "Do not advertise to any peer (well-known community)\n"
9343 "Do not export to next AS (well-known community)\n"
9344 "community number\n"
9345 "Do not send outside local AS (well-known community)\n"
9346 "Do not advertise to any peer (well-known community)\n"
9347 "Do not export to next AS (well-known community)\n")
9348
9349DEFUN (show_ip_bgp_ipv4_community,
9350 show_ip_bgp_ipv4_community_cmd,
9351 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9352 SHOW_STR
9353 IP_STR
9354 BGP_STR
9355 "Address family\n"
9356 "Address Family modifier\n"
9357 "Address Family modifier\n"
9358 "Display routes matching the communities\n"
9359 "community number\n"
9360 "Do not send outside local AS (well-known community)\n"
9361 "Do not advertise to any peer (well-known community)\n"
9362 "Do not export to next AS (well-known community)\n")
9363{
9364 if (strncmp (argv[0], "m", 1) == 0)
9365 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9366
9367 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9368}
9369
9370ALIAS (show_ip_bgp_ipv4_community,
9371 show_ip_bgp_ipv4_community2_cmd,
9372 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9373 SHOW_STR
9374 IP_STR
9375 BGP_STR
9376 "Address family\n"
9377 "Address Family modifier\n"
9378 "Address Family modifier\n"
9379 "Display routes matching the communities\n"
9380 "community number\n"
9381 "Do not send outside local AS (well-known community)\n"
9382 "Do not advertise to any peer (well-known community)\n"
9383 "Do not export to next AS (well-known community)\n"
9384 "community number\n"
9385 "Do not send outside local AS (well-known community)\n"
9386 "Do not advertise to any peer (well-known community)\n"
9387 "Do not export to next AS (well-known community)\n")
9388
9389ALIAS (show_ip_bgp_ipv4_community,
9390 show_ip_bgp_ipv4_community3_cmd,
9391 "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)",
9392 SHOW_STR
9393 IP_STR
9394 BGP_STR
9395 "Address family\n"
9396 "Address Family modifier\n"
9397 "Address Family modifier\n"
9398 "Display routes matching the communities\n"
9399 "community number\n"
9400 "Do not send outside local AS (well-known community)\n"
9401 "Do not advertise to any peer (well-known community)\n"
9402 "Do not export to next AS (well-known community)\n"
9403 "community number\n"
9404 "Do not send outside local AS (well-known community)\n"
9405 "Do not advertise to any peer (well-known community)\n"
9406 "Do not export to next AS (well-known community)\n"
9407 "community number\n"
9408 "Do not send outside local AS (well-known community)\n"
9409 "Do not advertise to any peer (well-known community)\n"
9410 "Do not export to next AS (well-known community)\n")
9411
9412ALIAS (show_ip_bgp_ipv4_community,
9413 show_ip_bgp_ipv4_community4_cmd,
9414 "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)",
9415 SHOW_STR
9416 IP_STR
9417 BGP_STR
9418 "Address family\n"
9419 "Address Family modifier\n"
9420 "Address Family modifier\n"
9421 "Display routes matching the communities\n"
9422 "community number\n"
9423 "Do not send outside local AS (well-known community)\n"
9424 "Do not advertise to any peer (well-known community)\n"
9425 "Do not export to next AS (well-known community)\n"
9426 "community number\n"
9427 "Do not send outside local AS (well-known community)\n"
9428 "Do not advertise to any peer (well-known community)\n"
9429 "Do not export to next AS (well-known community)\n"
9430 "community number\n"
9431 "Do not send outside local AS (well-known community)\n"
9432 "Do not advertise to any peer (well-known community)\n"
9433 "Do not export to next AS (well-known community)\n"
9434 "community number\n"
9435 "Do not send outside local AS (well-known community)\n"
9436 "Do not advertise to any peer (well-known community)\n"
9437 "Do not export to next AS (well-known community)\n")
9438
9439DEFUN (show_ip_bgp_community_exact,
9440 show_ip_bgp_community_exact_cmd,
9441 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9442 SHOW_STR
9443 IP_STR
9444 BGP_STR
9445 "Display routes matching the communities\n"
9446 "community number\n"
9447 "Do not send outside local AS (well-known community)\n"
9448 "Do not advertise to any peer (well-known community)\n"
9449 "Do not export to next AS (well-known community)\n"
9450 "Exact match of the communities")
9451{
9452 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9453}
9454
9455ALIAS (show_ip_bgp_community_exact,
9456 show_ip_bgp_community2_exact_cmd,
9457 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9458 SHOW_STR
9459 IP_STR
9460 BGP_STR
9461 "Display routes matching the communities\n"
9462 "community number\n"
9463 "Do not send outside local AS (well-known community)\n"
9464 "Do not advertise to any peer (well-known community)\n"
9465 "Do not export to next AS (well-known community)\n"
9466 "community number\n"
9467 "Do not send outside local AS (well-known community)\n"
9468 "Do not advertise to any peer (well-known community)\n"
9469 "Do not export to next AS (well-known community)\n"
9470 "Exact match of the communities")
9471
9472ALIAS (show_ip_bgp_community_exact,
9473 show_ip_bgp_community3_exact_cmd,
9474 "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",
9475 SHOW_STR
9476 IP_STR
9477 BGP_STR
9478 "Display routes matching the communities\n"
9479 "community number\n"
9480 "Do not send outside local AS (well-known community)\n"
9481 "Do not advertise to any peer (well-known community)\n"
9482 "Do not export to next AS (well-known community)\n"
9483 "community number\n"
9484 "Do not send outside local AS (well-known community)\n"
9485 "Do not advertise to any peer (well-known community)\n"
9486 "Do not export to next AS (well-known community)\n"
9487 "community number\n"
9488 "Do not send outside local AS (well-known community)\n"
9489 "Do not advertise to any peer (well-known community)\n"
9490 "Do not export to next AS (well-known community)\n"
9491 "Exact match of the communities")
9492
9493ALIAS (show_ip_bgp_community_exact,
9494 show_ip_bgp_community4_exact_cmd,
9495 "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",
9496 SHOW_STR
9497 IP_STR
9498 BGP_STR
9499 "Display routes matching the communities\n"
9500 "community number\n"
9501 "Do not send outside local AS (well-known community)\n"
9502 "Do not advertise to any peer (well-known community)\n"
9503 "Do not export to next AS (well-known community)\n"
9504 "community number\n"
9505 "Do not send outside local AS (well-known community)\n"
9506 "Do not advertise to any peer (well-known community)\n"
9507 "Do not export to next AS (well-known community)\n"
9508 "community number\n"
9509 "Do not send outside local AS (well-known community)\n"
9510 "Do not advertise to any peer (well-known community)\n"
9511 "Do not export to next AS (well-known community)\n"
9512 "community number\n"
9513 "Do not send outside local AS (well-known community)\n"
9514 "Do not advertise to any peer (well-known community)\n"
9515 "Do not export to next AS (well-known community)\n"
9516 "Exact match of the communities")
9517
9518DEFUN (show_ip_bgp_ipv4_community_exact,
9519 show_ip_bgp_ipv4_community_exact_cmd,
9520 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9521 SHOW_STR
9522 IP_STR
9523 BGP_STR
9524 "Address family\n"
9525 "Address Family modifier\n"
9526 "Address Family modifier\n"
9527 "Display routes matching the communities\n"
9528 "community number\n"
9529 "Do not send outside local AS (well-known community)\n"
9530 "Do not advertise to any peer (well-known community)\n"
9531 "Do not export to next AS (well-known community)\n"
9532 "Exact match of the communities")
9533{
9534 if (strncmp (argv[0], "m", 1) == 0)
9535 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9536
9537 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9538}
9539
9540ALIAS (show_ip_bgp_ipv4_community_exact,
9541 show_ip_bgp_ipv4_community2_exact_cmd,
9542 "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",
9543 SHOW_STR
9544 IP_STR
9545 BGP_STR
9546 "Address family\n"
9547 "Address Family modifier\n"
9548 "Address Family modifier\n"
9549 "Display routes matching the communities\n"
9550 "community number\n"
9551 "Do not send outside local AS (well-known community)\n"
9552 "Do not advertise to any peer (well-known community)\n"
9553 "Do not export to next AS (well-known community)\n"
9554 "community number\n"
9555 "Do not send outside local AS (well-known community)\n"
9556 "Do not advertise to any peer (well-known community)\n"
9557 "Do not export to next AS (well-known community)\n"
9558 "Exact match of the communities")
9559
9560ALIAS (show_ip_bgp_ipv4_community_exact,
9561 show_ip_bgp_ipv4_community3_exact_cmd,
9562 "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",
9563 SHOW_STR
9564 IP_STR
9565 BGP_STR
9566 "Address family\n"
9567 "Address Family modifier\n"
9568 "Address Family modifier\n"
9569 "Display routes matching the communities\n"
9570 "community number\n"
9571 "Do not send outside local AS (well-known community)\n"
9572 "Do not advertise to any peer (well-known community)\n"
9573 "Do not export to next AS (well-known community)\n"
9574 "community number\n"
9575 "Do not send outside local AS (well-known community)\n"
9576 "Do not advertise to any peer (well-known community)\n"
9577 "Do not export to next AS (well-known community)\n"
9578 "community number\n"
9579 "Do not send outside local AS (well-known community)\n"
9580 "Do not advertise to any peer (well-known community)\n"
9581 "Do not export to next AS (well-known community)\n"
9582 "Exact match of the communities")
9583
9584ALIAS (show_ip_bgp_ipv4_community_exact,
9585 show_ip_bgp_ipv4_community4_exact_cmd,
9586 "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",
9587 SHOW_STR
9588 IP_STR
9589 BGP_STR
9590 "Address family\n"
9591 "Address Family modifier\n"
9592 "Address Family modifier\n"
9593 "Display routes matching the communities\n"
9594 "community number\n"
9595 "Do not send outside local AS (well-known community)\n"
9596 "Do not advertise to any peer (well-known community)\n"
9597 "Do not export to next AS (well-known community)\n"
9598 "community number\n"
9599 "Do not send outside local AS (well-known community)\n"
9600 "Do not advertise to any peer (well-known community)\n"
9601 "Do not export to next AS (well-known community)\n"
9602 "community number\n"
9603 "Do not send outside local AS (well-known community)\n"
9604 "Do not advertise to any peer (well-known community)\n"
9605 "Do not export to next AS (well-known community)\n"
9606 "community number\n"
9607 "Do not send outside local AS (well-known community)\n"
9608 "Do not advertise to any peer (well-known community)\n"
9609 "Do not export to next AS (well-known community)\n"
9610 "Exact match of the communities")
9611
9612#ifdef HAVE_IPV6
9613DEFUN (show_bgp_community,
9614 show_bgp_community_cmd,
9615 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9616 SHOW_STR
9617 BGP_STR
9618 "Display routes matching the communities\n"
9619 "community number\n"
9620 "Do not send outside local AS (well-known community)\n"
9621 "Do not advertise to any peer (well-known community)\n"
9622 "Do not export to next AS (well-known community)\n")
9623{
9624 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9625}
9626
9627ALIAS (show_bgp_community,
9628 show_bgp_ipv6_community_cmd,
9629 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9630 SHOW_STR
9631 BGP_STR
9632 "Address family\n"
9633 "Display routes matching the communities\n"
9634 "community number\n"
9635 "Do not send outside local AS (well-known community)\n"
9636 "Do not advertise to any peer (well-known community)\n"
9637 "Do not export to next AS (well-known community)\n")
9638
9639ALIAS (show_bgp_community,
9640 show_bgp_community2_cmd,
9641 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9642 SHOW_STR
9643 BGP_STR
9644 "Display routes matching the communities\n"
9645 "community number\n"
9646 "Do not send outside local AS (well-known community)\n"
9647 "Do not advertise to any peer (well-known community)\n"
9648 "Do not export to next AS (well-known community)\n"
9649 "community number\n"
9650 "Do not send outside local AS (well-known community)\n"
9651 "Do not advertise to any peer (well-known community)\n"
9652 "Do not export to next AS (well-known community)\n")
9653
9654ALIAS (show_bgp_community,
9655 show_bgp_ipv6_community2_cmd,
9656 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9657 SHOW_STR
9658 BGP_STR
9659 "Address family\n"
9660 "Display routes matching the communities\n"
9661 "community number\n"
9662 "Do not send outside local AS (well-known community)\n"
9663 "Do not advertise to any peer (well-known community)\n"
9664 "Do not export to next AS (well-known community)\n"
9665 "community number\n"
9666 "Do not send outside local AS (well-known community)\n"
9667 "Do not advertise to any peer (well-known community)\n"
9668 "Do not export to next AS (well-known community)\n")
9669
9670ALIAS (show_bgp_community,
9671 show_bgp_community3_cmd,
9672 "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)",
9673 SHOW_STR
9674 BGP_STR
9675 "Display routes matching the communities\n"
9676 "community number\n"
9677 "Do not send outside local AS (well-known community)\n"
9678 "Do not advertise to any peer (well-known community)\n"
9679 "Do not export to next AS (well-known community)\n"
9680 "community number\n"
9681 "Do not send outside local AS (well-known community)\n"
9682 "Do not advertise to any peer (well-known community)\n"
9683 "Do not export to next AS (well-known community)\n"
9684 "community number\n"
9685 "Do not send outside local AS (well-known community)\n"
9686 "Do not advertise to any peer (well-known community)\n"
9687 "Do not export to next AS (well-known community)\n")
9688
9689ALIAS (show_bgp_community,
9690 show_bgp_ipv6_community3_cmd,
9691 "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)",
9692 SHOW_STR
9693 BGP_STR
9694 "Address family\n"
9695 "Display routes matching the communities\n"
9696 "community number\n"
9697 "Do not send outside local AS (well-known community)\n"
9698 "Do not advertise to any peer (well-known community)\n"
9699 "Do not export to next AS (well-known community)\n"
9700 "community number\n"
9701 "Do not send outside local AS (well-known community)\n"
9702 "Do not advertise to any peer (well-known community)\n"
9703 "Do not export to next AS (well-known community)\n"
9704 "community number\n"
9705 "Do not send outside local AS (well-known community)\n"
9706 "Do not advertise to any peer (well-known community)\n"
9707 "Do not export to next AS (well-known community)\n")
9708
9709ALIAS (show_bgp_community,
9710 show_bgp_community4_cmd,
9711 "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)",
9712 SHOW_STR
9713 BGP_STR
9714 "Display routes matching the communities\n"
9715 "community number\n"
9716 "Do not send outside local AS (well-known community)\n"
9717 "Do not advertise to any peer (well-known community)\n"
9718 "Do not export to next AS (well-known community)\n"
9719 "community number\n"
9720 "Do not send outside local AS (well-known community)\n"
9721 "Do not advertise to any peer (well-known community)\n"
9722 "Do not export to next AS (well-known community)\n"
9723 "community number\n"
9724 "Do not send outside local AS (well-known community)\n"
9725 "Do not advertise to any peer (well-known community)\n"
9726 "Do not export to next AS (well-known community)\n"
9727 "community number\n"
9728 "Do not send outside local AS (well-known community)\n"
9729 "Do not advertise to any peer (well-known community)\n"
9730 "Do not export to next AS (well-known community)\n")
9731
9732ALIAS (show_bgp_community,
9733 show_bgp_ipv6_community4_cmd,
9734 "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)",
9735 SHOW_STR
9736 BGP_STR
9737 "Address family\n"
9738 "Display routes matching the communities\n"
9739 "community number\n"
9740 "Do not send outside local AS (well-known community)\n"
9741 "Do not advertise to any peer (well-known community)\n"
9742 "Do not export to next AS (well-known community)\n"
9743 "community number\n"
9744 "Do not send outside local AS (well-known community)\n"
9745 "Do not advertise to any peer (well-known community)\n"
9746 "Do not export to next AS (well-known community)\n"
9747 "community number\n"
9748 "Do not send outside local AS (well-known community)\n"
9749 "Do not advertise to any peer (well-known community)\n"
9750 "Do not export to next AS (well-known community)\n"
9751 "community number\n"
9752 "Do not send outside local AS (well-known community)\n"
9753 "Do not advertise to any peer (well-known community)\n"
9754 "Do not export to next AS (well-known community)\n")
9755
9756/* old command */
9757DEFUN (show_ipv6_bgp_community,
9758 show_ipv6_bgp_community_cmd,
9759 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9760 SHOW_STR
9761 IPV6_STR
9762 BGP_STR
9763 "Display routes matching the communities\n"
9764 "community number\n"
9765 "Do not send outside local AS (well-known community)\n"
9766 "Do not advertise to any peer (well-known community)\n"
9767 "Do not export to next AS (well-known community)\n")
9768{
9769 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9770}
9771
9772/* old command */
9773ALIAS (show_ipv6_bgp_community,
9774 show_ipv6_bgp_community2_cmd,
9775 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9776 SHOW_STR
9777 IPV6_STR
9778 BGP_STR
9779 "Display routes matching the communities\n"
9780 "community number\n"
9781 "Do not send outside local AS (well-known community)\n"
9782 "Do not advertise to any peer (well-known community)\n"
9783 "Do not export to next AS (well-known community)\n"
9784 "community number\n"
9785 "Do not send outside local AS (well-known community)\n"
9786 "Do not advertise to any peer (well-known community)\n"
9787 "Do not export to next AS (well-known community)\n")
9788
9789/* old command */
9790ALIAS (show_ipv6_bgp_community,
9791 show_ipv6_bgp_community3_cmd,
9792 "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)",
9793 SHOW_STR
9794 IPV6_STR
9795 BGP_STR
9796 "Display routes matching the communities\n"
9797 "community number\n"
9798 "Do not send outside local AS (well-known community)\n"
9799 "Do not advertise to any peer (well-known community)\n"
9800 "Do not export to next AS (well-known community)\n"
9801 "community number\n"
9802 "Do not send outside local AS (well-known community)\n"
9803 "Do not advertise to any peer (well-known community)\n"
9804 "Do not export to next AS (well-known community)\n"
9805 "community number\n"
9806 "Do not send outside local AS (well-known community)\n"
9807 "Do not advertise to any peer (well-known community)\n"
9808 "Do not export to next AS (well-known community)\n")
9809
9810/* old command */
9811ALIAS (show_ipv6_bgp_community,
9812 show_ipv6_bgp_community4_cmd,
9813 "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)",
9814 SHOW_STR
9815 IPV6_STR
9816 BGP_STR
9817 "Display routes matching the communities\n"
9818 "community number\n"
9819 "Do not send outside local AS (well-known community)\n"
9820 "Do not advertise to any peer (well-known community)\n"
9821 "Do not export to next AS (well-known community)\n"
9822 "community number\n"
9823 "Do not send outside local AS (well-known community)\n"
9824 "Do not advertise to any peer (well-known community)\n"
9825 "Do not export to next AS (well-known community)\n"
9826 "community number\n"
9827 "Do not send outside local AS (well-known community)\n"
9828 "Do not advertise to any peer (well-known community)\n"
9829 "Do not export to next AS (well-known community)\n"
9830 "community number\n"
9831 "Do not send outside local AS (well-known community)\n"
9832 "Do not advertise to any peer (well-known community)\n"
9833 "Do not export to next AS (well-known community)\n")
9834
9835DEFUN (show_bgp_community_exact,
9836 show_bgp_community_exact_cmd,
9837 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9838 SHOW_STR
9839 BGP_STR
9840 "Display routes matching the communities\n"
9841 "community number\n"
9842 "Do not send outside local AS (well-known community)\n"
9843 "Do not advertise to any peer (well-known community)\n"
9844 "Do not export to next AS (well-known community)\n"
9845 "Exact match of the communities")
9846{
9847 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9848}
9849
9850ALIAS (show_bgp_community_exact,
9851 show_bgp_ipv6_community_exact_cmd,
9852 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9853 SHOW_STR
9854 BGP_STR
9855 "Address family\n"
9856 "Display routes matching the communities\n"
9857 "community number\n"
9858 "Do not send outside local AS (well-known community)\n"
9859 "Do not advertise to any peer (well-known community)\n"
9860 "Do not export to next AS (well-known community)\n"
9861 "Exact match of the communities")
9862
9863ALIAS (show_bgp_community_exact,
9864 show_bgp_community2_exact_cmd,
9865 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9866 SHOW_STR
9867 BGP_STR
9868 "Display routes matching the communities\n"
9869 "community number\n"
9870 "Do not send outside local AS (well-known community)\n"
9871 "Do not advertise to any peer (well-known community)\n"
9872 "Do not export to next AS (well-known community)\n"
9873 "community number\n"
9874 "Do not send outside local AS (well-known community)\n"
9875 "Do not advertise to any peer (well-known community)\n"
9876 "Do not export to next AS (well-known community)\n"
9877 "Exact match of the communities")
9878
9879ALIAS (show_bgp_community_exact,
9880 show_bgp_ipv6_community2_exact_cmd,
9881 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9882 SHOW_STR
9883 BGP_STR
9884 "Address family\n"
9885 "Display routes matching the communities\n"
9886 "community number\n"
9887 "Do not send outside local AS (well-known community)\n"
9888 "Do not advertise to any peer (well-known community)\n"
9889 "Do not export to next AS (well-known community)\n"
9890 "community number\n"
9891 "Do not send outside local AS (well-known community)\n"
9892 "Do not advertise to any peer (well-known community)\n"
9893 "Do not export to next AS (well-known community)\n"
9894 "Exact match of the communities")
9895
9896ALIAS (show_bgp_community_exact,
9897 show_bgp_community3_exact_cmd,
9898 "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",
9899 SHOW_STR
9900 BGP_STR
9901 "Display routes matching the communities\n"
9902 "community number\n"
9903 "Do not send outside local AS (well-known community)\n"
9904 "Do not advertise to any peer (well-known community)\n"
9905 "Do not export to next AS (well-known community)\n"
9906 "community number\n"
9907 "Do not send outside local AS (well-known community)\n"
9908 "Do not advertise to any peer (well-known community)\n"
9909 "Do not export to next AS (well-known community)\n"
9910 "community number\n"
9911 "Do not send outside local AS (well-known community)\n"
9912 "Do not advertise to any peer (well-known community)\n"
9913 "Do not export to next AS (well-known community)\n"
9914 "Exact match of the communities")
9915
9916ALIAS (show_bgp_community_exact,
9917 show_bgp_ipv6_community3_exact_cmd,
9918 "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",
9919 SHOW_STR
9920 BGP_STR
9921 "Address family\n"
9922 "Display routes matching the communities\n"
9923 "community number\n"
9924 "Do not send outside local AS (well-known community)\n"
9925 "Do not advertise to any peer (well-known community)\n"
9926 "Do not export to next AS (well-known community)\n"
9927 "community number\n"
9928 "Do not send outside local AS (well-known community)\n"
9929 "Do not advertise to any peer (well-known community)\n"
9930 "Do not export to next AS (well-known community)\n"
9931 "community number\n"
9932 "Do not send outside local AS (well-known community)\n"
9933 "Do not advertise to any peer (well-known community)\n"
9934 "Do not export to next AS (well-known community)\n"
9935 "Exact match of the communities")
9936
9937ALIAS (show_bgp_community_exact,
9938 show_bgp_community4_exact_cmd,
9939 "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",
9940 SHOW_STR
9941 BGP_STR
9942 "Display routes matching the communities\n"
9943 "community number\n"
9944 "Do not send outside local AS (well-known community)\n"
9945 "Do not advertise to any peer (well-known community)\n"
9946 "Do not export to next AS (well-known community)\n"
9947 "community number\n"
9948 "Do not send outside local AS (well-known community)\n"
9949 "Do not advertise to any peer (well-known community)\n"
9950 "Do not export to next AS (well-known community)\n"
9951 "community number\n"
9952 "Do not send outside local AS (well-known community)\n"
9953 "Do not advertise to any peer (well-known community)\n"
9954 "Do not export to next AS (well-known community)\n"
9955 "community number\n"
9956 "Do not send outside local AS (well-known community)\n"
9957 "Do not advertise to any peer (well-known community)\n"
9958 "Do not export to next AS (well-known community)\n"
9959 "Exact match of the communities")
9960
9961ALIAS (show_bgp_community_exact,
9962 show_bgp_ipv6_community4_exact_cmd,
9963 "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",
9964 SHOW_STR
9965 BGP_STR
9966 "Address family\n"
9967 "Display routes matching the communities\n"
9968 "community number\n"
9969 "Do not send outside local AS (well-known community)\n"
9970 "Do not advertise to any peer (well-known community)\n"
9971 "Do not export to next AS (well-known community)\n"
9972 "community number\n"
9973 "Do not send outside local AS (well-known community)\n"
9974 "Do not advertise to any peer (well-known community)\n"
9975 "Do not export to next AS (well-known community)\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n"
9980 "community number\n"
9981 "Do not send outside local AS (well-known community)\n"
9982 "Do not advertise to any peer (well-known community)\n"
9983 "Do not export to next AS (well-known community)\n"
9984 "Exact match of the communities")
9985
9986/* old command */
9987DEFUN (show_ipv6_bgp_community_exact,
9988 show_ipv6_bgp_community_exact_cmd,
9989 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9990 SHOW_STR
9991 IPV6_STR
9992 BGP_STR
9993 "Display routes matching the communities\n"
9994 "community number\n"
9995 "Do not send outside local AS (well-known community)\n"
9996 "Do not advertise to any peer (well-known community)\n"
9997 "Do not export to next AS (well-known community)\n"
9998 "Exact match of the communities")
9999{
10000 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10001}
10002
10003/* old command */
10004ALIAS (show_ipv6_bgp_community_exact,
10005 show_ipv6_bgp_community2_exact_cmd,
10006 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10007 SHOW_STR
10008 IPV6_STR
10009 BGP_STR
10010 "Display routes matching the communities\n"
10011 "community number\n"
10012 "Do not send outside local AS (well-known community)\n"
10013 "Do not advertise to any peer (well-known community)\n"
10014 "Do not export to next AS (well-known community)\n"
10015 "community number\n"
10016 "Do not send outside local AS (well-known community)\n"
10017 "Do not advertise to any peer (well-known community)\n"
10018 "Do not export to next AS (well-known community)\n"
10019 "Exact match of the communities")
10020
10021/* old command */
10022ALIAS (show_ipv6_bgp_community_exact,
10023 show_ipv6_bgp_community3_exact_cmd,
10024 "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",
10025 SHOW_STR
10026 IPV6_STR
10027 BGP_STR
10028 "Display routes matching the communities\n"
10029 "community number\n"
10030 "Do not send outside local AS (well-known community)\n"
10031 "Do not advertise to any peer (well-known community)\n"
10032 "Do not export to next AS (well-known community)\n"
10033 "community number\n"
10034 "Do not send outside local AS (well-known community)\n"
10035 "Do not advertise to any peer (well-known community)\n"
10036 "Do not export to next AS (well-known community)\n"
10037 "community number\n"
10038 "Do not send outside local AS (well-known community)\n"
10039 "Do not advertise to any peer (well-known community)\n"
10040 "Do not export to next AS (well-known community)\n"
10041 "Exact match of the communities")
10042
10043/* old command */
10044ALIAS (show_ipv6_bgp_community_exact,
10045 show_ipv6_bgp_community4_exact_cmd,
10046 "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",
10047 SHOW_STR
10048 IPV6_STR
10049 BGP_STR
10050 "Display routes matching the communities\n"
10051 "community number\n"
10052 "Do not send outside local AS (well-known community)\n"
10053 "Do not advertise to any peer (well-known community)\n"
10054 "Do not export to next AS (well-known community)\n"
10055 "community number\n"
10056 "Do not send outside local AS (well-known community)\n"
10057 "Do not advertise to any peer (well-known community)\n"
10058 "Do not export to next AS (well-known community)\n"
10059 "community number\n"
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n"
10063 "community number\n"
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n"
10067 "Exact match of the communities")
10068
10069/* old command */
10070DEFUN (show_ipv6_mbgp_community,
10071 show_ipv6_mbgp_community_cmd,
10072 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10073 SHOW_STR
10074 IPV6_STR
10075 MBGP_STR
10076 "Display routes matching the communities\n"
10077 "community number\n"
10078 "Do not send outside local AS (well-known community)\n"
10079 "Do not advertise to any peer (well-known community)\n"
10080 "Do not export to next AS (well-known community)\n")
10081{
10082 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10083}
10084
10085/* old command */
10086ALIAS (show_ipv6_mbgp_community,
10087 show_ipv6_mbgp_community2_cmd,
10088 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10089 SHOW_STR
10090 IPV6_STR
10091 MBGP_STR
10092 "Display routes matching the communities\n"
10093 "community number\n"
10094 "Do not send outside local AS (well-known community)\n"
10095 "Do not advertise to any peer (well-known community)\n"
10096 "Do not export to next AS (well-known community)\n"
10097 "community number\n"
10098 "Do not send outside local AS (well-known community)\n"
10099 "Do not advertise to any peer (well-known community)\n"
10100 "Do not export to next AS (well-known community)\n")
10101
10102/* old command */
10103ALIAS (show_ipv6_mbgp_community,
10104 show_ipv6_mbgp_community3_cmd,
10105 "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)",
10106 SHOW_STR
10107 IPV6_STR
10108 MBGP_STR
10109 "Display routes matching the communities\n"
10110 "community number\n"
10111 "Do not send outside local AS (well-known community)\n"
10112 "Do not advertise to any peer (well-known community)\n"
10113 "Do not export to next AS (well-known community)\n"
10114 "community number\n"
10115 "Do not send outside local AS (well-known community)\n"
10116 "Do not advertise to any peer (well-known community)\n"
10117 "Do not export to next AS (well-known community)\n"
10118 "community number\n"
10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n")
10122
10123/* old command */
10124ALIAS (show_ipv6_mbgp_community,
10125 show_ipv6_mbgp_community4_cmd,
10126 "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)",
10127 SHOW_STR
10128 IPV6_STR
10129 MBGP_STR
10130 "Display routes matching the communities\n"
10131 "community number\n"
10132 "Do not send outside local AS (well-known community)\n"
10133 "Do not advertise to any peer (well-known community)\n"
10134 "Do not export to next AS (well-known community)\n"
10135 "community number\n"
10136 "Do not send outside local AS (well-known community)\n"
10137 "Do not advertise to any peer (well-known community)\n"
10138 "Do not export to next AS (well-known community)\n"
10139 "community number\n"
10140 "Do not send outside local AS (well-known community)\n"
10141 "Do not advertise to any peer (well-known community)\n"
10142 "Do not export to next AS (well-known community)\n"
10143 "community number\n"
10144 "Do not send outside local AS (well-known community)\n"
10145 "Do not advertise to any peer (well-known community)\n"
10146 "Do not export to next AS (well-known community)\n")
10147
10148/* old command */
10149DEFUN (show_ipv6_mbgp_community_exact,
10150 show_ipv6_mbgp_community_exact_cmd,
10151 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10152 SHOW_STR
10153 IPV6_STR
10154 MBGP_STR
10155 "Display routes matching the communities\n"
10156 "community number\n"
10157 "Do not send outside local AS (well-known community)\n"
10158 "Do not advertise to any peer (well-known community)\n"
10159 "Do not export to next AS (well-known community)\n"
10160 "Exact match of the communities")
10161{
10162 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10163}
10164
10165/* old command */
10166ALIAS (show_ipv6_mbgp_community_exact,
10167 show_ipv6_mbgp_community2_exact_cmd,
10168 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10169 SHOW_STR
10170 IPV6_STR
10171 MBGP_STR
10172 "Display routes matching the communities\n"
10173 "community number\n"
10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n"
10177 "community number\n"
10178 "Do not send outside local AS (well-known community)\n"
10179 "Do not advertise to any peer (well-known community)\n"
10180 "Do not export to next AS (well-known community)\n"
10181 "Exact match of the communities")
10182
10183/* old command */
10184ALIAS (show_ipv6_mbgp_community_exact,
10185 show_ipv6_mbgp_community3_exact_cmd,
10186 "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",
10187 SHOW_STR
10188 IPV6_STR
10189 MBGP_STR
10190 "Display routes matching the communities\n"
10191 "community number\n"
10192 "Do not send outside local AS (well-known community)\n"
10193 "Do not advertise to any peer (well-known community)\n"
10194 "Do not export to next AS (well-known community)\n"
10195 "community number\n"
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n"
10199 "community number\n"
10200 "Do not send outside local AS (well-known community)\n"
10201 "Do not advertise to any peer (well-known community)\n"
10202 "Do not export to next AS (well-known community)\n"
10203 "Exact match of the communities")
10204
10205/* old command */
10206ALIAS (show_ipv6_mbgp_community_exact,
10207 show_ipv6_mbgp_community4_exact_cmd,
10208 "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",
10209 SHOW_STR
10210 IPV6_STR
10211 MBGP_STR
10212 "Display routes matching the communities\n"
10213 "community number\n"
10214 "Do not send outside local AS (well-known community)\n"
10215 "Do not advertise to any peer (well-known community)\n"
10216 "Do not export to next AS (well-known community)\n"
10217 "community number\n"
10218 "Do not send outside local AS (well-known community)\n"
10219 "Do not advertise to any peer (well-known community)\n"
10220 "Do not export to next AS (well-known community)\n"
10221 "community number\n"
10222 "Do not send outside local AS (well-known community)\n"
10223 "Do not advertise to any peer (well-known community)\n"
10224 "Do not export to next AS (well-known community)\n"
10225 "community number\n"
10226 "Do not send outside local AS (well-known community)\n"
10227 "Do not advertise to any peer (well-known community)\n"
10228 "Do not export to next AS (well-known community)\n"
10229 "Exact match of the communities")
10230#endif /* HAVE_IPV6 */
10231
Lou Berger651b4022016-01-12 13:42:07 -050010232DEFUN (show_bgp_ipv4_community,
10233 show_bgp_ipv4_community_cmd,
10234 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010235 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010236 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010237 IP_STR
paul718e3742002-12-13 20:15:29 +000010238 "Display routes matching the communities\n"
10239 "community number\n"
10240 "Do not send outside local AS (well-known community)\n"
10241 "Do not advertise to any peer (well-known community)\n"
10242 "Do not export to next AS (well-known community)\n")
10243{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010244 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010245}
10246
Lou Berger651b4022016-01-12 13:42:07 -050010247ALIAS (show_bgp_ipv4_community,
10248 show_bgp_ipv4_community2_cmd,
10249 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010250 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010251 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010252 IP_STR
paul718e3742002-12-13 20:15:29 +000010253 "Display routes matching the communities\n"
10254 "community number\n"
10255 "Do not send outside local AS (well-known community)\n"
10256 "Do not advertise to any peer (well-known community)\n"
10257 "Do not export to next AS (well-known community)\n"
10258 "community number\n"
10259 "Do not send outside local AS (well-known community)\n"
10260 "Do not advertise to any peer (well-known community)\n"
10261 "Do not export to next AS (well-known community)\n")
10262
Lou Berger651b4022016-01-12 13:42:07 -050010263ALIAS (show_bgp_ipv4_community,
10264 show_bgp_ipv4_community3_cmd,
10265 "show bgp ipv4 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)",
paul718e3742002-12-13 20:15:29 +000010266 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010267 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010268 IP_STR
paul718e3742002-12-13 20:15:29 +000010269 "Display routes matching the communities\n"
10270 "community number\n"
10271 "Do not send outside local AS (well-known community)\n"
10272 "Do not advertise to any peer (well-known community)\n"
10273 "Do not export to next AS (well-known community)\n"
10274 "community number\n"
10275 "Do not send outside local AS (well-known community)\n"
10276 "Do not advertise to any peer (well-known community)\n"
10277 "Do not export to next AS (well-known community)\n"
10278 "community number\n"
10279 "Do not send outside local AS (well-known community)\n"
10280 "Do not advertise to any peer (well-known community)\n"
10281 "Do not export to next AS (well-known community)\n")
10282
Lou Berger651b4022016-01-12 13:42:07 -050010283ALIAS (show_bgp_ipv4_community,
10284 show_bgp_ipv4_community4_cmd,
10285 "show bgp ipv4 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)",
paul718e3742002-12-13 20:15:29 +000010286 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010287 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010288 IP_STR
paul718e3742002-12-13 20:15:29 +000010289 "Display routes matching the communities\n"
10290 "community number\n"
10291 "Do not send outside local AS (well-known community)\n"
10292 "Do not advertise to any peer (well-known community)\n"
10293 "Do not export to next AS (well-known community)\n"
10294 "community number\n"
10295 "Do not send outside local AS (well-known community)\n"
10296 "Do not advertise to any peer (well-known community)\n"
10297 "Do not export to next AS (well-known community)\n"
10298 "community number\n"
10299 "Do not send outside local AS (well-known community)\n"
10300 "Do not advertise to any peer (well-known community)\n"
10301 "Do not export to next AS (well-known community)\n"
10302 "community number\n"
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n")
10306
Lou Berger651b4022016-01-12 13:42:07 -050010307DEFUN (show_bgp_ipv4_safi_community,
10308 show_bgp_ipv4_safi_community_cmd,
10309 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010310 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010311 BGP_STR
10312 "Address family\n"
10313 "Address Family modifier\n"
10314 "Address Family modifier\n"
10315 "Display routes matching the communities\n"
10316 "community number\n"
10317 "Do not send outside local AS (well-known community)\n"
10318 "Do not advertise to any peer (well-known community)\n"
10319 "Do not export to next AS (well-known community)\n")
10320{
10321 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010322 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010323
Michael Lambert95cbbd22010-07-23 14:43:04 -040010324 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010325}
10326
Lou Berger651b4022016-01-12 13:42:07 -050010327ALIAS (show_bgp_ipv4_safi_community,
10328 show_bgp_ipv4_safi_community2_cmd,
10329 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010330 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010331 BGP_STR
10332 "Address family\n"
10333 "Address Family modifier\n"
10334 "Address Family modifier\n"
10335 "Display routes matching the communities\n"
10336 "community number\n"
10337 "Do not send outside local AS (well-known community)\n"
10338 "Do not advertise to any peer (well-known community)\n"
10339 "Do not export to next AS (well-known community)\n"
10340 "community number\n"
10341 "Do not send outside local AS (well-known community)\n"
10342 "Do not advertise to any peer (well-known community)\n"
10343 "Do not export to next AS (well-known community)\n")
10344
Lou Berger651b4022016-01-12 13:42:07 -050010345ALIAS (show_bgp_ipv4_safi_community,
10346 show_bgp_ipv4_safi_community3_cmd,
10347 "show 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)",
paul718e3742002-12-13 20:15:29 +000010348 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010349 BGP_STR
10350 "Address family\n"
10351 "Address Family modifier\n"
10352 "Address Family modifier\n"
10353 "Display routes matching the communities\n"
10354 "community number\n"
10355 "Do not send outside local AS (well-known community)\n"
10356 "Do not advertise to any peer (well-known community)\n"
10357 "Do not export to next AS (well-known community)\n"
10358 "community number\n"
10359 "Do not send outside local AS (well-known community)\n"
10360 "Do not advertise to any peer (well-known community)\n"
10361 "Do not export to next AS (well-known community)\n"
10362 "community number\n"
10363 "Do not send outside local AS (well-known community)\n"
10364 "Do not advertise to any peer (well-known community)\n"
10365 "Do not export to next AS (well-known community)\n")
10366
Lou Berger651b4022016-01-12 13:42:07 -050010367ALIAS (show_bgp_ipv4_safi_community,
10368 show_bgp_ipv4_safi_community4_cmd,
10369 "show 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)",
paul718e3742002-12-13 20:15:29 +000010370 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010371 BGP_STR
10372 "Address family\n"
10373 "Address Family modifier\n"
10374 "Address Family modifier\n"
10375 "Display routes matching the communities\n"
10376 "community number\n"
10377 "Do not send outside local AS (well-known community)\n"
10378 "Do not advertise to any peer (well-known community)\n"
10379 "Do not export to next AS (well-known community)\n"
10380 "community number\n"
10381 "Do not send outside local AS (well-known community)\n"
10382 "Do not advertise to any peer (well-known community)\n"
10383 "Do not export to next AS (well-known community)\n"
10384 "community number\n"
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n"
10388 "community number\n"
10389 "Do not send outside local AS (well-known community)\n"
10390 "Do not advertise to any peer (well-known community)\n"
10391 "Do not export to next AS (well-known community)\n")
10392
Michael Lambert95cbbd22010-07-23 14:43:04 -040010393DEFUN (show_bgp_view_afi_safi_community_all,
10394 show_bgp_view_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010395#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010396 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Lou Berger651b4022016-01-12 13:42:07 -050010397#else
10398 "show bgp view WORD ipv4 (unicast|multicast) community",
10399#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010400 SHOW_STR
10401 BGP_STR
10402 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010403 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010404 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010405#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010406 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010407#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010408 "Address Family modifier\n"
10409 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010410 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010411{
10412 int afi;
10413 int safi;
10414 struct bgp *bgp;
10415
10416 /* BGP structure lookup. */
10417 bgp = bgp_lookup_by_name (argv[0]);
10418 if (bgp == NULL)
10419 {
10420 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10421 return CMD_WARNING;
10422 }
10423
Lou Berger651b4022016-01-12 13:42:07 -050010424#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010425 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10426 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Lou Berger651b4022016-01-12 13:42:07 -050010427#else
10428 afi = AFI_IP;
10429 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10430#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010431 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10432}
10433
10434DEFUN (show_bgp_view_afi_safi_community,
10435 show_bgp_view_afi_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010436#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010437 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Lou Berger651b4022016-01-12 13:42:07 -050010438#else
10439 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
10440#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010441 SHOW_STR
10442 BGP_STR
10443 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010444 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010445 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010446#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010447 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010448#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010449 "Address family modifier\n"
10450 "Address family modifier\n"
10451 "Display routes matching the communities\n"
10452 "community number\n"
10453 "Do not send outside local AS (well-known community)\n"
10454 "Do not advertise to any peer (well-known community)\n"
10455 "Do not export to next AS (well-known community)\n")
10456{
10457 int afi;
10458 int safi;
10459
Lou Berger651b4022016-01-12 13:42:07 -050010460#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010461 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10462 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10463 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Lou Berger651b4022016-01-12 13:42:07 -050010464#else
10465 afi = AFI_IP;
10466 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10467 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
10468#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010469}
10470
10471ALIAS (show_bgp_view_afi_safi_community,
10472 show_bgp_view_afi_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010473#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010474 "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)",
Lou Berger651b4022016-01-12 13:42:07 -050010475#else
10476 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10477#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010478 SHOW_STR
10479 BGP_STR
10480 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010481 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010482 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010483#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010484 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010485#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010486 "Address family modifier\n"
10487 "Address family modifier\n"
10488 "Display routes matching the communities\n"
10489 "community number\n"
10490 "Do not send outside local AS (well-known community)\n"
10491 "Do not advertise to any peer (well-known community)\n"
10492 "Do not export to next AS (well-known community)\n"
10493 "community number\n"
10494 "Do not send outside local AS (well-known community)\n"
10495 "Do not advertise to any peer (well-known community)\n"
10496 "Do not export to next AS (well-known community)\n")
10497
10498ALIAS (show_bgp_view_afi_safi_community,
10499 show_bgp_view_afi_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010500#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010501 "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)",
Lou Berger651b4022016-01-12 13:42:07 -050010502#else
10503 "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)",
10504#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010505 SHOW_STR
10506 BGP_STR
10507 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010508 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010509 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010510#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010511 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010512#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010513 "Address family modifier\n"
10514 "Address family modifier\n"
10515 "Display routes matching the communities\n"
10516 "community number\n"
10517 "Do not send outside local AS (well-known community)\n"
10518 "Do not advertise to any peer (well-known community)\n"
10519 "Do not export to next AS (well-known community)\n"
10520 "community number\n"
10521 "Do not send outside local AS (well-known community)\n"
10522 "Do not advertise to any peer (well-known community)\n"
10523 "Do not export to next AS (well-known community)\n"
10524 "community number\n"
10525 "Do not send outside local AS (well-known community)\n"
10526 "Do not advertise to any peer (well-known community)\n"
10527 "Do not export to next AS (well-known community)\n")
10528
10529ALIAS (show_bgp_view_afi_safi_community,
10530 show_bgp_view_afi_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010531#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010532 "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)",
Lou Berger651b4022016-01-12 13:42:07 -050010533#else
10534 "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)",
10535#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010536 SHOW_STR
10537 BGP_STR
10538 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010539 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010540 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010541#ifdef HAVE_IPV6
Michael Lambert95cbbd22010-07-23 14:43:04 -040010542 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010543#endif
Michael Lambert95cbbd22010-07-23 14:43:04 -040010544 "Address family modifier\n"
10545 "Address family modifier\n"
10546 "Display routes matching the communities\n"
10547 "community number\n"
10548 "Do not send outside local AS (well-known community)\n"
10549 "Do not advertise to any peer (well-known community)\n"
10550 "Do not export to next AS (well-known community)\n"
10551 "community number\n"
10552 "Do not send outside local AS (well-known community)\n"
10553 "Do not advertise to any peer (well-known community)\n"
10554 "Do not export to next AS (well-known community)\n"
10555 "community number\n"
10556 "Do not send outside local AS (well-known community)\n"
10557 "Do not advertise to any peer (well-known community)\n"
10558 "Do not export to next AS (well-known community)\n"
10559 "community number\n"
10560 "Do not send outside local AS (well-known community)\n"
10561 "Do not advertise to any peer (well-known community)\n"
10562 "Do not export to next AS (well-known community)\n")
10563
Lou Berger651b4022016-01-12 13:42:07 -050010564DEFUN (show_bgp_ipv4_community_exact,
10565 show_bgp_ipv4_community_exact_cmd,
10566 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010567 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010568 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010569 IP_STR
paul718e3742002-12-13 20:15:29 +000010570 "Display routes matching the communities\n"
10571 "community number\n"
10572 "Do not send outside local AS (well-known community)\n"
10573 "Do not advertise to any peer (well-known community)\n"
10574 "Do not export to next AS (well-known community)\n"
10575 "Exact match of the communities")
10576{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010577 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010578}
10579
Lou Berger651b4022016-01-12 13:42:07 -050010580ALIAS (show_bgp_ipv4_community_exact,
10581 show_bgp_ipv4_community2_exact_cmd,
10582 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010583 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010584 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010585 IP_STR
paul718e3742002-12-13 20:15:29 +000010586 "Display routes matching the communities\n"
10587 "community number\n"
10588 "Do not send outside local AS (well-known community)\n"
10589 "Do not advertise to any peer (well-known community)\n"
10590 "Do not export to next AS (well-known community)\n"
10591 "community number\n"
10592 "Do not send outside local AS (well-known community)\n"
10593 "Do not advertise to any peer (well-known community)\n"
10594 "Do not export to next AS (well-known community)\n"
10595 "Exact match of the communities")
10596
Lou Berger651b4022016-01-12 13:42:07 -050010597ALIAS (show_bgp_ipv4_community_exact,
10598 show_bgp_ipv4_community3_exact_cmd,
10599 "show bgp ipv4 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",
paul718e3742002-12-13 20:15:29 +000010600 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010601 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010602 IP_STR
paul718e3742002-12-13 20:15:29 +000010603 "Display routes matching the communities\n"
10604 "community number\n"
10605 "Do not send outside local AS (well-known community)\n"
10606 "Do not advertise to any peer (well-known community)\n"
10607 "Do not export to next AS (well-known community)\n"
10608 "community number\n"
10609 "Do not send outside local AS (well-known community)\n"
10610 "Do not advertise to any peer (well-known community)\n"
10611 "Do not export to next AS (well-known community)\n"
10612 "community number\n"
10613 "Do not send outside local AS (well-known community)\n"
10614 "Do not advertise to any peer (well-known community)\n"
10615 "Do not export to next AS (well-known community)\n"
10616 "Exact match of the communities")
10617
Lou Berger651b4022016-01-12 13:42:07 -050010618ALIAS (show_bgp_ipv4_community_exact,
10619 show_bgp_ipv4_community4_exact_cmd,
10620 "show bgp ipv4 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",
paul718e3742002-12-13 20:15:29 +000010621 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010622 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010623 IP_STR
paul718e3742002-12-13 20:15:29 +000010624 "Display routes matching the communities\n"
10625 "community number\n"
10626 "Do not send outside local AS (well-known community)\n"
10627 "Do not advertise to any peer (well-known community)\n"
10628 "Do not export to next AS (well-known community)\n"
10629 "community number\n"
10630 "Do not send outside local AS (well-known community)\n"
10631 "Do not advertise to any peer (well-known community)\n"
10632 "Do not export to next AS (well-known community)\n"
10633 "community number\n"
10634 "Do not send outside local AS (well-known community)\n"
10635 "Do not advertise to any peer (well-known community)\n"
10636 "Do not export to next AS (well-known community)\n"
10637 "community number\n"
10638 "Do not send outside local AS (well-known community)\n"
10639 "Do not advertise to any peer (well-known community)\n"
10640 "Do not export to next AS (well-known community)\n"
10641 "Exact match of the communities")
10642
Lou Berger651b4022016-01-12 13:42:07 -050010643DEFUN (show_bgp_ipv4_safi_community4_exact,
10644 show_bgp_ipv4_safi_community_exact_cmd,
10645 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010646 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010647 BGP_STR
10648 "Address family\n"
10649 "Address Family modifier\n"
10650 "Address Family modifier\n"
10651 "Display routes matching the communities\n"
10652 "community number\n"
10653 "Do not send outside local AS (well-known community)\n"
10654 "Do not advertise to any peer (well-known community)\n"
10655 "Do not export to next AS (well-known community)\n"
10656 "Exact match of the communities")
10657{
10658 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010659 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010660
Michael Lambert95cbbd22010-07-23 14:43:04 -040010661 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010662}
10663
Lou Berger651b4022016-01-12 13:42:07 -050010664ALIAS (show_bgp_ipv4_safi_community4_exact,
10665 show_bgp_ipv4_safi_community2_exact_cmd,
10666 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010667 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010668 BGP_STR
10669 "Address family\n"
10670 "Address Family modifier\n"
10671 "Address Family modifier\n"
10672 "Display routes matching the communities\n"
10673 "community number\n"
10674 "Do not send outside local AS (well-known community)\n"
10675 "Do not advertise to any peer (well-known community)\n"
10676 "Do not export to next AS (well-known community)\n"
10677 "community number\n"
10678 "Do not send outside local AS (well-known community)\n"
10679 "Do not advertise to any peer (well-known community)\n"
10680 "Do not export to next AS (well-known community)\n"
10681 "Exact match of the communities")
10682
Lou Berger651b4022016-01-12 13:42:07 -050010683ALIAS (show_bgp_ipv4_safi_community4_exact,
10684 show_bgp_ipv4_safi_community3_exact_cmd,
10685 "show 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",
paul718e3742002-12-13 20:15:29 +000010686 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010687 BGP_STR
10688 "Address family\n"
10689 "Address Family modifier\n"
10690 "Address Family modifier\n"
10691 "Display routes matching the communities\n"
10692 "community number\n"
10693 "Do not send outside local AS (well-known community)\n"
10694 "Do not advertise to any peer (well-known community)\n"
10695 "Do not export to next AS (well-known community)\n"
10696 "community number\n"
10697 "Do not send outside local AS (well-known community)\n"
10698 "Do not advertise to any peer (well-known community)\n"
10699 "Do not export to next AS (well-known community)\n"
10700 "community number\n"
10701 "Do not send outside local AS (well-known community)\n"
10702 "Do not advertise to any peer (well-known community)\n"
10703 "Do not export to next AS (well-known community)\n"
10704 "Exact match of the communities")
10705
Lou Berger651b4022016-01-12 13:42:07 -050010706ALIAS (show_bgp_ipv4_safi_community4_exact,
10707 show_bgp_ipv4_safi_community4_exact_cmd,
10708 "show 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",
paul718e3742002-12-13 20:15:29 +000010709 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010710 BGP_STR
10711 "Address family\n"
10712 "Address Family modifier\n"
10713 "Address Family modifier\n"
10714 "Display routes matching the communities\n"
10715 "community number\n"
10716 "Do not send outside local AS (well-known community)\n"
10717 "Do not advertise to any peer (well-known community)\n"
10718 "Do not export to next AS (well-known community)\n"
10719 "community number\n"
10720 "Do not send outside local AS (well-known community)\n"
10721 "Do not advertise to any peer (well-known community)\n"
10722 "Do not export to next AS (well-known community)\n"
10723 "community number\n"
10724 "Do not send outside local AS (well-known community)\n"
10725 "Do not advertise to any peer (well-known community)\n"
10726 "Do not export to next AS (well-known community)\n"
10727 "community number\n"
10728 "Do not send outside local AS (well-known community)\n"
10729 "Do not advertise to any peer (well-known community)\n"
10730 "Do not export to next AS (well-known community)\n"
10731 "Exact match of the communities")
10732
Lou Berger651b4022016-01-12 13:42:07 -050010733
paul718e3742002-12-13 20:15:29 +000010734#ifdef HAVE_IPV6
Lou Bergerf9b6c392016-01-12 13:42:09 -050010735DEFUN (show_bgp_ipv6_safi_community,
10736 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010737 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010738 SHOW_STR
10739 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010740 "Address family\n"
10741 "Address family modifier\n"
10742 "Address family modifier\n"
10743 "Address family modifier\n"
10744 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010745 "Display routes matching the communities\n"
10746 "community number\n"
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n")
10750{
Lou Berger651b4022016-01-12 13:42:07 -050010751 safi_t safi;
10752
10753 if (bgp_parse_safi(argv[0], &safi)) {
10754 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10755 return CMD_WARNING;
10756 }
10757 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010758}
10759
Lou Bergerf9b6c392016-01-12 13:42:09 -050010760ALIAS (show_bgp_ipv6_safi_community,
10761 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010762 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010763 SHOW_STR
10764 BGP_STR
10765 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010766 "Address family modifier\n"
10767 "Address family modifier\n"
10768 "Address family modifier\n"
10769 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010770 "Display routes matching the communities\n"
10771 "community number\n"
10772 "Do not send outside local AS (well-known community)\n"
10773 "Do not advertise to any peer (well-known community)\n"
10774 "Do not export to next AS (well-known community)\n"
10775 "community number\n"
10776 "Do not send outside local AS (well-known community)\n"
10777 "Do not advertise to any peer (well-known community)\n"
10778 "Do not export to next AS (well-known community)\n")
10779
Lou Bergerf9b6c392016-01-12 13:42:09 -050010780ALIAS (show_bgp_ipv6_safi_community,
10781 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010782 "show bgp ipv6 (encap|multicast|unicast|vpn) 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)",
paul718e3742002-12-13 20:15:29 +000010783 SHOW_STR
10784 BGP_STR
10785 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010786 "Address family modifier\n"
10787 "Address family modifier\n"
10788 "Address family modifier\n"
10789 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010790 "Display routes matching the communities\n"
10791 "community number\n"
10792 "Do not send outside local AS (well-known community)\n"
10793 "Do not advertise to any peer (well-known community)\n"
10794 "Do not export to next AS (well-known community)\n"
10795 "community number\n"
10796 "Do not send outside local AS (well-known community)\n"
10797 "Do not advertise to any peer (well-known community)\n"
10798 "Do not export to next AS (well-known community)\n"
10799 "community number\n"
10800 "Do not send outside local AS (well-known community)\n"
10801 "Do not advertise to any peer (well-known community)\n"
10802 "Do not export to next AS (well-known community)\n")
10803
Lou Bergerf9b6c392016-01-12 13:42:09 -050010804ALIAS (show_bgp_ipv6_safi_community,
10805 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010806 "show bgp ipv6 (encap|multicast|unicast|vpn) 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)",
paul718e3742002-12-13 20:15:29 +000010807 SHOW_STR
10808 BGP_STR
10809 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010810 "Address family modifier\n"
10811 "Address family modifier\n"
10812 "Address family modifier\n"
10813 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010814 "Display routes matching the communities\n"
10815 "community number\n"
10816 "Do not send outside local AS (well-known community)\n"
10817 "Do not advertise to any peer (well-known community)\n"
10818 "Do not export to next AS (well-known community)\n"
10819 "community number\n"
10820 "Do not send outside local AS (well-known community)\n"
10821 "Do not advertise to any peer (well-known community)\n"
10822 "Do not export to next AS (well-known community)\n"
10823 "community number\n"
10824 "Do not send outside local AS (well-known community)\n"
10825 "Do not advertise to any peer (well-known community)\n"
10826 "Do not export to next AS (well-known community)\n"
10827 "community number\n"
10828 "Do not send outside local AS (well-known community)\n"
10829 "Do not advertise to any peer (well-known community)\n"
10830 "Do not export to next AS (well-known community)\n")
10831
paul718e3742002-12-13 20:15:29 +000010832
Lou Bergerf9b6c392016-01-12 13:42:09 -050010833DEFUN (show_bgp_ipv6_safi_community_exact,
10834 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010835 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010836 SHOW_STR
10837 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010838 "Address family\n"
10839 "Address family modifier\n"
10840 "Address family modifier\n"
10841 "Address family modifier\n"
10842 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010843 "Display routes matching the communities\n"
10844 "community number\n"
10845 "Do not send outside local AS (well-known community)\n"
10846 "Do not advertise to any peer (well-known community)\n"
10847 "Do not export to next AS (well-known community)\n"
10848 "Exact match of the communities")
10849{
Lou Berger651b4022016-01-12 13:42:07 -050010850 safi_t safi;
10851
10852 if (bgp_parse_safi(argv[0], &safi)) {
10853 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10854 return CMD_WARNING;
10855 }
10856 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010857}
10858
paul718e3742002-12-13 20:15:29 +000010859
10860ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010861 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010862 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010863 SHOW_STR
10864 BGP_STR
10865 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010866 "Address family modifier\n"
10867 "Address family modifier\n"
10868 "Address family modifier\n"
10869 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010870 "Display routes matching the communities\n"
10871 "community number\n"
10872 "Do not send outside local AS (well-known community)\n"
10873 "Do not advertise to any peer (well-known community)\n"
10874 "Do not export to next AS (well-known community)\n"
10875 "community number\n"
10876 "Do not send outside local AS (well-known community)\n"
10877 "Do not advertise to any peer (well-known community)\n"
10878 "Do not export to next AS (well-known community)\n"
10879 "Exact match of the communities")
10880
10881ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010882 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010883 "show bgp ipv6 (encap|multicast|unicast|vpn) 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",
paul718e3742002-12-13 20:15:29 +000010884 SHOW_STR
10885 BGP_STR
10886 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010887 "Address family modifier\n"
10888 "Address family modifier\n"
10889 "Address family modifier\n"
10890 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010891 "Display routes matching the communities\n"
10892 "community number\n"
10893 "Do not send outside local AS (well-known community)\n"
10894 "Do not advertise to any peer (well-known community)\n"
10895 "Do not export to next AS (well-known community)\n"
10896 "community number\n"
10897 "Do not send outside local AS (well-known community)\n"
10898 "Do not advertise to any peer (well-known community)\n"
10899 "Do not export to next AS (well-known community)\n"
10900 "community number\n"
10901 "Do not send outside local AS (well-known community)\n"
10902 "Do not advertise to any peer (well-known community)\n"
10903 "Do not export to next AS (well-known community)\n"
10904 "Exact match of the communities")
10905
10906ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010907 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010908 "show bgp ipv6 (encap|multicast|unicast|vpn) 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",
paul718e3742002-12-13 20:15:29 +000010909 SHOW_STR
10910 BGP_STR
10911 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010912 "Address family modifier\n"
10913 "Address family modifier\n"
10914 "Address family modifier\n"
10915 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010916 "Display routes matching the communities\n"
10917 "community number\n"
10918 "Do not send outside local AS (well-known community)\n"
10919 "Do not advertise to any peer (well-known community)\n"
10920 "Do not export to next AS (well-known community)\n"
10921 "community number\n"
10922 "Do not send outside local AS (well-known community)\n"
10923 "Do not advertise to any peer (well-known community)\n"
10924 "Do not export to next AS (well-known community)\n"
10925 "community number\n"
10926 "Do not send outside local AS (well-known community)\n"
10927 "Do not advertise to any peer (well-known community)\n"
10928 "Do not export to next AS (well-known community)\n"
10929 "community number\n"
10930 "Do not send outside local AS (well-known community)\n"
10931 "Do not advertise to any peer (well-known community)\n"
10932 "Do not export to next AS (well-known community)\n"
10933 "Exact match of the communities")
10934
paul718e3742002-12-13 20:15:29 +000010935#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010936
paul94f2b392005-06-28 12:44:16 +000010937static int
paulfd79ac92004-10-13 05:06:08 +000010938bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040010939 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000010940{
10941 struct community_list *list;
10942
hassofee6e4e2005-02-02 16:29:31 +000010943 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000010944 if (list == NULL)
10945 {
10946 vty_out (vty, "%% %s is not a valid community-list name%s", com,
10947 VTY_NEWLINE);
10948 return CMD_WARNING;
10949 }
10950
ajs5a646652004-11-05 01:25:55 +000010951 return bgp_show (vty, NULL, afi, safi,
10952 (exact ? bgp_show_type_community_list_exact :
10953 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000010954}
10955
Lou Bergerf9b6c392016-01-12 13:42:09 -050010956DEFUN (show_ip_bgp_community_list,
10957 show_ip_bgp_community_list_cmd,
10958 "show ip bgp community-list (<1-500>|WORD)",
10959 SHOW_STR
10960 IP_STR
10961 BGP_STR
10962 "Display routes matching the community-list\n"
10963 "community-list number\n"
10964 "community-list name\n")
10965{
10966 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
10967}
10968
10969DEFUN (show_ip_bgp_ipv4_community_list,
10970 show_ip_bgp_ipv4_community_list_cmd,
10971 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
10972 SHOW_STR
10973 IP_STR
10974 BGP_STR
10975 "Address family\n"
10976 "Address Family modifier\n"
10977 "Address Family modifier\n"
10978 "Display routes matching the community-list\n"
10979 "community-list number\n"
10980 "community-list name\n")
10981{
10982 if (strncmp (argv[0], "m", 1) == 0)
10983 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
10984
10985 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
10986}
10987
10988DEFUN (show_ip_bgp_community_list_exact,
10989 show_ip_bgp_community_list_exact_cmd,
10990 "show ip bgp community-list (<1-500>|WORD) exact-match",
10991 SHOW_STR
10992 IP_STR
10993 BGP_STR
10994 "Display routes matching the community-list\n"
10995 "community-list number\n"
10996 "community-list name\n"
10997 "Exact match of the communities\n")
10998{
10999 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11000}
11001
11002DEFUN (show_ip_bgp_ipv4_community_list_exact,
11003 show_ip_bgp_ipv4_community_list_exact_cmd,
11004 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11005 SHOW_STR
11006 IP_STR
11007 BGP_STR
11008 "Address family\n"
11009 "Address Family modifier\n"
11010 "Address Family modifier\n"
11011 "Display routes matching the community-list\n"
11012 "community-list number\n"
11013 "community-list name\n"
11014 "Exact match of the communities\n")
11015{
11016 if (strncmp (argv[0], "m", 1) == 0)
11017 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11018
11019 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11020}
11021
11022#ifdef HAVE_IPV6
11023DEFUN (show_bgp_community_list,
11024 show_bgp_community_list_cmd,
11025 "show bgp community-list (<1-500>|WORD)",
11026 SHOW_STR
11027 BGP_STR
11028 "Display routes matching the community-list\n"
11029 "community-list number\n"
11030 "community-list name\n")
11031{
11032 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11033}
11034
11035ALIAS (show_bgp_community_list,
11036 show_bgp_ipv6_community_list_cmd,
11037 "show bgp ipv6 community-list (<1-500>|WORD)",
11038 SHOW_STR
11039 BGP_STR
11040 "Address family\n"
11041 "Display routes matching the community-list\n"
11042 "community-list number\n"
11043 "community-list name\n")
11044
11045/* old command */
11046DEFUN (show_ipv6_bgp_community_list,
11047 show_ipv6_bgp_community_list_cmd,
11048 "show ipv6 bgp community-list WORD",
11049 SHOW_STR
11050 IPV6_STR
11051 BGP_STR
11052 "Display routes matching the community-list\n"
11053 "community-list name\n")
11054{
11055 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11056}
11057
11058/* old command */
11059DEFUN (show_ipv6_mbgp_community_list,
11060 show_ipv6_mbgp_community_list_cmd,
11061 "show ipv6 mbgp community-list WORD",
11062 SHOW_STR
11063 IPV6_STR
11064 MBGP_STR
11065 "Display routes matching the community-list\n"
11066 "community-list name\n")
11067{
11068 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11069}
11070
11071DEFUN (show_bgp_community_list_exact,
11072 show_bgp_community_list_exact_cmd,
11073 "show bgp community-list (<1-500>|WORD) exact-match",
11074 SHOW_STR
11075 BGP_STR
11076 "Display routes matching the community-list\n"
11077 "community-list number\n"
11078 "community-list name\n"
11079 "Exact match of the communities\n")
11080{
11081 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11082}
11083
11084ALIAS (show_bgp_community_list_exact,
11085 show_bgp_ipv6_community_list_exact_cmd,
11086 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11087 SHOW_STR
11088 BGP_STR
11089 "Address family\n"
11090 "Display routes matching the community-list\n"
11091 "community-list number\n"
11092 "community-list name\n"
11093 "Exact match of the communities\n")
11094
11095/* old command */
11096DEFUN (show_ipv6_bgp_community_list_exact,
11097 show_ipv6_bgp_community_list_exact_cmd,
11098 "show ipv6 bgp community-list WORD exact-match",
11099 SHOW_STR
11100 IPV6_STR
11101 BGP_STR
11102 "Display routes matching the community-list\n"
11103 "community-list name\n"
11104 "Exact match of the communities\n")
11105{
11106 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11107}
11108
11109/* old command */
11110DEFUN (show_ipv6_mbgp_community_list_exact,
11111 show_ipv6_mbgp_community_list_exact_cmd,
11112 "show ipv6 mbgp community-list WORD exact-match",
11113 SHOW_STR
11114 IPV6_STR
11115 MBGP_STR
11116 "Display routes matching the community-list\n"
11117 "community-list name\n"
11118 "Exact match of the communities\n")
11119{
11120 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11121}
11122#endif /* HAVE_IPV6 */
11123
Lou Berger651b4022016-01-12 13:42:07 -050011124DEFUN (show_bgp_ipv4_community_list,
11125 show_bgp_ipv4_community_list_cmd,
11126 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011127 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011128 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011129 IP_STR
paul718e3742002-12-13 20:15:29 +000011130 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011131 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011132 "community-list name\n")
11133{
11134 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11135}
11136
Lou Berger651b4022016-01-12 13:42:07 -050011137DEFUN (show_bgp_ipv4_safi_community_list,
11138 show_bgp_ipv4_safi_community_list_cmd,
11139 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011140 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011141 BGP_STR
11142 "Address family\n"
11143 "Address Family modifier\n"
11144 "Address Family modifier\n"
11145 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011146 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011147 "community-list name\n")
11148{
11149 if (strncmp (argv[0], "m", 1) == 0)
11150 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11151
11152 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11153}
11154
Lou Berger651b4022016-01-12 13:42:07 -050011155DEFUN (show_bgp_ipv4_community_list_exact,
11156 show_bgp_ipv4_community_list_exact_cmd,
11157 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011158 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011159 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011160 IP_STR
paul718e3742002-12-13 20:15:29 +000011161 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011162 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011163 "community-list name\n"
11164 "Exact match of the communities\n")
11165{
11166 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11167}
11168
Lou Berger651b4022016-01-12 13:42:07 -050011169DEFUN (show_bgp_ipv4_safi_community_list_exact,
11170 show_bgp_ipv4_safi_community_list_exact_cmd,
11171 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011172 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011173 BGP_STR
11174 "Address family\n"
11175 "Address Family modifier\n"
11176 "Address Family modifier\n"
11177 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011178 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011179 "community-list name\n"
11180 "Exact match of the communities\n")
11181{
11182 if (strncmp (argv[0], "m", 1) == 0)
11183 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11184
11185 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11186}
11187
11188#ifdef HAVE_IPV6
Lou Bergerf9b6c392016-01-12 13:42:09 -050011189DEFUN (show_bgp_ipv6_safi_community_list,
11190 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011191 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011192 SHOW_STR
11193 BGP_STR
11194 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011195 "Address family modifier\n"
11196 "Address family modifier\n"
11197 "Address family modifier\n"
11198 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011199 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011200 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011201 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011202{
Lou Berger651b4022016-01-12 13:42:07 -050011203 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011204
Lou Berger651b4022016-01-12 13:42:07 -050011205 if (bgp_parse_safi(argv[0], &safi)) {
11206 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11207 return CMD_WARNING;
11208 }
11209 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011210}
11211
Lou Bergerf9b6c392016-01-12 13:42:09 -050011212DEFUN (show_bgp_ipv6_safi_community_list_exact,
11213 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011214 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011215 SHOW_STR
11216 BGP_STR
11217 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011218 "Address family modifier\n"
11219 "Address family modifier\n"
11220 "Address family modifier\n"
11221 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011222 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011223 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011224 "community-list name\n"
11225 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011226{
Lou Berger651b4022016-01-12 13:42:07 -050011227 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011228
Lou Berger651b4022016-01-12 13:42:07 -050011229 if (bgp_parse_safi(argv[0], &safi)) {
11230 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11231 return CMD_WARNING;
11232 }
11233 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011234}
11235#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011236
paul94f2b392005-06-28 12:44:16 +000011237static int
paulfd79ac92004-10-13 05:06:08 +000011238bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011239 safi_t safi, enum bgp_show_type type)
11240{
11241 int ret;
11242 struct prefix *p;
11243
11244 p = prefix_new();
11245
11246 ret = str2prefix (prefix, p);
11247 if (! ret)
11248 {
11249 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11250 return CMD_WARNING;
11251 }
11252
ajs5a646652004-11-05 01:25:55 +000011253 ret = bgp_show (vty, NULL, afi, safi, type, p);
11254 prefix_free(p);
11255 return ret;
paul718e3742002-12-13 20:15:29 +000011256}
11257
Lou Bergerf9b6c392016-01-12 13:42:09 -050011258DEFUN (show_ip_bgp_prefix_longer,
11259 show_ip_bgp_prefix_longer_cmd,
11260 "show ip bgp A.B.C.D/M longer-prefixes",
11261 SHOW_STR
11262 IP_STR
11263 BGP_STR
11264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11265 "Display route and more specific routes\n")
11266{
11267 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11268 bgp_show_type_prefix_longer);
11269}
11270
11271DEFUN (show_ip_bgp_flap_prefix_longer,
11272 show_ip_bgp_flap_prefix_longer_cmd,
11273 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11274 SHOW_STR
11275 IP_STR
11276 BGP_STR
11277 "Display flap statistics of routes\n"
11278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11279 "Display route and more specific routes\n")
11280{
11281 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11282 bgp_show_type_flap_prefix_longer);
11283}
11284
11285ALIAS (show_ip_bgp_flap_prefix_longer,
11286 show_ip_bgp_damp_flap_prefix_longer_cmd,
11287 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11288 SHOW_STR
11289 IP_STR
11290 BGP_STR
11291 "Display detailed information about dampening\n"
11292 "Display flap statistics of routes\n"
11293 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11294 "Display route and more specific routes\n")
11295
11296DEFUN (show_ip_bgp_ipv4_prefix_longer,
11297 show_ip_bgp_ipv4_prefix_longer_cmd,
11298 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11299 SHOW_STR
11300 IP_STR
11301 BGP_STR
11302 "Address family\n"
11303 "Address Family modifier\n"
11304 "Address Family modifier\n"
11305 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11306 "Display route and more specific routes\n")
11307{
11308 if (strncmp (argv[0], "m", 1) == 0)
11309 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11310 bgp_show_type_prefix_longer);
11311
11312 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11313 bgp_show_type_prefix_longer);
11314}
11315
11316DEFUN (show_ip_bgp_flap_address,
11317 show_ip_bgp_flap_address_cmd,
11318 "show ip bgp flap-statistics A.B.C.D",
11319 SHOW_STR
11320 IP_STR
11321 BGP_STR
11322 "Display flap statistics of routes\n"
11323 "Network in the BGP routing table to display\n")
11324{
11325 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11326 bgp_show_type_flap_address);
11327}
11328
11329ALIAS (show_ip_bgp_flap_address,
11330 show_ip_bgp_damp_flap_address_cmd,
11331 "show ip bgp dampening flap-statistics A.B.C.D",
11332 SHOW_STR
11333 IP_STR
11334 BGP_STR
11335 "Display detailed information about dampening\n"
11336 "Display flap statistics of routes\n"
11337 "Network in the BGP routing table to display\n")
11338
11339DEFUN (show_ip_bgp_flap_prefix,
11340 show_ip_bgp_flap_prefix_cmd,
11341 "show ip bgp flap-statistics A.B.C.D/M",
11342 SHOW_STR
11343 IP_STR
11344 BGP_STR
11345 "Display flap statistics of routes\n"
11346 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11347{
11348 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11349 bgp_show_type_flap_prefix);
11350}
11351
11352ALIAS (show_ip_bgp_flap_prefix,
11353 show_ip_bgp_damp_flap_prefix_cmd,
11354 "show ip bgp dampening flap-statistics A.B.C.D/M",
11355 SHOW_STR
11356 IP_STR
11357 BGP_STR
11358 "Display detailed information about dampening\n"
11359 "Display flap statistics of routes\n"
11360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11361
11362#ifdef HAVE_IPV6
11363DEFUN (show_bgp_prefix_longer,
11364 show_bgp_prefix_longer_cmd,
11365 "show bgp X:X::X:X/M longer-prefixes",
11366 SHOW_STR
11367 BGP_STR
11368 "IPv6 prefix <network>/<length>\n"
11369 "Display route and more specific routes\n")
11370{
11371 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11372 bgp_show_type_prefix_longer);
11373}
11374
11375/* old command */
11376DEFUN (show_ipv6_bgp_prefix_longer,
11377 show_ipv6_bgp_prefix_longer_cmd,
11378 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11379 SHOW_STR
11380 IPV6_STR
11381 BGP_STR
11382 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11383 "Display route and more specific routes\n")
11384{
11385 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11386 bgp_show_type_prefix_longer);
11387}
11388
11389/* old command */
11390DEFUN (show_ipv6_mbgp_prefix_longer,
11391 show_ipv6_mbgp_prefix_longer_cmd,
11392 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11393 SHOW_STR
11394 IPV6_STR
11395 MBGP_STR
11396 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11397 "Display route and more specific routes\n")
11398{
11399 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11400 bgp_show_type_prefix_longer);
11401}
11402#endif /* HAVE_IPV6 */
11403
Lou Berger651b4022016-01-12 13:42:07 -050011404DEFUN (show_bgp_ipv4_prefix_longer,
11405 show_bgp_ipv4_prefix_longer_cmd,
11406 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011407 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011408 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011409 IP_STR
paul718e3742002-12-13 20:15:29 +000011410 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11411 "Display route and more specific routes\n")
11412{
11413 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11414 bgp_show_type_prefix_longer);
11415}
11416
Lou Berger651b4022016-01-12 13:42:07 -050011417DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11418 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11419 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011420 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011421 BGP_STR
11422 "Address family\n"
11423 "Address Family modifier\n"
11424 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011425 "Address Family modifier\n"
11426 "Address Family modifier\n"
11427 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011428 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11429 "Display route and more specific routes\n")
11430{
Lou Berger651b4022016-01-12 13:42:07 -050011431 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011432
Lou Berger651b4022016-01-12 13:42:07 -050011433 if (bgp_parse_safi(argv[0], &safi)) {
11434 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11435 return CMD_WARNING;
11436 }
11437 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11438 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011439}
11440
Lou Berger651b4022016-01-12 13:42:07 -050011441ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11442 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11443 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011444 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011445 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011446 "Address family\n"
11447 "Address Family modifier\n"
11448 "Address Family modifier\n"
11449 "Address Family modifier\n"
11450 "Address Family modifier\n"
11451 "Display detailed information about dampening\n"
11452 "Display flap statistics of routes\n"
11453 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11454 "Display route and more specific routes\n")
11455
11456#ifdef HAVE_IPV6
11457DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11458 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11459 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11460 SHOW_STR
11461 BGP_STR
11462 "Address family\n"
11463 "Address Family modifier\n"
11464 "Address Family modifier\n"
11465 "Address Family modifier\n"
11466 "Address Family modifier\n"
11467 "Display flap statistics of routes\n"
11468 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11469 "Display route and more specific routes\n")
11470{
11471 safi_t safi;
11472
11473 if (bgp_parse_safi(argv[0], &safi)) {
11474 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11475 return CMD_WARNING;
11476 }
11477 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11478 bgp_show_type_flap_prefix_longer);
11479}
11480ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11481 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11482 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11483 SHOW_STR
11484 BGP_STR
11485 "Address family\n"
11486 "Address Family modifier\n"
11487 "Address Family modifier\n"
11488 "Address Family modifier\n"
11489 "Address Family modifier\n"
11490 "Display detailed information about dampening\n"
11491 "Display flap statistics of routes\n"
11492 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11493 "Display route and more specific routes\n")
11494#endif
11495
11496DEFUN (show_bgp_ipv4_safi_prefix_longer,
11497 show_bgp_ipv4_safi_prefix_longer_cmd,
11498 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11499 SHOW_STR
11500 BGP_STR
11501 "Address family\n"
11502 "Address Family modifier\n"
11503 "Address Family modifier\n"
11504 "Address Family modifier\n"
11505 "Address Family modifier\n"
11506 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11507 "Display route and more specific routes\n")
11508{
11509 safi_t safi;
11510
11511 if (bgp_parse_safi(argv[0], &safi)) {
11512 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11513 return CMD_WARNING;
11514 }
11515
11516 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11517 bgp_show_type_prefix_longer);
11518}
11519
11520#ifdef HAVE_IPV6
11521DEFUN (show_bgp_ipv6_safi_prefix_longer,
11522 show_bgp_ipv6_safi_prefix_longer_cmd,
11523 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11524 SHOW_STR
11525 BGP_STR
11526 "Address family\n"
11527 "Address Family modifier\n"
11528 "Address Family modifier\n"
11529 "Address Family modifier\n"
11530 "Address Family modifier\n"
11531 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11532 "Display route and more specific routes\n")
11533{
11534 safi_t safi;
11535
11536 if (bgp_parse_safi(argv[0], &safi)) {
11537 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11538 return CMD_WARNING;
11539 }
11540
11541 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11542 bgp_show_type_prefix_longer);
11543}
11544#endif
11545
11546DEFUN (show_bgp_ipv4_safi_flap_address,
11547 show_bgp_ipv4_safi_flap_address_cmd,
11548 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11549 SHOW_STR
11550 BGP_STR
11551 "Address family\n"
11552 "Address Family modifier\n"
11553 "Address Family modifier\n"
11554 "Address Family modifier\n"
11555 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011556 "Display flap statistics of routes\n"
11557 "Network in the BGP routing table to display\n")
11558{
Lou Berger651b4022016-01-12 13:42:07 -050011559 safi_t safi;
11560
11561 if (bgp_parse_safi(argv[0], &safi)) {
11562 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11563 return CMD_WARNING;
11564 }
11565 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011566 bgp_show_type_flap_address);
11567}
Lou Berger651b4022016-01-12 13:42:07 -050011568ALIAS (show_bgp_ipv4_safi_flap_address,
11569 show_bgp_ipv4_safi_damp_flap_address_cmd,
11570 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011571 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011572 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011573 "Address family\n"
11574 "Address Family modifier\n"
11575 "Address Family modifier\n"
11576 "Address Family modifier\n"
11577 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011578 "Display detailed information about dampening\n"
11579 "Display flap statistics of routes\n"
11580 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011581#ifdef HAVE_IPV6
11582DEFUN (show_bgp_ipv6_flap_address,
11583 show_bgp_ipv6_flap_address_cmd,
11584 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011585 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011586 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011587 "Address family\n"
11588 "Address Family modifier\n"
11589 "Address Family modifier\n"
11590 "Address Family modifier\n"
11591 "Address Family modifier\n"
11592 "Display flap statistics of routes\n"
11593 "Network in the BGP routing table to display\n")
11594{
11595 safi_t safi;
11596
11597 if (bgp_parse_safi(argv[0], &safi)) {
11598 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11599 return CMD_WARNING;
11600 }
11601 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11602 bgp_show_type_flap_address);
11603}
11604ALIAS (show_bgp_ipv6_flap_address,
11605 show_bgp_ipv6_damp_flap_address_cmd,
11606 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11607 SHOW_STR
11608 BGP_STR
11609 "Address family\n"
11610 "Address Family modifier\n"
11611 "Address Family modifier\n"
11612 "Address Family modifier\n"
11613 "Address Family modifier\n"
11614 "Display detailed information about dampening\n"
11615 "Display flap statistics of routes\n"
11616 "Network in the BGP routing table to display\n")
11617#endif
11618
11619DEFUN (show_bgp_ipv4_safi_flap_prefix,
11620 show_bgp_ipv4_safi_flap_prefix_cmd,
11621 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11622 SHOW_STR
11623 BGP_STR
11624 "Address family\n"
11625 "Address Family modifier\n"
11626 "Address Family modifier\n"
11627 "Address Family modifier\n"
11628 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011629 "Display flap statistics of routes\n"
11630 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11631{
Lou Berger651b4022016-01-12 13:42:07 -050011632 safi_t safi;
11633
11634 if (bgp_parse_safi(argv[0], &safi)) {
11635 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11636 return CMD_WARNING;
11637 }
11638 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011639 bgp_show_type_flap_prefix);
11640}
Balaji3921cc52015-05-16 23:12:17 +053011641
Lou Berger651b4022016-01-12 13:42:07 -050011642ALIAS (show_bgp_ipv4_safi_flap_prefix,
11643 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11644 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011645 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011646 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011647 "Address family\n"
11648 "Address Family modifier\n"
11649 "Address Family modifier\n"
11650 "Address Family modifier\n"
11651 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011652 "Display detailed information about dampening\n"
11653 "Display flap statistics of routes\n"
11654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11655
paul718e3742002-12-13 20:15:29 +000011656#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -050011657DEFUN (show_bgp_ipv6_safi_flap_prefix,
11658 show_bgp_ipv6_safi_flap_prefix_cmd,
11659 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011660 SHOW_STR
11661 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011662 "Address family\n"
11663 "Address Family modifier\n"
11664 "Address Family modifier\n"
11665 "Address Family modifier\n"
11666 "Address Family modifier\n"
11667 "Display flap statistics of routes\n"
11668 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011669{
Lou Berger651b4022016-01-12 13:42:07 -050011670 safi_t safi;
11671
11672 if (bgp_parse_safi(argv[0], &safi)) {
11673 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11674 return CMD_WARNING;
11675 }
11676 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11677 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011678}
11679
Lou Berger651b4022016-01-12 13:42:07 -050011680ALIAS (show_bgp_ipv6_safi_flap_prefix,
11681 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11682 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11683 SHOW_STR
11684 BGP_STR
11685 "Address family\n"
11686 "Address Family modifier\n"
11687 "Address Family modifier\n"
11688 "Address Family modifier\n"
11689 "Address Family modifier\n"
11690 "Display detailed information about dampening\n"
11691 "Display flap statistics of routes\n"
11692 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11693
11694DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011695 show_bgp_ipv6_prefix_longer_cmd,
11696 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11697 SHOW_STR
11698 BGP_STR
11699 "Address family\n"
11700 "IPv6 prefix <network>/<length>\n"
11701 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011702{
11703 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11704 bgp_show_type_prefix_longer);
11705}
11706
paul718e3742002-12-13 20:15:29 +000011707#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +000011708
paul94f2b392005-06-28 12:44:16 +000011709static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011710peer_lookup_in_view (struct vty *vty, const char *view_name,
11711 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011712{
11713 int ret;
11714 struct bgp *bgp;
11715 struct peer *peer;
11716 union sockunion su;
11717
11718 /* BGP structure lookup. */
11719 if (view_name)
11720 {
11721 bgp = bgp_lookup_by_name (view_name);
11722 if (! bgp)
11723 {
11724 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11725 return NULL;
11726 }
11727 }
paul5228ad22004-06-04 17:58:18 +000011728 else
paulbb46e942003-10-24 19:02:03 +000011729 {
11730 bgp = bgp_get_default ();
11731 if (! bgp)
11732 {
11733 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11734 return NULL;
11735 }
11736 }
11737
11738 /* Get peer sockunion. */
11739 ret = str2sockunion (ip_str, &su);
11740 if (ret < 0)
11741 {
11742 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11743 return NULL;
11744 }
11745
11746 /* Peer structure lookup. */
11747 peer = peer_lookup (bgp, &su);
11748 if (! peer)
11749 {
11750 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11751 return NULL;
11752 }
11753
11754 return peer;
11755}
David Lamparter6b0655a2014-06-04 06:53:35 +020011756
Paul Jakma2815e612006-09-14 02:56:07 +000011757enum bgp_stats
11758{
11759 BGP_STATS_MAXBITLEN = 0,
11760 BGP_STATS_RIB,
11761 BGP_STATS_PREFIXES,
11762 BGP_STATS_TOTPLEN,
11763 BGP_STATS_UNAGGREGATEABLE,
11764 BGP_STATS_MAX_AGGREGATEABLE,
11765 BGP_STATS_AGGREGATES,
11766 BGP_STATS_SPACE,
11767 BGP_STATS_ASPATH_COUNT,
11768 BGP_STATS_ASPATH_MAXHOPS,
11769 BGP_STATS_ASPATH_TOTHOPS,
11770 BGP_STATS_ASPATH_MAXSIZE,
11771 BGP_STATS_ASPATH_TOTSIZE,
11772 BGP_STATS_ASN_HIGHEST,
11773 BGP_STATS_MAX,
11774};
paulbb46e942003-10-24 19:02:03 +000011775
Paul Jakma2815e612006-09-14 02:56:07 +000011776static const char *table_stats_strs[] =
11777{
11778 [BGP_STATS_PREFIXES] = "Total Prefixes",
11779 [BGP_STATS_TOTPLEN] = "Average prefix length",
11780 [BGP_STATS_RIB] = "Total Advertisements",
11781 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11782 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11783 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11784 [BGP_STATS_SPACE] = "Address space advertised",
11785 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11786 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11787 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11788 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11789 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11790 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11791 [BGP_STATS_MAX] = NULL,
11792};
11793
11794struct bgp_table_stats
11795{
11796 struct bgp_table *table;
11797 unsigned long long counts[BGP_STATS_MAX];
11798};
11799
11800#if 0
11801#define TALLY_SIGFIG 100000
11802static unsigned long
11803ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11804{
11805 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11806 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11807 unsigned long ret = newtot / count;
11808
11809 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11810 return ret + 1;
11811 else
11812 return ret;
11813}
11814#endif
11815
11816static int
11817bgp_table_stats_walker (struct thread *t)
11818{
11819 struct bgp_node *rn;
11820 struct bgp_node *top;
11821 struct bgp_table_stats *ts = THREAD_ARG (t);
11822 unsigned int space = 0;
11823
Paul Jakma53d9f672006-10-15 23:41:16 +000011824 if (!(top = bgp_table_top (ts->table)))
11825 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011826
11827 switch (top->p.family)
11828 {
11829 case AF_INET:
11830 space = IPV4_MAX_BITLEN;
11831 break;
11832 case AF_INET6:
11833 space = IPV6_MAX_BITLEN;
11834 break;
11835 }
11836
11837 ts->counts[BGP_STATS_MAXBITLEN] = space;
11838
11839 for (rn = top; rn; rn = bgp_route_next (rn))
11840 {
11841 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011842 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011843 unsigned int rinum = 0;
11844
11845 if (rn == top)
11846 continue;
11847
11848 if (!rn->info)
11849 continue;
11850
11851 ts->counts[BGP_STATS_PREFIXES]++;
11852 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11853
11854#if 0
11855 ts->counts[BGP_STATS_AVGPLEN]
11856 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11857 ts->counts[BGP_STATS_AVGPLEN],
11858 rn->p.prefixlen);
11859#endif
11860
11861 /* check if the prefix is included by any other announcements */
11862 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011863 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011864
11865 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011866 {
11867 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11868 /* announced address space */
11869 if (space)
11870 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11871 }
Paul Jakma2815e612006-09-14 02:56:07 +000011872 else if (prn->info)
11873 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11874
Paul Jakma2815e612006-09-14 02:56:07 +000011875 for (ri = rn->info; ri; ri = ri->next)
11876 {
11877 rinum++;
11878 ts->counts[BGP_STATS_RIB]++;
11879
11880 if (ri->attr &&
11881 (CHECK_FLAG (ri->attr->flag,
11882 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11883 ts->counts[BGP_STATS_AGGREGATES]++;
11884
11885 /* as-path stats */
11886 if (ri->attr && ri->attr->aspath)
11887 {
11888 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11889 unsigned int size = aspath_size (ri->attr->aspath);
11890 as_t highest = aspath_highest (ri->attr->aspath);
11891
11892 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11893
11894 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11895 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11896
11897 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11898 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11899
11900 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11901 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11902#if 0
11903 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11904 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11905 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11906 hops);
11907 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11908 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11909 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11910 size);
11911#endif
11912 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11913 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11914 }
11915 }
11916 }
11917 return 0;
11918}
11919
11920static int
11921bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11922{
11923 struct bgp_table_stats ts;
11924 unsigned int i;
11925
11926 if (!bgp->rib[afi][safi])
11927 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050011928 vty_out (vty, "%% No RIB exists for the AFI/SAFI%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011929 return CMD_WARNING;
11930 }
11931
11932 memset (&ts, 0, sizeof (ts));
11933 ts.table = bgp->rib[afi][safi];
11934 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
11935
11936 vty_out (vty, "BGP %s RIB statistics%s%s",
11937 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
11938
11939 for (i = 0; i < BGP_STATS_MAX; i++)
11940 {
11941 if (!table_stats_strs[i])
11942 continue;
11943
11944 switch (i)
11945 {
11946#if 0
11947 case BGP_STATS_ASPATH_AVGHOPS:
11948 case BGP_STATS_ASPATH_AVGSIZE:
11949 case BGP_STATS_AVGPLEN:
11950 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11951 vty_out (vty, "%12.2f",
11952 (float)ts.counts[i] / (float)TALLY_SIGFIG);
11953 break;
11954#endif
11955 case BGP_STATS_ASPATH_TOTHOPS:
11956 case BGP_STATS_ASPATH_TOTSIZE:
11957 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11958 vty_out (vty, "%12.2f",
11959 ts.counts[i] ?
11960 (float)ts.counts[i] /
11961 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
11962 : 0);
11963 break;
11964 case BGP_STATS_TOTPLEN:
11965 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11966 vty_out (vty, "%12.2f",
11967 ts.counts[i] ?
11968 (float)ts.counts[i] /
11969 (float)ts.counts[BGP_STATS_PREFIXES]
11970 : 0);
11971 break;
11972 case BGP_STATS_SPACE:
11973 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11974 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
11975 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
11976 break;
Paul Jakma30a22312008-08-15 14:05:22 +010011977 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000011978 vty_out (vty, "%12.2f%s",
11979 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000011980 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000011981 VTY_NEWLINE);
11982 vty_out (vty, "%30s: ", "/8 equivalent ");
11983 vty_out (vty, "%12.2f%s",
11984 (float)ts.counts[BGP_STATS_SPACE] /
11985 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
11986 VTY_NEWLINE);
11987 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
11988 break;
11989 vty_out (vty, "%30s: ", "/24 equivalent ");
11990 vty_out (vty, "%12.2f",
11991 (float)ts.counts[BGP_STATS_SPACE] /
11992 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
11993 break;
11994 default:
11995 vty_out (vty, "%-30s: ", table_stats_strs[i]);
11996 vty_out (vty, "%12llu", ts.counts[i]);
11997 }
11998
11999 vty_out (vty, "%s", VTY_NEWLINE);
12000 }
12001 return CMD_SUCCESS;
12002}
12003
12004static int
12005bgp_table_stats_vty (struct vty *vty, const char *name,
12006 const char *afi_str, const char *safi_str)
12007{
12008 struct bgp *bgp;
12009 afi_t afi;
12010 safi_t safi;
12011
12012 if (name)
12013 bgp = bgp_lookup_by_name (name);
12014 else
12015 bgp = bgp_get_default ();
12016
12017 if (!bgp)
12018 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012019 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012020 return CMD_WARNING;
12021 }
12022 if (strncmp (afi_str, "ipv", 3) == 0)
12023 {
12024 if (strncmp (afi_str, "ipv4", 4) == 0)
12025 afi = AFI_IP;
12026 else if (strncmp (afi_str, "ipv6", 4) == 0)
12027 afi = AFI_IP6;
12028 else
12029 {
12030 vty_out (vty, "%% Invalid address family %s%s",
12031 afi_str, VTY_NEWLINE);
12032 return CMD_WARNING;
12033 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012034 switch (safi_str[0]) {
12035 case 'm':
12036 safi = SAFI_MULTICAST;
12037 break;
12038 case 'u':
12039 safi = SAFI_UNICAST;
12040 break;
12041 case 'v':
12042 safi = SAFI_MPLS_LABELED_VPN;
12043 break;
12044 case 'e':
12045 safi = SAFI_ENCAP;
12046 break;
12047 default:
12048 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012049 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012050 return CMD_WARNING;
12051 }
Paul Jakma2815e612006-09-14 02:56:07 +000012052 }
12053 else
12054 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012055 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012056 afi_str, VTY_NEWLINE);
12057 return CMD_WARNING;
12058 }
12059
Paul Jakma2815e612006-09-14 02:56:07 +000012060 return bgp_table_stats (vty, bgp, afi, safi);
12061}
12062
12063DEFUN (show_bgp_statistics,
12064 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012065 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012066 SHOW_STR
12067 BGP_STR
12068 "Address family\n"
12069 "Address family\n"
12070 "Address Family modifier\n"
12071 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012072 "Address Family modifier\n"
12073 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012074 "BGP RIB advertisement statistics\n")
12075{
12076 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12077}
12078
Lou Bergerf9b6c392016-01-12 13:42:09 -050012079ALIAS (show_bgp_statistics,
12080 show_bgp_statistics_vpnv4_cmd,
12081 "show bgp (ipv4) (vpnv4) statistics",
12082 SHOW_STR
12083 BGP_STR
12084 "Address family\n"
12085 "Address Family modifier\n"
12086 "BGP RIB advertisement statistics\n")
12087
Paul Jakma2815e612006-09-14 02:56:07 +000012088DEFUN (show_bgp_statistics_view,
12089 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012090 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012091 SHOW_STR
12092 BGP_STR
12093 "BGP view\n"
12094 "Address family\n"
12095 "Address family\n"
12096 "Address Family modifier\n"
12097 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012098 "Address Family modifier\n"
12099 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012100 "BGP RIB advertisement statistics\n")
12101{
12102 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12103}
12104
12105ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012106 show_bgp_statistics_view_vpnv4_cmd,
12107 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012108 SHOW_STR
12109 BGP_STR
12110 "BGP view\n"
12111 "Address family\n"
12112 "Address Family modifier\n"
12113 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012114
Paul Jakmaff7924f2006-09-04 01:10:36 +000012115enum bgp_pcounts
12116{
12117 PCOUNT_ADJ_IN = 0,
12118 PCOUNT_DAMPED,
12119 PCOUNT_REMOVED,
12120 PCOUNT_HISTORY,
12121 PCOUNT_STALE,
12122 PCOUNT_VALID,
12123 PCOUNT_ALL,
12124 PCOUNT_COUNTED,
12125 PCOUNT_PFCNT, /* the figure we display to users */
12126 PCOUNT_MAX,
12127};
12128
12129static const char *pcount_strs[] =
12130{
12131 [PCOUNT_ADJ_IN] = "Adj-in",
12132 [PCOUNT_DAMPED] = "Damped",
12133 [PCOUNT_REMOVED] = "Removed",
12134 [PCOUNT_HISTORY] = "History",
12135 [PCOUNT_STALE] = "Stale",
12136 [PCOUNT_VALID] = "Valid",
12137 [PCOUNT_ALL] = "All RIB",
12138 [PCOUNT_COUNTED] = "PfxCt counted",
12139 [PCOUNT_PFCNT] = "Useable",
12140 [PCOUNT_MAX] = NULL,
12141};
12142
Paul Jakma2815e612006-09-14 02:56:07 +000012143struct peer_pcounts
12144{
12145 unsigned int count[PCOUNT_MAX];
12146 const struct peer *peer;
12147 const struct bgp_table *table;
12148};
12149
Paul Jakmaff7924f2006-09-04 01:10:36 +000012150static int
Paul Jakma2815e612006-09-14 02:56:07 +000012151bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012152{
12153 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012154 struct peer_pcounts *pc = THREAD_ARG (t);
12155 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012156
Paul Jakma2815e612006-09-14 02:56:07 +000012157 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012158 {
12159 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012160 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012161
12162 for (ain = rn->adj_in; ain; ain = ain->next)
12163 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012164 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012165
Paul Jakmaff7924f2006-09-04 01:10:36 +000012166 for (ri = rn->info; ri; ri = ri->next)
12167 {
12168 char buf[SU_ADDRSTRLEN];
12169
12170 if (ri->peer != peer)
12171 continue;
12172
Paul Jakma2815e612006-09-14 02:56:07 +000012173 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012174
12175 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012176 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012177 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012178 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012179 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012180 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012181 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012182 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012183 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012184 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012185 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012186 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012187
12188 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12189 {
Paul Jakma2815e612006-09-14 02:56:07 +000012190 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012191 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012192 plog_warn (peer->log,
12193 "%s [pcount] %s/%d is counted but flags 0x%x",
12194 peer->host,
12195 inet_ntop(rn->p.family, &rn->p.u.prefix,
12196 buf, SU_ADDRSTRLEN),
12197 rn->p.prefixlen,
12198 ri->flags);
12199 }
12200 else
12201 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012202 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012203 plog_warn (peer->log,
12204 "%s [pcount] %s/%d not counted but flags 0x%x",
12205 peer->host,
12206 inet_ntop(rn->p.family, &rn->p.u.prefix,
12207 buf, SU_ADDRSTRLEN),
12208 rn->p.prefixlen,
12209 ri->flags);
12210 }
12211 }
12212 }
Paul Jakma2815e612006-09-14 02:56:07 +000012213 return 0;
12214}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012215
Paul Jakma2815e612006-09-14 02:56:07 +000012216static int
12217bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12218{
12219 struct peer_pcounts pcounts = { .peer = peer };
12220 unsigned int i;
12221
12222 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12223 || !peer->bgp->rib[afi][safi])
12224 {
12225 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12226 return CMD_WARNING;
12227 }
12228
12229 memset (&pcounts, 0, sizeof(pcounts));
12230 pcounts.peer = peer;
12231 pcounts.table = peer->bgp->rib[afi][safi];
12232
12233 /* in-place call via thread subsystem so as to record execution time
12234 * stats for the thread-walk (i.e. ensure this can't be blamed on
12235 * on just vty_read()).
12236 */
12237 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12238
Paul Jakmaff7924f2006-09-04 01:10:36 +000012239 vty_out (vty, "Prefix counts for %s, %s%s",
12240 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12241 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12242 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12243 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12244
12245 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012246 vty_out (vty, "%20s: %-10d%s",
12247 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012248
Paul Jakma2815e612006-09-14 02:56:07 +000012249 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012250 {
12251 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12252 peer->host, VTY_NEWLINE);
12253 vty_out (vty, "Please report this bug, with the above command output%s",
12254 VTY_NEWLINE);
12255 }
12256
12257 return CMD_SUCCESS;
12258}
12259
Lou Bergerf9b6c392016-01-12 13:42:09 -050012260DEFUN (show_ip_bgp_neighbor_prefix_counts,
12261 show_ip_bgp_neighbor_prefix_counts_cmd,
12262 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12263 SHOW_STR
12264 IP_STR
12265 BGP_STR
12266 "Detailed information on TCP and BGP neighbor connections\n"
12267 "Neighbor to display information about\n"
12268 "Neighbor to display information about\n"
12269 "Display detailed prefix count information\n")
12270{
12271 struct peer *peer;
12272
12273 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12274 if (! peer)
12275 return CMD_WARNING;
12276
12277 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12278}
12279
Paul Jakmaff7924f2006-09-04 01:10:36 +000012280DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12281 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12282 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12283 SHOW_STR
12284 BGP_STR
12285 "Address family\n"
12286 "Detailed information on TCP and BGP neighbor connections\n"
12287 "Neighbor to display information about\n"
12288 "Neighbor to display information about\n"
12289 "Display detailed prefix count information\n")
12290{
12291 struct peer *peer;
12292
12293 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12294 if (! peer)
12295 return CMD_WARNING;
12296
12297 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12298}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012299
12300DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12301 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12302 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12303 SHOW_STR
12304 IP_STR
12305 BGP_STR
12306 "Address family\n"
12307 "Address Family modifier\n"
12308 "Address Family modifier\n"
12309 "Detailed information on TCP and BGP neighbor connections\n"
12310 "Neighbor to display information about\n"
12311 "Neighbor to display information about\n"
12312 "Display detailed prefix count information\n")
12313{
12314 struct peer *peer;
12315
12316 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12317 if (! peer)
12318 return CMD_WARNING;
12319
12320 if (strncmp (argv[0], "m", 1) == 0)
12321 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12322
12323 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12324}
12325
12326DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12327 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12328 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12329 SHOW_STR
12330 IP_STR
12331 BGP_STR
12332 "Address family\n"
12333 "Address Family modifier\n"
12334 "Address Family modifier\n"
12335 "Detailed information on TCP and BGP neighbor connections\n"
12336 "Neighbor to display information about\n"
12337 "Neighbor to display information about\n"
12338 "Display detailed prefix count information\n")
12339{
12340 struct peer *peer;
12341
12342 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12343 if (! peer)
12344 return CMD_WARNING;
12345
12346 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12347}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012348
Lou Berger651b4022016-01-12 13:42:07 -050012349DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12350 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12351 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012352 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012353 BGP_STR
12354 "Address family\n"
12355 "Address Family modifier\n"
12356 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012357 "Address Family modifier\n"
12358 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012359 "Detailed information on TCP and BGP neighbor connections\n"
12360 "Neighbor to display information about\n"
12361 "Neighbor to display information about\n"
12362 "Display detailed prefix count information\n")
12363{
12364 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012365 safi_t safi;
12366
12367 if (bgp_parse_safi(argv[0], &safi)) {
12368 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12369 return CMD_WARNING;
12370 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012371
12372 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12373 if (! peer)
12374 return CMD_WARNING;
12375
Lou Berger651b4022016-01-12 13:42:07 -050012376 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012377}
Lou Berger651b4022016-01-12 13:42:07 -050012378#ifdef HAVE_IPV6
12379DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12380 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12381 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12382 SHOW_STR
12383 BGP_STR
12384 "Address family\n"
12385 "Address Family modifier\n"
12386 "Address Family modifier\n"
12387 "Address Family modifier\n"
12388 "Address Family modifier\n"
12389 "Detailed information on TCP and BGP neighbor connections\n"
12390 "Neighbor to display information about\n"
12391 "Neighbor to display information about\n"
12392 "Display detailed prefix count information\n")
12393{
12394 struct peer *peer;
12395 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012396
Lou Berger651b4022016-01-12 13:42:07 -050012397 if (bgp_parse_safi(argv[0], &safi)) {
12398 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12399 return CMD_WARNING;
12400 }
12401
12402 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12403 if (! peer)
12404 return CMD_WARNING;
12405
12406 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12407}
12408#endif
12409
12410DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12411 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12412 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012413 SHOW_STR
12414 IP_STR
12415 BGP_STR
12416 "Address family\n"
12417 "Address Family modifier\n"
12418 "Address Family modifier\n"
12419 "Detailed information on TCP and BGP neighbor connections\n"
12420 "Neighbor to display information about\n"
12421 "Neighbor to display information about\n"
12422 "Display detailed prefix count information\n")
12423{
12424 struct peer *peer;
12425
12426 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12427 if (! peer)
12428 return CMD_WARNING;
12429
Lou Berger651b4022016-01-12 13:42:07 -050012430 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012431}
12432
12433
paul94f2b392005-06-28 12:44:16 +000012434static void
paul718e3742002-12-13 20:15:29 +000012435show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12436 int in)
12437{
12438 struct bgp_table *table;
12439 struct bgp_adj_in *ain;
12440 struct bgp_adj_out *adj;
12441 unsigned long output_count;
12442 struct bgp_node *rn;
12443 int header1 = 1;
12444 struct bgp *bgp;
12445 int header2 = 1;
12446
paulbb46e942003-10-24 19:02:03 +000012447 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012448
12449 if (! bgp)
12450 return;
12451
12452 table = bgp->rib[afi][safi];
12453
12454 output_count = 0;
12455
12456 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12457 PEER_STATUS_DEFAULT_ORIGINATE))
12458 {
12459 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 +000012460 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12461 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012462
12463 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12464 VTY_NEWLINE, VTY_NEWLINE);
12465 header1 = 0;
12466 }
12467
12468 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12469 if (in)
12470 {
12471 for (ain = rn->adj_in; ain; ain = ain->next)
12472 if (ain->peer == peer)
12473 {
12474 if (header1)
12475 {
12476 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 +000012477 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12478 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012479 header1 = 0;
12480 }
12481 if (header2)
12482 {
12483 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12484 header2 = 0;
12485 }
12486 if (ain->attr)
12487 {
12488 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12489 output_count++;
12490 }
12491 }
12492 }
12493 else
12494 {
12495 for (adj = rn->adj_out; adj; adj = adj->next)
12496 if (adj->peer == peer)
12497 {
12498 if (header1)
12499 {
12500 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 +000012501 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12502 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012503 header1 = 0;
12504 }
12505 if (header2)
12506 {
12507 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12508 header2 = 0;
12509 }
12510 if (adj->attr)
12511 {
12512 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12513 output_count++;
12514 }
12515 }
12516 }
12517
12518 if (output_count != 0)
12519 vty_out (vty, "%sTotal number of prefixes %ld%s",
12520 VTY_NEWLINE, output_count, VTY_NEWLINE);
12521}
12522
paul94f2b392005-06-28 12:44:16 +000012523static int
paulbb46e942003-10-24 19:02:03 +000012524peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12525{
paul718e3742002-12-13 20:15:29 +000012526 if (! peer || ! peer->afc[afi][safi])
12527 {
12528 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12529 return CMD_WARNING;
12530 }
12531
12532 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12533 {
12534 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12535 VTY_NEWLINE);
12536 return CMD_WARNING;
12537 }
12538
12539 show_adj_route (vty, peer, afi, safi, in);
12540
12541 return CMD_SUCCESS;
12542}
12543
Lou Bergerf9b6c392016-01-12 13:42:09 -050012544DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12545 show_ip_bgp_view_neighbor_advertised_route_cmd,
12546 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12547 SHOW_STR
12548 IP_STR
12549 BGP_STR
12550 "BGP view\n"
12551 "View name\n"
12552 "Detailed information on TCP and BGP neighbor connections\n"
12553 "Neighbor to display information about\n"
12554 "Neighbor to display information about\n"
12555 "Display the routes advertised to a BGP neighbor\n")
12556{
12557 struct peer *peer;
12558
12559 if (argc == 2)
12560 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12561 else
12562 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12563
12564 if (! peer)
12565 return CMD_WARNING;
12566
12567 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12568}
12569
12570ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12571 show_ip_bgp_neighbor_advertised_route_cmd,
12572 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12573 SHOW_STR
12574 IP_STR
12575 BGP_STR
12576 "Detailed information on TCP and BGP neighbor connections\n"
12577 "Neighbor to display information about\n"
12578 "Neighbor to display information about\n"
12579 "Display the routes advertised to a BGP neighbor\n")
12580
12581DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12582 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12583 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12584 SHOW_STR
12585 IP_STR
12586 BGP_STR
12587 "Address family\n"
12588 "Address Family modifier\n"
12589 "Address Family modifier\n"
12590 "Detailed information on TCP and BGP neighbor connections\n"
12591 "Neighbor to display information about\n"
12592 "Neighbor to display information about\n"
12593 "Display the routes advertised to a BGP neighbor\n")
12594{
12595 struct peer *peer;
12596
12597 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12598 if (! peer)
12599 return CMD_WARNING;
12600
12601 if (strncmp (argv[0], "m", 1) == 0)
12602 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12603
12604 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12605}
12606
12607#ifdef HAVE_IPV6
12608DEFUN (show_bgp_view_neighbor_advertised_route,
12609 show_bgp_view_neighbor_advertised_route_cmd,
12610 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12611 SHOW_STR
12612 BGP_STR
12613 "BGP view\n"
12614 "View name\n"
12615 "Detailed information on TCP and BGP neighbor connections\n"
12616 "Neighbor to display information about\n"
12617 "Neighbor to display information about\n"
12618 "Display the routes advertised to a BGP neighbor\n")
12619{
12620 struct peer *peer;
12621
12622 if (argc == 2)
12623 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12624 else
12625 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12626
12627 if (! peer)
12628 return CMD_WARNING;
12629
12630 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12631}
12632
12633DEFUN (show_bgp_view_neighbor_received_routes,
12634 show_bgp_view_neighbor_received_routes_cmd,
12635 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12636 SHOW_STR
12637 BGP_STR
12638 "BGP view\n"
12639 "View name\n"
12640 "Detailed information on TCP and BGP neighbor connections\n"
12641 "Neighbor to display information about\n"
12642 "Neighbor to display information about\n"
12643 "Display the received routes from neighbor\n")
12644{
12645 struct peer *peer;
12646
12647 if (argc == 2)
12648 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12649 else
12650 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12651
12652 if (! peer)
12653 return CMD_WARNING;
12654
12655 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12656}
12657
12658ALIAS (show_bgp_view_neighbor_advertised_route,
12659 show_bgp_neighbor_advertised_route_cmd,
12660 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12661 SHOW_STR
12662 BGP_STR
12663 "Detailed information on TCP and BGP neighbor connections\n"
12664 "Neighbor to display information about\n"
12665 "Neighbor to display information about\n"
12666 "Display the routes advertised to a BGP neighbor\n")
12667
12668ALIAS (show_bgp_view_neighbor_advertised_route,
12669 show_bgp_ipv6_neighbor_advertised_route_cmd,
12670 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12671 SHOW_STR
12672 BGP_STR
12673 "Address family\n"
12674 "Detailed information on TCP and BGP neighbor connections\n"
12675 "Neighbor to display information about\n"
12676 "Neighbor to display information about\n"
12677 "Display the routes advertised to a BGP neighbor\n")
12678
12679/* old command */
12680ALIAS (show_bgp_view_neighbor_advertised_route,
12681 ipv6_bgp_neighbor_advertised_route_cmd,
12682 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12683 SHOW_STR
12684 IPV6_STR
12685 BGP_STR
12686 "Detailed information on TCP and BGP neighbor connections\n"
12687 "Neighbor to display information about\n"
12688 "Neighbor to display information about\n"
12689 "Display the routes advertised to a BGP neighbor\n")
12690
12691/* old command */
12692DEFUN (ipv6_mbgp_neighbor_advertised_route,
12693 ipv6_mbgp_neighbor_advertised_route_cmd,
12694 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12695 SHOW_STR
12696 IPV6_STR
12697 MBGP_STR
12698 "Detailed information on TCP and BGP neighbor connections\n"
12699 "Neighbor to display information about\n"
12700 "Neighbor to display information about\n"
12701 "Display the routes advertised to a BGP neighbor\n")
12702{
12703 struct peer *peer;
12704
12705 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12706 if (! peer)
12707 return CMD_WARNING;
12708
12709 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12710}
12711#endif /* HAVE_IPV6 */
12712
12713DEFUN (show_ip_bgp_view_neighbor_received_routes,
12714 show_ip_bgp_view_neighbor_received_routes_cmd,
12715 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12716 SHOW_STR
12717 IP_STR
12718 BGP_STR
12719 "BGP view\n"
12720 "View name\n"
12721 "Detailed information on TCP and BGP neighbor connections\n"
12722 "Neighbor to display information about\n"
12723 "Neighbor to display information about\n"
12724 "Display the received routes from neighbor\n")
12725{
12726 struct peer *peer;
12727
12728 if (argc == 2)
12729 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12730 else
12731 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12732
12733 if (! peer)
12734 return CMD_WARNING;
12735
12736 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12737}
12738
12739ALIAS (show_ip_bgp_view_neighbor_received_routes,
12740 show_ip_bgp_neighbor_received_routes_cmd,
12741 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12742 SHOW_STR
12743 IP_STR
12744 BGP_STR
12745 "Detailed information on TCP and BGP neighbor connections\n"
12746 "Neighbor to display information about\n"
12747 "Neighbor to display information about\n"
12748 "Display the received routes from neighbor\n")
12749
12750ALIAS (show_bgp_view_neighbor_received_routes,
12751 show_bgp_ipv6_neighbor_received_routes_cmd,
12752 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12753 SHOW_STR
12754 BGP_STR
12755 "Address family\n"
12756 "Detailed information on TCP and BGP neighbor connections\n"
12757 "Neighbor to display information about\n"
12758 "Neighbor to display information about\n"
12759 "Display the received routes from neighbor\n")
12760
12761DEFUN (show_bgp_neighbor_received_prefix_filter,
12762 show_bgp_neighbor_received_prefix_filter_cmd,
12763 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12764 SHOW_STR
12765 BGP_STR
12766 "Detailed information on TCP and BGP neighbor connections\n"
12767 "Neighbor to display information about\n"
12768 "Neighbor to display information about\n"
12769 "Display information received from a BGP neighbor\n"
12770 "Display the prefixlist filter\n")
12771{
12772 char name[BUFSIZ];
12773 union sockunion su;
12774 struct peer *peer;
12775 int count, ret;
12776
12777 ret = str2sockunion (argv[0], &su);
12778 if (ret < 0)
12779 {
12780 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12781 return CMD_WARNING;
12782 }
12783
12784 peer = peer_lookup (NULL, &su);
12785 if (! peer)
12786 return CMD_WARNING;
12787
12788 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12789 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12790 if (count)
12791 {
12792 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12793 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12794 }
12795
12796 return CMD_SUCCESS;
12797}
12798
12799/* old command */
12800ALIAS (show_bgp_view_neighbor_received_routes,
12801 ipv6_bgp_neighbor_received_routes_cmd,
12802 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12803 SHOW_STR
12804 IPV6_STR
12805 BGP_STR
12806 "Detailed information on TCP and BGP neighbor connections\n"
12807 "Neighbor to display information about\n"
12808 "Neighbor to display information about\n"
12809 "Display the received routes from neighbor\n")
12810
12811/* old command */
12812DEFUN (ipv6_mbgp_neighbor_received_routes,
12813 ipv6_mbgp_neighbor_received_routes_cmd,
12814 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12815 SHOW_STR
12816 IPV6_STR
12817 MBGP_STR
12818 "Detailed information on TCP and BGP neighbor connections\n"
12819 "Neighbor to display information about\n"
12820 "Neighbor to display information about\n"
12821 "Display the received routes from neighbor\n")
12822{
12823 struct peer *peer;
12824
12825 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12826 if (! peer)
12827 return CMD_WARNING;
12828
12829 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12830}
12831
12832DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12833 show_bgp_view_neighbor_received_prefix_filter_cmd,
12834 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12835 SHOW_STR
12836 BGP_STR
12837 "BGP view\n"
12838 "View name\n"
12839 "Detailed information on TCP and BGP neighbor connections\n"
12840 "Neighbor to display information about\n"
12841 "Neighbor to display information about\n"
12842 "Display information received from a BGP neighbor\n"
12843 "Display the prefixlist filter\n")
12844{
12845 char name[BUFSIZ];
12846 union sockunion su;
12847 struct peer *peer;
12848 struct bgp *bgp;
12849 int count, ret;
12850
12851 /* BGP structure lookup. */
12852 bgp = bgp_lookup_by_name (argv[0]);
12853 if (bgp == NULL)
12854 {
12855 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12856 return CMD_WARNING;
12857 }
12858
12859 ret = str2sockunion (argv[1], &su);
12860 if (ret < 0)
12861 {
12862 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12863 return CMD_WARNING;
12864 }
12865
12866 peer = peer_lookup (bgp, &su);
12867 if (! peer)
12868 return CMD_WARNING;
12869
12870 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12871 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12872 if (count)
12873 {
12874 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12875 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12876 }
12877
12878 return CMD_SUCCESS;
12879}
12880
12881
12882DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12883 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12884 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12885 SHOW_STR
12886 IP_STR
12887 BGP_STR
12888 "Address family\n"
12889 "Address Family modifier\n"
12890 "Address Family modifier\n"
12891 "Detailed information on TCP and BGP neighbor connections\n"
12892 "Neighbor to display information about\n"
12893 "Neighbor to display information about\n"
12894 "Display the received routes from neighbor\n")
12895{
12896 struct peer *peer;
12897
12898 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12899 if (! peer)
12900 return CMD_WARNING;
12901
12902 if (strncmp (argv[0], "m", 1) == 0)
12903 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12904
12905 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12906}
12907
Lou Berger651b4022016-01-12 13:42:07 -050012908DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12909 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12910 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012911 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012912 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012913 "Address Family modifier\n"
12914 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012915 "Detailed information on TCP and BGP neighbor connections\n"
12916 "Neighbor to display information about\n"
12917 "Neighbor to display information about\n"
12918 "Display the routes advertised to a BGP neighbor\n")
12919{
12920 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012921 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012922
Lou Berger651b4022016-01-12 13:42:07 -050012923 if (bgp_parse_safi(argv[0], &safi)) {
12924 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012925 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012926 }
paul718e3742002-12-13 20:15:29 +000012927
paulbb46e942003-10-24 19:02:03 +000012928 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12929 if (! peer)
12930 return CMD_WARNING;
12931
Lou Berger651b4022016-01-12 13:42:07 -050012932 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
12933}
12934#ifdef HAVE_IPV6
12935DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
12936 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
12937 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12938 SHOW_STR
12939 BGP_STR
12940 "Address Family modifier\n"
12941 "Address Family modifier\n"
12942 "Address Family modifier\n"
12943 "Detailed information on TCP and BGP neighbor connections\n"
12944 "Neighbor to display information about\n"
12945 "Neighbor to display information about\n"
12946 "Display the routes advertised to a BGP neighbor\n")
12947{
12948 struct peer *peer;
12949 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000012950
Lou Berger651b4022016-01-12 13:42:07 -050012951 if (bgp_parse_safi(argv[0], &safi)) {
12952 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12953 return CMD_WARNING;
12954 }
12955
12956 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12957 if (! peer)
12958 return CMD_WARNING;
12959
12960 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000012961}
12962
Lou Bergerf9b6c392016-01-12 13:42:09 -050012963DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050012964 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
12965 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000012966 SHOW_STR
12967 BGP_STR
12968 "BGP view\n"
12969 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050012970 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000012971 "Detailed information on TCP and BGP neighbor connections\n"
12972 "Neighbor to display information about\n"
12973 "Neighbor to display information about\n"
12974 "Display the routes advertised to a BGP neighbor\n")
12975{
12976 struct peer *peer;
12977
12978 if (argc == 2)
12979 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12980 else
12981 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12982
12983 if (! peer)
12984 return CMD_WARNING;
12985
12986 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12987}
12988
Lou Bergerf9b6c392016-01-12 13:42:09 -050012989DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050012990 show_bgp_view_ipv6_neighbor_received_routes_cmd,
12991 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000012992 SHOW_STR
12993 BGP_STR
12994 "BGP view\n"
12995 "View name\n"
12996 "Address family\n"
12997 "Detailed information on TCP and BGP neighbor connections\n"
12998 "Neighbor to display information about\n"
12999 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013000 "Display the received routes from neighbor\n")
13001{
13002 struct peer *peer;
13003
13004 if (argc == 2)
13005 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13006 else
13007 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13008
13009 if (! peer)
13010 return CMD_WARNING;
13011
13012 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13013}
paul718e3742002-12-13 20:15:29 +000013014#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020013015
Lou Berger651b4022016-01-12 13:42:07 -050013016
13017DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13018 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13019 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013020 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013021 BGP_STR
13022 "Address family\n"
13023 "Address Family modifier\n"
13024 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013025 "Address Family modifier\n"
13026 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013027 "Detailed information on TCP and BGP neighbor connections\n"
13028 "Neighbor to display information about\n"
13029 "Neighbor to display information about\n"
13030 "Display the received routes from neighbor\n")
13031{
paulbb46e942003-10-24 19:02:03 +000013032 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013033 safi_t safi;
13034
13035 if (bgp_parse_safi(argv[0], &safi)) {
13036 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13037 return CMD_WARNING;
13038 }
paul718e3742002-12-13 20:15:29 +000013039
paulbb46e942003-10-24 19:02:03 +000013040 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13041 if (! peer)
13042 return CMD_WARNING;
13043
Lou Berger651b4022016-01-12 13:42:07 -050013044 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013045}
Lou Berger651b4022016-01-12 13:42:07 -050013046#ifdef HAVE_IPV6
13047DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13048 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13049 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13050 SHOW_STR
13051 BGP_STR
13052 "Address family\n"
13053 "Address Family modifier\n"
13054 "Address Family modifier\n"
13055 "Address Family modifier\n"
13056 "Address Family modifier\n"
13057 "Detailed information on TCP and BGP neighbor connections\n"
13058 "Neighbor to display information about\n"
13059 "Neighbor to display information about\n"
13060 "Display the received routes from neighbor\n")
13061{
13062 struct peer *peer;
13063 safi_t safi;
13064
13065 if (bgp_parse_safi(argv[0], &safi)) {
13066 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13067 return CMD_WARNING;
13068 }
13069
13070 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13071 if (! peer)
13072 return CMD_WARNING;
13073
13074 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13075}
13076#endif
paul718e3742002-12-13 20:15:29 +000013077
Michael Lambert95cbbd22010-07-23 14:43:04 -040013078DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13079 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013080 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040013081 SHOW_STR
13082 BGP_STR
13083 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013084 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013085 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013086 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013087 "Address family modifier\n"
13088 "Address family modifier\n"
13089 "Detailed information on TCP and BGP neighbor connections\n"
13090 "Neighbor to display information about\n"
13091 "Neighbor to display information about\n"
13092 "Display the advertised routes to neighbor\n"
13093 "Display the received routes from neighbor\n")
13094{
13095 int afi;
13096 int safi;
13097 int in;
13098 struct peer *peer;
13099
David Lamparter94bad672015-03-03 08:52:22 +010013100 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013101
13102 if (! peer)
13103 return CMD_WARNING;
13104
Michael Lambert95cbbd22010-07-23 14:43:04 -040013105 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13106 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13107 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013108
13109 return peer_adj_routes (vty, peer, afi, safi, in);
13110}
13111
Lou Bergerf9b6c392016-01-12 13:42:09 -050013112DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13113 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13114 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13115 SHOW_STR
13116 IP_STR
13117 BGP_STR
13118 "Detailed information on TCP and BGP neighbor connections\n"
13119 "Neighbor to display information about\n"
13120 "Neighbor to display information about\n"
13121 "Display information received from a BGP neighbor\n"
13122 "Display the prefixlist filter\n")
13123{
13124 char name[BUFSIZ];
13125 union sockunion su;
13126 struct peer *peer;
13127 int count, ret;
13128
13129 ret = str2sockunion (argv[0], &su);
13130 if (ret < 0)
13131 {
13132 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13133 return CMD_WARNING;
13134 }
13135
13136 peer = peer_lookup (NULL, &su);
13137 if (! peer)
13138 return CMD_WARNING;
13139
13140 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13141 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13142 if (count)
13143 {
13144 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13145 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13146 }
13147
13148 return CMD_SUCCESS;
13149}
13150
13151DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13152 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13153 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13154 SHOW_STR
13155 IP_STR
13156 BGP_STR
13157 "Address family\n"
13158 "Address Family modifier\n"
13159 "Address Family modifier\n"
13160 "Detailed information on TCP and BGP neighbor connections\n"
13161 "Neighbor to display information about\n"
13162 "Neighbor to display information about\n"
13163 "Display information received from a BGP neighbor\n"
13164 "Display the prefixlist filter\n")
13165{
13166 char name[BUFSIZ];
13167 union sockunion su;
13168 struct peer *peer;
13169 int count, ret;
13170
13171 ret = str2sockunion (argv[1], &su);
13172 if (ret < 0)
13173 {
13174 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13175 return CMD_WARNING;
13176 }
13177
13178 peer = peer_lookup (NULL, &su);
13179 if (! peer)
13180 return CMD_WARNING;
13181
13182 if (strncmp (argv[0], "m", 1) == 0)
13183 {
13184 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13185 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13186 if (count)
13187 {
13188 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13189 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13190 }
13191 }
13192 else
13193 {
13194 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13195 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13196 if (count)
13197 {
13198 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13199 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13200 }
13201 }
13202
13203 return CMD_SUCCESS;
13204}
13205
13206ALIAS (show_bgp_view_neighbor_received_routes,
13207 show_bgp_neighbor_received_routes_cmd,
13208 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13209 SHOW_STR
13210 BGP_STR
13211 "Detailed information on TCP and BGP neighbor connections\n"
13212 "Neighbor to display information about\n"
13213 "Neighbor to display information about\n"
13214 "Display the received routes from neighbor\n")
13215
Lou Berger651b4022016-01-12 13:42:07 -050013216DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13217 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13218 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013219 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013220 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013221 IP_STR
13222 "Address Family modifier\n"
13223 "Address Family modifier\n"
13224 "Address Family modifier\n"
13225 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013226 "Detailed information on TCP and BGP neighbor connections\n"
13227 "Neighbor to display information about\n"
13228 "Neighbor to display information about\n"
13229 "Display information received from a BGP neighbor\n"
13230 "Display the prefixlist filter\n")
13231{
13232 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013233 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013234 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013235 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013236 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013237
Lou Berger651b4022016-01-12 13:42:07 -050013238 if (bgp_parse_safi(argv[0], &safi)) {
13239 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013240 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013241 }
paul718e3742002-12-13 20:15:29 +000013242
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013243 ret = str2sockunion (argv[1], &su);
13244 if (ret < 0)
13245 {
13246 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13247 return CMD_WARNING;
13248 }
paul718e3742002-12-13 20:15:29 +000013249
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013250 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013251 if (! peer)
13252 return CMD_WARNING;
13253
Lou Berger651b4022016-01-12 13:42:07 -050013254 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13255 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13256 if (count) {
13257 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13258 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13259 }
paul718e3742002-12-13 20:15:29 +000013260
13261 return CMD_SUCCESS;
13262}
paul718e3742002-12-13 20:15:29 +000013263#ifdef HAVE_IPV6
Lou Berger651b4022016-01-12 13:42:07 -050013264DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13265 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13266 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013267 SHOW_STR
13268 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013269 IP_STR
13270 "Address Family modifier\n"
13271 "Address Family modifier\n"
13272 "Address Family modifier\n"
13273 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013274 "Detailed information on TCP and BGP neighbor connections\n"
13275 "Neighbor to display information about\n"
13276 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013277 "Display information received from a BGP neighbor\n"
13278 "Display the prefixlist filter\n")
13279{
13280 char name[BUFSIZ];
13281 union sockunion su;
13282 struct peer *peer;
13283 int count, ret;
13284 safi_t safi;
13285
13286 if (bgp_parse_safi(argv[0], &safi)) {
13287 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13288 return CMD_WARNING;
13289 }
13290
13291 ret = str2sockunion (argv[1], &su);
13292 if (ret < 0)
13293 {
13294 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13295 return CMD_WARNING;
13296 }
13297
13298 peer = peer_lookup (NULL, &su);
13299 if (! peer)
13300 return CMD_WARNING;
13301
13302 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13303 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13304 if (count) {
13305 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13306 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13307 }
13308
13309 return CMD_SUCCESS;
13310}
paul718e3742002-12-13 20:15:29 +000013311
Lou Bergerf9b6c392016-01-12 13:42:09 -050013312DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013313 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13314 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013315 SHOW_STR
13316 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013317 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013318 "Detailed information on TCP and BGP neighbor connections\n"
13319 "Neighbor to display information about\n"
13320 "Neighbor to display information about\n"
13321 "Display information received from a BGP neighbor\n"
13322 "Display the prefixlist filter\n")
13323{
13324 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013325 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013326 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013327 int count, ret;
paul718e3742002-12-13 20:15:29 +000013328
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013329 ret = str2sockunion (argv[0], &su);
13330 if (ret < 0)
13331 {
13332 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13333 return CMD_WARNING;
13334 }
paul718e3742002-12-13 20:15:29 +000013335
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013336 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013337 if (! peer)
13338 return CMD_WARNING;
13339
13340 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13341 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13342 if (count)
13343 {
13344 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13345 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13346 }
13347
13348 return CMD_SUCCESS;
13349}
13350
Lou Bergerf9b6c392016-01-12 13:42:09 -050013351DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013352 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13353 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013354 SHOW_STR
13355 BGP_STR
13356 "BGP view\n"
13357 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013358 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013359 "Detailed information on TCP and BGP neighbor connections\n"
13360 "Neighbor to display information about\n"
13361 "Neighbor to display information about\n"
13362 "Display information received from a BGP neighbor\n"
13363 "Display the prefixlist filter\n")
13364{
13365 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013366 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013367 struct peer *peer;
13368 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013369 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013370
13371 /* BGP structure lookup. */
13372 bgp = bgp_lookup_by_name (argv[0]);
13373 if (bgp == NULL)
13374 {
13375 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13376 return CMD_WARNING;
13377 }
13378
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013379 ret = str2sockunion (argv[1], &su);
13380 if (ret < 0)
13381 {
13382 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13383 return CMD_WARNING;
13384 }
paulbb46e942003-10-24 19:02:03 +000013385
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013386 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013387 if (! peer)
13388 return CMD_WARNING;
13389
13390 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13391 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13392 if (count)
13393 {
13394 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13395 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13396 }
13397
13398 return CMD_SUCCESS;
13399}
paul718e3742002-12-13 20:15:29 +000013400#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020013401
paul94f2b392005-06-28 12:44:16 +000013402static int
paulbb46e942003-10-24 19:02:03 +000013403bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013404 safi_t safi, enum bgp_show_type type)
13405{
paul718e3742002-12-13 20:15:29 +000013406 if (! peer || ! peer->afc[afi][safi])
13407 {
13408 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013409 return CMD_WARNING;
13410 }
13411
ajs5a646652004-11-05 01:25:55 +000013412 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013413}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013414DEFUN (show_ip_bgp_neighbor_routes,
13415 show_ip_bgp_neighbor_routes_cmd,
13416 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13417 SHOW_STR
13418 IP_STR
13419 BGP_STR
13420 "Detailed information on TCP and BGP neighbor connections\n"
13421 "Neighbor to display information about\n"
13422 "Neighbor to display information about\n"
13423 "Display routes learned from neighbor\n")
13424{
13425 struct peer *peer;
13426
13427 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13428 if (! peer)
13429 return CMD_WARNING;
13430
13431 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13432 bgp_show_type_neighbor);
13433}
13434
13435DEFUN (show_ip_bgp_neighbor_flap,
13436 show_ip_bgp_neighbor_flap_cmd,
13437 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13438 SHOW_STR
13439 IP_STR
13440 BGP_STR
13441 "Detailed information on TCP and BGP neighbor connections\n"
13442 "Neighbor to display information about\n"
13443 "Neighbor to display information about\n"
13444 "Display flap statistics of the routes learned from neighbor\n")
13445{
13446 struct peer *peer;
13447
13448 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13449 if (! peer)
13450 return CMD_WARNING;
13451
13452 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13453 bgp_show_type_flap_neighbor);
13454}
13455
13456DEFUN (show_ip_bgp_neighbor_damp,
13457 show_ip_bgp_neighbor_damp_cmd,
13458 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13459 SHOW_STR
13460 IP_STR
13461 BGP_STR
13462 "Detailed information on TCP and BGP neighbor connections\n"
13463 "Neighbor to display information about\n"
13464 "Neighbor to display information about\n"
13465 "Display the dampened routes received from neighbor\n")
13466{
13467 struct peer *peer;
13468
13469 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13470 if (! peer)
13471 return CMD_WARNING;
13472
13473 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13474 bgp_show_type_damp_neighbor);
13475}
13476
13477DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13478 show_ip_bgp_ipv4_neighbor_routes_cmd,
13479 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13480 SHOW_STR
13481 IP_STR
13482 BGP_STR
13483 "Address family\n"
13484 "Address Family modifier\n"
13485 "Address Family modifier\n"
13486 "Detailed information on TCP and BGP neighbor connections\n"
13487 "Neighbor to display information about\n"
13488 "Neighbor to display information about\n"
13489 "Display routes learned from neighbor\n")
13490{
13491 struct peer *peer;
13492
13493 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13494 if (! peer)
13495 return CMD_WARNING;
13496
13497 if (strncmp (argv[0], "m", 1) == 0)
13498 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13499 bgp_show_type_neighbor);
13500
13501 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13502 bgp_show_type_neighbor);
13503}
13504
13505DEFUN (show_ip_bgp_view_rsclient,
13506 show_ip_bgp_view_rsclient_cmd,
13507 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13508 SHOW_STR
13509 IP_STR
13510 BGP_STR
13511 "BGP view\n"
13512 "View name\n"
13513 "Information about Route Server Client\n"
13514 NEIGHBOR_ADDR_STR)
13515{
13516 struct bgp_table *table;
13517 struct peer *peer;
13518
13519 if (argc == 2)
13520 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13521 else
13522 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13523
13524 if (! peer)
13525 return CMD_WARNING;
13526
13527 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13528 {
13529 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13530 VTY_NEWLINE);
13531 return CMD_WARNING;
13532 }
13533
13534 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13535 PEER_FLAG_RSERVER_CLIENT))
13536 {
13537 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13538 VTY_NEWLINE);
13539 return CMD_WARNING;
13540 }
13541
13542 table = peer->rib[AFI_IP][SAFI_UNICAST];
13543
13544 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13545}
13546
13547ALIAS (show_ip_bgp_view_rsclient,
13548 show_ip_bgp_rsclient_cmd,
13549 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13550 SHOW_STR
13551 IP_STR
13552 BGP_STR
13553 "Information about Route Server Client\n"
13554 NEIGHBOR_ADDR_STR)
13555
13556DEFUN (show_bgp_view_ipv4_safi_rsclient,
13557 show_bgp_view_ipv4_safi_rsclient_cmd,
13558 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13559 SHOW_STR
13560 BGP_STR
13561 "BGP view\n"
13562 "View name\n"
13563 "Address family\n"
13564 "Address Family modifier\n"
13565 "Address Family modifier\n"
13566 "Information about Route Server Client\n"
13567 NEIGHBOR_ADDR_STR)
13568{
13569 struct bgp_table *table;
13570 struct peer *peer;
13571 safi_t safi;
13572
13573 if (argc == 3) {
13574 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13575 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13576 } else {
13577 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13578 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13579 }
13580
13581 if (! peer)
13582 return CMD_WARNING;
13583
13584 if (! peer->afc[AFI_IP][safi])
13585 {
13586 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13587 VTY_NEWLINE);
13588 return CMD_WARNING;
13589 }
13590
13591 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13592 PEER_FLAG_RSERVER_CLIENT))
13593 {
13594 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13595 VTY_NEWLINE);
13596 return CMD_WARNING;
13597 }
13598
13599 table = peer->rib[AFI_IP][safi];
13600
13601 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13602}
13603
13604ALIAS (show_bgp_view_ipv4_safi_rsclient,
13605 show_bgp_ipv4_safi_rsclient_cmd,
13606 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13607 SHOW_STR
13608 BGP_STR
13609 "Address family\n"
13610 "Address Family modifier\n"
13611 "Address Family modifier\n"
13612 "Information about Route Server Client\n"
13613 NEIGHBOR_ADDR_STR)
13614
13615DEFUN (show_ip_bgp_view_rsclient_route,
13616 show_ip_bgp_view_rsclient_route_cmd,
13617 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13618 SHOW_STR
13619 IP_STR
13620 BGP_STR
13621 "BGP view\n"
13622 "View name\n"
13623 "Information about Route Server Client\n"
13624 NEIGHBOR_ADDR_STR
13625 "Network in the BGP routing table to display\n")
13626{
13627 struct bgp *bgp;
13628 struct peer *peer;
13629
13630 /* BGP structure lookup. */
13631 if (argc == 3)
13632 {
13633 bgp = bgp_lookup_by_name (argv[0]);
13634 if (bgp == NULL)
13635 {
13636 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13637 return CMD_WARNING;
13638 }
13639 }
13640 else
13641 {
13642 bgp = bgp_get_default ();
13643 if (bgp == NULL)
13644 {
13645 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13646 return CMD_WARNING;
13647 }
13648 }
13649
13650 if (argc == 3)
13651 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13652 else
13653 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13654
13655 if (! peer)
13656 return CMD_WARNING;
13657
13658 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13659 {
13660 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13661 VTY_NEWLINE);
13662 return CMD_WARNING;
13663}
13664
13665 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13666 PEER_FLAG_RSERVER_CLIENT))
13667 {
13668 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13669 VTY_NEWLINE);
13670 return CMD_WARNING;
13671 }
13672
13673 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13674 (argc == 3) ? argv[2] : argv[1],
13675 AFI_IP, SAFI_UNICAST, NULL, 0);
13676}
13677
13678ALIAS (show_ip_bgp_view_rsclient_route,
13679 show_ip_bgp_rsclient_route_cmd,
13680 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13681 SHOW_STR
13682 IP_STR
13683 BGP_STR
13684 "Information about Route Server Client\n"
13685 NEIGHBOR_ADDR_STR
13686 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013687
Lou Berger651b4022016-01-12 13:42:07 -050013688DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13689 show_bgp_ipv4_safi_neighbor_flap_cmd,
13690 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013691 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013692 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013693 "Address Family Modifier\n"
13694 "Address Family Modifier\n"
13695 "Address Family Modifier\n"
13696 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013697 "Detailed information on TCP and BGP neighbor connections\n"
13698 "Neighbor to display information about\n"
13699 "Neighbor to display information about\n"
13700 "Display flap statistics of the routes learned from neighbor\n")
13701{
paulbb46e942003-10-24 19:02:03 +000013702 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013703 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013704
Lou Berger651b4022016-01-12 13:42:07 -050013705 if (bgp_parse_safi(argv[0], &safi)) {
13706 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13707 return CMD_WARNING;
13708 }
13709
13710 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013711 if (! peer)
13712 return CMD_WARNING;
13713
Lou Berger651b4022016-01-12 13:42:07 -050013714 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013715 bgp_show_type_flap_neighbor);
13716}
Lou Berger651b4022016-01-12 13:42:07 -050013717#ifdef HAVE_IPV6
13718DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13719 show_bgp_ipv6_safi_neighbor_flap_cmd,
13720 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013721 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013722 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013723 "Address Family Modifier\n"
13724 "Address Family Modifier\n"
13725 "Address Family Modifier\n"
13726 "Address Family Modifier\n"
13727 "Detailed information on TCP and BGP neighbor connections\n"
13728 "Neighbor to display information about\n"
13729 "Neighbor to display information about\n"
13730 "Display flap statistics of the routes learned from neighbor\n")
13731{
13732 struct peer *peer;
13733 safi_t safi;
13734
13735 if (bgp_parse_safi(argv[0], &safi)) {
13736 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13737 return CMD_WARNING;
13738 }
13739
13740 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13741 if (! peer)
13742 return CMD_WARNING;
13743
13744 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13745 bgp_show_type_flap_neighbor);
13746}
13747#endif
13748
13749DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13750 show_bgp_ipv4_safi_neighbor_damp_cmd,
13751 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13752 SHOW_STR
13753 BGP_STR
13754 "Address Family Modifier\n"
13755 "Address Family Modifier\n"
13756 "Address Family Modifier\n"
13757 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013758 "Detailed information on TCP and BGP neighbor connections\n"
13759 "Neighbor to display information about\n"
13760 "Neighbor to display information about\n"
13761 "Display the dampened routes received from neighbor\n")
13762{
paulbb46e942003-10-24 19:02:03 +000013763 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013764 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013765
Lou Berger651b4022016-01-12 13:42:07 -050013766 if (bgp_parse_safi(argv[0], &safi)) {
13767 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13768 return CMD_WARNING;
13769 }
13770
13771 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013772 if (! peer)
13773 return CMD_WARNING;
13774
Lou Berger651b4022016-01-12 13:42:07 -050013775 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013776 bgp_show_type_damp_neighbor);
13777}
Lou Berger651b4022016-01-12 13:42:07 -050013778#ifdef HAVE_IPV6
13779DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13780 show_bgp_ipv6_safi_neighbor_damp_cmd,
13781 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013782 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013783 BGP_STR
13784 "Address Family Modifier\n"
13785 "Address Family Modifier\n"
13786 "Address Family Modifier\n"
13787 "Address Family Modifier\n"
13788 "Detailed information on TCP and BGP neighbor connections\n"
13789 "Neighbor to display information about\n"
13790 "Neighbor to display information about\n"
13791 "Display the dampened routes received from neighbor\n")
13792{
13793 struct peer *peer;
13794 safi_t safi;
13795
13796 if (bgp_parse_safi(argv[0], &safi)) {
13797 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13798 return CMD_WARNING;
13799 }
13800
13801 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13802 if (! peer)
13803 return CMD_WARNING;
13804
13805 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13806 bgp_show_type_damp_neighbor);
13807}
13808#endif
13809
13810DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13811 show_bgp_ipv4_safi_neighbor_routes_cmd,
13812 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13813 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013814 BGP_STR
13815 "Address family\n"
13816 "Address Family modifier\n"
13817 "Address Family modifier\n"
13818 "Detailed information on TCP and BGP neighbor connections\n"
13819 "Neighbor to display information about\n"
13820 "Neighbor to display information about\n"
13821 "Display routes learned from neighbor\n")
13822{
paulbb46e942003-10-24 19:02:03 +000013823 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013824 safi_t safi;
13825
13826 if (bgp_parse_safi(argv[0], &safi)) {
13827 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13828 return CMD_WARNING;
13829 }
paulbb46e942003-10-24 19:02:03 +000013830
13831 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13832 if (! peer)
13833 return CMD_WARNING;
13834
Lou Berger651b4022016-01-12 13:42:07 -050013835 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013836 bgp_show_type_neighbor);
13837}
Lou Berger651b4022016-01-12 13:42:07 -050013838#ifdef HAVE_IPV6
13839DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13840 show_bgp_ipv6_safi_neighbor_routes_cmd,
13841 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013842 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013843 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013844 "Address family\n"
13845 "Address Family modifier\n"
13846 "Address Family modifier\n"
13847 "Detailed information on TCP and BGP neighbor connections\n"
13848 NEIGHBOR_ADDR_STR
13849 NEIGHBOR_ADDR_STR
13850 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013851{
paulfee0f4c2004-09-13 05:12:46 +000013852 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013853 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013854
Lou Berger651b4022016-01-12 13:42:07 -050013855 if (bgp_parse_safi(argv[0], &safi)) {
13856 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13857 return CMD_WARNING;
13858 }
paulfee0f4c2004-09-13 05:12:46 +000013859
Lou Berger651b4022016-01-12 13:42:07 -050013860 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013861 if (! peer)
13862 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013863
13864 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13865 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013866}
Lou Berger651b4022016-01-12 13:42:07 -050013867#endif
paulfee0f4c2004-09-13 05:12:46 +000013868
Michael Lambert95cbbd22010-07-23 14:43:04 -040013869DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13870 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13871 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13872 SHOW_STR
13873 BGP_STR
13874 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013875 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013876 "Address family\n"
13877 "Address Family modifier\n"
13878 "Address Family modifier\n"
13879 "Information about Route Server Client\n"
13880 NEIGHBOR_ADDR_STR
13881 "Network in the BGP routing table to display\n")
13882{
13883 struct bgp *bgp;
13884 struct peer *peer;
13885 safi_t safi;
13886
13887 /* BGP structure lookup. */
13888 if (argc == 4)
13889 {
13890 bgp = bgp_lookup_by_name (argv[0]);
13891 if (bgp == NULL)
13892 {
13893 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13894 return CMD_WARNING;
13895 }
13896 }
13897 else
13898 {
13899 bgp = bgp_get_default ();
13900 if (bgp == NULL)
13901 {
13902 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13903 return CMD_WARNING;
13904 }
13905 }
13906
13907 if (argc == 4) {
13908 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13909 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13910 } else {
13911 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13912 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13913 }
13914
13915 if (! peer)
13916 return CMD_WARNING;
13917
13918 if (! peer->afc[AFI_IP][safi])
13919 {
13920 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13921 VTY_NEWLINE);
13922 return CMD_WARNING;
13923}
13924
13925 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13926 PEER_FLAG_RSERVER_CLIENT))
13927 {
13928 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13929 VTY_NEWLINE);
13930 return CMD_WARNING;
13931 }
13932
13933 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13934 (argc == 4) ? argv[3] : argv[2],
13935 AFI_IP, safi, NULL, 0);
13936}
13937
13938ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13939 show_bgp_ipv4_safi_rsclient_route_cmd,
13940 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13941 SHOW_STR
13942 BGP_STR
13943 "Address family\n"
13944 "Address Family modifier\n"
13945 "Address Family modifier\n"
13946 "Information about Route Server Client\n"
13947 NEIGHBOR_ADDR_STR
13948 "Network in the BGP routing table to display\n")
13949
paulfee0f4c2004-09-13 05:12:46 +000013950
Michael Lambert95cbbd22010-07-23 14:43:04 -040013951DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
13952 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
13953 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
13954 SHOW_STR
13955 BGP_STR
13956 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013957 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013958 "Address family\n"
13959 "Address Family modifier\n"
13960 "Address Family modifier\n"
13961 "Information about Route Server Client\n"
13962 NEIGHBOR_ADDR_STR
13963 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
13964{
13965 struct bgp *bgp;
13966 struct peer *peer;
13967 safi_t safi;
13968
13969 /* BGP structure lookup. */
13970 if (argc == 4)
13971 {
13972 bgp = bgp_lookup_by_name (argv[0]);
13973 if (bgp == NULL)
13974 {
13975 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13976 return CMD_WARNING;
13977 }
13978 }
13979 else
13980 {
13981 bgp = bgp_get_default ();
13982 if (bgp == NULL)
13983 {
13984 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13985 return CMD_WARNING;
13986 }
13987 }
13988
13989 if (argc == 4) {
13990 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13991 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13992 } else {
13993 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13994 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13995 }
13996
13997 if (! peer)
13998 return CMD_WARNING;
13999
14000 if (! peer->afc[AFI_IP][safi])
14001 {
14002 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14003 VTY_NEWLINE);
14004 return CMD_WARNING;
14005}
14006
14007 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14008 PEER_FLAG_RSERVER_CLIENT))
14009{
14010 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14011 VTY_NEWLINE);
14012 return CMD_WARNING;
14013 }
14014
14015 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14016 (argc == 4) ? argv[3] : argv[2],
14017 AFI_IP, safi, NULL, 1);
14018}
14019
Lou Bergerf9b6c392016-01-12 13:42:09 -050014020DEFUN (show_ip_bgp_view_rsclient_prefix,
14021 show_ip_bgp_view_rsclient_prefix_cmd,
14022 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14023 SHOW_STR
14024 IP_STR
14025 BGP_STR
14026 "BGP view\n"
14027 "View name\n"
14028 "Information about Route Server Client\n"
14029 NEIGHBOR_ADDR_STR
14030 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14031{
14032 struct bgp *bgp;
14033 struct peer *peer;
14034
14035 /* BGP structure lookup. */
14036 if (argc == 3)
14037 {
14038 bgp = bgp_lookup_by_name (argv[0]);
14039 if (bgp == NULL)
14040 {
14041 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14042 return CMD_WARNING;
14043 }
14044 }
14045 else
14046 {
14047 bgp = bgp_get_default ();
14048 if (bgp == NULL)
14049 {
14050 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14051 return CMD_WARNING;
14052 }
14053 }
14054
14055 if (argc == 3)
14056 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14057 else
14058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14059
14060 if (! peer)
14061 return CMD_WARNING;
14062
14063 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14064 {
14065 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14066 VTY_NEWLINE);
14067 return CMD_WARNING;
14068}
14069
14070 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14071 PEER_FLAG_RSERVER_CLIENT))
14072{
14073 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14074 VTY_NEWLINE);
14075 return CMD_WARNING;
14076 }
14077
14078 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14079 (argc == 3) ? argv[2] : argv[1],
14080 AFI_IP, SAFI_UNICAST, NULL, 1);
14081}
14082
14083ALIAS (show_ip_bgp_view_rsclient_prefix,
14084 show_ip_bgp_rsclient_prefix_cmd,
14085 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14086 SHOW_STR
14087 IP_STR
14088 BGP_STR
14089 "Information about Route Server Client\n"
14090 NEIGHBOR_ADDR_STR
14091 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14092
Michael Lambert95cbbd22010-07-23 14:43:04 -040014093ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14094 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14095 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14096 SHOW_STR
14097 BGP_STR
14098 "Address family\n"
14099 "Address Family modifier\n"
14100 "Address Family modifier\n"
14101 "Information about Route Server Client\n"
14102 NEIGHBOR_ADDR_STR
14103 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014104
paul718e3742002-12-13 20:15:29 +000014105#ifdef HAVE_IPV6
Lou Bergerf9b6c392016-01-12 13:42:09 -050014106DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014107 show_bgp_view_ipv6_neighbor_routes_cmd,
14108 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014109 SHOW_STR
14110 BGP_STR
14111 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014112 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014113 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014114 "Detailed information on TCP and BGP neighbor connections\n"
14115 "Neighbor to display information about\n"
14116 "Neighbor to display information about\n"
14117 "Display routes learned from neighbor\n")
14118{
14119 struct peer *peer;
14120
14121 if (argc == 2)
14122 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14123 else
14124 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14125
14126 if (! peer)
14127 return CMD_WARNING;
14128
14129 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14130 bgp_show_type_neighbor);
14131}
14132
Lou Berger651b4022016-01-12 13:42:07 -050014133DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014134 show_bgp_view_neighbor_damp_cmd,
14135 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14136 SHOW_STR
14137 BGP_STR
14138 "BGP view\n"
14139 "View name\n"
14140 "Detailed information on TCP and BGP neighbor connections\n"
14141 "Neighbor to display information about\n"
14142 "Neighbor to display information about\n"
14143 "Display the dampened routes received from neighbor\n")
14144{
14145 struct peer *peer;
14146
14147 if (argc == 2)
14148 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14149 else
14150 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14151
14152 if (! peer)
14153 return CMD_WARNING;
14154
14155 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14156 bgp_show_type_damp_neighbor);
14157}
14158
14159DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014160 show_bgp_view_ipv6_neighbor_damp_cmd,
14161 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014162 SHOW_STR
14163 BGP_STR
14164 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014165 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014166 "Address family\n"
14167 "Detailed information on TCP and BGP neighbor connections\n"
14168 "Neighbor to display information about\n"
14169 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014170 "Display the dampened routes received from neighbor\n")
14171{
14172 struct peer *peer;
14173
14174 if (argc == 2)
14175 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14176 else
14177 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14178
14179 if (! peer)
14180 return CMD_WARNING;
14181
14182 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14183 bgp_show_type_damp_neighbor);
14184}
14185
Lou Bergerf9b6c392016-01-12 13:42:09 -050014186DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014187 show_bgp_view_ipv6_neighbor_flap_cmd,
14188 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014189 SHOW_STR
14190 BGP_STR
14191 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014192 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014193 "Address family\n"
14194 "Detailed information on TCP and BGP neighbor connections\n"
14195 "Neighbor to display information about\n"
14196 "Neighbor to display information about\n"
14197 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014198{
14199 struct peer *peer;
14200
14201 if (argc == 2)
14202 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14203 else
14204 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14205
14206 if (! peer)
14207 return CMD_WARNING;
14208
14209 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14210 bgp_show_type_flap_neighbor);
14211}
14212
Lou Bergerf9b6c392016-01-12 13:42:09 -050014213DEFUN (show_bgp_view_neighbor_flap,
14214 show_bgp_view_neighbor_flap_cmd,
14215 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14216 SHOW_STR
14217 BGP_STR
14218 "BGP view\n"
14219 "View name\n"
14220 "Detailed information on TCP and BGP neighbor connections\n"
14221 "Neighbor to display information about\n"
14222 "Neighbor to display information about\n"
14223 "Display flap statistics of the routes learned from neighbor\n")
14224{
14225 struct peer *peer;
14226
14227 if (argc == 2)
14228 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14229 else
14230 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14231
14232 if (! peer)
14233 return CMD_WARNING;
14234
14235 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14236 bgp_show_type_flap_neighbor);
14237}
14238
14239ALIAS (show_bgp_view_neighbor_flap,
14240 show_bgp_neighbor_flap_cmd,
14241 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14242 SHOW_STR
14243 BGP_STR
14244 "Detailed information on TCP and BGP neighbor connections\n"
14245 "Neighbor to display information about\n"
14246 "Neighbor to display information about\n"
14247 "Display flap statistics of the routes learned from neighbor\n")
14248
14249ALIAS (show_bgp_view_neighbor_damp,
14250 show_bgp_neighbor_damp_cmd,
14251 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14252 SHOW_STR
14253 BGP_STR
14254 "Detailed information on TCP and BGP neighbor connections\n"
14255 "Neighbor to display information about\n"
14256 "Neighbor to display information about\n"
14257 "Display the dampened routes received from neighbor\n")
14258
14259DEFUN (show_bgp_view_neighbor_routes,
14260 show_bgp_view_neighbor_routes_cmd,
14261 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14262 SHOW_STR
14263 BGP_STR
14264 "BGP view\n"
14265 "View name\n"
14266 "Detailed information on TCP and BGP neighbor connections\n"
14267 "Neighbor to display information about\n"
14268 "Neighbor to display information about\n"
14269 "Display routes learned from neighbor\n")
14270{
14271 struct peer *peer;
14272
14273 if (argc == 2)
14274 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14275 else
14276 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14277
14278 if (! peer)
14279 return CMD_WARNING;
14280
14281 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14282 bgp_show_type_neighbor);
14283}
14284
14285ALIAS (show_bgp_view_neighbor_routes,
14286 show_bgp_neighbor_routes_cmd,
14287 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14288 SHOW_STR
14289 BGP_STR
14290 "Detailed information on TCP and BGP neighbor connections\n"
14291 "Neighbor to display information about\n"
14292 "Neighbor to display information about\n"
14293 "Display routes learned from neighbor\n")
14294
paulbb46e942003-10-24 19:02:03 +000014295ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014296 show_bgp_ipv6_neighbor_routes_cmd,
14297 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14298 SHOW_STR
14299 BGP_STR
14300 "Address family\n"
14301 "Detailed information on TCP and BGP neighbor connections\n"
14302 "Neighbor to display information about\n"
14303 "Neighbor to display information about\n"
14304 "Display routes learned from neighbor\n")
14305
Lou Bergerf9b6c392016-01-12 13:42:09 -050014306/* old command */
14307ALIAS (show_bgp_view_neighbor_routes,
14308 ipv6_bgp_neighbor_routes_cmd,
14309 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14310 SHOW_STR
14311 IPV6_STR
14312 BGP_STR
14313 "Detailed information on TCP and BGP neighbor connections\n"
14314 "Neighbor to display information about\n"
14315 "Neighbor to display information about\n"
14316 "Display routes learned from neighbor\n")
14317
14318/* old command */
14319DEFUN (ipv6_mbgp_neighbor_routes,
14320 ipv6_mbgp_neighbor_routes_cmd,
14321 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14322 SHOW_STR
14323 IPV6_STR
14324 MBGP_STR
14325 "Detailed information on TCP and BGP neighbor connections\n"
14326 "Neighbor to display information about\n"
14327 "Neighbor to display information about\n"
14328 "Display routes learned from neighbor\n")
14329{
14330 struct peer *peer;
14331
14332 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14333 if (! peer)
14334 return CMD_WARNING;
14335
14336 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14337 bgp_show_type_neighbor);
14338}
14339
paulbb46e942003-10-24 19:02:03 +000014340ALIAS (show_bgp_view_neighbor_flap,
14341 show_bgp_ipv6_neighbor_flap_cmd,
14342 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14343 SHOW_STR
14344 BGP_STR
14345 "Address family\n"
14346 "Detailed information on TCP and BGP neighbor connections\n"
14347 "Neighbor to display information about\n"
14348 "Neighbor to display information about\n"
14349 "Display flap statistics of the routes learned from neighbor\n")
14350
14351ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014352 show_bgp_ipv6_neighbor_damp_cmd,
14353 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14354 SHOW_STR
14355 BGP_STR
14356 "Address family\n"
14357 "Detailed information on TCP and BGP neighbor connections\n"
14358 "Neighbor to display information about\n"
14359 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014360 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014361
Lou Berger651b4022016-01-12 13:42:07 -050014362#endif /* HAVE_IPV6 */
14363
Lou Bergerf9b6c392016-01-12 13:42:09 -050014364DEFUN (show_bgp_view_rsclient,
14365 show_bgp_view_rsclient_cmd,
14366 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14367 SHOW_STR
14368 BGP_STR
14369 "BGP view\n"
14370 "View name\n"
14371 "Information about Route Server Client\n"
14372 NEIGHBOR_ADDR_STR)
14373{
14374 struct bgp_table *table;
14375 struct peer *peer;
14376
14377 if (argc == 2)
14378 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14379 else
14380 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14381
14382 if (! peer)
14383 return CMD_WARNING;
14384
14385 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14386 {
14387 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14388 VTY_NEWLINE);
14389 return CMD_WARNING;
14390 }
14391
14392 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14393 PEER_FLAG_RSERVER_CLIENT))
14394 {
14395 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14396 VTY_NEWLINE);
14397 return CMD_WARNING;
14398 }
14399
14400 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14401
14402 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14403}
14404
14405ALIAS (show_bgp_view_rsclient,
14406 show_bgp_rsclient_cmd,
14407 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14408 SHOW_STR
14409 BGP_STR
14410 "Information about Route Server Client\n"
14411 NEIGHBOR_ADDR_STR)
14412
Lou Berger651b4022016-01-12 13:42:07 -050014413DEFUN (show_bgp_view_ipv4_rsclient,
14414 show_bgp_view_ipv4_rsclient_cmd,
14415 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014416 SHOW_STR
14417 BGP_STR
14418 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014419 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014420 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014421 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014422 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014423{
Lou Berger651b4022016-01-12 13:42:07 -050014424 struct bgp_table *table;
14425 struct peer *peer;
14426
14427 if (argc == 2)
14428 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14429 else
14430 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14431
14432 if (! peer)
14433 return CMD_WARNING;
14434
14435 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14436 {
14437 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14438 VTY_NEWLINE);
14439 return CMD_WARNING;
14440 }
14441
14442 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14443 PEER_FLAG_RSERVER_CLIENT))
14444 {
14445 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14446 VTY_NEWLINE);
14447 return CMD_WARNING;
14448 }
14449
14450 table = peer->rib[AFI_IP][SAFI_UNICAST];
14451
14452 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14453}
14454DEFUN (show_bgp_view_ipv6_rsclient,
14455 show_bgp_view_ipv6_rsclient_cmd,
14456 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14457 SHOW_STR
14458 BGP_STR
14459 "BGP view\n"
14460 "BGP view name\n"
14461 "Address Family\n"
14462 "Information about Route Server Client\n"
14463 NEIGHBOR_ADDR_STR2)
14464{
14465 struct bgp_table *table;
14466 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014467
14468 if (argc == 2)
14469 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14470 else
14471 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14472
14473 if (! peer)
14474 return CMD_WARNING;
14475
14476 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14477 {
14478 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14479 VTY_NEWLINE);
14480 return CMD_WARNING;
14481 }
14482
14483 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14484 PEER_FLAG_RSERVER_CLIENT))
14485 {
14486 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14487 VTY_NEWLINE);
14488 return CMD_WARNING;
14489 }
14490
14491 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14492
ajs5a646652004-11-05 01:25:55 +000014493 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014494}
14495
Lou Berger651b4022016-01-12 13:42:07 -050014496ALIAS (show_bgp_view_ipv4_rsclient,
14497 show_bgp_ipv4_rsclient_cmd,
14498 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014499 SHOW_STR
14500 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014501 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014502 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014503 NEIGHBOR_ADDR_STR2)
14504
14505#ifdef HAVE_IPV6
14506ALIAS (show_bgp_view_ipv6_rsclient,
14507 show_bgp_ipv6_rsclient_cmd,
14508 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14509 SHOW_STR
14510 BGP_STR
14511 "Address Family\n"
14512 "Information about Route Server Client\n"
14513 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014514
Michael Lambert95cbbd22010-07-23 14:43:04 -040014515DEFUN (show_bgp_view_ipv6_safi_rsclient,
14516 show_bgp_view_ipv6_safi_rsclient_cmd,
14517 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14518 SHOW_STR
14519 BGP_STR
14520 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014521 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014522 "Address family\n"
14523 "Address Family modifier\n"
14524 "Address Family modifier\n"
14525 "Information about Route Server Client\n"
14526 NEIGHBOR_ADDR_STR)
14527{
14528 struct bgp_table *table;
14529 struct peer *peer;
14530 safi_t safi;
14531
14532 if (argc == 3) {
14533 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14534 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14535 } else {
14536 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14537 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14538 }
14539
14540 if (! peer)
14541 return CMD_WARNING;
14542
14543 if (! peer->afc[AFI_IP6][safi])
14544 {
14545 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14546 VTY_NEWLINE);
14547 return CMD_WARNING;
14548 }
14549
14550 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14551 PEER_FLAG_RSERVER_CLIENT))
14552 {
14553 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14554 VTY_NEWLINE);
14555 return CMD_WARNING;
14556 }
14557
14558 table = peer->rib[AFI_IP6][safi];
14559
14560 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14561}
14562
14563ALIAS (show_bgp_view_ipv6_safi_rsclient,
14564 show_bgp_ipv6_safi_rsclient_cmd,
14565 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14566 SHOW_STR
14567 BGP_STR
14568 "Address family\n"
14569 "Address Family modifier\n"
14570 "Address Family modifier\n"
14571 "Information about Route Server Client\n"
14572 NEIGHBOR_ADDR_STR)
14573
paulfee0f4c2004-09-13 05:12:46 +000014574DEFUN (show_bgp_view_rsclient_route,
14575 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014576 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14577 SHOW_STR
14578 BGP_STR
14579 "BGP view\n"
14580 "View name\n"
14581 "Information about Route Server Client\n"
14582 NEIGHBOR_ADDR_STR
14583 "Network in the BGP routing table to display\n")
14584{
14585 struct bgp *bgp;
14586 struct peer *peer;
14587
14588 /* BGP structure lookup. */
14589 if (argc == 3)
14590 {
14591 bgp = bgp_lookup_by_name (argv[0]);
14592 if (bgp == NULL)
14593 {
14594 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14595 return CMD_WARNING;
14596 }
14597 }
14598 else
14599 {
14600 bgp = bgp_get_default ();
14601 if (bgp == NULL)
14602 {
14603 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14604 return CMD_WARNING;
14605 }
14606 }
14607
14608 if (argc == 3)
14609 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14610 else
14611 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14612
14613 if (! peer)
14614 return CMD_WARNING;
14615
14616 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14617 {
14618 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14619 VTY_NEWLINE);
14620 return CMD_WARNING;
14621 }
14622
14623 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14624 PEER_FLAG_RSERVER_CLIENT))
14625 {
14626 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14627 VTY_NEWLINE);
14628 return CMD_WARNING;
14629 }
14630
14631 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14632 (argc == 3) ? argv[2] : argv[1],
14633 AFI_IP6, SAFI_UNICAST, NULL, 0);
14634}
14635
14636DEFUN (show_bgp_view_ipv6_rsclient_route,
14637 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014638 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014639 SHOW_STR
14640 BGP_STR
14641 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014642 "BGP view name\n"
14643 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014644 "Information about Route Server Client\n"
14645 NEIGHBOR_ADDR_STR
14646 "Network in the BGP routing table to display\n")
14647{
14648 struct bgp *bgp;
14649 struct peer *peer;
14650
14651 /* BGP structure lookup. */
14652 if (argc == 3)
14653 {
14654 bgp = bgp_lookup_by_name (argv[0]);
14655 if (bgp == NULL)
14656 {
14657 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14658 return CMD_WARNING;
14659 }
14660 }
14661 else
14662 {
14663 bgp = bgp_get_default ();
14664 if (bgp == NULL)
14665 {
14666 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14667 return CMD_WARNING;
14668 }
14669 }
14670
14671 if (argc == 3)
14672 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14673 else
14674 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14675
14676 if (! peer)
14677 return CMD_WARNING;
14678
14679 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14680 {
14681 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14682 VTY_NEWLINE);
14683 return CMD_WARNING;
14684 }
14685
14686 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14687 PEER_FLAG_RSERVER_CLIENT))
14688 {
14689 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14690 VTY_NEWLINE);
14691 return CMD_WARNING;
14692 }
14693
14694 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14695 (argc == 3) ? argv[2] : argv[1],
14696 AFI_IP6, SAFI_UNICAST, NULL, 0);
14697}
14698
Lou Bergerf9b6c392016-01-12 13:42:09 -050014699ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014700 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014701 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14702 SHOW_STR
14703 BGP_STR
14704 "Information about Route Server Client\n"
14705 NEIGHBOR_ADDR_STR
14706 "Network in the BGP routing table to display\n")
14707
14708ALIAS (show_bgp_view_ipv6_rsclient_route,
14709 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014710 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014711 SHOW_STR
14712 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014713 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014714 "Information about Route Server Client\n"
14715 NEIGHBOR_ADDR_STR
14716 "Network in the BGP routing table to display\n")
14717
Michael Lambert95cbbd22010-07-23 14:43:04 -040014718DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14719 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14720 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14721 SHOW_STR
14722 BGP_STR
14723 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014724 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014725 "Address family\n"
14726 "Address Family modifier\n"
14727 "Address Family modifier\n"
14728 "Information about Route Server Client\n"
14729 NEIGHBOR_ADDR_STR
14730 "Network in the BGP routing table to display\n")
14731{
14732 struct bgp *bgp;
14733 struct peer *peer;
14734 safi_t safi;
14735
14736 /* BGP structure lookup. */
14737 if (argc == 4)
14738 {
14739 bgp = bgp_lookup_by_name (argv[0]);
14740 if (bgp == NULL)
14741 {
14742 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14743 return CMD_WARNING;
14744 }
14745 }
14746 else
14747 {
14748 bgp = bgp_get_default ();
14749 if (bgp == NULL)
14750 {
14751 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14752 return CMD_WARNING;
14753 }
14754 }
14755
14756 if (argc == 4) {
14757 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14758 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14759 } else {
14760 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14761 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14762 }
14763
14764 if (! peer)
14765 return CMD_WARNING;
14766
14767 if (! peer->afc[AFI_IP6][safi])
14768 {
14769 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14770 VTY_NEWLINE);
14771 return CMD_WARNING;
14772}
14773
14774 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14775 PEER_FLAG_RSERVER_CLIENT))
14776 {
14777 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14778 VTY_NEWLINE);
14779 return CMD_WARNING;
14780 }
14781
14782 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14783 (argc == 4) ? argv[3] : argv[2],
14784 AFI_IP6, safi, NULL, 0);
14785}
14786
14787ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14788 show_bgp_ipv6_safi_rsclient_route_cmd,
14789 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14790 SHOW_STR
14791 BGP_STR
14792 "Address family\n"
14793 "Address Family modifier\n"
14794 "Address Family modifier\n"
14795 "Information about Route Server Client\n"
14796 NEIGHBOR_ADDR_STR
14797 "Network in the BGP routing table to display\n")
14798
Lou Berger651b4022016-01-12 13:42:07 -050014799
paulfee0f4c2004-09-13 05:12:46 +000014800DEFUN (show_bgp_view_rsclient_prefix,
14801 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014802 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14803 SHOW_STR
14804 BGP_STR
14805 "BGP view\n"
14806 "View name\n"
14807 "Information about Route Server Client\n"
14808 NEIGHBOR_ADDR_STR
14809 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14810{
14811 struct bgp *bgp;
14812 struct peer *peer;
14813
14814 /* BGP structure lookup. */
14815 if (argc == 3)
14816 {
14817 bgp = bgp_lookup_by_name (argv[0]);
14818 if (bgp == NULL)
14819 {
14820 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14821 return CMD_WARNING;
14822 }
14823 }
14824 else
14825 {
14826 bgp = bgp_get_default ();
14827 if (bgp == NULL)
14828 {
14829 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14830 return CMD_WARNING;
14831 }
14832 }
14833
14834 if (argc == 3)
14835 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14836 else
14837 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14838
14839 if (! peer)
14840 return CMD_WARNING;
14841
14842 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14843 {
14844 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14845 VTY_NEWLINE);
14846 return CMD_WARNING;
14847 }
14848
14849 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14850 PEER_FLAG_RSERVER_CLIENT))
14851 {
14852 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14853 VTY_NEWLINE);
14854 return CMD_WARNING;
14855 }
14856
14857 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14858 (argc == 3) ? argv[2] : argv[1],
14859 AFI_IP6, SAFI_UNICAST, NULL, 1);
14860}
14861
14862DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14863 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014864 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014865 SHOW_STR
14866 BGP_STR
14867 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014868 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014869 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014870 "Information about Route Server Client\n"
14871 NEIGHBOR_ADDR_STR
14872 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14873{
14874 struct bgp *bgp;
14875 struct peer *peer;
14876
14877 /* BGP structure lookup. */
14878 if (argc == 3)
14879 {
14880 bgp = bgp_lookup_by_name (argv[0]);
14881 if (bgp == NULL)
14882 {
14883 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14884 return CMD_WARNING;
14885 }
14886 }
14887 else
14888 {
14889 bgp = bgp_get_default ();
14890 if (bgp == NULL)
14891 {
14892 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14893 return CMD_WARNING;
14894 }
14895 }
14896
14897 if (argc == 3)
14898 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14899 else
14900 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14901
14902 if (! peer)
14903 return CMD_WARNING;
14904
14905 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14906 {
14907 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14908 VTY_NEWLINE);
14909 return CMD_WARNING;
14910 }
14911
14912 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14913 PEER_FLAG_RSERVER_CLIENT))
14914 {
14915 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14916 VTY_NEWLINE);
14917 return CMD_WARNING;
14918 }
14919
14920 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14921 (argc == 3) ? argv[2] : argv[1],
14922 AFI_IP6, SAFI_UNICAST, NULL, 1);
14923}
14924
Lou Bergerf9b6c392016-01-12 13:42:09 -050014925ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014926 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014927 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14928 SHOW_STR
14929 BGP_STR
14930 "Information about Route Server Client\n"
14931 NEIGHBOR_ADDR_STR
14932 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14933
14934ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14935 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014936 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014937 SHOW_STR
14938 BGP_STR
14939 "Information about Route Server Client\n"
14940 NEIGHBOR_ADDR_STR
14941 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14942
Michael Lambert95cbbd22010-07-23 14:43:04 -040014943DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
14944 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
14945 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14946 SHOW_STR
14947 BGP_STR
14948 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014949 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014950 "Address family\n"
14951 "Address Family modifier\n"
14952 "Address Family modifier\n"
14953 "Information about Route Server Client\n"
14954 NEIGHBOR_ADDR_STR
14955 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
14956{
14957 struct bgp *bgp;
14958 struct peer *peer;
14959 safi_t safi;
14960
14961 /* BGP structure lookup. */
14962 if (argc == 4)
14963 {
14964 bgp = bgp_lookup_by_name (argv[0]);
14965 if (bgp == NULL)
14966 {
14967 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14968 return CMD_WARNING;
14969 }
14970 }
14971 else
14972 {
14973 bgp = bgp_get_default ();
14974 if (bgp == NULL)
14975 {
14976 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14977 return CMD_WARNING;
14978 }
14979 }
14980
14981 if (argc == 4) {
14982 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14983 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14984 } else {
14985 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14986 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14987 }
14988
14989 if (! peer)
14990 return CMD_WARNING;
14991
14992 if (! peer->afc[AFI_IP6][safi])
14993 {
14994 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14995 VTY_NEWLINE);
14996 return CMD_WARNING;
14997}
14998
14999 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15000 PEER_FLAG_RSERVER_CLIENT))
15001{
15002 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15003 VTY_NEWLINE);
15004 return CMD_WARNING;
15005 }
15006
15007 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15008 (argc == 4) ? argv[3] : argv[2],
15009 AFI_IP6, safi, NULL, 1);
15010}
15011
15012ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15013 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15014 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15015 SHOW_STR
15016 BGP_STR
15017 "Address family\n"
15018 "Address Family modifier\n"
15019 "Address Family modifier\n"
15020 "Information about Route Server Client\n"
15021 NEIGHBOR_ADDR_STR
15022 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15023
paul718e3742002-12-13 20:15:29 +000015024#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020015025
paul718e3742002-12-13 20:15:29 +000015026struct bgp_table *bgp_distance_table;
15027
15028struct bgp_distance
15029{
15030 /* Distance value for the IP source prefix. */
15031 u_char distance;
15032
15033 /* Name of the access-list to be matched. */
15034 char *access_list;
15035};
15036
paul94f2b392005-06-28 12:44:16 +000015037static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015038bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015039{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015040 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015041}
15042
paul94f2b392005-06-28 12:44:16 +000015043static void
paul718e3742002-12-13 20:15:29 +000015044bgp_distance_free (struct bgp_distance *bdistance)
15045{
15046 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15047}
15048
paul94f2b392005-06-28 12:44:16 +000015049static int
paulfd79ac92004-10-13 05:06:08 +000015050bgp_distance_set (struct vty *vty, const char *distance_str,
15051 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015052{
15053 int ret;
15054 struct prefix_ipv4 p;
15055 u_char distance;
15056 struct bgp_node *rn;
15057 struct bgp_distance *bdistance;
15058
15059 ret = str2prefix_ipv4 (ip_str, &p);
15060 if (ret == 0)
15061 {
15062 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15063 return CMD_WARNING;
15064 }
15065
15066 distance = atoi (distance_str);
15067
15068 /* Get BGP distance node. */
15069 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15070 if (rn->info)
15071 {
15072 bdistance = rn->info;
15073 bgp_unlock_node (rn);
15074 }
15075 else
15076 {
15077 bdistance = bgp_distance_new ();
15078 rn->info = bdistance;
15079 }
15080
15081 /* Set distance value. */
15082 bdistance->distance = distance;
15083
15084 /* Reset access-list configuration. */
15085 if (bdistance->access_list)
15086 {
15087 free (bdistance->access_list);
15088 bdistance->access_list = NULL;
15089 }
15090 if (access_list_str)
15091 bdistance->access_list = strdup (access_list_str);
15092
15093 return CMD_SUCCESS;
15094}
15095
paul94f2b392005-06-28 12:44:16 +000015096static int
paulfd79ac92004-10-13 05:06:08 +000015097bgp_distance_unset (struct vty *vty, const char *distance_str,
15098 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015099{
15100 int ret;
15101 struct prefix_ipv4 p;
15102 u_char distance;
15103 struct bgp_node *rn;
15104 struct bgp_distance *bdistance;
15105
15106 ret = str2prefix_ipv4 (ip_str, &p);
15107 if (ret == 0)
15108 {
15109 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15110 return CMD_WARNING;
15111 }
15112
15113 distance = atoi (distance_str);
15114
15115 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15116 if (! rn)
15117 {
15118 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15119 return CMD_WARNING;
15120 }
15121
15122 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015123
15124 if (bdistance->distance != distance)
15125 {
15126 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15127 return CMD_WARNING;
15128 }
15129
paul718e3742002-12-13 20:15:29 +000015130 if (bdistance->access_list)
15131 free (bdistance->access_list);
15132 bgp_distance_free (bdistance);
15133
15134 rn->info = NULL;
15135 bgp_unlock_node (rn);
15136 bgp_unlock_node (rn);
15137
15138 return CMD_SUCCESS;
15139}
15140
paul718e3742002-12-13 20:15:29 +000015141/* Apply BGP information to distance method. */
15142u_char
15143bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15144{
15145 struct bgp_node *rn;
15146 struct prefix_ipv4 q;
15147 struct peer *peer;
15148 struct bgp_distance *bdistance;
15149 struct access_list *alist;
15150 struct bgp_static *bgp_static;
15151
15152 if (! bgp)
15153 return 0;
15154
15155 if (p->family != AF_INET)
15156 return 0;
15157
15158 peer = rinfo->peer;
15159
15160 if (peer->su.sa.sa_family != AF_INET)
15161 return 0;
15162
15163 memset (&q, 0, sizeof (struct prefix_ipv4));
15164 q.family = AF_INET;
15165 q.prefix = peer->su.sin.sin_addr;
15166 q.prefixlen = IPV4_MAX_BITLEN;
15167
15168 /* Check source address. */
15169 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15170 if (rn)
15171 {
15172 bdistance = rn->info;
15173 bgp_unlock_node (rn);
15174
15175 if (bdistance->access_list)
15176 {
15177 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15178 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15179 return bdistance->distance;
15180 }
15181 else
15182 return bdistance->distance;
15183 }
15184
15185 /* Backdoor check. */
15186 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15187 if (rn)
15188 {
15189 bgp_static = rn->info;
15190 bgp_unlock_node (rn);
15191
15192 if (bgp_static->backdoor)
15193 {
15194 if (bgp->distance_local)
15195 return bgp->distance_local;
15196 else
15197 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15198 }
15199 }
15200
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015201 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015202 {
15203 if (bgp->distance_ebgp)
15204 return bgp->distance_ebgp;
15205 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15206 }
15207 else
15208 {
15209 if (bgp->distance_ibgp)
15210 return bgp->distance_ibgp;
15211 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15212 }
15213}
15214
15215DEFUN (bgp_distance,
15216 bgp_distance_cmd,
15217 "distance bgp <1-255> <1-255> <1-255>",
15218 "Define an administrative distance\n"
15219 "BGP distance\n"
15220 "Distance for routes external to the AS\n"
15221 "Distance for routes internal to the AS\n"
15222 "Distance for local routes\n")
15223{
15224 struct bgp *bgp;
15225
15226 bgp = vty->index;
15227
15228 bgp->distance_ebgp = atoi (argv[0]);
15229 bgp->distance_ibgp = atoi (argv[1]);
15230 bgp->distance_local = atoi (argv[2]);
15231 return CMD_SUCCESS;
15232}
15233
15234DEFUN (no_bgp_distance,
15235 no_bgp_distance_cmd,
15236 "no distance bgp <1-255> <1-255> <1-255>",
15237 NO_STR
15238 "Define an administrative distance\n"
15239 "BGP distance\n"
15240 "Distance for routes external to the AS\n"
15241 "Distance for routes internal to the AS\n"
15242 "Distance for local routes\n")
15243{
15244 struct bgp *bgp;
15245
15246 bgp = vty->index;
15247
15248 bgp->distance_ebgp= 0;
15249 bgp->distance_ibgp = 0;
15250 bgp->distance_local = 0;
15251 return CMD_SUCCESS;
15252}
15253
15254ALIAS (no_bgp_distance,
15255 no_bgp_distance2_cmd,
15256 "no distance bgp",
15257 NO_STR
15258 "Define an administrative distance\n"
15259 "BGP distance\n")
15260
15261DEFUN (bgp_distance_source,
15262 bgp_distance_source_cmd,
15263 "distance <1-255> A.B.C.D/M",
15264 "Define an administrative distance\n"
15265 "Administrative distance\n"
15266 "IP source prefix\n")
15267{
15268 bgp_distance_set (vty, argv[0], argv[1], NULL);
15269 return CMD_SUCCESS;
15270}
15271
15272DEFUN (no_bgp_distance_source,
15273 no_bgp_distance_source_cmd,
15274 "no distance <1-255> A.B.C.D/M",
15275 NO_STR
15276 "Define an administrative distance\n"
15277 "Administrative distance\n"
15278 "IP source prefix\n")
15279{
15280 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15281 return CMD_SUCCESS;
15282}
15283
15284DEFUN (bgp_distance_source_access_list,
15285 bgp_distance_source_access_list_cmd,
15286 "distance <1-255> A.B.C.D/M WORD",
15287 "Define an administrative distance\n"
15288 "Administrative distance\n"
15289 "IP source prefix\n"
15290 "Access list name\n")
15291{
15292 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15293 return CMD_SUCCESS;
15294}
15295
15296DEFUN (no_bgp_distance_source_access_list,
15297 no_bgp_distance_source_access_list_cmd,
15298 "no distance <1-255> A.B.C.D/M WORD",
15299 NO_STR
15300 "Define an administrative distance\n"
15301 "Administrative distance\n"
15302 "IP source prefix\n"
15303 "Access list name\n")
15304{
15305 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15306 return CMD_SUCCESS;
15307}
David Lamparter6b0655a2014-06-04 06:53:35 +020015308
paul718e3742002-12-13 20:15:29 +000015309DEFUN (bgp_damp_set,
15310 bgp_damp_set_cmd,
15311 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15312 "BGP Specific commands\n"
15313 "Enable route-flap dampening\n"
15314 "Half-life time for the penalty\n"
15315 "Value to start reusing a route\n"
15316 "Value to start suppressing a route\n"
15317 "Maximum duration to suppress a stable route\n")
15318{
15319 struct bgp *bgp;
15320 int half = DEFAULT_HALF_LIFE * 60;
15321 int reuse = DEFAULT_REUSE;
15322 int suppress = DEFAULT_SUPPRESS;
15323 int max = 4 * half;
15324
15325 if (argc == 4)
15326 {
15327 half = atoi (argv[0]) * 60;
15328 reuse = atoi (argv[1]);
15329 suppress = atoi (argv[2]);
15330 max = atoi (argv[3]) * 60;
15331 }
15332 else if (argc == 1)
15333 {
15334 half = atoi (argv[0]) * 60;
15335 max = 4 * half;
15336 }
15337
15338 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015339
15340 if (suppress < reuse)
15341 {
15342 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15343 VTY_NEWLINE);
15344 return 0;
15345 }
15346
paul718e3742002-12-13 20:15:29 +000015347 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15348 half, reuse, suppress, max);
15349}
15350
15351ALIAS (bgp_damp_set,
15352 bgp_damp_set2_cmd,
15353 "bgp dampening <1-45>",
15354 "BGP Specific commands\n"
15355 "Enable route-flap dampening\n"
15356 "Half-life time for the penalty\n")
15357
15358ALIAS (bgp_damp_set,
15359 bgp_damp_set3_cmd,
15360 "bgp dampening",
15361 "BGP Specific commands\n"
15362 "Enable route-flap dampening\n")
15363
15364DEFUN (bgp_damp_unset,
15365 bgp_damp_unset_cmd,
15366 "no bgp dampening",
15367 NO_STR
15368 "BGP Specific commands\n"
15369 "Enable route-flap dampening\n")
15370{
15371 struct bgp *bgp;
15372
15373 bgp = vty->index;
15374 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15375}
15376
15377ALIAS (bgp_damp_unset,
15378 bgp_damp_unset2_cmd,
15379 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15380 NO_STR
15381 "BGP Specific commands\n"
15382 "Enable route-flap dampening\n"
15383 "Half-life time for the penalty\n"
15384 "Value to start reusing a route\n"
15385 "Value to start suppressing a route\n"
15386 "Maximum duration to suppress a stable route\n")
15387
Lou Bergerf9b6c392016-01-12 13:42:09 -050015388DEFUN (show_ip_bgp_dampened_paths,
15389 show_ip_bgp_dampened_paths_cmd,
15390 "show ip bgp dampened-paths",
15391 SHOW_STR
15392 IP_STR
15393 BGP_STR
15394 "Display paths suppressed due to dampening\n")
15395{
15396 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15397 NULL);
15398}
15399
15400ALIAS (show_ip_bgp_dampened_paths,
15401 show_ip_bgp_damp_dampened_paths_cmd,
15402 "show ip bgp dampening dampened-paths",
15403 SHOW_STR
15404 IP_STR
15405 BGP_STR
15406 "Display detailed information about dampening\n"
15407 "Display paths suppressed due to dampening\n")
15408
15409DEFUN (show_ip_bgp_flap_statistics,
15410 show_ip_bgp_flap_statistics_cmd,
15411 "show ip bgp flap-statistics",
15412 SHOW_STR
15413 IP_STR
15414 BGP_STR
15415 "Display flap statistics of routes\n")
15416{
15417 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15418 bgp_show_type_flap_statistics, NULL);
15419}
15420
15421ALIAS (show_ip_bgp_flap_statistics,
15422 show_ip_bgp_damp_flap_statistics_cmd,
15423 "show ip bgp dampening flap-statistics",
15424 SHOW_STR
15425 IP_STR
15426 BGP_STR
15427 "Display detailed information about dampening\n"
15428 "Display flap statistics of routes\n")
15429
Lou Berger651b4022016-01-12 13:42:07 -050015430DEFUN (show_bgp_ipv4_safi_dampened_paths,
15431 show_bgp_ipv4_safi_dampened_paths_cmd,
15432 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015433 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015434 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015435 IP_STR
15436 "Address Family modifier\n"
15437 "Address Family modifier\n"
15438 "Address Family modifier\n"
15439 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015440 "Display paths suppressed due to dampening\n")
15441{
Lou Berger651b4022016-01-12 13:42:07 -050015442 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015443
Lou Berger651b4022016-01-12 13:42:07 -050015444 if (bgp_parse_safi(argv[0], &safi)) {
15445 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15446 return CMD_WARNING;
15447 }
15448
15449 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15450}
15451ALIAS (show_bgp_ipv4_safi_dampened_paths,
15452 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15453 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015454 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015455 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015456 IP_STR
15457 "Address Family modifier\n"
15458 "Address Family modifier\n"
15459 "Address Family modifier\n"
15460 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015461 "Display detailed information about dampening\n"
15462 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015463#ifdef HAVE_IPV6
15464DEFUN (show_bgp_ipv6_safi_dampened_paths,
15465 show_bgp_ipv6_safi_dampened_paths_cmd,
15466 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015467 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015468 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015469 IPV6_STR
15470 "Address Family modifier\n"
15471 "Address Family modifier\n"
15472 "Address Family modifier\n"
15473 "Address Family modifier\n"
15474 "Display paths suppressed due to dampening\n")
15475{
15476 safi_t safi;
15477
15478 if (bgp_parse_safi(argv[0], &safi)) {
15479 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15480 return CMD_WARNING;
15481 }
15482
15483 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15484}
15485ALIAS (show_bgp_ipv6_safi_dampened_paths,
15486 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15487 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15488 SHOW_STR
15489 BGP_STR
15490 IPV6_STR
15491 "Address Family modifier\n"
15492 "Address Family modifier\n"
15493 "Address Family modifier\n"
15494 "Address Family modifier\n"
15495 "Display detailed information about dampening\n"
15496 "Display paths suppressed due to dampening\n")
15497#endif
15498
15499DEFUN (show_bgp_ipv4_safi_flap_statistics,
15500 show_bgp_ipv4_safi_flap_statistics_cmd,
15501 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15502 SHOW_STR
15503 BGP_STR
15504 "Address Family\n"
15505 "Address Family modifier\n"
15506 "Address Family modifier\n"
15507 "Address Family modifier\n"
15508 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015509 "Display flap statistics of routes\n")
15510{
Lou Berger651b4022016-01-12 13:42:07 -050015511 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015512
Lou Berger651b4022016-01-12 13:42:07 -050015513 if (bgp_parse_safi(argv[0], &safi)) {
15514 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15515 return CMD_WARNING;
15516 }
15517
15518 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15519}
15520ALIAS (show_bgp_ipv4_safi_flap_statistics,
15521 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15522 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015523 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015524 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015525 "Address Family\n"
15526 "Address Family modifier\n"
15527 "Address Family modifier\n"
15528 "Address Family modifier\n"
15529 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015530 "Display detailed information about dampening\n"
15531 "Display flap statistics of routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050015532#ifdef HAVE_IPV6
15533DEFUN (show_bgp_ipv6_safi_flap_statistics,
15534 show_bgp_ipv6_safi_flap_statistics_cmd,
15535 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15536 SHOW_STR
15537 BGP_STR
15538 "Address Family\n"
15539 "Address Family modifier\n"
15540 "Address Family modifier\n"
15541 "Address Family modifier\n"
15542 "Address Family modifier\n"
15543 "Display flap statistics of routes\n")
15544{
15545 safi_t safi;
15546
15547 if (bgp_parse_safi(argv[0], &safi)) {
15548 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15549 return CMD_WARNING;
15550 }
15551
15552 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15553}
15554ALIAS (show_bgp_ipv6_safi_flap_statistics,
15555 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15556 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15557 SHOW_STR
15558 BGP_STR
15559 "Address Family\n"
15560 "Address Family modifier\n"
15561 "Address Family modifier\n"
15562 "Address Family modifier\n"
15563 "Address Family modifier\n"
15564 "Display detailed information about dampening\n"
15565 "Display flap statistics of routes\n")
15566#endif
Balaji3921cc52015-05-16 23:12:17 +053015567
paul718e3742002-12-13 20:15:29 +000015568/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015569static int
paulfd79ac92004-10-13 05:06:08 +000015570bgp_clear_damp_route (struct vty *vty, const char *view_name,
15571 const char *ip_str, afi_t afi, safi_t safi,
15572 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015573{
15574 int ret;
15575 struct prefix match;
15576 struct bgp_node *rn;
15577 struct bgp_node *rm;
15578 struct bgp_info *ri;
15579 struct bgp_info *ri_temp;
15580 struct bgp *bgp;
15581 struct bgp_table *table;
15582
15583 /* BGP structure lookup. */
15584 if (view_name)
15585 {
15586 bgp = bgp_lookup_by_name (view_name);
15587 if (bgp == NULL)
15588 {
15589 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15590 return CMD_WARNING;
15591 }
15592 }
15593 else
15594 {
15595 bgp = bgp_get_default ();
15596 if (bgp == NULL)
15597 {
15598 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15599 return CMD_WARNING;
15600 }
15601 }
15602
15603 /* Check IP address argument. */
15604 ret = str2prefix (ip_str, &match);
15605 if (! ret)
15606 {
15607 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15608 return CMD_WARNING;
15609 }
15610
15611 match.family = afi2family (afi);
15612
Lou Berger298cc2f2016-01-12 13:42:02 -050015613 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015614 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015615 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015616 {
15617 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15618 continue;
15619
15620 if ((table = rn->info) != NULL)
15621 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015622 {
15623 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15624 {
15625 ri = rm->info;
15626 while (ri)
15627 {
15628 if (ri->extra && ri->extra->damp_info)
15629 {
15630 ri_temp = ri->next;
15631 bgp_damp_info_free (ri->extra->damp_info, 1);
15632 ri = ri_temp;
15633 }
15634 else
15635 ri = ri->next;
15636 }
15637 }
15638
15639 bgp_unlock_node (rm);
15640 }
paul718e3742002-12-13 20:15:29 +000015641 }
15642 }
15643 else
15644 {
15645 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015646 {
15647 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15648 {
15649 ri = rn->info;
15650 while (ri)
15651 {
15652 if (ri->extra && ri->extra->damp_info)
15653 {
15654 ri_temp = ri->next;
15655 bgp_damp_info_free (ri->extra->damp_info, 1);
15656 ri = ri_temp;
15657 }
15658 else
15659 ri = ri->next;
15660 }
15661 }
15662
15663 bgp_unlock_node (rn);
15664 }
paul718e3742002-12-13 20:15:29 +000015665 }
15666
15667 return CMD_SUCCESS;
15668}
15669
15670DEFUN (clear_ip_bgp_dampening,
15671 clear_ip_bgp_dampening_cmd,
15672 "clear ip bgp dampening",
15673 CLEAR_STR
15674 IP_STR
15675 BGP_STR
15676 "Clear route flap dampening information\n")
15677{
15678 bgp_damp_info_clean ();
15679 return CMD_SUCCESS;
15680}
15681
15682DEFUN (clear_ip_bgp_dampening_prefix,
15683 clear_ip_bgp_dampening_prefix_cmd,
15684 "clear ip bgp dampening A.B.C.D/M",
15685 CLEAR_STR
15686 IP_STR
15687 BGP_STR
15688 "Clear route flap dampening information\n"
15689 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15690{
15691 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15692 SAFI_UNICAST, NULL, 1);
15693}
15694
15695DEFUN (clear_ip_bgp_dampening_address,
15696 clear_ip_bgp_dampening_address_cmd,
15697 "clear ip bgp dampening A.B.C.D",
15698 CLEAR_STR
15699 IP_STR
15700 BGP_STR
15701 "Clear route flap dampening information\n"
15702 "Network to clear damping information\n")
15703{
15704 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15705 SAFI_UNICAST, NULL, 0);
15706}
15707
15708DEFUN (clear_ip_bgp_dampening_address_mask,
15709 clear_ip_bgp_dampening_address_mask_cmd,
15710 "clear ip bgp dampening A.B.C.D A.B.C.D",
15711 CLEAR_STR
15712 IP_STR
15713 BGP_STR
15714 "Clear route flap dampening information\n"
15715 "Network to clear damping information\n"
15716 "Network mask\n")
15717{
15718 int ret;
15719 char prefix_str[BUFSIZ];
15720
15721 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15722 if (! ret)
15723 {
15724 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15725 return CMD_WARNING;
15726 }
15727
15728 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15729 SAFI_UNICAST, NULL, 0);
15730}
David Lamparter6b0655a2014-06-04 06:53:35 +020015731
Lou Berger298cc2f2016-01-12 13:42:02 -050015732/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015733static int
paul718e3742002-12-13 20:15:29 +000015734bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15735 afi_t afi, safi_t safi, int *write)
15736{
15737 struct bgp_node *prn;
15738 struct bgp_node *rn;
15739 struct bgp_table *table;
15740 struct prefix *p;
15741 struct prefix_rd *prd;
15742 struct bgp_static *bgp_static;
15743 u_int32_t label;
15744 char buf[SU_ADDRSTRLEN];
15745 char rdbuf[RD_ADDRSTRLEN];
15746
15747 /* Network configuration. */
15748 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15749 if ((table = prn->info) != NULL)
15750 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15751 if ((bgp_static = rn->info) != NULL)
15752 {
15753 p = &rn->p;
15754 prd = (struct prefix_rd *) &prn->p;
15755
15756 /* "address-family" display. */
15757 bgp_config_write_family_header (vty, afi, safi, write);
15758
15759 /* "network" configuration display. */
15760 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15761 label = decode_label (bgp_static->tag);
15762
15763 vty_out (vty, " network %s/%d rd %s tag %d",
15764 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15765 p->prefixlen,
15766 rdbuf, label);
15767 vty_out (vty, "%s", VTY_NEWLINE);
15768 }
15769 return 0;
15770}
15771
15772/* Configuration of static route announcement and aggregate
15773 information. */
15774int
15775bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15776 afi_t afi, safi_t safi, int *write)
15777{
15778 struct bgp_node *rn;
15779 struct prefix *p;
15780 struct bgp_static *bgp_static;
15781 struct bgp_aggregate *bgp_aggregate;
15782 char buf[SU_ADDRSTRLEN];
15783
Lou Berger298cc2f2016-01-12 13:42:02 -050015784 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000015785 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
15786
15787 /* Network configuration. */
15788 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
15789 if ((bgp_static = rn->info) != NULL)
15790 {
15791 p = &rn->p;
15792
15793 /* "address-family" display. */
15794 bgp_config_write_family_header (vty, afi, safi, write);
15795
15796 /* "network" configuration display. */
15797 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15798 {
15799 u_int32_t destination;
15800 struct in_addr netmask;
15801
15802 destination = ntohl (p->u.prefix4.s_addr);
15803 masklen2ip (p->prefixlen, &netmask);
15804 vty_out (vty, " network %s",
15805 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
15806
15807 if ((IN_CLASSC (destination) && p->prefixlen == 24)
15808 || (IN_CLASSB (destination) && p->prefixlen == 16)
15809 || (IN_CLASSA (destination) && p->prefixlen == 8)
15810 || p->u.prefix4.s_addr == 0)
15811 {
15812 /* Natural mask is not display. */
15813 }
15814 else
15815 vty_out (vty, " mask %s", inet_ntoa (netmask));
15816 }
15817 else
15818 {
15819 vty_out (vty, " network %s/%d",
15820 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15821 p->prefixlen);
15822 }
15823
15824 if (bgp_static->rmap.name)
15825 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000015826 else
15827 {
15828 if (bgp_static->backdoor)
15829 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000015830 }
paul718e3742002-12-13 20:15:29 +000015831
15832 vty_out (vty, "%s", VTY_NEWLINE);
15833 }
15834
15835 /* Aggregate-address configuration. */
15836 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
15837 if ((bgp_aggregate = rn->info) != NULL)
15838 {
15839 p = &rn->p;
15840
15841 /* "address-family" display. */
15842 bgp_config_write_family_header (vty, afi, safi, write);
15843
15844 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
15845 {
15846 struct in_addr netmask;
15847
15848 masklen2ip (p->prefixlen, &netmask);
15849 vty_out (vty, " aggregate-address %s %s",
15850 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15851 inet_ntoa (netmask));
15852 }
15853 else
15854 {
15855 vty_out (vty, " aggregate-address %s/%d",
15856 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15857 p->prefixlen);
15858 }
15859
15860 if (bgp_aggregate->as_set)
15861 vty_out (vty, " as-set");
15862
15863 if (bgp_aggregate->summary_only)
15864 vty_out (vty, " summary-only");
15865
15866 vty_out (vty, "%s", VTY_NEWLINE);
15867 }
15868
15869 return 0;
15870}
15871
15872int
15873bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
15874{
15875 struct bgp_node *rn;
15876 struct bgp_distance *bdistance;
15877
15878 /* Distance configuration. */
15879 if (bgp->distance_ebgp
15880 && bgp->distance_ibgp
15881 && bgp->distance_local
15882 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
15883 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
15884 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
15885 vty_out (vty, " distance bgp %d %d %d%s",
15886 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
15887 VTY_NEWLINE);
15888
15889 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
15890 if ((bdistance = rn->info) != NULL)
15891 {
15892 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
15893 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
15894 bdistance->access_list ? bdistance->access_list : "",
15895 VTY_NEWLINE);
15896 }
15897
15898 return 0;
15899}
15900
15901/* Allocate routing table structure and install commands. */
15902void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015903bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000015904{
15905 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000015906 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000015907
15908 /* IPv4 BGP commands. */
15909 install_element (BGP_NODE, &bgp_network_cmd);
15910 install_element (BGP_NODE, &bgp_network_mask_cmd);
15911 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
15912 install_element (BGP_NODE, &bgp_network_route_map_cmd);
15913 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
15914 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
15915 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
15916 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
15917 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
15918 install_element (BGP_NODE, &no_bgp_network_cmd);
15919 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
15920 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
15921 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
15922 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
15923 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15924 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
15925 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
15926 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
15927
15928 install_element (BGP_NODE, &aggregate_address_cmd);
15929 install_element (BGP_NODE, &aggregate_address_mask_cmd);
15930 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
15931 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
15932 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
15933 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
15934 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
15935 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
15936 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
15937 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
15938 install_element (BGP_NODE, &no_aggregate_address_cmd);
15939 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
15940 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
15941 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
15942 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
15943 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
15944 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
15945 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
15946 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15947 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15948
15949 /* IPv4 unicast configuration. */
15950 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
15951 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
15952 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
15953 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
15954 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
15955 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000015956 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000015957 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
15958 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
15959 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
15960 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
15961 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000015962
paul718e3742002-12-13 20:15:29 +000015963 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
15964 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
15965 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
15966 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
15967 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
15968 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
15969 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
15970 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
15971 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
15972 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
15973 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
15974 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
15975 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
15976 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
15977 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
15978 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
15979 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
15980 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
15981 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
15982 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
15983
15984 /* IPv4 multicast configuration. */
15985 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
15986 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
15987 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
15988 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
15989 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
15990 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
15991 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
15992 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
15993 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
15994 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
15995 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
15996 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
15997 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
15998 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
15999 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16000 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16001 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16002 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16003 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16004 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16005 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16006 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16007 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16008 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16009 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16010 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16011 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16012 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16013 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16014 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16015 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16016 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16017
Michael Lambert95cbbd22010-07-23 14:43:04 -040016018 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016019 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016020 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16021 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16022 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16023 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16024 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16025 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16026 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16027 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16028 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016029 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016030 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16031 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16032 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16033 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16034 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16035 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16036 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16037 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16038 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16039 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16040 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16041 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16042 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16043 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16044 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16045 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16046 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16047 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16048 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16049 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16050 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16051 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16052 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16053 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16054 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16055 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16056 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16057 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016058 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16059 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16060 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16061 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16062 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016063 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16064 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16065 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16066 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16067 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16068 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16069 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16070 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16071 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16072 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16073 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16074 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16075 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16076 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16077 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16078 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16079 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16080 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16081 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016082 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016083 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16084 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16085 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16086 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16087 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16088 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16089 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16090 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16091 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16092 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16093 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16094 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16095 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16096 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16097 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16098 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16099 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16100 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16101 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16102 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16103 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16104 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16105 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16106 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16107 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16108 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16109 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16110 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16111 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16112 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16113 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16114 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16115 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16116 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16117 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16118 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16119 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16120 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16121 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16122 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16123 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16124 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16125 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16126 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16127 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016128 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016129 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016130 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016131 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016132 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016133 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016134
16135 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016136 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016137 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16138 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16139 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16140 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16141 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016142 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016143 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16144 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16145 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16146 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16147 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16148 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16149 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16150 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16151 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16152 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16153 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16154 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16155 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16156 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16157 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16158 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016159 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16160 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16161 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16162 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16163 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016164 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16165 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16166 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16167 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16168 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16169 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16170 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16171 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016172 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016173 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016174 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016175 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016176
Michael Lambert95cbbd22010-07-23 14:43:04 -040016177 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016178 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016179 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_route_cmd);
16180 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_route_cmd);
16181 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16182 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16183 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_route_cmd);
16184 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_route_cmd);
16185 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16186 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16187 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016188 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016189 install_element (ENABLE_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16190 install_element (ENABLE_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16191 install_element (ENABLE_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16192 install_element (ENABLE_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16193 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16194 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16195 install_element (ENABLE_NODE, &show_bgp_afi_safi_view_cmd);
16196 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_route_cmd);
16197 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16198 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16199 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16200 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_list_cmd);
16201 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16202 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16203 install_element (ENABLE_NODE, &show_bgp_ipv4_filter_list_cmd);
16204 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16205 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16206 install_element (ENABLE_NODE, &show_bgp_ipv4_route_map_cmd);
16207 install_element (ENABLE_NODE, &show_bgp_ipv4_cidr_only_cmd);
16208 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16209 install_element (ENABLE_NODE, &show_bgp_ipv4_community_cmd);
16210 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_cmd);
16211 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_cmd);
16212 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_cmd);
16213 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_cmd);
16214 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_cmd);
16215 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_cmd);
16216 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016217 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16218 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
16219 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
16220 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
16221 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016222 install_element (ENABLE_NODE, &show_bgp_ipv4_community_exact_cmd);
16223 install_element (ENABLE_NODE, &show_bgp_ipv4_community2_exact_cmd);
16224 install_element (ENABLE_NODE, &show_bgp_ipv4_community3_exact_cmd);
16225 install_element (ENABLE_NODE, &show_bgp_ipv4_community4_exact_cmd);
16226 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16227 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16228 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16229 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16230 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_cmd);
16231 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16232 install_element (ENABLE_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16233 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16234 install_element (ENABLE_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16235 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16236 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16237 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16238 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16239 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16240 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016241 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016242 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16243 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16244 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16245 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16246 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16247 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16248 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16249 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16250 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16251 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16252 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16253 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16254 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16255 install_element (ENABLE_NODE, &show_bgp_ipv6_flap_address_cmd);
16256 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16257 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16258 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16259 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16260 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16261 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16262 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16263 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16264 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16265 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16266 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16267 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16268 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16269 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16270 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16271 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16272 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16273 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16274 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16275 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16276 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16277 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16278 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16279 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16280 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16281 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16282 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16283 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16284 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16285 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16286 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016287 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016288 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016289 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016290 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016291 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016292 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016293
16294 /* BGP dampening clear commands */
16295 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16296 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16297 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16298 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16299
Paul Jakmaff7924f2006-09-04 01:10:36 +000016300 /* prefix count */
Lou Berger651b4022016-01-12 13:42:07 -050016301 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_neighbor_prefix_counts_cmd);
16302 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000016303#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000016304 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
16305
paul718e3742002-12-13 20:15:29 +000016306 /* New config IPv6 BGP commands. */
16307 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16308 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16309 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16310 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16311
16312 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16313 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16314 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16315 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16316
G.Balaji73bfe0b2011-09-23 22:36:20 +053016317 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16318 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16319
paul718e3742002-12-13 20:15:29 +000016320 /* Old config IPv6 BGP commands. */
16321 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16322 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16323
16324 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16325 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16326 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16327 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16328
Michael Lambert95cbbd22010-07-23 14:43:04 -040016329 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016330 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016331 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016332 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016333 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016334 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016335 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016336 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016337 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016338 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16341 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16342 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016346 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016347 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016348 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016349 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016350 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016351 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016352 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016353 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016354 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016356 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016357 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016358 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016359 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016360 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016361 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016362 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016363 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016364 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016365 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016366 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016367 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016368 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016369 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016370 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16371 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016372 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016373 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016374 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016375 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016376 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016377
16378 /* Restricted:
16379 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16380 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016381 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016382 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016383 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016384 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016385 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16386 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16387 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16388 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16389 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16390 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16391 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16392 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16393 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016394 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016395 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016396 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016397 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016398 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016399 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016400 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016401 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016402 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016403 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016404
Michael Lambert95cbbd22010-07-23 14:43:04 -040016405 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016406 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016407 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016408 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016409 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016410 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016411 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016412 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016413 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016414 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community_cmd);
16415 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community2_cmd);
16416 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community3_cmd);
16417 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community4_cmd);
16418 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16419 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16420 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16421 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016422 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016423 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016424 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016425 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016426 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016427 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016428 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016429 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016430 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016431 install_element (ENABLE_NODE, &show_bgp_ipv4_rsclient_cmd);
16432 install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016433 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016434 install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016435 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016436 install_element (ENABLE_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016437 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016438 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016439 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016440 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016441 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016442 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016443 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016444 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016445 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016446 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016447 install_element (ENABLE_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16448 install_element (ENABLE_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016449 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016450 install_element (ENABLE_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016451 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016452 install_element (ENABLE_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016453 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000016454
16455 /* Statistics */
16456 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016457 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016458#endif /* HAVE_IPV6 */
16459
16460 install_element (BGP_NODE, &bgp_distance_cmd);
16461 install_element (BGP_NODE, &no_bgp_distance_cmd);
16462 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16463 install_element (BGP_NODE, &bgp_distance_source_cmd);
16464 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16465 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16466 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
16467
16468 install_element (BGP_NODE, &bgp_damp_set_cmd);
16469 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16470 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16471 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16472 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16473 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16474 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16475 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16476 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16477 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016478
16479 /* Deprecated AS-Pathlimit commands */
16480 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16481 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16482 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16483 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16484 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16485 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16486
16487 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16488 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16489 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16490 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16491 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16492 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16493
16494 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16495 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16496 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16497 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16498 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16499 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16500
16501 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16502 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16503 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16504 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16505 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16506 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16507
16508 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16509 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16510 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16511 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16512 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16513 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16514
16515 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16516 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16517 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16518 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16519 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16520 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016521
16522#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016523 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16524 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016525#endif
Lou Bergerf9b6c392016-01-12 13:42:09 -050016526
16527 /* old style commands */
16528 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16530 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
16531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16532 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16533 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16534 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16536 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16537 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16538 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16539 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16540 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16541 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16542 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16543 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16545 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16547 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16548 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16549 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16550 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16551 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16552 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16553 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16554 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16555 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16556 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16558 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16559 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16561 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16562 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16563 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16564 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16565 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16566 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16567 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16568 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16569 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16570 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16571 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16572 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16573 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16574 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16575 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16576 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16577 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16578 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16579 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16580 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16581 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16582 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16583 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
16584 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
16585 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16586 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16587 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16588 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16589 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16590 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16591 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16592 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16593 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16594 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16595 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16596 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16597 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16598 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16599 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16600 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16601 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16602 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16603 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16604 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16605 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16606 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16607 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16608 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16609 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16610 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16611 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
16612 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
16613 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16614 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16615 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16616 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16617 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16618 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16619 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16620 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16621 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16622 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16623 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16624 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16625 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16626 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16627 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16628 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16629 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16630 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16631 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16632 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16633 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16634 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16635 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16636 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16637 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16638 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16639 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16640 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
16641 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
16642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
16643 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
16644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
16645 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16646 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16647 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
16648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
16649 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16650 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16651 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
16652 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
16653 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
16654 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
16655 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16656 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
16657 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16658 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
16659 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16660 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
16661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16662 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
16663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16664 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
16665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16666 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
16667 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
16668 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
16669 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
16670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
16671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
16672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
16673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
16674 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
16675 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
16676 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
16677 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
16678 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16682 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
16683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16684 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
16685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16686 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
16687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16688 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16689 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16690 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16692 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
16693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16694 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16696 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
16697 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
16698 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16699 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
16700 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16701 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
16702 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
16703 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
16704 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16705 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16706 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
16707 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
16708 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
16709 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16710 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16711 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16712 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16713 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16714 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
16715 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16716 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
16717 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
16718 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
16719 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
16720 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16721 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16722 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16723 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
16724 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16725 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
16726 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16727 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16728 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
16729 install_element (VIEW_NODE, &show_bgp_cmd);
16730 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16731 install_element (VIEW_NODE, &show_bgp_route_cmd);
16732 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
16733 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16734 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16735 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16736 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16737 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16738 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16739 install_element (VIEW_NODE, &show_bgp_community_cmd);
16740 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16741 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16742 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16743 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16744 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16745 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16746 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16747 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16748 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16749 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16750 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16751 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16752 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16753 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16754 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16755 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16756 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16757 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16758 install_element (VIEW_NODE, &show_bgp_view_cmd);
16759 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16760 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16761 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16762 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16763 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16764 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16765 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16766 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16767 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
16768 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16769 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
16770 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16771 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16772 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16773 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16774 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16775 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16776 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16777 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16778 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16779 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16780 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16781 install_element (ENABLE_NODE, &show_bgp_cmd);
16782 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
16783 install_element (ENABLE_NODE, &show_bgp_route_cmd);
16784 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
16785 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
16786 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
16787 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
16788 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
16789 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
16790 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
16791 install_element (ENABLE_NODE, &show_bgp_community_cmd);
16792 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
16793 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
16794 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
16795 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
16796 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
16797 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
16798 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
16799 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16800 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
16801 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
16802 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
16803 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
16804 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
16805 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16806 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
16807 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
16808 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
16809 install_element (ENABLE_NODE, &show_bgp_view_cmd);
16810 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
16811 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
16812 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16813 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16814 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
16815 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16816 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
16817 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
16818 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
16819 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16820 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
16821 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16822 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16823 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16824 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16825 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16826 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16827 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16828 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16829 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16830 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16831 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16832 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16833 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16834 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16835 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16836 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16837 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16838 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16839 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
16857 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
16858 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
16859 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
16860 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
16861 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
16862 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
16863 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
16864 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
16865 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
16866 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
16867 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
16868 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
16869 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
16870 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
16871 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
16872 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
16873 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16874 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16875 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
16876 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
16877 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
16878 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
16879 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16880 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
16881 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
16882 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
16883 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
16884 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
16885 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
16886 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
16887 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16888 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16889 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16890 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
16891 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16892 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
16893 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
16894 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
16895 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
16896 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
16897 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
16898 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
16899 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
16900 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
16901 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
16902 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
16903 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
16904 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
16905 /* old with name safi collision */
16906 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16907 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16908 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16909 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16910 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16911 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16912 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16913 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16914 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16915 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16916 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16917 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16918 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16919 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16920 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16921 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
16922 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
16923 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
16924 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
16925 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
16926 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
16927 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
16928 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
16929 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
16930 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
16931 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16932 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
16933 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
16934
16935 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16936 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16937 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16938 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
16939 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
16940 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
16941
16942 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16943 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16944 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16945 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
16946 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
16947 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016948}
Chris Caputo228da422009-07-18 05:44:03 +000016949
16950void
16951bgp_route_finish (void)
16952{
16953 bgp_table_unlock (bgp_distance_table);
16954 bgp_distance_table = NULL;
16955}