blob: 72e1005af7621d728efb610f28268e9d99120528 [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"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050058#include "bgpd/bgp_nht.c"
paul718e3742002-12-13 20:15:29 +000059
60/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070061extern const char *bgp_origin_str[];
62extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020063
paul94f2b392005-06-28 12:44:16 +000064static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000065bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000066 struct prefix_rd *prd)
67{
68 struct bgp_node *rn;
69 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000070
71 assert (table);
72 if (!table)
73 return NULL;
74
Lou Berger298cc2f2016-01-12 13:42:02 -050075 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000076 {
paulfee0f4c2004-09-13 05:12:46 +000077 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000078
79 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000080 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000081 else
82 bgp_unlock_node (prn);
83 table = prn->info;
84 }
paul718e3742002-12-13 20:15:29 +000085
86 rn = bgp_node_get (table, p);
87
Lou Berger298cc2f2016-01-12 13:42:02 -050088 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000089 rn->prn = prn;
90
91 return rn;
92}
David Lamparter6b0655a2014-06-04 06:53:35 +020093
Paul Jakmafb982c22007-05-04 20:15:47 +000094/* Allocate bgp_info_extra */
95static struct bgp_info_extra *
96bgp_info_extra_new (void)
97{
98 struct bgp_info_extra *new;
99 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
100 return new;
101}
102
103static void
104bgp_info_extra_free (struct bgp_info_extra **extra)
105{
106 if (extra && *extra)
107 {
108 if ((*extra)->damp_info)
109 bgp_damp_info_free ((*extra)->damp_info, 0);
110
111 (*extra)->damp_info = NULL;
112
113 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
114
115 *extra = NULL;
116 }
117}
118
119/* Get bgp_info extra information for the given bgp_info, lazy allocated
120 * if required.
121 */
122struct bgp_info_extra *
123bgp_info_extra_get (struct bgp_info *ri)
124{
125 if (!ri->extra)
126 ri->extra = bgp_info_extra_new();
127 return ri->extra;
128}
129
paul718e3742002-12-13 20:15:29 +0000130/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000131static void
paul718e3742002-12-13 20:15:29 +0000132bgp_info_free (struct bgp_info *binfo)
133{
134 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000135 bgp_attr_unintern (&binfo->attr);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500136
137 bgp_unlink_nexthop(binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +0000138 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700139 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000140
paul200df112005-06-01 11:17:05 +0000141 peer_unlock (binfo->peer); /* bgp_info peer reference */
142
paul718e3742002-12-13 20:15:29 +0000143 XFREE (MTYPE_BGP_ROUTE, binfo);
144}
145
paul200df112005-06-01 11:17:05 +0000146struct bgp_info *
147bgp_info_lock (struct bgp_info *binfo)
148{
149 binfo->lock++;
150 return binfo;
151}
152
153struct bgp_info *
154bgp_info_unlock (struct bgp_info *binfo)
155{
156 assert (binfo && binfo->lock > 0);
157 binfo->lock--;
158
159 if (binfo->lock == 0)
160 {
161#if 0
162 zlog_debug ("%s: unlocked and freeing", __func__);
163 zlog_backtrace (LOG_DEBUG);
164#endif
165 bgp_info_free (binfo);
166 return NULL;
167 }
168
169#if 0
170 if (binfo->lock == 1)
171 {
172 zlog_debug ("%s: unlocked to 1", __func__);
173 zlog_backtrace (LOG_DEBUG);
174 }
175#endif
176
177 return binfo;
178}
179
paul718e3742002-12-13 20:15:29 +0000180void
181bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
182{
183 struct bgp_info *top;
184
185 top = rn->info;
paul200df112005-06-01 11:17:05 +0000186
paul718e3742002-12-13 20:15:29 +0000187 ri->next = rn->info;
188 ri->prev = NULL;
189 if (top)
190 top->prev = ri;
191 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000192
193 bgp_info_lock (ri);
194 bgp_lock_node (rn);
195 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000196}
197
paulb40d9392005-08-22 22:34:41 +0000198/* Do the actual removal of info from RIB, for use by bgp_process
199 completion callback *only* */
200static void
201bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000202{
203 if (ri->next)
204 ri->next->prev = ri->prev;
205 if (ri->prev)
206 ri->prev->next = ri->next;
207 else
208 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000209
Josh Baileyde8d5df2011-07-20 20:46:01 -0700210 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000211 bgp_info_unlock (ri);
212 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000213}
214
paulb40d9392005-08-22 22:34:41 +0000215void
216bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
217{
Paul Jakma1a392d42006-09-07 00:24:49 +0000218 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
219 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000220 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
221}
222
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000223/* undo the effects of a previous call to bgp_info_delete; typically
224 called when a route is deleted and then quickly re-added before the
225 deletion has been processed */
226static void
227bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
228{
229 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
230 /* unset of previous already took care of pcount */
231 SET_FLAG (ri->flags, BGP_INFO_VALID);
232}
233
Paul Jakma1a392d42006-09-07 00:24:49 +0000234/* Adjust pcount as required */
235static void
236bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
237{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700238 struct bgp_table *table;
239
240 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000241 assert (ri && ri->peer && ri->peer->bgp);
242
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 table = bgp_node_table (rn);
244
Paul Jakma1a392d42006-09-07 00:24:49 +0000245 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700246 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000247 || ri->peer == ri->peer->bgp->peer_self)
248 return;
249
250 if (BGP_INFO_HOLDDOWN (ri)
251 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
252 {
253
254 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
255
256 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700257 if (ri->peer->pcount[table->afi][table->safi])
258 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000259 else
260 {
261 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
262 __func__, ri->peer->host);
263 zlog_backtrace (LOG_WARNING);
264 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
265 }
266 }
267 else if (!BGP_INFO_HOLDDOWN (ri)
268 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
269 {
270 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700271 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000272 }
273}
274
275
276/* Set/unset bgp_info flags, adjusting any other state as needed.
277 * This is here primarily to keep prefix-count in check.
278 */
279void
280bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
281{
282 SET_FLAG (ri->flags, flag);
283
284 /* early bath if we know it's not a flag that changes useability state */
285 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
286 return;
287
288 bgp_pcount_adjust (rn, ri);
289}
290
291void
292bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
293{
294 UNSET_FLAG (ri->flags, flag);
295
296 /* early bath if we know it's not a flag that changes useability state */
297 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
298 return;
299
300 bgp_pcount_adjust (rn, ri);
301}
302
paul718e3742002-12-13 20:15:29 +0000303/* Get MED value. If MED value is missing and "bgp bestpath
304 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000305static u_int32_t
paul718e3742002-12-13 20:15:29 +0000306bgp_med_value (struct attr *attr, struct bgp *bgp)
307{
308 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
309 return attr->med;
310 else
311 {
312 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000313 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000314 else
315 return 0;
316 }
317}
318
Paul Jakma6d4742b2015-11-25 17:14:37 +0000319/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
320 * is preferred, or 0 if they are the same (usually will only occur if
321 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000322static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000325{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000326 struct attr *newattr, *existattr;
327 struct attr_extra *newattre, *existattre;
328 bgp_peer_sort_t new_sort;
329 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000330 u_int32_t new_pref;
331 u_int32_t exist_pref;
332 u_int32_t new_med;
333 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000334 u_int32_t new_weight;
335 u_int32_t exist_weight;
336 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000337 struct in_addr new_id;
338 struct in_addr exist_id;
339 int new_cluster;
340 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000341 int internal_as_route;
342 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000343 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700344
paul718e3742002-12-13 20:15:29 +0000345 /* 0. Null check. */
346 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000348 if (exist == NULL)
349 return -1;
paul718e3742002-12-13 20:15:29 +0000350
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000351 newattr = new->attr;
352 existattr = exist->attr;
353 newattre = newattr->extra;
354 existattre = existattr->extra;
355
paul718e3742002-12-13 20:15:29 +0000356 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000357 new_weight = exist_weight = 0;
358
359 if (newattre)
360 new_weight = newattre->weight;
361 if (existattre)
362 exist_weight = existattre->weight;
363
Paul Jakmafb982c22007-05-04 20:15:47 +0000364 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000365 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000366 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000367 return 1;
paul718e3742002-12-13 20:15:29 +0000368
369 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000370 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000371
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000372 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
373 new_pref = newattr->local_pref;
374 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375 exist_pref = existattr->local_pref;
376
paul718e3742002-12-13 20:15:29 +0000377 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000378 return -1;
paul718e3742002-12-13 20:15:29 +0000379 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000380 return 1;
paul718e3742002-12-13 20:15:29 +0000381
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000382 /* 3. Local route check. We prefer:
383 * - BGP_ROUTE_STATIC
384 * - BGP_ROUTE_AGGREGATE
385 * - BGP_ROUTE_REDISTRIBUTE
386 */
387 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000388 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000389 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000390 return 1;
paul718e3742002-12-13 20:15:29 +0000391
392 /* 4. AS path length check. */
393 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
394 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000395 int exist_hops = aspath_count_hops (existattr->aspath);
396 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000397
hasso68118452005-04-08 15:40:36 +0000398 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
399 {
paulfe69a502005-09-10 16:55:02 +0000400 int aspath_hops;
401
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000402 aspath_hops = aspath_count_hops (newattr->aspath);
403 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000404
405 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000406 return -1;
paulfe69a502005-09-10 16:55:02 +0000407 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000408 return 1;
hasso68118452005-04-08 15:40:36 +0000409 }
410 else
411 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000412 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000413
414 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000415 return -1;
paulfe69a502005-09-10 16:55:02 +0000416 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000417 return 1;
hasso68118452005-04-08 15:40:36 +0000418 }
paul718e3742002-12-13 20:15:29 +0000419 }
420
421 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000422 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000423 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000424 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000425 return 1;
paul718e3742002-12-13 20:15:29 +0000426
427 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000428 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
429 && aspath_count_hops (existattr->aspath) == 0);
430 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
431 && aspath_count_confeds (existattr->aspath) > 0
432 && aspath_count_hops (newattr->aspath) == 0
433 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000434
435 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
436 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
437 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000438 || aspath_cmp_left (newattr->aspath, existattr->aspath)
439 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000440 || internal_as_route)
441 {
442 new_med = bgp_med_value (new->attr, bgp);
443 exist_med = bgp_med_value (exist->attr, bgp);
444
445 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000446 return -1;
paul718e3742002-12-13 20:15:29 +0000447 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000448 return 1;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000452 new_sort = new->peer->sort;
453 exist_sort = exist->peer->sort;
454
455 if (new_sort == BGP_PEER_EBGP
456 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000457 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000458 if (exist_sort == BGP_PEER_EBGP
459 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000460 return 1;
paul718e3742002-12-13 20:15:29 +0000461
462 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 newm = existm = 0;
464
465 if (new->extra)
466 newm = new->extra->igpmetric;
467 if (exist->extra)
468 existm = exist->extra->igpmetric;
469
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000471 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000473 return 1;
paul718e3742002-12-13 20:15:29 +0000474
475 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000478 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
479 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000480 /*
481 * For the two paths, all comparison steps till IGP metric
482 * have succeeded - including AS_PATH hop count. Since 'bgp
483 * bestpath as-path multipath-relax' knob is on, we don't need
484 * an exact match of AS_PATH. Thus, mark the paths are equal.
485 * That will trigger both these paths to get into the multipath
486 * array.
487 */
488 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000489 }
490 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000491 {
492 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
493 return 0;
494 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700495 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 }
paul718e3742002-12-13 20:15:29 +0000498
499 /* 10. If both paths are external, prefer the path that was received
500 first (the oldest one). This step minimizes route-flap, since a
501 newer path won't displace an older one, even if it was the
502 preferred route based on the additional decision criteria below. */
503 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000504 && new_sort == BGP_PEER_EBGP
505 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000506 {
507 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000508 return -1;
paul718e3742002-12-13 20:15:29 +0000509 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000510 return 1;
paul718e3742002-12-13 20:15:29 +0000511 }
512
vivekbd4b7f12014-09-30 15:54:45 -0700513 /* 11. Router-ID comparision. */
514 /* If one of the paths is "stale", the corresponding peer router-id will
515 * be 0 and would always win over the other path. If originator id is
516 * used for the comparision, it will decide which path is better.
517 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
519 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000520 else
521 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000522 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
523 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000524 else
525 exist_id.s_addr = exist->peer->remote_id.s_addr;
526
527 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000528 return -1;
paul718e3742002-12-13 20:15:29 +0000529 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000530 return 1;
paul718e3742002-12-13 20:15:29 +0000531
532 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000533 new_cluster = exist_cluster = 0;
534
535 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
536 new_cluster = newattre->cluster->length;
537 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000539
540 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000541 return -1;
paul718e3742002-12-13 20:15:29 +0000542 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000543 return 1;
paul718e3742002-12-13 20:15:29 +0000544
545 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700546 /* Do this only if neither path is "stale" as stale paths do not have
547 * valid peer information (as the connection may or may not be up).
548 */
549 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000550 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700551 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000552 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300553 /* locally configured routes to advertise do not have su_remote */
554 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300555 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000556 if (exist->peer->su_remote == NULL)
557 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558
paul718e3742002-12-13 20:15:29 +0000559 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
560
561 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000562 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000563 if (ret == -1)
564 return -1;
paul718e3742002-12-13 20:15:29 +0000565
Paul Jakma6d4742b2015-11-25 17:14:37 +0000566 return -1;
paul718e3742002-12-13 20:15:29 +0000567}
568
paul94f2b392005-06-28 12:44:16 +0000569static enum filter_type
paul718e3742002-12-13 20:15:29 +0000570bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
571 afi_t afi, safi_t safi)
572{
573 struct bgp_filter *filter;
574
575 filter = &peer->filter[afi][safi];
576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577#define FILTER_EXIST_WARN(F,f,filter) \
578 if (BGP_DEBUG (update, UPDATE_IN) \
579 && !(F ## _IN (filter))) \
580 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
581 peer->host, #f, F ## _IN_NAME(filter));
582
583 if (DISTRIBUTE_IN_NAME (filter)) {
584 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
585
paul718e3742002-12-13 20:15:29 +0000586 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
587 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100588 }
paul718e3742002-12-13 20:15:29 +0000589
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 if (PREFIX_LIST_IN_NAME (filter)) {
591 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
592
paul718e3742002-12-13 20:15:29 +0000593 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
594 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 }
paul718e3742002-12-13 20:15:29 +0000596
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 if (FILTER_LIST_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
603
paul718e3742002-12-13 20:15:29 +0000604 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100605#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000606}
607
paul94f2b392005-06-28 12:44:16 +0000608static enum filter_type
paul718e3742002-12-13 20:15:29 +0000609bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
610 afi_t afi, safi_t safi)
611{
612 struct bgp_filter *filter;
613
614 filter = &peer->filter[afi][safi];
615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616#define FILTER_EXIST_WARN(F,f,filter) \
617 if (BGP_DEBUG (update, UPDATE_OUT) \
618 && !(F ## _OUT (filter))) \
619 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
620 peer->host, #f, F ## _OUT_NAME(filter));
621
622 if (DISTRIBUTE_OUT_NAME (filter)) {
623 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
624
paul718e3742002-12-13 20:15:29 +0000625 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
626 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100627 }
paul718e3742002-12-13 20:15:29 +0000628
Paul Jakma650f76c2009-06-25 18:06:31 +0100629 if (PREFIX_LIST_OUT_NAME (filter)) {
630 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
631
paul718e3742002-12-13 20:15:29 +0000632 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
633 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 }
paul718e3742002-12-13 20:15:29 +0000635
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 if (FILTER_LIST_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
643 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100644#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000645}
646
647/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000648static int
paul718e3742002-12-13 20:15:29 +0000649bgp_community_filter (struct peer *peer, struct attr *attr)
650{
651 if (attr->community)
652 {
653 /* NO_ADVERTISE check. */
654 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
655 return 1;
656
657 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000658 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000659 community_include (attr->community, COMMUNITY_NO_EXPORT))
660 return 1;
661
662 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP
664 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000665 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
666 return 1;
667 }
668 return 0;
669}
670
671/* Route reflection loop check. */
672static int
673bgp_cluster_filter (struct peer *peer, struct attr *attr)
674{
675 struct in_addr cluster_id;
676
Paul Jakmafb982c22007-05-04 20:15:47 +0000677 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000678 {
679 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
680 cluster_id = peer->bgp->cluster_id;
681 else
682 cluster_id = peer->bgp->router_id;
683
Paul Jakmafb982c22007-05-04 20:15:47 +0000684 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000685 return 1;
686 }
687 return 0;
688}
David Lamparter6b0655a2014-06-04 06:53:35 +0200689
paul94f2b392005-06-28 12:44:16 +0000690static int
paul718e3742002-12-13 20:15:29 +0000691bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
692 afi_t afi, safi_t safi)
693{
694 struct bgp_filter *filter;
695 struct bgp_info info;
696 route_map_result_t ret;
697
698 filter = &peer->filter[afi][safi];
699
700 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000701 if (peer->weight)
702 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000703
704 /* Route map apply. */
705 if (ROUTE_MAP_IN_NAME (filter))
706 {
707 /* Duplicate current value to new strucutre for modification. */
708 info.peer = peer;
709 info.attr = attr;
710
paulac41b2a2003-08-12 05:32:27 +0000711 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
712
paul718e3742002-12-13 20:15:29 +0000713 /* Apply BGP route map to the attribute. */
714 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000715
716 peer->rmap_type = 0;
717
paul718e3742002-12-13 20:15:29 +0000718 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200719 /* caller has multiple error paths with bgp_attr_flush() */
720 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
paul718e3742002-12-13 20:15:29 +0000836 else if (p->family == AF_INET6 && p->prefixlen == 0)
837 return 0;
paul718e3742002-12-13 20:15:29 +0000838 }
839
paul286e1e72003-08-08 00:24:31 +0000840 /* Transparency check. */
841 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
842 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
843 transparent = 1;
844 else
845 transparent = 0;
846
paul718e3742002-12-13 20:15:29 +0000847 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000849 return 0;
850
851 /* If the attribute has originator-id and it is same as remote
852 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700853 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000854 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000856 {
857 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000858 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000859 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
860 peer->host,
861 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
862 p->prefixlen);
863 return 0;
864 }
865 }
866
867 /* ORF prefix-list filter check */
868 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
869 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
870 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
871 if (peer->orf_plist[afi][safi])
872 {
873 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
874 return 0;
875 }
876
877 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700878 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000879 {
880 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000881 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000882 "%s [Update:SEND] %s/%d is filtered",
883 peer->host,
884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
885 p->prefixlen);
886 return 0;
887 }
888
889#ifdef BGP_SEND_ASPATH_CHECK
890 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700891 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000894 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400895 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000896 peer->host, peer->as);
897 return 0;
898 }
899#endif /* BGP_SEND_ASPATH_CHECK */
900
901 /* If we're a CONFED we need to loop check the CONFED ID too */
902 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
903 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700904 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000905 {
906 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000907 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400908 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000909 peer->host,
910 bgp->confed_id);
911 return 0;
912 }
913 }
914
915 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000916 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000917 reflect = 1;
918 else
919 reflect = 0;
920
921 /* IBGP reflection check. */
922 if (reflect)
923 {
924 /* A route from a Client peer. */
925 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
926 {
927 /* Reflect to all the Non-Client peers and also to the
928 Client peers other than the originator. Originator check
929 is already done. So there is noting to do. */
930 /* no bgp client-to-client reflection check. */
931 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
932 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 return 0;
934 }
935 else
936 {
937 /* A route from a Non-client peer. Reflect to all other
938 clients. */
939 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 }
Paul Jakma41367172007-08-06 15:24:51 +0000943
paul718e3742002-12-13 20:15:29 +0000944 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700945 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000946
paul718e3742002-12-13 20:15:29 +0000947 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000948 if ((peer->sort == BGP_PEER_IBGP
949 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000950 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
951 {
952 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
953 attr->local_pref = bgp->default_local_pref;
954 }
955
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000956 /* If originator-id is not set and the route is to be reflected,
957 set the originator id */
958 if (peer && from && peer->sort == BGP_PEER_IBGP &&
959 from->sort == BGP_PEER_IBGP &&
960 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
961 {
962 attr->extra = bgp_attr_extra_get(attr);
963 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
964 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
965 }
966
paul718e3742002-12-13 20:15:29 +0000967 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000968 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000969 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
970 {
971 if (ri->peer != bgp->peer_self && ! transparent
972 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
973 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
974 }
975
Lou Berger298cc2f2016-01-12 13:42:02 -0500976
977#define NEXTHOP_IS_V4 (\
978 (safi != SAFI_ENCAP && p->family == AF_INET) || \
979 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
980
Lou Berger298cc2f2016-01-12 13:42:02 -0500981#define NEXTHOP_IS_V6 (\
982 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
983 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
Lou Berger298cc2f2016-01-12 13:42:02 -0500984
paul718e3742002-12-13 20:15:29 +0000985 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300986 if (transparent
987 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000988 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500989 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
Lou Berger298cc2f2016-01-12 13:42:02 -0500990 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -0500997 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001000 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001001 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1002 {
1003 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001004 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1008 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001009 else
1010 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1011 }
paul718e3742002-12-13 20:15:29 +00001012 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001013 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001014 {
1015 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001017 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001019 }
paul718e3742002-12-13 20:15:29 +00001020 }
1021
Lou Berger298cc2f2016-01-12 13:42:02 -05001022 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
Dinesh Dutt083e5e22015-11-09 20:21:54 -05001081 of the reflected IBGP routes, unless configured to allow it */
1082 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1083 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
paulfee0f4c2004-09-13 05:12:46 +00001200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202 )
1203 {
1204 /* Set IPv4 nexthop. */
1205 if (p->family == AF_INET)
1206 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001207 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV4_MAX_BYTELEN);
1210 else
1211 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1212 }
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Set IPv6 nexthop. */
1214 if (p->family == AF_INET6)
1215 {
1216 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
paulfee0f4c2004-09-13 05:12:46 +00001223 if (p->family == AF_INET6)
1224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001226
paulfee0f4c2004-09-13 05:12:46 +00001227 /* Left nexthop_local unchanged if so configured. */
1228 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1229 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Default nexthop_local treatment for RS-Clients */
1238 else
1239 {
1240 /* Announcer and RS-Client are both in the same network */
1241 if (rsclient->shared_network && from->shared_network &&
1242 (rsclient->ifindex == from->ifindex))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Set link-local address for shared network peer. */
1251 else if (rsclient->shared_network
1252 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001255 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 }
paulfee0f4c2004-09-13 05:12:46 +00001264
1265 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001266 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001267 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1268 && aspath_private_as_check (attr->aspath))
1269 attr->aspath = aspath_empty_get ();
1270
1271 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001273 {
1274 info.peer = rsclient;
1275 info.attr = attr;
1276
1277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1278
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001280 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1281 else
1282 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1283
1284 rsclient->rmap_type = 0;
1285
1286 if (ret == RMAP_DENYMATCH)
1287 {
1288 bgp_attr_flush (attr);
1289 return 0;
1290 }
1291 }
1292
1293 return 1;
1294}
1295
1296struct bgp_info_pair
1297{
1298 struct bgp_info *old;
1299 struct bgp_info *new;
1300};
1301
paul94f2b392005-06-28 12:44:16 +00001302static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001303bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001304 struct bgp_info_pair *result,
1305 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul718e3742002-12-13 20:15:29 +00001307 struct bgp_info *new_select;
1308 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001309 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001310 struct bgp_info *ri1;
1311 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001312 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001313 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001314 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001315
1316 result->old = result->new = NULL;
1317
1318 if (rn->info == NULL)
1319 {
1320 char buf[PREFIX_STRLEN];
1321 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1322 __func__,
1323 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1324 return;
1325 }
1326
Josh Bailey96450fa2011-07-20 20:45:12 -07001327 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001339 if (ri1->peer && ri1->peer != bgp->peer_self)
1340 if (ri1->peer->status != Established)
1341 continue;
paul718e3742002-12-13 20:15:29 +00001342
1343 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath)
1345 bgp_mp_list_add (&mp_list, ri1);
1346 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001347 if (ri1->next)
1348 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1349 {
1350 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri2))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri2->peer &&
1355 ri2->peer != bgp->peer_self &&
1356 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1357 if (ri2->peer->status != Established)
1358 continue;
paul718e3742002-12-13 20:15:29 +00001359
1360 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1361 || aspath_cmp_left_confed (ri1->attr->aspath,
1362 ri2->attr->aspath))
1363 {
Josh Bailey6918e742011-07-20 20:48:20 -07001364 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1365 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001366 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1367 == -1)
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
1371 }
1372
Paul Jakma6d4742b2015-11-25 17:14:37 +00001373 if (do_mpath)
1374 {
1375 if (cmpret != 0)
1376 bgp_mp_list_clear (&mp_list);
1377
1378 if (cmpret == 0 || cmpret == -1)
1379 bgp_mp_list_add (&mp_list, ri2);
1380 }
Josh Bailey6918e742011-07-20 20:48:20 -07001381
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001383 }
1384 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001389 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
paul718e3742002-12-13 20:15:29 +00001411
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001412 if (ri->peer &&
1413 ri->peer != bgp->peer_self &&
1414 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1415 if (ri->peer->status != Established)
1416 continue;
1417
paul718e3742002-12-13 20:15:29 +00001418 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1419 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1420 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001421 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001422 continue;
1423 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001424 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1425 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001426
Paul Jakma6d4742b2015-11-25 17:14:37 +00001427 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001428 {
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_mp_dmed_deselect (new_select);
1431
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001434 else if (cmpret == 1 && do_mpath
1435 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001436 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001437
Paul Jakma6d4742b2015-11-25 17:14:37 +00001438 if (do_mpath)
1439 {
1440 if (cmpret != 0)
1441 bgp_mp_list_clear (&mp_list);
1442
1443 if (cmpret == 0 || cmpret == -1)
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
paul718e3742002-12-13 20:15:29 +00001446 }
paulfee0f4c2004-09-13 05:12:46 +00001447
Josh Bailey6918e742011-07-20 20:48:20 -07001448 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001450
Josh Bailey0b597ef2011-07-20 20:49:11 -07001451 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452 bgp_mp_list_clear (&mp_list);
1453
1454 result->old = old_select;
1455 result->new = new_select;
1456
1457 return;
paulfee0f4c2004-09-13 05:12:46 +00001458}
1459
paul94f2b392005-06-28 12:44:16 +00001460static int
paulfee0f4c2004-09-13 05:12:46 +00001461bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 struct bgp_node *rn, afi_t afi, safi_t safi)
1463{
paulfee0f4c2004-09-13 05:12:46 +00001464 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 struct attr attr;
1466 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001467
Lou Berger050defe2016-01-12 13:41:59 -05001468 memset (&attr, 0, sizeof(struct attr));
1469 memset (&extra, 0, sizeof(struct attr_extra));
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 p = &rn->p;
1472
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 /* Announce route to Established peer. */
1474 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001475 return 0;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Address family configuration check. */
1478 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001482 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1483 PEER_STATUS_ORF_WAIT_REFRESH))
1484 return 0;
1485
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1487 attr.extra = &extra;
1488
Avneesh Sachdev67174042012-08-17 08:19:49 -07001489 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001490 {
1491 case BGP_TABLE_MAIN:
1492 /* Announcement to peer->conf. If the route is filtered,
1493 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
1498 break;
1499 case BGP_TABLE_RSCLIENT:
1500 /* Announcement to peer->conf. If the route is filtered,
1501 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001502 if (selected &&
1503 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001507 break;
1508 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001509
Lou Berger050defe2016-01-12 13:41:59 -05001510 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001511 return 0;
paul200df112005-06-01 11:17:05 +00001512}
paulfee0f4c2004-09-13 05:12:46 +00001513
paul200df112005-06-01 11:17:05 +00001514struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001515{
paul200df112005-06-01 11:17:05 +00001516 struct bgp *bgp;
1517 struct bgp_node *rn;
1518 afi_t afi;
1519 safi_t safi;
1520};
1521
1522static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001523bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001524{
paul0fb58d52005-11-14 14:31:49 +00001525 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001526 struct bgp *bgp = pq->bgp;
1527 struct bgp_node *rn = pq->rn;
1528 afi_t afi = pq->afi;
1529 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001533 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001534 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001535
paulfee0f4c2004-09-13 05:12:46 +00001536 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001537 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001538 new_select = old_and_new.new;
1539 old_select = old_and_new.old;
1540
paul200df112005-06-01 11:17:05 +00001541 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1542 {
Chris Caputo228da422009-07-18 05:44:03 +00001543 if (rsclient->group)
1544 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1545 {
1546 /* Nothing to do. */
1547 if (old_select && old_select == new_select)
1548 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1549 continue;
paulfee0f4c2004-09-13 05:12:46 +00001550
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (old_select)
1552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1553 if (new_select)
1554 {
1555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001557 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1558 }
paulfee0f4c2004-09-13 05:12:46 +00001559
Chris Caputo228da422009-07-18 05:44:03 +00001560 bgp_process_announce_selected (rsclient, new_select, rn,
1561 afi, safi);
1562 }
paul200df112005-06-01 11:17:05 +00001563 }
1564 else
1565 {
hassob7395792005-08-26 12:58:38 +00001566 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001568 if (new_select)
1569 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001573 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001574 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001575 }
paulfee0f4c2004-09-13 05:12:46 +00001576
paulb40d9392005-08-22 22:34:41 +00001577 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1578 bgp_info_reap (rn, old_select);
1579
paul200df112005-06-01 11:17:05 +00001580 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1581 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001582}
1583
paul200df112005-06-01 11:17:05 +00001584static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001585bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001586{
paul0fb58d52005-11-14 14:31:49 +00001587 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001588 struct bgp *bgp = pq->bgp;
1589 struct bgp_node *rn = pq->rn;
1590 afi_t afi = pq->afi;
1591 safi_t safi = pq->safi;
1592 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001593 struct bgp_info *new_select;
1594 struct bgp_info *old_select;
1595 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001596 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001597 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001598
paulfee0f4c2004-09-13 05:12:46 +00001599 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001600 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001601 old_select = old_and_new.old;
1602 new_select = old_and_new.new;
1603
1604 /* Nothing to do. */
Daniel Walton325fcfb2015-05-19 17:58:10 -07001605 if (old_select && old_select == new_select
1606 && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
paulfee0f4c2004-09-13 05:12:46 +00001607 {
1608 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001609 {
Josh Bailey8196f132011-07-20 20:47:07 -07001610 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1611 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001612 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001613
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001615 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1616 return WQ_SUCCESS;
1617 }
paulfee0f4c2004-09-13 05:12:46 +00001618 }
paul718e3742002-12-13 20:15:29 +00001619
Daniel Walton325fcfb2015-05-19 17:58:10 -07001620 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1621 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1622
hasso338b3422005-02-23 14:27:24 +00001623 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001624 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001625 if (new_select)
1626 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001627 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1628 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001629 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001630 }
1631
1632
paul718e3742002-12-13 20:15:29 +00001633 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001634 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001635 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001636 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001637 }
1638
1639 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001640 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1641 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001642 {
1643 if (new_select
1644 && new_select->type == ZEBRA_ROUTE_BGP
1645 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001646 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001647 else
1648 {
1649 /* Withdraw the route from the kernel. */
1650 if (old_select
1651 && old_select->type == ZEBRA_ROUTE_BGP
1652 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001654 }
1655 }
paulb40d9392005-08-22 22:34:41 +00001656
Lou Berger050defe2016-01-12 13:41:59 -05001657 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001658 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1659 bgp_info_reap (rn, old_select);
1660
paul200df112005-06-01 11:17:05 +00001661 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1662 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001663}
1664
paul200df112005-06-01 11:17:05 +00001665static void
paul0fb58d52005-11-14 14:31:49 +00001666bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001667{
paul0fb58d52005-11-14 14:31:49 +00001668 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001669 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001670
Chris Caputo228da422009-07-18 05:44:03 +00001671 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001672 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001673 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001674 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1675}
1676
1677static void
1678bgp_process_queue_init (void)
1679{
1680 bm->process_main_queue
1681 = work_queue_new (bm->master, "process_main_queue");
1682 bm->process_rsclient_queue
1683 = work_queue_new (bm->master, "process_rsclient_queue");
1684
1685 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1686 {
1687 zlog_err ("%s: Failed to allocate work queue", __func__);
1688 exit (1);
1689 }
1690
1691 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001692 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001693 bm->process_main_queue->spec.max_retries = 0;
1694 bm->process_main_queue->spec.hold = 50;
1695
Paul Jakma838bbde2010-01-08 14:05:32 +00001696 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001697 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1698 bm->process_rsclient_queue->spec.max_retries = 0;
1699 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001700}
1701
1702void
paulfee0f4c2004-09-13 05:12:46 +00001703bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1704{
paul200df112005-06-01 11:17:05 +00001705 struct bgp_process_queue *pqnode;
1706
1707 /* already scheduled for processing? */
1708 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1709 return;
1710
Paul Jakma91b9e852015-12-01 14:32:11 +00001711 if (rn->info == NULL)
1712 {
1713 /* XXX: Perhaps remove before next release, after we've flushed out
1714 * any obvious cases
1715 */
1716 assert (rn->info != NULL);
1717 char buf[PREFIX_STRLEN];
1718 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1719 __func__,
1720 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1721 return;
1722 }
1723
paul200df112005-06-01 11:17:05 +00001724 if ( (bm->process_main_queue == NULL) ||
1725 (bm->process_rsclient_queue == NULL) )
1726 bgp_process_queue_init ();
1727
1728 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1729 sizeof (struct bgp_process_queue));
1730 if (!pqnode)
1731 return;
Chris Caputo228da422009-07-18 05:44:03 +00001732
1733 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001734 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001735 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001736 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001737 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001738 pqnode->afi = afi;
1739 pqnode->safi = safi;
1740
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001742 {
paul200df112005-06-01 11:17:05 +00001743 case BGP_TABLE_MAIN:
1744 work_queue_add (bm->process_main_queue, pqnode);
1745 break;
1746 case BGP_TABLE_RSCLIENT:
1747 work_queue_add (bm->process_rsclient_queue, pqnode);
1748 break;
paulfee0f4c2004-09-13 05:12:46 +00001749 }
paul200df112005-06-01 11:17:05 +00001750
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001751 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001752 return;
paulfee0f4c2004-09-13 05:12:46 +00001753}
hasso0a486e52005-02-01 20:57:17 +00001754
paul94f2b392005-06-28 12:44:16 +00001755static int
hasso0a486e52005-02-01 20:57:17 +00001756bgp_maximum_prefix_restart_timer (struct thread *thread)
1757{
1758 struct peer *peer;
1759
1760 peer = THREAD_ARG (thread);
1761 peer->t_pmax_restart = NULL;
1762
1763 if (BGP_DEBUG (events, EVENTS))
1764 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1765 peer->host);
1766
1767 peer_clear (peer);
1768
1769 return 0;
1770}
1771
paulfee0f4c2004-09-13 05:12:46 +00001772int
paul5228ad22004-06-04 17:58:18 +00001773bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1774 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001775{
hassoe0701b72004-05-20 09:19:34 +00001776 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1777 return 0;
1778
1779 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001780 {
hassoe0701b72004-05-20 09:19:34 +00001781 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1782 && ! always)
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001786 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1787 "limit %ld", afi_safi_print (afi, safi), peer->host,
1788 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001789 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001790
hassoe0701b72004-05-20 09:19:34 +00001791 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1792 return 0;
paul718e3742002-12-13 20:15:29 +00001793
hassoe0701b72004-05-20 09:19:34 +00001794 {
paul5228ad22004-06-04 17:58:18 +00001795 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001796
1797 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001798 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001799
1800 ndata[0] = (afi >> 8);
1801 ndata[1] = afi;
1802 ndata[2] = safi;
1803 ndata[3] = (peer->pmax[afi][safi] >> 24);
1804 ndata[4] = (peer->pmax[afi][safi] >> 16);
1805 ndata[5] = (peer->pmax[afi][safi] >> 8);
1806 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001807
1808 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1809 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1810 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1811 }
hasso0a486e52005-02-01 20:57:17 +00001812
1813 /* restart timer start */
1814 if (peer->pmax_restart[afi][safi])
1815 {
1816 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1817
1818 if (BGP_DEBUG (events, EVENTS))
1819 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1820 peer->host, peer->v_pmax_restart);
1821
1822 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1823 peer->v_pmax_restart);
1824 }
1825
hassoe0701b72004-05-20 09:19:34 +00001826 return 1;
paul718e3742002-12-13 20:15:29 +00001827 }
hassoe0701b72004-05-20 09:19:34 +00001828 else
1829 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1830
1831 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1832 {
1833 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1834 && ! always)
1835 return 0;
1836
1837 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001838 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1839 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1840 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001841 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1842 }
1843 else
1844 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001845 return 0;
1846}
1847
paulb40d9392005-08-22 22:34:41 +00001848/* Unconditionally remove the route from the RIB, without taking
1849 * damping into consideration (eg, because the session went down)
1850 */
paul94f2b392005-06-28 12:44:16 +00001851static void
paul718e3742002-12-13 20:15:29 +00001852bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1853 afi_t afi, safi_t safi)
1854{
paul902212c2006-02-05 17:51:19 +00001855 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1856
1857 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1858 bgp_info_delete (rn, ri); /* keep historical info */
1859
paulb40d9392005-08-22 22:34:41 +00001860 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001861}
1862
paul94f2b392005-06-28 12:44:16 +00001863static void
paul718e3742002-12-13 20:15:29 +00001864bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001865 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001866{
paul718e3742002-12-13 20:15:29 +00001867 int status = BGP_DAMP_NONE;
1868
paulb40d9392005-08-22 22:34:41 +00001869 /* apply dampening, if result is suppressed, we'll be retaining
1870 * the bgp_info in the RIB for historical reference.
1871 */
1872 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001873 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001874 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1875 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001876 {
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878 return;
1879 }
1880
1881 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001882}
1883
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001884static struct bgp_info *
1885info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1886 struct bgp_node *rn)
1887{
1888 struct bgp_info *new;
1889
1890 /* Make new BGP info. */
1891 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1892 new->type = type;
1893 new->sub_type = sub_type;
1894 new->peer = peer;
1895 new->attr = attr;
1896 new->uptime = bgp_clock ();
1897 new->net = rn;
1898 return new;
1899}
1900
paul94f2b392005-06-28 12:44:16 +00001901static void
paulfee0f4c2004-09-13 05:12:46 +00001902bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1903 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1904 int sub_type, struct prefix_rd *prd, u_char *tag)
1905{
1906 struct bgp_node *rn;
1907 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001908 struct attr new_attr;
1909 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001910 struct attr *attr_new;
1911 struct attr *attr_new2;
1912 struct bgp_info *ri;
1913 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001914 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001915 char buf[SU_ADDRSTRLEN];
1916
1917 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1918 if (peer == rsclient)
1919 return;
1920
1921 bgp = peer->bgp;
1922 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1923
1924 /* Check previously received route. */
1925 for (ri = rn->info; ri; ri = ri->next)
1926 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1927 break;
1928
1929 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001930 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001931 {
1932 reason = "as-path contains our own AS;";
1933 goto filtered;
1934 }
1935
1936 /* Route reflector originator ID check. */
1937 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001938 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001939 {
1940 reason = "originator is us;";
1941 goto filtered;
1942 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001943
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001944 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001945 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Apply export policy. */
1948 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1949 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1950 {
1951 reason = "export-policy;";
1952 goto filtered;
1953 }
1954
1955 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* Apply import policy. */
1958 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1959 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001960 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 reason = "import-policy;";
1963 goto filtered;
1964 }
1965
1966 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001967 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001970 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001972 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001973 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001974 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001975 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001976 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 reason = "martian next-hop;";
1979 goto filtered;
1980 }
1981 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001982
paulfee0f4c2004-09-13 05:12:46 +00001983 /* If the update is implicit withdraw. */
1984 if (ri)
1985 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001986 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001987
1988 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001989 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1990 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001991 {
1992
Paul Jakma1a392d42006-09-07 00:24:49 +00001993 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001994
1995 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001996 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001997 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1998 peer->host,
1999 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2000 p->prefixlen, rsclient->host);
2001
Chris Caputo228da422009-07-18 05:44:03 +00002002 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002003 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002004 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002005 return;
paulfee0f4c2004-09-13 05:12:46 +00002006 }
2007
Paul Jakma16d2e242007-04-10 19:32:10 +00002008 /* Withdraw/Announce before we fully processed the withdraw */
2009 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2010 bgp_info_restore (rn, ri);
2011
paulfee0f4c2004-09-13 05:12:46 +00002012 /* Received Logging. */
2013 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002014 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002015 peer->host,
2016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen, rsclient->host);
2018
2019 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002021
2022 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002023 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002024 ri->attr = attr_new;
2025
2026 /* Update MPLS tag. */
2027 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002028 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002029
Paul Jakma1a392d42006-09-07 00:24:49 +00002030 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002031
2032 /* Process change. */
2033 bgp_process (bgp, rn, afi, safi);
2034 bgp_unlock_node (rn);
2035
2036 return;
2037 }
2038
2039 /* Received Logging. */
2040 if (BGP_DEBUG (update, UPDATE_IN))
2041 {
ajsd2c1f162004-12-08 21:10:20 +00002042 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002043 peer->host,
2044 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2045 p->prefixlen, rsclient->host);
2046 }
2047
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002048 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002049
2050 /* Update MPLS tag. */
2051 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002053
Paul Jakma1a392d42006-09-07 00:24:49 +00002054 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002055
2056 /* Register new BGP information. */
2057 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002058
2059 /* route_node_get lock */
2060 bgp_unlock_node (rn);
2061
paulfee0f4c2004-09-13 05:12:46 +00002062 /* Process change. */
2063 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002064
paulfee0f4c2004-09-13 05:12:46 +00002065 return;
2066
2067 filtered:
2068
2069 /* This BGP update is filtered. Log the reason then update BGP entry. */
2070 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002071 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002072 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2073 peer->host,
2074 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2075 p->prefixlen, rsclient->host, reason);
2076
2077 if (ri)
paulb40d9392005-08-22 22:34:41 +00002078 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002079
2080 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002081
paulfee0f4c2004-09-13 05:12:46 +00002082 return;
2083}
2084
paul94f2b392005-06-28 12:44:16 +00002085static void
paulfee0f4c2004-09-13 05:12:46 +00002086bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2087 struct peer *peer, struct prefix *p, int type, int sub_type,
2088 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002089{
paulfee0f4c2004-09-13 05:12:46 +00002090 struct bgp_node *rn;
2091 struct bgp_info *ri;
2092 char buf[SU_ADDRSTRLEN];
2093
2094 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002095 return;
paulfee0f4c2004-09-13 05:12:46 +00002096
2097 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2098
2099 /* Lookup withdrawn route. */
2100 for (ri = rn->info; ri; ri = ri->next)
2101 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2102 break;
2103
2104 /* Withdraw specified route from routing table. */
2105 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002106 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002107 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002108 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002109 "%s Can't find the route %s/%d", peer->host,
2110 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2111 p->prefixlen);
2112
2113 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002114 bgp_unlock_node (rn);
2115}
paulfee0f4c2004-09-13 05:12:46 +00002116
paul94f2b392005-06-28 12:44:16 +00002117static int
paulfee0f4c2004-09-13 05:12:46 +00002118bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002119 afi_t afi, safi_t safi, int type, int sub_type,
2120 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2121{
2122 int ret;
2123 int aspath_loop_count = 0;
2124 struct bgp_node *rn;
2125 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002126 struct attr new_attr;
2127 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002128 struct attr *attr_new;
2129 struct bgp_info *ri;
2130 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002131 const char *reason;
paul718e3742002-12-13 20:15:29 +00002132 char buf[SU_ADDRSTRLEN];
2133
Lou Berger370b7e52016-02-04 21:29:49 -05002134 memset (&new_attr, 0, sizeof(struct attr));
2135 memset (&new_extra, 0, sizeof(struct attr_extra));
2136
paul718e3742002-12-13 20:15:29 +00002137 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002138 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002139
paul718e3742002-12-13 20:15:29 +00002140 /* When peer's soft reconfiguration enabled. Record input packet in
2141 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002142 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2143 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002144 bgp_adj_in_set (rn, peer, attr);
2145
2146 /* Check previously received route. */
2147 for (ri = rn->info; ri; ri = ri->next)
2148 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2149 break;
2150
2151 /* AS path local-as loop check. */
2152 if (peer->change_local_as)
2153 {
2154 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2155 aspath_loop_count = 1;
2156
2157 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2158 {
2159 reason = "as-path contains our own AS;";
2160 goto filtered;
2161 }
2162 }
2163
2164 /* AS path loop check. */
2165 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2166 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2167 && aspath_loop_check(attr->aspath, bgp->confed_id)
2168 > peer->allowas_in[afi][safi]))
2169 {
2170 reason = "as-path contains our own AS;";
2171 goto filtered;
2172 }
2173
2174 /* Route reflector originator ID check. */
2175 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002176 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002177 {
2178 reason = "originator is us;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector cluster ID check. */
2183 if (bgp_cluster_filter (peer, attr))
2184 {
2185 reason = "reflected from the same cluster;";
2186 goto filtered;
2187 }
2188
2189 /* Apply incoming filter. */
2190 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2191 {
2192 reason = "filter;";
2193 goto filtered;
2194 }
2195
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002196 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002197 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002198
David Lamparterc460e572014-06-04 00:54:58 +02002199 /* Apply incoming route-map.
2200 * NB: new_attr may now contain newly allocated values from route-map "set"
2201 * commands, so we need bgp_attr_flush in the error paths, until we intern
2202 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002203 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2204 {
2205 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002206 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002207 goto filtered;
2208 }
2209
2210 /* IPv4 unicast next hop check. */
2211 if (afi == AFI_IP && safi == SAFI_UNICAST)
2212 {
2213 /* If the peer is EBGP and nexthop is not on connected route,
2214 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002215 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002216 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002217 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002218 {
2219 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002220 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002221 goto filtered;
2222 }
2223
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002224 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002225 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002226 if (new_attr.nexthop.s_addr == 0
2227 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2228 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002229 {
2230 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002231 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002232 goto filtered;
2233 }
2234 }
2235
2236 attr_new = bgp_attr_intern (&new_attr);
2237
2238 /* If the update is implicit withdraw. */
2239 if (ri)
2240 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002241 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002242
2243 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002244 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2245 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002246 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002247 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002248
2249 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002250 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002251 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 {
2253 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002254 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002255 peer->host,
2256 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2257 p->prefixlen);
2258
paul902212c2006-02-05 17:51:19 +00002259 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2260 {
2261 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2262 bgp_process (bgp, rn, afi, safi);
2263 }
paul718e3742002-12-13 20:15:29 +00002264 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002266 {
2267 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002268 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002269 "%s rcvd %s/%d...duplicate ignored",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002273
2274 /* graceful restart STALE flag unset. */
2275 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2276 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002277 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002278 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002279 }
paul718e3742002-12-13 20:15:29 +00002280 }
2281
2282 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002283 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002284 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002285
paul718e3742002-12-13 20:15:29 +00002286 return 0;
2287 }
2288
Paul Jakma16d2e242007-04-10 19:32:10 +00002289 /* Withdraw/Announce before we fully processed the withdraw */
2290 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2291 {
2292 if (BGP_DEBUG (update, UPDATE_IN))
2293 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2294 peer->host,
2295 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2296 p->prefixlen);
2297 bgp_info_restore (rn, ri);
2298 }
2299
paul718e3742002-12-13 20:15:29 +00002300 /* Received Logging. */
2301 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002302 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002303 peer->host,
2304 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2305 p->prefixlen);
2306
hasso93406d82005-02-02 14:40:33 +00002307 /* graceful restart STALE flag unset. */
2308 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002310
paul718e3742002-12-13 20:15:29 +00002311 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002312 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002313
2314 /* implicit withdraw, decrement aggregate and pcount here.
2315 * only if update is accepted, they'll increment below.
2316 */
paul902212c2006-02-05 17:51:19 +00002317 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2318
paul718e3742002-12-13 20:15:29 +00002319 /* Update bgp route dampening information. */
2320 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002321 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002322 {
2323 /* This is implicit withdraw so we should update dampening
2324 information. */
2325 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2326 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002327 }
2328
paul718e3742002-12-13 20:15:29 +00002329 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002330 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002331 ri->attr = attr_new;
2332
2333 /* Update MPLS tag. */
2334 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002335 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002336
Lou Berger050defe2016-01-12 13:41:59 -05002337 bgp_attr_flush (&new_attr);
2338
paul718e3742002-12-13 20:15:29 +00002339 /* Update bgp route dampening information. */
2340 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002341 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002342 {
2343 /* Now we do normal update dampening. */
2344 ret = bgp_damp_update (ri, rn, afi, safi);
2345 if (ret == BGP_DAMP_SUPPRESSED)
2346 {
2347 bgp_unlock_node (rn);
2348 return 0;
2349 }
2350 }
2351
2352 /* Nexthop reachability check. */
2353 if ((afi == AFI_IP || afi == AFI_IP6)
2354 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002355 && (peer->sort == BGP_PEER_IBGP
2356 || peer->sort == BGP_PEER_CONFED
2357 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002358 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002359 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002360 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002361 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364 }
2365 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002366 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002367
Lou Berger050defe2016-01-12 13:41:59 -05002368 bgp_attr_flush (&new_attr);
2369
paul718e3742002-12-13 20:15:29 +00002370 /* Process change. */
2371 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2372
2373 bgp_process (bgp, rn, afi, safi);
2374 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002375
paul718e3742002-12-13 20:15:29 +00002376 return 0;
2377 }
2378
2379 /* Received Logging. */
2380 if (BGP_DEBUG (update, UPDATE_IN))
2381 {
ajsd2c1f162004-12-08 21:10:20 +00002382 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002383 peer->host,
2384 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2385 p->prefixlen);
2386 }
2387
paul718e3742002-12-13 20:15:29 +00002388 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002389 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Update MPLS tag. */
2392 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002393 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002394
2395 /* Nexthop reachability check. */
2396 if ((afi == AFI_IP || afi == AFI_IP6)
2397 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002398 && (peer->sort == BGP_PEER_IBGP
2399 || peer->sort == BGP_PEER_CONFED
2400 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002401 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002402 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002403 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002404 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002405 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407 }
2408 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002409 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002410
paul902212c2006-02-05 17:51:19 +00002411 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002412 bgp_aggregate_increment (bgp, p, new, afi, safi);
2413
2414 /* Register new BGP information. */
2415 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002416
2417 /* route_node_get lock */
2418 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002419
Lou Berger050defe2016-01-12 13:41:59 -05002420 bgp_attr_flush (&new_attr);
2421
paul718e3742002-12-13 20:15:29 +00002422 /* If maximum prefix count is configured and current prefix
2423 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002424 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2425 return -1;
paul718e3742002-12-13 20:15:29 +00002426
2427 /* Process change. */
2428 bgp_process (bgp, rn, afi, safi);
2429
2430 return 0;
2431
2432 /* This BGP update is filtered. Log the reason then update BGP
2433 entry. */
2434 filtered:
2435 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002436 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002437 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2438 peer->host,
2439 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2440 p->prefixlen, reason);
2441
2442 if (ri)
paulb40d9392005-08-22 22:34:41 +00002443 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002444
2445 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002446 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002447
paul718e3742002-12-13 20:15:29 +00002448 return 0;
2449}
2450
2451int
paulfee0f4c2004-09-13 05:12:46 +00002452bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2455{
2456 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002457 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002458 struct bgp *bgp;
2459 int ret;
2460
2461 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2462 soft_reconfig);
2463
2464 bgp = peer->bgp;
2465
2466 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002467 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002468 {
2469 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2470 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2471 sub_type, prd, tag);
2472 }
2473
2474 return ret;
2475}
2476
2477int
paul718e3742002-12-13 20:15:29 +00002478bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002479 afi_t afi, safi_t safi, int type, int sub_type,
2480 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002481{
2482 struct bgp *bgp;
2483 char buf[SU_ADDRSTRLEN];
2484 struct bgp_node *rn;
2485 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002486 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002487 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002488
2489 bgp = peer->bgp;
2490
David Lamparter4584c232015-04-13 09:50:00 +02002491 /* Lookup node. */
2492 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2493
2494 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2495 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2496 * the iteration over all RS clients.
2497 * Since we need to remove the entry from adj_in anyway, do that first and
2498 * if there was no entry, we don't need to do anything more. */
2499 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2500 && peer != bgp->peer_self)
2501 if (!bgp_adj_in_unset (rn, peer))
2502 {
2503 if (BGP_DEBUG (update, UPDATE_IN))
2504 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2505 "not in adj-in", peer->host,
2506 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2507 p->prefixlen);
2508 bgp_unlock_node (rn);
2509 return 0;
2510 }
2511
paulfee0f4c2004-09-13 05:12:46 +00002512 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002513 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002514 {
2515 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2516 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2517 }
2518
paul718e3742002-12-13 20:15:29 +00002519 /* Logging. */
2520 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002521 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002522 peer->host,
2523 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2524 p->prefixlen);
2525
paul718e3742002-12-13 20:15:29 +00002526 /* Lookup withdrawn route. */
2527 for (ri = rn->info; ri; ri = ri->next)
2528 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2529 break;
2530
2531 /* Withdraw specified route from routing table. */
2532 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002533 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002534 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002535 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002536 "%s Can't find the route %s/%d", peer->host,
2537 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2538 p->prefixlen);
2539
2540 /* Unlock bgp_node_get() lock. */
2541 bgp_unlock_node (rn);
2542
2543 return 0;
2544}
David Lamparter6b0655a2014-06-04 06:53:35 +02002545
paul718e3742002-12-13 20:15:29 +00002546void
2547bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2548{
2549 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002550 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002551 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002552 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002553 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002554 struct bgp_node *rn;
2555 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002556 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002557
Paul Jakmab2497022007-06-14 11:17:58 +00002558 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002559 return;
2560
paul718e3742002-12-13 20:15:29 +00002561 bgp = peer->bgp;
2562 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002563
paul718e3742002-12-13 20:15:29 +00002564 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2565 aspath = attr.aspath;
2566 attr.local_pref = bgp->default_local_pref;
2567 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2568
2569 if (afi == AFI_IP)
2570 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002571 else if (afi == AFI_IP6)
2572 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002573 struct attr_extra *ae = attr.extra;
2574
paul718e3742002-12-13 20:15:29 +00002575 str2prefix ("::/0", &p);
2576
2577 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002579 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002580 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002581
2582 /* If the peer is on shared nextwork and we have link-local
2583 nexthop set it. */
2584 if (peer->shared_network
2585 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2586 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002587 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002588 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002589 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002590 }
2591 }
paul718e3742002-12-13 20:15:29 +00002592
2593 if (peer->default_rmap[afi][safi].name)
2594 {
paulfee0f4c2004-09-13 05:12:46 +00002595 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2597 {
2598 for (ri = rn->info; ri; ri = ri->next)
2599 {
2600 struct attr dummy_attr;
2601 struct attr_extra dummy_extra;
2602 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002603
Christian Frankedcab1bb2012-12-07 16:45:52 +00002604 /* Provide dummy so the route-map can't modify the attributes */
2605 dummy_attr.extra = &dummy_extra;
2606 bgp_attr_dup(&dummy_attr, ri->attr);
2607 info.peer = ri->peer;
2608 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002609
Christian Frankedcab1bb2012-12-07 16:45:52 +00002610 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2611 RMAP_BGP, &info);
2612
2613 /* The route map might have set attributes. If we don't flush them
2614 * here, they will be leaked. */
2615 bgp_attr_flush(&dummy_attr);
2616 if (ret != RMAP_DENYMATCH)
2617 break;
2618 }
2619 if (ret != RMAP_DENYMATCH)
2620 break;
2621 }
paulfee0f4c2004-09-13 05:12:46 +00002622 bgp->peer_self->rmap_type = 0;
2623
paul718e3742002-12-13 20:15:29 +00002624 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002626 }
2627
2628 if (withdraw)
2629 {
2630 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2631 bgp_default_withdraw_send (peer, afi, safi);
2632 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2633 }
2634 else
2635 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002636 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2637 {
2638 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2639 bgp_default_update_send (peer, &attr, afi, safi, from);
2640 }
paul718e3742002-12-13 20:15:29 +00002641 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002642
2643 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002644 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002645}
David Lamparter6b0655a2014-06-04 06:53:35 +02002646
paul718e3742002-12-13 20:15:29 +00002647static void
2648bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002649 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002650{
2651 struct bgp_node *rn;
2652 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002653 struct attr attr;
2654 struct attr_extra extra;
2655
Lou Berger298cc2f2016-01-12 13:42:02 -05002656 memset(&extra, 0, sizeof(extra));
2657
paul718e3742002-12-13 20:15:29 +00002658 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002659 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002660
Lou Berger298cc2f2016-01-12 13:42:02 -05002661 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002662 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2663 bgp_default_originate (peer, afi, safi, 0);
2664
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002665 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2666 attr.extra = &extra;
2667
paul718e3742002-12-13 20:15:29 +00002668 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2669 for (ri = rn->info; ri; ri = ri->next)
2670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2671 {
paulfee0f4c2004-09-13 05:12:46 +00002672 if ( (rsclient) ?
2673 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2674 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002675 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2676 else
2677 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2678 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002679
2680 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2685{
2686 struct bgp_node *rn;
2687 struct bgp_table *table;
2688
2689 if (peer->status != Established)
2690 return;
2691
2692 if (! peer->afc_nego[afi][safi])
2693 return;
2694
2695 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2696 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2697 return;
2698
Lou Berger298cc2f2016-01-12 13:42:02 -05002699 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002700 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002701 else
2702 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2703 rn = bgp_route_next(rn))
2704 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_announce_table (peer, afi, safi, table, 0);
2706
2707 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2708 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002709}
2710
2711void
2712bgp_announce_route_all (struct peer *peer)
2713{
2714 afi_t afi;
2715 safi_t safi;
2716
2717 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2718 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2719 bgp_announce_route (peer, afi, safi);
2720}
David Lamparter6b0655a2014-06-04 06:53:35 +02002721
paul718e3742002-12-13 20:15:29 +00002722static void
paulfee0f4c2004-09-13 05:12:46 +00002723bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002724 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002725{
2726 struct bgp_node *rn;
2727 struct bgp_adj_in *ain;
2728
2729 if (! table)
2730 table = rsclient->bgp->rib[afi][safi];
2731
2732 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2733 for (ain = rn->adj_in; ain; ain = ain->next)
2734 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737
paulfee0f4c2004-09-13 05:12:46 +00002738 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002739 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002740 }
2741}
2742
2743void
2744bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2745{
2746 struct bgp_table *table;
2747 struct bgp_node *rn;
2748
Lou Berger298cc2f2016-01-12 13:42:02 -05002749 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002751
2752 else
2753 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2754 rn = bgp_route_next (rn))
2755 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 {
2757 struct prefix_rd prd;
2758 prd.family = AF_UNSPEC;
2759 prd.prefixlen = 64;
2760 memcpy(&prd.val, rn->p.u.val, 8);
2761
2762 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2763 }
paulfee0f4c2004-09-13 05:12:46 +00002764}
David Lamparter6b0655a2014-06-04 06:53:35 +02002765
paulfee0f4c2004-09-13 05:12:46 +00002766static void
paul718e3742002-12-13 20:15:29 +00002767bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002768 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002769{
2770 int ret;
2771 struct bgp_node *rn;
2772 struct bgp_adj_in *ain;
2773
2774 if (! table)
2775 table = peer->bgp->rib[afi][safi];
2776
2777 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2778 for (ain = rn->adj_in; ain; ain = ain->next)
2779 {
2780 if (ain->peer == peer)
2781 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002782 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2786 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002787 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002788
paul718e3742002-12-13 20:15:29 +00002789 if (ret < 0)
2790 {
2791 bgp_unlock_node (rn);
2792 return;
2793 }
2794 continue;
2795 }
2796 }
2797}
2798
2799void
2800bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2801{
2802 struct bgp_node *rn;
2803 struct bgp_table *table;
2804
2805 if (peer->status != Established)
2806 return;
2807
Lou Berger298cc2f2016-01-12 13:42:02 -05002808 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002809 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002810 else
2811 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2812 rn = bgp_route_next (rn))
2813 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002814 {
2815 struct prefix_rd prd;
2816 prd.family = AF_UNSPEC;
2817 prd.prefixlen = 64;
2818 memcpy(&prd.val, rn->p.u.val, 8);
2819
2820 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2821 }
paul718e3742002-12-13 20:15:29 +00002822}
David Lamparter6b0655a2014-06-04 06:53:35 +02002823
Chris Caputo228da422009-07-18 05:44:03 +00002824
2825struct bgp_clear_node_queue
2826{
2827 struct bgp_node *rn;
2828 enum bgp_clear_route_type purpose;
2829};
2830
paul200df112005-06-01 11:17:05 +00002831static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002837 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002838 afi_t afi = bgp_node_table (rn)->afi;
2839 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002840
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002842
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002844 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002845 {
2846 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2848 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002849 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002850 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2851 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002852 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002853 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002854 break;
2855 }
paul200df112005-06-01 11:17:05 +00002856 return WQ_SUCCESS;
2857}
2858
2859static void
paul0fb58d52005-11-14 14:31:49 +00002860bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002861{
Chris Caputo228da422009-07-18 05:44:03 +00002862 struct bgp_clear_node_queue *cnq = data;
2863 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002864 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002865
2866 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002867 bgp_table_unlock (table);
2868 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002869}
2870
2871static void
paul94f2b392005-06-28 12:44:16 +00002872bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002873{
Paul Jakma64e580a2006-02-21 01:09:01 +00002874 struct peer *peer = wq->spec.data;
2875
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002876 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002877 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002878
2879 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002880}
2881
2882static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002883bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002884{
Paul Jakmaa2943652009-07-21 14:02:04 +01002885 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002886
Paul Jakmaa2943652009-07-21 14:02:04 +01002887 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002888#undef CLEAR_QUEUE_NAME_LEN
2889
2890 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002891 {
2892 zlog_err ("%s: Failed to allocate work queue", __func__);
2893 exit (1);
2894 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002895 peer->clear_node_queue->spec.hold = 10;
2896 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2897 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2898 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2899 peer->clear_node_queue->spec.max_retries = 0;
2900
2901 /* we only 'lock' this peer reference when the queue is actually active */
2902 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002903}
2904
paul718e3742002-12-13 20:15:29 +00002905static void
2906bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002907 struct bgp_table *table, struct peer *rsclient,
2908 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002909{
2910 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002911
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002912
paul718e3742002-12-13 20:15:29 +00002913 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002914 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002915
hasso6cf159b2005-03-21 10:28:14 +00002916 /* If still no table => afi/safi isn't configured at all or smth. */
2917 if (! table)
2918 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002919
2920 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2921 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002922 struct bgp_info *ri;
2923 struct bgp_adj_in *ain;
2924 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002925
2926 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2927 * queued for every clearing peer, regardless of whether it is
2928 * relevant to the peer at hand.
2929 *
2930 * Overview: There are 3 different indices which need to be
2931 * scrubbed, potentially, when a peer is removed:
2932 *
2933 * 1 peer's routes visible via the RIB (ie accepted routes)
2934 * 2 peer's routes visible by the (optional) peer's adj-in index
2935 * 3 other routes visible by the peer's adj-out index
2936 *
2937 * 3 there is no hurry in scrubbing, once the struct peer is
2938 * removed from bgp->peer, we could just GC such deleted peer's
2939 * adj-outs at our leisure.
2940 *
2941 * 1 and 2 must be 'scrubbed' in some way, at least made
2942 * invisible via RIB index before peer session is allowed to be
2943 * brought back up. So one needs to know when such a 'search' is
2944 * complete.
2945 *
2946 * Ideally:
2947 *
2948 * - there'd be a single global queue or a single RIB walker
2949 * - rather than tracking which route_nodes still need to be
2950 * examined on a peer basis, we'd track which peers still
2951 * aren't cleared
2952 *
2953 * Given that our per-peer prefix-counts now should be reliable,
2954 * this may actually be achievable. It doesn't seem to be a huge
2955 * problem at this time,
2956 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002957 for (ain = rn->adj_in; ain; ain = ain->next)
2958 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2959 {
2960 bgp_adj_in_remove (rn, ain);
2961 bgp_unlock_node (rn);
2962 break;
2963 }
2964 for (aout = rn->adj_out; aout; aout = aout->next)
2965 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2966 {
2967 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2968 bgp_unlock_node (rn);
2969 break;
2970 }
2971
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002972 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002973 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 {
Chris Caputo228da422009-07-18 05:44:03 +00002975 struct bgp_clear_node_queue *cnq;
2976
2977 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002978 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002979 bgp_lock_node (rn);
2980 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2981 sizeof (struct bgp_clear_node_queue));
2982 cnq->rn = rn;
2983 cnq->purpose = purpose;
2984 work_queue_add (peer->clear_node_queue, cnq);
2985 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002986 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002987 }
2988 return;
2989}
2990
2991void
Chris Caputo228da422009-07-18 05:44:03 +00002992bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2993 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002994{
2995 struct bgp_node *rn;
2996 struct bgp_table *table;
2997 struct peer *rsclient;
2998 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002999
Paul Jakma64e580a2006-02-21 01:09:01 +00003000 if (peer->clear_node_queue == NULL)
3001 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003002
Paul Jakmaca058a32006-09-14 02:58:49 +00003003 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3004 * Idle until it receives a Clearing_Completed event. This protects
3005 * against peers which flap faster than we can we clear, which could
3006 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003007 *
3008 * a) race with routes from the new session being installed before
3009 * clear_route_node visits the node (to delete the route of that
3010 * peer)
3011 * b) resource exhaustion, clear_route_node likely leads to an entry
3012 * on the process_main queue. Fast-flapping could cause that queue
3013 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003014 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003015
3016 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3017 * the unlock will happen upon work-queue completion; other wise, the
3018 * unlock happens at the end of this function.
3019 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003020 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003021 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003022 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003023 {
Chris Caputo228da422009-07-18 05:44:03 +00003024 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003025 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003026 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3027 else
3028 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3029 rn = bgp_route_next (rn))
3030 if ((table = rn->info) != NULL)
3031 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3032
3033 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3034 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3035 PEER_FLAG_RSERVER_CLIENT))
3036 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3037 break;
3038
3039 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003040 /*
3041 * gpz 091009: TBD why don't we have special handling for
3042 * SAFI_MPLS_VPN here in the original quagga code?
3043 * (and, by extension, for SAFI_ENCAP)
3044 */
Chris Caputo228da422009-07-18 05:44:03 +00003045 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3046 break;
3047
3048 default:
3049 assert (0);
3050 break;
paulfee0f4c2004-09-13 05:12:46 +00003051 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003052
3053 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003054 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003055 peer_unlock (peer);
3056
paul718e3742002-12-13 20:15:29 +00003057}
3058
3059void
3060bgp_clear_route_all (struct peer *peer)
3061{
3062 afi_t afi;
3063 safi_t safi;
3064
3065 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3066 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003067 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003068}
3069
Lou Berger82dd7072016-01-12 13:41:57 -05003070/*
3071 * Finish freeing things when exiting
3072 */
3073static void
3074bgp_drain_workqueue_immediate (struct work_queue *wq)
3075{
3076 if (!wq)
3077 return;
3078
3079 if (!wq->thread)
3080 {
3081 /*
3082 * no thread implies no queued items
3083 */
3084 assert(!wq->items->count);
3085 return;
3086 }
3087
3088 while (wq->items->count)
3089 {
3090 if (wq->thread)
3091 thread_cancel(wq->thread);
3092 work_queue_run(wq->thread);
3093 }
3094}
3095
3096/*
3097 * Special function to process clear node queue when bgpd is exiting
3098 * and the thread scheduler is no longer running.
3099 */
3100void
3101bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3102{
3103 if (!peer)
3104 return;
3105
3106 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3107}
3108
3109/*
3110 * The work queues are not specific to a BGP instance, but the
3111 * items in them refer to BGP instances, so this should be called
3112 * before each BGP instance is deleted.
3113 */
3114void
3115bgp_process_queues_drain_immediate(void)
3116{
3117 bgp_drain_workqueue_immediate(bm->process_main_queue);
3118 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3119}
3120
paul718e3742002-12-13 20:15:29 +00003121void
3122bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3123{
3124 struct bgp_table *table;
3125 struct bgp_node *rn;
3126 struct bgp_adj_in *ain;
3127
3128 table = peer->bgp->rib[afi][safi];
3129
3130 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3131 for (ain = rn->adj_in; ain ; ain = ain->next)
3132 if (ain->peer == peer)
3133 {
3134 bgp_adj_in_remove (rn, ain);
3135 bgp_unlock_node (rn);
3136 break;
3137 }
3138}
hasso93406d82005-02-02 14:40:33 +00003139
3140void
3141bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3142{
3143 struct bgp_node *rn;
3144 struct bgp_info *ri;
3145 struct bgp_table *table;
3146
3147 table = peer->bgp->rib[afi][safi];
3148
3149 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3150 {
3151 for (ri = rn->info; ri; ri = ri->next)
3152 if (ri->peer == peer)
3153 {
3154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3155 bgp_rib_remove (rn, ri, peer, afi, safi);
3156 break;
3157 }
3158 }
3159}
David Lamparter6b0655a2014-06-04 06:53:35 +02003160
Lou Berger82dd7072016-01-12 13:41:57 -05003161static void
3162bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3163{
3164 struct bgp_node *rn;
3165 struct bgp_info *ri;
3166 struct bgp_info *next;
3167
3168 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3169 for (ri = rn->info; ri; ri = next)
3170 {
3171 next = ri->next;
3172 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3173 && ri->type == ZEBRA_ROUTE_BGP
3174 && ri->sub_type == BGP_ROUTE_NORMAL)
3175 bgp_zebra_withdraw (&rn->p, ri, safi);
3176 }
3177}
3178
paul718e3742002-12-13 20:15:29 +00003179/* Delete all kernel routes. */
3180void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003181bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003182{
3183 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003184 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003185 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003186
paul1eb8ef22005-04-07 07:30:20 +00003187 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003188 {
Lou Berger82dd7072016-01-12 13:41:57 -05003189 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3190 {
3191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003192
Lou Berger82dd7072016-01-12 13:41:57 -05003193 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003194
Lou Berger82dd7072016-01-12 13:41:57 -05003195 /*
3196 * VPN and ENCAP tables are two-level (RD is top level)
3197 */
3198 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3199 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003200 {
3201 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003202 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003203 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3204 bgp_table_finish ((struct bgp_table **)&(rn->info));
3205 rn->info = NULL;
3206 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003207 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003208 }
3209
3210 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3211 rn = bgp_route_next (rn))
3212 {
3213 if (rn->info)
3214 {
3215 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3216 bgp_table_finish ((struct bgp_table **)&(rn->info));
3217 rn->info = NULL;
3218 bgp_unlock_node(rn);
3219 }
3220 }
Lou Berger82dd7072016-01-12 13:41:57 -05003221 }
paul718e3742002-12-13 20:15:29 +00003222 }
3223}
3224
3225void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003226bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003227{
3228 vty_reset ();
3229 bgp_zclient_reset ();
3230 access_list_reset ();
3231 prefix_list_reset ();
3232}
David Lamparter6b0655a2014-06-04 06:53:35 +02003233
paul718e3742002-12-13 20:15:29 +00003234/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3235 value. */
3236int
Paul Jakma518a4b72016-02-04 13:27:04 +00003237bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3238 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003239{
3240 u_char *pnt;
3241 u_char *lim;
3242 struct prefix p;
3243 int psize;
3244 int ret;
3245
3246 /* Check peer status. */
3247 if (peer->status != Established)
3248 return 0;
3249
3250 pnt = packet->nlri;
3251 lim = pnt + packet->length;
3252
Paul Jakma405e9e12016-02-04 17:00:18 +00003253 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3254 syntactic validity. If the field is syntactically incorrect,
3255 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003256 for (; pnt < lim; pnt += psize)
3257 {
3258 /* Clear prefix structure. */
3259 memset (&p, 0, sizeof (struct prefix));
3260
3261 /* Fetch prefix length. */
3262 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003263 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003264 p.family = afi2family (packet->afi);
3265
Paul Jakma405e9e12016-02-04 17:00:18 +00003266 /* Prefix length check. */
3267 if (p.prefixlen > prefix_blen (&p) * 8)
3268 {
3269 plog_err (peer->log,
3270 "%s [Error] Update packet error"
3271 " (wrong prefix length %u for afi %u)",
3272 peer->host, p.prefixlen, packet->afi);
3273 return -1;
3274 }
3275
paul718e3742002-12-13 20:15:29 +00003276 /* Packet size overflow check. */
3277 psize = PSIZE (p.prefixlen);
3278
3279 /* When packet overflow occur return immediately. */
3280 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003281 {
3282 plog_err (peer->log,
3283 "%s [Error] Update packet error"
3284 " (prefix length %u overflows packet)",
3285 peer->host, p.prefixlen);
3286 return -1;
3287 }
3288
3289 /* Defensive coding, double-check the psize fits in a struct prefix */
3290 if (psize > (ssize_t) sizeof(p.u))
3291 {
3292 plog_err (peer->log,
3293 "%s [Error] Update packet error"
3294 " (prefix length %u too large for prefix storage %zu!?!!",
3295 peer->host, p.prefixlen, sizeof(p.u));
3296 return -1;
3297 }
paul718e3742002-12-13 20:15:29 +00003298
3299 /* Fetch prefix from NLRI packet. */
3300 memcpy (&p.u.prefix, pnt, psize);
3301
3302 /* Check address. */
3303 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3304 {
3305 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3306 {
paulf5ba3872004-07-09 12:11:31 +00003307 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003308 * From RFC4271 Section 6.3:
3309 *
3310 * If a prefix in the NLRI field is semantically incorrect
3311 * (e.g., an unexpected multicast IP address), an error SHOULD
3312 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003313 */
paul718e3742002-12-13 20:15:29 +00003314 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003315 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3316 peer->host, inet_ntoa (p.u.prefix4));
3317 continue;
paul718e3742002-12-13 20:15:29 +00003318 }
3319 }
3320
paul718e3742002-12-13 20:15:29 +00003321 /* Check address. */
3322 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3323 {
3324 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3325 {
3326 char buf[BUFSIZ];
3327
Paul Jakma405e9e12016-02-04 17:00:18 +00003328 zlog (peer->log, LOG_ERR,
3329 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3330 peer->host,
paul718e3742002-12-13 20:15:29 +00003331 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003332 continue;
3333 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003334 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3335 {
3336 char buf[BUFSIZ];
3337
3338 zlog (peer->log, LOG_ERR,
3339 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3340 peer->host,
3341 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3342 continue;
3343 }
3344 }
paul718e3742002-12-13 20:15:29 +00003345
3346 /* Normal process. */
3347 if (attr)
3348 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3349 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3350 else
3351 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3352 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3353
3354 /* Address family configuration mismatch or maximum-prefix count
3355 overflow. */
3356 if (ret < 0)
3357 return -1;
3358 }
3359
3360 /* Packet length consistency check. */
3361 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003362 {
3363 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003364 "%s [Error] Update packet error"
3365 " (prefix length mismatch with total length)",
3366 peer->host);
paul718e3742002-12-13 20:15:29 +00003367 return -1;
3368 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003369
paul718e3742002-12-13 20:15:29 +00003370 return 0;
3371}
David Lamparter6b0655a2014-06-04 06:53:35 +02003372
paul94f2b392005-06-28 12:44:16 +00003373static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003374bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003375{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003376 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003377}
3378
paul94f2b392005-06-28 12:44:16 +00003379static void
paul718e3742002-12-13 20:15:29 +00003380bgp_static_free (struct bgp_static *bgp_static)
3381{
3382 if (bgp_static->rmap.name)
3383 free (bgp_static->rmap.name);
3384 XFREE (MTYPE_BGP_STATIC, bgp_static);
3385}
3386
paul94f2b392005-06-28 12:44:16 +00003387static void
paulfee0f4c2004-09-13 05:12:46 +00003388bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3389 struct prefix *p, afi_t afi, safi_t safi)
3390{
3391 struct bgp_node *rn;
3392 struct bgp_info *ri;
3393
3394 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3395
3396 /* Check selected route and self inserted route. */
3397 for (ri = rn->info; ri; ri = ri->next)
3398 if (ri->peer == bgp->peer_self
3399 && ri->type == ZEBRA_ROUTE_BGP
3400 && ri->sub_type == BGP_ROUTE_STATIC)
3401 break;
3402
3403 /* Withdraw static BGP route from routing table. */
3404 if (ri)
3405 {
paulfee0f4c2004-09-13 05:12:46 +00003406 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003407 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003408 }
3409
3410 /* Unlock bgp_node_lookup. */
3411 bgp_unlock_node (rn);
3412}
3413
paul94f2b392005-06-28 12:44:16 +00003414static void
paulfee0f4c2004-09-13 05:12:46 +00003415bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 struct bgp_static *bgp_static,
3417 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003418{
3419 struct bgp_node *rn;
3420 struct bgp_info *ri;
3421 struct bgp_info *new;
3422 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003423 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003424 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003425 struct attr new_attr;
3426 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003427 struct bgp *bgp;
3428 int ret;
3429 char buf[SU_ADDRSTRLEN];
3430
3431 bgp = rsclient->bgp;
3432
Paul Jakma06e110f2006-05-12 23:29:22 +00003433 assert (bgp_static);
3434 if (!bgp_static)
3435 return;
3436
paulfee0f4c2004-09-13 05:12:46 +00003437 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3438
3439 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003440
3441 attr.nexthop = bgp_static->igpnexthop;
3442 attr.med = bgp_static->igpmetric;
3443 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003444
Paul Jakma41367172007-08-06 15:24:51 +00003445 if (bgp_static->atomic)
3446 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3447
paulfee0f4c2004-09-13 05:12:46 +00003448 /* Apply network route-map for export to this rsclient. */
3449 if (bgp_static->rmap.name)
3450 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003452 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 info.attr = &attr_tmp;
3454
paulfee0f4c2004-09-13 05:12:46 +00003455 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3456 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3457
3458 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3459
3460 rsclient->rmap_type = 0;
3461
3462 if (ret == RMAP_DENYMATCH)
3463 {
3464 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003465 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003466
3467 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003468 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003469 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003470 bgp_attr_extra_free (&attr);
3471
paulfee0f4c2004-09-13 05:12:46 +00003472 return;
3473 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003474 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003475 }
3476 else
3477 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003478
3479 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003480 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3483
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3485 == RMAP_DENY)
3486 {
paulfee0f4c2004-09-13 05:12:46 +00003487 /* This BGP update is filtered. Log the reason then update BGP entry. */
3488 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003489 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003490 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3491 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3492 p->prefixlen, rsclient->host);
3493
3494 bgp->peer_self->rmap_type = 0;
3495
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 bgp_attr_unintern (&attr_new);
3497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003498 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003499
3500 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3501
3502 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 }
paulfee0f4c2004-09-13 05:12:46 +00003504
3505 bgp->peer_self->rmap_type = 0;
3506
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003507 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003508 attr_new = bgp_attr_intern (&new_attr);
3509
3510 for (ri = rn->info; ri; ri = ri->next)
3511 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3512 && ri->sub_type == BGP_ROUTE_STATIC)
3513 break;
3514
3515 if (ri)
3516 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003517 if (attrhash_cmp (ri->attr, attr_new) &&
3518 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003519 {
3520 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003521 bgp_attr_unintern (&attr_new);
3522 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003523 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003524 return;
3525 }
3526 else
3527 {
3528 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003529 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003530
3531 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003532 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3533 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003534 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003535 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003536 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003537
3538 /* Process change. */
3539 bgp_process (bgp, rn, afi, safi);
3540 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003542 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003543 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003544 }
paulfee0f4c2004-09-13 05:12:46 +00003545 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003546
paulfee0f4c2004-09-13 05:12:46 +00003547 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003548 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3549 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003550 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003551
3552 /* Register new BGP information. */
3553 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003554
3555 /* route_node_get lock */
3556 bgp_unlock_node (rn);
3557
paulfee0f4c2004-09-13 05:12:46 +00003558 /* Process change. */
3559 bgp_process (bgp, rn, afi, safi);
3560
3561 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003564}
3565
paul94f2b392005-06-28 12:44:16 +00003566static void
paulfee0f4c2004-09-13 05:12:46 +00003567bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003568 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3569{
3570 struct bgp_node *rn;
3571 struct bgp_info *ri;
3572 struct bgp_info *new;
3573 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003574 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003575 struct attr *attr_new;
3576 int ret;
3577
Paul Jakmadd8103a2006-05-12 23:27:30 +00003578 assert (bgp_static);
3579 if (!bgp_static)
3580 return;
3581
paulfee0f4c2004-09-13 05:12:46 +00003582 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003583
3584 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003585
3586 attr.nexthop = bgp_static->igpnexthop;
3587 attr.med = bgp_static->igpmetric;
3588 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003589
Paul Jakma41367172007-08-06 15:24:51 +00003590 if (bgp_static->atomic)
3591 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Apply route-map. */
3594 if (bgp_static->rmap.name)
3595 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003596 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003597 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003598 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003599
paulfee0f4c2004-09-13 05:12:46 +00003600 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3601
paul718e3742002-12-13 20:15:29 +00003602 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003603
paulfee0f4c2004-09-13 05:12:46 +00003604 bgp->peer_self->rmap_type = 0;
3605
paul718e3742002-12-13 20:15:29 +00003606 if (ret == RMAP_DENYMATCH)
3607 {
3608 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003609 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003610
3611 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003612 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003613 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003614 bgp_static_withdraw (bgp, p, afi, safi);
3615 return;
3616 }
paul286e1e72003-08-08 00:24:31 +00003617 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003618 }
paul286e1e72003-08-08 00:24:31 +00003619 else
3620 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003621
3622 for (ri = rn->info; ri; ri = ri->next)
3623 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3624 && ri->sub_type == BGP_ROUTE_STATIC)
3625 break;
3626
3627 if (ri)
3628 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003629 if (attrhash_cmp (ri->attr, attr_new) &&
3630 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003631 {
3632 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003633 bgp_attr_unintern (&attr_new);
3634 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003635 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003636 return;
3637 }
3638 else
3639 {
3640 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003641 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003642
3643 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003644 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3645 bgp_info_restore(rn, ri);
3646 else
3647 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003648 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003649 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003650 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003651
3652 /* Process change. */
3653 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3654 bgp_process (bgp, rn, afi, safi);
3655 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003656 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003657 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003658 return;
3659 }
3660 }
3661
3662 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003663 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3664 rn);
paul718e3742002-12-13 20:15:29 +00003665 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003666
3667 /* Aggregate address increment. */
3668 bgp_aggregate_increment (bgp, p, new, afi, safi);
3669
3670 /* Register new BGP information. */
3671 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003672
3673 /* route_node_get lock */
3674 bgp_unlock_node (rn);
3675
paul718e3742002-12-13 20:15:29 +00003676 /* Process change. */
3677 bgp_process (bgp, rn, afi, safi);
3678
3679 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003680 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003681 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003682}
3683
3684void
paulfee0f4c2004-09-13 05:12:46 +00003685bgp_static_update (struct bgp *bgp, struct prefix *p,
3686 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3687{
3688 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003689 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003690
3691 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3692
paul1eb8ef22005-04-07 07:30:20 +00003693 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003694 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003695 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3696 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003697 }
3698}
3699
paul718e3742002-12-13 20:15:29 +00003700void
3701bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3702 safi_t safi)
3703{
3704 struct bgp_node *rn;
3705 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003706 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003707
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003708 /* Make new BGP info. */
3709 rn = bgp_node_get (bgp->rib[afi][safi], p);
3710 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3711 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3712
3713 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003714
3715 /* Check selected route and self inserted route. */
3716 for (ri = rn->info; ri; ri = ri->next)
3717 if (ri->peer == bgp->peer_self
3718 && ri->type == ZEBRA_ROUTE_BGP
3719 && ri->sub_type == BGP_ROUTE_STATIC)
3720 break;
3721
3722 /* Withdraw static BGP route from routing table. */
3723 if (ri)
3724 {
3725 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003726 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003727 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003728 }
3729
3730 /* Unlock bgp_node_lookup. */
3731 bgp_unlock_node (rn);
3732}
3733
3734void
paulfee0f4c2004-09-13 05:12:46 +00003735bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3736{
3737 struct bgp_static *bgp_static;
3738 struct bgp *bgp;
3739 struct bgp_node *rn;
3740 struct prefix *p;
3741
3742 bgp = rsclient->bgp;
3743
3744 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3745 if ((bgp_static = rn->info) != NULL)
3746 {
3747 p = &rn->p;
3748
3749 bgp_static_update_rsclient (rsclient, p, bgp_static,
3750 afi, safi);
3751 }
3752}
3753
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754/*
3755 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3756 */
paul94f2b392005-06-28 12:44:16 +00003757static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003758bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3759 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003760{
3761 struct bgp_node *rn;
3762 struct bgp_info *ri;
3763
paulfee0f4c2004-09-13 05:12:46 +00003764 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003765
3766 /* Check selected route and self inserted route. */
3767 for (ri = rn->info; ri; ri = ri->next)
3768 if (ri->peer == bgp->peer_self
3769 && ri->type == ZEBRA_ROUTE_BGP
3770 && ri->sub_type == BGP_ROUTE_STATIC)
3771 break;
3772
3773 /* Withdraw static BGP route from routing table. */
3774 if (ri)
3775 {
3776 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003777 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003778 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003779 }
3780
3781 /* Unlock bgp_node_lookup. */
3782 bgp_unlock_node (rn);
3783}
3784
Lou Bergera76d9ca2016-01-12 13:41:53 -05003785static void
3786bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3787 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3788{
3789 struct bgp_node *rn;
3790 struct bgp_info *new;
3791 struct attr *attr_new;
3792 struct attr attr = { 0 };
3793 struct bgp_info *ri;
3794
3795 assert (bgp_static);
3796
3797 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3798
3799 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3800
3801 attr.nexthop = bgp_static->igpnexthop;
3802 attr.med = bgp_static->igpmetric;
3803 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3804
3805 /* Apply route-map. */
3806 if (bgp_static->rmap.name)
3807 {
3808 struct attr attr_tmp = attr;
3809 struct bgp_info info;
3810 int ret;
3811
3812 info.peer = bgp->peer_self;
3813 info.attr = &attr_tmp;
3814
3815 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3816
3817 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3818
3819 bgp->peer_self->rmap_type = 0;
3820
3821 if (ret == RMAP_DENYMATCH)
3822 {
3823 /* Free uninterned attribute. */
3824 bgp_attr_flush (&attr_tmp);
3825
3826 /* Unintern original. */
3827 aspath_unintern (&attr.aspath);
3828 bgp_attr_extra_free (&attr);
3829 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3830 bgp_static->tag);
3831 return;
3832 }
3833
3834 attr_new = bgp_attr_intern (&attr_tmp);
3835 }
3836 else
3837 {
3838 attr_new = bgp_attr_intern (&attr);
3839 }
3840
3841 for (ri = rn->info; ri; ri = ri->next)
3842 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3843 && ri->sub_type == BGP_ROUTE_STATIC)
3844 break;
3845
3846 if (ri)
3847 {
3848 if (attrhash_cmp (ri->attr, attr_new) &&
3849 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3850 {
3851 bgp_unlock_node (rn);
3852 bgp_attr_unintern (&attr_new);
3853 aspath_unintern (&attr.aspath);
3854 bgp_attr_extra_free (&attr);
3855 return;
3856 }
3857 else
3858 {
3859 /* The attribute is changed. */
3860 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3861
3862 /* Rewrite BGP route information. */
3863 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3864 bgp_info_restore(rn, ri);
3865 else
3866 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3867 bgp_attr_unintern (&ri->attr);
3868 ri->attr = attr_new;
3869 ri->uptime = bgp_clock ();
3870
3871 /* Process change. */
3872 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3873 bgp_process (bgp, rn, afi, safi);
3874 bgp_unlock_node (rn);
3875 aspath_unintern (&attr.aspath);
3876 bgp_attr_extra_free (&attr);
3877 return;
3878 }
3879 }
3880
3881
3882 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003883 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3884 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003885 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003886 new->extra = bgp_info_extra_new();
3887 memcpy (new->extra->tag, bgp_static->tag, 3);
3888
3889 /* Aggregate address increment. */
3890 bgp_aggregate_increment (bgp, p, new, afi, safi);
3891
3892 /* Register new BGP information. */
3893 bgp_info_add (rn, new);
3894
3895 /* route_node_get lock */
3896 bgp_unlock_node (rn);
3897
3898 /* Process change. */
3899 bgp_process (bgp, rn, afi, safi);
3900
3901 /* Unintern original. */
3902 aspath_unintern (&attr.aspath);
3903 bgp_attr_extra_free (&attr);
3904}
3905
paul718e3742002-12-13 20:15:29 +00003906/* Configure static BGP network. When user don't run zebra, static
3907 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003908static int
paulfd79ac92004-10-13 05:06:08 +00003909bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003910 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003911{
3912 int ret;
3913 struct prefix p;
3914 struct bgp_static *bgp_static;
3915 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003916 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003917
3918 /* Convert IP prefix string to struct prefix. */
3919 ret = str2prefix (ip_str, &p);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
paul718e3742002-12-13 20:15:29 +00003925 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3926 {
3927 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3928 VTY_NEWLINE);
3929 return CMD_WARNING;
3930 }
paul718e3742002-12-13 20:15:29 +00003931
3932 apply_mask (&p);
3933
3934 /* Set BGP static route configuration. */
3935 rn = bgp_node_get (bgp->route[afi][safi], &p);
3936
3937 if (rn->info)
3938 {
3939 /* Configuration change. */
3940 bgp_static = rn->info;
3941
3942 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003943 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3944 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003945
paul718e3742002-12-13 20:15:29 +00003946 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003947
paul718e3742002-12-13 20:15:29 +00003948 if (rmap)
3949 {
3950 if (bgp_static->rmap.name)
3951 free (bgp_static->rmap.name);
3952 bgp_static->rmap.name = strdup (rmap);
3953 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3954 }
3955 else
3956 {
3957 if (bgp_static->rmap.name)
3958 free (bgp_static->rmap.name);
3959 bgp_static->rmap.name = NULL;
3960 bgp_static->rmap.map = NULL;
3961 bgp_static->valid = 0;
3962 }
3963 bgp_unlock_node (rn);
3964 }
3965 else
3966 {
3967 /* New configuration. */
3968 bgp_static = bgp_static_new ();
3969 bgp_static->backdoor = backdoor;
3970 bgp_static->valid = 0;
3971 bgp_static->igpmetric = 0;
3972 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003973
paul718e3742002-12-13 20:15:29 +00003974 if (rmap)
3975 {
3976 if (bgp_static->rmap.name)
3977 free (bgp_static->rmap.name);
3978 bgp_static->rmap.name = strdup (rmap);
3979 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3980 }
3981 rn->info = bgp_static;
3982 }
3983
3984 /* If BGP scan is not enabled, we should install this route here. */
3985 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3986 {
3987 bgp_static->valid = 1;
3988
3989 if (need_update)
3990 bgp_static_withdraw (bgp, &p, afi, safi);
3991
3992 if (! bgp_static->backdoor)
3993 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3994 }
3995
3996 return CMD_SUCCESS;
3997}
3998
3999/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004000static int
paulfd79ac92004-10-13 05:06:08 +00004001bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004002 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004003{
4004 int ret;
4005 struct prefix p;
4006 struct bgp_static *bgp_static;
4007 struct bgp_node *rn;
4008
4009 /* Convert IP prefix string to struct prefix. */
4010 ret = str2prefix (ip_str, &p);
4011 if (! ret)
4012 {
4013 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4014 return CMD_WARNING;
4015 }
paul718e3742002-12-13 20:15:29 +00004016 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4017 {
4018 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4019 VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
paul718e3742002-12-13 20:15:29 +00004022
4023 apply_mask (&p);
4024
4025 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4026 if (! rn)
4027 {
4028 vty_out (vty, "%% Can't find specified static route configuration.%s",
4029 VTY_NEWLINE);
4030 return CMD_WARNING;
4031 }
4032
4033 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004034
paul718e3742002-12-13 20:15:29 +00004035 /* Update BGP RIB. */
4036 if (! bgp_static->backdoor)
4037 bgp_static_withdraw (bgp, &p, afi, safi);
4038
4039 /* Clear configuration. */
4040 bgp_static_free (bgp_static);
4041 rn->info = NULL;
4042 bgp_unlock_node (rn);
4043 bgp_unlock_node (rn);
4044
4045 return CMD_SUCCESS;
4046}
4047
4048/* Called from bgp_delete(). Delete all static routes from the BGP
4049 instance. */
4050void
4051bgp_static_delete (struct bgp *bgp)
4052{
4053 afi_t afi;
4054 safi_t safi;
4055 struct bgp_node *rn;
4056 struct bgp_node *rm;
4057 struct bgp_table *table;
4058 struct bgp_static *bgp_static;
4059
4060 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4061 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4062 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4063 if (rn->info != NULL)
4064 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004065 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004066 {
4067 table = rn->info;
4068
4069 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4070 {
4071 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004072 bgp_static_withdraw_safi (bgp, &rm->p,
4073 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004074 (struct prefix_rd *)&rn->p,
4075 bgp_static->tag);
4076 bgp_static_free (bgp_static);
4077 rn->info = NULL;
4078 bgp_unlock_node (rn);
4079 }
4080 }
4081 else
4082 {
4083 bgp_static = rn->info;
4084 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4085 bgp_static_free (bgp_static);
4086 rn->info = NULL;
4087 bgp_unlock_node (rn);
4088 }
4089 }
4090}
4091
Lou Bergera76d9ca2016-01-12 13:41:53 -05004092/*
4093 * gpz 110624
4094 * Currently this is used to set static routes for VPN and ENCAP.
4095 * I think it can probably be factored with bgp_static_set.
4096 */
paul718e3742002-12-13 20:15:29 +00004097int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004098bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4099 const char *rd_str, const char *tag_str,
4100 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004101{
4102 int ret;
4103 struct prefix p;
4104 struct prefix_rd prd;
4105 struct bgp *bgp;
4106 struct bgp_node *prn;
4107 struct bgp_node *rn;
4108 struct bgp_table *table;
4109 struct bgp_static *bgp_static;
4110 u_char tag[3];
4111
4112 bgp = vty->index;
4113
4114 ret = str2prefix (ip_str, &p);
4115 if (! ret)
4116 {
4117 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4118 return CMD_WARNING;
4119 }
4120 apply_mask (&p);
4121
4122 ret = str2prefix_rd (rd_str, &prd);
4123 if (! ret)
4124 {
4125 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4126 return CMD_WARNING;
4127 }
4128
4129 ret = str2tag (tag_str, tag);
4130 if (! ret)
4131 {
4132 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4133 return CMD_WARNING;
4134 }
4135
Lou Bergera76d9ca2016-01-12 13:41:53 -05004136 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004137 (struct prefix *)&prd);
4138 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004139 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004140 else
4141 bgp_unlock_node (prn);
4142 table = prn->info;
4143
4144 rn = bgp_node_get (table, &p);
4145
4146 if (rn->info)
4147 {
4148 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4149 bgp_unlock_node (rn);
4150 }
4151 else
4152 {
4153 /* New configuration. */
4154 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004155 bgp_static->backdoor = 0;
4156 bgp_static->valid = 0;
4157 bgp_static->igpmetric = 0;
4158 bgp_static->igpnexthop.s_addr = 0;
4159 memcpy(bgp_static->tag, tag, 3);
4160 bgp_static->prd = prd;
4161
4162 if (rmap_str)
4163 {
4164 if (bgp_static->rmap.name)
4165 free (bgp_static->rmap.name);
4166 bgp_static->rmap.name = strdup (rmap_str);
4167 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4168 }
paul718e3742002-12-13 20:15:29 +00004169 rn->info = bgp_static;
4170
Lou Bergera76d9ca2016-01-12 13:41:53 -05004171 bgp_static->valid = 1;
4172 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004173 }
4174
4175 return CMD_SUCCESS;
4176}
4177
4178/* Configure static BGP network. */
4179int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004180bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4181 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004182{
4183 int ret;
4184 struct bgp *bgp;
4185 struct prefix p;
4186 struct prefix_rd prd;
4187 struct bgp_node *prn;
4188 struct bgp_node *rn;
4189 struct bgp_table *table;
4190 struct bgp_static *bgp_static;
4191 u_char tag[3];
4192
4193 bgp = vty->index;
4194
4195 /* Convert IP prefix string to struct prefix. */
4196 ret = str2prefix (ip_str, &p);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202 apply_mask (&p);
4203
4204 ret = str2prefix_rd (rd_str, &prd);
4205 if (! ret)
4206 {
4207 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4208 return CMD_WARNING;
4209 }
4210
4211 ret = str2tag (tag_str, tag);
4212 if (! ret)
4213 {
4214 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4215 return CMD_WARNING;
4216 }
4217
Lou Bergera76d9ca2016-01-12 13:41:53 -05004218 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004219 (struct prefix *)&prd);
4220 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004221 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004222 else
4223 bgp_unlock_node (prn);
4224 table = prn->info;
4225
4226 rn = bgp_node_lookup (table, &p);
4227
4228 if (rn)
4229 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004230 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004231
4232 bgp_static = rn->info;
4233 bgp_static_free (bgp_static);
4234 rn->info = NULL;
4235 bgp_unlock_node (rn);
4236 bgp_unlock_node (rn);
4237 }
4238 else
4239 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4240
4241 return CMD_SUCCESS;
4242}
David Lamparter6b0655a2014-06-04 06:53:35 +02004243
paul718e3742002-12-13 20:15:29 +00004244DEFUN (bgp_network,
4245 bgp_network_cmd,
4246 "network A.B.C.D/M",
4247 "Specify a network to announce via BGP\n"
4248 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4249{
4250 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004251 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004252}
4253
4254DEFUN (bgp_network_route_map,
4255 bgp_network_route_map_cmd,
4256 "network A.B.C.D/M route-map WORD",
4257 "Specify a network to announce via BGP\n"
4258 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4259 "Route-map to modify the attributes\n"
4260 "Name of the route map\n")
4261{
4262 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004263 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004264}
4265
4266DEFUN (bgp_network_backdoor,
4267 bgp_network_backdoor_cmd,
4268 "network A.B.C.D/M backdoor",
4269 "Specify a network to announce via BGP\n"
4270 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4271 "Specify a BGP backdoor route\n")
4272{
Paul Jakma41367172007-08-06 15:24:51 +00004273 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004274 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004275}
4276
4277DEFUN (bgp_network_mask,
4278 bgp_network_mask_cmd,
4279 "network A.B.C.D mask A.B.C.D",
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n")
4284{
4285 int ret;
4286 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004287
paul718e3742002-12-13 20:15:29 +00004288 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4289 if (! ret)
4290 {
4291 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4292 return CMD_WARNING;
4293 }
4294
4295 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004296 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004297}
4298
4299DEFUN (bgp_network_mask_route_map,
4300 bgp_network_mask_route_map_cmd,
4301 "network A.B.C.D mask A.B.C.D route-map WORD",
4302 "Specify a network to announce via BGP\n"
4303 "Network number\n"
4304 "Network mask\n"
4305 "Network mask\n"
4306 "Route-map to modify the attributes\n"
4307 "Name of the route map\n")
4308{
4309 int ret;
4310 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004311
paul718e3742002-12-13 20:15:29 +00004312 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4313 if (! ret)
4314 {
4315 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4316 return CMD_WARNING;
4317 }
4318
4319 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004320 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004321}
4322
4323DEFUN (bgp_network_mask_backdoor,
4324 bgp_network_mask_backdoor_cmd,
4325 "network A.B.C.D mask A.B.C.D backdoor",
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n")
4331{
4332 int ret;
4333 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004334
paul718e3742002-12-13 20:15:29 +00004335 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4336 if (! ret)
4337 {
4338 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4339 return CMD_WARNING;
4340 }
4341
Paul Jakma41367172007-08-06 15:24:51 +00004342 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004343 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004344}
4345
4346DEFUN (bgp_network_mask_natural,
4347 bgp_network_mask_natural_cmd,
4348 "network A.B.C.D",
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n")
4351{
4352 int ret;
4353 char prefix_str[BUFSIZ];
4354
4355 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
4362 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004363 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004364}
4365
4366DEFUN (bgp_network_mask_natural_route_map,
4367 bgp_network_mask_natural_route_map_cmd,
4368 "network A.B.C.D route-map WORD",
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n"
4371 "Route-map to modify the attributes\n"
4372 "Name of the route map\n")
4373{
4374 int ret;
4375 char prefix_str[BUFSIZ];
4376
4377 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4378 if (! ret)
4379 {
4380 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4381 return CMD_WARNING;
4382 }
4383
4384 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004385 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004386}
4387
4388DEFUN (bgp_network_mask_natural_backdoor,
4389 bgp_network_mask_natural_backdoor_cmd,
4390 "network A.B.C.D backdoor",
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n"
4393 "Specify a BGP backdoor route\n")
4394{
4395 int ret;
4396 char prefix_str[BUFSIZ];
4397
4398 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4399 if (! ret)
4400 {
4401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4402 return CMD_WARNING;
4403 }
4404
Paul Jakma41367172007-08-06 15:24:51 +00004405 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004406 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004407}
4408
4409DEFUN (no_bgp_network,
4410 no_bgp_network_cmd,
4411 "no network A.B.C.D/M",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4415{
4416 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4417 bgp_node_safi (vty));
4418}
4419
4420ALIAS (no_bgp_network,
4421 no_bgp_network_route_map_cmd,
4422 "no network A.B.C.D/M route-map WORD",
4423 NO_STR
4424 "Specify a network to announce via BGP\n"
4425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4426 "Route-map to modify the attributes\n"
4427 "Name of the route map\n")
4428
4429ALIAS (no_bgp_network,
4430 no_bgp_network_backdoor_cmd,
4431 "no network A.B.C.D/M backdoor",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4435 "Specify a BGP backdoor route\n")
4436
4437DEFUN (no_bgp_network_mask,
4438 no_bgp_network_mask_cmd,
4439 "no network A.B.C.D mask A.B.C.D",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "Network number\n"
4443 "Network mask\n"
4444 "Network mask\n")
4445{
4446 int ret;
4447 char prefix_str[BUFSIZ];
4448
4449 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4450 if (! ret)
4451 {
4452 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4453 return CMD_WARNING;
4454 }
4455
4456 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4457 bgp_node_safi (vty));
4458}
4459
4460ALIAS (no_bgp_network_mask,
4461 no_bgp_network_mask_route_map_cmd,
4462 "no network A.B.C.D mask A.B.C.D route-map WORD",
4463 NO_STR
4464 "Specify a network to announce via BGP\n"
4465 "Network number\n"
4466 "Network mask\n"
4467 "Network mask\n"
4468 "Route-map to modify the attributes\n"
4469 "Name of the route map\n")
4470
4471ALIAS (no_bgp_network_mask,
4472 no_bgp_network_mask_backdoor_cmd,
4473 "no network A.B.C.D mask A.B.C.D backdoor",
4474 NO_STR
4475 "Specify a network to announce via BGP\n"
4476 "Network number\n"
4477 "Network mask\n"
4478 "Network mask\n"
4479 "Specify a BGP backdoor route\n")
4480
4481DEFUN (no_bgp_network_mask_natural,
4482 no_bgp_network_mask_natural_cmd,
4483 "no network A.B.C.D",
4484 NO_STR
4485 "Specify a network to announce via BGP\n"
4486 "Network number\n")
4487{
4488 int ret;
4489 char prefix_str[BUFSIZ];
4490
4491 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4492 if (! ret)
4493 {
4494 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4495 return CMD_WARNING;
4496 }
4497
4498 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4499 bgp_node_safi (vty));
4500}
4501
4502ALIAS (no_bgp_network_mask_natural,
4503 no_bgp_network_mask_natural_route_map_cmd,
4504 "no network A.B.C.D route-map WORD",
4505 NO_STR
4506 "Specify a network to announce via BGP\n"
4507 "Network number\n"
4508 "Route-map to modify the attributes\n"
4509 "Name of the route map\n")
4510
4511ALIAS (no_bgp_network_mask_natural,
4512 no_bgp_network_mask_natural_backdoor_cmd,
4513 "no network A.B.C.D backdoor",
4514 NO_STR
4515 "Specify a network to announce via BGP\n"
4516 "Network number\n"
4517 "Specify a BGP backdoor route\n")
4518
paul718e3742002-12-13 20:15:29 +00004519DEFUN (ipv6_bgp_network,
4520 ipv6_bgp_network_cmd,
4521 "network X:X::X:X/M",
4522 "Specify a network to announce via BGP\n"
4523 "IPv6 prefix <network>/<length>\n")
4524{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304525 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004526 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004527}
4528
4529DEFUN (ipv6_bgp_network_route_map,
4530 ipv6_bgp_network_route_map_cmd,
4531 "network X:X::X:X/M route-map WORD",
4532 "Specify a network to announce via BGP\n"
4533 "IPv6 prefix <network>/<length>\n"
4534 "Route-map to modify the attributes\n"
4535 "Name of the route map\n")
4536{
4537 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004538 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004539}
4540
4541DEFUN (no_ipv6_bgp_network,
4542 no_ipv6_bgp_network_cmd,
4543 "no network X:X::X:X/M",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "IPv6 prefix <network>/<length>\n")
4547{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304548 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004549}
4550
4551ALIAS (no_ipv6_bgp_network,
4552 no_ipv6_bgp_network_route_map_cmd,
4553 "no network X:X::X:X/M route-map WORD",
4554 NO_STR
4555 "Specify a network to announce via BGP\n"
4556 "IPv6 prefix <network>/<length>\n"
4557 "Route-map to modify the attributes\n"
4558 "Name of the route map\n")
4559
4560ALIAS (ipv6_bgp_network,
4561 old_ipv6_bgp_network_cmd,
4562 "ipv6 bgp network X:X::X:X/M",
4563 IPV6_STR
4564 BGP_STR
4565 "Specify a network to announce via BGP\n"
4566 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4567
4568ALIAS (no_ipv6_bgp_network,
4569 old_no_ipv6_bgp_network_cmd,
4570 "no ipv6 bgp network X:X::X:X/M",
4571 NO_STR
4572 IPV6_STR
4573 BGP_STR
4574 "Specify a network to announce via BGP\n"
4575 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004576
4577/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4578ALIAS_DEPRECATED (bgp_network,
4579 bgp_network_ttl_cmd,
4580 "network A.B.C.D/M pathlimit <0-255>",
4581 "Specify a network to announce via BGP\n"
4582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4583 "AS-Path hopcount limit attribute\n"
4584 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4585ALIAS_DEPRECATED (bgp_network_backdoor,
4586 bgp_network_backdoor_ttl_cmd,
4587 "network A.B.C.D/M backdoor pathlimit <0-255>",
4588 "Specify a network to announce via BGP\n"
4589 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4590 "Specify a BGP backdoor route\n"
4591 "AS-Path hopcount limit attribute\n"
4592 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4593ALIAS_DEPRECATED (bgp_network_mask,
4594 bgp_network_mask_ttl_cmd,
4595 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4596 "Specify a network to announce via BGP\n"
4597 "Network number\n"
4598 "Network mask\n"
4599 "Network mask\n"
4600 "AS-Path hopcount limit attribute\n"
4601 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4602ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4603 bgp_network_mask_backdoor_ttl_cmd,
4604 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4605 "Specify a network to announce via BGP\n"
4606 "Network number\n"
4607 "Network mask\n"
4608 "Network mask\n"
4609 "Specify a BGP backdoor route\n"
4610 "AS-Path hopcount limit attribute\n"
4611 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4612ALIAS_DEPRECATED (bgp_network_mask_natural,
4613 bgp_network_mask_natural_ttl_cmd,
4614 "network A.B.C.D pathlimit <0-255>",
4615 "Specify a network to announce via BGP\n"
4616 "Network number\n"
4617 "AS-Path hopcount limit attribute\n"
4618 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4619ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4620 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004621 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004622 "Specify a network to announce via BGP\n"
4623 "Network number\n"
4624 "Specify a BGP backdoor route\n"
4625 "AS-Path hopcount limit attribute\n"
4626 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4627ALIAS_DEPRECATED (no_bgp_network,
4628 no_bgp_network_ttl_cmd,
4629 "no network A.B.C.D/M pathlimit <0-255>",
4630 NO_STR
4631 "Specify a network to announce via BGP\n"
4632 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4633 "AS-Path hopcount limit attribute\n"
4634 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4635ALIAS_DEPRECATED (no_bgp_network,
4636 no_bgp_network_backdoor_ttl_cmd,
4637 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4638 NO_STR
4639 "Specify a network to announce via BGP\n"
4640 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4641 "Specify a BGP backdoor route\n"
4642 "AS-Path hopcount limit attribute\n"
4643 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4644ALIAS_DEPRECATED (no_bgp_network,
4645 no_bgp_network_mask_ttl_cmd,
4646 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4647 NO_STR
4648 "Specify a network to announce via BGP\n"
4649 "Network number\n"
4650 "Network mask\n"
4651 "Network mask\n"
4652 "AS-Path hopcount limit attribute\n"
4653 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4654ALIAS_DEPRECATED (no_bgp_network_mask,
4655 no_bgp_network_mask_backdoor_ttl_cmd,
4656 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4657 NO_STR
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "Specify a BGP backdoor route\n"
4663 "AS-Path hopcount limit attribute\n"
4664 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4665ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4666 no_bgp_network_mask_natural_ttl_cmd,
4667 "no network A.B.C.D pathlimit <0-255>",
4668 NO_STR
4669 "Specify a network to announce via BGP\n"
4670 "Network number\n"
4671 "AS-Path hopcount limit attribute\n"
4672 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4673ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4674 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4675 "no network A.B.C.D backdoor pathlimit <0-255>",
4676 NO_STR
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "Specify a BGP backdoor route\n"
4680 "AS-Path hopcount limit attribute\n"
4681 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4682ALIAS_DEPRECATED (ipv6_bgp_network,
4683 ipv6_bgp_network_ttl_cmd,
4684 "network X:X::X:X/M pathlimit <0-255>",
4685 "Specify a network to announce via BGP\n"
4686 "IPv6 prefix <network>/<length>\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_ipv6_bgp_network,
4690 no_ipv6_bgp_network_ttl_cmd,
4691 "no network X:X::X:X/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IPv6 prefix <network>/<length>\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004697
paul718e3742002-12-13 20:15:29 +00004698/* Aggreagete address:
4699
4700 advertise-map Set condition to advertise attribute
4701 as-set Generate AS set path information
4702 attribute-map Set attributes of aggregate
4703 route-map Set parameters of aggregate
4704 summary-only Filter more specific routes from updates
4705 suppress-map Conditionally filter more specific routes from updates
4706 <cr>
4707 */
4708struct bgp_aggregate
4709{
4710 /* Summary-only flag. */
4711 u_char summary_only;
4712
4713 /* AS set generation. */
4714 u_char as_set;
4715
4716 /* Route-map for aggregated route. */
4717 struct route_map *map;
4718
4719 /* Suppress-count. */
4720 unsigned long count;
4721
4722 /* SAFI configuration. */
4723 safi_t safi;
4724};
4725
paul94f2b392005-06-28 12:44:16 +00004726static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004727bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004728{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004729 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004730}
4731
paul94f2b392005-06-28 12:44:16 +00004732static void
paul718e3742002-12-13 20:15:29 +00004733bgp_aggregate_free (struct bgp_aggregate *aggregate)
4734{
4735 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4736}
4737
Daniel Walton76a72802015-05-19 17:47:24 -07004738/* Update an aggregate as routes are added/removed from the BGP table */
paul94f2b392005-06-28 12:44:16 +00004739static void
paul718e3742002-12-13 20:15:29 +00004740bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4741 afi_t afi, safi_t safi, struct bgp_info *del,
4742 struct bgp_aggregate *aggregate)
4743{
4744 struct bgp_table *table;
4745 struct bgp_node *top;
4746 struct bgp_node *rn;
4747 u_char origin;
4748 struct aspath *aspath = NULL;
4749 struct aspath *asmerge = NULL;
4750 struct community *community = NULL;
4751 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004752 struct bgp_info *ri;
4753 struct bgp_info *new;
4754 int first = 1;
4755 unsigned long match = 0;
4756
paul718e3742002-12-13 20:15:29 +00004757 /* ORIGIN attribute: If at least one route among routes that are
4758 aggregated has ORIGIN with the value INCOMPLETE, then the
4759 aggregated route must have the ORIGIN attribute with the value
4760 INCOMPLETE. Otherwise, if at least one route among routes that
4761 are aggregated has ORIGIN with the value EGP, then the aggregated
4762 route must have the origin attribute with the value EGP. In all
4763 other case the value of the ORIGIN attribute of the aggregated
4764 route is INTERNAL. */
4765 origin = BGP_ORIGIN_IGP;
4766
4767 table = bgp->rib[afi][safi];
4768
4769 top = bgp_node_get (table, p);
4770 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4771 if (rn->p.prefixlen > p->prefixlen)
4772 {
4773 match = 0;
4774
4775 for (ri = rn->info; ri; ri = ri->next)
4776 {
4777 if (BGP_INFO_HOLDDOWN (ri))
4778 continue;
4779
4780 if (del && ri == del)
4781 continue;
4782
4783 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004784 first = 0;
paul718e3742002-12-13 20:15:29 +00004785
4786#ifdef AGGREGATE_NEXTHOP_CHECK
4787 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4788 || ri->attr->med != med)
4789 {
4790 if (aspath)
4791 aspath_free (aspath);
4792 if (community)
4793 community_free (community);
4794 bgp_unlock_node (rn);
4795 bgp_unlock_node (top);
4796 return;
4797 }
4798#endif /* AGGREGATE_NEXTHOP_CHECK */
4799
4800 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 {
4802 if (aggregate->summary_only)
4803 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004804 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004805 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004806 match++;
4807 }
4808
4809 aggregate->count++;
4810
Daniel Walton76a72802015-05-19 17:47:24 -07004811 if (origin < ri->attr->origin)
4812 origin = ri->attr->origin;
4813
paul718e3742002-12-13 20:15:29 +00004814 if (aggregate->as_set)
4815 {
paul718e3742002-12-13 20:15:29 +00004816 if (aspath)
4817 {
4818 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4819 aspath_free (aspath);
4820 aspath = asmerge;
4821 }
4822 else
4823 aspath = aspath_dup (ri->attr->aspath);
4824
4825 if (ri->attr->community)
4826 {
4827 if (community)
4828 {
4829 commerge = community_merge (community,
4830 ri->attr->community);
4831 community = community_uniq_sort (commerge);
4832 community_free (commerge);
4833 }
4834 else
4835 community = community_dup (ri->attr->community);
4836 }
4837 }
4838 }
4839 }
4840 if (match)
4841 bgp_process (bgp, rn, afi, safi);
4842 }
4843 bgp_unlock_node (top);
4844
4845 if (rinew)
4846 {
4847 aggregate->count++;
4848
4849 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004850 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004851
Daniel Walton76a72802015-05-19 17:47:24 -07004852 if (origin < rinew->attr->origin)
4853 origin = rinew->attr->origin;
4854
paul718e3742002-12-13 20:15:29 +00004855 if (aggregate->as_set)
4856 {
paul718e3742002-12-13 20:15:29 +00004857 if (aspath)
4858 {
4859 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4860 aspath_free (aspath);
4861 aspath = asmerge;
4862 }
4863 else
4864 aspath = aspath_dup (rinew->attr->aspath);
4865
4866 if (rinew->attr->community)
4867 {
4868 if (community)
4869 {
4870 commerge = community_merge (community,
4871 rinew->attr->community);
4872 community = community_uniq_sort (commerge);
4873 community_free (commerge);
4874 }
4875 else
4876 community = community_dup (rinew->attr->community);
4877 }
4878 }
4879 }
4880
4881 if (aggregate->count > 0)
4882 {
4883 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004884 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4885 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4886 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00004887 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004888
4889 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004890 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004891 bgp_process (bgp, rn, afi, safi);
4892 }
4893 else
4894 {
4895 if (aspath)
4896 aspath_free (aspath);
4897 if (community)
4898 community_free (community);
4899 }
4900}
4901
4902void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4903 struct bgp_aggregate *);
4904
4905void
4906bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4907 struct bgp_info *ri, afi_t afi, safi_t safi)
4908{
4909 struct bgp_node *child;
4910 struct bgp_node *rn;
4911 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004912 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004913
4914 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004915 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004916 return;
4917
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004918 table = bgp->aggregate[afi][safi];
4919
4920 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004921 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004922 return;
4923
paul718e3742002-12-13 20:15:29 +00004924 if (p->prefixlen == 0)
4925 return;
4926
4927 if (BGP_INFO_HOLDDOWN (ri))
4928 return;
4929
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004930 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004931
4932 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004933 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004934 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4935 {
4936 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004937 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004938 }
4939 bgp_unlock_node (child);
4940}
4941
4942void
4943bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4944 struct bgp_info *del, afi_t afi, safi_t safi)
4945{
4946 struct bgp_node *child;
4947 struct bgp_node *rn;
4948 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004949 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004950
4951 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004952 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004953 return;
4954
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004955 table = bgp->aggregate[afi][safi];
4956
4957 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004958 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004959 return;
4960
paul718e3742002-12-13 20:15:29 +00004961 if (p->prefixlen == 0)
4962 return;
4963
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004964 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004965
4966 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004967 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004968 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4969 {
4970 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004971 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004972 }
4973 bgp_unlock_node (child);
4974}
4975
Daniel Walton76a72802015-05-19 17:47:24 -07004976/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004977static void
paul718e3742002-12-13 20:15:29 +00004978bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4979 struct bgp_aggregate *aggregate)
4980{
4981 struct bgp_table *table;
4982 struct bgp_node *top;
4983 struct bgp_node *rn;
4984 struct bgp_info *new;
4985 struct bgp_info *ri;
4986 unsigned long match;
4987 u_char origin = BGP_ORIGIN_IGP;
4988 struct aspath *aspath = NULL;
4989 struct aspath *asmerge = NULL;
4990 struct community *community = NULL;
4991 struct community *commerge = NULL;
4992
4993 table = bgp->rib[afi][safi];
4994
4995 /* Sanity check. */
4996 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4997 return;
4998 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4999 return;
5000
5001 /* If routes exists below this node, generate aggregate routes. */
5002 top = bgp_node_get (table, p);
5003 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5004 if (rn->p.prefixlen > p->prefixlen)
5005 {
5006 match = 0;
5007
5008 for (ri = rn->info; ri; ri = ri->next)
5009 {
5010 if (BGP_INFO_HOLDDOWN (ri))
5011 continue;
5012
5013 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5014 {
5015 /* summary-only aggregate route suppress aggregated
5016 route announcement. */
5017 if (aggregate->summary_only)
5018 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005019 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005021 match++;
5022 }
Daniel Walton76a72802015-05-19 17:47:24 -07005023
5024 /* If at least one route among routes that are aggregated has
5025 * ORIGIN with the value INCOMPLETE, then the aggregated route
5026 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5027 * Otherwise, if at least one route among routes that are
5028 * aggregated has ORIGIN with the value EGP, then the aggregated
5029 * route MUST have the ORIGIN attribute with the value EGP.
5030 */
5031 if (origin < ri->attr->origin)
5032 origin = ri->attr->origin;
5033
paul718e3742002-12-13 20:15:29 +00005034 /* as-set aggregate route generate origin, as path,
5035 community aggregation. */
5036 if (aggregate->as_set)
5037 {
paul718e3742002-12-13 20:15:29 +00005038 if (aspath)
5039 {
5040 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5041 aspath_free (aspath);
5042 aspath = asmerge;
5043 }
5044 else
5045 aspath = aspath_dup (ri->attr->aspath);
5046
5047 if (ri->attr->community)
5048 {
5049 if (community)
5050 {
5051 commerge = community_merge (community,
5052 ri->attr->community);
5053 community = community_uniq_sort (commerge);
5054 community_free (commerge);
5055 }
5056 else
5057 community = community_dup (ri->attr->community);
5058 }
5059 }
5060 aggregate->count++;
5061 }
5062 }
5063
5064 /* If this node is suppressed, process the change. */
5065 if (match)
5066 bgp_process (bgp, rn, afi, safi);
5067 }
5068 bgp_unlock_node (top);
5069
5070 /* Add aggregate route to BGP table. */
5071 if (aggregate->count)
5072 {
5073 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005074 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5075 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5076 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00005077 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005078
5079 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005080 bgp_unlock_node (rn);
5081
paul718e3742002-12-13 20:15:29 +00005082 /* Process change. */
5083 bgp_process (bgp, rn, afi, safi);
5084 }
Denil Virae2a92582015-08-11 13:34:59 -07005085 else
5086 {
5087 if (aspath)
5088 aspath_free (aspath);
5089 if (community)
5090 community_free (community);
5091 }
paul718e3742002-12-13 20:15:29 +00005092}
5093
5094void
5095bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5096 safi_t safi, struct bgp_aggregate *aggregate)
5097{
5098 struct bgp_table *table;
5099 struct bgp_node *top;
5100 struct bgp_node *rn;
5101 struct bgp_info *ri;
5102 unsigned long match;
5103
5104 table = bgp->rib[afi][safi];
5105
5106 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5107 return;
5108 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5109 return;
5110
5111 /* If routes exists below this node, generate aggregate routes. */
5112 top = bgp_node_get (table, p);
5113 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5114 if (rn->p.prefixlen > p->prefixlen)
5115 {
5116 match = 0;
5117
5118 for (ri = rn->info; ri; ri = ri->next)
5119 {
5120 if (BGP_INFO_HOLDDOWN (ri))
5121 continue;
5122
5123 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5124 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005125 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005127 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005128
Paul Jakmafb982c22007-05-04 20:15:47 +00005129 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005130 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005131 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005132 match++;
5133 }
5134 }
5135 aggregate->count--;
5136 }
5137 }
5138
Paul Jakmafb982c22007-05-04 20:15:47 +00005139 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005140 if (match)
5141 bgp_process (bgp, rn, afi, safi);
5142 }
5143 bgp_unlock_node (top);
5144
5145 /* Delete aggregate route from BGP table. */
5146 rn = bgp_node_get (table, p);
5147
5148 for (ri = rn->info; ri; ri = ri->next)
5149 if (ri->peer == bgp->peer_self
5150 && ri->type == ZEBRA_ROUTE_BGP
5151 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5152 break;
5153
5154 /* Withdraw static BGP route from routing table. */
5155 if (ri)
5156 {
paul718e3742002-12-13 20:15:29 +00005157 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005158 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005159 }
5160
5161 /* Unlock bgp_node_lookup. */
5162 bgp_unlock_node (rn);
5163}
5164
5165/* Aggregate route attribute. */
5166#define AGGREGATE_SUMMARY_ONLY 1
5167#define AGGREGATE_AS_SET 1
5168
paul94f2b392005-06-28 12:44:16 +00005169static int
Robert Baysf6269b42010-08-05 10:26:28 -07005170bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5171 afi_t afi, safi_t safi)
5172{
5173 int ret;
5174 struct prefix p;
5175 struct bgp_node *rn;
5176 struct bgp *bgp;
5177 struct bgp_aggregate *aggregate;
5178
5179 /* Convert string to prefix structure. */
5180 ret = str2prefix (prefix_str, &p);
5181 if (!ret)
5182 {
5183 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186 apply_mask (&p);
5187
5188 /* Get BGP structure. */
5189 bgp = vty->index;
5190
5191 /* Old configuration check. */
5192 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5193 if (! rn)
5194 {
5195 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5196 VTY_NEWLINE);
5197 return CMD_WARNING;
5198 }
5199
5200 aggregate = rn->info;
5201 if (aggregate->safi & SAFI_UNICAST)
5202 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5203 if (aggregate->safi & SAFI_MULTICAST)
5204 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5205
5206 /* Unlock aggregate address configuration. */
5207 rn->info = NULL;
5208 bgp_aggregate_free (aggregate);
5209 bgp_unlock_node (rn);
5210 bgp_unlock_node (rn);
5211
5212 return CMD_SUCCESS;
5213}
5214
5215static int
5216bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005217 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005218 u_char summary_only, u_char as_set)
5219{
5220 int ret;
5221 struct prefix p;
5222 struct bgp_node *rn;
5223 struct bgp *bgp;
5224 struct bgp_aggregate *aggregate;
5225
5226 /* Convert string to prefix structure. */
5227 ret = str2prefix (prefix_str, &p);
5228 if (!ret)
5229 {
5230 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5231 return CMD_WARNING;
5232 }
5233 apply_mask (&p);
5234
5235 /* Get BGP structure. */
5236 bgp = vty->index;
5237
5238 /* Old configuration check. */
5239 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5240
5241 if (rn->info)
5242 {
5243 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005244 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005245 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5246 if (ret)
5247 {
Robert Bays368473f2010-08-05 10:26:29 -07005248 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5249 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005250 return CMD_WARNING;
5251 }
paul718e3742002-12-13 20:15:29 +00005252 }
5253
5254 /* Make aggregate address structure. */
5255 aggregate = bgp_aggregate_new ();
5256 aggregate->summary_only = summary_only;
5257 aggregate->as_set = as_set;
5258 aggregate->safi = safi;
5259 rn->info = aggregate;
5260
5261 /* Aggregate address insert into BGP routing table. */
5262 if (safi & SAFI_UNICAST)
5263 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (safi & SAFI_MULTICAST)
5265 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 return CMD_SUCCESS;
5268}
5269
paul718e3742002-12-13 20:15:29 +00005270DEFUN (aggregate_address,
5271 aggregate_address_cmd,
5272 "aggregate-address A.B.C.D/M",
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n")
5275{
5276 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5277}
5278
5279DEFUN (aggregate_address_mask,
5280 aggregate_address_mask_cmd,
5281 "aggregate-address A.B.C.D A.B.C.D",
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n")
5285{
5286 int ret;
5287 char prefix_str[BUFSIZ];
5288
5289 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5290
5291 if (! ret)
5292 {
5293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5294 return CMD_WARNING;
5295 }
5296
5297 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5298 0, 0);
5299}
5300
5301DEFUN (aggregate_address_summary_only,
5302 aggregate_address_summary_only_cmd,
5303 "aggregate-address A.B.C.D/M summary-only",
5304 "Configure BGP aggregate entries\n"
5305 "Aggregate prefix\n"
5306 "Filter more specific routes from updates\n")
5307{
5308 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5309 AGGREGATE_SUMMARY_ONLY, 0);
5310}
5311
5312DEFUN (aggregate_address_mask_summary_only,
5313 aggregate_address_mask_summary_only_cmd,
5314 "aggregate-address A.B.C.D A.B.C.D summary-only",
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n")
5319{
5320 int ret;
5321 char prefix_str[BUFSIZ];
5322
5323 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5324
5325 if (! ret)
5326 {
5327 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5328 return CMD_WARNING;
5329 }
5330
5331 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5332 AGGREGATE_SUMMARY_ONLY, 0);
5333}
5334
5335DEFUN (aggregate_address_as_set,
5336 aggregate_address_as_set_cmd,
5337 "aggregate-address A.B.C.D/M as-set",
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Generate AS set path information\n")
5341{
5342 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5343 0, AGGREGATE_AS_SET);
5344}
5345
5346DEFUN (aggregate_address_mask_as_set,
5347 aggregate_address_mask_as_set_cmd,
5348 "aggregate-address A.B.C.D A.B.C.D as-set",
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate address\n"
5351 "Aggregate mask\n"
5352 "Generate AS set path information\n")
5353{
5354 int ret;
5355 char prefix_str[BUFSIZ];
5356
5357 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5358
5359 if (! ret)
5360 {
5361 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5362 return CMD_WARNING;
5363 }
5364
5365 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5366 0, AGGREGATE_AS_SET);
5367}
5368
5369
5370DEFUN (aggregate_address_as_set_summary,
5371 aggregate_address_as_set_summary_cmd,
5372 "aggregate-address A.B.C.D/M as-set summary-only",
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n"
5375 "Generate AS set path information\n"
5376 "Filter more specific routes from updates\n")
5377{
5378 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5379 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5380}
5381
5382ALIAS (aggregate_address_as_set_summary,
5383 aggregate_address_summary_as_set_cmd,
5384 "aggregate-address A.B.C.D/M summary-only as-set",
5385 "Configure BGP aggregate entries\n"
5386 "Aggregate prefix\n"
5387 "Filter more specific routes from updates\n"
5388 "Generate AS set path information\n")
5389
5390DEFUN (aggregate_address_mask_as_set_summary,
5391 aggregate_address_mask_as_set_summary_cmd,
5392 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate address\n"
5395 "Aggregate mask\n"
5396 "Generate AS set path information\n"
5397 "Filter more specific routes from updates\n")
5398{
5399 int ret;
5400 char prefix_str[BUFSIZ];
5401
5402 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5403
5404 if (! ret)
5405 {
5406 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5407 return CMD_WARNING;
5408 }
5409
5410 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5411 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5412}
5413
5414ALIAS (aggregate_address_mask_as_set_summary,
5415 aggregate_address_mask_summary_as_set_cmd,
5416 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5417 "Configure BGP aggregate entries\n"
5418 "Aggregate address\n"
5419 "Aggregate mask\n"
5420 "Filter more specific routes from updates\n"
5421 "Generate AS set path information\n")
5422
5423DEFUN (no_aggregate_address,
5424 no_aggregate_address_cmd,
5425 "no aggregate-address A.B.C.D/M",
5426 NO_STR
5427 "Configure BGP aggregate entries\n"
5428 "Aggregate prefix\n")
5429{
5430 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5431}
5432
5433ALIAS (no_aggregate_address,
5434 no_aggregate_address_summary_only_cmd,
5435 "no aggregate-address A.B.C.D/M summary-only",
5436 NO_STR
5437 "Configure BGP aggregate entries\n"
5438 "Aggregate prefix\n"
5439 "Filter more specific routes from updates\n")
5440
5441ALIAS (no_aggregate_address,
5442 no_aggregate_address_as_set_cmd,
5443 "no aggregate-address A.B.C.D/M as-set",
5444 NO_STR
5445 "Configure BGP aggregate entries\n"
5446 "Aggregate prefix\n"
5447 "Generate AS set path information\n")
5448
5449ALIAS (no_aggregate_address,
5450 no_aggregate_address_as_set_summary_cmd,
5451 "no aggregate-address A.B.C.D/M as-set summary-only",
5452 NO_STR
5453 "Configure BGP aggregate entries\n"
5454 "Aggregate prefix\n"
5455 "Generate AS set path information\n"
5456 "Filter more specific routes from updates\n")
5457
5458ALIAS (no_aggregate_address,
5459 no_aggregate_address_summary_as_set_cmd,
5460 "no aggregate-address A.B.C.D/M summary-only as-set",
5461 NO_STR
5462 "Configure BGP aggregate entries\n"
5463 "Aggregate prefix\n"
5464 "Filter more specific routes from updates\n"
5465 "Generate AS set path information\n")
5466
5467DEFUN (no_aggregate_address_mask,
5468 no_aggregate_address_mask_cmd,
5469 "no aggregate-address A.B.C.D A.B.C.D",
5470 NO_STR
5471 "Configure BGP aggregate entries\n"
5472 "Aggregate address\n"
5473 "Aggregate mask\n")
5474{
5475 int ret;
5476 char prefix_str[BUFSIZ];
5477
5478 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5479
5480 if (! ret)
5481 {
5482 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5483 return CMD_WARNING;
5484 }
5485
5486 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5487}
5488
5489ALIAS (no_aggregate_address_mask,
5490 no_aggregate_address_mask_summary_only_cmd,
5491 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5492 NO_STR
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate address\n"
5495 "Aggregate mask\n"
5496 "Filter more specific routes from updates\n")
5497
5498ALIAS (no_aggregate_address_mask,
5499 no_aggregate_address_mask_as_set_cmd,
5500 "no aggregate-address A.B.C.D A.B.C.D as-set",
5501 NO_STR
5502 "Configure BGP aggregate entries\n"
5503 "Aggregate address\n"
5504 "Aggregate mask\n"
5505 "Generate AS set path information\n")
5506
5507ALIAS (no_aggregate_address_mask,
5508 no_aggregate_address_mask_as_set_summary_cmd,
5509 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5510 NO_STR
5511 "Configure BGP aggregate entries\n"
5512 "Aggregate address\n"
5513 "Aggregate mask\n"
5514 "Generate AS set path information\n"
5515 "Filter more specific routes from updates\n")
5516
5517ALIAS (no_aggregate_address_mask,
5518 no_aggregate_address_mask_summary_as_set_cmd,
5519 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5520 NO_STR
5521 "Configure BGP aggregate entries\n"
5522 "Aggregate address\n"
5523 "Aggregate mask\n"
5524 "Filter more specific routes from updates\n"
5525 "Generate AS set path information\n")
5526
paul718e3742002-12-13 20:15:29 +00005527DEFUN (ipv6_aggregate_address,
5528 ipv6_aggregate_address_cmd,
5529 "aggregate-address X:X::X:X/M",
5530 "Configure BGP aggregate entries\n"
5531 "Aggregate prefix\n")
5532{
5533 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5534}
5535
5536DEFUN (ipv6_aggregate_address_summary_only,
5537 ipv6_aggregate_address_summary_only_cmd,
5538 "aggregate-address X:X::X:X/M summary-only",
5539 "Configure BGP aggregate entries\n"
5540 "Aggregate prefix\n"
5541 "Filter more specific routes from updates\n")
5542{
5543 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5544 AGGREGATE_SUMMARY_ONLY, 0);
5545}
5546
5547DEFUN (no_ipv6_aggregate_address,
5548 no_ipv6_aggregate_address_cmd,
5549 "no aggregate-address X:X::X:X/M",
5550 NO_STR
5551 "Configure BGP aggregate entries\n"
5552 "Aggregate prefix\n")
5553{
5554 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5555}
5556
5557DEFUN (no_ipv6_aggregate_address_summary_only,
5558 no_ipv6_aggregate_address_summary_only_cmd,
5559 "no aggregate-address X:X::X:X/M summary-only",
5560 NO_STR
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate prefix\n"
5563 "Filter more specific routes from updates\n")
5564{
5565 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5566}
5567
5568ALIAS (ipv6_aggregate_address,
5569 old_ipv6_aggregate_address_cmd,
5570 "ipv6 bgp aggregate-address X:X::X:X/M",
5571 IPV6_STR
5572 BGP_STR
5573 "Configure BGP aggregate entries\n"
5574 "Aggregate prefix\n")
5575
5576ALIAS (ipv6_aggregate_address_summary_only,
5577 old_ipv6_aggregate_address_summary_only_cmd,
5578 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5579 IPV6_STR
5580 BGP_STR
5581 "Configure BGP aggregate entries\n"
5582 "Aggregate prefix\n"
5583 "Filter more specific routes from updates\n")
5584
5585ALIAS (no_ipv6_aggregate_address,
5586 old_no_ipv6_aggregate_address_cmd,
5587 "no ipv6 bgp aggregate-address X:X::X:X/M",
5588 NO_STR
5589 IPV6_STR
5590 BGP_STR
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n")
5593
5594ALIAS (no_ipv6_aggregate_address_summary_only,
5595 old_no_ipv6_aggregate_address_summary_only_cmd,
5596 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5597 NO_STR
5598 IPV6_STR
5599 BGP_STR
5600 "Configure BGP aggregate entries\n"
5601 "Aggregate prefix\n"
5602 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005603
paul718e3742002-12-13 20:15:29 +00005604/* Redistribute route treatment. */
5605void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005606bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5607 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005608 u_int32_t metric, u_char type)
5609{
5610 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005611 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005612 struct bgp_info *new;
5613 struct bgp_info *bi;
5614 struct bgp_info info;
5615 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005616 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005617 struct attr *new_attr;
5618 afi_t afi;
5619 int ret;
5620
5621 /* Make default attribute. */
5622 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5623 if (nexthop)
5624 attr.nexthop = *nexthop;
5625
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005626 if (nexthop6)
5627 {
5628 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5629 extra->mp_nexthop_global = *nexthop6;
5630 extra->mp_nexthop_len = 16;
5631 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005632
paul718e3742002-12-13 20:15:29 +00005633 attr.med = metric;
5634 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5635
paul1eb8ef22005-04-07 07:30:20 +00005636 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005637 {
5638 afi = family2afi (p->family);
5639
5640 if (bgp->redist[afi][type])
5641 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005642 struct attr attr_new;
5643 struct attr_extra extra_new;
5644
paul718e3742002-12-13 20:15:29 +00005645 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005646 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005647 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005648
5649 if (bgp->redist_metric_flag[afi][type])
5650 attr_new.med = bgp->redist_metric[afi][type];
5651
5652 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005653 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005654 {
5655 info.peer = bgp->peer_self;
5656 info.attr = &attr_new;
5657
paulfee0f4c2004-09-13 05:12:46 +00005658 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5659
paul718e3742002-12-13 20:15:29 +00005660 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5661 &info);
paulfee0f4c2004-09-13 05:12:46 +00005662
5663 bgp->peer_self->rmap_type = 0;
5664
paul718e3742002-12-13 20:15:29 +00005665 if (ret == RMAP_DENYMATCH)
5666 {
5667 /* Free uninterned attribute. */
5668 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005669
paul718e3742002-12-13 20:15:29 +00005670 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005671 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005672 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005673 bgp_redistribute_delete (p, type);
5674 return;
5675 }
5676 }
5677
Paul Jakmafb982c22007-05-04 20:15:47 +00005678 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5679 afi, SAFI_UNICAST, p, NULL);
5680
paul718e3742002-12-13 20:15:29 +00005681 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005682
paul718e3742002-12-13 20:15:29 +00005683 for (bi = bn->info; bi; bi = bi->next)
5684 if (bi->peer == bgp->peer_self
5685 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5686 break;
5687
5688 if (bi)
5689 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005690 if (attrhash_cmp (bi->attr, new_attr) &&
5691 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005692 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005693 bgp_attr_unintern (&new_attr);
5694 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005696 bgp_unlock_node (bn);
5697 return;
5698 }
5699 else
5700 {
5701 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005702 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005703
5704 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005705 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5706 bgp_info_restore(bn, bi);
5707 else
5708 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005709 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005710 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005711 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005712
5713 /* Process change. */
5714 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5715 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5716 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005717 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005718 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005719 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005720 }
paul718e3742002-12-13 20:15:29 +00005721 }
5722
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005723 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5724 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005725 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005726
5727 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5728 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005729 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005730 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5731 }
5732 }
5733
5734 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005735 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005736 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005737}
5738
5739void
5740bgp_redistribute_delete (struct prefix *p, u_char type)
5741{
5742 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005743 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005744 afi_t afi;
5745 struct bgp_node *rn;
5746 struct bgp_info *ri;
5747
paul1eb8ef22005-04-07 07:30:20 +00005748 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005749 {
5750 afi = family2afi (p->family);
5751
5752 if (bgp->redist[afi][type])
5753 {
paulfee0f4c2004-09-13 05:12:46 +00005754 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005755
5756 for (ri = rn->info; ri; ri = ri->next)
5757 if (ri->peer == bgp->peer_self
5758 && ri->type == type)
5759 break;
5760
5761 if (ri)
5762 {
5763 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005764 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005765 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005766 }
5767 bgp_unlock_node (rn);
5768 }
5769 }
5770}
5771
5772/* Withdraw specified route type's route. */
5773void
5774bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5775{
5776 struct bgp_node *rn;
5777 struct bgp_info *ri;
5778 struct bgp_table *table;
5779
5780 table = bgp->rib[afi][SAFI_UNICAST];
5781
5782 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5783 {
5784 for (ri = rn->info; ri; ri = ri->next)
5785 if (ri->peer == bgp->peer_self
5786 && ri->type == type)
5787 break;
5788
5789 if (ri)
5790 {
5791 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005792 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005793 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005794 }
5795 }
5796}
David Lamparter6b0655a2014-06-04 06:53:35 +02005797
paul718e3742002-12-13 20:15:29 +00005798/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005799static void
paul718e3742002-12-13 20:15:29 +00005800route_vty_out_route (struct prefix *p, struct vty *vty)
5801{
5802 int len;
5803 u_int32_t destination;
5804 char buf[BUFSIZ];
5805
5806 if (p->family == AF_INET)
5807 {
5808 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5809 destination = ntohl (p->u.prefix4.s_addr);
5810
5811 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5812 || (IN_CLASSB (destination) && p->prefixlen == 16)
5813 || (IN_CLASSA (destination) && p->prefixlen == 8)
5814 || p->u.prefix4.s_addr == 0)
5815 {
5816 /* When mask is natural, mask is not displayed. */
5817 }
5818 else
5819 len += vty_out (vty, "/%d", p->prefixlen);
5820 }
5821 else
5822 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5823 p->prefixlen);
5824
5825 len = 17 - len;
5826 if (len < 1)
5827 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5828 else
5829 vty_out (vty, "%*s", len, " ");
5830}
5831
paul718e3742002-12-13 20:15:29 +00005832enum bgp_display_type
5833{
5834 normal_list,
5835};
5836
paulb40d9392005-08-22 22:34:41 +00005837/* Print the short form route status for a bgp_info */
5838static void
5839route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005840{
paulb40d9392005-08-22 22:34:41 +00005841 /* Route status display. */
5842 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5843 vty_out (vty, "R");
5844 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005845 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005847 vty_out (vty, "s");
5848 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5849 vty_out (vty, "*");
5850 else
5851 vty_out (vty, " ");
5852
5853 /* Selected */
5854 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5855 vty_out (vty, "h");
5856 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5857 vty_out (vty, "d");
5858 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5859 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005860 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5861 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005862 else
5863 vty_out (vty, " ");
5864
5865 /* Internal route. */
5866 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5867 vty_out (vty, "i");
5868 else
paulb40d9392005-08-22 22:34:41 +00005869 vty_out (vty, " ");
5870}
5871
5872/* called from terminal list command */
5873void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005874route_vty_out(
5875 struct vty *vty,
5876 struct prefix *p,
5877 struct bgp_info *binfo,
5878 int display,
5879 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005880{
5881 struct attr *attr;
5882
5883 /* short status lead text */
5884 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005885
5886 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005887 if (!display)
paul718e3742002-12-13 20:15:29 +00005888 route_vty_out_route (p, vty);
5889 else
5890 vty_out (vty, "%*s", 17, " ");
5891
5892 /* Print attribute */
5893 attr = binfo->attr;
5894 if (attr)
5895 {
paul718e3742002-12-13 20:15:29 +00005896
Lou Berger298cc2f2016-01-12 13:42:02 -05005897 /*
5898 * NEXTHOP start
5899 */
5900
5901 /*
5902 * For ENCAP routes, nexthop address family is not
5903 * neccessarily the same as the prefix address family.
5904 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5905 */
5906 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5907 if (attr->extra) {
5908 char buf[BUFSIZ];
5909 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5910
5911 switch (af) {
5912 case AF_INET:
5913 vty_out (vty, "%s", inet_ntop(af,
5914 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5915 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005916 case AF_INET6:
5917 vty_out (vty, "%s", inet_ntop(af,
5918 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5919 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005920 default:
5921 vty_out(vty, "?");
5922 }
5923 } else {
5924 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005925 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005926 } else {
5927
5928 if (p->family == AF_INET)
5929 {
5930 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5931 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005932 else if (p->family == AF_INET6)
5933 {
5934 int len;
5935 char buf[BUFSIZ];
5936
5937 len = vty_out (vty, "%s",
5938 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5939 buf, BUFSIZ));
5940 len = 16 - len;
5941 if (len < 1)
5942 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5943 else
5944 vty_out (vty, "%*s", len, " ");
5945 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005946 else
5947 {
5948 vty_out(vty, "?");
5949 }
5950 }
5951
5952 /*
5953 * NEXTHOP end
5954 */
5955
paul718e3742002-12-13 20:15:29 +00005956
5957 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005958 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005959 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005960 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005961
5962 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005963 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005964 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005965 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005966
Paul Jakmafb982c22007-05-04 20:15:47 +00005967 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005968
Paul Jakmab2518c12006-05-12 23:48:40 +00005969 /* Print aspath */
5970 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005971 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005972
Paul Jakmab2518c12006-05-12 23:48:40 +00005973 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005974 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 }
paul718e3742002-12-13 20:15:29 +00005976 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005977}
5978
5979/* called from terminal list command */
5980void
5981route_vty_out_tmp (struct vty *vty, struct prefix *p,
5982 struct attr *attr, safi_t safi)
5983{
5984 /* Route status display. */
5985 vty_out (vty, "*");
5986 vty_out (vty, ">");
5987 vty_out (vty, " ");
5988
5989 /* print prefix and mask */
5990 route_vty_out_route (p, vty);
5991
5992 /* Print attribute */
5993 if (attr)
5994 {
5995 if (p->family == AF_INET)
5996 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005997 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 vty_out (vty, "%-16s",
5999 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006000 else
6001 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6002 }
paul718e3742002-12-13 20:15:29 +00006003 else if (p->family == AF_INET6)
6004 {
6005 int len;
6006 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006007
6008 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006009
6010 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006011 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6012 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006013 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
6020 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006021 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006022 else
6023 vty_out (vty, " ");
6024
6025 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006026 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006027 else
6028 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006029
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006030 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006031
Paul Jakmab2518c12006-05-12 23:48:40 +00006032 /* Print aspath */
6033 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006034 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006035
Paul Jakmab2518c12006-05-12 23:48:40 +00006036 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006037 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006038 }
paul718e3742002-12-13 20:15:29 +00006039
6040 vty_out (vty, "%s", VTY_NEWLINE);
6041}
6042
ajs5a646652004-11-05 01:25:55 +00006043void
paul718e3742002-12-13 20:15:29 +00006044route_vty_out_tag (struct vty *vty, struct prefix *p,
6045 struct bgp_info *binfo, int display, safi_t safi)
6046{
6047 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006048 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006049
6050 if (!binfo->extra)
6051 return;
6052
paulb40d9392005-08-22 22:34:41 +00006053 /* short status lead text */
6054 route_vty_short_status_out (vty, binfo);
6055
paul718e3742002-12-13 20:15:29 +00006056 /* print prefix and mask */
6057 if (! display)
6058 route_vty_out_route (p, vty);
6059 else
6060 vty_out (vty, "%*s", 17, " ");
6061
6062 /* Print attribute */
6063 attr = binfo->attr;
6064 if (attr)
6065 {
6066 if (p->family == AF_INET)
6067 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006068 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006069 vty_out (vty, "%-16s",
6070 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006071 else
6072 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6073 }
paul718e3742002-12-13 20:15:29 +00006074 else if (p->family == AF_INET6)
6075 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006077 char buf[BUFSIZ];
6078 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006080 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006081 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6082 buf, BUFSIZ));
6083 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006084 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6086 buf, BUFSIZ),
6087 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6088 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006089
6090 }
paul718e3742002-12-13 20:15:29 +00006091 }
6092
Paul Jakmafb982c22007-05-04 20:15:47 +00006093 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006094
6095 vty_out (vty, "notag/%d", label);
6096
6097 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006098}
6099
6100/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006101static void
paul718e3742002-12-13 20:15:29 +00006102damp_route_vty_out (struct vty *vty, struct prefix *p,
6103 struct bgp_info *binfo, int display, safi_t safi)
6104{
6105 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006106 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006107 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006108
paulb40d9392005-08-22 22:34:41 +00006109 /* short status lead text */
6110 route_vty_short_status_out (vty, binfo);
6111
paul718e3742002-12-13 20:15:29 +00006112 /* print prefix and mask */
6113 if (! display)
6114 route_vty_out_route (p, vty);
6115 else
6116 vty_out (vty, "%*s", 17, " ");
6117
6118 len = vty_out (vty, "%s", binfo->peer->host);
6119 len = 17 - len;
6120 if (len < 1)
6121 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6122 else
6123 vty_out (vty, "%*s", len, " ");
6124
Chris Caputo50aef6f2009-06-23 06:06:49 +00006125 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006126
6127 /* Print attribute */
6128 attr = binfo->attr;
6129 if (attr)
6130 {
6131 /* Print aspath */
6132 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006133 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006134
6135 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006136 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006137 }
6138 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006139}
6140
paul718e3742002-12-13 20:15:29 +00006141/* flap route */
ajs5a646652004-11-05 01:25:55 +00006142static void
paul718e3742002-12-13 20:15:29 +00006143flap_route_vty_out (struct vty *vty, struct prefix *p,
6144 struct bgp_info *binfo, int display, safi_t safi)
6145{
6146 struct attr *attr;
6147 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006148 char timebuf[BGP_UPTIME_LEN];
6149 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006150
6151 if (!binfo->extra)
6152 return;
6153
6154 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006155
paulb40d9392005-08-22 22:34:41 +00006156 /* short status lead text */
6157 route_vty_short_status_out (vty, binfo);
6158
paul718e3742002-12-13 20:15:29 +00006159 /* print prefix and mask */
6160 if (! display)
6161 route_vty_out_route (p, vty);
6162 else
6163 vty_out (vty, "%*s", 17, " ");
6164
6165 len = vty_out (vty, "%s", binfo->peer->host);
6166 len = 16 - len;
6167 if (len < 1)
6168 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6169 else
6170 vty_out (vty, "%*s", len, " ");
6171
6172 len = vty_out (vty, "%d", bdi->flap);
6173 len = 5 - len;
6174 if (len < 1)
6175 vty_out (vty, " ");
6176 else
6177 vty_out (vty, "%*s ", len, " ");
6178
6179 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6180 timebuf, BGP_UPTIME_LEN));
6181
6182 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6183 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006184 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006185 else
6186 vty_out (vty, "%*s ", 8, " ");
6187
6188 /* Print attribute */
6189 attr = binfo->attr;
6190 if (attr)
6191 {
6192 /* Print aspath */
6193 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006194 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006195
6196 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006197 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006198 }
6199 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006200}
6201
paul94f2b392005-06-28 12:44:16 +00006202static void
paul718e3742002-12-13 20:15:29 +00006203route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6204 struct bgp_info *binfo, afi_t afi, safi_t safi)
6205{
6206 char buf[INET6_ADDRSTRLEN];
6207 char buf1[BUFSIZ];
6208 struct attr *attr;
6209 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006210#ifdef HAVE_CLOCK_MONOTONIC
6211 time_t tbuf;
6212#endif
paul718e3742002-12-13 20:15:29 +00006213
6214 attr = binfo->attr;
6215
6216 if (attr)
6217 {
6218 /* Line1 display AS-path, Aggregator */
6219 if (attr->aspath)
6220 {
6221 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006222 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006223 vty_out (vty, "Local");
6224 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006225 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006226 }
6227
paulb40d9392005-08-22 22:34:41 +00006228 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6229 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006230 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6231 vty_out (vty, ", (stale)");
6232 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006233 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006234 attr->extra->aggregator_as,
6235 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006236 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6237 vty_out (vty, ", (Received from a RR-client)");
6238 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6239 vty_out (vty, ", (Received from a RS-client)");
6240 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6241 vty_out (vty, ", (history entry)");
6242 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6243 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006244 vty_out (vty, "%s", VTY_NEWLINE);
6245
6246 /* Line2 display Next-hop, Neighbor, Router-id */
6247 if (p->family == AF_INET)
6248 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006249 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006250 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006251 inet_ntoa (attr->nexthop));
6252 }
paul718e3742002-12-13 20:15:29 +00006253 else
6254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006255 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006256 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006257 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006258 buf, INET6_ADDRSTRLEN));
6259 }
paul718e3742002-12-13 20:15:29 +00006260
6261 if (binfo->peer == bgp->peer_self)
6262 {
6263 vty_out (vty, " from %s ",
6264 p->family == AF_INET ? "0.0.0.0" : "::");
6265 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6266 }
6267 else
6268 {
6269 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6270 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006271 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006272 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006273 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6274 buf[0] = '?';
6275 buf[1] = 0;
6276 }
6277 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006278 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006279 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006280 else
6281 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6282 }
6283 vty_out (vty, "%s", VTY_NEWLINE);
6284
paul718e3742002-12-13 20:15:29 +00006285 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006286 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006287 {
6288 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006289 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006290 buf, INET6_ADDRSTRLEN),
6291 VTY_NEWLINE);
6292 }
paul718e3742002-12-13 20:15:29 +00006293
6294 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6295 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6296
6297 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006298 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006299
6300 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006301 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006302 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006303 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006304
Paul Jakmafb982c22007-05-04 20:15:47 +00006305 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006306 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006307
6308 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6309 vty_out (vty, ", valid");
6310
6311 if (binfo->peer != bgp->peer_self)
6312 {
6313 if (binfo->peer->as == binfo->peer->local_as)
6314 vty_out (vty, ", internal");
6315 else
6316 vty_out (vty, ", %s",
6317 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6318 }
6319 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6320 vty_out (vty, ", aggregated, local");
6321 else if (binfo->type != ZEBRA_ROUTE_BGP)
6322 vty_out (vty, ", sourced");
6323 else
6324 vty_out (vty, ", sourced, local");
6325
6326 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6327 vty_out (vty, ", atomic-aggregate");
6328
Josh Baileyde8d5df2011-07-20 20:46:01 -07006329 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6330 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6331 bgp_info_mpath_count (binfo)))
6332 vty_out (vty, ", multipath");
6333
paul718e3742002-12-13 20:15:29 +00006334 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6335 vty_out (vty, ", best");
6336
6337 vty_out (vty, "%s", VTY_NEWLINE);
6338
6339 /* Line 4 display Community */
6340 if (attr->community)
6341 vty_out (vty, " Community: %s%s", attr->community->str,
6342 VTY_NEWLINE);
6343
6344 /* Line 5 display Extended-community */
6345 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006346 vty_out (vty, " Extended Community: %s%s",
6347 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006348
6349 /* Line 6 display Originator, Cluster-id */
6350 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6351 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6352 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006353 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006354 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006355 vty_out (vty, " Originator: %s",
6356 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006357
6358 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6359 {
6360 int i;
6361 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6363 vty_out (vty, "%s ",
6364 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006365 }
6366 vty_out (vty, "%s", VTY_NEWLINE);
6367 }
Paul Jakma41367172007-08-06 15:24:51 +00006368
Paul Jakmafb982c22007-05-04 20:15:47 +00006369 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006370 bgp_damp_info_vty (vty, binfo);
6371
6372 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006373#ifdef HAVE_CLOCK_MONOTONIC
6374 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006375 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006376#else
6377 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6378#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006379 }
6380 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006381}
6382
6383#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6384 "h history, * valid, > best, = multipath,%s"\
6385 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006386#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006387#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6388#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6389#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6390
6391enum bgp_show_type
6392{
6393 bgp_show_type_normal,
6394 bgp_show_type_regexp,
6395 bgp_show_type_prefix_list,
6396 bgp_show_type_filter_list,
6397 bgp_show_type_route_map,
6398 bgp_show_type_neighbor,
6399 bgp_show_type_cidr_only,
6400 bgp_show_type_prefix_longer,
6401 bgp_show_type_community_all,
6402 bgp_show_type_community,
6403 bgp_show_type_community_exact,
6404 bgp_show_type_community_list,
6405 bgp_show_type_community_list_exact,
6406 bgp_show_type_flap_statistics,
6407 bgp_show_type_flap_address,
6408 bgp_show_type_flap_prefix,
6409 bgp_show_type_flap_cidr_only,
6410 bgp_show_type_flap_regexp,
6411 bgp_show_type_flap_filter_list,
6412 bgp_show_type_flap_prefix_list,
6413 bgp_show_type_flap_prefix_longer,
6414 bgp_show_type_flap_route_map,
6415 bgp_show_type_flap_neighbor,
6416 bgp_show_type_dampend_paths,
6417 bgp_show_type_damp_neighbor
6418};
6419
ajs5a646652004-11-05 01:25:55 +00006420static int
paulfee0f4c2004-09-13 05:12:46 +00006421bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006422 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006423{
paul718e3742002-12-13 20:15:29 +00006424 struct bgp_info *ri;
6425 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006426 int header = 1;
paul718e3742002-12-13 20:15:29 +00006427 int display;
ajs5a646652004-11-05 01:25:55 +00006428 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006429 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006430
6431 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006432 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006433 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006434
paul718e3742002-12-13 20:15:29 +00006435 /* Start processing of routes. */
6436 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6437 if (rn->info != NULL)
6438 {
6439 display = 0;
6440
6441 for (ri = rn->info; ri; ri = ri->next)
6442 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006443 total_count++;
ajs5a646652004-11-05 01:25:55 +00006444 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006445 || type == bgp_show_type_flap_address
6446 || type == bgp_show_type_flap_prefix
6447 || type == bgp_show_type_flap_cidr_only
6448 || type == bgp_show_type_flap_regexp
6449 || type == bgp_show_type_flap_filter_list
6450 || type == bgp_show_type_flap_prefix_list
6451 || type == bgp_show_type_flap_prefix_longer
6452 || type == bgp_show_type_flap_route_map
6453 || type == bgp_show_type_flap_neighbor
6454 || type == bgp_show_type_dampend_paths
6455 || type == bgp_show_type_damp_neighbor)
6456 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006457 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006458 continue;
6459 }
6460 if (type == bgp_show_type_regexp
6461 || type == bgp_show_type_flap_regexp)
6462 {
ajs5a646652004-11-05 01:25:55 +00006463 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006464
6465 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6466 continue;
6467 }
6468 if (type == bgp_show_type_prefix_list
6469 || type == bgp_show_type_flap_prefix_list)
6470 {
ajs5a646652004-11-05 01:25:55 +00006471 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006472
6473 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6474 continue;
6475 }
6476 if (type == bgp_show_type_filter_list
6477 || type == bgp_show_type_flap_filter_list)
6478 {
ajs5a646652004-11-05 01:25:55 +00006479 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006480
6481 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6482 continue;
6483 }
6484 if (type == bgp_show_type_route_map
6485 || type == bgp_show_type_flap_route_map)
6486 {
ajs5a646652004-11-05 01:25:55 +00006487 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006488 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006489 struct attr dummy_attr;
6490 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006491 int ret;
6492
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006493 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006494 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006495
paul718e3742002-12-13 20:15:29 +00006496 binfo.peer = ri->peer;
6497 binfo.attr = &dummy_attr;
6498
6499 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006500 if (ret == RMAP_DENYMATCH)
6501 continue;
6502 }
6503 if (type == bgp_show_type_neighbor
6504 || type == bgp_show_type_flap_neighbor
6505 || type == bgp_show_type_damp_neighbor)
6506 {
ajs5a646652004-11-05 01:25:55 +00006507 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006508
6509 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6510 continue;
6511 }
6512 if (type == bgp_show_type_cidr_only
6513 || type == bgp_show_type_flap_cidr_only)
6514 {
6515 u_int32_t destination;
6516
6517 destination = ntohl (rn->p.u.prefix4.s_addr);
6518 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6519 continue;
6520 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6521 continue;
6522 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6523 continue;
6524 }
6525 if (type == bgp_show_type_prefix_longer
6526 || type == bgp_show_type_flap_prefix_longer)
6527 {
ajs5a646652004-11-05 01:25:55 +00006528 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006529
6530 if (! prefix_match (p, &rn->p))
6531 continue;
6532 }
6533 if (type == bgp_show_type_community_all)
6534 {
6535 if (! ri->attr->community)
6536 continue;
6537 }
6538 if (type == bgp_show_type_community)
6539 {
ajs5a646652004-11-05 01:25:55 +00006540 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006541
6542 if (! ri->attr->community ||
6543 ! community_match (ri->attr->community, com))
6544 continue;
6545 }
6546 if (type == bgp_show_type_community_exact)
6547 {
ajs5a646652004-11-05 01:25:55 +00006548 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006549
6550 if (! ri->attr->community ||
6551 ! community_cmp (ri->attr->community, com))
6552 continue;
6553 }
6554 if (type == bgp_show_type_community_list)
6555 {
ajs5a646652004-11-05 01:25:55 +00006556 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006557
6558 if (! community_list_match (ri->attr->community, list))
6559 continue;
6560 }
6561 if (type == bgp_show_type_community_list_exact)
6562 {
ajs5a646652004-11-05 01:25:55 +00006563 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006564
6565 if (! community_list_exact_match (ri->attr->community, list))
6566 continue;
6567 }
6568 if (type == bgp_show_type_flap_address
6569 || type == bgp_show_type_flap_prefix)
6570 {
ajs5a646652004-11-05 01:25:55 +00006571 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006572
6573 if (! prefix_match (&rn->p, p))
6574 continue;
6575
6576 if (type == bgp_show_type_flap_prefix)
6577 if (p->prefixlen != rn->p.prefixlen)
6578 continue;
6579 }
6580 if (type == bgp_show_type_dampend_paths
6581 || type == bgp_show_type_damp_neighbor)
6582 {
6583 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6584 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6585 continue;
6586 }
6587
6588 if (header)
6589 {
hasso93406d82005-02-02 14:40:33 +00006590 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6591 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6592 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006593 if (type == bgp_show_type_dampend_paths
6594 || type == bgp_show_type_damp_neighbor)
6595 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6596 else if (type == bgp_show_type_flap_statistics
6597 || type == bgp_show_type_flap_address
6598 || type == bgp_show_type_flap_prefix
6599 || type == bgp_show_type_flap_cidr_only
6600 || type == bgp_show_type_flap_regexp
6601 || type == bgp_show_type_flap_filter_list
6602 || type == bgp_show_type_flap_prefix_list
6603 || type == bgp_show_type_flap_prefix_longer
6604 || type == bgp_show_type_flap_route_map
6605 || type == bgp_show_type_flap_neighbor)
6606 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6607 else
6608 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006609 header = 0;
6610 }
6611
6612 if (type == bgp_show_type_dampend_paths
6613 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006614 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006615 else if (type == bgp_show_type_flap_statistics
6616 || type == bgp_show_type_flap_address
6617 || type == bgp_show_type_flap_prefix
6618 || type == bgp_show_type_flap_cidr_only
6619 || type == bgp_show_type_flap_regexp
6620 || type == bgp_show_type_flap_filter_list
6621 || type == bgp_show_type_flap_prefix_list
6622 || type == bgp_show_type_flap_prefix_longer
6623 || type == bgp_show_type_flap_route_map
6624 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006625 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006626 else
ajs5a646652004-11-05 01:25:55 +00006627 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006628 display++;
6629 }
6630 if (display)
ajs5a646652004-11-05 01:25:55 +00006631 output_count++;
paul718e3742002-12-13 20:15:29 +00006632 }
6633
6634 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006635 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006636 {
6637 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006638 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006639 }
6640 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006641 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6642 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006643
6644 return CMD_SUCCESS;
6645}
6646
ajs5a646652004-11-05 01:25:55 +00006647static int
paulfee0f4c2004-09-13 05:12:46 +00006648bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006649 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006650{
6651 struct bgp_table *table;
6652
6653 if (bgp == NULL) {
6654 bgp = bgp_get_default ();
6655 }
6656
6657 if (bgp == NULL)
6658 {
6659 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6660 return CMD_WARNING;
6661 }
6662
6663
6664 table = bgp->rib[afi][safi];
6665
ajs5a646652004-11-05 01:25:55 +00006666 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006667}
6668
paul718e3742002-12-13 20:15:29 +00006669/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006670static void
paul718e3742002-12-13 20:15:29 +00006671route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6672 struct bgp_node *rn,
6673 struct prefix_rd *prd, afi_t afi, safi_t safi)
6674{
6675 struct bgp_info *ri;
6676 struct prefix *p;
6677 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006678 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006679 char buf1[INET6_ADDRSTRLEN];
6680 char buf2[INET6_ADDRSTRLEN];
6681 int count = 0;
6682 int best = 0;
6683 int suppress = 0;
6684 int no_export = 0;
6685 int no_advertise = 0;
6686 int local_as = 0;
6687 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006688 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006689
6690 p = &rn->p;
6691 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006692 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6693 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006694 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6695 p->prefixlen, VTY_NEWLINE);
6696
6697 for (ri = rn->info; ri; ri = ri->next)
6698 {
6699 count++;
6700 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6701 {
6702 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006703 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006704 suppress = 1;
6705 if (ri->attr->community != NULL)
6706 {
6707 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6708 no_advertise = 1;
6709 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6710 no_export = 1;
6711 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6712 local_as = 1;
6713 }
6714 }
6715 }
6716
6717 vty_out (vty, "Paths: (%d available", count);
6718 if (best)
6719 {
6720 vty_out (vty, ", best #%d", best);
6721 if (safi == SAFI_UNICAST)
6722 vty_out (vty, ", table Default-IP-Routing-Table");
6723 }
6724 else
6725 vty_out (vty, ", no best path");
6726 if (no_advertise)
6727 vty_out (vty, ", not advertised to any peer");
6728 else if (no_export)
6729 vty_out (vty, ", not advertised to EBGP peer");
6730 else if (local_as)
6731 vty_out (vty, ", not advertised outside local AS");
6732 if (suppress)
6733 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6734 vty_out (vty, ")%s", VTY_NEWLINE);
6735
6736 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006737 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006738 {
6739 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6740 {
6741 if (! first)
6742 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6743 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6744 first = 1;
6745 }
6746 }
6747 if (! first)
6748 vty_out (vty, " Not advertised to any peer");
6749 vty_out (vty, "%s", VTY_NEWLINE);
6750}
6751
6752/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006753static int
paulfee0f4c2004-09-13 05:12:46 +00006754bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006755 struct bgp_table *rib, const char *ip_str,
6756 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006757 int prefix_check, enum bgp_path_type pathtype)
paul718e3742002-12-13 20:15:29 +00006758{
6759 int ret;
6760 int header;
6761 int display = 0;
6762 struct prefix match;
6763 struct bgp_node *rn;
6764 struct bgp_node *rm;
6765 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006766 struct bgp_table *table;
6767
Lou Berger050defe2016-01-12 13:41:59 -05006768 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006769 /* Check IP address argument. */
6770 ret = str2prefix (ip_str, &match);
6771 if (! ret)
6772 {
6773 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6774 return CMD_WARNING;
6775 }
6776
6777 match.family = afi2family (afi);
6778
Lou Berger298cc2f2016-01-12 13:42:02 -05006779 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006780 {
paulfee0f4c2004-09-13 05:12:46 +00006781 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006782 {
6783 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6784 continue;
6785
6786 if ((table = rn->info) != NULL)
6787 {
6788 header = 1;
6789
6790 if ((rm = bgp_node_match (table, &match)) != NULL)
6791 {
6792 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006793 {
6794 bgp_unlock_node (rm);
6795 continue;
6796 }
paul718e3742002-12-13 20:15:29 +00006797
6798 for (ri = rm->info; ri; ri = ri->next)
6799 {
6800 if (header)
6801 {
6802 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006803 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006804
6805 header = 0;
6806 }
6807 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006808
6809 if (pathtype == BGP_PATH_ALL ||
6810 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6811 (pathtype == BGP_PATH_MULTIPATH &&
6812 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6813 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006814 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006815
6816 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006817 }
6818 }
6819 }
6820 }
6821 else
6822 {
6823 header = 1;
6824
paulfee0f4c2004-09-13 05:12:46 +00006825 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006826 {
6827 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6828 {
6829 for (ri = rn->info; ri; ri = ri->next)
6830 {
6831 if (header)
6832 {
6833 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6834 header = 0;
6835 }
6836 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006837
6838 if (pathtype == BGP_PATH_ALL ||
6839 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6840 (pathtype == BGP_PATH_MULTIPATH &&
6841 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6842 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00006843 }
6844 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006845
6846 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006847 }
6848 }
6849
6850 if (! display)
6851 {
6852 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6853 return CMD_WARNING;
6854 }
6855
6856 return CMD_SUCCESS;
6857}
6858
paulfee0f4c2004-09-13 05:12:46 +00006859/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006860static int
paulfd79ac92004-10-13 05:06:08 +00006861bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006862 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006863 int prefix_check, enum bgp_path_type pathtype)
paulfee0f4c2004-09-13 05:12:46 +00006864{
6865 struct bgp *bgp;
6866
6867 /* BGP structure lookup. */
6868 if (view_name)
6869 {
6870 bgp = bgp_lookup_by_name (view_name);
6871 if (bgp == NULL)
6872 {
6873 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6874 return CMD_WARNING;
6875 }
6876 }
6877 else
6878 {
6879 bgp = bgp_get_default ();
6880 if (bgp == NULL)
6881 {
6882 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6883 return CMD_WARNING;
6884 }
6885 }
6886
6887 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006888 afi, safi, prd, prefix_check, pathtype);
paulfee0f4c2004-09-13 05:12:46 +00006889}
6890
paul718e3742002-12-13 20:15:29 +00006891/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006892DEFUN (show_ip_bgp,
6893 show_ip_bgp_cmd,
6894 "show ip bgp",
6895 SHOW_STR
6896 IP_STR
6897 BGP_STR)
6898{
6899 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6900}
6901
6902DEFUN (show_ip_bgp_ipv4,
6903 show_ip_bgp_ipv4_cmd,
6904 "show ip bgp ipv4 (unicast|multicast)",
6905 SHOW_STR
6906 IP_STR
6907 BGP_STR
6908 "Address family\n"
6909 "Address Family modifier\n"
6910 "Address Family modifier\n")
6911{
6912 if (strncmp (argv[0], "m", 1) == 0)
6913 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6914 NULL);
6915
6916 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6917}
6918
6919DEFUN (show_ip_bgp_route,
6920 show_ip_bgp_route_cmd,
6921 "show ip bgp A.B.C.D",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "Network in the BGP routing table to display\n")
6926{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006927 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
6928}
6929
6930DEFUN (show_ip_bgp_route_pathtype,
6931 show_ip_bgp_route_pathtype_cmd,
6932 "show ip bgp A.B.C.D (bestpath|multipath)",
6933 SHOW_STR
6934 IP_STR
6935 BGP_STR
6936 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6937 "Display only the bestpath\n"
6938 "Display only multipaths\n")
6939{
6940 if (strncmp (argv[1], "b", 1) == 0)
6941 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6942 else
6943 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
6944}
6945
6946DEFUN (show_bgp_ipv4_safi_route_pathtype,
6947 show_bgp_ipv4_safi_route_pathtype_cmd,
6948 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
6949 SHOW_STR
6950 BGP_STR
6951 "Address family\n"
6952 "Address Family modifier\n"
6953 "Address Family modifier\n"
6954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6955 "Display only the bestpath\n"
6956 "Display only multipaths\n")
6957{
6958 if (strncmp (argv[0], "m", 1) == 0)
6959 if (strncmp (argv[2], "b", 1) == 0)
6960 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
6961 else
6962 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
6963 else
6964 if (strncmp (argv[2], "b", 1) == 0)
6965 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6966 else
6967 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006968}
6969
6970DEFUN (show_ip_bgp_ipv4_route,
6971 show_ip_bgp_ipv4_route_cmd,
6972 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6973 SHOW_STR
6974 IP_STR
6975 BGP_STR
6976 "Address family\n"
6977 "Address Family modifier\n"
6978 "Address Family modifier\n"
6979 "Network in the BGP routing table to display\n")
6980{
6981 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006982 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006983
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006984 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006985}
6986
6987DEFUN (show_ip_bgp_vpnv4_all_route,
6988 show_ip_bgp_vpnv4_all_route_cmd,
6989 "show ip bgp vpnv4 all A.B.C.D",
6990 SHOW_STR
6991 IP_STR
6992 BGP_STR
6993 "Display VPNv4 NLRI specific information\n"
6994 "Display information about all VPNv4 NLRIs\n"
6995 "Network in the BGP routing table to display\n")
6996{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006997 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006998}
6999
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007000
Lou Bergerf9b6c392016-01-12 13:42:09 -05007001DEFUN (show_ip_bgp_vpnv4_rd_route,
7002 show_ip_bgp_vpnv4_rd_route_cmd,
7003 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7004 SHOW_STR
7005 IP_STR
7006 BGP_STR
7007 "Display VPNv4 NLRI specific information\n"
7008 "Display information for a route distinguisher\n"
7009 "VPN Route Distinguisher\n"
7010 "Network in the BGP routing table to display\n")
7011{
7012 int ret;
7013 struct prefix_rd prd;
7014
7015 ret = str2prefix_rd (argv[0], &prd);
7016 if (! ret)
7017 {
7018 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7019 return CMD_WARNING;
7020 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007021 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007022}
7023
7024DEFUN (show_ip_bgp_prefix,
7025 show_ip_bgp_prefix_cmd,
7026 "show ip bgp A.B.C.D/M",
7027 SHOW_STR
7028 IP_STR
7029 BGP_STR
7030 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7031{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007032 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7033}
7034
7035DEFUN (show_ip_bgp_prefix_pathtype,
7036 show_ip_bgp_prefix_pathtype_cmd,
7037 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7038 SHOW_STR
7039 IP_STR
7040 BGP_STR
7041 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7042 "Display only the bestpath\n"
7043 "Display only multipaths\n")
7044{
7045 if (strncmp (argv[1], "b", 1) == 0)
7046 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7047 else
7048 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007049}
7050
7051DEFUN (show_ip_bgp_ipv4_prefix,
7052 show_ip_bgp_ipv4_prefix_cmd,
7053 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7054 SHOW_STR
7055 IP_STR
7056 BGP_STR
7057 "Address family\n"
7058 "Address Family modifier\n"
7059 "Address Family modifier\n"
7060 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7061{
7062 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007063 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007064
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007065 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007066}
7067
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007068DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7069 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7070 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7071 SHOW_STR
7072 IP_STR
7073 BGP_STR
7074 "Address family\n"
7075 "Address Family modifier\n"
7076 "Address Family modifier\n"
7077 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7078 "Display only the bestpath\n"
7079 "Display only multipaths\n")
7080{
7081 if (strncmp (argv[0], "m", 1) == 0)
7082 if (strncmp (argv[2], "b", 1) == 0)
7083 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7084 else
7085 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7086 else
7087 if (strncmp (argv[2], "b", 1) == 0)
7088 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7089 else
7090 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7091}
7092
7093ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7094 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7095 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7096 SHOW_STR
7097 BGP_STR
7098 "Address family\n"
7099 "Address Family modifier\n"
7100 "Address Family modifier\n"
7101 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7102 "Display only the bestpath\n"
7103 "Display only multipaths\n")
7104
Lou Bergerf9b6c392016-01-12 13:42:09 -05007105DEFUN (show_ip_bgp_vpnv4_all_prefix,
7106 show_ip_bgp_vpnv4_all_prefix_cmd,
7107 "show ip bgp vpnv4 all A.B.C.D/M",
7108 SHOW_STR
7109 IP_STR
7110 BGP_STR
7111 "Display VPNv4 NLRI specific information\n"
7112 "Display information about all VPNv4 NLRIs\n"
7113 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7114{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007115 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007116}
7117
7118DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7119 show_ip_bgp_vpnv4_rd_prefix_cmd,
7120 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7121 SHOW_STR
7122 IP_STR
7123 BGP_STR
7124 "Display VPNv4 NLRI specific information\n"
7125 "Display information for a route distinguisher\n"
7126 "VPN Route Distinguisher\n"
7127 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7128{
7129 int ret;
7130 struct prefix_rd prd;
7131
7132 ret = str2prefix_rd (argv[0], &prd);
7133 if (! ret)
7134 {
7135 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7136 return CMD_WARNING;
7137 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007138 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007139}
7140
7141DEFUN (show_ip_bgp_view,
7142 show_ip_bgp_view_cmd,
7143 "show ip bgp view WORD",
7144 SHOW_STR
7145 IP_STR
7146 BGP_STR
7147 "BGP view\n"
7148 "View name\n")
7149{
7150 struct bgp *bgp;
7151
7152 /* BGP structure lookup. */
7153 bgp = bgp_lookup_by_name (argv[0]);
7154 if (bgp == NULL)
7155 {
7156 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7157 return CMD_WARNING;
7158 }
7159
7160 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7161}
7162
7163DEFUN (show_ip_bgp_view_route,
7164 show_ip_bgp_view_route_cmd,
7165 "show ip bgp view WORD A.B.C.D",
7166 SHOW_STR
7167 IP_STR
7168 BGP_STR
7169 "BGP view\n"
7170 "View name\n"
7171 "Network in the BGP routing table to display\n")
7172{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007173 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007174}
7175
7176DEFUN (show_ip_bgp_view_prefix,
7177 show_ip_bgp_view_prefix_cmd,
7178 "show ip bgp view WORD A.B.C.D/M",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "BGP view\n"
7183 "View name\n"
7184 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7185{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007186 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007187}
7188
7189DEFUN (show_bgp,
7190 show_bgp_cmd,
7191 "show bgp",
7192 SHOW_STR
7193 BGP_STR)
7194{
7195 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7196 NULL);
7197}
7198
7199ALIAS (show_bgp,
7200 show_bgp_ipv6_cmd,
7201 "show bgp ipv6",
7202 SHOW_STR
7203 BGP_STR
7204 "Address family\n")
7205
7206/* old command */
7207DEFUN (show_ipv6_bgp,
7208 show_ipv6_bgp_cmd,
7209 "show ipv6 bgp",
7210 SHOW_STR
7211 IP_STR
7212 BGP_STR)
7213{
7214 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7215 NULL);
7216}
7217
7218DEFUN (show_bgp_route,
7219 show_bgp_route_cmd,
7220 "show bgp X:X::X:X",
7221 SHOW_STR
7222 BGP_STR
7223 "Network in the BGP routing table to display\n")
7224{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007225 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007226}
7227
Lou Berger35c36862016-01-12 13:42:06 -05007228DEFUN (show_bgp_ipv4_safi,
7229 show_bgp_ipv4_safi_cmd,
7230 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007231 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007232 BGP_STR
7233 "Address family\n"
7234 "Address Family modifier\n"
7235 "Address Family modifier\n")
7236{
7237 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007238 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7239 NULL);
paul718e3742002-12-13 20:15:29 +00007240
ajs5a646652004-11-05 01:25:55 +00007241 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007242}
7243
Lou Berger35c36862016-01-12 13:42:06 -05007244DEFUN (show_bgp_ipv4_safi_route,
7245 show_bgp_ipv4_safi_route_cmd,
7246 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007247 SHOW_STR
7248 BGP_STR
7249 "Address family\n"
7250 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007251 "Address Family modifier\n"
7252 "Network in the BGP routing table to display\n")
7253{
7254 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007255 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007256
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007257 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7258}
7259
7260DEFUN (show_bgp_route_pathtype,
7261 show_bgp_route_pathtype_cmd,
7262 "show bgp X:X::X:X (bestpath|multipath)",
7263 SHOW_STR
7264 BGP_STR
7265 "Network in the BGP routing table to display\n"
7266 "Display only the bestpath\n"
7267 "Display only multipaths\n")
7268{
7269 if (strncmp (argv[1], "b", 1) == 0)
7270 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7271 else
7272 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7273}
7274
7275ALIAS (show_bgp_route_pathtype,
7276 show_bgp_ipv6_route_pathtype_cmd,
7277 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7278 SHOW_STR
7279 BGP_STR
7280 "Address family\n"
7281 "Network in the BGP routing table to display\n"
7282 "Display only the bestpath\n"
7283 "Display only multipaths\n")
7284
7285DEFUN (show_bgp_ipv6_safi_route_pathtype,
7286 show_bgp_ipv6_safi_route_pathtype_cmd,
7287 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7288 SHOW_STR
7289 BGP_STR
7290 "Address family\n"
7291 "Address Family modifier\n"
7292 "Address Family modifier\n"
7293 "Network in the BGP routing table to display\n"
7294 "Display only the bestpath\n"
7295 "Display only multipaths\n")
7296{
7297 if (strncmp (argv[0], "m", 1) == 0)
7298 if (strncmp (argv[2], "b", 1) == 0)
7299 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7300 else
7301 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7302 else
7303 if (strncmp (argv[2], "b", 1) == 0)
7304 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7305 else
7306 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007307}
7308
Lou Berger35c36862016-01-12 13:42:06 -05007309DEFUN (show_bgp_ipv4_vpn_route,
7310 show_bgp_ipv4_vpn_route_cmd,
7311 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007312 SHOW_STR
7313 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007314 "Address Family\n"
7315 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007316 "Network in the BGP routing table to display\n")
7317{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007318 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007319}
7320
Lou Berger35c36862016-01-12 13:42:06 -05007321DEFUN (show_bgp_ipv6_vpn_route,
7322 show_bgp_ipv6_vpn_route_cmd,
7323 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007324 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007325 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007326 "Address Family\n"
7327 "Display VPN NLRI specific information\n"
7328 "Network in the BGP routing table to display\n")
7329{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007330 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007331}
Lou Berger35c36862016-01-12 13:42:06 -05007332
7333DEFUN (show_bgp_ipv4_vpn_rd_route,
7334 show_bgp_ipv4_vpn_rd_route_cmd,
7335 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7336 SHOW_STR
7337 BGP_STR
7338 IP_STR
7339 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007340 "Display information for a route distinguisher\n"
7341 "VPN Route Distinguisher\n"
7342 "Network in the BGP routing table to display\n")
7343{
7344 int ret;
7345 struct prefix_rd prd;
7346
7347 ret = str2prefix_rd (argv[0], &prd);
7348 if (! ret)
7349 {
7350 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7351 return CMD_WARNING;
7352 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007353 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007354}
7355
Lou Berger35c36862016-01-12 13:42:06 -05007356DEFUN (show_bgp_ipv6_vpn_rd_route,
7357 show_bgp_ipv6_vpn_rd_route_cmd,
7358 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007359 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007360 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007361 "Address Family\n"
7362 "Display VPN NLRI specific information\n"
7363 "Display information for a route distinguisher\n"
7364 "VPN Route Distinguisher\n"
7365 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007366{
Lou Berger35c36862016-01-12 13:42:06 -05007367 int ret;
7368 struct prefix_rd prd;
7369
7370 ret = str2prefix_rd (argv[0], &prd);
7371 if (! ret)
7372 {
7373 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7374 return CMD_WARNING;
7375 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007376 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7377}
7378
7379DEFUN (show_bgp_prefix_pathtype,
7380 show_bgp_prefix_pathtype_cmd,
7381 "show bgp X:X::X:X/M (bestpath|multipath)",
7382 SHOW_STR
7383 BGP_STR
7384 "IPv6 prefix <network>/<length>\n"
7385 "Display only the bestpath\n"
7386 "Display only multipaths\n")
7387{
7388 if (strncmp (argv[1], "b", 1) == 0)
7389 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7390 else
7391 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7392}
7393
7394ALIAS (show_bgp_prefix_pathtype,
7395 show_bgp_ipv6_prefix_pathtype_cmd,
7396 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7397 SHOW_STR
7398 BGP_STR
7399 "Address family\n"
7400 "IPv6 prefix <network>/<length>\n"
7401 "Display only the bestpath\n"
7402 "Display only multipaths\n")
7403
7404DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7405 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7406 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7407 SHOW_STR
7408 BGP_STR
7409 "Address family\n"
7410 "Address Family modifier\n"
7411 "Address Family modifier\n"
7412 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7413 "Display only the bestpath\n"
7414 "Display only multipaths\n")
7415{
7416 if (strncmp (argv[0], "m", 1) == 0)
7417 if (strncmp (argv[2], "b", 1) == 0)
7418 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7419 else
7420 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7421 else
7422 if (strncmp (argv[2], "b", 1) == 0)
7423 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7424 else
7425 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007426}
7427
Lou Berger651b4022016-01-12 13:42:07 -05007428DEFUN (show_bgp_ipv4_encap_route,
7429 show_bgp_ipv4_encap_route_cmd,
7430 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007431 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007432 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007433 IP_STR
7434 "Display ENCAP NLRI specific information\n"
7435 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007436{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007437 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007438}
7439
Lou Berger651b4022016-01-12 13:42:07 -05007440DEFUN (show_bgp_ipv6_encap_route,
7441 show_bgp_ipv6_encap_route_cmd,
7442 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007443 SHOW_STR
7444 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007445 IP6_STR
7446 "Display ENCAP NLRI specific information\n"
7447 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007448{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007449 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007450}
7451
Lou Berger651b4022016-01-12 13:42:07 -05007452DEFUN (show_bgp_ipv4_safi_rd_route,
7453 show_bgp_ipv4_safi_rd_route_cmd,
7454 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007455 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007456 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007457 "Address Family\n"
7458 "Address Family Modifier\n"
7459 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007460 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007461 "ENCAP Route Distinguisher\n"
7462 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007463{
7464 int ret;
7465 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007466 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007467
Lou Berger651b4022016-01-12 13:42:07 -05007468 if (bgp_parse_safi(argv[0], &safi)) {
7469 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7470 return CMD_WARNING;
7471 }
7472 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007473 if (! ret)
7474 {
7475 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7476 return CMD_WARNING;
7477 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007478 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007479}
7480
Lou Berger651b4022016-01-12 13:42:07 -05007481DEFUN (show_bgp_ipv6_safi_rd_route,
7482 show_bgp_ipv6_safi_rd_route_cmd,
7483 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007484 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007485 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007486 "Address Family\n"
7487 "Address Family Modifier\n"
7488 "Address Family Modifier\n"
7489 "Display information for a route distinguisher\n"
7490 "ENCAP Route Distinguisher\n"
7491 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007492{
Lou Berger651b4022016-01-12 13:42:07 -05007493 int ret;
7494 struct prefix_rd prd;
7495 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007496
Lou Berger651b4022016-01-12 13:42:07 -05007497 if (bgp_parse_safi(argv[0], &safi)) {
7498 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7499 return CMD_WARNING;
7500 }
7501 ret = str2prefix_rd (argv[1], &prd);
7502 if (! ret)
7503 {
7504 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7505 return CMD_WARNING;
7506 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007507 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007508}
7509
Lou Berger35c36862016-01-12 13:42:06 -05007510DEFUN (show_bgp_ipv4_prefix,
7511 show_bgp_ipv4_prefix_cmd,
7512 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007513 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007514 BGP_STR
paul718e3742002-12-13 20:15:29 +00007515 IP_STR
paul718e3742002-12-13 20:15:29 +00007516 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7517{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007518 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007519}
7520
Lou Berger35c36862016-01-12 13:42:06 -05007521DEFUN (show_bgp_ipv4_safi_prefix,
7522 show_bgp_ipv4_safi_prefix_cmd,
7523 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007524 SHOW_STR
7525 BGP_STR
7526 "Address family\n"
7527 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007528 "Address Family modifier\n"
7529 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007530{
7531 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007532 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007533
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007534 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007535}
7536
Lou Berger35c36862016-01-12 13:42:06 -05007537DEFUN (show_bgp_ipv4_vpn_prefix,
7538 show_bgp_ipv4_vpn_prefix_cmd,
7539 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007540 SHOW_STR
7541 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007542 IP_STR
7543 "Display VPN NLRI specific information\n"
7544 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007545{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007546 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007547}
7548
Lou Berger35c36862016-01-12 13:42:06 -05007549DEFUN (show_bgp_ipv6_vpn_prefix,
7550 show_bgp_ipv6_vpn_prefix_cmd,
7551 "show bgp ipv6 vpn X:X::X:X/M",
7552 SHOW_STR
7553 BGP_STR
7554 "Address Family\n"
7555 "Display VPN NLRI specific information\n"
7556 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7557{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007558 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007559}
Lou Berger35c36862016-01-12 13:42:06 -05007560
Lou Berger651b4022016-01-12 13:42:07 -05007561DEFUN (show_bgp_ipv4_encap_prefix,
7562 show_bgp_ipv4_encap_prefix_cmd,
7563 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007564 SHOW_STR
7565 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007566 IP_STR
7567 "Display ENCAP NLRI specific information\n"
7568 "Display information about ENCAP NLRIs\n"
7569 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7570{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007571 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007572}
paul718e3742002-12-13 20:15:29 +00007573
Lou Berger651b4022016-01-12 13:42:07 -05007574DEFUN (show_bgp_ipv6_encap_prefix,
7575 show_bgp_ipv6_encap_prefix_cmd,
7576 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007577 SHOW_STR
7578 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007579 IP_STR
7580 "Display ENCAP NLRI specific information\n"
7581 "Display information about ENCAP NLRIs\n"
7582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7583{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007584 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007585}
Lou Berger651b4022016-01-12 13:42:07 -05007586
7587DEFUN (show_bgp_ipv4_safi_rd_prefix,
7588 show_bgp_ipv4_safi_rd_prefix_cmd,
7589 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7590 SHOW_STR
7591 BGP_STR
7592 "Address Family\n"
7593 "Address Family Modifier\n"
7594 "Address Family Modifier\n"
7595 "Display information for a route distinguisher\n"
7596 "ENCAP Route Distinguisher\n"
7597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7598{
7599 int ret;
7600 struct prefix_rd prd;
7601 safi_t safi;
7602
7603 if (bgp_parse_safi(argv[0], &safi)) {
7604 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7605 return CMD_WARNING;
7606 }
7607
7608 ret = str2prefix_rd (argv[1], &prd);
7609 if (! ret)
7610 {
7611 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7612 return CMD_WARNING;
7613 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007614 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007615}
7616
Lou Berger651b4022016-01-12 13:42:07 -05007617DEFUN (show_bgp_ipv6_safi_rd_prefix,
7618 show_bgp_ipv6_safi_rd_prefix_cmd,
7619 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7620 SHOW_STR
7621 BGP_STR
7622 "Address Family\n"
7623 "Address Family Modifier\n"
7624 "Address Family Modifier\n"
7625 "Display information for a route distinguisher\n"
7626 "ENCAP Route Distinguisher\n"
7627 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7628{
7629 int ret;
7630 struct prefix_rd prd;
7631 safi_t safi;
7632
7633 if (bgp_parse_safi(argv[0], &safi)) {
7634 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7635 return CMD_WARNING;
7636 }
7637
7638 ret = str2prefix_rd (argv[1], &prd);
7639 if (! ret)
7640 {
7641 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7642 return CMD_WARNING;
7643 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007644 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007645}
Lou Berger651b4022016-01-12 13:42:07 -05007646
7647DEFUN (show_bgp_afi_safi_view,
7648 show_bgp_afi_safi_view_cmd,
7649 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7650 SHOW_STR
7651 BGP_STR
7652 "BGP view\n"
7653 "BGP view name\n"
7654 "Address Family\n"
7655 "Address Family\n"
7656 "Address Family Modifier\n"
7657 "Address Family Modifier\n"
7658 "Address Family Modifier\n"
7659 "Address Family Modifier\n"
7660 )
7661{
7662 struct bgp *bgp;
7663 safi_t safi;
7664 afi_t afi;
7665
7666 if (bgp_parse_afi(argv[1], &afi)) {
7667 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7668 return CMD_WARNING;
7669 }
7670 if (bgp_parse_safi(argv[2], &safi)) {
7671 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7672 return CMD_WARNING;
7673 }
7674
7675 /* BGP structure lookup. */
7676 bgp = bgp_lookup_by_name (argv[0]);
7677 if (bgp == NULL)
7678 {
7679 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7680 return CMD_WARNING;
7681 }
7682
7683 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7684}
7685
7686DEFUN (show_bgp_view_afi_safi_route,
7687 show_bgp_view_afi_safi_route_cmd,
7688 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7689 SHOW_STR
7690 BGP_STR
7691 "BGP view\n"
7692 "View name\n"
7693 "Address Family\n"
7694 "Address Family\n"
7695 "Address Family Modifier\n"
7696 "Address Family Modifier\n"
7697 "Address Family Modifier\n"
7698 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007699 "Network in the BGP routing table to display\n")
7700{
Lou Berger651b4022016-01-12 13:42:07 -05007701 safi_t safi;
7702 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007703
Lou Berger651b4022016-01-12 13:42:07 -05007704 if (bgp_parse_afi(argv[1], &afi)) {
7705 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7706 return CMD_WARNING;
7707 }
7708 if (bgp_parse_safi(argv[2], &safi)) {
7709 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7710 return CMD_WARNING;
7711 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007712 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007713}
7714
7715DEFUN (show_bgp_view_afi_safi_prefix,
7716 show_bgp_view_afi_safi_prefix_cmd,
7717 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7718 SHOW_STR
7719 BGP_STR
7720 "BGP view\n"
7721 "View name\n"
7722 "Address Family\n"
7723 "Address Family\n"
7724 "Address Family Modifier\n"
7725 "Address Family Modifier\n"
7726 "Address Family Modifier\n"
7727 "Address Family Modifier\n"
7728 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7729{
7730 safi_t safi;
7731 afi_t afi;
7732
7733 if (bgp_parse_afi(argv[1], &afi)) {
7734 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7735 return CMD_WARNING;
7736 }
7737 if (bgp_parse_safi(argv[2], &safi)) {
7738 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7739 return CMD_WARNING;
7740 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007741 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007742}
7743
7744/* new001 */
7745DEFUN (show_bgp_afi,
7746 show_bgp_afi_cmd,
7747 "show bgp (ipv4|ipv6)",
7748 SHOW_STR
7749 BGP_STR
7750 "Address family\n"
7751 "Address family\n")
7752{
7753 afi_t afi;
7754
7755 if (bgp_parse_afi(argv[0], &afi)) {
7756 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7757 return CMD_WARNING;
7758 }
7759 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7760 NULL);
7761}
7762
Lou Berger651b4022016-01-12 13:42:07 -05007763DEFUN (show_bgp_ipv6_safi,
7764 show_bgp_ipv6_safi_cmd,
7765 "show bgp ipv6 (unicast|multicast)",
7766 SHOW_STR
7767 BGP_STR
7768 "Address family\n"
7769 "Address Family modifier\n"
7770 "Address Family modifier\n")
7771{
7772 if (strncmp (argv[0], "m", 1) == 0)
7773 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7774 NULL);
7775
7776 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007777}
7778
Lou Berger35c36862016-01-12 13:42:06 -05007779DEFUN (show_bgp_ipv6_route,
7780 show_bgp_ipv6_route_cmd,
7781 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007782 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007783 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007784 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007785 "Network in the BGP routing table to display\n")
7786{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007787 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007788}
7789
Lou Berger35c36862016-01-12 13:42:06 -05007790DEFUN (show_bgp_ipv6_safi_route,
7791 show_bgp_ipv6_safi_route_cmd,
7792 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007793 SHOW_STR
7794 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007795 "Address family\n"
7796 "Address Family modifier\n"
7797 "Address Family modifier\n"
7798 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007799{
Lou Berger35c36862016-01-12 13:42:06 -05007800 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007801 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007802
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007803 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007804}
7805
Lou Bergerf9b6c392016-01-12 13:42:09 -05007806/* old command */
7807DEFUN (show_ipv6_bgp_route,
7808 show_ipv6_bgp_route_cmd,
7809 "show ipv6 bgp X:X::X:X",
7810 SHOW_STR
7811 IP_STR
7812 BGP_STR
7813 "Network in the BGP routing table to display\n")
7814{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007815 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007816}
7817
7818DEFUN (show_bgp_prefix,
7819 show_bgp_prefix_cmd,
7820 "show bgp X:X::X:X/M",
7821 SHOW_STR
7822 BGP_STR
7823 "IPv6 prefix <network>/<length>\n")
7824{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007826}
7827
7828
Lou Berger35c36862016-01-12 13:42:06 -05007829/* new002 */
7830DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007831 show_bgp_ipv6_prefix_cmd,
7832 "show bgp ipv6 X:X::X:X/M",
7833 SHOW_STR
7834 BGP_STR
7835 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007836 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7837{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007838 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007839}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007840DEFUN (show_bgp_ipv6_safi_prefix,
7841 show_bgp_ipv6_safi_prefix_cmd,
7842 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7843 SHOW_STR
7844 BGP_STR
7845 "Address family\n"
7846 "Address Family modifier\n"
7847 "Address Family modifier\n"
7848 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7849{
7850 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007851 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007852
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007853 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007854}
7855
Lou Bergerf9b6c392016-01-12 13:42:09 -05007856/* old command */
7857DEFUN (show_ipv6_bgp_prefix,
7858 show_ipv6_bgp_prefix_cmd,
7859 "show ipv6 bgp X:X::X:X/M",
7860 SHOW_STR
7861 IP_STR
7862 BGP_STR
7863 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7864{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007865 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007866}
7867
paulbb46e942003-10-24 19:02:03 +00007868DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007869 show_bgp_view_cmd,
7870 "show bgp view WORD",
7871 SHOW_STR
7872 BGP_STR
7873 "BGP view\n"
7874 "View name\n")
7875{
7876 struct bgp *bgp;
7877
7878 /* BGP structure lookup. */
7879 bgp = bgp_lookup_by_name (argv[0]);
7880 if (bgp == NULL)
7881 {
7882 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7883 return CMD_WARNING;
7884 }
7885
7886 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7887}
7888
7889DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007890 show_bgp_view_ipv6_cmd,
7891 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007892 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007893 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007894 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007895 "View name\n"
7896 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007897{
7898 struct bgp *bgp;
7899
7900 /* BGP structure lookup. */
7901 bgp = bgp_lookup_by_name (argv[0]);
7902 if (bgp == NULL)
7903 {
7904 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7905 return CMD_WARNING;
7906 }
7907
ajs5a646652004-11-05 01:25:55 +00007908 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007909}
paulbb46e942003-10-24 19:02:03 +00007910
7911DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007912 show_bgp_view_route_cmd,
7913 "show bgp view WORD X:X::X:X",
7914 SHOW_STR
7915 BGP_STR
7916 "BGP view\n"
7917 "View name\n"
7918 "Network in the BGP routing table to display\n")
7919{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007920 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007921}
7922
7923DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007924 show_bgp_view_ipv6_route_cmd,
7925 "show bgp view WORD ipv6 X:X::X:X",
7926 SHOW_STR
7927 BGP_STR
7928 "BGP view\n"
7929 "View name\n"
7930 "Address family\n"
7931 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007932{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007933 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulbb46e942003-10-24 19:02:03 +00007934}
7935
Lou Bergerf9b6c392016-01-12 13:42:09 -05007936/* old command */
7937DEFUN (show_ipv6_mbgp,
7938 show_ipv6_mbgp_cmd,
7939 "show ipv6 mbgp",
7940 SHOW_STR
7941 IP_STR
7942 MBGP_STR)
7943{
7944 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7945 NULL);
7946}
7947
7948/* old command */
7949DEFUN (show_ipv6_mbgp_route,
7950 show_ipv6_mbgp_route_cmd,
7951 "show ipv6 mbgp X:X::X:X",
7952 SHOW_STR
7953 IP_STR
7954 MBGP_STR
7955 "Network in the MBGP routing table to display\n")
7956{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007957 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007958}
7959
7960/* old command */
7961DEFUN (show_ipv6_mbgp_prefix,
7962 show_ipv6_mbgp_prefix_cmd,
7963 "show ipv6 mbgp X:X::X:X/M",
7964 SHOW_STR
7965 IP_STR
7966 MBGP_STR
7967 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7968{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007969 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007970}
7971
Lou Berger35c36862016-01-12 13:42:06 -05007972DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007973 show_bgp_view_prefix_cmd,
7974 "show bgp view WORD X:X::X:X/M",
7975 SHOW_STR
7976 BGP_STR
7977 "BGP view\n"
7978 "View name\n"
7979 "IPv6 prefix <network>/<length>\n")
7980{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007981 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007982}
7983
7984DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007985 show_bgp_view_ipv6_prefix_cmd,
7986 "show bgp view WORD ipv6 X:X::X:X/M",
7987 SHOW_STR
7988 BGP_STR
7989 "BGP view\n"
7990 "View name\n"
7991 "Address family\n"
7992 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007993{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007994 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007995}
7996
paul94f2b392005-06-28 12:44:16 +00007997static int
paulfd79ac92004-10-13 05:06:08 +00007998bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007999 safi_t safi, enum bgp_show_type type)
8000{
8001 int i;
8002 struct buffer *b;
8003 char *regstr;
8004 int first;
8005 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00008006 int rc;
paul718e3742002-12-13 20:15:29 +00008007
8008 first = 0;
8009 b = buffer_new (1024);
8010 for (i = 0; i < argc; i++)
8011 {
8012 if (first)
8013 buffer_putc (b, ' ');
8014 else
8015 {
8016 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8017 continue;
8018 first = 1;
8019 }
8020
8021 buffer_putstr (b, argv[i]);
8022 }
8023 buffer_putc (b, '\0');
8024
8025 regstr = buffer_getstr (b);
8026 buffer_free (b);
8027
8028 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00008029 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00008030 if (! regex)
8031 {
8032 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8033 VTY_NEWLINE);
8034 return CMD_WARNING;
8035 }
8036
ajs5a646652004-11-05 01:25:55 +00008037 rc = bgp_show (vty, NULL, afi, safi, type, regex);
8038 bgp_regex_free (regex);
8039 return rc;
paul718e3742002-12-13 20:15:29 +00008040}
8041
Lou Bergerf9b6c392016-01-12 13:42:09 -05008042
8043DEFUN (show_ip_bgp_regexp,
8044 show_ip_bgp_regexp_cmd,
8045 "show ip bgp regexp .LINE",
8046 SHOW_STR
8047 IP_STR
8048 BGP_STR
8049 "Display routes matching the AS path regular expression\n"
8050 "A regular-expression to match the BGP AS paths\n")
8051{
8052 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8053 bgp_show_type_regexp);
8054}
8055
8056DEFUN (show_ip_bgp_flap_regexp,
8057 show_ip_bgp_flap_regexp_cmd,
8058 "show ip bgp flap-statistics regexp .LINE",
8059 SHOW_STR
8060 IP_STR
8061 BGP_STR
8062 "Display flap statistics of routes\n"
8063 "Display routes matching the AS path regular expression\n"
8064 "A regular-expression to match the BGP AS paths\n")
8065{
8066 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8067 bgp_show_type_flap_regexp);
8068}
8069
8070ALIAS (show_ip_bgp_flap_regexp,
8071 show_ip_bgp_damp_flap_regexp_cmd,
8072 "show ip bgp dampening flap-statistics regexp .LINE",
8073 SHOW_STR
8074 IP_STR
8075 BGP_STR
8076 "Display detailed information about dampening\n"
8077 "Display flap statistics of routes\n"
8078 "Display routes matching the AS path regular expression\n"
8079 "A regular-expression to match the BGP AS paths\n")
8080
8081DEFUN (show_ip_bgp_ipv4_regexp,
8082 show_ip_bgp_ipv4_regexp_cmd,
8083 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8084 SHOW_STR
8085 IP_STR
8086 BGP_STR
8087 "Address family\n"
8088 "Address Family modifier\n"
8089 "Address Family modifier\n"
8090 "Display routes matching the AS path regular expression\n"
8091 "A regular-expression to match the BGP AS paths\n")
8092{
8093 if (strncmp (argv[0], "m", 1) == 0)
8094 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8095 bgp_show_type_regexp);
8096
8097 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8098 bgp_show_type_regexp);
8099}
8100
Lou Bergerf9b6c392016-01-12 13:42:09 -05008101DEFUN (show_bgp_regexp,
8102 show_bgp_regexp_cmd,
8103 "show bgp regexp .LINE",
8104 SHOW_STR
8105 BGP_STR
8106 "Display routes matching the AS path regular expression\n"
8107 "A regular-expression to match the BGP AS paths\n")
8108{
8109 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8110 bgp_show_type_regexp);
8111}
8112
8113/* old command */
8114DEFUN (show_ipv6_bgp_regexp,
8115 show_ipv6_bgp_regexp_cmd,
8116 "show ipv6 bgp regexp .LINE",
8117 SHOW_STR
8118 IP_STR
8119 BGP_STR
8120 "Display routes matching the AS path regular expression\n"
8121 "A regular-expression to match the BGP AS paths\n")
8122{
8123 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8124 bgp_show_type_regexp);
8125}
8126
8127/* old command */
8128DEFUN (show_ipv6_mbgp_regexp,
8129 show_ipv6_mbgp_regexp_cmd,
8130 "show ipv6 mbgp regexp .LINE",
8131 SHOW_STR
8132 IP_STR
8133 BGP_STR
8134 "Display routes matching the AS path regular expression\n"
8135 "A regular-expression to match the MBGP AS paths\n")
8136{
8137 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8138 bgp_show_type_regexp);
8139}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008140
Lou Berger651b4022016-01-12 13:42:07 -05008141DEFUN (show_bgp_ipv4_safi_flap_regexp,
8142 show_bgp_ipv4_safi_flap_regexp_cmd,
8143 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008144 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008145 BGP_STR
paul718e3742002-12-13 20:15:29 +00008146 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008147 "Address Family Modifier\n"
8148 "Address Family Modifier\n"
8149 "Address Family Modifier\n"
8150 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008151 "Display flap statistics of routes\n"
8152 "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
8157 if (bgp_parse_safi(argv[0], &safi)) {
8158 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8159 return CMD_WARNING;
8160 }
8161 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8162 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008163}
8164
Lou Berger651b4022016-01-12 13:42:07 -05008165ALIAS (show_bgp_ipv4_safi_flap_regexp,
8166 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8167 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308168 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308169 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008170 IP_STR
8171 "Address Family Modifier\n"
8172 "Address Family Modifier\n"
8173 "Address Family Modifier\n"
8174 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308175 "Display detailed information about dampening\n"
8176 "Display flap statistics of routes\n"
8177 "Display routes matching the AS path regular expression\n"
8178 "A regular-expression to match the BGP AS paths\n")
8179
Lou Berger651b4022016-01-12 13:42:07 -05008180DEFUN (show_bgp_ipv6_safi_flap_regexp,
8181 show_bgp_ipv6_safi_flap_regexp_cmd,
8182 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008183 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008184 BGP_STR
8185 IPV6_STR
8186 "Address Family Modifier\n"
8187 "Address Family Modifier\n"
8188 "Address Family Modifier\n"
8189 "Address Family Modifier\n"
8190 "Display flap statistics of routes\n"
8191 "Display routes matching the AS path regular expression\n"
8192 "A regular-expression to match the BGP AS paths\n")
8193{
8194 safi_t safi;
8195
8196 if (bgp_parse_safi(argv[0], &safi)) {
8197 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8198 return CMD_WARNING;
8199 }
8200 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8201 bgp_show_type_flap_regexp);
8202}
8203
8204ALIAS (show_bgp_ipv6_safi_flap_regexp,
8205 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8206 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8207 SHOW_STR
8208 BGP_STR
8209 IPV6_STR
8210 "Address Family Modifier\n"
8211 "Address Family Modifier\n"
8212 "Address Family Modifier\n"
8213 "Address Family Modifier\n"
8214 "Display detailed information about dampening\n"
8215 "Display flap statistics of routes\n"
8216 "Display routes matching the AS path regular expression\n"
8217 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008218
8219DEFUN (show_bgp_ipv4_safi_regexp,
8220 show_bgp_ipv4_safi_regexp_cmd,
8221 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8222 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008223 BGP_STR
8224 "Address family\n"
8225 "Address Family modifier\n"
8226 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008227 "Address Family modifier\n"
8228 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008229 "Display routes matching the AS path regular expression\n"
8230 "A regular-expression to match the BGP AS paths\n")
8231{
Lou Berger651b4022016-01-12 13:42:07 -05008232 safi_t safi;
8233 if (bgp_parse_safi(argv[0], &safi)) {
8234 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8235 return CMD_WARNING;
8236 }
paul718e3742002-12-13 20:15:29 +00008237
Lou Berger651b4022016-01-12 13:42:07 -05008238 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008239 bgp_show_type_regexp);
8240}
Lou Berger205e6742016-01-12 13:42:11 -05008241
Lou Berger651b4022016-01-12 13:42:07 -05008242DEFUN (show_bgp_ipv6_safi_regexp,
8243 show_bgp_ipv6_safi_regexp_cmd,
8244 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008245 SHOW_STR
8246 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008247 "Address family\n"
8248 "Address Family modifier\n"
8249 "Address Family modifier\n"
8250 "Address Family modifier\n"
8251 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008252 "Display routes matching the AS path regular expression\n"
8253 "A regular-expression to match the BGP AS paths\n")
8254{
Lou Berger651b4022016-01-12 13:42:07 -05008255 safi_t safi;
8256 if (bgp_parse_safi(argv[0], &safi)) {
8257 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8258 return CMD_WARNING;
8259 }
8260
8261 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008262 bgp_show_type_regexp);
8263}
8264
Lou Berger651b4022016-01-12 13:42:07 -05008265DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008266 show_bgp_ipv6_regexp_cmd,
8267 "show bgp ipv6 regexp .LINE",
8268 SHOW_STR
8269 BGP_STR
8270 "Address family\n"
8271 "Display routes matching the AS path regular expression\n"
8272 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008273{
8274 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8275 bgp_show_type_regexp);
8276}
8277
paul94f2b392005-06-28 12:44:16 +00008278static int
paulfd79ac92004-10-13 05:06:08 +00008279bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008280 safi_t safi, enum bgp_show_type type)
8281{
8282 struct prefix_list *plist;
8283
8284 plist = prefix_list_lookup (afi, prefix_list_str);
8285 if (plist == NULL)
8286 {
8287 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8288 prefix_list_str, VTY_NEWLINE);
8289 return CMD_WARNING;
8290 }
8291
ajs5a646652004-11-05 01:25:55 +00008292 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008293}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008294DEFUN (show_ip_bgp_prefix_list,
8295 show_ip_bgp_prefix_list_cmd,
8296 "show ip bgp prefix-list WORD",
8297 SHOW_STR
8298 IP_STR
8299 BGP_STR
8300 "Display routes conforming to the prefix-list\n"
8301 "IP prefix-list name\n")
8302{
8303 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8304 bgp_show_type_prefix_list);
8305}
8306
8307DEFUN (show_ip_bgp_flap_prefix_list,
8308 show_ip_bgp_flap_prefix_list_cmd,
8309 "show ip bgp flap-statistics prefix-list WORD",
8310 SHOW_STR
8311 IP_STR
8312 BGP_STR
8313 "Display flap statistics of routes\n"
8314 "Display routes conforming to the prefix-list\n"
8315 "IP prefix-list name\n")
8316{
8317 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8318 bgp_show_type_flap_prefix_list);
8319}
8320
8321ALIAS (show_ip_bgp_flap_prefix_list,
8322 show_ip_bgp_damp_flap_prefix_list_cmd,
8323 "show ip bgp dampening flap-statistics prefix-list WORD",
8324 SHOW_STR
8325 IP_STR
8326 BGP_STR
8327 "Display detailed information about dampening\n"
8328 "Display flap statistics of routes\n"
8329 "Display routes conforming to the prefix-list\n"
8330 "IP prefix-list name\n")
8331
8332DEFUN (show_ip_bgp_ipv4_prefix_list,
8333 show_ip_bgp_ipv4_prefix_list_cmd,
8334 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8335 SHOW_STR
8336 IP_STR
8337 BGP_STR
8338 "Address family\n"
8339 "Address Family modifier\n"
8340 "Address Family modifier\n"
8341 "Display routes conforming to the prefix-list\n"
8342 "IP prefix-list name\n")
8343{
8344 if (strncmp (argv[0], "m", 1) == 0)
8345 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8346 bgp_show_type_prefix_list);
8347
8348 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8349 bgp_show_type_prefix_list);
8350}
8351
Lou Bergerf9b6c392016-01-12 13:42:09 -05008352DEFUN (show_bgp_prefix_list,
8353 show_bgp_prefix_list_cmd,
8354 "show bgp prefix-list WORD",
8355 SHOW_STR
8356 BGP_STR
8357 "Display routes conforming to the prefix-list\n"
8358 "IPv6 prefix-list name\n")
8359{
8360 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8361 bgp_show_type_prefix_list);
8362}
8363
8364ALIAS (show_bgp_prefix_list,
8365 show_bgp_ipv6_prefix_list_cmd,
8366 "show bgp ipv6 prefix-list WORD",
8367 SHOW_STR
8368 BGP_STR
8369 "Address family\n"
8370 "Display routes conforming to the prefix-list\n"
8371 "IPv6 prefix-list name\n")
8372
8373/* old command */
8374DEFUN (show_ipv6_bgp_prefix_list,
8375 show_ipv6_bgp_prefix_list_cmd,
8376 "show ipv6 bgp prefix-list WORD",
8377 SHOW_STR
8378 IPV6_STR
8379 BGP_STR
8380 "Display routes matching the prefix-list\n"
8381 "IPv6 prefix-list name\n")
8382{
8383 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8384 bgp_show_type_prefix_list);
8385}
8386
8387/* old command */
8388DEFUN (show_ipv6_mbgp_prefix_list,
8389 show_ipv6_mbgp_prefix_list_cmd,
8390 "show ipv6 mbgp prefix-list WORD",
8391 SHOW_STR
8392 IPV6_STR
8393 MBGP_STR
8394 "Display routes matching the prefix-list\n"
8395 "IPv6 prefix-list name\n")
8396{
8397 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8398 bgp_show_type_prefix_list);
8399}
paul718e3742002-12-13 20:15:29 +00008400
Lou Berger35c36862016-01-12 13:42:06 -05008401DEFUN (show_bgp_ipv4_prefix_list,
8402 show_bgp_ipv4_prefix_list_cmd,
8403 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008404 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008405 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008406 IP_STR
paul718e3742002-12-13 20:15:29 +00008407 "Display routes conforming to the prefix-list\n"
8408 "IP prefix-list name\n")
8409{
8410 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8411 bgp_show_type_prefix_list);
8412}
8413
Lou Berger651b4022016-01-12 13:42:07 -05008414DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8415 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8416 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008417 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008418 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008419 IP_STR
8420 "Address Family Modifier\n"
8421 "Address Family Modifier\n"
8422 "Address Family Modifier\n"
8423 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008424 "Display flap statistics of routes\n"
8425 "Display routes conforming to the prefix-list\n"
8426 "IP prefix-list name\n")
8427{
Lou Berger651b4022016-01-12 13:42:07 -05008428 safi_t safi;
8429 if (bgp_parse_safi(argv[0], &safi)) {
8430 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8431 return CMD_WARNING;
8432 }
8433 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008434 bgp_show_type_flap_prefix_list);
8435}
8436
Lou Berger651b4022016-01-12 13:42:07 -05008437ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8438 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8439 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308440 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308441 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008442 IP_STR
8443 "Address Family Modifier\n"
8444 "Address Family Modifier\n"
8445 "Address Family Modifier\n"
8446 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308447 "Display detailed information about dampening\n"
8448 "Display flap statistics of routes\n"
8449 "Display routes conforming to the prefix-list\n"
8450 "IP prefix-list name\n")
8451
Lou Berger651b4022016-01-12 13:42:07 -05008452DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8453 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8454 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008455 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008456 BGP_STR
8457 IPV6_STR
8458 "Address Family Modifier\n"
8459 "Address Family Modifier\n"
8460 "Address Family Modifier\n"
8461 "Address Family Modifier\n"
8462 "Display flap statistics of routes\n"
8463 "Display routes conforming to the prefix-list\n"
8464 "IP prefix-list name\n")
8465{
8466 safi_t safi;
8467 if (bgp_parse_safi(argv[0], &safi)) {
8468 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8469 return CMD_WARNING;
8470 }
8471 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8472 bgp_show_type_flap_prefix_list);
8473}
8474ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8475 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8476 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8477 SHOW_STR
8478 BGP_STR
8479 IPV6_STR
8480 "Address Family Modifier\n"
8481 "Address Family Modifier\n"
8482 "Address Family Modifier\n"
8483 "Address Family Modifier\n"
8484 "Display detailed information about dampening\n"
8485 "Display flap statistics of routes\n"
8486 "Display routes conforming to the prefix-list\n"
8487 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008488
8489DEFUN (show_bgp_ipv4_safi_prefix_list,
8490 show_bgp_ipv4_safi_prefix_list_cmd,
8491 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8492 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008493 BGP_STR
8494 "Address family\n"
8495 "Address Family modifier\n"
8496 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008497 "Address Family modifier\n"
8498 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008499 "Display routes conforming to the prefix-list\n"
8500 "IP prefix-list name\n")
8501{
Lou Berger651b4022016-01-12 13:42:07 -05008502 safi_t safi;
8503 if (bgp_parse_safi(argv[0], &safi)) {
8504 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8505 return CMD_WARNING;
8506 }
8507 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008508 bgp_show_type_prefix_list);
8509}
Lou Berger205e6742016-01-12 13:42:11 -05008510
Lou Berger651b4022016-01-12 13:42:07 -05008511DEFUN (show_bgp_ipv6_safi_prefix_list,
8512 show_bgp_ipv6_safi_prefix_list_cmd,
8513 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008514 SHOW_STR
8515 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008516 "Address family\n"
8517 "Address Family modifier\n"
8518 "Address Family modifier\n"
8519 "Address Family modifier\n"
8520 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008521 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008522 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008523{
Lou Berger651b4022016-01-12 13:42:07 -05008524 safi_t safi;
8525 if (bgp_parse_safi(argv[0], &safi)) {
8526 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8527 return CMD_WARNING;
8528 }
8529 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008530 bgp_show_type_prefix_list);
8531}
8532
paul94f2b392005-06-28 12:44:16 +00008533static int
paulfd79ac92004-10-13 05:06:08 +00008534bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008535 safi_t safi, enum bgp_show_type type)
8536{
8537 struct as_list *as_list;
8538
8539 as_list = as_list_lookup (filter);
8540 if (as_list == NULL)
8541 {
8542 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8543 return CMD_WARNING;
8544 }
8545
ajs5a646652004-11-05 01:25:55 +00008546 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008547}
8548
Lou Bergerf9b6c392016-01-12 13:42:09 -05008549DEFUN (show_ip_bgp_filter_list,
8550 show_ip_bgp_filter_list_cmd,
8551 "show ip bgp filter-list WORD",
8552 SHOW_STR
8553 IP_STR
8554 BGP_STR
8555 "Display routes conforming to the filter-list\n"
8556 "Regular expression access list name\n")
8557{
8558 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8559 bgp_show_type_filter_list);
8560}
8561
8562DEFUN (show_ip_bgp_flap_filter_list,
8563 show_ip_bgp_flap_filter_list_cmd,
8564 "show ip bgp flap-statistics filter-list WORD",
8565 SHOW_STR
8566 IP_STR
8567 BGP_STR
8568 "Display flap statistics of routes\n"
8569 "Display routes conforming to the filter-list\n"
8570 "Regular expression access list name\n")
8571{
8572 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8573 bgp_show_type_flap_filter_list);
8574}
8575
8576ALIAS (show_ip_bgp_flap_filter_list,
8577 show_ip_bgp_damp_flap_filter_list_cmd,
8578 "show ip bgp dampening flap-statistics filter-list WORD",
8579 SHOW_STR
8580 IP_STR
8581 BGP_STR
8582 "Display detailed information about dampening\n"
8583 "Display flap statistics of routes\n"
8584 "Display routes conforming to the filter-list\n"
8585 "Regular expression access list name\n")
8586
8587DEFUN (show_ip_bgp_ipv4_filter_list,
8588 show_ip_bgp_ipv4_filter_list_cmd,
8589 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8590 SHOW_STR
8591 IP_STR
8592 BGP_STR
8593 "Address family\n"
8594 "Address Family modifier\n"
8595 "Address Family modifier\n"
8596 "Display routes conforming to the filter-list\n"
8597 "Regular expression access list name\n")
8598{
8599 if (strncmp (argv[0], "m", 1) == 0)
8600 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8601 bgp_show_type_filter_list);
8602
8603 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8604 bgp_show_type_filter_list);
8605}
8606
Lou Bergerf9b6c392016-01-12 13:42:09 -05008607DEFUN (show_bgp_filter_list,
8608 show_bgp_filter_list_cmd,
8609 "show bgp filter-list WORD",
8610 SHOW_STR
8611 BGP_STR
8612 "Display routes conforming to the filter-list\n"
8613 "Regular expression access list name\n")
8614{
8615 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8616 bgp_show_type_filter_list);
8617}
8618
8619/* old command */
8620DEFUN (show_ipv6_bgp_filter_list,
8621 show_ipv6_bgp_filter_list_cmd,
8622 "show ipv6 bgp filter-list WORD",
8623 SHOW_STR
8624 IPV6_STR
8625 BGP_STR
8626 "Display routes conforming to the filter-list\n"
8627 "Regular expression access list name\n")
8628{
8629 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8630 bgp_show_type_filter_list);
8631}
8632
8633/* old command */
8634DEFUN (show_ipv6_mbgp_filter_list,
8635 show_ipv6_mbgp_filter_list_cmd,
8636 "show ipv6 mbgp filter-list WORD",
8637 SHOW_STR
8638 IPV6_STR
8639 MBGP_STR
8640 "Display routes conforming to the filter-list\n"
8641 "Regular expression access list name\n")
8642{
8643 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8644 bgp_show_type_filter_list);
8645}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008646
8647DEFUN (show_ip_bgp_dampening_info,
8648 show_ip_bgp_dampening_params_cmd,
8649 "show ip bgp dampening parameters",
8650 SHOW_STR
8651 IP_STR
8652 BGP_STR
8653 "Display detailed information about dampening\n"
8654 "Display detail of configured dampening parameters\n")
8655{
8656 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8657}
8658
Lou Berger651b4022016-01-12 13:42:07 -05008659DEFUN (show_bgp_ipv4_filter_list,
8660 show_bgp_ipv4_filter_list_cmd,
8661 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008662 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008663 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008664 IP_STR
paul718e3742002-12-13 20:15:29 +00008665 "Display routes conforming to the filter-list\n"
8666 "Regular expression access list name\n")
8667{
8668 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8669 bgp_show_type_filter_list);
8670}
8671
Lou Berger651b4022016-01-12 13:42:07 -05008672DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8673 show_bgp_ipv4_safi_flap_filter_list_cmd,
8674 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008675 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008676 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008677 IP_STR
8678 "Address Family modifier\n"
8679 "Address Family modifier\n"
8680 "Address Family modifier\n"
8681 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008682 "Display flap statistics of routes\n"
8683 "Display routes conforming to the filter-list\n"
8684 "Regular expression access list name\n")
8685{
Lou Berger651b4022016-01-12 13:42:07 -05008686 safi_t safi;
8687
8688 if (bgp_parse_safi(argv[0], &safi)) {
8689 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8690 return CMD_WARNING;
8691 }
8692 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008693 bgp_show_type_flap_filter_list);
8694}
8695
Lou Berger651b4022016-01-12 13:42:07 -05008696ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8697 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8698 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308699 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308700 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008701 IP_STR
8702 "Address Family modifier\n"
8703 "Address Family modifier\n"
8704 "Address Family modifier\n"
8705 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308706 "Display detailed information about dampening\n"
8707 "Display flap statistics of routes\n"
8708 "Display routes conforming to the filter-list\n"
8709 "Regular expression access list name\n")
8710
Lou Berger651b4022016-01-12 13:42:07 -05008711DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8712 show_bgp_ipv6_safi_flap_filter_list_cmd,
8713 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008714 SHOW_STR
8715 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008716 IPV6_STR
8717 "Address Family modifier\n"
8718 "Address Family modifier\n"
8719 "Address Family modifier\n"
8720 "Address Family modifier\n"
8721 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008722 "Display routes conforming to the filter-list\n"
8723 "Regular expression access list name\n")
8724{
Lou Berger651b4022016-01-12 13:42:07 -05008725 safi_t safi;
8726
8727 if (bgp_parse_safi(argv[0], &safi)) {
8728 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8729 return CMD_WARNING;
8730 }
8731 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8732 bgp_show_type_flap_filter_list);
8733}
8734ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8735 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8736 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8737 SHOW_STR
8738 BGP_STR
8739 IPV6_STR
8740 "Address Family modifier\n"
8741 "Address Family modifier\n"
8742 "Address Family modifier\n"
8743 "Address Family modifier\n"
8744 "Display detailed information about dampening\n"
8745 "Display flap statistics of routes\n"
8746 "Display routes conforming to the filter-list\n"
8747 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008748
8749DEFUN (show_bgp_ipv4_safi_filter_list,
8750 show_bgp_ipv4_safi_filter_list_cmd,
8751 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8752 SHOW_STR
8753 BGP_STR
8754 "Address Family modifier\n"
8755 "Address Family modifier\n"
8756 "Address Family modifier\n"
8757 "Address Family modifier\n"
8758 "Display routes conforming to the filter-list\n"
8759 "Regular expression access list name\n")
8760{
8761 safi_t safi;
8762
8763 if (bgp_parse_safi(argv[0], &safi)) {
8764 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8765 return CMD_WARNING;
8766 }
8767 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8768 bgp_show_type_filter_list);
8769}
Lou Berger205e6742016-01-12 13:42:11 -05008770
Lou Berger651b4022016-01-12 13:42:07 -05008771DEFUN (show_bgp_ipv6_safi_filter_list,
8772 show_bgp_ipv6_safi_filter_list_cmd,
8773 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8774 SHOW_STR
8775 BGP_STR
8776 "Address Family modifier\n"
8777 "Address Family modifier\n"
8778 "Address Family modifier\n"
8779 "Address Family modifier\n"
8780 "Display routes conforming to the filter-list\n"
8781 "Regular expression access list name\n")
8782{
8783 safi_t safi;
8784
8785 if (bgp_parse_safi(argv[0], &safi)) {
8786 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8787 return CMD_WARNING;
8788 }
8789 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8790 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008791}
8792
Lou Bergerf9b6c392016-01-12 13:42:09 -05008793DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008794 show_bgp_ipv6_filter_list_cmd,
8795 "show bgp ipv6 filter-list WORD",
8796 SHOW_STR
8797 BGP_STR
8798 "Address family\n"
8799 "Display routes conforming to the filter-list\n"
8800 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008801{
8802 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8803 bgp_show_type_filter_list);
8804}
8805
Balaji9c52cae2016-01-20 22:59:26 +05308806
8807DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8808 show_ip_bgp_ipv4_dampening_parameters_cmd,
8809 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8810 SHOW_STR
8811 IP_STR
8812 BGP_STR
8813 "Address family\n"
8814 "Address Family modifier\n"
8815 "Address Family modifier\n"
8816 "Display detailed information about dampening\n"
8817 "Display detail of configured dampening parameters\n")
8818{
8819 if (strncmp(argv[0], "m", 1) == 0)
8820 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8821
8822 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8823}
8824
8825
8826DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8827 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8828 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8829 SHOW_STR
8830 IP_STR
8831 BGP_STR
8832 "Address family\n"
8833 "Address Family modifier\n"
8834 "Address Family modifier\n"
8835 "Display detailed information about dampening\n"
8836 "Display flap statistics of routes\n")
8837{
8838 if (strncmp(argv[0], "m", 1) == 0)
8839 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8840 bgp_show_type_flap_statistics, NULL);
8841
8842 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8843 bgp_show_type_flap_statistics, NULL);
8844}
8845
8846DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8847 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8848 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8849 SHOW_STR
8850 IP_STR
8851 BGP_STR
8852 "Address family\n"
8853 "Address Family modifier\n"
8854 "Address Family modifier\n"
8855 "Display detailed information about dampening\n"
8856 "Display paths suppressed due to dampening\n")
8857{
8858 if (strncmp(argv[0], "m", 1) == 0)
8859 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8860 bgp_show_type_dampend_paths, NULL);
8861
8862 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8863 bgp_show_type_dampend_paths, NULL);
8864}
8865
paul94f2b392005-06-28 12:44:16 +00008866static int
paulfd79ac92004-10-13 05:06:08 +00008867bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008868 safi_t safi, enum bgp_show_type type)
8869{
8870 struct route_map *rmap;
8871
8872 rmap = route_map_lookup_by_name (rmap_str);
8873 if (! rmap)
8874 {
8875 vty_out (vty, "%% %s is not a valid route-map name%s",
8876 rmap_str, VTY_NEWLINE);
8877 return CMD_WARNING;
8878 }
8879
ajs5a646652004-11-05 01:25:55 +00008880 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008881}
8882
Lou Bergerf9b6c392016-01-12 13:42:09 -05008883DEFUN (show_ip_bgp_route_map,
8884 show_ip_bgp_route_map_cmd,
8885 "show ip bgp route-map WORD",
8886 SHOW_STR
8887 IP_STR
8888 BGP_STR
8889 "Display routes matching the route-map\n"
8890 "A route-map to match on\n")
8891{
8892 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8893 bgp_show_type_route_map);
8894}
8895
8896DEFUN (show_ip_bgp_flap_route_map,
8897 show_ip_bgp_flap_route_map_cmd,
8898 "show ip bgp flap-statistics route-map WORD",
8899 SHOW_STR
8900 IP_STR
8901 BGP_STR
8902 "Display flap statistics of routes\n"
8903 "Display routes matching the route-map\n"
8904 "A route-map to match on\n")
8905{
8906 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8907 bgp_show_type_flap_route_map);
8908}
8909
8910ALIAS (show_ip_bgp_flap_route_map,
8911 show_ip_bgp_damp_flap_route_map_cmd,
8912 "show ip bgp dampening flap-statistics route-map WORD",
8913 SHOW_STR
8914 IP_STR
8915 BGP_STR
8916 "Display detailed information about dampening\n"
8917 "Display flap statistics of routes\n"
8918 "Display routes matching the route-map\n"
8919 "A route-map to match on\n")
8920
8921DEFUN (show_ip_bgp_ipv4_route_map,
8922 show_ip_bgp_ipv4_route_map_cmd,
8923 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8924 SHOW_STR
8925 IP_STR
8926 BGP_STR
8927 "Address family\n"
8928 "Address Family modifier\n"
8929 "Address Family modifier\n"
8930 "Display routes matching the route-map\n"
8931 "A route-map to match on\n")
8932{
8933 if (strncmp (argv[0], "m", 1) == 0)
8934 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8935 bgp_show_type_route_map);
8936
8937 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8938 bgp_show_type_route_map);
8939}
8940
8941DEFUN (show_bgp_route_map,
8942 show_bgp_route_map_cmd,
8943 "show bgp route-map WORD",
8944 SHOW_STR
8945 BGP_STR
8946 "Display routes matching the route-map\n"
8947 "A route-map to match on\n")
8948{
8949 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8950 bgp_show_type_route_map);
8951}
8952
8953DEFUN (show_ip_bgp_cidr_only,
8954 show_ip_bgp_cidr_only_cmd,
8955 "show ip bgp cidr-only",
8956 SHOW_STR
8957 IP_STR
8958 BGP_STR
8959 "Display only routes with non-natural netmasks\n")
8960{
8961 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8962 bgp_show_type_cidr_only, NULL);
8963}
8964
8965DEFUN (show_ip_bgp_flap_cidr_only,
8966 show_ip_bgp_flap_cidr_only_cmd,
8967 "show ip bgp flap-statistics cidr-only",
8968 SHOW_STR
8969 IP_STR
8970 BGP_STR
8971 "Display flap statistics of routes\n"
8972 "Display only routes with non-natural netmasks\n")
8973{
8974 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8975 bgp_show_type_flap_cidr_only, NULL);
8976}
8977
8978ALIAS (show_ip_bgp_flap_cidr_only,
8979 show_ip_bgp_damp_flap_cidr_only_cmd,
8980 "show ip bgp dampening flap-statistics cidr-only",
8981 SHOW_STR
8982 IP_STR
8983 BGP_STR
8984 "Display detailed information about dampening\n"
8985 "Display flap statistics of routes\n"
8986 "Display only routes with non-natural netmasks\n")
8987
8988DEFUN (show_ip_bgp_ipv4_cidr_only,
8989 show_ip_bgp_ipv4_cidr_only_cmd,
8990 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8991 SHOW_STR
8992 IP_STR
8993 BGP_STR
8994 "Address family\n"
8995 "Address Family modifier\n"
8996 "Address Family modifier\n"
8997 "Display only routes with non-natural netmasks\n")
8998{
8999 if (strncmp (argv[0], "m", 1) == 0)
9000 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9001 bgp_show_type_cidr_only, NULL);
9002
9003 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9004 bgp_show_type_cidr_only, NULL);
9005}
9006
9007DEFUN (show_ip_bgp_community_all,
9008 show_ip_bgp_community_all_cmd,
9009 "show ip bgp community",
9010 SHOW_STR
9011 IP_STR
9012 BGP_STR
9013 "Display routes matching the communities\n")
9014{
9015 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9016 bgp_show_type_community_all, NULL);
9017}
9018
9019DEFUN (show_ip_bgp_ipv4_community_all,
9020 show_ip_bgp_ipv4_community_all_cmd,
9021 "show ip bgp ipv4 (unicast|multicast) community",
9022 SHOW_STR
9023 IP_STR
9024 BGP_STR
9025 "Address family\n"
9026 "Address Family modifier\n"
9027 "Address Family modifier\n"
9028 "Display routes matching the communities\n")
9029{
9030 if (strncmp (argv[0], "m", 1) == 0)
9031 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9032 bgp_show_type_community_all, NULL);
9033
9034 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9035 bgp_show_type_community_all, NULL);
9036}
9037
Lou Bergerf9b6c392016-01-12 13:42:09 -05009038DEFUN (show_bgp_community_all,
9039 show_bgp_community_all_cmd,
9040 "show bgp community",
9041 SHOW_STR
9042 BGP_STR
9043 "Display routes matching the communities\n")
9044{
9045 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9046 bgp_show_type_community_all, NULL);
9047}
9048
9049ALIAS (show_bgp_community_all,
9050 show_bgp_ipv6_community_all_cmd,
9051 "show bgp ipv6 community",
9052 SHOW_STR
9053 BGP_STR
9054 "Address family\n"
9055 "Display routes matching the communities\n")
9056
9057/* old command */
9058DEFUN (show_ipv6_bgp_community_all,
9059 show_ipv6_bgp_community_all_cmd,
9060 "show ipv6 bgp community",
9061 SHOW_STR
9062 IPV6_STR
9063 BGP_STR
9064 "Display routes matching the communities\n")
9065{
9066 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9067 bgp_show_type_community_all, NULL);
9068}
9069
9070/* old command */
9071DEFUN (show_ipv6_mbgp_community_all,
9072 show_ipv6_mbgp_community_all_cmd,
9073 "show ipv6 mbgp community",
9074 SHOW_STR
9075 IPV6_STR
9076 MBGP_STR
9077 "Display routes matching the communities\n")
9078{
9079 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9080 bgp_show_type_community_all, NULL);
9081}
Lou Bergerf9b6c392016-01-12 13:42:09 -05009082
Lou Berger651b4022016-01-12 13:42:07 -05009083DEFUN (show_bgp_ipv4_route_map,
9084 show_bgp_ipv4_route_map_cmd,
9085 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00009086 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009087 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009088 IP_STR
paul718e3742002-12-13 20:15:29 +00009089 "Display routes matching the route-map\n"
9090 "A route-map to match on\n")
9091{
9092 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9093 bgp_show_type_route_map);
9094}
9095
Lou Berger651b4022016-01-12 13:42:07 -05009096DEFUN (show_bgp_ipv4_safi_flap_route_map,
9097 show_bgp_ipv4_safi_flap_route_map_cmd,
9098 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009099 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009100 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009101 IP_STR
9102 "Address Family Modifier\n"
9103 "Address Family Modifier\n"
9104 "Address Family Modifier\n"
9105 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009106 "Display flap statistics of routes\n"
9107 "Display routes matching the route-map\n"
9108 "A route-map to match on\n")
9109{
Lou Berger651b4022016-01-12 13:42:07 -05009110 safi_t safi;
9111 if (bgp_parse_safi(argv[0], &safi)) {
9112 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9113 return CMD_WARNING;
9114 }
9115 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009116 bgp_show_type_flap_route_map);
9117}
9118
Lou Berger651b4022016-01-12 13:42:07 -05009119ALIAS (show_bgp_ipv4_safi_flap_route_map,
9120 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9121 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05309122 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309123 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009124 IP_STR
9125 "Address Family Modifier\n"
9126 "Address Family Modifier\n"
9127 "Address Family Modifier\n"
9128 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309129 "Display detailed information about dampening\n"
9130 "Display flap statistics of routes\n"
9131 "Display routes matching the route-map\n"
9132 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05009133
Lou Berger651b4022016-01-12 13:42:07 -05009134DEFUN (show_bgp_ipv6_safi_flap_route_map,
9135 show_bgp_ipv6_safi_flap_route_map_cmd,
9136 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009137 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05009138 BGP_STR
9139 IPV6_STR
9140 "Address Family Modifier\n"
9141 "Address Family Modifier\n"
9142 "Address Family Modifier\n"
9143 "Address Family Modifier\n"
9144 "Display flap statistics of routes\n"
9145 "Display routes matching the route-map\n"
9146 "A route-map to match on\n")
9147{
9148 safi_t safi;
9149 if (bgp_parse_safi(argv[0], &safi)) {
9150 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9151 return CMD_WARNING;
9152 }
9153 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9154 bgp_show_type_flap_route_map);
9155}
9156ALIAS (show_bgp_ipv6_safi_flap_route_map,
9157 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9158 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9159 SHOW_STR
9160 BGP_STR
9161 IPV6_STR
9162 "Address Family Modifier\n"
9163 "Address Family Modifier\n"
9164 "Address Family Modifier\n"
9165 "Address Family Modifier\n"
9166 "Display detailed information about dampening\n"
9167 "Display flap statistics of routes\n"
9168 "Display routes matching the route-map\n"
9169 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009170
9171DEFUN (show_bgp_ipv4_safi_route_map,
9172 show_bgp_ipv4_safi_route_map_cmd,
9173 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9174 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009175 BGP_STR
9176 "Address family\n"
9177 "Address Family modifier\n"
9178 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009179 "Address Family modifier\n"
9180 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009181 "Display routes matching the route-map\n"
9182 "A route-map to match on\n")
9183{
Lou Berger651b4022016-01-12 13:42:07 -05009184 safi_t safi;
9185 if (bgp_parse_safi(argv[0], &safi)) {
9186 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9187 return CMD_WARNING;
9188 }
9189 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009190 bgp_show_type_route_map);
9191}
Lou Berger205e6742016-01-12 13:42:11 -05009192
Lou Berger651b4022016-01-12 13:42:07 -05009193DEFUN (show_bgp_ipv6_safi_route_map,
9194 show_bgp_ipv6_safi_route_map_cmd,
9195 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009196 SHOW_STR
9197 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009198 "Address family\n"
9199 "Address Family modifier\n"
9200 "Address Family modifier\n"
9201 "Address Family modifier\n"
9202 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009203 "Display routes matching the route-map\n"
9204 "A route-map to match on\n")
9205{
Lou Berger651b4022016-01-12 13:42:07 -05009206 safi_t safi;
9207 if (bgp_parse_safi(argv[0], &safi)) {
9208 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9209 return CMD_WARNING;
9210 }
9211 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009212 bgp_show_type_route_map);
9213}
9214
Lou Berger651b4022016-01-12 13:42:07 -05009215DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009216 show_bgp_ipv6_route_map_cmd,
9217 "show bgp ipv6 route-map WORD",
9218 SHOW_STR
9219 BGP_STR
9220 "Address family\n"
9221 "Display routes matching the route-map\n"
9222 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009223{
9224 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9225 bgp_show_type_route_map);
9226}
David Lamparter6b0655a2014-06-04 06:53:35 +02009227
Lou Berger651b4022016-01-12 13:42:07 -05009228DEFUN (show_bgp_ipv4_cidr_only,
9229 show_bgp_ipv4_cidr_only_cmd,
9230 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009231 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009232 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009233 IP_STR
paul718e3742002-12-13 20:15:29 +00009234 "Display only routes with non-natural netmasks\n")
9235{
9236 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009237 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009238}
9239
Lou Berger651b4022016-01-12 13:42:07 -05009240DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9241 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9242 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009243 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009244 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009245 "Address Family\n"
9246 "Address Family Modifier\n"
9247 "Address Family Modifier\n"
9248 "Address Family Modifier\n"
9249 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009250 "Display flap statistics of routes\n"
9251 "Display only routes with non-natural netmasks\n")
9252{
Lou Berger651b4022016-01-12 13:42:07 -05009253 safi_t safi;
9254
9255 if (bgp_parse_safi(argv[0], &safi)) {
9256 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009260}
9261
Lou Berger651b4022016-01-12 13:42:07 -05009262ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9263 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9264 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309265 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309266 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009267 "Address Family\n"
9268 "Address Family Modifier\n"
9269 "Address Family Modifier\n"
9270 "Address Family Modifier\n"
9271 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309272 "Display detailed information about dampening\n"
9273 "Display flap statistics of routes\n"
9274 "Display only routes with non-natural netmasks\n")
9275
Lou Berger651b4022016-01-12 13:42:07 -05009276DEFUN (show_bgp_ipv4_safi_cidr_only,
9277 show_bgp_ipv4_safi_cidr_only_cmd,
9278 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009279 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009280 BGP_STR
9281 "Address family\n"
9282 "Address Family modifier\n"
9283 "Address Family modifier\n"
9284 "Display only routes with non-natural netmasks\n")
9285{
9286 if (strncmp (argv[0], "m", 1) == 0)
9287 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009288 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009289
9290 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009291 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009292}
David Lamparter6b0655a2014-06-04 06:53:35 +02009293
Lou Berger651b4022016-01-12 13:42:07 -05009294/* new046 */
9295DEFUN (show_bgp_afi_safi_community_all,
9296 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009297 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009298 SHOW_STR
9299 BGP_STR
9300 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009301 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009302 "Address Family modifier\n"
9303 "Address Family modifier\n"
9304 "Address Family modifier\n"
9305 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009306 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009307{
9308 safi_t safi;
9309 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009310
Lou Berger651b4022016-01-12 13:42:07 -05009311 if (bgp_parse_afi(argv[0], &afi)) {
9312 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9313 return CMD_WARNING;
9314 }
9315 if (bgp_parse_safi(argv[1], &safi)) {
9316 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9317 return CMD_WARNING;
9318 }
9319
9320 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9321}
9322DEFUN (show_bgp_afi_community_all,
9323 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009324 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009325 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009326 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009327 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009328 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009329 "Display routes matching the communities\n")
9330{
Lou Berger651b4022016-01-12 13:42:07 -05009331 afi_t afi;
9332 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009333
Lou Berger651b4022016-01-12 13:42:07 -05009334 if (bgp_parse_afi(argv[0], &afi)) {
9335 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9336 return CMD_WARNING;
9337 }
9338 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009339}
David Lamparter6b0655a2014-06-04 06:53:35 +02009340
paul94f2b392005-06-28 12:44:16 +00009341static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009342bgp_show_community (struct vty *vty, const char *view_name, int argc,
9343 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009344{
9345 struct community *com;
9346 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009347 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009348 int i;
9349 char *str;
9350 int first = 0;
9351
Michael Lambert95cbbd22010-07-23 14:43:04 -04009352 /* BGP structure lookup */
9353 if (view_name)
9354 {
9355 bgp = bgp_lookup_by_name (view_name);
9356 if (bgp == NULL)
9357 {
9358 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9359 return CMD_WARNING;
9360 }
9361 }
9362 else
9363 {
9364 bgp = bgp_get_default ();
9365 if (bgp == NULL)
9366 {
9367 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9368 return CMD_WARNING;
9369 }
9370 }
9371
paul718e3742002-12-13 20:15:29 +00009372 b = buffer_new (1024);
9373 for (i = 0; i < argc; i++)
9374 {
9375 if (first)
9376 buffer_putc (b, ' ');
9377 else
9378 {
9379 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9380 continue;
9381 first = 1;
9382 }
9383
9384 buffer_putstr (b, argv[i]);
9385 }
9386 buffer_putc (b, '\0');
9387
9388 str = buffer_getstr (b);
9389 buffer_free (b);
9390
9391 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009392 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009393 if (! com)
9394 {
9395 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9396 return CMD_WARNING;
9397 }
9398
Michael Lambert95cbbd22010-07-23 14:43:04 -04009399 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009400 (exact ? bgp_show_type_community_exact :
9401 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009402}
9403
Lou Bergerf9b6c392016-01-12 13:42:09 -05009404DEFUN (show_ip_bgp_community,
9405 show_ip_bgp_community_cmd,
9406 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9407 SHOW_STR
9408 IP_STR
9409 BGP_STR
9410 "Display routes matching the communities\n"
9411 "community number\n"
9412 "Do not send outside local AS (well-known community)\n"
9413 "Do not advertise to any peer (well-known community)\n"
9414 "Do not export to next AS (well-known community)\n")
9415{
9416 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9417}
9418
9419ALIAS (show_ip_bgp_community,
9420 show_ip_bgp_community2_cmd,
9421 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9422 SHOW_STR
9423 IP_STR
9424 BGP_STR
9425 "Display routes matching the communities\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
9435ALIAS (show_ip_bgp_community,
9436 show_ip_bgp_community3_cmd,
9437 "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)",
9438 SHOW_STR
9439 IP_STR
9440 BGP_STR
9441 "Display routes matching the communities\n"
9442 "community number\n"
9443 "Do not send outside local AS (well-known community)\n"
9444 "Do not advertise to any peer (well-known community)\n"
9445 "Do not export to next AS (well-known community)\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 "community number\n"
9451 "Do not send outside local AS (well-known community)\n"
9452 "Do not advertise to any peer (well-known community)\n"
9453 "Do not export to next AS (well-known community)\n")
9454
9455ALIAS (show_ip_bgp_community,
9456 show_ip_bgp_community4_cmd,
9457 "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)",
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 "community number\n"
9471 "Do not send outside local AS (well-known community)\n"
9472 "Do not advertise to any peer (well-known community)\n"
9473 "Do not export to next AS (well-known community)\n"
9474 "community number\n"
9475 "Do not send outside local AS (well-known community)\n"
9476 "Do not advertise to any peer (well-known community)\n"
9477 "Do not export to next AS (well-known community)\n")
9478
9479DEFUN (show_ip_bgp_ipv4_community,
9480 show_ip_bgp_ipv4_community_cmd,
9481 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9482 SHOW_STR
9483 IP_STR
9484 BGP_STR
9485 "Address family\n"
9486 "Address Family modifier\n"
9487 "Address Family modifier\n"
9488 "Display routes matching the communities\n"
9489 "community number\n"
9490 "Do not send outside local AS (well-known community)\n"
9491 "Do not advertise to any peer (well-known community)\n"
9492 "Do not export to next AS (well-known community)\n")
9493{
9494 if (strncmp (argv[0], "m", 1) == 0)
9495 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9496
9497 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9498}
9499
9500ALIAS (show_ip_bgp_ipv4_community,
9501 show_ip_bgp_ipv4_community2_cmd,
9502 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9503 SHOW_STR
9504 IP_STR
9505 BGP_STR
9506 "Address family\n"
9507 "Address Family modifier\n"
9508 "Address Family modifier\n"
9509 "Display routes matching the communities\n"
9510 "community number\n"
9511 "Do not send outside local AS (well-known community)\n"
9512 "Do not advertise to any peer (well-known community)\n"
9513 "Do not export to next AS (well-known community)\n"
9514 "community number\n"
9515 "Do not send outside local AS (well-known community)\n"
9516 "Do not advertise to any peer (well-known community)\n"
9517 "Do not export to next AS (well-known community)\n")
9518
9519ALIAS (show_ip_bgp_ipv4_community,
9520 show_ip_bgp_ipv4_community3_cmd,
9521 "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)",
9522 SHOW_STR
9523 IP_STR
9524 BGP_STR
9525 "Address family\n"
9526 "Address Family modifier\n"
9527 "Address Family modifier\n"
9528 "Display routes matching the communities\n"
9529 "community number\n"
9530 "Do not send outside local AS (well-known community)\n"
9531 "Do not advertise to any peer (well-known community)\n"
9532 "Do not export to next AS (well-known community)\n"
9533 "community number\n"
9534 "Do not send outside local AS (well-known community)\n"
9535 "Do not advertise to any peer (well-known community)\n"
9536 "Do not export to next AS (well-known community)\n"
9537 "community number\n"
9538 "Do not send outside local AS (well-known community)\n"
9539 "Do not advertise to any peer (well-known community)\n"
9540 "Do not export to next AS (well-known community)\n")
9541
9542ALIAS (show_ip_bgp_ipv4_community,
9543 show_ip_bgp_ipv4_community4_cmd,
9544 "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)",
9545 SHOW_STR
9546 IP_STR
9547 BGP_STR
9548 "Address family\n"
9549 "Address Family modifier\n"
9550 "Address Family modifier\n"
9551 "Display routes matching the communities\n"
9552 "community number\n"
9553 "Do not send outside local AS (well-known community)\n"
9554 "Do not advertise to any peer (well-known community)\n"
9555 "Do not export to next AS (well-known community)\n"
9556 "community number\n"
9557 "Do not send outside local AS (well-known community)\n"
9558 "Do not advertise to any peer (well-known community)\n"
9559 "Do not export to next AS (well-known community)\n"
9560 "community number\n"
9561 "Do not send outside local AS (well-known community)\n"
9562 "Do not advertise to any peer (well-known community)\n"
9563 "Do not export to next AS (well-known community)\n"
9564 "community number\n"
9565 "Do not send outside local AS (well-known community)\n"
9566 "Do not advertise to any peer (well-known community)\n"
9567 "Do not export to next AS (well-known community)\n")
9568
9569DEFUN (show_ip_bgp_community_exact,
9570 show_ip_bgp_community_exact_cmd,
9571 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9572 SHOW_STR
9573 IP_STR
9574 BGP_STR
9575 "Display routes matching the communities\n"
9576 "community number\n"
9577 "Do not send outside local AS (well-known community)\n"
9578 "Do not advertise to any peer (well-known community)\n"
9579 "Do not export to next AS (well-known community)\n"
9580 "Exact match of the communities")
9581{
9582 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9583}
9584
9585ALIAS (show_ip_bgp_community_exact,
9586 show_ip_bgp_community2_exact_cmd,
9587 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9588 SHOW_STR
9589 IP_STR
9590 BGP_STR
9591 "Display routes matching the communities\n"
9592 "community number\n"
9593 "Do not send outside local AS (well-known community)\n"
9594 "Do not advertise to any peer (well-known community)\n"
9595 "Do not export to next AS (well-known community)\n"
9596 "community number\n"
9597 "Do not send outside local AS (well-known community)\n"
9598 "Do not advertise to any peer (well-known community)\n"
9599 "Do not export to next AS (well-known community)\n"
9600 "Exact match of the communities")
9601
9602ALIAS (show_ip_bgp_community_exact,
9603 show_ip_bgp_community3_exact_cmd,
9604 "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",
9605 SHOW_STR
9606 IP_STR
9607 BGP_STR
9608 "Display routes matching the communities\n"
9609 "community number\n"
9610 "Do not send outside local AS (well-known community)\n"
9611 "Do not advertise to any peer (well-known community)\n"
9612 "Do not export to next AS (well-known community)\n"
9613 "community number\n"
9614 "Do not send outside local AS (well-known community)\n"
9615 "Do not advertise to any peer (well-known community)\n"
9616 "Do not export to next AS (well-known community)\n"
9617 "community number\n"
9618 "Do not send outside local AS (well-known community)\n"
9619 "Do not advertise to any peer (well-known community)\n"
9620 "Do not export to next AS (well-known community)\n"
9621 "Exact match of the communities")
9622
9623ALIAS (show_ip_bgp_community_exact,
9624 show_ip_bgp_community4_exact_cmd,
9625 "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",
9626 SHOW_STR
9627 IP_STR
9628 BGP_STR
9629 "Display routes matching the communities\n"
9630 "community number\n"
9631 "Do not send outside local AS (well-known community)\n"
9632 "Do not advertise to any peer (well-known community)\n"
9633 "Do not export to next AS (well-known community)\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 "community number\n"
9639 "Do not send outside local AS (well-known community)\n"
9640 "Do not advertise to any peer (well-known community)\n"
9641 "Do not export to next AS (well-known community)\n"
9642 "community number\n"
9643 "Do not send outside local AS (well-known community)\n"
9644 "Do not advertise to any peer (well-known community)\n"
9645 "Do not export to next AS (well-known community)\n"
9646 "Exact match of the communities")
9647
9648DEFUN (show_ip_bgp_ipv4_community_exact,
9649 show_ip_bgp_ipv4_community_exact_cmd,
9650 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9651 SHOW_STR
9652 IP_STR
9653 BGP_STR
9654 "Address family\n"
9655 "Address Family modifier\n"
9656 "Address Family modifier\n"
9657 "Display routes matching the communities\n"
9658 "community number\n"
9659 "Do not send outside local AS (well-known community)\n"
9660 "Do not advertise to any peer (well-known community)\n"
9661 "Do not export to next AS (well-known community)\n"
9662 "Exact match of the communities")
9663{
9664 if (strncmp (argv[0], "m", 1) == 0)
9665 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9666
9667 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9668}
9669
9670ALIAS (show_ip_bgp_ipv4_community_exact,
9671 show_ip_bgp_ipv4_community2_exact_cmd,
9672 "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",
9673 SHOW_STR
9674 IP_STR
9675 BGP_STR
9676 "Address family\n"
9677 "Address Family modifier\n"
9678 "Address Family modifier\n"
9679 "Display routes matching the communities\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 "Exact match of the communities")
9689
9690ALIAS (show_ip_bgp_ipv4_community_exact,
9691 show_ip_bgp_ipv4_community3_exact_cmd,
9692 "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",
9693 SHOW_STR
9694 IP_STR
9695 BGP_STR
9696 "Address family\n"
9697 "Address Family modifier\n"
9698 "Address Family modifier\n"
9699 "Display routes matching the communities\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 "community number\n"
9709 "Do not send outside local AS (well-known community)\n"
9710 "Do not advertise to any peer (well-known community)\n"
9711 "Do not export to next AS (well-known community)\n"
9712 "Exact match of the communities")
9713
9714ALIAS (show_ip_bgp_ipv4_community_exact,
9715 show_ip_bgp_ipv4_community4_exact_cmd,
9716 "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",
9717 SHOW_STR
9718 IP_STR
9719 BGP_STR
9720 "Address family\n"
9721 "Address Family modifier\n"
9722 "Address Family modifier\n"
9723 "Display routes matching the communities\n"
9724 "community number\n"
9725 "Do not send outside local AS (well-known community)\n"
9726 "Do not advertise to any peer (well-known community)\n"
9727 "Do not export to next AS (well-known community)\n"
9728 "community number\n"
9729 "Do not send outside local AS (well-known community)\n"
9730 "Do not advertise to any peer (well-known community)\n"
9731 "Do not export to next AS (well-known community)\n"
9732 "community number\n"
9733 "Do not send outside local AS (well-known community)\n"
9734 "Do not advertise to any peer (well-known community)\n"
9735 "Do not export to next AS (well-known community)\n"
9736 "community number\n"
9737 "Do not send outside local AS (well-known community)\n"
9738 "Do not advertise to any peer (well-known community)\n"
9739 "Do not export to next AS (well-known community)\n"
9740 "Exact match of the communities")
9741
Lou Bergerf9b6c392016-01-12 13:42:09 -05009742DEFUN (show_bgp_community,
9743 show_bgp_community_cmd,
9744 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9745 SHOW_STR
9746 BGP_STR
9747 "Display routes matching the communities\n"
9748 "community number\n"
9749 "Do not send outside local AS (well-known community)\n"
9750 "Do not advertise to any peer (well-known community)\n"
9751 "Do not export to next AS (well-known community)\n")
9752{
9753 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9754}
9755
9756ALIAS (show_bgp_community,
9757 show_bgp_ipv6_community_cmd,
9758 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9759 SHOW_STR
9760 BGP_STR
9761 "Address family\n"
9762 "Display routes matching the communities\n"
9763 "community number\n"
9764 "Do not send outside local AS (well-known community)\n"
9765 "Do not advertise to any peer (well-known community)\n"
9766 "Do not export to next AS (well-known community)\n")
9767
9768ALIAS (show_bgp_community,
9769 show_bgp_community2_cmd,
9770 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9771 SHOW_STR
9772 BGP_STR
9773 "Display routes matching the communities\n"
9774 "community number\n"
9775 "Do not send outside local AS (well-known community)\n"
9776 "Do not advertise to any peer (well-known community)\n"
9777 "Do not export to next AS (well-known community)\n"
9778 "community number\n"
9779 "Do not send outside local AS (well-known community)\n"
9780 "Do not advertise to any peer (well-known community)\n"
9781 "Do not export to next AS (well-known community)\n")
9782
9783ALIAS (show_bgp_community,
9784 show_bgp_ipv6_community2_cmd,
9785 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9786 SHOW_STR
9787 BGP_STR
9788 "Address family\n"
9789 "Display routes matching the communities\n"
9790 "community number\n"
9791 "Do not send outside local AS (well-known community)\n"
9792 "Do not advertise to any peer (well-known community)\n"
9793 "Do not export to next AS (well-known community)\n"
9794 "community number\n"
9795 "Do not send outside local AS (well-known community)\n"
9796 "Do not advertise to any peer (well-known community)\n"
9797 "Do not export to next AS (well-known community)\n")
9798
9799ALIAS (show_bgp_community,
9800 show_bgp_community3_cmd,
9801 "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)",
9802 SHOW_STR
9803 BGP_STR
9804 "Display routes matching the communities\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 "community number\n"
9810 "Do not send outside local AS (well-known community)\n"
9811 "Do not advertise to any peer (well-known community)\n"
9812 "Do not export to next AS (well-known community)\n"
9813 "community number\n"
9814 "Do not send outside local AS (well-known community)\n"
9815 "Do not advertise to any peer (well-known community)\n"
9816 "Do not export to next AS (well-known community)\n")
9817
9818ALIAS (show_bgp_community,
9819 show_bgp_ipv6_community3_cmd,
9820 "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)",
9821 SHOW_STR
9822 BGP_STR
9823 "Address family\n"
9824 "Display routes matching the communities\n"
9825 "community number\n"
9826 "Do not send outside local AS (well-known community)\n"
9827 "Do not advertise to any peer (well-known community)\n"
9828 "Do not export to next AS (well-known community)\n"
9829 "community number\n"
9830 "Do not send outside local AS (well-known community)\n"
9831 "Do not advertise to any peer (well-known community)\n"
9832 "Do not export to next AS (well-known community)\n"
9833 "community number\n"
9834 "Do not send outside local AS (well-known community)\n"
9835 "Do not advertise to any peer (well-known community)\n"
9836 "Do not export to next AS (well-known community)\n")
9837
9838ALIAS (show_bgp_community,
9839 show_bgp_community4_cmd,
9840 "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)",
9841 SHOW_STR
9842 BGP_STR
9843 "Display routes matching the communities\n"
9844 "community number\n"
9845 "Do not send outside local AS (well-known community)\n"
9846 "Do not advertise to any peer (well-known community)\n"
9847 "Do not export to next AS (well-known community)\n"
9848 "community number\n"
9849 "Do not send outside local AS (well-known community)\n"
9850 "Do not advertise to any peer (well-known community)\n"
9851 "Do not export to next AS (well-known community)\n"
9852 "community number\n"
9853 "Do not send outside local AS (well-known community)\n"
9854 "Do not advertise to any peer (well-known community)\n"
9855 "Do not export to next AS (well-known community)\n"
9856 "community number\n"
9857 "Do not send outside local AS (well-known community)\n"
9858 "Do not advertise to any peer (well-known community)\n"
9859 "Do not export to next AS (well-known community)\n")
9860
9861ALIAS (show_bgp_community,
9862 show_bgp_ipv6_community4_cmd,
9863 "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)",
9864 SHOW_STR
9865 BGP_STR
9866 "Address family\n"
9867 "Display routes matching the communities\n"
9868 "community number\n"
9869 "Do not send outside local AS (well-known community)\n"
9870 "Do not advertise to any peer (well-known community)\n"
9871 "Do not export to next AS (well-known community)\n"
9872 "community number\n"
9873 "Do not send outside local AS (well-known community)\n"
9874 "Do not advertise to any peer (well-known community)\n"
9875 "Do not export to next AS (well-known community)\n"
9876 "community number\n"
9877 "Do not send outside local AS (well-known community)\n"
9878 "Do not advertise to any peer (well-known community)\n"
9879 "Do not export to next AS (well-known community)\n"
9880 "community number\n"
9881 "Do not send outside local AS (well-known community)\n"
9882 "Do not advertise to any peer (well-known community)\n"
9883 "Do not export to next AS (well-known community)\n")
9884
9885/* old command */
9886DEFUN (show_ipv6_bgp_community,
9887 show_ipv6_bgp_community_cmd,
9888 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9889 SHOW_STR
9890 IPV6_STR
9891 BGP_STR
9892 "Display routes matching the communities\n"
9893 "community number\n"
9894 "Do not send outside local AS (well-known community)\n"
9895 "Do not advertise to any peer (well-known community)\n"
9896 "Do not export to next AS (well-known community)\n")
9897{
9898 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9899}
9900
9901/* old command */
9902ALIAS (show_ipv6_bgp_community,
9903 show_ipv6_bgp_community2_cmd,
9904 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9905 SHOW_STR
9906 IPV6_STR
9907 BGP_STR
9908 "Display routes matching the communities\n"
9909 "community number\n"
9910 "Do not send outside local AS (well-known community)\n"
9911 "Do not advertise to any peer (well-known community)\n"
9912 "Do not export to next AS (well-known community)\n"
9913 "community number\n"
9914 "Do not send outside local AS (well-known community)\n"
9915 "Do not advertise to any peer (well-known community)\n"
9916 "Do not export to next AS (well-known community)\n")
9917
9918/* old command */
9919ALIAS (show_ipv6_bgp_community,
9920 show_ipv6_bgp_community3_cmd,
9921 "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)",
9922 SHOW_STR
9923 IPV6_STR
9924 BGP_STR
9925 "Display routes matching the communities\n"
9926 "community number\n"
9927 "Do not send outside local AS (well-known community)\n"
9928 "Do not advertise to any peer (well-known community)\n"
9929 "Do not export to next AS (well-known community)\n"
9930 "community number\n"
9931 "Do not send outside local AS (well-known community)\n"
9932 "Do not advertise to any peer (well-known community)\n"
9933 "Do not export to next AS (well-known community)\n"
9934 "community number\n"
9935 "Do not send outside local AS (well-known community)\n"
9936 "Do not advertise to any peer (well-known community)\n"
9937 "Do not export to next AS (well-known community)\n")
9938
9939/* old command */
9940ALIAS (show_ipv6_bgp_community,
9941 show_ipv6_bgp_community4_cmd,
9942 "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)",
9943 SHOW_STR
9944 IPV6_STR
9945 BGP_STR
9946 "Display routes matching the communities\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 "community number\n"
9960 "Do not send outside local AS (well-known community)\n"
9961 "Do not advertise to any peer (well-known community)\n"
9962 "Do not export to next AS (well-known community)\n")
9963
9964DEFUN (show_bgp_community_exact,
9965 show_bgp_community_exact_cmd,
9966 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9967 SHOW_STR
9968 BGP_STR
9969 "Display routes matching the communities\n"
9970 "community number\n"
9971 "Do not send outside local AS (well-known community)\n"
9972 "Do not advertise to any peer (well-known community)\n"
9973 "Do not export to next AS (well-known community)\n"
9974 "Exact match of the communities")
9975{
9976 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9977}
9978
9979ALIAS (show_bgp_community_exact,
9980 show_bgp_ipv6_community_exact_cmd,
9981 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9982 SHOW_STR
9983 BGP_STR
9984 "Address family\n"
9985 "Display routes matching the communities\n"
9986 "community number\n"
9987 "Do not send outside local AS (well-known community)\n"
9988 "Do not advertise to any peer (well-known community)\n"
9989 "Do not export to next AS (well-known community)\n"
9990 "Exact match of the communities")
9991
9992ALIAS (show_bgp_community_exact,
9993 show_bgp_community2_exact_cmd,
9994 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9995 SHOW_STR
9996 BGP_STR
9997 "Display routes matching the communities\n"
9998 "community number\n"
9999 "Do not send outside local AS (well-known community)\n"
10000 "Do not advertise to any peer (well-known community)\n"
10001 "Do not export to next AS (well-known community)\n"
10002 "community number\n"
10003 "Do not send outside local AS (well-known community)\n"
10004 "Do not advertise to any peer (well-known community)\n"
10005 "Do not export to next AS (well-known community)\n"
10006 "Exact match of the communities")
10007
10008ALIAS (show_bgp_community_exact,
10009 show_bgp_ipv6_community2_exact_cmd,
10010 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10011 SHOW_STR
10012 BGP_STR
10013 "Address family\n"
10014 "Display routes matching the communities\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 "community number\n"
10020 "Do not send outside local AS (well-known community)\n"
10021 "Do not advertise to any peer (well-known community)\n"
10022 "Do not export to next AS (well-known community)\n"
10023 "Exact match of the communities")
10024
10025ALIAS (show_bgp_community_exact,
10026 show_bgp_community3_exact_cmd,
10027 "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",
10028 SHOW_STR
10029 BGP_STR
10030 "Display routes matching the communities\n"
10031 "community number\n"
10032 "Do not send outside local AS (well-known community)\n"
10033 "Do not advertise to any peer (well-known community)\n"
10034 "Do not export to next AS (well-known community)\n"
10035 "community number\n"
10036 "Do not send outside local AS (well-known community)\n"
10037 "Do not advertise to any peer (well-known community)\n"
10038 "Do not export to next AS (well-known community)\n"
10039 "community number\n"
10040 "Do not send outside local AS (well-known community)\n"
10041 "Do not advertise to any peer (well-known community)\n"
10042 "Do not export to next AS (well-known community)\n"
10043 "Exact match of the communities")
10044
10045ALIAS (show_bgp_community_exact,
10046 show_bgp_ipv6_community3_exact_cmd,
10047 "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",
10048 SHOW_STR
10049 BGP_STR
10050 "Address family\n"
10051 "Display routes matching the communities\n"
10052 "community number\n"
10053 "Do not send outside local AS (well-known community)\n"
10054 "Do not advertise to any peer (well-known community)\n"
10055 "Do not export to next AS (well-known community)\n"
10056 "community number\n"
10057 "Do not send outside local AS (well-known community)\n"
10058 "Do not advertise to any peer (well-known community)\n"
10059 "Do not export to next AS (well-known community)\n"
10060 "community number\n"
10061 "Do not send outside local AS (well-known community)\n"
10062 "Do not advertise to any peer (well-known community)\n"
10063 "Do not export to next AS (well-known community)\n"
10064 "Exact match of the communities")
10065
10066ALIAS (show_bgp_community_exact,
10067 show_bgp_community4_exact_cmd,
10068 "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",
10069 SHOW_STR
10070 BGP_STR
10071 "Display routes matching the communities\n"
10072 "community number\n"
10073 "Do not send outside local AS (well-known community)\n"
10074 "Do not advertise to any peer (well-known community)\n"
10075 "Do not export to next AS (well-known community)\n"
10076 "community number\n"
10077 "Do not send outside local AS (well-known community)\n"
10078 "Do not advertise to any peer (well-known community)\n"
10079 "Do not export to next AS (well-known community)\n"
10080 "community number\n"
10081 "Do not send outside local AS (well-known community)\n"
10082 "Do not advertise to any peer (well-known community)\n"
10083 "Do not export to next AS (well-known community)\n"
10084 "community number\n"
10085 "Do not send outside local AS (well-known community)\n"
10086 "Do not advertise to any peer (well-known community)\n"
10087 "Do not export to next AS (well-known community)\n"
10088 "Exact match of the communities")
10089
10090ALIAS (show_bgp_community_exact,
10091 show_bgp_ipv6_community4_exact_cmd,
10092 "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",
10093 SHOW_STR
10094 BGP_STR
10095 "Address family\n"
10096 "Display routes matching the communities\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 "community number\n"
10102 "Do not send outside local AS (well-known community)\n"
10103 "Do not advertise to any peer (well-known community)\n"
10104 "Do not export to next AS (well-known community)\n"
10105 "community number\n"
10106 "Do not send outside local AS (well-known community)\n"
10107 "Do not advertise to any peer (well-known community)\n"
10108 "Do not export to next AS (well-known community)\n"
10109 "community number\n"
10110 "Do not send outside local AS (well-known community)\n"
10111 "Do not advertise to any peer (well-known community)\n"
10112 "Do not export to next AS (well-known community)\n"
10113 "Exact match of the communities")
10114
10115/* old command */
10116DEFUN (show_ipv6_bgp_community_exact,
10117 show_ipv6_bgp_community_exact_cmd,
10118 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10119 SHOW_STR
10120 IPV6_STR
10121 BGP_STR
10122 "Display routes matching the communities\n"
10123 "community number\n"
10124 "Do not send outside local AS (well-known community)\n"
10125 "Do not advertise to any peer (well-known community)\n"
10126 "Do not export to next AS (well-known community)\n"
10127 "Exact match of the communities")
10128{
10129 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10130}
10131
10132/* old command */
10133ALIAS (show_ipv6_bgp_community_exact,
10134 show_ipv6_bgp_community2_exact_cmd,
10135 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10136 SHOW_STR
10137 IPV6_STR
10138 BGP_STR
10139 "Display routes matching the communities\n"
10140 "community number\n"
10141 "Do not send outside local AS (well-known community)\n"
10142 "Do not advertise to any peer (well-known community)\n"
10143 "Do not export to next AS (well-known community)\n"
10144 "community number\n"
10145 "Do not send outside local AS (well-known community)\n"
10146 "Do not advertise to any peer (well-known community)\n"
10147 "Do not export to next AS (well-known community)\n"
10148 "Exact match of the communities")
10149
10150/* old command */
10151ALIAS (show_ipv6_bgp_community_exact,
10152 show_ipv6_bgp_community3_exact_cmd,
10153 "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",
10154 SHOW_STR
10155 IPV6_STR
10156 BGP_STR
10157 "Display routes matching the communities\n"
10158 "community number\n"
10159 "Do not send outside local AS (well-known community)\n"
10160 "Do not advertise to any peer (well-known community)\n"
10161 "Do not export to next AS (well-known community)\n"
10162 "community number\n"
10163 "Do not send outside local AS (well-known community)\n"
10164 "Do not advertise to any peer (well-known community)\n"
10165 "Do not export to next AS (well-known community)\n"
10166 "community number\n"
10167 "Do not send outside local AS (well-known community)\n"
10168 "Do not advertise to any peer (well-known community)\n"
10169 "Do not export to next AS (well-known community)\n"
10170 "Exact match of the communities")
10171
10172/* old command */
10173ALIAS (show_ipv6_bgp_community_exact,
10174 show_ipv6_bgp_community4_exact_cmd,
10175 "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",
10176 SHOW_STR
10177 IPV6_STR
10178 BGP_STR
10179 "Display routes matching the communities\n"
10180 "community number\n"
10181 "Do not send outside local AS (well-known community)\n"
10182 "Do not advertise to any peer (well-known community)\n"
10183 "Do not export to next AS (well-known community)\n"
10184 "community number\n"
10185 "Do not send outside local AS (well-known community)\n"
10186 "Do not advertise to any peer (well-known community)\n"
10187 "Do not export to next AS (well-known community)\n"
10188 "community number\n"
10189 "Do not send outside local AS (well-known community)\n"
10190 "Do not advertise to any peer (well-known community)\n"
10191 "Do not export to next AS (well-known community)\n"
10192 "community number\n"
10193 "Do not send outside local AS (well-known community)\n"
10194 "Do not advertise to any peer (well-known community)\n"
10195 "Do not export to next AS (well-known community)\n"
10196 "Exact match of the communities")
10197
10198/* old command */
10199DEFUN (show_ipv6_mbgp_community,
10200 show_ipv6_mbgp_community_cmd,
10201 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10202 SHOW_STR
10203 IPV6_STR
10204 MBGP_STR
10205 "Display routes matching the communities\n"
10206 "community number\n"
10207 "Do not send outside local AS (well-known community)\n"
10208 "Do not advertise to any peer (well-known community)\n"
10209 "Do not export to next AS (well-known community)\n")
10210{
10211 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10212}
10213
10214/* old command */
10215ALIAS (show_ipv6_mbgp_community,
10216 show_ipv6_mbgp_community2_cmd,
10217 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10218 SHOW_STR
10219 IPV6_STR
10220 MBGP_STR
10221 "Display routes matching the communities\n"
10222 "community number\n"
10223 "Do not send outside local AS (well-known community)\n"
10224 "Do not advertise to any peer (well-known community)\n"
10225 "Do not export to next AS (well-known community)\n"
10226 "community number\n"
10227 "Do not send outside local AS (well-known community)\n"
10228 "Do not advertise to any peer (well-known community)\n"
10229 "Do not export to next AS (well-known community)\n")
10230
10231/* old command */
10232ALIAS (show_ipv6_mbgp_community,
10233 show_ipv6_mbgp_community3_cmd,
10234 "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)",
10235 SHOW_STR
10236 IPV6_STR
10237 MBGP_STR
10238 "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 "community number\n"
10244 "Do not send outside local AS (well-known community)\n"
10245 "Do not advertise to any peer (well-known community)\n"
10246 "Do not export to next AS (well-known community)\n"
10247 "community number\n"
10248 "Do not send outside local AS (well-known community)\n"
10249 "Do not advertise to any peer (well-known community)\n"
10250 "Do not export to next AS (well-known community)\n")
10251
10252/* old command */
10253ALIAS (show_ipv6_mbgp_community,
10254 show_ipv6_mbgp_community4_cmd,
10255 "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)",
10256 SHOW_STR
10257 IPV6_STR
10258 MBGP_STR
10259 "Display routes matching the communities\n"
10260 "community number\n"
10261 "Do not send outside local AS (well-known community)\n"
10262 "Do not advertise to any peer (well-known community)\n"
10263 "Do not export to next AS (well-known community)\n"
10264 "community number\n"
10265 "Do not send outside local AS (well-known community)\n"
10266 "Do not advertise to any peer (well-known community)\n"
10267 "Do not export to next AS (well-known community)\n"
10268 "community number\n"
10269 "Do not send outside local AS (well-known community)\n"
10270 "Do not advertise to any peer (well-known community)\n"
10271 "Do not export to next AS (well-known community)\n"
10272 "community number\n"
10273 "Do not send outside local AS (well-known community)\n"
10274 "Do not advertise to any peer (well-known community)\n"
10275 "Do not export to next AS (well-known community)\n")
10276
10277/* old command */
10278DEFUN (show_ipv6_mbgp_community_exact,
10279 show_ipv6_mbgp_community_exact_cmd,
10280 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10281 SHOW_STR
10282 IPV6_STR
10283 MBGP_STR
10284 "Display routes matching the communities\n"
10285 "community number\n"
10286 "Do not send outside local AS (well-known community)\n"
10287 "Do not advertise to any peer (well-known community)\n"
10288 "Do not export to next AS (well-known community)\n"
10289 "Exact match of the communities")
10290{
10291 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10292}
10293
10294/* old command */
10295ALIAS (show_ipv6_mbgp_community_exact,
10296 show_ipv6_mbgp_community2_exact_cmd,
10297 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10298 SHOW_STR
10299 IPV6_STR
10300 MBGP_STR
10301 "Display routes matching the communities\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 "community number\n"
10307 "Do not send outside local AS (well-known community)\n"
10308 "Do not advertise to any peer (well-known community)\n"
10309 "Do not export to next AS (well-known community)\n"
10310 "Exact match of the communities")
10311
10312/* old command */
10313ALIAS (show_ipv6_mbgp_community_exact,
10314 show_ipv6_mbgp_community3_exact_cmd,
10315 "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",
10316 SHOW_STR
10317 IPV6_STR
10318 MBGP_STR
10319 "Display routes matching the communities\n"
10320 "community number\n"
10321 "Do not send outside local AS (well-known community)\n"
10322 "Do not advertise to any peer (well-known community)\n"
10323 "Do not export to next AS (well-known community)\n"
10324 "community number\n"
10325 "Do not send outside local AS (well-known community)\n"
10326 "Do not advertise to any peer (well-known community)\n"
10327 "Do not export to next AS (well-known community)\n"
10328 "community number\n"
10329 "Do not send outside local AS (well-known community)\n"
10330 "Do not advertise to any peer (well-known community)\n"
10331 "Do not export to next AS (well-known community)\n"
10332 "Exact match of the communities")
10333
10334/* old command */
10335ALIAS (show_ipv6_mbgp_community_exact,
10336 show_ipv6_mbgp_community4_exact_cmd,
10337 "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",
10338 SHOW_STR
10339 IPV6_STR
10340 MBGP_STR
10341 "Display routes matching the communities\n"
10342 "community number\n"
10343 "Do not send outside local AS (well-known community)\n"
10344 "Do not advertise to any peer (well-known community)\n"
10345 "Do not export to next AS (well-known community)\n"
10346 "community number\n"
10347 "Do not send outside local AS (well-known community)\n"
10348 "Do not advertise to any peer (well-known community)\n"
10349 "Do not export to next AS (well-known community)\n"
10350 "community number\n"
10351 "Do not send outside local AS (well-known community)\n"
10352 "Do not advertise to any peer (well-known community)\n"
10353 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010359
Lou Berger651b4022016-01-12 13:42:07 -050010360DEFUN (show_bgp_ipv4_community,
10361 show_bgp_ipv4_community_cmd,
10362 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010363 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010364 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010365 IP_STR
paul718e3742002-12-13 20:15:29 +000010366 "Display routes matching the communities\n"
10367 "community number\n"
10368 "Do not send outside local AS (well-known community)\n"
10369 "Do not advertise to any peer (well-known community)\n"
10370 "Do not export to next AS (well-known community)\n")
10371{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010372 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010373}
10374
Lou Berger651b4022016-01-12 13:42:07 -050010375ALIAS (show_bgp_ipv4_community,
10376 show_bgp_ipv4_community2_cmd,
10377 "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 +000010378 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010379 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010380 IP_STR
paul718e3742002-12-13 20:15:29 +000010381 "Display routes matching the communities\n"
10382 "community number\n"
10383 "Do not send outside local AS (well-known community)\n"
10384 "Do not advertise to any peer (well-known community)\n"
10385 "Do not export to next AS (well-known community)\n"
10386 "community number\n"
10387 "Do not send outside local AS (well-known community)\n"
10388 "Do not advertise to any peer (well-known community)\n"
10389 "Do not export to next AS (well-known community)\n")
10390
Lou Berger651b4022016-01-12 13:42:07 -050010391ALIAS (show_bgp_ipv4_community,
10392 show_bgp_ipv4_community3_cmd,
10393 "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 +000010394 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010395 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010396 IP_STR
paul718e3742002-12-13 20:15:29 +000010397 "Display routes matching the communities\n"
10398 "community number\n"
10399 "Do not send outside local AS (well-known community)\n"
10400 "Do not advertise to any peer (well-known community)\n"
10401 "Do not export to next AS (well-known community)\n"
10402 "community number\n"
10403 "Do not send outside local AS (well-known community)\n"
10404 "Do not advertise to any peer (well-known community)\n"
10405 "Do not export to next AS (well-known community)\n"
10406 "community number\n"
10407 "Do not send outside local AS (well-known community)\n"
10408 "Do not advertise to any peer (well-known community)\n"
10409 "Do not export to next AS (well-known community)\n")
10410
Lou Berger651b4022016-01-12 13:42:07 -050010411ALIAS (show_bgp_ipv4_community,
10412 show_bgp_ipv4_community4_cmd,
10413 "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 +000010414 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010415 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010416 IP_STR
paul718e3742002-12-13 20:15:29 +000010417 "Display routes matching the communities\n"
10418 "community number\n"
10419 "Do not send outside local AS (well-known community)\n"
10420 "Do not advertise to any peer (well-known community)\n"
10421 "Do not export to next AS (well-known community)\n"
10422 "community number\n"
10423 "Do not send outside local AS (well-known community)\n"
10424 "Do not advertise to any peer (well-known community)\n"
10425 "Do not export to next AS (well-known community)\n"
10426 "community number\n"
10427 "Do not send outside local AS (well-known community)\n"
10428 "Do not advertise to any peer (well-known community)\n"
10429 "Do not export to next AS (well-known community)\n"
10430 "community number\n"
10431 "Do not send outside local AS (well-known community)\n"
10432 "Do not advertise to any peer (well-known community)\n"
10433 "Do not export to next AS (well-known community)\n")
10434
Lou Berger651b4022016-01-12 13:42:07 -050010435DEFUN (show_bgp_ipv4_safi_community,
10436 show_bgp_ipv4_safi_community_cmd,
10437 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010438 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010439 BGP_STR
10440 "Address family\n"
10441 "Address Family modifier\n"
10442 "Address Family modifier\n"
10443 "Display routes matching the communities\n"
10444 "community number\n"
10445 "Do not send outside local AS (well-known community)\n"
10446 "Do not advertise to any peer (well-known community)\n"
10447 "Do not export to next AS (well-known community)\n")
10448{
10449 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010450 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010451
Michael Lambert95cbbd22010-07-23 14:43:04 -040010452 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010453}
10454
Lou Berger651b4022016-01-12 13:42:07 -050010455ALIAS (show_bgp_ipv4_safi_community,
10456 show_bgp_ipv4_safi_community2_cmd,
10457 "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 +000010458 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010459 BGP_STR
10460 "Address family\n"
10461 "Address Family modifier\n"
10462 "Address Family modifier\n"
10463 "Display routes matching the communities\n"
10464 "community number\n"
10465 "Do not send outside local AS (well-known community)\n"
10466 "Do not advertise to any peer (well-known community)\n"
10467 "Do not export to next AS (well-known community)\n"
10468 "community number\n"
10469 "Do not send outside local AS (well-known community)\n"
10470 "Do not advertise to any peer (well-known community)\n"
10471 "Do not export to next AS (well-known community)\n")
10472
Lou Berger651b4022016-01-12 13:42:07 -050010473ALIAS (show_bgp_ipv4_safi_community,
10474 show_bgp_ipv4_safi_community3_cmd,
10475 "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 +000010476 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010477 BGP_STR
10478 "Address family\n"
10479 "Address Family modifier\n"
10480 "Address Family modifier\n"
10481 "Display routes matching the communities\n"
10482 "community number\n"
10483 "Do not send outside local AS (well-known community)\n"
10484 "Do not advertise to any peer (well-known community)\n"
10485 "Do not export to next AS (well-known community)\n"
10486 "community number\n"
10487 "Do not send outside local AS (well-known community)\n"
10488 "Do not advertise to any peer (well-known community)\n"
10489 "Do not export to next AS (well-known community)\n"
10490 "community number\n"
10491 "Do not send outside local AS (well-known community)\n"
10492 "Do not advertise to any peer (well-known community)\n"
10493 "Do not export to next AS (well-known community)\n")
10494
Lou Berger651b4022016-01-12 13:42:07 -050010495ALIAS (show_bgp_ipv4_safi_community,
10496 show_bgp_ipv4_safi_community4_cmd,
10497 "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 +000010498 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010499 BGP_STR
10500 "Address family\n"
10501 "Address Family modifier\n"
10502 "Address Family modifier\n"
10503 "Display routes matching the communities\n"
10504 "community number\n"
10505 "Do not send outside local AS (well-known community)\n"
10506 "Do not advertise to any peer (well-known community)\n"
10507 "Do not export to next AS (well-known community)\n"
10508 "community number\n"
10509 "Do not send outside local AS (well-known community)\n"
10510 "Do not advertise to any peer (well-known community)\n"
10511 "Do not export to next AS (well-known community)\n"
10512 "community number\n"
10513 "Do not send outside local AS (well-known community)\n"
10514 "Do not advertise to any peer (well-known community)\n"
10515 "Do not export to next AS (well-known community)\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
Michael Lambert95cbbd22010-07-23 14:43:04 -040010521DEFUN (show_bgp_view_afi_safi_community_all,
10522 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010523 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010524 SHOW_STR
10525 BGP_STR
10526 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010527 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010528 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010529 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010530 "Address Family modifier\n"
10531 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010532 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010533{
10534 int afi;
10535 int safi;
10536 struct bgp *bgp;
10537
10538 /* BGP structure lookup. */
10539 bgp = bgp_lookup_by_name (argv[0]);
10540 if (bgp == NULL)
10541 {
10542 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10543 return CMD_WARNING;
10544 }
10545
Michael Lambert95cbbd22010-07-23 14:43:04 -040010546 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10547 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010548 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10549}
10550
10551DEFUN (show_bgp_view_afi_safi_community,
10552 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010553 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010554 SHOW_STR
10555 BGP_STR
10556 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010557 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010558 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010559 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010560 "Address family modifier\n"
10561 "Address family modifier\n"
10562 "Display routes matching the communities\n"
10563 "community number\n"
10564 "Do not send outside local AS (well-known community)\n"
10565 "Do not advertise to any peer (well-known community)\n"
10566 "Do not export to next AS (well-known community)\n")
10567{
10568 int afi;
10569 int safi;
10570
Michael Lambert95cbbd22010-07-23 14:43:04 -040010571 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10572 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10573 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010574}
10575
10576ALIAS (show_bgp_view_afi_safi_community,
10577 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010578 "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)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010579 SHOW_STR
10580 BGP_STR
10581 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010582 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010583 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010584 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010585 "Address family modifier\n"
10586 "Address family modifier\n"
10587 "Display routes matching the communities\n"
10588 "community number\n"
10589 "Do not send outside local AS (well-known community)\n"
10590 "Do not advertise to any peer (well-known community)\n"
10591 "Do not export to next AS (well-known community)\n"
10592 "community number\n"
10593 "Do not send outside local AS (well-known community)\n"
10594 "Do not advertise to any peer (well-known community)\n"
10595 "Do not export to next AS (well-known community)\n")
10596
10597ALIAS (show_bgp_view_afi_safi_community,
10598 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010599 "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)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010600 SHOW_STR
10601 BGP_STR
10602 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010603 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010604 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010605 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010606 "Address family modifier\n"
10607 "Address family modifier\n"
10608 "Display routes matching the communities\n"
10609 "community number\n"
10610 "Do not send outside local AS (well-known community)\n"
10611 "Do not advertise to any peer (well-known community)\n"
10612 "Do not export to next AS (well-known community)\n"
10613 "community number\n"
10614 "Do not send outside local AS (well-known community)\n"
10615 "Do not advertise to any peer (well-known community)\n"
10616 "Do not export to next AS (well-known community)\n"
10617 "community number\n"
10618 "Do not send outside local AS (well-known community)\n"
10619 "Do not advertise to any peer (well-known community)\n"
10620 "Do not export to next AS (well-known community)\n")
10621
10622ALIAS (show_bgp_view_afi_safi_community,
10623 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010624 "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)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010625 SHOW_STR
10626 BGP_STR
10627 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010628 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010629 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010630 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010631 "Address family modifier\n"
10632 "Address family modifier\n"
10633 "Display routes matching the communities\n"
10634 "community number\n"
10635 "Do not send outside local AS (well-known community)\n"
10636 "Do not advertise to any peer (well-known community)\n"
10637 "Do not export to next AS (well-known community)\n"
10638 "community number\n"
10639 "Do not send outside local AS (well-known community)\n"
10640 "Do not advertise to any peer (well-known community)\n"
10641 "Do not export to next AS (well-known community)\n"
10642 "community number\n"
10643 "Do not send outside local AS (well-known community)\n"
10644 "Do not advertise to any peer (well-known community)\n"
10645 "Do not export to next AS (well-known community)\n"
10646 "community number\n"
10647 "Do not send outside local AS (well-known community)\n"
10648 "Do not advertise to any peer (well-known community)\n"
10649 "Do not export to next AS (well-known community)\n")
10650
Lou Berger651b4022016-01-12 13:42:07 -050010651DEFUN (show_bgp_ipv4_community_exact,
10652 show_bgp_ipv4_community_exact_cmd,
10653 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010654 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010655 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010656 IP_STR
paul718e3742002-12-13 20:15:29 +000010657 "Display routes matching the communities\n"
10658 "community number\n"
10659 "Do not send outside local AS (well-known community)\n"
10660 "Do not advertise to any peer (well-known community)\n"
10661 "Do not export to next AS (well-known community)\n"
10662 "Exact match of the communities")
10663{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010664 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010665}
10666
Lou Berger651b4022016-01-12 13:42:07 -050010667ALIAS (show_bgp_ipv4_community_exact,
10668 show_bgp_ipv4_community2_exact_cmd,
10669 "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 +000010670 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010671 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010672 IP_STR
paul718e3742002-12-13 20:15:29 +000010673 "Display routes matching the communities\n"
10674 "community number\n"
10675 "Do not send outside local AS (well-known community)\n"
10676 "Do not advertise to any peer (well-known community)\n"
10677 "Do not export to next AS (well-known community)\n"
10678 "community number\n"
10679 "Do not send outside local AS (well-known community)\n"
10680 "Do not advertise to any peer (well-known community)\n"
10681 "Do not export to next AS (well-known community)\n"
10682 "Exact match of the communities")
10683
Lou Berger651b4022016-01-12 13:42:07 -050010684ALIAS (show_bgp_ipv4_community_exact,
10685 show_bgp_ipv4_community3_exact_cmd,
10686 "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 +000010687 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010688 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010689 IP_STR
paul718e3742002-12-13 20:15:29 +000010690 "Display routes matching the communities\n"
10691 "community number\n"
10692 "Do not send outside local AS (well-known community)\n"
10693 "Do not advertise to any peer (well-known community)\n"
10694 "Do not export to next AS (well-known community)\n"
10695 "community number\n"
10696 "Do not send outside local AS (well-known community)\n"
10697 "Do not advertise to any peer (well-known community)\n"
10698 "Do not export to next AS (well-known community)\n"
10699 "community number\n"
10700 "Do not send outside local AS (well-known community)\n"
10701 "Do not advertise to any peer (well-known community)\n"
10702 "Do not export to next AS (well-known community)\n"
10703 "Exact match of the communities")
10704
Lou Berger651b4022016-01-12 13:42:07 -050010705ALIAS (show_bgp_ipv4_community_exact,
10706 show_bgp_ipv4_community4_exact_cmd,
10707 "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 +000010708 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010709 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010710 IP_STR
paul718e3742002-12-13 20:15:29 +000010711 "Display routes matching the communities\n"
10712 "community number\n"
10713 "Do not send outside local AS (well-known community)\n"
10714 "Do not advertise to any peer (well-known community)\n"
10715 "Do not export to next AS (well-known community)\n"
10716 "community number\n"
10717 "Do not send outside local AS (well-known community)\n"
10718 "Do not advertise to any peer (well-known community)\n"
10719 "Do not export to next AS (well-known community)\n"
10720 "community number\n"
10721 "Do not send outside local AS (well-known community)\n"
10722 "Do not advertise to any peer (well-known community)\n"
10723 "Do not export to next AS (well-known community)\n"
10724 "community number\n"
10725 "Do not send outside local AS (well-known community)\n"
10726 "Do not advertise to any peer (well-known community)\n"
10727 "Do not export to next AS (well-known community)\n"
10728 "Exact match of the communities")
10729
Lou Berger651b4022016-01-12 13:42:07 -050010730DEFUN (show_bgp_ipv4_safi_community4_exact,
10731 show_bgp_ipv4_safi_community_exact_cmd,
10732 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010733 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010734 BGP_STR
10735 "Address family\n"
10736 "Address Family modifier\n"
10737 "Address Family modifier\n"
10738 "Display routes matching the communities\n"
10739 "community number\n"
10740 "Do not send outside local AS (well-known community)\n"
10741 "Do not advertise to any peer (well-known community)\n"
10742 "Do not export to next AS (well-known community)\n"
10743 "Exact match of the communities")
10744{
10745 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010746 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010747
Michael Lambert95cbbd22010-07-23 14:43:04 -040010748 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010749}
10750
Lou Berger651b4022016-01-12 13:42:07 -050010751ALIAS (show_bgp_ipv4_safi_community4_exact,
10752 show_bgp_ipv4_safi_community2_exact_cmd,
10753 "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 +000010754 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010755 BGP_STR
10756 "Address family\n"
10757 "Address Family modifier\n"
10758 "Address Family modifier\n"
10759 "Display routes matching the communities\n"
10760 "community number\n"
10761 "Do not send outside local AS (well-known community)\n"
10762 "Do not advertise to any peer (well-known community)\n"
10763 "Do not export to next AS (well-known community)\n"
10764 "community number\n"
10765 "Do not send outside local AS (well-known community)\n"
10766 "Do not advertise to any peer (well-known community)\n"
10767 "Do not export to next AS (well-known community)\n"
10768 "Exact match of the communities")
10769
Lou Berger651b4022016-01-12 13:42:07 -050010770ALIAS (show_bgp_ipv4_safi_community4_exact,
10771 show_bgp_ipv4_safi_community3_exact_cmd,
10772 "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 +000010773 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010774 BGP_STR
10775 "Address family\n"
10776 "Address Family modifier\n"
10777 "Address Family modifier\n"
10778 "Display routes matching the communities\n"
10779 "community number\n"
10780 "Do not send outside local AS (well-known community)\n"
10781 "Do not advertise to any peer (well-known community)\n"
10782 "Do not export to next AS (well-known community)\n"
10783 "community number\n"
10784 "Do not send outside local AS (well-known community)\n"
10785 "Do not advertise to any peer (well-known community)\n"
10786 "Do not export to next AS (well-known community)\n"
10787 "community number\n"
10788 "Do not send outside local AS (well-known community)\n"
10789 "Do not advertise to any peer (well-known community)\n"
10790 "Do not export to next AS (well-known community)\n"
10791 "Exact match of the communities")
10792
Lou Berger651b4022016-01-12 13:42:07 -050010793ALIAS (show_bgp_ipv4_safi_community4_exact,
10794 show_bgp_ipv4_safi_community4_exact_cmd,
10795 "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 +000010796 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010797 BGP_STR
10798 "Address family\n"
10799 "Address Family modifier\n"
10800 "Address Family modifier\n"
10801 "Display routes matching the communities\n"
10802 "community number\n"
10803 "Do not send outside local AS (well-known community)\n"
10804 "Do not advertise to any peer (well-known community)\n"
10805 "Do not export to next AS (well-known community)\n"
10806 "community number\n"
10807 "Do not send outside local AS (well-known community)\n"
10808 "Do not advertise to any peer (well-known community)\n"
10809 "Do not export to next AS (well-known community)\n"
10810 "community number\n"
10811 "Do not send outside local AS (well-known community)\n"
10812 "Do not advertise to any peer (well-known community)\n"
10813 "Do not export to next AS (well-known community)\n"
10814 "community number\n"
10815 "Do not send outside local AS (well-known community)\n"
10816 "Do not advertise to any peer (well-known community)\n"
10817 "Do not export to next AS (well-known community)\n"
10818 "Exact match of the communities")
10819
Lou Bergerf9b6c392016-01-12 13:42:09 -050010820DEFUN (show_bgp_ipv6_safi_community,
10821 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010822 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010823 SHOW_STR
10824 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010825 "Address family\n"
10826 "Address family modifier\n"
10827 "Address family modifier\n"
10828 "Address family modifier\n"
10829 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010830 "Display routes matching the communities\n"
10831 "community number\n"
10832 "Do not send outside local AS (well-known community)\n"
10833 "Do not advertise to any peer (well-known community)\n"
10834 "Do not export to next AS (well-known community)\n")
10835{
Lou Berger651b4022016-01-12 13:42:07 -050010836 safi_t safi;
10837
10838 if (bgp_parse_safi(argv[0], &safi)) {
10839 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10840 return CMD_WARNING;
10841 }
10842 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010843}
10844
Lou Bergerf9b6c392016-01-12 13:42:09 -050010845ALIAS (show_bgp_ipv6_safi_community,
10846 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010847 "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 +000010848 SHOW_STR
10849 BGP_STR
10850 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010851 "Address family modifier\n"
10852 "Address family modifier\n"
10853 "Address family modifier\n"
10854 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010855 "Display routes matching the communities\n"
10856 "community number\n"
10857 "Do not send outside local AS (well-known community)\n"
10858 "Do not advertise to any peer (well-known community)\n"
10859 "Do not export to next AS (well-known community)\n"
10860 "community number\n"
10861 "Do not send outside local AS (well-known community)\n"
10862 "Do not advertise to any peer (well-known community)\n"
10863 "Do not export to next AS (well-known community)\n")
10864
Lou Bergerf9b6c392016-01-12 13:42:09 -050010865ALIAS (show_bgp_ipv6_safi_community,
10866 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010867 "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 +000010868 SHOW_STR
10869 BGP_STR
10870 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010871 "Address family modifier\n"
10872 "Address family modifier\n"
10873 "Address family modifier\n"
10874 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010875 "Display routes matching the communities\n"
10876 "community number\n"
10877 "Do not send outside local AS (well-known community)\n"
10878 "Do not advertise to any peer (well-known community)\n"
10879 "Do not export to next AS (well-known community)\n"
10880 "community number\n"
10881 "Do not send outside local AS (well-known community)\n"
10882 "Do not advertise to any peer (well-known community)\n"
10883 "Do not export to next AS (well-known community)\n"
10884 "community number\n"
10885 "Do not send outside local AS (well-known community)\n"
10886 "Do not advertise to any peer (well-known community)\n"
10887 "Do not export to next AS (well-known community)\n")
10888
Lou Bergerf9b6c392016-01-12 13:42:09 -050010889ALIAS (show_bgp_ipv6_safi_community,
10890 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010891 "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 +000010892 SHOW_STR
10893 BGP_STR
10894 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010895 "Address family modifier\n"
10896 "Address family modifier\n"
10897 "Address family modifier\n"
10898 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010899 "Display routes matching the communities\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 "community number\n"
10905 "Do not send outside local AS (well-known community)\n"
10906 "Do not advertise to any peer (well-known community)\n"
10907 "Do not export to next AS (well-known community)\n"
10908 "community number\n"
10909 "Do not send outside local AS (well-known community)\n"
10910 "Do not advertise to any peer (well-known community)\n"
10911 "Do not export to next AS (well-known community)\n"
10912 "community number\n"
10913 "Do not send outside local AS (well-known community)\n"
10914 "Do not advertise to any peer (well-known community)\n"
10915 "Do not export to next AS (well-known community)\n")
10916
paul718e3742002-12-13 20:15:29 +000010917
Lou Bergerf9b6c392016-01-12 13:42:09 -050010918DEFUN (show_bgp_ipv6_safi_community_exact,
10919 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010920 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010921 SHOW_STR
10922 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010923 "Address family\n"
10924 "Address family modifier\n"
10925 "Address family modifier\n"
10926 "Address family modifier\n"
10927 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010928 "Display routes matching the communities\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{
Lou Berger651b4022016-01-12 13:42:07 -050010935 safi_t safi;
10936
10937 if (bgp_parse_safi(argv[0], &safi)) {
10938 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10939 return CMD_WARNING;
10940 }
10941 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010942}
10943
paul718e3742002-12-13 20:15:29 +000010944
10945ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010946 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010947 "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 +000010948 SHOW_STR
10949 BGP_STR
10950 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010951 "Address family modifier\n"
10952 "Address family modifier\n"
10953 "Address family modifier\n"
10954 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010955 "Display routes matching the communities\n"
10956 "community number\n"
10957 "Do not send outside local AS (well-known community)\n"
10958 "Do not advertise to any peer (well-known community)\n"
10959 "Do not export to next AS (well-known community)\n"
10960 "community number\n"
10961 "Do not send outside local AS (well-known community)\n"
10962 "Do not advertise to any peer (well-known community)\n"
10963 "Do not export to next AS (well-known community)\n"
10964 "Exact match of the communities")
10965
10966ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010967 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010968 "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 +000010969 SHOW_STR
10970 BGP_STR
10971 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010972 "Address family modifier\n"
10973 "Address family modifier\n"
10974 "Address family modifier\n"
10975 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010976 "Display routes matching the communities\n"
10977 "community number\n"
10978 "Do not send outside local AS (well-known community)\n"
10979 "Do not advertise to any peer (well-known community)\n"
10980 "Do not export to next AS (well-known community)\n"
10981 "community number\n"
10982 "Do not send outside local AS (well-known community)\n"
10983 "Do not advertise to any peer (well-known community)\n"
10984 "Do not export to next AS (well-known community)\n"
10985 "community number\n"
10986 "Do not send outside local AS (well-known community)\n"
10987 "Do not advertise to any peer (well-known community)\n"
10988 "Do not export to next AS (well-known community)\n"
10989 "Exact match of the communities")
10990
10991ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010992 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010993 "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 +000010994 SHOW_STR
10995 BGP_STR
10996 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010997 "Address family modifier\n"
10998 "Address family modifier\n"
10999 "Address family modifier\n"
11000 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011001 "Display routes matching the communities\n"
11002 "community number\n"
11003 "Do not send outside local AS (well-known community)\n"
11004 "Do not advertise to any peer (well-known community)\n"
11005 "Do not export to next AS (well-known community)\n"
11006 "community number\n"
11007 "Do not send outside local AS (well-known community)\n"
11008 "Do not advertise to any peer (well-known community)\n"
11009 "Do not export to next AS (well-known community)\n"
11010 "community number\n"
11011 "Do not send outside local AS (well-known community)\n"
11012 "Do not advertise to any peer (well-known community)\n"
11013 "Do not export to next AS (well-known community)\n"
11014 "community number\n"
11015 "Do not send outside local AS (well-known community)\n"
11016 "Do not advertise to any peer (well-known community)\n"
11017 "Do not export to next AS (well-known community)\n"
11018 "Exact match of the communities")
11019
paul94f2b392005-06-28 12:44:16 +000011020static int
paulfd79ac92004-10-13 05:06:08 +000011021bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040011022 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000011023{
11024 struct community_list *list;
11025
hassofee6e4e2005-02-02 16:29:31 +000011026 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000011027 if (list == NULL)
11028 {
11029 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11030 VTY_NEWLINE);
11031 return CMD_WARNING;
11032 }
11033
ajs5a646652004-11-05 01:25:55 +000011034 return bgp_show (vty, NULL, afi, safi,
11035 (exact ? bgp_show_type_community_list_exact :
11036 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000011037}
11038
Lou Bergerf9b6c392016-01-12 13:42:09 -050011039DEFUN (show_ip_bgp_community_list,
11040 show_ip_bgp_community_list_cmd,
11041 "show ip bgp community-list (<1-500>|WORD)",
11042 SHOW_STR
11043 IP_STR
11044 BGP_STR
11045 "Display routes matching the community-list\n"
11046 "community-list number\n"
11047 "community-list name\n")
11048{
11049 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11050}
11051
11052DEFUN (show_ip_bgp_ipv4_community_list,
11053 show_ip_bgp_ipv4_community_list_cmd,
11054 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11055 SHOW_STR
11056 IP_STR
11057 BGP_STR
11058 "Address family\n"
11059 "Address Family modifier\n"
11060 "Address Family modifier\n"
11061 "Display routes matching the community-list\n"
11062 "community-list number\n"
11063 "community-list name\n")
11064{
11065 if (strncmp (argv[0], "m", 1) == 0)
11066 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11067
11068 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11069}
11070
11071DEFUN (show_ip_bgp_community_list_exact,
11072 show_ip_bgp_community_list_exact_cmd,
11073 "show ip bgp community-list (<1-500>|WORD) exact-match",
11074 SHOW_STR
11075 IP_STR
11076 BGP_STR
11077 "Display routes matching the community-list\n"
11078 "community-list number\n"
11079 "community-list name\n"
11080 "Exact match of the communities\n")
11081{
11082 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11083}
11084
11085DEFUN (show_ip_bgp_ipv4_community_list_exact,
11086 show_ip_bgp_ipv4_community_list_exact_cmd,
11087 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11088 SHOW_STR
11089 IP_STR
11090 BGP_STR
11091 "Address family\n"
11092 "Address Family modifier\n"
11093 "Address Family modifier\n"
11094 "Display routes matching the community-list\n"
11095 "community-list number\n"
11096 "community-list name\n"
11097 "Exact match of the communities\n")
11098{
11099 if (strncmp (argv[0], "m", 1) == 0)
11100 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11101
11102 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11103}
11104
Lou Bergerf9b6c392016-01-12 13:42:09 -050011105DEFUN (show_bgp_community_list,
11106 show_bgp_community_list_cmd,
11107 "show bgp community-list (<1-500>|WORD)",
11108 SHOW_STR
11109 BGP_STR
11110 "Display routes matching the community-list\n"
11111 "community-list number\n"
11112 "community-list name\n")
11113{
11114 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11115}
11116
11117ALIAS (show_bgp_community_list,
11118 show_bgp_ipv6_community_list_cmd,
11119 "show bgp ipv6 community-list (<1-500>|WORD)",
11120 SHOW_STR
11121 BGP_STR
11122 "Address family\n"
11123 "Display routes matching the community-list\n"
11124 "community-list number\n"
11125 "community-list name\n")
11126
11127/* old command */
11128DEFUN (show_ipv6_bgp_community_list,
11129 show_ipv6_bgp_community_list_cmd,
11130 "show ipv6 bgp community-list WORD",
11131 SHOW_STR
11132 IPV6_STR
11133 BGP_STR
11134 "Display routes matching the community-list\n"
11135 "community-list name\n")
11136{
11137 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11138}
11139
11140/* old command */
11141DEFUN (show_ipv6_mbgp_community_list,
11142 show_ipv6_mbgp_community_list_cmd,
11143 "show ipv6 mbgp community-list WORD",
11144 SHOW_STR
11145 IPV6_STR
11146 MBGP_STR
11147 "Display routes matching the community-list\n"
11148 "community-list name\n")
11149{
11150 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11151}
11152
11153DEFUN (show_bgp_community_list_exact,
11154 show_bgp_community_list_exact_cmd,
11155 "show bgp community-list (<1-500>|WORD) exact-match",
11156 SHOW_STR
11157 BGP_STR
11158 "Display routes matching the community-list\n"
11159 "community-list number\n"
11160 "community-list name\n"
11161 "Exact match of the communities\n")
11162{
11163 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11164}
11165
11166ALIAS (show_bgp_community_list_exact,
11167 show_bgp_ipv6_community_list_exact_cmd,
11168 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11169 SHOW_STR
11170 BGP_STR
11171 "Address family\n"
11172 "Display routes matching the community-list\n"
11173 "community-list number\n"
11174 "community-list name\n"
11175 "Exact match of the communities\n")
11176
11177/* old command */
11178DEFUN (show_ipv6_bgp_community_list_exact,
11179 show_ipv6_bgp_community_list_exact_cmd,
11180 "show ipv6 bgp community-list WORD exact-match",
11181 SHOW_STR
11182 IPV6_STR
11183 BGP_STR
11184 "Display routes matching the community-list\n"
11185 "community-list name\n"
11186 "Exact match of the communities\n")
11187{
11188 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11189}
11190
11191/* old command */
11192DEFUN (show_ipv6_mbgp_community_list_exact,
11193 show_ipv6_mbgp_community_list_exact_cmd,
11194 "show ipv6 mbgp community-list WORD exact-match",
11195 SHOW_STR
11196 IPV6_STR
11197 MBGP_STR
11198 "Display routes matching the community-list\n"
11199 "community-list name\n"
11200 "Exact match of the communities\n")
11201{
11202 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11203}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011204
Lou Berger651b4022016-01-12 13:42:07 -050011205DEFUN (show_bgp_ipv4_community_list,
11206 show_bgp_ipv4_community_list_cmd,
11207 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011208 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011209 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011210 IP_STR
paul718e3742002-12-13 20:15:29 +000011211 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011212 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011213 "community-list name\n")
11214{
11215 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11216}
11217
Lou Berger651b4022016-01-12 13:42:07 -050011218DEFUN (show_bgp_ipv4_safi_community_list,
11219 show_bgp_ipv4_safi_community_list_cmd,
11220 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011221 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011222 BGP_STR
11223 "Address family\n"
11224 "Address Family modifier\n"
11225 "Address Family modifier\n"
11226 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011227 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011228 "community-list name\n")
11229{
11230 if (strncmp (argv[0], "m", 1) == 0)
11231 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11232
11233 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11234}
11235
Lou Berger651b4022016-01-12 13:42:07 -050011236DEFUN (show_bgp_ipv4_community_list_exact,
11237 show_bgp_ipv4_community_list_exact_cmd,
11238 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011239 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011240 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011241 IP_STR
paul718e3742002-12-13 20:15:29 +000011242 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011243 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011244 "community-list name\n"
11245 "Exact match of the communities\n")
11246{
11247 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11248}
11249
Lou Berger651b4022016-01-12 13:42:07 -050011250DEFUN (show_bgp_ipv4_safi_community_list_exact,
11251 show_bgp_ipv4_safi_community_list_exact_cmd,
11252 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011253 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011254 BGP_STR
11255 "Address family\n"
11256 "Address Family modifier\n"
11257 "Address Family modifier\n"
11258 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011259 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011260 "community-list name\n"
11261 "Exact match of the communities\n")
11262{
11263 if (strncmp (argv[0], "m", 1) == 0)
11264 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11265
11266 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11267}
11268
Lou Bergerf9b6c392016-01-12 13:42:09 -050011269DEFUN (show_bgp_ipv6_safi_community_list,
11270 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011271 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011272 SHOW_STR
11273 BGP_STR
11274 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011275 "Address family modifier\n"
11276 "Address family modifier\n"
11277 "Address family modifier\n"
11278 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011279 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011280 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011281 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011282{
Lou Berger651b4022016-01-12 13:42:07 -050011283 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011284
Lou Berger651b4022016-01-12 13:42:07 -050011285 if (bgp_parse_safi(argv[0], &safi)) {
11286 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11287 return CMD_WARNING;
11288 }
11289 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011290}
11291
Lou Bergerf9b6c392016-01-12 13:42:09 -050011292DEFUN (show_bgp_ipv6_safi_community_list_exact,
11293 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011294 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011295 SHOW_STR
11296 BGP_STR
11297 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011298 "Address family modifier\n"
11299 "Address family modifier\n"
11300 "Address family modifier\n"
11301 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011302 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011303 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011304 "community-list name\n"
11305 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011306{
Lou Berger651b4022016-01-12 13:42:07 -050011307 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011308
Lou Berger651b4022016-01-12 13:42:07 -050011309 if (bgp_parse_safi(argv[0], &safi)) {
11310 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11311 return CMD_WARNING;
11312 }
11313 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011314}
David Lamparter6b0655a2014-06-04 06:53:35 +020011315
paul94f2b392005-06-28 12:44:16 +000011316static int
paulfd79ac92004-10-13 05:06:08 +000011317bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011318 safi_t safi, enum bgp_show_type type)
11319{
11320 int ret;
11321 struct prefix *p;
11322
11323 p = prefix_new();
11324
11325 ret = str2prefix (prefix, p);
11326 if (! ret)
11327 {
11328 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11329 return CMD_WARNING;
11330 }
11331
ajs5a646652004-11-05 01:25:55 +000011332 ret = bgp_show (vty, NULL, afi, safi, type, p);
11333 prefix_free(p);
11334 return ret;
paul718e3742002-12-13 20:15:29 +000011335}
11336
Lou Bergerf9b6c392016-01-12 13:42:09 -050011337DEFUN (show_ip_bgp_prefix_longer,
11338 show_ip_bgp_prefix_longer_cmd,
11339 "show ip bgp A.B.C.D/M longer-prefixes",
11340 SHOW_STR
11341 IP_STR
11342 BGP_STR
11343 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11344 "Display route and more specific routes\n")
11345{
11346 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11347 bgp_show_type_prefix_longer);
11348}
11349
11350DEFUN (show_ip_bgp_flap_prefix_longer,
11351 show_ip_bgp_flap_prefix_longer_cmd,
11352 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11353 SHOW_STR
11354 IP_STR
11355 BGP_STR
11356 "Display flap statistics of routes\n"
11357 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11358 "Display route and more specific routes\n")
11359{
11360 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11361 bgp_show_type_flap_prefix_longer);
11362}
11363
11364ALIAS (show_ip_bgp_flap_prefix_longer,
11365 show_ip_bgp_damp_flap_prefix_longer_cmd,
11366 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11367 SHOW_STR
11368 IP_STR
11369 BGP_STR
11370 "Display detailed information about dampening\n"
11371 "Display flap statistics of routes\n"
11372 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11373 "Display route and more specific routes\n")
11374
11375DEFUN (show_ip_bgp_ipv4_prefix_longer,
11376 show_ip_bgp_ipv4_prefix_longer_cmd,
11377 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11378 SHOW_STR
11379 IP_STR
11380 BGP_STR
11381 "Address family\n"
11382 "Address Family modifier\n"
11383 "Address Family modifier\n"
11384 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11385 "Display route and more specific routes\n")
11386{
11387 if (strncmp (argv[0], "m", 1) == 0)
11388 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11389 bgp_show_type_prefix_longer);
11390
11391 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11392 bgp_show_type_prefix_longer);
11393}
11394
11395DEFUN (show_ip_bgp_flap_address,
11396 show_ip_bgp_flap_address_cmd,
11397 "show ip bgp flap-statistics A.B.C.D",
11398 SHOW_STR
11399 IP_STR
11400 BGP_STR
11401 "Display flap statistics of routes\n"
11402 "Network in the BGP routing table to display\n")
11403{
11404 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11405 bgp_show_type_flap_address);
11406}
11407
11408ALIAS (show_ip_bgp_flap_address,
11409 show_ip_bgp_damp_flap_address_cmd,
11410 "show ip bgp dampening flap-statistics A.B.C.D",
11411 SHOW_STR
11412 IP_STR
11413 BGP_STR
11414 "Display detailed information about dampening\n"
11415 "Display flap statistics of routes\n"
11416 "Network in the BGP routing table to display\n")
11417
11418DEFUN (show_ip_bgp_flap_prefix,
11419 show_ip_bgp_flap_prefix_cmd,
11420 "show ip bgp flap-statistics A.B.C.D/M",
11421 SHOW_STR
11422 IP_STR
11423 BGP_STR
11424 "Display flap statistics of routes\n"
11425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11426{
11427 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11428 bgp_show_type_flap_prefix);
11429}
11430
11431ALIAS (show_ip_bgp_flap_prefix,
11432 show_ip_bgp_damp_flap_prefix_cmd,
11433 "show ip bgp dampening flap-statistics A.B.C.D/M",
11434 SHOW_STR
11435 IP_STR
11436 BGP_STR
11437 "Display detailed information about dampening\n"
11438 "Display flap statistics of routes\n"
11439 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11440
Lou Bergerf9b6c392016-01-12 13:42:09 -050011441DEFUN (show_bgp_prefix_longer,
11442 show_bgp_prefix_longer_cmd,
11443 "show bgp X:X::X:X/M longer-prefixes",
11444 SHOW_STR
11445 BGP_STR
11446 "IPv6 prefix <network>/<length>\n"
11447 "Display route and more specific routes\n")
11448{
11449 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11450 bgp_show_type_prefix_longer);
11451}
11452
11453/* old command */
11454DEFUN (show_ipv6_bgp_prefix_longer,
11455 show_ipv6_bgp_prefix_longer_cmd,
11456 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11457 SHOW_STR
11458 IPV6_STR
11459 BGP_STR
11460 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11461 "Display route and more specific routes\n")
11462{
11463 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11464 bgp_show_type_prefix_longer);
11465}
11466
11467/* old command */
11468DEFUN (show_ipv6_mbgp_prefix_longer,
11469 show_ipv6_mbgp_prefix_longer_cmd,
11470 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11471 SHOW_STR
11472 IPV6_STR
11473 MBGP_STR
11474 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11475 "Display route and more specific routes\n")
11476{
11477 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11478 bgp_show_type_prefix_longer);
11479}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011480
Lou Berger651b4022016-01-12 13:42:07 -050011481DEFUN (show_bgp_ipv4_prefix_longer,
11482 show_bgp_ipv4_prefix_longer_cmd,
11483 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011484 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011485 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011486 IP_STR
paul718e3742002-12-13 20:15:29 +000011487 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11488 "Display route and more specific routes\n")
11489{
11490 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11491 bgp_show_type_prefix_longer);
11492}
11493
Lou Berger651b4022016-01-12 13:42:07 -050011494DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11495 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11496 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011497 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011498 BGP_STR
11499 "Address family\n"
11500 "Address Family modifier\n"
11501 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011502 "Address Family modifier\n"
11503 "Address Family modifier\n"
11504 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011505 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11506 "Display route and more specific routes\n")
11507{
Lou Berger651b4022016-01-12 13:42:07 -050011508 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011509
Lou Berger651b4022016-01-12 13:42:07 -050011510 if (bgp_parse_safi(argv[0], &safi)) {
11511 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11512 return CMD_WARNING;
11513 }
11514 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11515 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011516}
11517
Lou Berger651b4022016-01-12 13:42:07 -050011518ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11519 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11520 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011521 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011522 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011523 "Address family\n"
11524 "Address Family modifier\n"
11525 "Address Family modifier\n"
11526 "Address Family modifier\n"
11527 "Address Family modifier\n"
11528 "Display detailed information about dampening\n"
11529 "Display flap statistics of routes\n"
11530 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11531 "Display route and more specific routes\n")
11532
Lou Berger651b4022016-01-12 13:42:07 -050011533DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11534 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11535 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11536 SHOW_STR
11537 BGP_STR
11538 "Address family\n"
11539 "Address Family modifier\n"
11540 "Address Family modifier\n"
11541 "Address Family modifier\n"
11542 "Address Family modifier\n"
11543 "Display flap statistics of routes\n"
11544 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11545 "Display route and more specific routes\n")
11546{
11547 safi_t safi;
11548
11549 if (bgp_parse_safi(argv[0], &safi)) {
11550 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11551 return CMD_WARNING;
11552 }
11553 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11554 bgp_show_type_flap_prefix_longer);
11555}
11556ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11557 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11558 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11559 SHOW_STR
11560 BGP_STR
11561 "Address family\n"
11562 "Address Family modifier\n"
11563 "Address Family modifier\n"
11564 "Address Family modifier\n"
11565 "Address Family modifier\n"
11566 "Display detailed information about dampening\n"
11567 "Display flap statistics of routes\n"
11568 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11569 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011570
11571DEFUN (show_bgp_ipv4_safi_prefix_longer,
11572 show_bgp_ipv4_safi_prefix_longer_cmd,
11573 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11574 SHOW_STR
11575 BGP_STR
11576 "Address family\n"
11577 "Address Family modifier\n"
11578 "Address Family modifier\n"
11579 "Address Family modifier\n"
11580 "Address Family modifier\n"
11581 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11582 "Display route and more specific routes\n")
11583{
11584 safi_t safi;
11585
11586 if (bgp_parse_safi(argv[0], &safi)) {
11587 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11588 return CMD_WARNING;
11589 }
11590
11591 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11592 bgp_show_type_prefix_longer);
11593}
11594
Lou Berger651b4022016-01-12 13:42:07 -050011595DEFUN (show_bgp_ipv6_safi_prefix_longer,
11596 show_bgp_ipv6_safi_prefix_longer_cmd,
11597 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11598 SHOW_STR
11599 BGP_STR
11600 "Address family\n"
11601 "Address Family modifier\n"
11602 "Address Family modifier\n"
11603 "Address Family modifier\n"
11604 "Address Family modifier\n"
11605 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11606 "Display route and more specific routes\n")
11607{
11608 safi_t safi;
11609
11610 if (bgp_parse_safi(argv[0], &safi)) {
11611 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11612 return CMD_WARNING;
11613 }
11614
11615 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11616 bgp_show_type_prefix_longer);
11617}
Lou Berger651b4022016-01-12 13:42:07 -050011618
11619DEFUN (show_bgp_ipv4_safi_flap_address,
11620 show_bgp_ipv4_safi_flap_address_cmd,
11621 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
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 "Network in the BGP routing table to display\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[0], VTY_NEWLINE);
11636 return CMD_WARNING;
11637 }
11638 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011639 bgp_show_type_flap_address);
11640}
Lou Berger651b4022016-01-12 13:42:07 -050011641ALIAS (show_bgp_ipv4_safi_flap_address,
11642 show_bgp_ipv4_safi_damp_flap_address_cmd,
11643 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011644 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011645 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011646 "Address family\n"
11647 "Address Family modifier\n"
11648 "Address Family modifier\n"
11649 "Address Family modifier\n"
11650 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011651 "Display detailed information about dampening\n"
11652 "Display flap statistics of routes\n"
11653 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011654
Lou Berger651b4022016-01-12 13:42:07 -050011655DEFUN (show_bgp_ipv6_flap_address,
11656 show_bgp_ipv6_flap_address_cmd,
11657 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011658 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011659 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011660 "Address family\n"
11661 "Address Family modifier\n"
11662 "Address Family modifier\n"
11663 "Address Family modifier\n"
11664 "Address Family modifier\n"
11665 "Display flap statistics of routes\n"
11666 "Network in the BGP routing table to display\n")
11667{
11668 safi_t safi;
11669
11670 if (bgp_parse_safi(argv[0], &safi)) {
11671 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11672 return CMD_WARNING;
11673 }
11674 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11675 bgp_show_type_flap_address);
11676}
11677ALIAS (show_bgp_ipv6_flap_address,
11678 show_bgp_ipv6_damp_flap_address_cmd,
11679 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11680 SHOW_STR
11681 BGP_STR
11682 "Address family\n"
11683 "Address Family modifier\n"
11684 "Address Family modifier\n"
11685 "Address Family modifier\n"
11686 "Address Family modifier\n"
11687 "Display detailed information about dampening\n"
11688 "Display flap statistics of routes\n"
11689 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011690
11691DEFUN (show_bgp_ipv4_safi_flap_prefix,
11692 show_bgp_ipv4_safi_flap_prefix_cmd,
11693 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11694 SHOW_STR
11695 BGP_STR
11696 "Address family\n"
11697 "Address Family modifier\n"
11698 "Address Family modifier\n"
11699 "Address Family modifier\n"
11700 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011701 "Display flap statistics of routes\n"
11702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11703{
Lou Berger651b4022016-01-12 13:42:07 -050011704 safi_t safi;
11705
11706 if (bgp_parse_safi(argv[0], &safi)) {
11707 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11708 return CMD_WARNING;
11709 }
11710 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011711 bgp_show_type_flap_prefix);
11712}
Balaji3921cc52015-05-16 23:12:17 +053011713
Lou Berger651b4022016-01-12 13:42:07 -050011714ALIAS (show_bgp_ipv4_safi_flap_prefix,
11715 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11716 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011717 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011718 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011719 "Address family\n"
11720 "Address Family modifier\n"
11721 "Address Family modifier\n"
11722 "Address Family modifier\n"
11723 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011724 "Display detailed information about dampening\n"
11725 "Display flap statistics of routes\n"
11726 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11727
Lou Berger651b4022016-01-12 13:42:07 -050011728DEFUN (show_bgp_ipv6_safi_flap_prefix,
11729 show_bgp_ipv6_safi_flap_prefix_cmd,
11730 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011731 SHOW_STR
11732 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011733 "Address family\n"
11734 "Address Family modifier\n"
11735 "Address Family modifier\n"
11736 "Address Family modifier\n"
11737 "Address Family modifier\n"
11738 "Display flap statistics of routes\n"
11739 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011740{
Lou Berger651b4022016-01-12 13:42:07 -050011741 safi_t safi;
11742
11743 if (bgp_parse_safi(argv[0], &safi)) {
11744 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11745 return CMD_WARNING;
11746 }
11747 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11748 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011749}
11750
Lou Berger651b4022016-01-12 13:42:07 -050011751ALIAS (show_bgp_ipv6_safi_flap_prefix,
11752 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11753 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11754 SHOW_STR
11755 BGP_STR
11756 "Address family\n"
11757 "Address Family modifier\n"
11758 "Address Family modifier\n"
11759 "Address Family modifier\n"
11760 "Address Family modifier\n"
11761 "Display detailed information about dampening\n"
11762 "Display flap statistics of routes\n"
11763 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11764
11765DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011766 show_bgp_ipv6_prefix_longer_cmd,
11767 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11768 SHOW_STR
11769 BGP_STR
11770 "Address family\n"
11771 "IPv6 prefix <network>/<length>\n"
11772 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011773{
11774 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11775 bgp_show_type_prefix_longer);
11776}
11777
paul94f2b392005-06-28 12:44:16 +000011778static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011779peer_lookup_in_view (struct vty *vty, const char *view_name,
11780 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011781{
11782 int ret;
11783 struct bgp *bgp;
11784 struct peer *peer;
11785 union sockunion su;
11786
11787 /* BGP structure lookup. */
11788 if (view_name)
11789 {
11790 bgp = bgp_lookup_by_name (view_name);
11791 if (! bgp)
11792 {
11793 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11794 return NULL;
11795 }
11796 }
paul5228ad22004-06-04 17:58:18 +000011797 else
paulbb46e942003-10-24 19:02:03 +000011798 {
11799 bgp = bgp_get_default ();
11800 if (! bgp)
11801 {
11802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11803 return NULL;
11804 }
11805 }
11806
11807 /* Get peer sockunion. */
11808 ret = str2sockunion (ip_str, &su);
11809 if (ret < 0)
11810 {
11811 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11812 return NULL;
11813 }
11814
11815 /* Peer structure lookup. */
11816 peer = peer_lookup (bgp, &su);
11817 if (! peer)
11818 {
11819 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11820 return NULL;
11821 }
11822
11823 return peer;
11824}
David Lamparter6b0655a2014-06-04 06:53:35 +020011825
Paul Jakma2815e612006-09-14 02:56:07 +000011826enum bgp_stats
11827{
11828 BGP_STATS_MAXBITLEN = 0,
11829 BGP_STATS_RIB,
11830 BGP_STATS_PREFIXES,
11831 BGP_STATS_TOTPLEN,
11832 BGP_STATS_UNAGGREGATEABLE,
11833 BGP_STATS_MAX_AGGREGATEABLE,
11834 BGP_STATS_AGGREGATES,
11835 BGP_STATS_SPACE,
11836 BGP_STATS_ASPATH_COUNT,
11837 BGP_STATS_ASPATH_MAXHOPS,
11838 BGP_STATS_ASPATH_TOTHOPS,
11839 BGP_STATS_ASPATH_MAXSIZE,
11840 BGP_STATS_ASPATH_TOTSIZE,
11841 BGP_STATS_ASN_HIGHEST,
11842 BGP_STATS_MAX,
11843};
paulbb46e942003-10-24 19:02:03 +000011844
Paul Jakma2815e612006-09-14 02:56:07 +000011845static const char *table_stats_strs[] =
11846{
11847 [BGP_STATS_PREFIXES] = "Total Prefixes",
11848 [BGP_STATS_TOTPLEN] = "Average prefix length",
11849 [BGP_STATS_RIB] = "Total Advertisements",
11850 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11851 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11852 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11853 [BGP_STATS_SPACE] = "Address space advertised",
11854 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11855 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11856 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11857 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11858 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11859 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11860 [BGP_STATS_MAX] = NULL,
11861};
11862
11863struct bgp_table_stats
11864{
11865 struct bgp_table *table;
11866 unsigned long long counts[BGP_STATS_MAX];
11867};
11868
11869#if 0
11870#define TALLY_SIGFIG 100000
11871static unsigned long
11872ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11873{
11874 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11875 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11876 unsigned long ret = newtot / count;
11877
11878 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11879 return ret + 1;
11880 else
11881 return ret;
11882}
11883#endif
11884
11885static int
11886bgp_table_stats_walker (struct thread *t)
11887{
11888 struct bgp_node *rn;
11889 struct bgp_node *top;
11890 struct bgp_table_stats *ts = THREAD_ARG (t);
11891 unsigned int space = 0;
11892
Paul Jakma53d9f672006-10-15 23:41:16 +000011893 if (!(top = bgp_table_top (ts->table)))
11894 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011895
11896 switch (top->p.family)
11897 {
11898 case AF_INET:
11899 space = IPV4_MAX_BITLEN;
11900 break;
11901 case AF_INET6:
11902 space = IPV6_MAX_BITLEN;
11903 break;
11904 }
11905
11906 ts->counts[BGP_STATS_MAXBITLEN] = space;
11907
11908 for (rn = top; rn; rn = bgp_route_next (rn))
11909 {
11910 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011911 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011912 unsigned int rinum = 0;
11913
11914 if (rn == top)
11915 continue;
11916
11917 if (!rn->info)
11918 continue;
11919
11920 ts->counts[BGP_STATS_PREFIXES]++;
11921 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11922
11923#if 0
11924 ts->counts[BGP_STATS_AVGPLEN]
11925 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11926 ts->counts[BGP_STATS_AVGPLEN],
11927 rn->p.prefixlen);
11928#endif
11929
11930 /* check if the prefix is included by any other announcements */
11931 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011932 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011933
11934 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011935 {
11936 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11937 /* announced address space */
11938 if (space)
11939 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11940 }
Paul Jakma2815e612006-09-14 02:56:07 +000011941 else if (prn->info)
11942 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11943
Paul Jakma2815e612006-09-14 02:56:07 +000011944 for (ri = rn->info; ri; ri = ri->next)
11945 {
11946 rinum++;
11947 ts->counts[BGP_STATS_RIB]++;
11948
11949 if (ri->attr &&
11950 (CHECK_FLAG (ri->attr->flag,
11951 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11952 ts->counts[BGP_STATS_AGGREGATES]++;
11953
11954 /* as-path stats */
11955 if (ri->attr && ri->attr->aspath)
11956 {
11957 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11958 unsigned int size = aspath_size (ri->attr->aspath);
11959 as_t highest = aspath_highest (ri->attr->aspath);
11960
11961 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11962
11963 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11964 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11965
11966 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11967 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11968
11969 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11970 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11971#if 0
11972 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11973 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11974 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11975 hops);
11976 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11977 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11978 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11979 size);
11980#endif
11981 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11982 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11983 }
11984 }
11985 }
11986 return 0;
11987}
11988
11989static int
11990bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11991{
11992 struct bgp_table_stats ts;
11993 unsigned int i;
11994
11995 if (!bgp->rib[afi][safi])
11996 {
Donald Sharp3c964042016-01-25 23:38:53 -050011997 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
11998 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000011999 return CMD_WARNING;
12000 }
12001
12002 memset (&ts, 0, sizeof (ts));
12003 ts.table = bgp->rib[afi][safi];
12004 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12005
12006 vty_out (vty, "BGP %s RIB statistics%s%s",
12007 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12008
12009 for (i = 0; i < BGP_STATS_MAX; i++)
12010 {
12011 if (!table_stats_strs[i])
12012 continue;
12013
12014 switch (i)
12015 {
12016#if 0
12017 case BGP_STATS_ASPATH_AVGHOPS:
12018 case BGP_STATS_ASPATH_AVGSIZE:
12019 case BGP_STATS_AVGPLEN:
12020 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12021 vty_out (vty, "%12.2f",
12022 (float)ts.counts[i] / (float)TALLY_SIGFIG);
12023 break;
12024#endif
12025 case BGP_STATS_ASPATH_TOTHOPS:
12026 case BGP_STATS_ASPATH_TOTSIZE:
12027 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12028 vty_out (vty, "%12.2f",
12029 ts.counts[i] ?
12030 (float)ts.counts[i] /
12031 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
12032 : 0);
12033 break;
12034 case BGP_STATS_TOTPLEN:
12035 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12036 vty_out (vty, "%12.2f",
12037 ts.counts[i] ?
12038 (float)ts.counts[i] /
12039 (float)ts.counts[BGP_STATS_PREFIXES]
12040 : 0);
12041 break;
12042 case BGP_STATS_SPACE:
12043 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12044 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
12045 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
12046 break;
Paul Jakma30a22312008-08-15 14:05:22 +010012047 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000012048 vty_out (vty, "%12.2f%s",
12049 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000012050 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000012051 VTY_NEWLINE);
12052 vty_out (vty, "%30s: ", "/8 equivalent ");
12053 vty_out (vty, "%12.2f%s",
12054 (float)ts.counts[BGP_STATS_SPACE] /
12055 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
12056 VTY_NEWLINE);
12057 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
12058 break;
12059 vty_out (vty, "%30s: ", "/24 equivalent ");
12060 vty_out (vty, "%12.2f",
12061 (float)ts.counts[BGP_STATS_SPACE] /
12062 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
12063 break;
12064 default:
12065 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12066 vty_out (vty, "%12llu", ts.counts[i]);
12067 }
12068
12069 vty_out (vty, "%s", VTY_NEWLINE);
12070 }
12071 return CMD_SUCCESS;
12072}
12073
12074static int
12075bgp_table_stats_vty (struct vty *vty, const char *name,
12076 const char *afi_str, const char *safi_str)
12077{
12078 struct bgp *bgp;
12079 afi_t afi;
12080 safi_t safi;
12081
12082 if (name)
12083 bgp = bgp_lookup_by_name (name);
12084 else
12085 bgp = bgp_get_default ();
12086
12087 if (!bgp)
12088 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012089 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012090 return CMD_WARNING;
12091 }
12092 if (strncmp (afi_str, "ipv", 3) == 0)
12093 {
12094 if (strncmp (afi_str, "ipv4", 4) == 0)
12095 afi = AFI_IP;
12096 else if (strncmp (afi_str, "ipv6", 4) == 0)
12097 afi = AFI_IP6;
12098 else
12099 {
12100 vty_out (vty, "%% Invalid address family %s%s",
12101 afi_str, VTY_NEWLINE);
12102 return CMD_WARNING;
12103 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012104 switch (safi_str[0]) {
12105 case 'm':
12106 safi = SAFI_MULTICAST;
12107 break;
12108 case 'u':
12109 safi = SAFI_UNICAST;
12110 break;
12111 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050012112 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050012113 break;
12114 case 'e':
12115 safi = SAFI_ENCAP;
12116 break;
12117 default:
12118 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012119 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012120 return CMD_WARNING;
12121 }
Paul Jakma2815e612006-09-14 02:56:07 +000012122 }
12123 else
12124 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012125 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012126 afi_str, VTY_NEWLINE);
12127 return CMD_WARNING;
12128 }
12129
Paul Jakma2815e612006-09-14 02:56:07 +000012130 return bgp_table_stats (vty, bgp, afi, safi);
12131}
12132
12133DEFUN (show_bgp_statistics,
12134 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012135 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012136 SHOW_STR
12137 BGP_STR
12138 "Address family\n"
12139 "Address family\n"
12140 "Address Family modifier\n"
12141 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012142 "Address Family modifier\n"
12143 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012144 "BGP RIB advertisement statistics\n")
12145{
12146 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12147}
12148
Lou Bergerf9b6c392016-01-12 13:42:09 -050012149ALIAS (show_bgp_statistics,
12150 show_bgp_statistics_vpnv4_cmd,
12151 "show bgp (ipv4) (vpnv4) statistics",
12152 SHOW_STR
12153 BGP_STR
12154 "Address family\n"
12155 "Address Family modifier\n"
12156 "BGP RIB advertisement statistics\n")
12157
Paul Jakma2815e612006-09-14 02:56:07 +000012158DEFUN (show_bgp_statistics_view,
12159 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012160 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012161 SHOW_STR
12162 BGP_STR
12163 "BGP view\n"
12164 "Address family\n"
12165 "Address family\n"
12166 "Address Family modifier\n"
12167 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012168 "Address Family modifier\n"
12169 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012170 "BGP RIB advertisement statistics\n")
12171{
12172 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12173}
12174
12175ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012176 show_bgp_statistics_view_vpnv4_cmd,
12177 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012178 SHOW_STR
12179 BGP_STR
12180 "BGP view\n"
12181 "Address family\n"
12182 "Address Family modifier\n"
12183 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012184
Paul Jakmaff7924f2006-09-04 01:10:36 +000012185enum bgp_pcounts
12186{
12187 PCOUNT_ADJ_IN = 0,
12188 PCOUNT_DAMPED,
12189 PCOUNT_REMOVED,
12190 PCOUNT_HISTORY,
12191 PCOUNT_STALE,
12192 PCOUNT_VALID,
12193 PCOUNT_ALL,
12194 PCOUNT_COUNTED,
12195 PCOUNT_PFCNT, /* the figure we display to users */
12196 PCOUNT_MAX,
12197};
12198
12199static const char *pcount_strs[] =
12200{
12201 [PCOUNT_ADJ_IN] = "Adj-in",
12202 [PCOUNT_DAMPED] = "Damped",
12203 [PCOUNT_REMOVED] = "Removed",
12204 [PCOUNT_HISTORY] = "History",
12205 [PCOUNT_STALE] = "Stale",
12206 [PCOUNT_VALID] = "Valid",
12207 [PCOUNT_ALL] = "All RIB",
12208 [PCOUNT_COUNTED] = "PfxCt counted",
12209 [PCOUNT_PFCNT] = "Useable",
12210 [PCOUNT_MAX] = NULL,
12211};
12212
Paul Jakma2815e612006-09-14 02:56:07 +000012213struct peer_pcounts
12214{
12215 unsigned int count[PCOUNT_MAX];
12216 const struct peer *peer;
12217 const struct bgp_table *table;
12218};
12219
Paul Jakmaff7924f2006-09-04 01:10:36 +000012220static int
Paul Jakma2815e612006-09-14 02:56:07 +000012221bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012222{
12223 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012224 struct peer_pcounts *pc = THREAD_ARG (t);
12225 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012226
Paul Jakma2815e612006-09-14 02:56:07 +000012227 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012228 {
12229 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012230 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012231
12232 for (ain = rn->adj_in; ain; ain = ain->next)
12233 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012234 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012235
Paul Jakmaff7924f2006-09-04 01:10:36 +000012236 for (ri = rn->info; ri; ri = ri->next)
12237 {
12238 char buf[SU_ADDRSTRLEN];
12239
12240 if (ri->peer != peer)
12241 continue;
12242
Paul Jakma2815e612006-09-14 02:56:07 +000012243 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012244
12245 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012246 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012247 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012248 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012249 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012250 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012251 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012252 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012253 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012254 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012255 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012256 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012257
12258 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12259 {
Paul Jakma2815e612006-09-14 02:56:07 +000012260 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012261 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012262 plog_warn (peer->log,
12263 "%s [pcount] %s/%d is counted but flags 0x%x",
12264 peer->host,
12265 inet_ntop(rn->p.family, &rn->p.u.prefix,
12266 buf, SU_ADDRSTRLEN),
12267 rn->p.prefixlen,
12268 ri->flags);
12269 }
12270 else
12271 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012272 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012273 plog_warn (peer->log,
12274 "%s [pcount] %s/%d not counted but flags 0x%x",
12275 peer->host,
12276 inet_ntop(rn->p.family, &rn->p.u.prefix,
12277 buf, SU_ADDRSTRLEN),
12278 rn->p.prefixlen,
12279 ri->flags);
12280 }
12281 }
12282 }
Paul Jakma2815e612006-09-14 02:56:07 +000012283 return 0;
12284}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012285
Paul Jakma2815e612006-09-14 02:56:07 +000012286static int
12287bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12288{
12289 struct peer_pcounts pcounts = { .peer = peer };
12290 unsigned int i;
12291
12292 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12293 || !peer->bgp->rib[afi][safi])
12294 {
12295 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12296 return CMD_WARNING;
12297 }
12298
12299 memset (&pcounts, 0, sizeof(pcounts));
12300 pcounts.peer = peer;
12301 pcounts.table = peer->bgp->rib[afi][safi];
12302
12303 /* in-place call via thread subsystem so as to record execution time
12304 * stats for the thread-walk (i.e. ensure this can't be blamed on
12305 * on just vty_read()).
12306 */
12307 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12308
Paul Jakmaff7924f2006-09-04 01:10:36 +000012309 vty_out (vty, "Prefix counts for %s, %s%s",
12310 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12311 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12312 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12313 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12314
12315 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012316 vty_out (vty, "%20s: %-10d%s",
12317 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012318
Paul Jakma2815e612006-09-14 02:56:07 +000012319 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012320 {
12321 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12322 peer->host, VTY_NEWLINE);
12323 vty_out (vty, "Please report this bug, with the above command output%s",
12324 VTY_NEWLINE);
12325 }
12326
12327 return CMD_SUCCESS;
12328}
12329
Lou Bergerf9b6c392016-01-12 13:42:09 -050012330DEFUN (show_ip_bgp_neighbor_prefix_counts,
12331 show_ip_bgp_neighbor_prefix_counts_cmd,
12332 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12333 SHOW_STR
12334 IP_STR
12335 BGP_STR
12336 "Detailed information on TCP and BGP neighbor connections\n"
12337 "Neighbor to display information about\n"
12338 "Neighbor to display information about\n"
12339 "Display detailed prefix count information\n")
12340{
12341 struct peer *peer;
12342
12343 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12344 if (! peer)
12345 return CMD_WARNING;
12346
12347 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12348}
12349
Paul Jakmaff7924f2006-09-04 01:10:36 +000012350DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12351 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12352 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12353 SHOW_STR
12354 BGP_STR
12355 "Address family\n"
12356 "Detailed information on TCP and BGP neighbor connections\n"
12357 "Neighbor to display information about\n"
12358 "Neighbor to display information about\n"
12359 "Display detailed prefix count information\n")
12360{
12361 struct peer *peer;
12362
12363 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12364 if (! peer)
12365 return CMD_WARNING;
12366
12367 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12368}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012369
12370DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12371 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12372 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12373 SHOW_STR
12374 IP_STR
12375 BGP_STR
12376 "Address family\n"
12377 "Address Family modifier\n"
12378 "Address Family modifier\n"
12379 "Detailed information on TCP and BGP neighbor connections\n"
12380 "Neighbor to display information about\n"
12381 "Neighbor to display information about\n"
12382 "Display detailed prefix count information\n")
12383{
12384 struct peer *peer;
12385
12386 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12387 if (! peer)
12388 return CMD_WARNING;
12389
12390 if (strncmp (argv[0], "m", 1) == 0)
12391 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12392
12393 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12394}
12395
12396DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12397 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12398 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12399 SHOW_STR
12400 IP_STR
12401 BGP_STR
12402 "Address family\n"
12403 "Address Family modifier\n"
12404 "Address Family modifier\n"
12405 "Detailed information on TCP and BGP neighbor connections\n"
12406 "Neighbor to display information about\n"
12407 "Neighbor to display information about\n"
12408 "Display detailed prefix count information\n")
12409{
12410 struct peer *peer;
12411
12412 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12413 if (! peer)
12414 return CMD_WARNING;
12415
12416 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12417}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012418
Lou Berger651b4022016-01-12 13:42:07 -050012419DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12420 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12421 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012422 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012423 BGP_STR
12424 "Address family\n"
12425 "Address Family modifier\n"
12426 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012427 "Address Family modifier\n"
12428 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012429 "Detailed information on TCP and BGP neighbor connections\n"
12430 "Neighbor to display information about\n"
12431 "Neighbor to display information about\n"
12432 "Display detailed prefix count information\n")
12433{
12434 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012435 safi_t safi;
12436
12437 if (bgp_parse_safi(argv[0], &safi)) {
12438 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12439 return CMD_WARNING;
12440 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012441
12442 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12443 if (! peer)
12444 return CMD_WARNING;
12445
Lou Berger651b4022016-01-12 13:42:07 -050012446 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012447}
Lou Berger205e6742016-01-12 13:42:11 -050012448
Lou Berger651b4022016-01-12 13:42:07 -050012449DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12450 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12451 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12452 SHOW_STR
12453 BGP_STR
12454 "Address family\n"
12455 "Address Family modifier\n"
12456 "Address Family modifier\n"
12457 "Address Family modifier\n"
12458 "Address Family modifier\n"
12459 "Detailed information on TCP and BGP neighbor connections\n"
12460 "Neighbor to display information about\n"
12461 "Neighbor to display information about\n"
12462 "Display detailed prefix count information\n")
12463{
12464 struct peer *peer;
12465 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012466
Lou Berger651b4022016-01-12 13:42:07 -050012467 if (bgp_parse_safi(argv[0], &safi)) {
12468 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12469 return CMD_WARNING;
12470 }
12471
12472 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12473 if (! peer)
12474 return CMD_WARNING;
12475
12476 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12477}
Lou Berger651b4022016-01-12 13:42:07 -050012478
12479DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12480 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12481 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012482 SHOW_STR
12483 IP_STR
12484 BGP_STR
12485 "Address family\n"
12486 "Address Family modifier\n"
12487 "Address Family modifier\n"
12488 "Detailed information on TCP and BGP neighbor connections\n"
12489 "Neighbor to display information about\n"
12490 "Neighbor to display information about\n"
12491 "Display detailed prefix count information\n")
12492{
12493 struct peer *peer;
12494
12495 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12496 if (! peer)
12497 return CMD_WARNING;
12498
Lou Berger651b4022016-01-12 13:42:07 -050012499 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012500}
12501
12502
paul94f2b392005-06-28 12:44:16 +000012503static void
paul718e3742002-12-13 20:15:29 +000012504show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12505 int in)
12506{
12507 struct bgp_table *table;
12508 struct bgp_adj_in *ain;
12509 struct bgp_adj_out *adj;
12510 unsigned long output_count;
12511 struct bgp_node *rn;
12512 int header1 = 1;
12513 struct bgp *bgp;
12514 int header2 = 1;
12515
paulbb46e942003-10-24 19:02:03 +000012516 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012517
12518 if (! bgp)
12519 return;
12520
12521 table = bgp->rib[afi][safi];
12522
12523 output_count = 0;
12524
12525 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12526 PEER_STATUS_DEFAULT_ORIGINATE))
12527 {
12528 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 +000012529 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12530 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012531
12532 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12533 VTY_NEWLINE, VTY_NEWLINE);
12534 header1 = 0;
12535 }
12536
12537 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12538 if (in)
12539 {
12540 for (ain = rn->adj_in; ain; ain = ain->next)
12541 if (ain->peer == peer)
12542 {
12543 if (header1)
12544 {
12545 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 +000012546 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12547 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012548 header1 = 0;
12549 }
12550 if (header2)
12551 {
12552 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12553 header2 = 0;
12554 }
12555 if (ain->attr)
12556 {
12557 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12558 output_count++;
12559 }
12560 }
12561 }
12562 else
12563 {
12564 for (adj = rn->adj_out; adj; adj = adj->next)
12565 if (adj->peer == peer)
12566 {
12567 if (header1)
12568 {
12569 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 +000012570 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12571 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012572 header1 = 0;
12573 }
12574 if (header2)
12575 {
12576 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12577 header2 = 0;
12578 }
12579 if (adj->attr)
12580 {
12581 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12582 output_count++;
12583 }
12584 }
12585 }
12586
12587 if (output_count != 0)
12588 vty_out (vty, "%sTotal number of prefixes %ld%s",
12589 VTY_NEWLINE, output_count, VTY_NEWLINE);
12590}
12591
paul94f2b392005-06-28 12:44:16 +000012592static int
paulbb46e942003-10-24 19:02:03 +000012593peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12594{
paul718e3742002-12-13 20:15:29 +000012595 if (! peer || ! peer->afc[afi][safi])
12596 {
12597 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12598 return CMD_WARNING;
12599 }
12600
12601 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12602 {
12603 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12604 VTY_NEWLINE);
12605 return CMD_WARNING;
12606 }
12607
12608 show_adj_route (vty, peer, afi, safi, in);
12609
12610 return CMD_SUCCESS;
12611}
12612
Lou Bergerf9b6c392016-01-12 13:42:09 -050012613DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12614 show_ip_bgp_view_neighbor_advertised_route_cmd,
12615 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12616 SHOW_STR
12617 IP_STR
12618 BGP_STR
12619 "BGP view\n"
12620 "View name\n"
12621 "Detailed information on TCP and BGP neighbor connections\n"
12622 "Neighbor to display information about\n"
12623 "Neighbor to display information about\n"
12624 "Display the routes advertised to a BGP neighbor\n")
12625{
12626 struct peer *peer;
12627
12628 if (argc == 2)
12629 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12630 else
12631 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12632
12633 if (! peer)
12634 return CMD_WARNING;
12635
12636 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12637}
12638
12639ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12640 show_ip_bgp_neighbor_advertised_route_cmd,
12641 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12642 SHOW_STR
12643 IP_STR
12644 BGP_STR
12645 "Detailed information on TCP and BGP neighbor connections\n"
12646 "Neighbor to display information about\n"
12647 "Neighbor to display information about\n"
12648 "Display the routes advertised to a BGP neighbor\n")
12649
12650DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12651 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12652 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12653 SHOW_STR
12654 IP_STR
12655 BGP_STR
12656 "Address family\n"
12657 "Address Family modifier\n"
12658 "Address Family modifier\n"
12659 "Detailed information on TCP and BGP neighbor connections\n"
12660 "Neighbor to display information about\n"
12661 "Neighbor to display information about\n"
12662 "Display the routes advertised to a BGP neighbor\n")
12663{
12664 struct peer *peer;
12665
12666 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12667 if (! peer)
12668 return CMD_WARNING;
12669
12670 if (strncmp (argv[0], "m", 1) == 0)
12671 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12672
12673 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12674}
12675
Lou Bergerf9b6c392016-01-12 13:42:09 -050012676DEFUN (show_bgp_view_neighbor_advertised_route,
12677 show_bgp_view_neighbor_advertised_route_cmd,
12678 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12679 SHOW_STR
12680 BGP_STR
12681 "BGP view\n"
12682 "View name\n"
12683 "Detailed information on TCP and BGP neighbor connections\n"
12684 "Neighbor to display information about\n"
12685 "Neighbor to display information about\n"
12686 "Display the routes advertised to a BGP neighbor\n")
12687{
12688 struct peer *peer;
12689
12690 if (argc == 2)
12691 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12692 else
12693 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12694
12695 if (! peer)
12696 return CMD_WARNING;
12697
12698 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12699}
12700
12701DEFUN (show_bgp_view_neighbor_received_routes,
12702 show_bgp_view_neighbor_received_routes_cmd,
12703 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12704 SHOW_STR
12705 BGP_STR
12706 "BGP view\n"
12707 "View name\n"
12708 "Detailed information on TCP and BGP neighbor connections\n"
12709 "Neighbor to display information about\n"
12710 "Neighbor to display information about\n"
12711 "Display the received routes from neighbor\n")
12712{
12713 struct peer *peer;
12714
12715 if (argc == 2)
12716 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12717 else
12718 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12719
12720 if (! peer)
12721 return CMD_WARNING;
12722
12723 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12724}
12725
12726ALIAS (show_bgp_view_neighbor_advertised_route,
12727 show_bgp_neighbor_advertised_route_cmd,
12728 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12729 SHOW_STR
12730 BGP_STR
12731 "Detailed information on TCP and BGP neighbor connections\n"
12732 "Neighbor to display information about\n"
12733 "Neighbor to display information about\n"
12734 "Display the routes advertised to a BGP neighbor\n")
12735
12736ALIAS (show_bgp_view_neighbor_advertised_route,
12737 show_bgp_ipv6_neighbor_advertised_route_cmd,
12738 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12739 SHOW_STR
12740 BGP_STR
12741 "Address family\n"
12742 "Detailed information on TCP and BGP neighbor connections\n"
12743 "Neighbor to display information about\n"
12744 "Neighbor to display information about\n"
12745 "Display the routes advertised to a BGP neighbor\n")
12746
12747/* old command */
12748ALIAS (show_bgp_view_neighbor_advertised_route,
12749 ipv6_bgp_neighbor_advertised_route_cmd,
12750 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12751 SHOW_STR
12752 IPV6_STR
12753 BGP_STR
12754 "Detailed information on TCP and BGP neighbor connections\n"
12755 "Neighbor to display information about\n"
12756 "Neighbor to display information about\n"
12757 "Display the routes advertised to a BGP neighbor\n")
12758
12759/* old command */
12760DEFUN (ipv6_mbgp_neighbor_advertised_route,
12761 ipv6_mbgp_neighbor_advertised_route_cmd,
12762 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12763 SHOW_STR
12764 IPV6_STR
12765 MBGP_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 the routes advertised to a BGP neighbor\n")
12770{
12771 struct peer *peer;
12772
12773 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12774 if (! peer)
12775 return CMD_WARNING;
12776
12777 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12778}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012779
12780DEFUN (show_ip_bgp_view_neighbor_received_routes,
12781 show_ip_bgp_view_neighbor_received_routes_cmd,
12782 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12783 SHOW_STR
12784 IP_STR
12785 BGP_STR
12786 "BGP view\n"
12787 "View name\n"
12788 "Detailed information on TCP and BGP neighbor connections\n"
12789 "Neighbor to display information about\n"
12790 "Neighbor to display information about\n"
12791 "Display the received routes from neighbor\n")
12792{
12793 struct peer *peer;
12794
12795 if (argc == 2)
12796 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12797 else
12798 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12799
12800 if (! peer)
12801 return CMD_WARNING;
12802
12803 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12804}
12805
12806ALIAS (show_ip_bgp_view_neighbor_received_routes,
12807 show_ip_bgp_neighbor_received_routes_cmd,
12808 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12809 SHOW_STR
12810 IP_STR
12811 BGP_STR
12812 "Detailed information on TCP and BGP neighbor connections\n"
12813 "Neighbor to display information about\n"
12814 "Neighbor to display information about\n"
12815 "Display the received routes from neighbor\n")
12816
12817ALIAS (show_bgp_view_neighbor_received_routes,
12818 show_bgp_ipv6_neighbor_received_routes_cmd,
12819 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12820 SHOW_STR
12821 BGP_STR
12822 "Address family\n"
12823 "Detailed information on TCP and BGP neighbor connections\n"
12824 "Neighbor to display information about\n"
12825 "Neighbor to display information about\n"
12826 "Display the received routes from neighbor\n")
12827
12828DEFUN (show_bgp_neighbor_received_prefix_filter,
12829 show_bgp_neighbor_received_prefix_filter_cmd,
12830 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12831 SHOW_STR
12832 BGP_STR
12833 "Detailed information on TCP and BGP neighbor connections\n"
12834 "Neighbor to display information about\n"
12835 "Neighbor to display information about\n"
12836 "Display information received from a BGP neighbor\n"
12837 "Display the prefixlist filter\n")
12838{
12839 char name[BUFSIZ];
12840 union sockunion su;
12841 struct peer *peer;
12842 int count, ret;
12843
12844 ret = str2sockunion (argv[0], &su);
12845 if (ret < 0)
12846 {
12847 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12848 return CMD_WARNING;
12849 }
12850
12851 peer = peer_lookup (NULL, &su);
12852 if (! peer)
12853 return CMD_WARNING;
12854
12855 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12856 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12857 if (count)
12858 {
12859 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12860 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12861 }
12862
12863 return CMD_SUCCESS;
12864}
12865
12866/* old command */
12867ALIAS (show_bgp_view_neighbor_received_routes,
12868 ipv6_bgp_neighbor_received_routes_cmd,
12869 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12870 SHOW_STR
12871 IPV6_STR
12872 BGP_STR
12873 "Detailed information on TCP and BGP neighbor connections\n"
12874 "Neighbor to display information about\n"
12875 "Neighbor to display information about\n"
12876 "Display the received routes from neighbor\n")
12877
12878/* old command */
12879DEFUN (ipv6_mbgp_neighbor_received_routes,
12880 ipv6_mbgp_neighbor_received_routes_cmd,
12881 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12882 SHOW_STR
12883 IPV6_STR
12884 MBGP_STR
12885 "Detailed information on TCP and BGP neighbor connections\n"
12886 "Neighbor to display information about\n"
12887 "Neighbor to display information about\n"
12888 "Display the received routes from neighbor\n")
12889{
12890 struct peer *peer;
12891
12892 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12893 if (! peer)
12894 return CMD_WARNING;
12895
12896 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12897}
12898
12899DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12900 show_bgp_view_neighbor_received_prefix_filter_cmd,
12901 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12902 SHOW_STR
12903 BGP_STR
12904 "BGP view\n"
12905 "View name\n"
12906 "Detailed information on TCP and BGP neighbor connections\n"
12907 "Neighbor to display information about\n"
12908 "Neighbor to display information about\n"
12909 "Display information received from a BGP neighbor\n"
12910 "Display the prefixlist filter\n")
12911{
12912 char name[BUFSIZ];
12913 union sockunion su;
12914 struct peer *peer;
12915 struct bgp *bgp;
12916 int count, ret;
12917
12918 /* BGP structure lookup. */
12919 bgp = bgp_lookup_by_name (argv[0]);
12920 if (bgp == NULL)
12921 {
12922 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12923 return CMD_WARNING;
12924 }
12925
12926 ret = str2sockunion (argv[1], &su);
12927 if (ret < 0)
12928 {
12929 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12930 return CMD_WARNING;
12931 }
12932
12933 peer = peer_lookup (bgp, &su);
12934 if (! peer)
12935 return CMD_WARNING;
12936
12937 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12938 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12939 if (count)
12940 {
12941 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12942 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12943 }
12944
12945 return CMD_SUCCESS;
12946}
12947
12948
12949DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12950 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12951 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12952 SHOW_STR
12953 IP_STR
12954 BGP_STR
12955 "Address family\n"
12956 "Address Family modifier\n"
12957 "Address Family modifier\n"
12958 "Detailed information on TCP and BGP neighbor connections\n"
12959 "Neighbor to display information about\n"
12960 "Neighbor to display information about\n"
12961 "Display the received routes from neighbor\n")
12962{
12963 struct peer *peer;
12964
12965 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12966 if (! peer)
12967 return CMD_WARNING;
12968
12969 if (strncmp (argv[0], "m", 1) == 0)
12970 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12971
12972 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12973}
12974
Lou Berger651b4022016-01-12 13:42:07 -050012975DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12976 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12977 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012978 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012979 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012980 "Address Family modifier\n"
12981 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012982 "Detailed information on TCP and BGP neighbor connections\n"
12983 "Neighbor to display information about\n"
12984 "Neighbor to display information about\n"
12985 "Display the routes advertised to a BGP neighbor\n")
12986{
12987 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012988 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012989
Lou Berger651b4022016-01-12 13:42:07 -050012990 if (bgp_parse_safi(argv[0], &safi)) {
12991 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012992 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012993 }
paul718e3742002-12-13 20:15:29 +000012994
paulbb46e942003-10-24 19:02:03 +000012995 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12996 if (! peer)
12997 return CMD_WARNING;
12998
Lou Berger651b4022016-01-12 13:42:07 -050012999 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13000}
Lou Berger205e6742016-01-12 13:42:11 -050013001
Lou Berger651b4022016-01-12 13:42:07 -050013002DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13003 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13004 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13005 SHOW_STR
13006 BGP_STR
13007 "Address Family modifier\n"
13008 "Address Family modifier\n"
13009 "Address Family modifier\n"
13010 "Detailed information on TCP and BGP neighbor connections\n"
13011 "Neighbor to display information about\n"
13012 "Neighbor to display information about\n"
13013 "Display the routes advertised to a BGP neighbor\n")
13014{
13015 struct peer *peer;
13016 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013017
Lou Berger651b4022016-01-12 13:42:07 -050013018 if (bgp_parse_safi(argv[0], &safi)) {
13019 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13020 return CMD_WARNING;
13021 }
13022
13023 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13024 if (! peer)
13025 return CMD_WARNING;
13026
13027 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000013028}
13029
Lou Bergerf9b6c392016-01-12 13:42:09 -050013030DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050013031 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
13032 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000013033 SHOW_STR
13034 BGP_STR
13035 "BGP view\n"
13036 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013037 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013038 "Detailed information on TCP and BGP neighbor connections\n"
13039 "Neighbor to display information about\n"
13040 "Neighbor to display information about\n"
13041 "Display the routes advertised to a BGP neighbor\n")
13042{
13043 struct peer *peer;
13044
13045 if (argc == 2)
13046 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13047 else
13048 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13049
13050 if (! peer)
13051 return CMD_WARNING;
13052
13053 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13054}
13055
Lou Bergerf9b6c392016-01-12 13:42:09 -050013056DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013057 show_bgp_view_ipv6_neighbor_received_routes_cmd,
13058 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000013059 SHOW_STR
13060 BGP_STR
13061 "BGP view\n"
13062 "View name\n"
13063 "Address family\n"
13064 "Detailed information on TCP and BGP neighbor connections\n"
13065 "Neighbor to display information about\n"
13066 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013067 "Display the received routes from neighbor\n")
13068{
13069 struct peer *peer;
13070
13071 if (argc == 2)
13072 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13073 else
13074 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13075
13076 if (! peer)
13077 return CMD_WARNING;
13078
13079 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13080}
Lou Berger651b4022016-01-12 13:42:07 -050013081
13082DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13083 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13084 "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 +010013085 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013086 BGP_STR
13087 "Address family\n"
13088 "Address Family modifier\n"
13089 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013090 "Address Family modifier\n"
13091 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013092 "Detailed information on TCP and BGP neighbor connections\n"
13093 "Neighbor to display information about\n"
13094 "Neighbor to display information about\n"
13095 "Display the received routes from neighbor\n")
13096{
paulbb46e942003-10-24 19:02:03 +000013097 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013098 safi_t safi;
13099
13100 if (bgp_parse_safi(argv[0], &safi)) {
13101 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13102 return CMD_WARNING;
13103 }
paul718e3742002-12-13 20:15:29 +000013104
paulbb46e942003-10-24 19:02:03 +000013105 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13106 if (! peer)
13107 return CMD_WARNING;
13108
Lou Berger651b4022016-01-12 13:42:07 -050013109 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013110}
Lou Berger205e6742016-01-12 13:42:11 -050013111
Lou Berger651b4022016-01-12 13:42:07 -050013112DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13113 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13114 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13115 SHOW_STR
13116 BGP_STR
13117 "Address family\n"
13118 "Address Family modifier\n"
13119 "Address Family modifier\n"
13120 "Address Family modifier\n"
13121 "Address Family modifier\n"
13122 "Detailed information on TCP and BGP neighbor connections\n"
13123 "Neighbor to display information about\n"
13124 "Neighbor to display information about\n"
13125 "Display the received routes from neighbor\n")
13126{
13127 struct peer *peer;
13128 safi_t safi;
13129
13130 if (bgp_parse_safi(argv[0], &safi)) {
13131 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13132 return CMD_WARNING;
13133 }
13134
13135 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13136 if (! peer)
13137 return CMD_WARNING;
13138
13139 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13140}
paul718e3742002-12-13 20:15:29 +000013141
Michael Lambert95cbbd22010-07-23 14:43:04 -040013142DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13143 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013144 "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 -040013145 SHOW_STR
13146 BGP_STR
13147 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013148 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013149 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013150 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013151 "Address family modifier\n"
13152 "Address family modifier\n"
13153 "Detailed information on TCP and BGP neighbor connections\n"
13154 "Neighbor to display information about\n"
13155 "Neighbor to display information about\n"
13156 "Display the advertised routes to neighbor\n"
13157 "Display the received routes from neighbor\n")
13158{
13159 int afi;
13160 int safi;
13161 int in;
13162 struct peer *peer;
13163
David Lamparter94bad672015-03-03 08:52:22 +010013164 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013165
13166 if (! peer)
13167 return CMD_WARNING;
13168
Michael Lambert95cbbd22010-07-23 14:43:04 -040013169 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13170 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13171 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013172
13173 return peer_adj_routes (vty, peer, afi, safi, in);
13174}
13175
Lou Bergerf9b6c392016-01-12 13:42:09 -050013176DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13177 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13178 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13179 SHOW_STR
13180 IP_STR
13181 BGP_STR
13182 "Detailed information on TCP and BGP neighbor connections\n"
13183 "Neighbor to display information about\n"
13184 "Neighbor to display information about\n"
13185 "Display information received from a BGP neighbor\n"
13186 "Display the prefixlist filter\n")
13187{
13188 char name[BUFSIZ];
13189 union sockunion su;
13190 struct peer *peer;
13191 int count, ret;
13192
13193 ret = str2sockunion (argv[0], &su);
13194 if (ret < 0)
13195 {
13196 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13197 return CMD_WARNING;
13198 }
13199
13200 peer = peer_lookup (NULL, &su);
13201 if (! peer)
13202 return CMD_WARNING;
13203
13204 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13205 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13206 if (count)
13207 {
13208 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13209 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13210 }
13211
13212 return CMD_SUCCESS;
13213}
13214
13215DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13216 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13217 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13218 SHOW_STR
13219 IP_STR
13220 BGP_STR
13221 "Address family\n"
13222 "Address Family modifier\n"
13223 "Address Family modifier\n"
13224 "Detailed information on TCP and BGP neighbor connections\n"
13225 "Neighbor to display information about\n"
13226 "Neighbor to display information about\n"
13227 "Display information received from a BGP neighbor\n"
13228 "Display the prefixlist filter\n")
13229{
13230 char name[BUFSIZ];
13231 union sockunion su;
13232 struct peer *peer;
13233 int count, ret;
13234
13235 ret = str2sockunion (argv[1], &su);
13236 if (ret < 0)
13237 {
13238 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13239 return CMD_WARNING;
13240 }
13241
13242 peer = peer_lookup (NULL, &su);
13243 if (! peer)
13244 return CMD_WARNING;
13245
13246 if (strncmp (argv[0], "m", 1) == 0)
13247 {
13248 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13249 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13250 if (count)
13251 {
13252 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13253 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13254 }
13255 }
13256 else
13257 {
13258 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13259 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13260 if (count)
13261 {
13262 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13263 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13264 }
13265 }
13266
13267 return CMD_SUCCESS;
13268}
13269
13270ALIAS (show_bgp_view_neighbor_received_routes,
13271 show_bgp_neighbor_received_routes_cmd,
13272 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13273 SHOW_STR
13274 BGP_STR
13275 "Detailed information on TCP and BGP neighbor connections\n"
13276 "Neighbor to display information about\n"
13277 "Neighbor to display information about\n"
13278 "Display the received routes from neighbor\n")
13279
Lou Berger651b4022016-01-12 13:42:07 -050013280DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13281 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13282 "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 +000013283 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013284 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013285 IP_STR
13286 "Address Family modifier\n"
13287 "Address Family modifier\n"
13288 "Address Family modifier\n"
13289 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013290 "Detailed information on TCP and BGP neighbor connections\n"
13291 "Neighbor to display information about\n"
13292 "Neighbor to display information about\n"
13293 "Display information received from a BGP neighbor\n"
13294 "Display the prefixlist filter\n")
13295{
13296 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013297 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013298 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013299 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013300 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013301
Lou Berger651b4022016-01-12 13:42:07 -050013302 if (bgp_parse_safi(argv[0], &safi)) {
13303 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013304 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013305 }
paul718e3742002-12-13 20:15:29 +000013306
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013307 ret = str2sockunion (argv[1], &su);
13308 if (ret < 0)
13309 {
13310 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13311 return CMD_WARNING;
13312 }
paul718e3742002-12-13 20:15:29 +000013313
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013314 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013315 if (! peer)
13316 return CMD_WARNING;
13317
Lou Berger651b4022016-01-12 13:42:07 -050013318 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13319 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13320 if (count) {
13321 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13322 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13323 }
paul718e3742002-12-13 20:15:29 +000013324
13325 return CMD_SUCCESS;
13326}
Lou Berger205e6742016-01-12 13:42:11 -050013327
Lou Berger651b4022016-01-12 13:42:07 -050013328DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13329 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13330 "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 +000013331 SHOW_STR
13332 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013333 IP_STR
13334 "Address Family modifier\n"
13335 "Address Family modifier\n"
13336 "Address Family modifier\n"
13337 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013338 "Detailed information on TCP and BGP neighbor connections\n"
13339 "Neighbor to display information about\n"
13340 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013341 "Display information received from a BGP neighbor\n"
13342 "Display the prefixlist filter\n")
13343{
13344 char name[BUFSIZ];
13345 union sockunion su;
13346 struct peer *peer;
13347 int count, ret;
13348 safi_t safi;
13349
13350 if (bgp_parse_safi(argv[0], &safi)) {
13351 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13352 return CMD_WARNING;
13353 }
13354
13355 ret = str2sockunion (argv[1], &su);
13356 if (ret < 0)
13357 {
13358 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13359 return CMD_WARNING;
13360 }
13361
13362 peer = peer_lookup (NULL, &su);
13363 if (! peer)
13364 return CMD_WARNING;
13365
13366 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13367 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13368 if (count) {
13369 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13370 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13371 }
13372
13373 return CMD_SUCCESS;
13374}
paul718e3742002-12-13 20:15:29 +000013375
Lou Bergerf9b6c392016-01-12 13:42:09 -050013376DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013377 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13378 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013379 SHOW_STR
13380 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013381 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013382 "Detailed information on TCP and BGP neighbor connections\n"
13383 "Neighbor to display information about\n"
13384 "Neighbor to display information about\n"
13385 "Display information received from a BGP neighbor\n"
13386 "Display the prefixlist filter\n")
13387{
13388 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013389 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013390 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013391 int count, ret;
paul718e3742002-12-13 20:15:29 +000013392
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013393 ret = str2sockunion (argv[0], &su);
13394 if (ret < 0)
13395 {
13396 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13397 return CMD_WARNING;
13398 }
paul718e3742002-12-13 20:15:29 +000013399
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013400 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013401 if (! peer)
13402 return CMD_WARNING;
13403
13404 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13405 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13406 if (count)
13407 {
13408 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13409 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13410 }
13411
13412 return CMD_SUCCESS;
13413}
13414
Lou Bergerf9b6c392016-01-12 13:42:09 -050013415DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013416 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13417 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013418 SHOW_STR
13419 BGP_STR
13420 "BGP view\n"
13421 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013422 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013423 "Detailed information on TCP and BGP neighbor connections\n"
13424 "Neighbor to display information about\n"
13425 "Neighbor to display information about\n"
13426 "Display information received from a BGP neighbor\n"
13427 "Display the prefixlist filter\n")
13428{
13429 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013430 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013431 struct peer *peer;
13432 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013433 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013434
13435 /* BGP structure lookup. */
13436 bgp = bgp_lookup_by_name (argv[0]);
13437 if (bgp == NULL)
13438 {
13439 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13440 return CMD_WARNING;
13441 }
13442
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013443 ret = str2sockunion (argv[1], &su);
13444 if (ret < 0)
13445 {
13446 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13447 return CMD_WARNING;
13448 }
paulbb46e942003-10-24 19:02:03 +000013449
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013450 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013451 if (! peer)
13452 return CMD_WARNING;
13453
13454 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13455 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13456 if (count)
13457 {
13458 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13459 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13460 }
13461
13462 return CMD_SUCCESS;
13463}
David Lamparter6b0655a2014-06-04 06:53:35 +020013464
paul94f2b392005-06-28 12:44:16 +000013465static int
paulbb46e942003-10-24 19:02:03 +000013466bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013467 safi_t safi, enum bgp_show_type type)
13468{
paul718e3742002-12-13 20:15:29 +000013469 if (! peer || ! peer->afc[afi][safi])
13470 {
13471 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013472 return CMD_WARNING;
13473 }
13474
ajs5a646652004-11-05 01:25:55 +000013475 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013476}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013477DEFUN (show_ip_bgp_neighbor_routes,
13478 show_ip_bgp_neighbor_routes_cmd,
13479 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13480 SHOW_STR
13481 IP_STR
13482 BGP_STR
13483 "Detailed information on TCP and BGP neighbor connections\n"
13484 "Neighbor to display information about\n"
13485 "Neighbor to display information about\n"
13486 "Display routes learned from neighbor\n")
13487{
13488 struct peer *peer;
13489
13490 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13491 if (! peer)
13492 return CMD_WARNING;
13493
13494 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13495 bgp_show_type_neighbor);
13496}
13497
13498DEFUN (show_ip_bgp_neighbor_flap,
13499 show_ip_bgp_neighbor_flap_cmd,
13500 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13501 SHOW_STR
13502 IP_STR
13503 BGP_STR
13504 "Detailed information on TCP and BGP neighbor connections\n"
13505 "Neighbor to display information about\n"
13506 "Neighbor to display information about\n"
13507 "Display flap statistics of the routes learned from neighbor\n")
13508{
13509 struct peer *peer;
13510
13511 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13512 if (! peer)
13513 return CMD_WARNING;
13514
13515 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13516 bgp_show_type_flap_neighbor);
13517}
13518
13519DEFUN (show_ip_bgp_neighbor_damp,
13520 show_ip_bgp_neighbor_damp_cmd,
13521 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13522 SHOW_STR
13523 IP_STR
13524 BGP_STR
13525 "Detailed information on TCP and BGP neighbor connections\n"
13526 "Neighbor to display information about\n"
13527 "Neighbor to display information about\n"
13528 "Display the dampened routes received from neighbor\n")
13529{
13530 struct peer *peer;
13531
13532 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13533 if (! peer)
13534 return CMD_WARNING;
13535
13536 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13537 bgp_show_type_damp_neighbor);
13538}
13539
13540DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13541 show_ip_bgp_ipv4_neighbor_routes_cmd,
13542 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13543 SHOW_STR
13544 IP_STR
13545 BGP_STR
13546 "Address family\n"
13547 "Address Family modifier\n"
13548 "Address Family modifier\n"
13549 "Detailed information on TCP and BGP neighbor connections\n"
13550 "Neighbor to display information about\n"
13551 "Neighbor to display information about\n"
13552 "Display routes learned from neighbor\n")
13553{
13554 struct peer *peer;
13555
13556 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13557 if (! peer)
13558 return CMD_WARNING;
13559
13560 if (strncmp (argv[0], "m", 1) == 0)
13561 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13562 bgp_show_type_neighbor);
13563
13564 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13565 bgp_show_type_neighbor);
13566}
13567
13568DEFUN (show_ip_bgp_view_rsclient,
13569 show_ip_bgp_view_rsclient_cmd,
13570 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13571 SHOW_STR
13572 IP_STR
13573 BGP_STR
13574 "BGP view\n"
13575 "View name\n"
13576 "Information about Route Server Client\n"
13577 NEIGHBOR_ADDR_STR)
13578{
13579 struct bgp_table *table;
13580 struct peer *peer;
13581
13582 if (argc == 2)
13583 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13584 else
13585 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13586
13587 if (! peer)
13588 return CMD_WARNING;
13589
13590 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13591 {
13592 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13593 VTY_NEWLINE);
13594 return CMD_WARNING;
13595 }
13596
13597 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13598 PEER_FLAG_RSERVER_CLIENT))
13599 {
13600 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13601 VTY_NEWLINE);
13602 return CMD_WARNING;
13603 }
13604
13605 table = peer->rib[AFI_IP][SAFI_UNICAST];
13606
13607 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13608}
13609
13610ALIAS (show_ip_bgp_view_rsclient,
13611 show_ip_bgp_rsclient_cmd,
13612 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13613 SHOW_STR
13614 IP_STR
13615 BGP_STR
13616 "Information about Route Server Client\n"
13617 NEIGHBOR_ADDR_STR)
13618
13619DEFUN (show_bgp_view_ipv4_safi_rsclient,
13620 show_bgp_view_ipv4_safi_rsclient_cmd,
13621 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13622 SHOW_STR
13623 BGP_STR
13624 "BGP view\n"
13625 "View name\n"
13626 "Address family\n"
13627 "Address Family modifier\n"
13628 "Address Family modifier\n"
13629 "Information about Route Server Client\n"
13630 NEIGHBOR_ADDR_STR)
13631{
13632 struct bgp_table *table;
13633 struct peer *peer;
13634 safi_t safi;
13635
13636 if (argc == 3) {
13637 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13638 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13639 } else {
13640 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13641 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13642 }
13643
13644 if (! peer)
13645 return CMD_WARNING;
13646
13647 if (! peer->afc[AFI_IP][safi])
13648 {
13649 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13650 VTY_NEWLINE);
13651 return CMD_WARNING;
13652 }
13653
13654 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13655 PEER_FLAG_RSERVER_CLIENT))
13656 {
13657 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13658 VTY_NEWLINE);
13659 return CMD_WARNING;
13660 }
13661
13662 table = peer->rib[AFI_IP][safi];
13663
13664 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13665}
13666
13667ALIAS (show_bgp_view_ipv4_safi_rsclient,
13668 show_bgp_ipv4_safi_rsclient_cmd,
13669 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13670 SHOW_STR
13671 BGP_STR
13672 "Address family\n"
13673 "Address Family modifier\n"
13674 "Address Family modifier\n"
13675 "Information about Route Server Client\n"
13676 NEIGHBOR_ADDR_STR)
13677
13678DEFUN (show_ip_bgp_view_rsclient_route,
13679 show_ip_bgp_view_rsclient_route_cmd,
13680 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13681 SHOW_STR
13682 IP_STR
13683 BGP_STR
13684 "BGP view\n"
13685 "View name\n"
13686 "Information about Route Server Client\n"
13687 NEIGHBOR_ADDR_STR
13688 "Network in the BGP routing table to display\n")
13689{
13690 struct bgp *bgp;
13691 struct peer *peer;
13692
13693 /* BGP structure lookup. */
13694 if (argc == 3)
13695 {
13696 bgp = bgp_lookup_by_name (argv[0]);
13697 if (bgp == NULL)
13698 {
13699 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13700 return CMD_WARNING;
13701 }
13702 }
13703 else
13704 {
13705 bgp = bgp_get_default ();
13706 if (bgp == NULL)
13707 {
13708 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13709 return CMD_WARNING;
13710 }
13711 }
13712
13713 if (argc == 3)
13714 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13715 else
13716 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13717
13718 if (! peer)
13719 return CMD_WARNING;
13720
13721 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13722 {
13723 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13724 VTY_NEWLINE);
13725 return CMD_WARNING;
13726}
13727
13728 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13729 PEER_FLAG_RSERVER_CLIENT))
13730 {
13731 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13732 VTY_NEWLINE);
13733 return CMD_WARNING;
13734 }
13735
13736 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13737 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013738 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050013739}
13740
13741ALIAS (show_ip_bgp_view_rsclient_route,
13742 show_ip_bgp_rsclient_route_cmd,
13743 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13744 SHOW_STR
13745 IP_STR
13746 BGP_STR
13747 "Information about Route Server Client\n"
13748 NEIGHBOR_ADDR_STR
13749 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013750
Lou Berger651b4022016-01-12 13:42:07 -050013751DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13752 show_bgp_ipv4_safi_neighbor_flap_cmd,
13753 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013754 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013755 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013756 "Address Family Modifier\n"
13757 "Address Family Modifier\n"
13758 "Address Family Modifier\n"
13759 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013760 "Detailed information on TCP and BGP neighbor connections\n"
13761 "Neighbor to display information about\n"
13762 "Neighbor to display information about\n"
13763 "Display flap statistics of the routes learned from neighbor\n")
13764{
paulbb46e942003-10-24 19:02:03 +000013765 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013766 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013767
Lou Berger651b4022016-01-12 13:42:07 -050013768 if (bgp_parse_safi(argv[0], &safi)) {
13769 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13770 return CMD_WARNING;
13771 }
13772
13773 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013774 if (! peer)
13775 return CMD_WARNING;
13776
Lou Berger651b4022016-01-12 13:42:07 -050013777 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013778 bgp_show_type_flap_neighbor);
13779}
Lou Berger205e6742016-01-12 13:42:11 -050013780
Lou Berger651b4022016-01-12 13:42:07 -050013781DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13782 show_bgp_ipv6_safi_neighbor_flap_cmd,
13783 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013784 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013785 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013786 "Address Family Modifier\n"
13787 "Address Family Modifier\n"
13788 "Address Family Modifier\n"
13789 "Address Family Modifier\n"
13790 "Detailed information on TCP and BGP neighbor connections\n"
13791 "Neighbor to display information about\n"
13792 "Neighbor to display information about\n"
13793 "Display flap statistics of the routes learned from neighbor\n")
13794{
13795 struct peer *peer;
13796 safi_t safi;
13797
13798 if (bgp_parse_safi(argv[0], &safi)) {
13799 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13800 return CMD_WARNING;
13801 }
13802
13803 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13804 if (! peer)
13805 return CMD_WARNING;
13806
13807 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13808 bgp_show_type_flap_neighbor);
13809}
Lou Berger651b4022016-01-12 13:42:07 -050013810
13811DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13812 show_bgp_ipv4_safi_neighbor_damp_cmd,
13813 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13814 SHOW_STR
13815 BGP_STR
13816 "Address Family Modifier\n"
13817 "Address Family Modifier\n"
13818 "Address Family Modifier\n"
13819 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013820 "Detailed information on TCP and BGP neighbor connections\n"
13821 "Neighbor to display information about\n"
13822 "Neighbor to display information about\n"
13823 "Display the dampened routes received from neighbor\n")
13824{
paulbb46e942003-10-24 19:02:03 +000013825 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013826 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013827
Lou Berger651b4022016-01-12 13:42:07 -050013828 if (bgp_parse_safi(argv[0], &safi)) {
13829 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13830 return CMD_WARNING;
13831 }
13832
13833 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013834 if (! peer)
13835 return CMD_WARNING;
13836
Lou Berger651b4022016-01-12 13:42:07 -050013837 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013838 bgp_show_type_damp_neighbor);
13839}
Lou Berger205e6742016-01-12 13:42:11 -050013840
Lou Berger651b4022016-01-12 13:42:07 -050013841DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13842 show_bgp_ipv6_safi_neighbor_damp_cmd,
13843 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013844 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013845 BGP_STR
13846 "Address Family Modifier\n"
13847 "Address Family Modifier\n"
13848 "Address Family Modifier\n"
13849 "Address Family Modifier\n"
13850 "Detailed information on TCP and BGP neighbor connections\n"
13851 "Neighbor to display information about\n"
13852 "Neighbor to display information about\n"
13853 "Display the dampened routes received from neighbor\n")
13854{
13855 struct peer *peer;
13856 safi_t safi;
13857
13858 if (bgp_parse_safi(argv[0], &safi)) {
13859 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13860 return CMD_WARNING;
13861 }
13862
13863 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13864 if (! peer)
13865 return CMD_WARNING;
13866
13867 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13868 bgp_show_type_damp_neighbor);
13869}
Lou Berger651b4022016-01-12 13:42:07 -050013870
13871DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13872 show_bgp_ipv4_safi_neighbor_routes_cmd,
13873 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13874 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013875 BGP_STR
13876 "Address family\n"
13877 "Address Family modifier\n"
13878 "Address Family modifier\n"
13879 "Detailed information on TCP and BGP neighbor connections\n"
13880 "Neighbor to display information about\n"
13881 "Neighbor to display information about\n"
13882 "Display routes learned from neighbor\n")
13883{
paulbb46e942003-10-24 19:02:03 +000013884 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013885 safi_t safi;
13886
13887 if (bgp_parse_safi(argv[0], &safi)) {
13888 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13889 return CMD_WARNING;
13890 }
paulbb46e942003-10-24 19:02:03 +000013891
13892 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13893 if (! peer)
13894 return CMD_WARNING;
13895
Lou Berger651b4022016-01-12 13:42:07 -050013896 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013897 bgp_show_type_neighbor);
13898}
Lou Berger205e6742016-01-12 13:42:11 -050013899
Lou Berger651b4022016-01-12 13:42:07 -050013900DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13901 show_bgp_ipv6_safi_neighbor_routes_cmd,
13902 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013903 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013904 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013905 "Address family\n"
13906 "Address Family modifier\n"
13907 "Address Family modifier\n"
13908 "Detailed information on TCP and BGP neighbor connections\n"
13909 NEIGHBOR_ADDR_STR
13910 NEIGHBOR_ADDR_STR
13911 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013912{
paulfee0f4c2004-09-13 05:12:46 +000013913 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013914 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013915
Lou Berger651b4022016-01-12 13:42:07 -050013916 if (bgp_parse_safi(argv[0], &safi)) {
13917 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13918 return CMD_WARNING;
13919 }
paulfee0f4c2004-09-13 05:12:46 +000013920
Lou Berger651b4022016-01-12 13:42:07 -050013921 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013922 if (! peer)
13923 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013924
13925 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13926 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013927}
paulfee0f4c2004-09-13 05:12:46 +000013928
Michael Lambert95cbbd22010-07-23 14:43:04 -040013929DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13930 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13931 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13932 SHOW_STR
13933 BGP_STR
13934 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013935 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013936 "Address family\n"
13937 "Address Family modifier\n"
13938 "Address Family modifier\n"
13939 "Information about Route Server Client\n"
13940 NEIGHBOR_ADDR_STR
13941 "Network in the BGP routing table to display\n")
13942{
13943 struct bgp *bgp;
13944 struct peer *peer;
13945 safi_t safi;
13946
13947 /* BGP structure lookup. */
13948 if (argc == 4)
13949 {
13950 bgp = bgp_lookup_by_name (argv[0]);
13951 if (bgp == NULL)
13952 {
13953 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13954 return CMD_WARNING;
13955 }
13956 }
13957 else
13958 {
13959 bgp = bgp_get_default ();
13960 if (bgp == NULL)
13961 {
13962 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13963 return CMD_WARNING;
13964 }
13965 }
13966
13967 if (argc == 4) {
13968 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13969 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13970 } else {
13971 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13972 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13973 }
13974
13975 if (! peer)
13976 return CMD_WARNING;
13977
13978 if (! peer->afc[AFI_IP][safi])
13979 {
13980 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13981 VTY_NEWLINE);
13982 return CMD_WARNING;
13983}
13984
13985 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13986 PEER_FLAG_RSERVER_CLIENT))
13987 {
13988 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13989 VTY_NEWLINE);
13990 return CMD_WARNING;
13991 }
13992
13993 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13994 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013995 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013996}
13997
13998ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
13999 show_bgp_ipv4_safi_rsclient_route_cmd,
14000 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14001 SHOW_STR
14002 BGP_STR
14003 "Address family\n"
14004 "Address Family modifier\n"
14005 "Address Family modifier\n"
14006 "Information about Route Server Client\n"
14007 NEIGHBOR_ADDR_STR
14008 "Network in the BGP routing table to display\n")
14009
paulfee0f4c2004-09-13 05:12:46 +000014010
Michael Lambert95cbbd22010-07-23 14:43:04 -040014011DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
14012 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
14013 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14014 SHOW_STR
14015 BGP_STR
14016 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014017 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014018 "Address family\n"
14019 "Address Family modifier\n"
14020 "Address Family modifier\n"
14021 "Information about Route Server Client\n"
14022 NEIGHBOR_ADDR_STR
14023 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14024{
14025 struct bgp *bgp;
14026 struct peer *peer;
14027 safi_t safi;
14028
14029 /* BGP structure lookup. */
14030 if (argc == 4)
14031 {
14032 bgp = bgp_lookup_by_name (argv[0]);
14033 if (bgp == NULL)
14034 {
14035 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14036 return CMD_WARNING;
14037 }
14038 }
14039 else
14040 {
14041 bgp = bgp_get_default ();
14042 if (bgp == NULL)
14043 {
14044 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14045 return CMD_WARNING;
14046 }
14047 }
14048
14049 if (argc == 4) {
14050 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14051 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14052 } else {
14053 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14054 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14055 }
14056
14057 if (! peer)
14058 return CMD_WARNING;
14059
14060 if (! peer->afc[AFI_IP][safi])
14061 {
14062 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14063 VTY_NEWLINE);
14064 return CMD_WARNING;
14065}
14066
14067 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14068 PEER_FLAG_RSERVER_CLIENT))
14069{
14070 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14071 VTY_NEWLINE);
14072 return CMD_WARNING;
14073 }
14074
14075 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14076 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014077 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014078}
14079
Lou Bergerf9b6c392016-01-12 13:42:09 -050014080DEFUN (show_ip_bgp_view_rsclient_prefix,
14081 show_ip_bgp_view_rsclient_prefix_cmd,
14082 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14083 SHOW_STR
14084 IP_STR
14085 BGP_STR
14086 "BGP view\n"
14087 "View name\n"
14088 "Information about Route Server Client\n"
14089 NEIGHBOR_ADDR_STR
14090 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14091{
14092 struct bgp *bgp;
14093 struct peer *peer;
14094
14095 /* BGP structure lookup. */
14096 if (argc == 3)
14097 {
14098 bgp = bgp_lookup_by_name (argv[0]);
14099 if (bgp == NULL)
14100 {
14101 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14102 return CMD_WARNING;
14103 }
14104 }
14105 else
14106 {
14107 bgp = bgp_get_default ();
14108 if (bgp == NULL)
14109 {
14110 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14111 return CMD_WARNING;
14112 }
14113 }
14114
14115 if (argc == 3)
14116 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14117 else
14118 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14119
14120 if (! peer)
14121 return CMD_WARNING;
14122
14123 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14124 {
14125 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14126 VTY_NEWLINE);
14127 return CMD_WARNING;
14128}
14129
14130 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14131 PEER_FLAG_RSERVER_CLIENT))
14132{
14133 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14134 VTY_NEWLINE);
14135 return CMD_WARNING;
14136 }
14137
14138 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14139 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014140 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014141}
14142
14143ALIAS (show_ip_bgp_view_rsclient_prefix,
14144 show_ip_bgp_rsclient_prefix_cmd,
14145 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14146 SHOW_STR
14147 IP_STR
14148 BGP_STR
14149 "Information about Route Server Client\n"
14150 NEIGHBOR_ADDR_STR
14151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14152
Michael Lambert95cbbd22010-07-23 14:43:04 -040014153ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14154 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14155 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14156 SHOW_STR
14157 BGP_STR
14158 "Address family\n"
14159 "Address Family modifier\n"
14160 "Address Family modifier\n"
14161 "Information about Route Server Client\n"
14162 NEIGHBOR_ADDR_STR
14163 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014164
Lou Bergerf9b6c392016-01-12 13:42:09 -050014165DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014166 show_bgp_view_ipv6_neighbor_routes_cmd,
14167 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014168 SHOW_STR
14169 BGP_STR
14170 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014171 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014172 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014173 "Detailed information on TCP and BGP neighbor connections\n"
14174 "Neighbor to display information about\n"
14175 "Neighbor to display information about\n"
14176 "Display routes learned from neighbor\n")
14177{
14178 struct peer *peer;
14179
14180 if (argc == 2)
14181 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14182 else
14183 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14184
14185 if (! peer)
14186 return CMD_WARNING;
14187
14188 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14189 bgp_show_type_neighbor);
14190}
14191
Lou Berger651b4022016-01-12 13:42:07 -050014192DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014193 show_bgp_view_neighbor_damp_cmd,
14194 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14195 SHOW_STR
14196 BGP_STR
14197 "BGP view\n"
14198 "View name\n"
14199 "Detailed information on TCP and BGP neighbor connections\n"
14200 "Neighbor to display information about\n"
14201 "Neighbor to display information about\n"
14202 "Display the dampened routes received from neighbor\n")
14203{
14204 struct peer *peer;
14205
14206 if (argc == 2)
14207 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14208 else
14209 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14210
14211 if (! peer)
14212 return CMD_WARNING;
14213
14214 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14215 bgp_show_type_damp_neighbor);
14216}
14217
14218DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014219 show_bgp_view_ipv6_neighbor_damp_cmd,
14220 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014221 SHOW_STR
14222 BGP_STR
14223 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014224 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014225 "Address family\n"
14226 "Detailed information on TCP and BGP neighbor connections\n"
14227 "Neighbor to display information about\n"
14228 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014229 "Display the dampened routes received from neighbor\n")
14230{
14231 struct peer *peer;
14232
14233 if (argc == 2)
14234 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14235 else
14236 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14237
14238 if (! peer)
14239 return CMD_WARNING;
14240
14241 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14242 bgp_show_type_damp_neighbor);
14243}
14244
Lou Bergerf9b6c392016-01-12 13:42:09 -050014245DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014246 show_bgp_view_ipv6_neighbor_flap_cmd,
14247 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014248 SHOW_STR
14249 BGP_STR
14250 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014251 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014252 "Address family\n"
14253 "Detailed information on TCP and BGP neighbor connections\n"
14254 "Neighbor to display information about\n"
14255 "Neighbor to display information about\n"
14256 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014257{
14258 struct peer *peer;
14259
14260 if (argc == 2)
14261 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14262 else
14263 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14264
14265 if (! peer)
14266 return CMD_WARNING;
14267
14268 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14269 bgp_show_type_flap_neighbor);
14270}
14271
Lou Bergerf9b6c392016-01-12 13:42:09 -050014272DEFUN (show_bgp_view_neighbor_flap,
14273 show_bgp_view_neighbor_flap_cmd,
14274 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14275 SHOW_STR
14276 BGP_STR
14277 "BGP view\n"
14278 "View name\n"
14279 "Detailed information on TCP and BGP neighbor connections\n"
14280 "Neighbor to display information about\n"
14281 "Neighbor to display information about\n"
14282 "Display flap statistics of the routes learned from neighbor\n")
14283{
14284 struct peer *peer;
14285
14286 if (argc == 2)
14287 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14288 else
14289 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14290
14291 if (! peer)
14292 return CMD_WARNING;
14293
14294 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14295 bgp_show_type_flap_neighbor);
14296}
14297
14298ALIAS (show_bgp_view_neighbor_flap,
14299 show_bgp_neighbor_flap_cmd,
14300 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14301 SHOW_STR
14302 BGP_STR
14303 "Detailed information on TCP and BGP neighbor connections\n"
14304 "Neighbor to display information about\n"
14305 "Neighbor to display information about\n"
14306 "Display flap statistics of the routes learned from neighbor\n")
14307
14308ALIAS (show_bgp_view_neighbor_damp,
14309 show_bgp_neighbor_damp_cmd,
14310 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14311 SHOW_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 the dampened routes received from neighbor\n")
14317
14318DEFUN (show_bgp_view_neighbor_routes,
14319 show_bgp_view_neighbor_routes_cmd,
14320 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14321 SHOW_STR
14322 BGP_STR
14323 "BGP view\n"
14324 "View name\n"
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 if (argc == 2)
14333 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14334 else
14335 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14336
14337 if (! peer)
14338 return CMD_WARNING;
14339
14340 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14341 bgp_show_type_neighbor);
14342}
14343
14344ALIAS (show_bgp_view_neighbor_routes,
14345 show_bgp_neighbor_routes_cmd,
14346 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14347 SHOW_STR
14348 BGP_STR
14349 "Detailed information on TCP and BGP neighbor connections\n"
14350 "Neighbor to display information about\n"
14351 "Neighbor to display information about\n"
14352 "Display routes learned from neighbor\n")
14353
paulbb46e942003-10-24 19:02:03 +000014354ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014355 show_bgp_ipv6_neighbor_routes_cmd,
14356 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14357 SHOW_STR
14358 BGP_STR
14359 "Address family\n"
14360 "Detailed information on TCP and BGP neighbor connections\n"
14361 "Neighbor to display information about\n"
14362 "Neighbor to display information about\n"
14363 "Display routes learned from neighbor\n")
14364
Lou Bergerf9b6c392016-01-12 13:42:09 -050014365/* old command */
14366ALIAS (show_bgp_view_neighbor_routes,
14367 ipv6_bgp_neighbor_routes_cmd,
14368 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14369 SHOW_STR
14370 IPV6_STR
14371 BGP_STR
14372 "Detailed information on TCP and BGP neighbor connections\n"
14373 "Neighbor to display information about\n"
14374 "Neighbor to display information about\n"
14375 "Display routes learned from neighbor\n")
14376
14377/* old command */
14378DEFUN (ipv6_mbgp_neighbor_routes,
14379 ipv6_mbgp_neighbor_routes_cmd,
14380 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14381 SHOW_STR
14382 IPV6_STR
14383 MBGP_STR
14384 "Detailed information on TCP and BGP neighbor connections\n"
14385 "Neighbor to display information about\n"
14386 "Neighbor to display information about\n"
14387 "Display routes learned from neighbor\n")
14388{
14389 struct peer *peer;
14390
14391 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14392 if (! peer)
14393 return CMD_WARNING;
14394
14395 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14396 bgp_show_type_neighbor);
14397}
14398
paulbb46e942003-10-24 19:02:03 +000014399ALIAS (show_bgp_view_neighbor_flap,
14400 show_bgp_ipv6_neighbor_flap_cmd,
14401 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14402 SHOW_STR
14403 BGP_STR
14404 "Address family\n"
14405 "Detailed information on TCP and BGP neighbor connections\n"
14406 "Neighbor to display information about\n"
14407 "Neighbor to display information about\n"
14408 "Display flap statistics of the routes learned from neighbor\n")
14409
14410ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014411 show_bgp_ipv6_neighbor_damp_cmd,
14412 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14413 SHOW_STR
14414 BGP_STR
14415 "Address family\n"
14416 "Detailed information on TCP and BGP neighbor connections\n"
14417 "Neighbor to display information about\n"
14418 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014419 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014420
Lou Bergerf9b6c392016-01-12 13:42:09 -050014421DEFUN (show_bgp_view_rsclient,
14422 show_bgp_view_rsclient_cmd,
14423 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14424 SHOW_STR
14425 BGP_STR
14426 "BGP view\n"
14427 "View name\n"
14428 "Information about Route Server Client\n"
14429 NEIGHBOR_ADDR_STR)
14430{
14431 struct bgp_table *table;
14432 struct peer *peer;
14433
14434 if (argc == 2)
14435 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14436 else
14437 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14438
14439 if (! peer)
14440 return CMD_WARNING;
14441
14442 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14443 {
14444 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14445 VTY_NEWLINE);
14446 return CMD_WARNING;
14447 }
14448
14449 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14450 PEER_FLAG_RSERVER_CLIENT))
14451 {
14452 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14453 VTY_NEWLINE);
14454 return CMD_WARNING;
14455 }
14456
14457 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14458
14459 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14460}
14461
14462ALIAS (show_bgp_view_rsclient,
14463 show_bgp_rsclient_cmd,
14464 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14465 SHOW_STR
14466 BGP_STR
14467 "Information about Route Server Client\n"
14468 NEIGHBOR_ADDR_STR)
14469
Lou Berger651b4022016-01-12 13:42:07 -050014470DEFUN (show_bgp_view_ipv4_rsclient,
14471 show_bgp_view_ipv4_rsclient_cmd,
14472 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014473 SHOW_STR
14474 BGP_STR
14475 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014476 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014477 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014478 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014479 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014480{
Lou Berger651b4022016-01-12 13:42:07 -050014481 struct bgp_table *table;
14482 struct peer *peer;
14483
14484 if (argc == 2)
14485 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14486 else
14487 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14488
14489 if (! peer)
14490 return CMD_WARNING;
14491
14492 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14493 {
14494 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14495 VTY_NEWLINE);
14496 return CMD_WARNING;
14497 }
14498
14499 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14500 PEER_FLAG_RSERVER_CLIENT))
14501 {
14502 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14503 VTY_NEWLINE);
14504 return CMD_WARNING;
14505 }
14506
14507 table = peer->rib[AFI_IP][SAFI_UNICAST];
14508
14509 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14510}
14511DEFUN (show_bgp_view_ipv6_rsclient,
14512 show_bgp_view_ipv6_rsclient_cmd,
14513 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14514 SHOW_STR
14515 BGP_STR
14516 "BGP view\n"
14517 "BGP view name\n"
14518 "Address Family\n"
14519 "Information about Route Server Client\n"
14520 NEIGHBOR_ADDR_STR2)
14521{
14522 struct bgp_table *table;
14523 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014524
14525 if (argc == 2)
14526 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14527 else
14528 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14529
14530 if (! peer)
14531 return CMD_WARNING;
14532
14533 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14534 {
14535 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14536 VTY_NEWLINE);
14537 return CMD_WARNING;
14538 }
14539
14540 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14541 PEER_FLAG_RSERVER_CLIENT))
14542 {
14543 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14544 VTY_NEWLINE);
14545 return CMD_WARNING;
14546 }
14547
14548 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14549
ajs5a646652004-11-05 01:25:55 +000014550 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014551}
14552
Lou Berger651b4022016-01-12 13:42:07 -050014553ALIAS (show_bgp_view_ipv4_rsclient,
14554 show_bgp_ipv4_rsclient_cmd,
14555 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014556 SHOW_STR
14557 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014558 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014559 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014560 NEIGHBOR_ADDR_STR2)
14561
Lou Berger651b4022016-01-12 13:42:07 -050014562ALIAS (show_bgp_view_ipv6_rsclient,
14563 show_bgp_ipv6_rsclient_cmd,
14564 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14565 SHOW_STR
14566 BGP_STR
14567 "Address Family\n"
14568 "Information about Route Server Client\n"
14569 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014570
Michael Lambert95cbbd22010-07-23 14:43:04 -040014571DEFUN (show_bgp_view_ipv6_safi_rsclient,
14572 show_bgp_view_ipv6_safi_rsclient_cmd,
14573 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14574 SHOW_STR
14575 BGP_STR
14576 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014577 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014578 "Address family\n"
14579 "Address Family modifier\n"
14580 "Address Family modifier\n"
14581 "Information about Route Server Client\n"
14582 NEIGHBOR_ADDR_STR)
14583{
14584 struct bgp_table *table;
14585 struct peer *peer;
14586 safi_t safi;
14587
14588 if (argc == 3) {
14589 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14590 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14591 } else {
14592 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14593 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14594 }
14595
14596 if (! peer)
14597 return CMD_WARNING;
14598
14599 if (! peer->afc[AFI_IP6][safi])
14600 {
14601 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14602 VTY_NEWLINE);
14603 return CMD_WARNING;
14604 }
14605
14606 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14607 PEER_FLAG_RSERVER_CLIENT))
14608 {
14609 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14610 VTY_NEWLINE);
14611 return CMD_WARNING;
14612 }
14613
14614 table = peer->rib[AFI_IP6][safi];
14615
14616 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14617}
14618
14619ALIAS (show_bgp_view_ipv6_safi_rsclient,
14620 show_bgp_ipv6_safi_rsclient_cmd,
14621 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14622 SHOW_STR
14623 BGP_STR
14624 "Address family\n"
14625 "Address Family modifier\n"
14626 "Address Family modifier\n"
14627 "Information about Route Server Client\n"
14628 NEIGHBOR_ADDR_STR)
14629
paulfee0f4c2004-09-13 05:12:46 +000014630DEFUN (show_bgp_view_rsclient_route,
14631 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014632 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14633 SHOW_STR
14634 BGP_STR
14635 "BGP view\n"
14636 "View name\n"
14637 "Information about Route Server Client\n"
14638 NEIGHBOR_ADDR_STR
14639 "Network in the BGP routing table to display\n")
14640{
14641 struct bgp *bgp;
14642 struct peer *peer;
14643
14644 /* BGP structure lookup. */
14645 if (argc == 3)
14646 {
14647 bgp = bgp_lookup_by_name (argv[0]);
14648 if (bgp == NULL)
14649 {
14650 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14651 return CMD_WARNING;
14652 }
14653 }
14654 else
14655 {
14656 bgp = bgp_get_default ();
14657 if (bgp == NULL)
14658 {
14659 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14660 return CMD_WARNING;
14661 }
14662 }
14663
14664 if (argc == 3)
14665 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14666 else
14667 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14668
14669 if (! peer)
14670 return CMD_WARNING;
14671
14672 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14673 {
14674 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14675 VTY_NEWLINE);
14676 return CMD_WARNING;
14677 }
14678
14679 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14680 PEER_FLAG_RSERVER_CLIENT))
14681 {
14682 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14683 VTY_NEWLINE);
14684 return CMD_WARNING;
14685 }
14686
14687 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14688 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014689 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014690}
14691
14692DEFUN (show_bgp_view_ipv6_rsclient_route,
14693 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014694 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014695 SHOW_STR
14696 BGP_STR
14697 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014698 "BGP view name\n"
14699 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014700 "Information about Route Server Client\n"
14701 NEIGHBOR_ADDR_STR
14702 "Network in the BGP routing table to display\n")
14703{
14704 struct bgp *bgp;
14705 struct peer *peer;
14706
14707 /* BGP structure lookup. */
14708 if (argc == 3)
14709 {
14710 bgp = bgp_lookup_by_name (argv[0]);
14711 if (bgp == NULL)
14712 {
14713 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14714 return CMD_WARNING;
14715 }
14716 }
14717 else
14718 {
14719 bgp = bgp_get_default ();
14720 if (bgp == NULL)
14721 {
14722 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14723 return CMD_WARNING;
14724 }
14725 }
14726
14727 if (argc == 3)
14728 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14729 else
14730 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14731
14732 if (! peer)
14733 return CMD_WARNING;
14734
14735 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14736 {
14737 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14738 VTY_NEWLINE);
14739 return CMD_WARNING;
14740 }
14741
14742 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14743 PEER_FLAG_RSERVER_CLIENT))
14744 {
14745 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14746 VTY_NEWLINE);
14747 return CMD_WARNING;
14748 }
14749
14750 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14751 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014752 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014753}
14754
Lou Bergerf9b6c392016-01-12 13:42:09 -050014755ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014756 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014757 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14758 SHOW_STR
14759 BGP_STR
14760 "Information about Route Server Client\n"
14761 NEIGHBOR_ADDR_STR
14762 "Network in the BGP routing table to display\n")
14763
14764ALIAS (show_bgp_view_ipv6_rsclient_route,
14765 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014766 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014767 SHOW_STR
14768 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014769 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014770 "Information about Route Server Client\n"
14771 NEIGHBOR_ADDR_STR
14772 "Network in the BGP routing table to display\n")
14773
Michael Lambert95cbbd22010-07-23 14:43:04 -040014774DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14775 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14776 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14777 SHOW_STR
14778 BGP_STR
14779 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014780 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014781 "Address family\n"
14782 "Address Family modifier\n"
14783 "Address Family modifier\n"
14784 "Information about Route Server Client\n"
14785 NEIGHBOR_ADDR_STR
14786 "Network in the BGP routing table to display\n")
14787{
14788 struct bgp *bgp;
14789 struct peer *peer;
14790 safi_t safi;
14791
14792 /* BGP structure lookup. */
14793 if (argc == 4)
14794 {
14795 bgp = bgp_lookup_by_name (argv[0]);
14796 if (bgp == NULL)
14797 {
14798 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14799 return CMD_WARNING;
14800 }
14801 }
14802 else
14803 {
14804 bgp = bgp_get_default ();
14805 if (bgp == NULL)
14806 {
14807 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14808 return CMD_WARNING;
14809 }
14810 }
14811
14812 if (argc == 4) {
14813 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14814 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14815 } else {
14816 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14817 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14818 }
14819
14820 if (! peer)
14821 return CMD_WARNING;
14822
14823 if (! peer->afc[AFI_IP6][safi])
14824 {
14825 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14826 VTY_NEWLINE);
14827 return CMD_WARNING;
14828}
14829
14830 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14831 PEER_FLAG_RSERVER_CLIENT))
14832 {
14833 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14834 VTY_NEWLINE);
14835 return CMD_WARNING;
14836 }
14837
14838 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14839 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014840 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014841}
14842
14843ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14844 show_bgp_ipv6_safi_rsclient_route_cmd,
14845 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14846 SHOW_STR
14847 BGP_STR
14848 "Address family\n"
14849 "Address Family modifier\n"
14850 "Address Family modifier\n"
14851 "Information about Route Server Client\n"
14852 NEIGHBOR_ADDR_STR
14853 "Network in the BGP routing table to display\n")
14854
Lou Berger651b4022016-01-12 13:42:07 -050014855
paulfee0f4c2004-09-13 05:12:46 +000014856DEFUN (show_bgp_view_rsclient_prefix,
14857 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014858 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14859 SHOW_STR
14860 BGP_STR
14861 "BGP view\n"
14862 "View name\n"
14863 "Information about Route Server Client\n"
14864 NEIGHBOR_ADDR_STR
14865 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14866{
14867 struct bgp *bgp;
14868 struct peer *peer;
14869
14870 /* BGP structure lookup. */
14871 if (argc == 3)
14872 {
14873 bgp = bgp_lookup_by_name (argv[0]);
14874 if (bgp == NULL)
14875 {
14876 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14877 return CMD_WARNING;
14878 }
14879 }
14880 else
14881 {
14882 bgp = bgp_get_default ();
14883 if (bgp == NULL)
14884 {
14885 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14886 return CMD_WARNING;
14887 }
14888 }
14889
14890 if (argc == 3)
14891 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14892 else
14893 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14894
14895 if (! peer)
14896 return CMD_WARNING;
14897
14898 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14899 {
14900 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14901 VTY_NEWLINE);
14902 return CMD_WARNING;
14903 }
14904
14905 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14906 PEER_FLAG_RSERVER_CLIENT))
14907 {
14908 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14909 VTY_NEWLINE);
14910 return CMD_WARNING;
14911 }
14912
14913 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14914 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014915 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014916}
14917
14918DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14919 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014920 "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 +000014921 SHOW_STR
14922 BGP_STR
14923 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014924 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014925 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014926 "Information about Route Server Client\n"
14927 NEIGHBOR_ADDR_STR
14928 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14929{
14930 struct bgp *bgp;
14931 struct peer *peer;
14932
14933 /* BGP structure lookup. */
14934 if (argc == 3)
14935 {
14936 bgp = bgp_lookup_by_name (argv[0]);
14937 if (bgp == NULL)
14938 {
14939 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14940 return CMD_WARNING;
14941 }
14942 }
14943 else
14944 {
14945 bgp = bgp_get_default ();
14946 if (bgp == NULL)
14947 {
14948 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14949 return CMD_WARNING;
14950 }
14951 }
14952
14953 if (argc == 3)
14954 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14955 else
14956 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14957
14958 if (! peer)
14959 return CMD_WARNING;
14960
14961 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14962 {
14963 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14964 VTY_NEWLINE);
14965 return CMD_WARNING;
14966 }
14967
14968 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14969 PEER_FLAG_RSERVER_CLIENT))
14970 {
14971 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14972 VTY_NEWLINE);
14973 return CMD_WARNING;
14974 }
14975
14976 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14977 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014978 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014979}
14980
Lou Bergerf9b6c392016-01-12 13:42:09 -050014981ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014982 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014983 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14984 SHOW_STR
14985 BGP_STR
14986 "Information about Route Server Client\n"
14987 NEIGHBOR_ADDR_STR
14988 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14989
14990ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14991 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014992 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014993 SHOW_STR
14994 BGP_STR
14995 "Information about Route Server Client\n"
14996 NEIGHBOR_ADDR_STR
14997 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14998
Michael Lambert95cbbd22010-07-23 14:43:04 -040014999DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15000 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15001 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15002 SHOW_STR
15003 BGP_STR
15004 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000015005 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040015006 "Address family\n"
15007 "Address Family modifier\n"
15008 "Address Family modifier\n"
15009 "Information about Route Server Client\n"
15010 NEIGHBOR_ADDR_STR
15011 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15012{
15013 struct bgp *bgp;
15014 struct peer *peer;
15015 safi_t safi;
15016
15017 /* BGP structure lookup. */
15018 if (argc == 4)
15019 {
15020 bgp = bgp_lookup_by_name (argv[0]);
15021 if (bgp == NULL)
15022 {
15023 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15024 return CMD_WARNING;
15025 }
15026 }
15027 else
15028 {
15029 bgp = bgp_get_default ();
15030 if (bgp == NULL)
15031 {
15032 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15033 return CMD_WARNING;
15034 }
15035 }
15036
15037 if (argc == 4) {
15038 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15039 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15040 } else {
15041 peer = peer_lookup_in_view (vty, NULL, argv[1]);
15042 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15043 }
15044
15045 if (! peer)
15046 return CMD_WARNING;
15047
15048 if (! peer->afc[AFI_IP6][safi])
15049 {
15050 vty_out (vty, "%% Activate the neighbor for the address family first%s",
15051 VTY_NEWLINE);
15052 return CMD_WARNING;
15053}
15054
15055 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15056 PEER_FLAG_RSERVER_CLIENT))
15057{
15058 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15059 VTY_NEWLINE);
15060 return CMD_WARNING;
15061 }
15062
15063 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15064 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070015065 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040015066}
15067
15068ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15069 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15070 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15071 SHOW_STR
15072 BGP_STR
15073 "Address family\n"
15074 "Address Family modifier\n"
15075 "Address Family modifier\n"
15076 "Information about Route Server Client\n"
15077 NEIGHBOR_ADDR_STR
15078 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15079
paul718e3742002-12-13 20:15:29 +000015080struct bgp_table *bgp_distance_table;
15081
15082struct bgp_distance
15083{
15084 /* Distance value for the IP source prefix. */
15085 u_char distance;
15086
15087 /* Name of the access-list to be matched. */
15088 char *access_list;
15089};
15090
paul94f2b392005-06-28 12:44:16 +000015091static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015092bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015093{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015094 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015095}
15096
paul94f2b392005-06-28 12:44:16 +000015097static void
paul718e3742002-12-13 20:15:29 +000015098bgp_distance_free (struct bgp_distance *bdistance)
15099{
15100 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15101}
15102
paul94f2b392005-06-28 12:44:16 +000015103static int
paulfd79ac92004-10-13 05:06:08 +000015104bgp_distance_set (struct vty *vty, const char *distance_str,
15105 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015106{
15107 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015108 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015109 u_char distance;
15110 struct bgp_node *rn;
15111 struct bgp_distance *bdistance;
15112
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015113 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015114 if (ret == 0)
15115 {
15116 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15117 return CMD_WARNING;
15118 }
15119
15120 distance = atoi (distance_str);
15121
15122 /* Get BGP distance node. */
15123 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15124 if (rn->info)
15125 {
15126 bdistance = rn->info;
15127 bgp_unlock_node (rn);
15128 }
15129 else
15130 {
15131 bdistance = bgp_distance_new ();
15132 rn->info = bdistance;
15133 }
15134
15135 /* Set distance value. */
15136 bdistance->distance = distance;
15137
15138 /* Reset access-list configuration. */
15139 if (bdistance->access_list)
15140 {
15141 free (bdistance->access_list);
15142 bdistance->access_list = NULL;
15143 }
15144 if (access_list_str)
15145 bdistance->access_list = strdup (access_list_str);
15146
15147 return CMD_SUCCESS;
15148}
15149
paul94f2b392005-06-28 12:44:16 +000015150static int
paulfd79ac92004-10-13 05:06:08 +000015151bgp_distance_unset (struct vty *vty, const char *distance_str,
15152 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015153{
15154 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015155 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015156 u_char distance;
15157 struct bgp_node *rn;
15158 struct bgp_distance *bdistance;
15159
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015160 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015161 if (ret == 0)
15162 {
15163 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15164 return CMD_WARNING;
15165 }
15166
15167 distance = atoi (distance_str);
15168
15169 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15170 if (! rn)
15171 {
15172 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15173 return CMD_WARNING;
15174 }
15175
15176 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015177
15178 if (bdistance->distance != distance)
15179 {
15180 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15181 return CMD_WARNING;
15182 }
15183
paul718e3742002-12-13 20:15:29 +000015184 if (bdistance->access_list)
15185 free (bdistance->access_list);
15186 bgp_distance_free (bdistance);
15187
15188 rn->info = NULL;
15189 bgp_unlock_node (rn);
15190 bgp_unlock_node (rn);
15191
15192 return CMD_SUCCESS;
15193}
15194
paul718e3742002-12-13 20:15:29 +000015195/* Apply BGP information to distance method. */
15196u_char
15197bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15198{
15199 struct bgp_node *rn;
15200 struct prefix_ipv4 q;
15201 struct peer *peer;
15202 struct bgp_distance *bdistance;
15203 struct access_list *alist;
15204 struct bgp_static *bgp_static;
15205
15206 if (! bgp)
15207 return 0;
15208
15209 if (p->family != AF_INET)
15210 return 0;
15211
15212 peer = rinfo->peer;
15213
15214 if (peer->su.sa.sa_family != AF_INET)
15215 return 0;
15216
15217 memset (&q, 0, sizeof (struct prefix_ipv4));
15218 q.family = AF_INET;
15219 q.prefix = peer->su.sin.sin_addr;
15220 q.prefixlen = IPV4_MAX_BITLEN;
15221
15222 /* Check source address. */
15223 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15224 if (rn)
15225 {
15226 bdistance = rn->info;
15227 bgp_unlock_node (rn);
15228
15229 if (bdistance->access_list)
15230 {
15231 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15232 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15233 return bdistance->distance;
15234 }
15235 else
15236 return bdistance->distance;
15237 }
15238
15239 /* Backdoor check. */
15240 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15241 if (rn)
15242 {
15243 bgp_static = rn->info;
15244 bgp_unlock_node (rn);
15245
15246 if (bgp_static->backdoor)
15247 {
15248 if (bgp->distance_local)
15249 return bgp->distance_local;
15250 else
15251 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15252 }
15253 }
15254
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015255 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015256 {
15257 if (bgp->distance_ebgp)
15258 return bgp->distance_ebgp;
15259 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15260 }
15261 else
15262 {
15263 if (bgp->distance_ibgp)
15264 return bgp->distance_ibgp;
15265 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15266 }
15267}
15268
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015269#ifdef HAVE_IPV6
15270/* Apply BGP information to ipv6 distance method. */
15271u_char
15272ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15273{
15274 struct bgp_node *rn;
15275 struct prefix_ipv6 q;
15276 struct peer *peer;
15277 struct bgp_distance *bdistance;
15278 struct access_list *alist;
15279 struct bgp_static *bgp_static;
15280
15281 if (! bgp)
15282 return 0;
15283
15284 if (p->family != AF_INET6)
15285 return 0;
15286
15287 peer = rinfo->peer;
15288
15289 if (peer->su.sa.sa_family != AF_INET6)
15290 return 0;
15291
15292 memset (&q, 0, sizeof (struct prefix_ipv6));
15293 q.family = AF_INET;
15294 q.prefix = peer->su.sin6.sin6_addr;
15295 q.prefixlen = IPV6_MAX_BITLEN;
15296
15297 /* Check source address. */
15298 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15299 if (rn)
15300 {
15301 bdistance = rn->info;
15302 bgp_unlock_node (rn);
15303
15304 if (bdistance->access_list)
15305 {
15306 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15307 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15308 return bdistance->distance;
15309 }
15310 else
15311 return bdistance->distance;
15312 }
15313 /* Backdoor check. */
15314 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15315 if (rn)
15316 {
15317 bgp_static = rn->info;
15318 bgp_unlock_node (rn);
15319
15320 if (bgp_static->backdoor)
15321 {
15322 if (bgp->ipv6_distance_local)
15323 return bgp->ipv6_distance_local;
15324 else
15325 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15326 }
15327 }
15328
15329 if (peer_sort (peer) == BGP_PEER_EBGP)
15330 {
15331 if (bgp->ipv6_distance_ebgp)
15332 return bgp->ipv6_distance_ebgp;
15333 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15334 }
15335 else
15336 {
15337 if (bgp->ipv6_distance_ibgp)
15338 return bgp->ipv6_distance_ibgp;
15339 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15340 }
15341}
15342#endif /* HAVE_IPV6 */
15343
paul718e3742002-12-13 20:15:29 +000015344DEFUN (bgp_distance,
15345 bgp_distance_cmd,
15346 "distance bgp <1-255> <1-255> <1-255>",
15347 "Define an administrative distance\n"
15348 "BGP distance\n"
15349 "Distance for routes external to the AS\n"
15350 "Distance for routes internal to the AS\n"
15351 "Distance for local routes\n")
15352{
15353 struct bgp *bgp;
15354
15355 bgp = vty->index;
15356
15357 bgp->distance_ebgp = atoi (argv[0]);
15358 bgp->distance_ibgp = atoi (argv[1]);
15359 bgp->distance_local = atoi (argv[2]);
15360 return CMD_SUCCESS;
15361}
15362
15363DEFUN (no_bgp_distance,
15364 no_bgp_distance_cmd,
15365 "no distance bgp <1-255> <1-255> <1-255>",
15366 NO_STR
15367 "Define an administrative distance\n"
15368 "BGP distance\n"
15369 "Distance for routes external to the AS\n"
15370 "Distance for routes internal to the AS\n"
15371 "Distance for local routes\n")
15372{
15373 struct bgp *bgp;
15374
15375 bgp = vty->index;
15376
15377 bgp->distance_ebgp= 0;
15378 bgp->distance_ibgp = 0;
15379 bgp->distance_local = 0;
15380 return CMD_SUCCESS;
15381}
15382
15383ALIAS (no_bgp_distance,
15384 no_bgp_distance2_cmd,
15385 "no distance bgp",
15386 NO_STR
15387 "Define an administrative distance\n"
15388 "BGP distance\n")
15389
15390DEFUN (bgp_distance_source,
15391 bgp_distance_source_cmd,
15392 "distance <1-255> A.B.C.D/M",
15393 "Define an administrative distance\n"
15394 "Administrative distance\n"
15395 "IP source prefix\n")
15396{
15397 bgp_distance_set (vty, argv[0], argv[1], NULL);
15398 return CMD_SUCCESS;
15399}
15400
15401DEFUN (no_bgp_distance_source,
15402 no_bgp_distance_source_cmd,
15403 "no distance <1-255> A.B.C.D/M",
15404 NO_STR
15405 "Define an administrative distance\n"
15406 "Administrative distance\n"
15407 "IP source prefix\n")
15408{
15409 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15410 return CMD_SUCCESS;
15411}
15412
15413DEFUN (bgp_distance_source_access_list,
15414 bgp_distance_source_access_list_cmd,
15415 "distance <1-255> A.B.C.D/M WORD",
15416 "Define an administrative distance\n"
15417 "Administrative distance\n"
15418 "IP source prefix\n"
15419 "Access list name\n")
15420{
15421 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15422 return CMD_SUCCESS;
15423}
15424
15425DEFUN (no_bgp_distance_source_access_list,
15426 no_bgp_distance_source_access_list_cmd,
15427 "no distance <1-255> A.B.C.D/M WORD",
15428 NO_STR
15429 "Define an administrative distance\n"
15430 "Administrative distance\n"
15431 "IP source prefix\n"
15432 "Access list name\n")
15433{
15434 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15435 return CMD_SUCCESS;
15436}
David Lamparter6b0655a2014-06-04 06:53:35 +020015437
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015438#ifdef HAVE_IPV6
15439DEFUN (ipv6_bgp_distance,
15440 ipv6_bgp_distance_cmd,
15441 "distance bgp <1-255> <1-255> <1-255>",
15442 "Define an administrative distance\n"
15443 "BGP distance\n"
15444 "Distance for routes external to the AS\n"
15445 "Distance for routes internal to the AS\n"
15446 "Distance for local routes\n")
15447{
15448 struct bgp *bgp;
15449
15450 bgp = vty->index;
15451
15452 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15453 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15454 bgp->ipv6_distance_local = atoi (argv[2]);
15455 return CMD_SUCCESS;
15456}
15457
15458DEFUN (no_ipv6_bgp_distance,
15459 no_ipv6_bgp_distance_cmd,
15460 "no distance bgp <1-255> <1-255> <1-255>",
15461 NO_STR
15462 "Define an administrative distance\n"
15463 "BGP distance\n"
15464 "Distance for routes external to the AS\n"
15465 "Distance for routes internal to the AS\n"
15466 "Distance for local routes\n")
15467{
15468 struct bgp *bgp;
15469
15470 bgp = vty->index;
15471
15472 bgp->ipv6_distance_ebgp= 0;
15473 bgp->ipv6_distance_ibgp = 0;
15474 bgp->ipv6_distance_local = 0;
15475 return CMD_SUCCESS;
15476}
15477
15478ALIAS (no_ipv6_bgp_distance,
15479 no_ipv6_bgp_distance2_cmd,
15480 "no distance bgp",
15481 NO_STR
15482 "Define an administrative distance\n"
15483 "BGP distance\n")
15484
15485DEFUN (ipv6_bgp_distance_source,
15486 ipv6_bgp_distance_source_cmd,
15487 "distance <1-255> X:X::X:X/M",
15488 "Define an administrative distance\n"
15489 "Administrative distance\n"
15490 "IP source prefix\n")
15491{
15492 bgp_distance_set (vty, argv[0], argv[1], NULL);
15493 return CMD_SUCCESS;
15494}
15495
15496DEFUN (no_ipv6_bgp_distance_source,
15497 no_ipv6_bgp_distance_source_cmd,
15498 "no distance <1-255> X:X::X:X/M",
15499 NO_STR
15500 "Define an administrative distance\n"
15501 "Administrative distance\n"
15502 "IP source prefix\n")
15503{
15504 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15505 return CMD_SUCCESS;
15506}
15507
15508DEFUN (ipv6_bgp_distance_source_access_list,
15509 ipv6_bgp_distance_source_access_list_cmd,
15510 "distance <1-255> X:X::X:X/M WORD",
15511 "Define an administrative distance\n"
15512 "Administrative distance\n"
15513 "IP source prefix\n"
15514 "Access list name\n")
15515{
15516 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15517 return CMD_SUCCESS;
15518}
15519
15520DEFUN (no_ipv6_bgp_distance_source_access_list,
15521 no_ipv6_bgp_distance_source_access_list_cmd,
15522 "no distance <1-255> X:X::X:X/M WORD",
15523 NO_STR
15524 "Define an administrative distance\n"
15525 "Administrative distance\n"
15526 "IP source prefix\n"
15527 "Access list name\n")
15528{
15529 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15530 return CMD_SUCCESS;
15531}
15532#endif
15533
paul718e3742002-12-13 20:15:29 +000015534DEFUN (bgp_damp_set,
15535 bgp_damp_set_cmd,
15536 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15537 "BGP Specific commands\n"
15538 "Enable route-flap dampening\n"
15539 "Half-life time for the penalty\n"
15540 "Value to start reusing a route\n"
15541 "Value to start suppressing a route\n"
15542 "Maximum duration to suppress a stable route\n")
15543{
15544 struct bgp *bgp;
15545 int half = DEFAULT_HALF_LIFE * 60;
15546 int reuse = DEFAULT_REUSE;
15547 int suppress = DEFAULT_SUPPRESS;
15548 int max = 4 * half;
15549
15550 if (argc == 4)
15551 {
15552 half = atoi (argv[0]) * 60;
15553 reuse = atoi (argv[1]);
15554 suppress = atoi (argv[2]);
15555 max = atoi (argv[3]) * 60;
15556 }
15557 else if (argc == 1)
15558 {
15559 half = atoi (argv[0]) * 60;
15560 max = 4 * half;
15561 }
15562
15563 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015564
15565 if (suppress < reuse)
15566 {
15567 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15568 VTY_NEWLINE);
15569 return 0;
15570 }
15571
paul718e3742002-12-13 20:15:29 +000015572 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15573 half, reuse, suppress, max);
15574}
15575
15576ALIAS (bgp_damp_set,
15577 bgp_damp_set2_cmd,
15578 "bgp dampening <1-45>",
15579 "BGP Specific commands\n"
15580 "Enable route-flap dampening\n"
15581 "Half-life time for the penalty\n")
15582
15583ALIAS (bgp_damp_set,
15584 bgp_damp_set3_cmd,
15585 "bgp dampening",
15586 "BGP Specific commands\n"
15587 "Enable route-flap dampening\n")
15588
15589DEFUN (bgp_damp_unset,
15590 bgp_damp_unset_cmd,
15591 "no bgp dampening",
15592 NO_STR
15593 "BGP Specific commands\n"
15594 "Enable route-flap dampening\n")
15595{
15596 struct bgp *bgp;
15597
15598 bgp = vty->index;
15599 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15600}
15601
15602ALIAS (bgp_damp_unset,
15603 bgp_damp_unset2_cmd,
15604 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15605 NO_STR
15606 "BGP Specific commands\n"
15607 "Enable route-flap dampening\n"
15608 "Half-life time for the penalty\n"
15609 "Value to start reusing a route\n"
15610 "Value to start suppressing a route\n"
15611 "Maximum duration to suppress a stable route\n")
15612
Lou Bergerf9b6c392016-01-12 13:42:09 -050015613DEFUN (show_ip_bgp_dampened_paths,
15614 show_ip_bgp_dampened_paths_cmd,
15615 "show ip bgp dampened-paths",
15616 SHOW_STR
15617 IP_STR
15618 BGP_STR
15619 "Display paths suppressed due to dampening\n")
15620{
15621 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15622 NULL);
15623}
15624
15625ALIAS (show_ip_bgp_dampened_paths,
15626 show_ip_bgp_damp_dampened_paths_cmd,
15627 "show ip bgp dampening dampened-paths",
15628 SHOW_STR
15629 IP_STR
15630 BGP_STR
15631 "Display detailed information about dampening\n"
15632 "Display paths suppressed due to dampening\n")
15633
15634DEFUN (show_ip_bgp_flap_statistics,
15635 show_ip_bgp_flap_statistics_cmd,
15636 "show ip bgp flap-statistics",
15637 SHOW_STR
15638 IP_STR
15639 BGP_STR
15640 "Display flap statistics of routes\n")
15641{
15642 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15643 bgp_show_type_flap_statistics, NULL);
15644}
15645
15646ALIAS (show_ip_bgp_flap_statistics,
15647 show_ip_bgp_damp_flap_statistics_cmd,
15648 "show ip bgp dampening flap-statistics",
15649 SHOW_STR
15650 IP_STR
15651 BGP_STR
15652 "Display detailed information about dampening\n"
15653 "Display flap statistics of routes\n")
15654
Lou Berger651b4022016-01-12 13:42:07 -050015655DEFUN (show_bgp_ipv4_safi_dampened_paths,
15656 show_bgp_ipv4_safi_dampened_paths_cmd,
15657 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015658 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015659 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015660 IP_STR
15661 "Address Family modifier\n"
15662 "Address Family modifier\n"
15663 "Address Family modifier\n"
15664 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015665 "Display paths suppressed due to dampening\n")
15666{
Lou Berger651b4022016-01-12 13:42:07 -050015667 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015668
Lou Berger651b4022016-01-12 13:42:07 -050015669 if (bgp_parse_safi(argv[0], &safi)) {
15670 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15671 return CMD_WARNING;
15672 }
15673
15674 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15675}
15676ALIAS (show_bgp_ipv4_safi_dampened_paths,
15677 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15678 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015679 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015680 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015681 IP_STR
15682 "Address Family modifier\n"
15683 "Address Family modifier\n"
15684 "Address Family modifier\n"
15685 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015686 "Display detailed information about dampening\n"
15687 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015688
Lou Berger651b4022016-01-12 13:42:07 -050015689DEFUN (show_bgp_ipv6_safi_dampened_paths,
15690 show_bgp_ipv6_safi_dampened_paths_cmd,
15691 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015692 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015693 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015694 IPV6_STR
15695 "Address Family modifier\n"
15696 "Address Family modifier\n"
15697 "Address Family modifier\n"
15698 "Address Family modifier\n"
15699 "Display paths suppressed due to dampening\n")
15700{
15701 safi_t safi;
15702
15703 if (bgp_parse_safi(argv[0], &safi)) {
15704 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15705 return CMD_WARNING;
15706 }
15707
15708 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15709}
15710ALIAS (show_bgp_ipv6_safi_dampened_paths,
15711 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15712 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15713 SHOW_STR
15714 BGP_STR
15715 IPV6_STR
15716 "Address Family modifier\n"
15717 "Address Family modifier\n"
15718 "Address Family modifier\n"
15719 "Address Family modifier\n"
15720 "Display detailed information about dampening\n"
15721 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015722
15723DEFUN (show_bgp_ipv4_safi_flap_statistics,
15724 show_bgp_ipv4_safi_flap_statistics_cmd,
15725 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15726 SHOW_STR
15727 BGP_STR
15728 "Address Family\n"
15729 "Address Family modifier\n"
15730 "Address Family modifier\n"
15731 "Address Family modifier\n"
15732 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015733 "Display flap statistics of routes\n")
15734{
Lou Berger651b4022016-01-12 13:42:07 -050015735 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015736
Lou Berger651b4022016-01-12 13:42:07 -050015737 if (bgp_parse_safi(argv[0], &safi)) {
15738 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15739 return CMD_WARNING;
15740 }
15741
15742 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15743}
15744ALIAS (show_bgp_ipv4_safi_flap_statistics,
15745 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15746 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015747 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015748 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015749 "Address Family\n"
15750 "Address Family modifier\n"
15751 "Address Family modifier\n"
15752 "Address Family modifier\n"
15753 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015754 "Display detailed information about dampening\n"
15755 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015756
Lou Berger651b4022016-01-12 13:42:07 -050015757DEFUN (show_bgp_ipv6_safi_flap_statistics,
15758 show_bgp_ipv6_safi_flap_statistics_cmd,
15759 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15760 SHOW_STR
15761 BGP_STR
15762 "Address Family\n"
15763 "Address Family modifier\n"
15764 "Address Family modifier\n"
15765 "Address Family modifier\n"
15766 "Address Family modifier\n"
15767 "Display flap statistics of routes\n")
15768{
15769 safi_t safi;
15770
15771 if (bgp_parse_safi(argv[0], &safi)) {
15772 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15773 return CMD_WARNING;
15774 }
15775
15776 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15777}
15778ALIAS (show_bgp_ipv6_safi_flap_statistics,
15779 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15780 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15781 SHOW_STR
15782 BGP_STR
15783 "Address Family\n"
15784 "Address Family modifier\n"
15785 "Address Family modifier\n"
15786 "Address Family modifier\n"
15787 "Address Family modifier\n"
15788 "Display detailed information about dampening\n"
15789 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015790
paul718e3742002-12-13 20:15:29 +000015791/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015792static int
paulfd79ac92004-10-13 05:06:08 +000015793bgp_clear_damp_route (struct vty *vty, const char *view_name,
15794 const char *ip_str, afi_t afi, safi_t safi,
15795 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015796{
15797 int ret;
15798 struct prefix match;
15799 struct bgp_node *rn;
15800 struct bgp_node *rm;
15801 struct bgp_info *ri;
15802 struct bgp_info *ri_temp;
15803 struct bgp *bgp;
15804 struct bgp_table *table;
15805
15806 /* BGP structure lookup. */
15807 if (view_name)
15808 {
15809 bgp = bgp_lookup_by_name (view_name);
15810 if (bgp == NULL)
15811 {
15812 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15813 return CMD_WARNING;
15814 }
15815 }
15816 else
15817 {
15818 bgp = bgp_get_default ();
15819 if (bgp == NULL)
15820 {
15821 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15822 return CMD_WARNING;
15823 }
15824 }
15825
15826 /* Check IP address argument. */
15827 ret = str2prefix (ip_str, &match);
15828 if (! ret)
15829 {
15830 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15831 return CMD_WARNING;
15832 }
15833
15834 match.family = afi2family (afi);
15835
Lou Berger298cc2f2016-01-12 13:42:02 -050015836 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015837 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015838 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015839 {
15840 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15841 continue;
15842
15843 if ((table = rn->info) != NULL)
15844 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015845 {
15846 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15847 {
15848 ri = rm->info;
15849 while (ri)
15850 {
15851 if (ri->extra && ri->extra->damp_info)
15852 {
15853 ri_temp = ri->next;
15854 bgp_damp_info_free (ri->extra->damp_info, 1);
15855 ri = ri_temp;
15856 }
15857 else
15858 ri = ri->next;
15859 }
15860 }
15861
15862 bgp_unlock_node (rm);
15863 }
paul718e3742002-12-13 20:15:29 +000015864 }
15865 }
15866 else
15867 {
15868 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015869 {
15870 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15871 {
15872 ri = rn->info;
15873 while (ri)
15874 {
15875 if (ri->extra && ri->extra->damp_info)
15876 {
15877 ri_temp = ri->next;
15878 bgp_damp_info_free (ri->extra->damp_info, 1);
15879 ri = ri_temp;
15880 }
15881 else
15882 ri = ri->next;
15883 }
15884 }
15885
15886 bgp_unlock_node (rn);
15887 }
paul718e3742002-12-13 20:15:29 +000015888 }
15889
15890 return CMD_SUCCESS;
15891}
15892
15893DEFUN (clear_ip_bgp_dampening,
15894 clear_ip_bgp_dampening_cmd,
15895 "clear ip bgp dampening",
15896 CLEAR_STR
15897 IP_STR
15898 BGP_STR
15899 "Clear route flap dampening information\n")
15900{
15901 bgp_damp_info_clean ();
15902 return CMD_SUCCESS;
15903}
15904
15905DEFUN (clear_ip_bgp_dampening_prefix,
15906 clear_ip_bgp_dampening_prefix_cmd,
15907 "clear ip bgp dampening A.B.C.D/M",
15908 CLEAR_STR
15909 IP_STR
15910 BGP_STR
15911 "Clear route flap dampening information\n"
15912 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15913{
15914 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15915 SAFI_UNICAST, NULL, 1);
15916}
15917
15918DEFUN (clear_ip_bgp_dampening_address,
15919 clear_ip_bgp_dampening_address_cmd,
15920 "clear ip bgp dampening A.B.C.D",
15921 CLEAR_STR
15922 IP_STR
15923 BGP_STR
15924 "Clear route flap dampening information\n"
15925 "Network to clear damping information\n")
15926{
15927 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15928 SAFI_UNICAST, NULL, 0);
15929}
15930
15931DEFUN (clear_ip_bgp_dampening_address_mask,
15932 clear_ip_bgp_dampening_address_mask_cmd,
15933 "clear ip bgp dampening A.B.C.D A.B.C.D",
15934 CLEAR_STR
15935 IP_STR
15936 BGP_STR
15937 "Clear route flap dampening information\n"
15938 "Network to clear damping information\n"
15939 "Network mask\n")
15940{
15941 int ret;
15942 char prefix_str[BUFSIZ];
15943
15944 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15945 if (! ret)
15946 {
15947 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15948 return CMD_WARNING;
15949 }
15950
15951 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15952 SAFI_UNICAST, NULL, 0);
15953}
David Lamparter6b0655a2014-06-04 06:53:35 +020015954
Lou Berger298cc2f2016-01-12 13:42:02 -050015955/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015956static int
paul718e3742002-12-13 20:15:29 +000015957bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15958 afi_t afi, safi_t safi, int *write)
15959{
15960 struct bgp_node *prn;
15961 struct bgp_node *rn;
15962 struct bgp_table *table;
15963 struct prefix *p;
15964 struct prefix_rd *prd;
15965 struct bgp_static *bgp_static;
15966 u_int32_t label;
15967 char buf[SU_ADDRSTRLEN];
15968 char rdbuf[RD_ADDRSTRLEN];
15969
15970 /* Network configuration. */
15971 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15972 if ((table = prn->info) != NULL)
15973 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15974 if ((bgp_static = rn->info) != NULL)
15975 {
15976 p = &rn->p;
15977 prd = (struct prefix_rd *) &prn->p;
15978
15979 /* "address-family" display. */
15980 bgp_config_write_family_header (vty, afi, safi, write);
15981
15982 /* "network" configuration display. */
15983 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15984 label = decode_label (bgp_static->tag);
15985
15986 vty_out (vty, " network %s/%d rd %s tag %d",
15987 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15988 p->prefixlen,
15989 rdbuf, label);
15990 vty_out (vty, "%s", VTY_NEWLINE);
15991 }
15992 return 0;
15993}
15994
15995/* Configuration of static route announcement and aggregate
15996 information. */
15997int
15998bgp_config_write_network (struct vty *vty, struct bgp *bgp,
15999 afi_t afi, safi_t safi, int *write)
16000{
16001 struct bgp_node *rn;
16002 struct prefix *p;
16003 struct bgp_static *bgp_static;
16004 struct bgp_aggregate *bgp_aggregate;
16005 char buf[SU_ADDRSTRLEN];
16006
Lou Berger298cc2f2016-01-12 13:42:02 -050016007 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000016008 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
16009
16010 /* Network configuration. */
16011 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
16012 if ((bgp_static = rn->info) != NULL)
16013 {
16014 p = &rn->p;
16015
16016 /* "address-family" display. */
16017 bgp_config_write_family_header (vty, afi, safi, write);
16018
16019 /* "network" configuration display. */
16020 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16021 {
16022 u_int32_t destination;
16023 struct in_addr netmask;
16024
16025 destination = ntohl (p->u.prefix4.s_addr);
16026 masklen2ip (p->prefixlen, &netmask);
16027 vty_out (vty, " network %s",
16028 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
16029
16030 if ((IN_CLASSC (destination) && p->prefixlen == 24)
16031 || (IN_CLASSB (destination) && p->prefixlen == 16)
16032 || (IN_CLASSA (destination) && p->prefixlen == 8)
16033 || p->u.prefix4.s_addr == 0)
16034 {
16035 /* Natural mask is not display. */
16036 }
16037 else
16038 vty_out (vty, " mask %s", inet_ntoa (netmask));
16039 }
16040 else
16041 {
16042 vty_out (vty, " network %s/%d",
16043 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16044 p->prefixlen);
16045 }
16046
16047 if (bgp_static->rmap.name)
16048 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000016049 else
16050 {
16051 if (bgp_static->backdoor)
16052 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000016053 }
paul718e3742002-12-13 20:15:29 +000016054
16055 vty_out (vty, "%s", VTY_NEWLINE);
16056 }
16057
16058 /* Aggregate-address configuration. */
16059 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
16060 if ((bgp_aggregate = rn->info) != NULL)
16061 {
16062 p = &rn->p;
16063
16064 /* "address-family" display. */
16065 bgp_config_write_family_header (vty, afi, safi, write);
16066
16067 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16068 {
16069 struct in_addr netmask;
16070
16071 masklen2ip (p->prefixlen, &netmask);
16072 vty_out (vty, " aggregate-address %s %s",
16073 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16074 inet_ntoa (netmask));
16075 }
16076 else
16077 {
16078 vty_out (vty, " aggregate-address %s/%d",
16079 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16080 p->prefixlen);
16081 }
16082
16083 if (bgp_aggregate->as_set)
16084 vty_out (vty, " as-set");
16085
16086 if (bgp_aggregate->summary_only)
16087 vty_out (vty, " summary-only");
16088
16089 vty_out (vty, "%s", VTY_NEWLINE);
16090 }
16091
16092 return 0;
16093}
16094
16095int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016096bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
16097 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000016098{
16099 struct bgp_node *rn;
16100 struct bgp_distance *bdistance;
16101
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016102 if (afi == AFI_IP && safi == SAFI_UNICAST)
16103 {
16104 /* Distance configuration. */
16105 if (bgp->distance_ebgp
16106 && bgp->distance_ibgp
16107 && bgp->distance_local
16108 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16109 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16110 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16111 vty_out (vty, " distance bgp %d %d %d%s",
16112 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
16113 VTY_NEWLINE);
16114
16115 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16116 if ((bdistance = rn->info) != NULL)
16117 {
16118 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16119 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
16120 bdistance->access_list ? bdistance->access_list : "",
16121 VTY_NEWLINE);
16122 }
16123 }
16124
16125#ifdef HAVE_IPV6
16126 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
16127 {
16128 bgp_config_write_family_header (vty, afi, safi, write);
16129 if (bgp->ipv6_distance_ebgp
16130 && bgp->ipv6_distance_ibgp
16131 && bgp->ipv6_distance_local
16132 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16133 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16134 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16135 vty_out (vty, " distance bgp %d %d %d%s",
16136 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
16137 VTY_NEWLINE);
16138
16139 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16140 if ((bdistance = rn->info) != NULL)
16141 {
16142 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16143 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
16144 bdistance->access_list ? bdistance->access_list : "",
16145 VTY_NEWLINE);
16146 }
16147 }
16148#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016149
16150 return 0;
16151}
16152
16153/* Allocate routing table structure and install commands. */
16154void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080016155bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000016156{
16157 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000016158 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000016159
16160 /* IPv4 BGP commands. */
16161 install_element (BGP_NODE, &bgp_network_cmd);
16162 install_element (BGP_NODE, &bgp_network_mask_cmd);
16163 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
16164 install_element (BGP_NODE, &bgp_network_route_map_cmd);
16165 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
16166 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
16167 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
16168 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
16169 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
16170 install_element (BGP_NODE, &no_bgp_network_cmd);
16171 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
16172 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
16173 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
16174 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
16175 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16176 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
16177 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
16178 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
16179
16180 install_element (BGP_NODE, &aggregate_address_cmd);
16181 install_element (BGP_NODE, &aggregate_address_mask_cmd);
16182 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
16183 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
16184 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
16185 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
16186 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
16187 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
16188 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
16189 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
16190 install_element (BGP_NODE, &no_aggregate_address_cmd);
16191 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
16192 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
16193 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
16194 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
16195 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
16196 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
16197 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
16198 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16199 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16200
16201 /* IPv4 unicast configuration. */
16202 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16203 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16204 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16205 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16206 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16207 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016208 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016209 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16210 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16211 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16212 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16213 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016214
paul718e3742002-12-13 20:15:29 +000016215 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16216 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16217 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16218 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16219 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16220 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16221 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16222 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16223 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16224 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16225 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16226 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16227 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16228 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16229 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16230 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16231 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16232 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16233 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16234 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16235
16236 /* IPv4 multicast configuration. */
16237 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16238 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16239 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16240 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16241 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16242 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16243 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16244 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16245 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16246 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16247 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16248 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16249 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16250 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16251 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16252 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16253 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16254 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16255 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16256 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16257 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16258 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16259 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16260 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16261 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16262 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16263 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16264 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16265 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16266 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16267 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16268 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16269
Michael Lambert95cbbd22010-07-23 14:43:04 -040016270 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016271 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016272 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16273 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16274 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16275 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16276 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16277 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16278 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16279 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16280 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016281 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016282 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16283 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16284 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16285 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16286 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16287 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16288 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16289 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16290 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16291 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16292 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16293 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16294 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16295 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16296 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16297 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16298 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16299 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16300 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16301 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16302 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16303 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16304 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16305 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16306 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16307 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16308 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16309 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016310 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16311 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16312 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16313 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16314 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016315 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16316 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16317 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16318 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16319 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16320 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16321 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16322 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16323 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16324 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16325 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16326 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16327 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16328 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16329 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16330 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16331 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16332 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16333 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016334 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016335 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16336 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16337 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16338 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16341 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16342 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16346 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16347 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16348 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16349 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16350 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16351 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16352 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16353 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16354 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16356 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16357 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16358 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16359 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16360 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16361 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16362 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16363 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16364 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16365 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16366 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16367 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16368 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16369 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16370 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16371 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16372 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16373 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16374 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16375 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16376 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16377 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16378 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16379 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016380 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016381 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016382 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016383 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016384 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016385 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016386
16387 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016388 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016389 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16390 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16391 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16392 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16393 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016394 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016395 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16396 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16397 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16398 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16399 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16400 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16401 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16402 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16403 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16404 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16405 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16406 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16407 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16408 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16409 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16410 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016411 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16412 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16413 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16414 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16415 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016416 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16417 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16418 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16419 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16420 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16421 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16422 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16423 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016424 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016425 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016426 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016427 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016428
Donald Sharp68b45cc2016-03-11 14:27:13 -050016429 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016430 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16431 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16432 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16433 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16434
paul718e3742002-12-13 20:15:29 +000016435 /* New config IPv6 BGP commands. */
16436 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16437 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16438 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16439 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16440
16441 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16442 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16443 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16444 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16445
G.Balaji73bfe0b2011-09-23 22:36:20 +053016446 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16447 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16448
paul718e3742002-12-13 20:15:29 +000016449 /* Old config IPv6 BGP commands. */
16450 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16451 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16452
16453 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16454 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16455 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16456 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16457
Michael Lambert95cbbd22010-07-23 14:43:04 -040016458 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016459 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016460 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016461 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016462 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016463 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016464 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016465 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016466 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016467 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16468 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16469 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16470 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16471 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16472 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16473 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16474 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016475 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016476 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016477 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016478 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016479 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016480 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016481 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016482 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016483 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16484 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016485 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016486 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016487 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016488 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016489 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016490 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016491 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016492 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016493 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016494 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016495 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016496 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016497 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016498 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016499 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16500 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016501 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016502 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016503 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016504 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016505 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016506
16507 /* Restricted:
16508 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16509 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016510 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016511 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016512 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016513 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016514 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16515 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16516 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16517 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16518 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16519 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16520 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16521 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16522 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016523 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016524 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016525 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016526 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016527 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016528 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016529 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016530 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016531 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016532 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016533
Paul Jakma2815e612006-09-14 02:56:07 +000016534 /* Statistics */
16535 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016536 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016537
16538 install_element (BGP_NODE, &bgp_distance_cmd);
16539 install_element (BGP_NODE, &no_bgp_distance_cmd);
16540 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16541 install_element (BGP_NODE, &bgp_distance_source_cmd);
16542 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16543 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16544 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016545#ifdef HAVE_IPV6
16546 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16547 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16548 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16549 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16550 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16551 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16552 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16553#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016554
16555 install_element (BGP_NODE, &bgp_damp_set_cmd);
16556 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16557 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16558 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16559 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16560 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16561 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16562 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16563 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16564 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016565
16566 /* IPv4 Multicast Mode */
16567 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16568 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16569 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16570 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16571 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16572
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016573
16574 /* Deprecated AS-Pathlimit commands */
16575 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16576 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16577 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16578 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16579 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16580 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16581
16582 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16583 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16584 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16585 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16586 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16587 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16588
16589 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16590 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16591 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16592 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16593 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16594 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16595
16596 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16597 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16598 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16599 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16600 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16601 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16602
16603 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16604 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16605 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16606 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16607 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16608 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16609
16610 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16611 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16612 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16613 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16614 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16615 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016616
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016617 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16618 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016619
16620 /* old style commands */
16621 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16622 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16623 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016624 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
16625 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016626 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16627 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16628 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16629 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16630 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016631 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16632 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16633 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016634 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16635 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16636 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16637 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16638 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16639 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16640 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16641 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16642 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16643 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16644 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16645 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16646 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16647 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16648 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16649 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16650 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16651 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16652 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16653 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16654 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16656 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16657 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16658 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16659 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16660 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16661 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16662 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16663 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16664 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16665 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16666 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16667 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16668 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16669 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16670 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16671 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16673 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16674 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16675 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16676 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16677 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16678 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16679 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16681 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016682 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016683 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016684 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016686 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16687 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16688 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16689 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16690 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16691 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16692 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16693 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16694 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16695 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16696 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16697 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16698 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16699 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16700 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16701 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16702 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16703 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16704 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16705 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16706 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16707 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16708 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16709 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16710 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16711 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16712 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016713
Lou Bergerf9b6c392016-01-12 13:42:09 -050016714 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016715 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
16716 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016717 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16718 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16719 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16720 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016721 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16722 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16723 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016724 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16725 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16726 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16727 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16728 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16729 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16730 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16731 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16732 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16733 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16734 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16735 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16736 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16737 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16738 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16739 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16740 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16741 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16742 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16743 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16744 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16745 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16746 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16747 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016748
16749 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16750 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16751 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016752
Lou Bergerf9b6c392016-01-12 13:42:09 -050016753 install_element (VIEW_NODE, &show_bgp_cmd);
16754 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16755 install_element (VIEW_NODE, &show_bgp_route_cmd);
16756 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016757 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
16758 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16759 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16760 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
16761 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016763 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16764 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16765 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16766 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16767 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16768 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16769 install_element (VIEW_NODE, &show_bgp_community_cmd);
16770 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16771 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16772 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16773 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16774 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16775 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16776 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16777 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16778 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16779 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16780 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16781 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16782 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16783 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16784 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16785 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16786 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16787 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16788 install_element (VIEW_NODE, &show_bgp_view_cmd);
16789 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16790 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16791 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16792 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16793 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16794 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16795 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16796 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16797 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016798
Lou Bergerf9b6c392016-01-12 13:42:09 -050016799 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16800 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016801 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
16802 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16804 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
16805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016807 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16808 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16809 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16810 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16811 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16812 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16813 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16814 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16815 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16816 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16817 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016818
Lou Bergerf9b6c392016-01-12 13:42:09 -050016819 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16820 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016821
Lou Bergerf9b6c392016-01-12 13:42:09 -050016822 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16823 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16824 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16825 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16826 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16827 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16828 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16829 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16830 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16831 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16832 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16833 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16834 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16835 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16836 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16837 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16838 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16839 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16857 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016858 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016859 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016860 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016861 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016862 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016863 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016864 /* old with name safi collision */
16865 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16866 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16867 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16868 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16869 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16870 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16871 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16872 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16873 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16874 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16875 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16876 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16877 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16878 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16879 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16880 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016881
Lou Bergerf9b6c392016-01-12 13:42:09 -050016882 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16883 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016884
16885 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16886 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16887 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16888 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016889
16890 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16891 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16892 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16893 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016894}
Chris Caputo228da422009-07-18 05:44:03 +000016895
16896void
16897bgp_route_finish (void)
16898{
16899 bgp_table_unlock (bgp_distance_table);
16900 bgp_distance_table = NULL;
16901}