blob: 93902deab027aaa7311e1f034e6f42afc86f8b8d [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");
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07005848 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5849 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00005850 vty_out (vty, "*");
5851 else
5852 vty_out (vty, " ");
5853
5854 /* Selected */
5855 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5856 vty_out (vty, "h");
5857 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5858 vty_out (vty, "d");
5859 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5860 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005861 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5862 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005863 else
5864 vty_out (vty, " ");
5865
5866 /* Internal route. */
5867 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5868 vty_out (vty, "i");
5869 else
paulb40d9392005-08-22 22:34:41 +00005870 vty_out (vty, " ");
5871}
5872
5873/* called from terminal list command */
5874void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005875route_vty_out(
5876 struct vty *vty,
5877 struct prefix *p,
5878 struct bgp_info *binfo,
5879 int display,
5880 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005881{
5882 struct attr *attr;
5883
5884 /* short status lead text */
5885 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005886
5887 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005888 if (!display)
paul718e3742002-12-13 20:15:29 +00005889 route_vty_out_route (p, vty);
5890 else
5891 vty_out (vty, "%*s", 17, " ");
5892
5893 /* Print attribute */
5894 attr = binfo->attr;
5895 if (attr)
5896 {
paul718e3742002-12-13 20:15:29 +00005897
Lou Berger298cc2f2016-01-12 13:42:02 -05005898 /*
5899 * NEXTHOP start
5900 */
5901
5902 /*
5903 * For ENCAP routes, nexthop address family is not
5904 * neccessarily the same as the prefix address family.
5905 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5906 */
5907 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5908 if (attr->extra) {
5909 char buf[BUFSIZ];
5910 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5911
5912 switch (af) {
5913 case AF_INET:
5914 vty_out (vty, "%s", inet_ntop(af,
5915 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5916 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005917 case AF_INET6:
5918 vty_out (vty, "%s", inet_ntop(af,
5919 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5920 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005921 default:
5922 vty_out(vty, "?");
5923 }
5924 } else {
5925 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005926 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005927 } else {
5928
5929 if (p->family == AF_INET)
5930 {
5931 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5932 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005933 else if (p->family == AF_INET6)
5934 {
5935 int len;
5936 char buf[BUFSIZ];
5937
5938 len = vty_out (vty, "%s",
5939 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5940 buf, BUFSIZ));
5941 len = 16 - len;
5942 if (len < 1)
5943 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5944 else
5945 vty_out (vty, "%*s", len, " ");
5946 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005947 else
5948 {
5949 vty_out(vty, "?");
5950 }
5951 }
5952
5953 /*
5954 * NEXTHOP end
5955 */
5956
paul718e3742002-12-13 20:15:29 +00005957
5958 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005959 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005960 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005961 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005962
5963 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005964 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005965 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005966 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005967
Paul Jakmafb982c22007-05-04 20:15:47 +00005968 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005969
Paul Jakmab2518c12006-05-12 23:48:40 +00005970 /* Print aspath */
5971 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005972 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005973
Paul Jakmab2518c12006-05-12 23:48:40 +00005974 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005975 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005976 }
paul718e3742002-12-13 20:15:29 +00005977 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005978}
5979
5980/* called from terminal list command */
5981void
5982route_vty_out_tmp (struct vty *vty, struct prefix *p,
5983 struct attr *attr, safi_t safi)
5984{
5985 /* Route status display. */
5986 vty_out (vty, "*");
5987 vty_out (vty, ">");
5988 vty_out (vty, " ");
5989
5990 /* print prefix and mask */
5991 route_vty_out_route (p, vty);
5992
5993 /* Print attribute */
5994 if (attr)
5995 {
5996 if (p->family == AF_INET)
5997 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005998 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00005999 vty_out (vty, "%-16s",
6000 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006001 else
6002 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6003 }
paul718e3742002-12-13 20:15:29 +00006004 else if (p->family == AF_INET6)
6005 {
6006 int len;
6007 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006008
6009 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006010
6011 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6013 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006014 len = 16 - len;
6015 if (len < 1)
6016 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6017 else
6018 vty_out (vty, "%*s", len, " ");
6019 }
paul718e3742002-12-13 20:15:29 +00006020
6021 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006022 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006023 else
6024 vty_out (vty, " ");
6025
6026 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006027 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006028 else
6029 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006030
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006031 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006032
Paul Jakmab2518c12006-05-12 23:48:40 +00006033 /* Print aspath */
6034 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006035 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006036
Paul Jakmab2518c12006-05-12 23:48:40 +00006037 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006038 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006039 }
paul718e3742002-12-13 20:15:29 +00006040
6041 vty_out (vty, "%s", VTY_NEWLINE);
6042}
6043
ajs5a646652004-11-05 01:25:55 +00006044void
paul718e3742002-12-13 20:15:29 +00006045route_vty_out_tag (struct vty *vty, struct prefix *p,
6046 struct bgp_info *binfo, int display, safi_t safi)
6047{
6048 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006049 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006050
6051 if (!binfo->extra)
6052 return;
6053
paulb40d9392005-08-22 22:34:41 +00006054 /* short status lead text */
6055 route_vty_short_status_out (vty, binfo);
6056
paul718e3742002-12-13 20:15:29 +00006057 /* print prefix and mask */
6058 if (! display)
6059 route_vty_out_route (p, vty);
6060 else
6061 vty_out (vty, "%*s", 17, " ");
6062
6063 /* Print attribute */
6064 attr = binfo->attr;
6065 if (attr)
6066 {
6067 if (p->family == AF_INET)
6068 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006069 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006070 vty_out (vty, "%-16s",
6071 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006072 else
6073 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6074 }
paul718e3742002-12-13 20:15:29 +00006075 else if (p->family == AF_INET6)
6076 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006077 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006078 char buf[BUFSIZ];
6079 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006080 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006081 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6083 buf, BUFSIZ));
6084 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006085 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6087 buf, BUFSIZ),
6088 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6089 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006090
6091 }
paul718e3742002-12-13 20:15:29 +00006092 }
6093
Paul Jakmafb982c22007-05-04 20:15:47 +00006094 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006095
6096 vty_out (vty, "notag/%d", label);
6097
6098 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006099}
6100
6101/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006102static void
paul718e3742002-12-13 20:15:29 +00006103damp_route_vty_out (struct vty *vty, struct prefix *p,
6104 struct bgp_info *binfo, int display, safi_t safi)
6105{
6106 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006107 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006108 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006109
paulb40d9392005-08-22 22:34:41 +00006110 /* short status lead text */
6111 route_vty_short_status_out (vty, binfo);
6112
paul718e3742002-12-13 20:15:29 +00006113 /* print prefix and mask */
6114 if (! display)
6115 route_vty_out_route (p, vty);
6116 else
6117 vty_out (vty, "%*s", 17, " ");
6118
6119 len = vty_out (vty, "%s", binfo->peer->host);
6120 len = 17 - len;
6121 if (len < 1)
6122 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6123 else
6124 vty_out (vty, "%*s", len, " ");
6125
Chris Caputo50aef6f2009-06-23 06:06:49 +00006126 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006127
6128 /* Print attribute */
6129 attr = binfo->attr;
6130 if (attr)
6131 {
6132 /* Print aspath */
6133 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006134 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006135
6136 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006137 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006138 }
6139 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006140}
6141
paul718e3742002-12-13 20:15:29 +00006142/* flap route */
ajs5a646652004-11-05 01:25:55 +00006143static void
paul718e3742002-12-13 20:15:29 +00006144flap_route_vty_out (struct vty *vty, struct prefix *p,
6145 struct bgp_info *binfo, int display, safi_t safi)
6146{
6147 struct attr *attr;
6148 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006149 char timebuf[BGP_UPTIME_LEN];
6150 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006151
6152 if (!binfo->extra)
6153 return;
6154
6155 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006156
paulb40d9392005-08-22 22:34:41 +00006157 /* short status lead text */
6158 route_vty_short_status_out (vty, binfo);
6159
paul718e3742002-12-13 20:15:29 +00006160 /* print prefix and mask */
6161 if (! display)
6162 route_vty_out_route (p, vty);
6163 else
6164 vty_out (vty, "%*s", 17, " ");
6165
6166 len = vty_out (vty, "%s", binfo->peer->host);
6167 len = 16 - len;
6168 if (len < 1)
6169 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6170 else
6171 vty_out (vty, "%*s", len, " ");
6172
6173 len = vty_out (vty, "%d", bdi->flap);
6174 len = 5 - len;
6175 if (len < 1)
6176 vty_out (vty, " ");
6177 else
6178 vty_out (vty, "%*s ", len, " ");
6179
6180 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6181 timebuf, BGP_UPTIME_LEN));
6182
6183 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6184 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006185 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006186 else
6187 vty_out (vty, "%*s ", 8, " ");
6188
6189 /* Print attribute */
6190 attr = binfo->attr;
6191 if (attr)
6192 {
6193 /* Print aspath */
6194 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006195 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006196
6197 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006198 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006199 }
6200 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006201}
6202
paul94f2b392005-06-28 12:44:16 +00006203static void
paul718e3742002-12-13 20:15:29 +00006204route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6205 struct bgp_info *binfo, afi_t afi, safi_t safi)
6206{
6207 char buf[INET6_ADDRSTRLEN];
6208 char buf1[BUFSIZ];
6209 struct attr *attr;
6210 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006211#ifdef HAVE_CLOCK_MONOTONIC
6212 time_t tbuf;
6213#endif
paul718e3742002-12-13 20:15:29 +00006214
6215 attr = binfo->attr;
6216
6217 if (attr)
6218 {
6219 /* Line1 display AS-path, Aggregator */
6220 if (attr->aspath)
6221 {
6222 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006223 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006224 vty_out (vty, "Local");
6225 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006226 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006227 }
6228
paulb40d9392005-08-22 22:34:41 +00006229 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6230 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006231 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6232 vty_out (vty, ", (stale)");
6233 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006234 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006235 attr->extra->aggregator_as,
6236 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006237 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6238 vty_out (vty, ", (Received from a RR-client)");
6239 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6240 vty_out (vty, ", (Received from a RS-client)");
6241 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6242 vty_out (vty, ", (history entry)");
6243 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6244 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006245 vty_out (vty, "%s", VTY_NEWLINE);
6246
6247 /* Line2 display Next-hop, Neighbor, Router-id */
6248 if (p->family == AF_INET)
6249 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006250 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006251 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006252 inet_ntoa (attr->nexthop));
6253 }
paul718e3742002-12-13 20:15:29 +00006254 else
6255 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006256 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006257 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006258 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006259 buf, INET6_ADDRSTRLEN));
6260 }
paul718e3742002-12-13 20:15:29 +00006261
6262 if (binfo->peer == bgp->peer_self)
6263 {
6264 vty_out (vty, " from %s ",
6265 p->family == AF_INET ? "0.0.0.0" : "::");
6266 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6267 }
6268 else
6269 {
6270 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6271 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006272 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006273 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006274 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6275 buf[0] = '?';
6276 buf[1] = 0;
6277 }
6278 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006279 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006280 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006281 else
6282 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6283 }
6284 vty_out (vty, "%s", VTY_NEWLINE);
6285
paul718e3742002-12-13 20:15:29 +00006286 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006287 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006288 {
6289 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006290 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006291 buf, INET6_ADDRSTRLEN),
6292 VTY_NEWLINE);
6293 }
paul718e3742002-12-13 20:15:29 +00006294
6295 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6296 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6297
6298 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006299 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006300
6301 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006302 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006303 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006304 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006305
Paul Jakmafb982c22007-05-04 20:15:47 +00006306 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006307 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006308
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07006309 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6310 vty_out (vty, ", invalid");
6311 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00006312 vty_out (vty, ", valid");
6313
6314 if (binfo->peer != bgp->peer_self)
6315 {
6316 if (binfo->peer->as == binfo->peer->local_as)
6317 vty_out (vty, ", internal");
6318 else
6319 vty_out (vty, ", %s",
6320 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6321 }
6322 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6323 vty_out (vty, ", aggregated, local");
6324 else if (binfo->type != ZEBRA_ROUTE_BGP)
6325 vty_out (vty, ", sourced");
6326 else
6327 vty_out (vty, ", sourced, local");
6328
6329 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6330 vty_out (vty, ", atomic-aggregate");
6331
Josh Baileyde8d5df2011-07-20 20:46:01 -07006332 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6333 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6334 bgp_info_mpath_count (binfo)))
6335 vty_out (vty, ", multipath");
6336
paul718e3742002-12-13 20:15:29 +00006337 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6338 vty_out (vty, ", best");
6339
6340 vty_out (vty, "%s", VTY_NEWLINE);
6341
6342 /* Line 4 display Community */
6343 if (attr->community)
6344 vty_out (vty, " Community: %s%s", attr->community->str,
6345 VTY_NEWLINE);
6346
6347 /* Line 5 display Extended-community */
6348 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006349 vty_out (vty, " Extended Community: %s%s",
6350 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006351
6352 /* Line 6 display Originator, Cluster-id */
6353 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6354 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6355 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006356 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006357 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006358 vty_out (vty, " Originator: %s",
6359 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006360
6361 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6362 {
6363 int i;
6364 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006365 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6366 vty_out (vty, "%s ",
6367 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006368 }
6369 vty_out (vty, "%s", VTY_NEWLINE);
6370 }
Paul Jakma41367172007-08-06 15:24:51 +00006371
Paul Jakmafb982c22007-05-04 20:15:47 +00006372 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006373 bgp_damp_info_vty (vty, binfo);
6374
6375 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006376#ifdef HAVE_CLOCK_MONOTONIC
6377 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006378 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006379#else
6380 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6381#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006382 }
6383 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006384}
6385
6386#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6387 "h history, * valid, > best, = multipath,%s"\
6388 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006389#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006390#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6391#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6392#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6393
6394enum bgp_show_type
6395{
6396 bgp_show_type_normal,
6397 bgp_show_type_regexp,
6398 bgp_show_type_prefix_list,
6399 bgp_show_type_filter_list,
6400 bgp_show_type_route_map,
6401 bgp_show_type_neighbor,
6402 bgp_show_type_cidr_only,
6403 bgp_show_type_prefix_longer,
6404 bgp_show_type_community_all,
6405 bgp_show_type_community,
6406 bgp_show_type_community_exact,
6407 bgp_show_type_community_list,
6408 bgp_show_type_community_list_exact,
6409 bgp_show_type_flap_statistics,
6410 bgp_show_type_flap_address,
6411 bgp_show_type_flap_prefix,
6412 bgp_show_type_flap_cidr_only,
6413 bgp_show_type_flap_regexp,
6414 bgp_show_type_flap_filter_list,
6415 bgp_show_type_flap_prefix_list,
6416 bgp_show_type_flap_prefix_longer,
6417 bgp_show_type_flap_route_map,
6418 bgp_show_type_flap_neighbor,
6419 bgp_show_type_dampend_paths,
6420 bgp_show_type_damp_neighbor
6421};
6422
ajs5a646652004-11-05 01:25:55 +00006423static int
paulfee0f4c2004-09-13 05:12:46 +00006424bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006425 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006426{
paul718e3742002-12-13 20:15:29 +00006427 struct bgp_info *ri;
6428 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006429 int header = 1;
paul718e3742002-12-13 20:15:29 +00006430 int display;
ajs5a646652004-11-05 01:25:55 +00006431 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006432 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006433
6434 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006435 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006436 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006437
paul718e3742002-12-13 20:15:29 +00006438 /* Start processing of routes. */
6439 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6440 if (rn->info != NULL)
6441 {
6442 display = 0;
6443
6444 for (ri = rn->info; ri; ri = ri->next)
6445 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006446 total_count++;
ajs5a646652004-11-05 01:25:55 +00006447 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006448 || type == bgp_show_type_flap_address
6449 || type == bgp_show_type_flap_prefix
6450 || type == bgp_show_type_flap_cidr_only
6451 || type == bgp_show_type_flap_regexp
6452 || type == bgp_show_type_flap_filter_list
6453 || type == bgp_show_type_flap_prefix_list
6454 || type == bgp_show_type_flap_prefix_longer
6455 || type == bgp_show_type_flap_route_map
6456 || type == bgp_show_type_flap_neighbor
6457 || type == bgp_show_type_dampend_paths
6458 || type == bgp_show_type_damp_neighbor)
6459 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006460 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006461 continue;
6462 }
6463 if (type == bgp_show_type_regexp
6464 || type == bgp_show_type_flap_regexp)
6465 {
ajs5a646652004-11-05 01:25:55 +00006466 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006467
6468 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6469 continue;
6470 }
6471 if (type == bgp_show_type_prefix_list
6472 || type == bgp_show_type_flap_prefix_list)
6473 {
ajs5a646652004-11-05 01:25:55 +00006474 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006475
6476 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6477 continue;
6478 }
6479 if (type == bgp_show_type_filter_list
6480 || type == bgp_show_type_flap_filter_list)
6481 {
ajs5a646652004-11-05 01:25:55 +00006482 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006483
6484 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6485 continue;
6486 }
6487 if (type == bgp_show_type_route_map
6488 || type == bgp_show_type_flap_route_map)
6489 {
ajs5a646652004-11-05 01:25:55 +00006490 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006491 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006492 struct attr dummy_attr;
6493 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006494 int ret;
6495
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006496 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006497 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006498
paul718e3742002-12-13 20:15:29 +00006499 binfo.peer = ri->peer;
6500 binfo.attr = &dummy_attr;
6501
6502 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006503 if (ret == RMAP_DENYMATCH)
6504 continue;
6505 }
6506 if (type == bgp_show_type_neighbor
6507 || type == bgp_show_type_flap_neighbor
6508 || type == bgp_show_type_damp_neighbor)
6509 {
ajs5a646652004-11-05 01:25:55 +00006510 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006511
6512 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6513 continue;
6514 }
6515 if (type == bgp_show_type_cidr_only
6516 || type == bgp_show_type_flap_cidr_only)
6517 {
6518 u_int32_t destination;
6519
6520 destination = ntohl (rn->p.u.prefix4.s_addr);
6521 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6522 continue;
6523 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6524 continue;
6525 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6526 continue;
6527 }
6528 if (type == bgp_show_type_prefix_longer
6529 || type == bgp_show_type_flap_prefix_longer)
6530 {
ajs5a646652004-11-05 01:25:55 +00006531 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006532
6533 if (! prefix_match (p, &rn->p))
6534 continue;
6535 }
6536 if (type == bgp_show_type_community_all)
6537 {
6538 if (! ri->attr->community)
6539 continue;
6540 }
6541 if (type == bgp_show_type_community)
6542 {
ajs5a646652004-11-05 01:25:55 +00006543 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006544
6545 if (! ri->attr->community ||
6546 ! community_match (ri->attr->community, com))
6547 continue;
6548 }
6549 if (type == bgp_show_type_community_exact)
6550 {
ajs5a646652004-11-05 01:25:55 +00006551 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006552
6553 if (! ri->attr->community ||
6554 ! community_cmp (ri->attr->community, com))
6555 continue;
6556 }
6557 if (type == bgp_show_type_community_list)
6558 {
ajs5a646652004-11-05 01:25:55 +00006559 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006560
6561 if (! community_list_match (ri->attr->community, list))
6562 continue;
6563 }
6564 if (type == bgp_show_type_community_list_exact)
6565 {
ajs5a646652004-11-05 01:25:55 +00006566 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006567
6568 if (! community_list_exact_match (ri->attr->community, list))
6569 continue;
6570 }
6571 if (type == bgp_show_type_flap_address
6572 || type == bgp_show_type_flap_prefix)
6573 {
ajs5a646652004-11-05 01:25:55 +00006574 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006575
6576 if (! prefix_match (&rn->p, p))
6577 continue;
6578
6579 if (type == bgp_show_type_flap_prefix)
6580 if (p->prefixlen != rn->p.prefixlen)
6581 continue;
6582 }
6583 if (type == bgp_show_type_dampend_paths
6584 || type == bgp_show_type_damp_neighbor)
6585 {
6586 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6587 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6588 continue;
6589 }
6590
6591 if (header)
6592 {
hasso93406d82005-02-02 14:40:33 +00006593 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6594 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6595 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006596 if (type == bgp_show_type_dampend_paths
6597 || type == bgp_show_type_damp_neighbor)
6598 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6599 else if (type == bgp_show_type_flap_statistics
6600 || type == bgp_show_type_flap_address
6601 || type == bgp_show_type_flap_prefix
6602 || type == bgp_show_type_flap_cidr_only
6603 || type == bgp_show_type_flap_regexp
6604 || type == bgp_show_type_flap_filter_list
6605 || type == bgp_show_type_flap_prefix_list
6606 || type == bgp_show_type_flap_prefix_longer
6607 || type == bgp_show_type_flap_route_map
6608 || type == bgp_show_type_flap_neighbor)
6609 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6610 else
6611 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006612 header = 0;
6613 }
6614
6615 if (type == bgp_show_type_dampend_paths
6616 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006617 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006618 else if (type == bgp_show_type_flap_statistics
6619 || type == bgp_show_type_flap_address
6620 || type == bgp_show_type_flap_prefix
6621 || type == bgp_show_type_flap_cidr_only
6622 || type == bgp_show_type_flap_regexp
6623 || type == bgp_show_type_flap_filter_list
6624 || type == bgp_show_type_flap_prefix_list
6625 || type == bgp_show_type_flap_prefix_longer
6626 || type == bgp_show_type_flap_route_map
6627 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006628 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006629 else
ajs5a646652004-11-05 01:25:55 +00006630 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006631 display++;
6632 }
6633 if (display)
ajs5a646652004-11-05 01:25:55 +00006634 output_count++;
paul718e3742002-12-13 20:15:29 +00006635 }
6636
6637 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006638 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006639 {
6640 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006641 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006642 }
6643 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006644 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6645 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006646
6647 return CMD_SUCCESS;
6648}
6649
ajs5a646652004-11-05 01:25:55 +00006650static int
paulfee0f4c2004-09-13 05:12:46 +00006651bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006652 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006653{
6654 struct bgp_table *table;
6655
6656 if (bgp == NULL) {
6657 bgp = bgp_get_default ();
6658 }
6659
6660 if (bgp == NULL)
6661 {
6662 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6663 return CMD_WARNING;
6664 }
6665
6666
6667 table = bgp->rib[afi][safi];
6668
ajs5a646652004-11-05 01:25:55 +00006669 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006670}
6671
paul718e3742002-12-13 20:15:29 +00006672/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006673static void
paul718e3742002-12-13 20:15:29 +00006674route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6675 struct bgp_node *rn,
6676 struct prefix_rd *prd, afi_t afi, safi_t safi)
6677{
6678 struct bgp_info *ri;
6679 struct prefix *p;
6680 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006681 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006682 char buf1[INET6_ADDRSTRLEN];
6683 char buf2[INET6_ADDRSTRLEN];
6684 int count = 0;
6685 int best = 0;
6686 int suppress = 0;
6687 int no_export = 0;
6688 int no_advertise = 0;
6689 int local_as = 0;
6690 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006691 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006692
6693 p = &rn->p;
6694 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006695 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6696 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006697 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6698 p->prefixlen, VTY_NEWLINE);
6699
6700 for (ri = rn->info; ri; ri = ri->next)
6701 {
6702 count++;
6703 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6704 {
6705 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006706 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006707 suppress = 1;
6708 if (ri->attr->community != NULL)
6709 {
6710 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6711 no_advertise = 1;
6712 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6713 no_export = 1;
6714 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6715 local_as = 1;
6716 }
6717 }
6718 }
6719
6720 vty_out (vty, "Paths: (%d available", count);
6721 if (best)
6722 {
6723 vty_out (vty, ", best #%d", best);
6724 if (safi == SAFI_UNICAST)
6725 vty_out (vty, ", table Default-IP-Routing-Table");
6726 }
6727 else
6728 vty_out (vty, ", no best path");
6729 if (no_advertise)
6730 vty_out (vty, ", not advertised to any peer");
6731 else if (no_export)
6732 vty_out (vty, ", not advertised to EBGP peer");
6733 else if (local_as)
6734 vty_out (vty, ", not advertised outside local AS");
6735 if (suppress)
6736 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6737 vty_out (vty, ")%s", VTY_NEWLINE);
6738
6739 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006740 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006741 {
6742 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6743 {
6744 if (! first)
6745 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6746 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6747 first = 1;
6748 }
6749 }
6750 if (! first)
6751 vty_out (vty, " Not advertised to any peer");
6752 vty_out (vty, "%s", VTY_NEWLINE);
6753}
6754
6755/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006756static int
paulfee0f4c2004-09-13 05:12:46 +00006757bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006758 struct bgp_table *rib, const char *ip_str,
6759 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006760 int prefix_check, enum bgp_path_type pathtype)
paul718e3742002-12-13 20:15:29 +00006761{
6762 int ret;
6763 int header;
6764 int display = 0;
6765 struct prefix match;
6766 struct bgp_node *rn;
6767 struct bgp_node *rm;
6768 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006769 struct bgp_table *table;
6770
Lou Berger050defe2016-01-12 13:41:59 -05006771 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006772 /* Check IP address argument. */
6773 ret = str2prefix (ip_str, &match);
6774 if (! ret)
6775 {
6776 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6777 return CMD_WARNING;
6778 }
6779
6780 match.family = afi2family (afi);
6781
Lou Berger298cc2f2016-01-12 13:42:02 -05006782 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006783 {
paulfee0f4c2004-09-13 05:12:46 +00006784 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006785 {
6786 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6787 continue;
6788
6789 if ((table = rn->info) != NULL)
6790 {
6791 header = 1;
6792
6793 if ((rm = bgp_node_match (table, &match)) != NULL)
6794 {
6795 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006796 {
6797 bgp_unlock_node (rm);
6798 continue;
6799 }
paul718e3742002-12-13 20:15:29 +00006800
6801 for (ri = rm->info; ri; ri = ri->next)
6802 {
6803 if (header)
6804 {
6805 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006806 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006807
6808 header = 0;
6809 }
6810 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006811
6812 if (pathtype == BGP_PATH_ALL ||
6813 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6814 (pathtype == BGP_PATH_MULTIPATH &&
6815 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6816 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006817 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006818
6819 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006820 }
6821 }
6822 }
6823 }
6824 else
6825 {
6826 header = 1;
6827
paulfee0f4c2004-09-13 05:12:46 +00006828 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006829 {
6830 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6831 {
6832 for (ri = rn->info; ri; ri = ri->next)
6833 {
6834 if (header)
6835 {
6836 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6837 header = 0;
6838 }
6839 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006840
6841 if (pathtype == BGP_PATH_ALL ||
6842 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6843 (pathtype == BGP_PATH_MULTIPATH &&
6844 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6845 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00006846 }
6847 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006848
6849 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006850 }
6851 }
6852
6853 if (! display)
6854 {
6855 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6856 return CMD_WARNING;
6857 }
6858
6859 return CMD_SUCCESS;
6860}
6861
paulfee0f4c2004-09-13 05:12:46 +00006862/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006863static int
paulfd79ac92004-10-13 05:06:08 +00006864bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006865 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006866 int prefix_check, enum bgp_path_type pathtype)
paulfee0f4c2004-09-13 05:12:46 +00006867{
6868 struct bgp *bgp;
6869
6870 /* BGP structure lookup. */
6871 if (view_name)
6872 {
6873 bgp = bgp_lookup_by_name (view_name);
6874 if (bgp == NULL)
6875 {
6876 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6877 return CMD_WARNING;
6878 }
6879 }
6880 else
6881 {
6882 bgp = bgp_get_default ();
6883 if (bgp == NULL)
6884 {
6885 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6886 return CMD_WARNING;
6887 }
6888 }
6889
6890 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006891 afi, safi, prd, prefix_check, pathtype);
paulfee0f4c2004-09-13 05:12:46 +00006892}
6893
paul718e3742002-12-13 20:15:29 +00006894/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006895DEFUN (show_ip_bgp,
6896 show_ip_bgp_cmd,
6897 "show ip bgp",
6898 SHOW_STR
6899 IP_STR
6900 BGP_STR)
6901{
6902 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6903}
6904
6905DEFUN (show_ip_bgp_ipv4,
6906 show_ip_bgp_ipv4_cmd,
6907 "show ip bgp ipv4 (unicast|multicast)",
6908 SHOW_STR
6909 IP_STR
6910 BGP_STR
6911 "Address family\n"
6912 "Address Family modifier\n"
6913 "Address Family modifier\n")
6914{
6915 if (strncmp (argv[0], "m", 1) == 0)
6916 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6917 NULL);
6918
6919 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6920}
6921
6922DEFUN (show_ip_bgp_route,
6923 show_ip_bgp_route_cmd,
6924 "show ip bgp A.B.C.D",
6925 SHOW_STR
6926 IP_STR
6927 BGP_STR
6928 "Network in the BGP routing table to display\n")
6929{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006930 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
6931}
6932
6933DEFUN (show_ip_bgp_route_pathtype,
6934 show_ip_bgp_route_pathtype_cmd,
6935 "show ip bgp A.B.C.D (bestpath|multipath)",
6936 SHOW_STR
6937 IP_STR
6938 BGP_STR
6939 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6940 "Display only the bestpath\n"
6941 "Display only multipaths\n")
6942{
6943 if (strncmp (argv[1], "b", 1) == 0)
6944 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6945 else
6946 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
6947}
6948
6949DEFUN (show_bgp_ipv4_safi_route_pathtype,
6950 show_bgp_ipv4_safi_route_pathtype_cmd,
6951 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
6952 SHOW_STR
6953 BGP_STR
6954 "Address family\n"
6955 "Address Family modifier\n"
6956 "Address Family modifier\n"
6957 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6958 "Display only the bestpath\n"
6959 "Display only multipaths\n")
6960{
6961 if (strncmp (argv[0], "m", 1) == 0)
6962 if (strncmp (argv[2], "b", 1) == 0)
6963 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
6964 else
6965 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
6966 else
6967 if (strncmp (argv[2], "b", 1) == 0)
6968 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6969 else
6970 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006971}
6972
6973DEFUN (show_ip_bgp_ipv4_route,
6974 show_ip_bgp_ipv4_route_cmd,
6975 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6976 SHOW_STR
6977 IP_STR
6978 BGP_STR
6979 "Address family\n"
6980 "Address Family modifier\n"
6981 "Address Family modifier\n"
6982 "Network in the BGP routing table to display\n")
6983{
6984 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006985 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006986
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006987 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006988}
6989
6990DEFUN (show_ip_bgp_vpnv4_all_route,
6991 show_ip_bgp_vpnv4_all_route_cmd,
6992 "show ip bgp vpnv4 all A.B.C.D",
6993 SHOW_STR
6994 IP_STR
6995 BGP_STR
6996 "Display VPNv4 NLRI specific information\n"
6997 "Display information about all VPNv4 NLRIs\n"
6998 "Network in the BGP routing table to display\n")
6999{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007000 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 -05007001}
7002
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007003
Lou Bergerf9b6c392016-01-12 13:42:09 -05007004DEFUN (show_ip_bgp_vpnv4_rd_route,
7005 show_ip_bgp_vpnv4_rd_route_cmd,
7006 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7007 SHOW_STR
7008 IP_STR
7009 BGP_STR
7010 "Display VPNv4 NLRI specific information\n"
7011 "Display information for a route distinguisher\n"
7012 "VPN Route Distinguisher\n"
7013 "Network in the BGP routing table to display\n")
7014{
7015 int ret;
7016 struct prefix_rd prd;
7017
7018 ret = str2prefix_rd (argv[0], &prd);
7019 if (! ret)
7020 {
7021 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7022 return CMD_WARNING;
7023 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007024 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 -05007025}
7026
7027DEFUN (show_ip_bgp_prefix,
7028 show_ip_bgp_prefix_cmd,
7029 "show ip bgp A.B.C.D/M",
7030 SHOW_STR
7031 IP_STR
7032 BGP_STR
7033 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7034{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007035 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7036}
7037
7038DEFUN (show_ip_bgp_prefix_pathtype,
7039 show_ip_bgp_prefix_pathtype_cmd,
7040 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7041 SHOW_STR
7042 IP_STR
7043 BGP_STR
7044 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7045 "Display only the bestpath\n"
7046 "Display only multipaths\n")
7047{
7048 if (strncmp (argv[1], "b", 1) == 0)
7049 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7050 else
7051 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007052}
7053
7054DEFUN (show_ip_bgp_ipv4_prefix,
7055 show_ip_bgp_ipv4_prefix_cmd,
7056 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7057 SHOW_STR
7058 IP_STR
7059 BGP_STR
7060 "Address family\n"
7061 "Address Family modifier\n"
7062 "Address Family modifier\n"
7063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7064{
7065 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007066 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007067
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007068 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007069}
7070
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007071DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7072 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7073 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7074 SHOW_STR
7075 IP_STR
7076 BGP_STR
7077 "Address family\n"
7078 "Address Family modifier\n"
7079 "Address Family modifier\n"
7080 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7081 "Display only the bestpath\n"
7082 "Display only multipaths\n")
7083{
7084 if (strncmp (argv[0], "m", 1) == 0)
7085 if (strncmp (argv[2], "b", 1) == 0)
7086 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7087 else
7088 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7089 else
7090 if (strncmp (argv[2], "b", 1) == 0)
7091 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7092 else
7093 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7094}
7095
7096ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7097 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7098 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7099 SHOW_STR
7100 BGP_STR
7101 "Address family\n"
7102 "Address Family modifier\n"
7103 "Address Family modifier\n"
7104 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7105 "Display only the bestpath\n"
7106 "Display only multipaths\n")
7107
Lou Bergerf9b6c392016-01-12 13:42:09 -05007108DEFUN (show_ip_bgp_vpnv4_all_prefix,
7109 show_ip_bgp_vpnv4_all_prefix_cmd,
7110 "show ip bgp vpnv4 all A.B.C.D/M",
7111 SHOW_STR
7112 IP_STR
7113 BGP_STR
7114 "Display VPNv4 NLRI specific information\n"
7115 "Display information about all VPNv4 NLRIs\n"
7116 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7117{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007118 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 -05007119}
7120
7121DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7122 show_ip_bgp_vpnv4_rd_prefix_cmd,
7123 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7124 SHOW_STR
7125 IP_STR
7126 BGP_STR
7127 "Display VPNv4 NLRI specific information\n"
7128 "Display information for a route distinguisher\n"
7129 "VPN Route Distinguisher\n"
7130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7131{
7132 int ret;
7133 struct prefix_rd prd;
7134
7135 ret = str2prefix_rd (argv[0], &prd);
7136 if (! ret)
7137 {
7138 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7139 return CMD_WARNING;
7140 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007141 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 -05007142}
7143
7144DEFUN (show_ip_bgp_view,
7145 show_ip_bgp_view_cmd,
7146 "show ip bgp view WORD",
7147 SHOW_STR
7148 IP_STR
7149 BGP_STR
7150 "BGP view\n"
7151 "View name\n")
7152{
7153 struct bgp *bgp;
7154
7155 /* BGP structure lookup. */
7156 bgp = bgp_lookup_by_name (argv[0]);
7157 if (bgp == NULL)
7158 {
7159 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7160 return CMD_WARNING;
7161 }
7162
7163 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7164}
7165
7166DEFUN (show_ip_bgp_view_route,
7167 show_ip_bgp_view_route_cmd,
7168 "show ip bgp view WORD A.B.C.D",
7169 SHOW_STR
7170 IP_STR
7171 BGP_STR
7172 "BGP view\n"
7173 "View name\n"
7174 "Network in the BGP routing table to display\n")
7175{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007176 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 -05007177}
7178
7179DEFUN (show_ip_bgp_view_prefix,
7180 show_ip_bgp_view_prefix_cmd,
7181 "show ip bgp view WORD A.B.C.D/M",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "BGP view\n"
7186 "View name\n"
7187 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7188{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007189 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 -05007190}
7191
7192DEFUN (show_bgp,
7193 show_bgp_cmd,
7194 "show bgp",
7195 SHOW_STR
7196 BGP_STR)
7197{
7198 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7199 NULL);
7200}
7201
7202ALIAS (show_bgp,
7203 show_bgp_ipv6_cmd,
7204 "show bgp ipv6",
7205 SHOW_STR
7206 BGP_STR
7207 "Address family\n")
7208
7209/* old command */
7210DEFUN (show_ipv6_bgp,
7211 show_ipv6_bgp_cmd,
7212 "show ipv6 bgp",
7213 SHOW_STR
7214 IP_STR
7215 BGP_STR)
7216{
7217 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7218 NULL);
7219}
7220
7221DEFUN (show_bgp_route,
7222 show_bgp_route_cmd,
7223 "show bgp X:X::X:X",
7224 SHOW_STR
7225 BGP_STR
7226 "Network in the BGP routing table to display\n")
7227{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007228 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007229}
7230
Lou Berger35c36862016-01-12 13:42:06 -05007231DEFUN (show_bgp_ipv4_safi,
7232 show_bgp_ipv4_safi_cmd,
7233 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007234 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007235 BGP_STR
7236 "Address family\n"
7237 "Address Family modifier\n"
7238 "Address Family modifier\n")
7239{
7240 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007241 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7242 NULL);
paul718e3742002-12-13 20:15:29 +00007243
ajs5a646652004-11-05 01:25:55 +00007244 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007245}
7246
Lou Berger35c36862016-01-12 13:42:06 -05007247DEFUN (show_bgp_ipv4_safi_route,
7248 show_bgp_ipv4_safi_route_cmd,
7249 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007250 SHOW_STR
7251 BGP_STR
7252 "Address family\n"
7253 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007254 "Address Family modifier\n"
7255 "Network in the BGP routing table to display\n")
7256{
7257 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007258 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007259
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007260 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7261}
7262
7263DEFUN (show_bgp_route_pathtype,
7264 show_bgp_route_pathtype_cmd,
7265 "show bgp X:X::X:X (bestpath|multipath)",
7266 SHOW_STR
7267 BGP_STR
7268 "Network in the BGP routing table to display\n"
7269 "Display only the bestpath\n"
7270 "Display only multipaths\n")
7271{
7272 if (strncmp (argv[1], "b", 1) == 0)
7273 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7274 else
7275 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7276}
7277
7278ALIAS (show_bgp_route_pathtype,
7279 show_bgp_ipv6_route_pathtype_cmd,
7280 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7281 SHOW_STR
7282 BGP_STR
7283 "Address family\n"
7284 "Network in the BGP routing table to display\n"
7285 "Display only the bestpath\n"
7286 "Display only multipaths\n")
7287
7288DEFUN (show_bgp_ipv6_safi_route_pathtype,
7289 show_bgp_ipv6_safi_route_pathtype_cmd,
7290 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7291 SHOW_STR
7292 BGP_STR
7293 "Address family\n"
7294 "Address Family modifier\n"
7295 "Address Family modifier\n"
7296 "Network in the BGP routing table to display\n"
7297 "Display only the bestpath\n"
7298 "Display only multipaths\n")
7299{
7300 if (strncmp (argv[0], "m", 1) == 0)
7301 if (strncmp (argv[2], "b", 1) == 0)
7302 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7303 else
7304 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7305 else
7306 if (strncmp (argv[2], "b", 1) == 0)
7307 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7308 else
7309 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007310}
7311
Lou Berger35c36862016-01-12 13:42:06 -05007312DEFUN (show_bgp_ipv4_vpn_route,
7313 show_bgp_ipv4_vpn_route_cmd,
7314 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007315 SHOW_STR
7316 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007317 "Address Family\n"
7318 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007319 "Network in the BGP routing table to display\n")
7320{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007321 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007322}
7323
Lou Berger35c36862016-01-12 13:42:06 -05007324DEFUN (show_bgp_ipv6_vpn_route,
7325 show_bgp_ipv6_vpn_route_cmd,
7326 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007327 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007328 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007329 "Address Family\n"
7330 "Display VPN NLRI specific information\n"
7331 "Network in the BGP routing table to display\n")
7332{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007333 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 -05007334}
Lou Berger35c36862016-01-12 13:42:06 -05007335
7336DEFUN (show_bgp_ipv4_vpn_rd_route,
7337 show_bgp_ipv4_vpn_rd_route_cmd,
7338 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7339 SHOW_STR
7340 BGP_STR
7341 IP_STR
7342 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007343 "Display information for a route distinguisher\n"
7344 "VPN Route Distinguisher\n"
7345 "Network in the BGP routing table to display\n")
7346{
7347 int ret;
7348 struct prefix_rd prd;
7349
7350 ret = str2prefix_rd (argv[0], &prd);
7351 if (! ret)
7352 {
7353 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7354 return CMD_WARNING;
7355 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007356 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007357}
7358
Lou Berger35c36862016-01-12 13:42:06 -05007359DEFUN (show_bgp_ipv6_vpn_rd_route,
7360 show_bgp_ipv6_vpn_rd_route_cmd,
7361 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007362 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007363 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007364 "Address Family\n"
7365 "Display VPN NLRI specific information\n"
7366 "Display information for a route distinguisher\n"
7367 "VPN Route Distinguisher\n"
7368 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007369{
Lou Berger35c36862016-01-12 13:42:06 -05007370 int ret;
7371 struct prefix_rd prd;
7372
7373 ret = str2prefix_rd (argv[0], &prd);
7374 if (! ret)
7375 {
7376 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7377 return CMD_WARNING;
7378 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007379 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7380}
7381
7382DEFUN (show_bgp_prefix_pathtype,
7383 show_bgp_prefix_pathtype_cmd,
7384 "show bgp X:X::X:X/M (bestpath|multipath)",
7385 SHOW_STR
7386 BGP_STR
7387 "IPv6 prefix <network>/<length>\n"
7388 "Display only the bestpath\n"
7389 "Display only multipaths\n")
7390{
7391 if (strncmp (argv[1], "b", 1) == 0)
7392 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7393 else
7394 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7395}
7396
7397ALIAS (show_bgp_prefix_pathtype,
7398 show_bgp_ipv6_prefix_pathtype_cmd,
7399 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7400 SHOW_STR
7401 BGP_STR
7402 "Address family\n"
7403 "IPv6 prefix <network>/<length>\n"
7404 "Display only the bestpath\n"
7405 "Display only multipaths\n")
7406
7407DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7408 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7409 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7410 SHOW_STR
7411 BGP_STR
7412 "Address family\n"
7413 "Address Family modifier\n"
7414 "Address Family modifier\n"
7415 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7416 "Display only the bestpath\n"
7417 "Display only multipaths\n")
7418{
7419 if (strncmp (argv[0], "m", 1) == 0)
7420 if (strncmp (argv[2], "b", 1) == 0)
7421 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7422 else
7423 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7424 else
7425 if (strncmp (argv[2], "b", 1) == 0)
7426 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7427 else
7428 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007429}
7430
Lou Berger651b4022016-01-12 13:42:07 -05007431DEFUN (show_bgp_ipv4_encap_route,
7432 show_bgp_ipv4_encap_route_cmd,
7433 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007434 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007435 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007436 IP_STR
7437 "Display ENCAP NLRI specific information\n"
7438 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007439{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007440 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007441}
7442
Lou Berger651b4022016-01-12 13:42:07 -05007443DEFUN (show_bgp_ipv6_encap_route,
7444 show_bgp_ipv6_encap_route_cmd,
7445 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007446 SHOW_STR
7447 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007448 IP6_STR
7449 "Display ENCAP NLRI specific information\n"
7450 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007451{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007452 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007453}
7454
Lou Berger651b4022016-01-12 13:42:07 -05007455DEFUN (show_bgp_ipv4_safi_rd_route,
7456 show_bgp_ipv4_safi_rd_route_cmd,
7457 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007458 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007459 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007460 "Address Family\n"
7461 "Address Family Modifier\n"
7462 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007463 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007464 "ENCAP Route Distinguisher\n"
7465 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007466{
7467 int ret;
7468 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007469 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007470
Lou Berger651b4022016-01-12 13:42:07 -05007471 if (bgp_parse_safi(argv[0], &safi)) {
7472 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7473 return CMD_WARNING;
7474 }
7475 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007476 if (! ret)
7477 {
7478 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7479 return CMD_WARNING;
7480 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007481 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007482}
7483
Lou Berger651b4022016-01-12 13:42:07 -05007484DEFUN (show_bgp_ipv6_safi_rd_route,
7485 show_bgp_ipv6_safi_rd_route_cmd,
7486 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007487 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007488 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007489 "Address Family\n"
7490 "Address Family Modifier\n"
7491 "Address Family Modifier\n"
7492 "Display information for a route distinguisher\n"
7493 "ENCAP Route Distinguisher\n"
7494 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007495{
Lou Berger651b4022016-01-12 13:42:07 -05007496 int ret;
7497 struct prefix_rd prd;
7498 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007499
Lou Berger651b4022016-01-12 13:42:07 -05007500 if (bgp_parse_safi(argv[0], &safi)) {
7501 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7502 return CMD_WARNING;
7503 }
7504 ret = str2prefix_rd (argv[1], &prd);
7505 if (! ret)
7506 {
7507 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7508 return CMD_WARNING;
7509 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007510 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007511}
7512
Lou Berger35c36862016-01-12 13:42:06 -05007513DEFUN (show_bgp_ipv4_prefix,
7514 show_bgp_ipv4_prefix_cmd,
7515 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007516 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007517 BGP_STR
paul718e3742002-12-13 20:15:29 +00007518 IP_STR
paul718e3742002-12-13 20:15:29 +00007519 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7520{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007521 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007522}
7523
Lou Berger35c36862016-01-12 13:42:06 -05007524DEFUN (show_bgp_ipv4_safi_prefix,
7525 show_bgp_ipv4_safi_prefix_cmd,
7526 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007527 SHOW_STR
7528 BGP_STR
7529 "Address family\n"
7530 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007531 "Address Family modifier\n"
7532 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007533{
7534 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007535 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007536
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007537 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007538}
7539
Lou Berger35c36862016-01-12 13:42:06 -05007540DEFUN (show_bgp_ipv4_vpn_prefix,
7541 show_bgp_ipv4_vpn_prefix_cmd,
7542 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007543 SHOW_STR
7544 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007545 IP_STR
7546 "Display VPN NLRI specific information\n"
7547 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007548{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007549 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007550}
7551
Lou Berger35c36862016-01-12 13:42:06 -05007552DEFUN (show_bgp_ipv6_vpn_prefix,
7553 show_bgp_ipv6_vpn_prefix_cmd,
7554 "show bgp ipv6 vpn X:X::X:X/M",
7555 SHOW_STR
7556 BGP_STR
7557 "Address Family\n"
7558 "Display VPN NLRI specific information\n"
7559 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7560{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007561 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 -05007562}
Lou Berger35c36862016-01-12 13:42:06 -05007563
Lou Berger651b4022016-01-12 13:42:07 -05007564DEFUN (show_bgp_ipv4_encap_prefix,
7565 show_bgp_ipv4_encap_prefix_cmd,
7566 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007567 SHOW_STR
7568 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007569 IP_STR
7570 "Display ENCAP NLRI specific information\n"
7571 "Display information about ENCAP NLRIs\n"
7572 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7573{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007574 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007575}
paul718e3742002-12-13 20:15:29 +00007576
Lou Berger651b4022016-01-12 13:42:07 -05007577DEFUN (show_bgp_ipv6_encap_prefix,
7578 show_bgp_ipv6_encap_prefix_cmd,
7579 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007580 SHOW_STR
7581 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007582 IP_STR
7583 "Display ENCAP NLRI specific information\n"
7584 "Display information about ENCAP NLRIs\n"
7585 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7586{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007587 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007588}
Lou Berger651b4022016-01-12 13:42:07 -05007589
7590DEFUN (show_bgp_ipv4_safi_rd_prefix,
7591 show_bgp_ipv4_safi_rd_prefix_cmd,
7592 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7593 SHOW_STR
7594 BGP_STR
7595 "Address Family\n"
7596 "Address Family Modifier\n"
7597 "Address Family Modifier\n"
7598 "Display information for a route distinguisher\n"
7599 "ENCAP Route Distinguisher\n"
7600 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7601{
7602 int ret;
7603 struct prefix_rd prd;
7604 safi_t safi;
7605
7606 if (bgp_parse_safi(argv[0], &safi)) {
7607 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7608 return CMD_WARNING;
7609 }
7610
7611 ret = str2prefix_rd (argv[1], &prd);
7612 if (! ret)
7613 {
7614 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7615 return CMD_WARNING;
7616 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007617 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007618}
7619
Lou Berger651b4022016-01-12 13:42:07 -05007620DEFUN (show_bgp_ipv6_safi_rd_prefix,
7621 show_bgp_ipv6_safi_rd_prefix_cmd,
7622 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7623 SHOW_STR
7624 BGP_STR
7625 "Address Family\n"
7626 "Address Family Modifier\n"
7627 "Address Family Modifier\n"
7628 "Display information for a route distinguisher\n"
7629 "ENCAP Route Distinguisher\n"
7630 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7631{
7632 int ret;
7633 struct prefix_rd prd;
7634 safi_t safi;
7635
7636 if (bgp_parse_safi(argv[0], &safi)) {
7637 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7638 return CMD_WARNING;
7639 }
7640
7641 ret = str2prefix_rd (argv[1], &prd);
7642 if (! ret)
7643 {
7644 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7645 return CMD_WARNING;
7646 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007647 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007648}
Lou Berger651b4022016-01-12 13:42:07 -05007649
7650DEFUN (show_bgp_afi_safi_view,
7651 show_bgp_afi_safi_view_cmd,
7652 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7653 SHOW_STR
7654 BGP_STR
7655 "BGP view\n"
7656 "BGP view name\n"
7657 "Address Family\n"
7658 "Address Family\n"
7659 "Address Family Modifier\n"
7660 "Address Family Modifier\n"
7661 "Address Family Modifier\n"
7662 "Address Family Modifier\n"
7663 )
7664{
7665 struct bgp *bgp;
7666 safi_t safi;
7667 afi_t afi;
7668
7669 if (bgp_parse_afi(argv[1], &afi)) {
7670 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7671 return CMD_WARNING;
7672 }
7673 if (bgp_parse_safi(argv[2], &safi)) {
7674 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7675 return CMD_WARNING;
7676 }
7677
7678 /* BGP structure lookup. */
7679 bgp = bgp_lookup_by_name (argv[0]);
7680 if (bgp == NULL)
7681 {
7682 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7683 return CMD_WARNING;
7684 }
7685
7686 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7687}
7688
7689DEFUN (show_bgp_view_afi_safi_route,
7690 show_bgp_view_afi_safi_route_cmd,
7691 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7692 SHOW_STR
7693 BGP_STR
7694 "BGP view\n"
7695 "View name\n"
7696 "Address Family\n"
7697 "Address Family\n"
7698 "Address Family Modifier\n"
7699 "Address Family Modifier\n"
7700 "Address Family Modifier\n"
7701 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007702 "Network in the BGP routing table to display\n")
7703{
Lou Berger651b4022016-01-12 13:42:07 -05007704 safi_t safi;
7705 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007706
Lou Berger651b4022016-01-12 13:42:07 -05007707 if (bgp_parse_afi(argv[1], &afi)) {
7708 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7709 return CMD_WARNING;
7710 }
7711 if (bgp_parse_safi(argv[2], &safi)) {
7712 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7713 return CMD_WARNING;
7714 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007715 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007716}
7717
7718DEFUN (show_bgp_view_afi_safi_prefix,
7719 show_bgp_view_afi_safi_prefix_cmd,
7720 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7721 SHOW_STR
7722 BGP_STR
7723 "BGP view\n"
7724 "View name\n"
7725 "Address Family\n"
7726 "Address Family\n"
7727 "Address Family Modifier\n"
7728 "Address Family Modifier\n"
7729 "Address Family Modifier\n"
7730 "Address Family Modifier\n"
7731 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7732{
7733 safi_t safi;
7734 afi_t afi;
7735
7736 if (bgp_parse_afi(argv[1], &afi)) {
7737 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7738 return CMD_WARNING;
7739 }
7740 if (bgp_parse_safi(argv[2], &safi)) {
7741 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7742 return CMD_WARNING;
7743 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007744 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007745}
7746
7747/* new001 */
7748DEFUN (show_bgp_afi,
7749 show_bgp_afi_cmd,
7750 "show bgp (ipv4|ipv6)",
7751 SHOW_STR
7752 BGP_STR
7753 "Address family\n"
7754 "Address family\n")
7755{
7756 afi_t afi;
7757
7758 if (bgp_parse_afi(argv[0], &afi)) {
7759 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7760 return CMD_WARNING;
7761 }
7762 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7763 NULL);
7764}
7765
Lou Berger651b4022016-01-12 13:42:07 -05007766DEFUN (show_bgp_ipv6_safi,
7767 show_bgp_ipv6_safi_cmd,
7768 "show bgp ipv6 (unicast|multicast)",
7769 SHOW_STR
7770 BGP_STR
7771 "Address family\n"
7772 "Address Family modifier\n"
7773 "Address Family modifier\n")
7774{
7775 if (strncmp (argv[0], "m", 1) == 0)
7776 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7777 NULL);
7778
7779 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007780}
7781
Lou Berger35c36862016-01-12 13:42:06 -05007782DEFUN (show_bgp_ipv6_route,
7783 show_bgp_ipv6_route_cmd,
7784 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007785 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007786 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007787 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007788 "Network in the BGP routing table to display\n")
7789{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007790 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007791}
7792
Lou Berger35c36862016-01-12 13:42:06 -05007793DEFUN (show_bgp_ipv6_safi_route,
7794 show_bgp_ipv6_safi_route_cmd,
7795 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007796 SHOW_STR
7797 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007798 "Address family\n"
7799 "Address Family modifier\n"
7800 "Address Family modifier\n"
7801 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007802{
Lou Berger35c36862016-01-12 13:42:06 -05007803 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007804 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007805
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007806 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007807}
7808
Lou Bergerf9b6c392016-01-12 13:42:09 -05007809/* old command */
7810DEFUN (show_ipv6_bgp_route,
7811 show_ipv6_bgp_route_cmd,
7812 "show ipv6 bgp X:X::X:X",
7813 SHOW_STR
7814 IP_STR
7815 BGP_STR
7816 "Network in the BGP routing table to display\n")
7817{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007818 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007819}
7820
7821DEFUN (show_bgp_prefix,
7822 show_bgp_prefix_cmd,
7823 "show bgp X:X::X:X/M",
7824 SHOW_STR
7825 BGP_STR
7826 "IPv6 prefix <network>/<length>\n")
7827{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007828 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007829}
7830
7831
Lou Berger35c36862016-01-12 13:42:06 -05007832/* new002 */
7833DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007834 show_bgp_ipv6_prefix_cmd,
7835 "show bgp ipv6 X:X::X:X/M",
7836 SHOW_STR
7837 BGP_STR
7838 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007839 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7840{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007841 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007842}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007843DEFUN (show_bgp_ipv6_safi_prefix,
7844 show_bgp_ipv6_safi_prefix_cmd,
7845 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7846 SHOW_STR
7847 BGP_STR
7848 "Address family\n"
7849 "Address Family modifier\n"
7850 "Address Family modifier\n"
7851 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7852{
7853 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007854 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007855
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007856 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007857}
7858
Lou Bergerf9b6c392016-01-12 13:42:09 -05007859/* old command */
7860DEFUN (show_ipv6_bgp_prefix,
7861 show_ipv6_bgp_prefix_cmd,
7862 "show ipv6 bgp X:X::X:X/M",
7863 SHOW_STR
7864 IP_STR
7865 BGP_STR
7866 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7867{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007868 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007869}
7870
paulbb46e942003-10-24 19:02:03 +00007871DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007872 show_bgp_view_cmd,
7873 "show bgp view WORD",
7874 SHOW_STR
7875 BGP_STR
7876 "BGP view\n"
7877 "View name\n")
7878{
7879 struct bgp *bgp;
7880
7881 /* BGP structure lookup. */
7882 bgp = bgp_lookup_by_name (argv[0]);
7883 if (bgp == NULL)
7884 {
7885 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7886 return CMD_WARNING;
7887 }
7888
7889 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7890}
7891
7892DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007893 show_bgp_view_ipv6_cmd,
7894 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007895 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007896 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007897 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007898 "View name\n"
7899 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007900{
7901 struct bgp *bgp;
7902
7903 /* BGP structure lookup. */
7904 bgp = bgp_lookup_by_name (argv[0]);
7905 if (bgp == NULL)
7906 {
7907 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7908 return CMD_WARNING;
7909 }
7910
ajs5a646652004-11-05 01:25:55 +00007911 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007912}
paulbb46e942003-10-24 19:02:03 +00007913
7914DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007915 show_bgp_view_route_cmd,
7916 "show bgp view WORD X:X::X:X",
7917 SHOW_STR
7918 BGP_STR
7919 "BGP view\n"
7920 "View name\n"
7921 "Network in the BGP routing table to display\n")
7922{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007923 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 -05007924}
7925
7926DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007927 show_bgp_view_ipv6_route_cmd,
7928 "show bgp view WORD ipv6 X:X::X:X",
7929 SHOW_STR
7930 BGP_STR
7931 "BGP view\n"
7932 "View name\n"
7933 "Address family\n"
7934 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007935{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007936 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulbb46e942003-10-24 19:02:03 +00007937}
7938
Lou Bergerf9b6c392016-01-12 13:42:09 -05007939/* old command */
7940DEFUN (show_ipv6_mbgp,
7941 show_ipv6_mbgp_cmd,
7942 "show ipv6 mbgp",
7943 SHOW_STR
7944 IP_STR
7945 MBGP_STR)
7946{
7947 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7948 NULL);
7949}
7950
7951/* old command */
7952DEFUN (show_ipv6_mbgp_route,
7953 show_ipv6_mbgp_route_cmd,
7954 "show ipv6 mbgp X:X::X:X",
7955 SHOW_STR
7956 IP_STR
7957 MBGP_STR
7958 "Network in the MBGP routing table to display\n")
7959{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007960 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007961}
7962
7963/* old command */
7964DEFUN (show_ipv6_mbgp_prefix,
7965 show_ipv6_mbgp_prefix_cmd,
7966 "show ipv6 mbgp X:X::X:X/M",
7967 SHOW_STR
7968 IP_STR
7969 MBGP_STR
7970 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7971{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007972 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007973}
7974
Lou Berger35c36862016-01-12 13:42:06 -05007975DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007976 show_bgp_view_prefix_cmd,
7977 "show bgp view WORD X:X::X:X/M",
7978 SHOW_STR
7979 BGP_STR
7980 "BGP view\n"
7981 "View name\n"
7982 "IPv6 prefix <network>/<length>\n")
7983{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007984 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 -05007985}
7986
7987DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007988 show_bgp_view_ipv6_prefix_cmd,
7989 "show bgp view WORD ipv6 X:X::X:X/M",
7990 SHOW_STR
7991 BGP_STR
7992 "BGP view\n"
7993 "View name\n"
7994 "Address family\n"
7995 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007996{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007997 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007998}
7999
paul94f2b392005-06-28 12:44:16 +00008000static int
paulfd79ac92004-10-13 05:06:08 +00008001bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008002 safi_t safi, enum bgp_show_type type)
8003{
8004 int i;
8005 struct buffer *b;
8006 char *regstr;
8007 int first;
8008 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00008009 int rc;
paul718e3742002-12-13 20:15:29 +00008010
8011 first = 0;
8012 b = buffer_new (1024);
8013 for (i = 0; i < argc; i++)
8014 {
8015 if (first)
8016 buffer_putc (b, ' ');
8017 else
8018 {
8019 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8020 continue;
8021 first = 1;
8022 }
8023
8024 buffer_putstr (b, argv[i]);
8025 }
8026 buffer_putc (b, '\0');
8027
8028 regstr = buffer_getstr (b);
8029 buffer_free (b);
8030
8031 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00008032 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00008033 if (! regex)
8034 {
8035 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8036 VTY_NEWLINE);
8037 return CMD_WARNING;
8038 }
8039
ajs5a646652004-11-05 01:25:55 +00008040 rc = bgp_show (vty, NULL, afi, safi, type, regex);
8041 bgp_regex_free (regex);
8042 return rc;
paul718e3742002-12-13 20:15:29 +00008043}
8044
Lou Bergerf9b6c392016-01-12 13:42:09 -05008045
8046DEFUN (show_ip_bgp_regexp,
8047 show_ip_bgp_regexp_cmd,
8048 "show ip bgp regexp .LINE",
8049 SHOW_STR
8050 IP_STR
8051 BGP_STR
8052 "Display routes matching the AS path regular expression\n"
8053 "A regular-expression to match the BGP AS paths\n")
8054{
8055 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8056 bgp_show_type_regexp);
8057}
8058
8059DEFUN (show_ip_bgp_flap_regexp,
8060 show_ip_bgp_flap_regexp_cmd,
8061 "show ip bgp flap-statistics regexp .LINE",
8062 SHOW_STR
8063 IP_STR
8064 BGP_STR
8065 "Display flap statistics of routes\n"
8066 "Display routes matching the AS path regular expression\n"
8067 "A regular-expression to match the BGP AS paths\n")
8068{
8069 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8070 bgp_show_type_flap_regexp);
8071}
8072
8073ALIAS (show_ip_bgp_flap_regexp,
8074 show_ip_bgp_damp_flap_regexp_cmd,
8075 "show ip bgp dampening flap-statistics regexp .LINE",
8076 SHOW_STR
8077 IP_STR
8078 BGP_STR
8079 "Display detailed information about dampening\n"
8080 "Display flap statistics of routes\n"
8081 "Display routes matching the AS path regular expression\n"
8082 "A regular-expression to match the BGP AS paths\n")
8083
8084DEFUN (show_ip_bgp_ipv4_regexp,
8085 show_ip_bgp_ipv4_regexp_cmd,
8086 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8087 SHOW_STR
8088 IP_STR
8089 BGP_STR
8090 "Address family\n"
8091 "Address Family modifier\n"
8092 "Address Family modifier\n"
8093 "Display routes matching the AS path regular expression\n"
8094 "A regular-expression to match the BGP AS paths\n")
8095{
8096 if (strncmp (argv[0], "m", 1) == 0)
8097 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8098 bgp_show_type_regexp);
8099
8100 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8101 bgp_show_type_regexp);
8102}
8103
Lou Bergerf9b6c392016-01-12 13:42:09 -05008104DEFUN (show_bgp_regexp,
8105 show_bgp_regexp_cmd,
8106 "show bgp regexp .LINE",
8107 SHOW_STR
8108 BGP_STR
8109 "Display routes matching the AS path regular expression\n"
8110 "A regular-expression to match the BGP AS paths\n")
8111{
8112 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8113 bgp_show_type_regexp);
8114}
8115
8116/* old command */
8117DEFUN (show_ipv6_bgp_regexp,
8118 show_ipv6_bgp_regexp_cmd,
8119 "show ipv6 bgp regexp .LINE",
8120 SHOW_STR
8121 IP_STR
8122 BGP_STR
8123 "Display routes matching the AS path regular expression\n"
8124 "A regular-expression to match the BGP AS paths\n")
8125{
8126 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8127 bgp_show_type_regexp);
8128}
8129
8130/* old command */
8131DEFUN (show_ipv6_mbgp_regexp,
8132 show_ipv6_mbgp_regexp_cmd,
8133 "show ipv6 mbgp regexp .LINE",
8134 SHOW_STR
8135 IP_STR
8136 BGP_STR
8137 "Display routes matching the AS path regular expression\n"
8138 "A regular-expression to match the MBGP AS paths\n")
8139{
8140 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8141 bgp_show_type_regexp);
8142}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008143
Lou Berger651b4022016-01-12 13:42:07 -05008144DEFUN (show_bgp_ipv4_safi_flap_regexp,
8145 show_bgp_ipv4_safi_flap_regexp_cmd,
8146 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008147 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008148 BGP_STR
paul718e3742002-12-13 20:15:29 +00008149 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008150 "Address Family Modifier\n"
8151 "Address Family Modifier\n"
8152 "Address Family Modifier\n"
8153 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008154 "Display flap statistics of routes\n"
8155 "Display routes matching the AS path regular expression\n"
8156 "A regular-expression to match the BGP AS paths\n")
8157{
Lou Berger651b4022016-01-12 13:42:07 -05008158 safi_t safi;
8159
8160 if (bgp_parse_safi(argv[0], &safi)) {
8161 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8162 return CMD_WARNING;
8163 }
8164 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8165 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008166}
8167
Lou Berger651b4022016-01-12 13:42:07 -05008168ALIAS (show_bgp_ipv4_safi_flap_regexp,
8169 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8170 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308171 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308172 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008173 IP_STR
8174 "Address Family Modifier\n"
8175 "Address Family Modifier\n"
8176 "Address Family Modifier\n"
8177 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308178 "Display detailed information about dampening\n"
8179 "Display flap statistics of routes\n"
8180 "Display routes matching the AS path regular expression\n"
8181 "A regular-expression to match the BGP AS paths\n")
8182
Lou Berger651b4022016-01-12 13:42:07 -05008183DEFUN (show_bgp_ipv6_safi_flap_regexp,
8184 show_bgp_ipv6_safi_flap_regexp_cmd,
8185 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008186 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008187 BGP_STR
8188 IPV6_STR
8189 "Address Family Modifier\n"
8190 "Address Family Modifier\n"
8191 "Address Family Modifier\n"
8192 "Address Family Modifier\n"
8193 "Display flap statistics of routes\n"
8194 "Display routes matching the AS path regular expression\n"
8195 "A regular-expression to match the BGP AS paths\n")
8196{
8197 safi_t safi;
8198
8199 if (bgp_parse_safi(argv[0], &safi)) {
8200 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8201 return CMD_WARNING;
8202 }
8203 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8204 bgp_show_type_flap_regexp);
8205}
8206
8207ALIAS (show_bgp_ipv6_safi_flap_regexp,
8208 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8209 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8210 SHOW_STR
8211 BGP_STR
8212 IPV6_STR
8213 "Address Family Modifier\n"
8214 "Address Family Modifier\n"
8215 "Address Family Modifier\n"
8216 "Address Family Modifier\n"
8217 "Display detailed information about dampening\n"
8218 "Display flap statistics of routes\n"
8219 "Display routes matching the AS path regular expression\n"
8220 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008221
8222DEFUN (show_bgp_ipv4_safi_regexp,
8223 show_bgp_ipv4_safi_regexp_cmd,
8224 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8225 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008226 BGP_STR
8227 "Address family\n"
8228 "Address Family modifier\n"
8229 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008230 "Address Family modifier\n"
8231 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008232 "Display routes matching the AS path regular expression\n"
8233 "A regular-expression to match the BGP AS paths\n")
8234{
Lou Berger651b4022016-01-12 13:42:07 -05008235 safi_t safi;
8236 if (bgp_parse_safi(argv[0], &safi)) {
8237 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8238 return CMD_WARNING;
8239 }
paul718e3742002-12-13 20:15:29 +00008240
Lou Berger651b4022016-01-12 13:42:07 -05008241 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008242 bgp_show_type_regexp);
8243}
Lou Berger205e6742016-01-12 13:42:11 -05008244
Lou Berger651b4022016-01-12 13:42:07 -05008245DEFUN (show_bgp_ipv6_safi_regexp,
8246 show_bgp_ipv6_safi_regexp_cmd,
8247 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008248 SHOW_STR
8249 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008250 "Address family\n"
8251 "Address Family modifier\n"
8252 "Address Family modifier\n"
8253 "Address Family modifier\n"
8254 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008255 "Display routes matching the AS path regular expression\n"
8256 "A regular-expression to match the BGP AS paths\n")
8257{
Lou Berger651b4022016-01-12 13:42:07 -05008258 safi_t safi;
8259 if (bgp_parse_safi(argv[0], &safi)) {
8260 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8261 return CMD_WARNING;
8262 }
8263
8264 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008265 bgp_show_type_regexp);
8266}
8267
Lou Berger651b4022016-01-12 13:42:07 -05008268DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008269 show_bgp_ipv6_regexp_cmd,
8270 "show bgp ipv6 regexp .LINE",
8271 SHOW_STR
8272 BGP_STR
8273 "Address family\n"
8274 "Display routes matching the AS path regular expression\n"
8275 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008276{
8277 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8278 bgp_show_type_regexp);
8279}
8280
paul94f2b392005-06-28 12:44:16 +00008281static int
paulfd79ac92004-10-13 05:06:08 +00008282bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008283 safi_t safi, enum bgp_show_type type)
8284{
8285 struct prefix_list *plist;
8286
8287 plist = prefix_list_lookup (afi, prefix_list_str);
8288 if (plist == NULL)
8289 {
8290 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8291 prefix_list_str, VTY_NEWLINE);
8292 return CMD_WARNING;
8293 }
8294
ajs5a646652004-11-05 01:25:55 +00008295 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008296}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008297DEFUN (show_ip_bgp_prefix_list,
8298 show_ip_bgp_prefix_list_cmd,
8299 "show ip bgp prefix-list WORD",
8300 SHOW_STR
8301 IP_STR
8302 BGP_STR
8303 "Display routes conforming to the prefix-list\n"
8304 "IP prefix-list name\n")
8305{
8306 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8307 bgp_show_type_prefix_list);
8308}
8309
8310DEFUN (show_ip_bgp_flap_prefix_list,
8311 show_ip_bgp_flap_prefix_list_cmd,
8312 "show ip bgp flap-statistics prefix-list WORD",
8313 SHOW_STR
8314 IP_STR
8315 BGP_STR
8316 "Display flap statistics of routes\n"
8317 "Display routes conforming to the prefix-list\n"
8318 "IP prefix-list name\n")
8319{
8320 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8321 bgp_show_type_flap_prefix_list);
8322}
8323
8324ALIAS (show_ip_bgp_flap_prefix_list,
8325 show_ip_bgp_damp_flap_prefix_list_cmd,
8326 "show ip bgp dampening flap-statistics prefix-list WORD",
8327 SHOW_STR
8328 IP_STR
8329 BGP_STR
8330 "Display detailed information about dampening\n"
8331 "Display flap statistics of routes\n"
8332 "Display routes conforming to the prefix-list\n"
8333 "IP prefix-list name\n")
8334
8335DEFUN (show_ip_bgp_ipv4_prefix_list,
8336 show_ip_bgp_ipv4_prefix_list_cmd,
8337 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8338 SHOW_STR
8339 IP_STR
8340 BGP_STR
8341 "Address family\n"
8342 "Address Family modifier\n"
8343 "Address Family modifier\n"
8344 "Display routes conforming to the prefix-list\n"
8345 "IP prefix-list name\n")
8346{
8347 if (strncmp (argv[0], "m", 1) == 0)
8348 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8349 bgp_show_type_prefix_list);
8350
8351 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8352 bgp_show_type_prefix_list);
8353}
8354
Lou Bergerf9b6c392016-01-12 13:42:09 -05008355DEFUN (show_bgp_prefix_list,
8356 show_bgp_prefix_list_cmd,
8357 "show bgp prefix-list WORD",
8358 SHOW_STR
8359 BGP_STR
8360 "Display routes conforming to the prefix-list\n"
8361 "IPv6 prefix-list name\n")
8362{
8363 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8364 bgp_show_type_prefix_list);
8365}
8366
8367ALIAS (show_bgp_prefix_list,
8368 show_bgp_ipv6_prefix_list_cmd,
8369 "show bgp ipv6 prefix-list WORD",
8370 SHOW_STR
8371 BGP_STR
8372 "Address family\n"
8373 "Display routes conforming to the prefix-list\n"
8374 "IPv6 prefix-list name\n")
8375
8376/* old command */
8377DEFUN (show_ipv6_bgp_prefix_list,
8378 show_ipv6_bgp_prefix_list_cmd,
8379 "show ipv6 bgp prefix-list WORD",
8380 SHOW_STR
8381 IPV6_STR
8382 BGP_STR
8383 "Display routes matching the prefix-list\n"
8384 "IPv6 prefix-list name\n")
8385{
8386 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8387 bgp_show_type_prefix_list);
8388}
8389
8390/* old command */
8391DEFUN (show_ipv6_mbgp_prefix_list,
8392 show_ipv6_mbgp_prefix_list_cmd,
8393 "show ipv6 mbgp prefix-list WORD",
8394 SHOW_STR
8395 IPV6_STR
8396 MBGP_STR
8397 "Display routes matching the prefix-list\n"
8398 "IPv6 prefix-list name\n")
8399{
8400 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8401 bgp_show_type_prefix_list);
8402}
paul718e3742002-12-13 20:15:29 +00008403
Lou Berger35c36862016-01-12 13:42:06 -05008404DEFUN (show_bgp_ipv4_prefix_list,
8405 show_bgp_ipv4_prefix_list_cmd,
8406 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008407 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008408 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008409 IP_STR
paul718e3742002-12-13 20:15:29 +00008410 "Display routes conforming to the prefix-list\n"
8411 "IP prefix-list name\n")
8412{
8413 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8414 bgp_show_type_prefix_list);
8415}
8416
Lou Berger651b4022016-01-12 13:42:07 -05008417DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8418 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8419 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008420 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008421 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008422 IP_STR
8423 "Address Family Modifier\n"
8424 "Address Family Modifier\n"
8425 "Address Family Modifier\n"
8426 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008427 "Display flap statistics of routes\n"
8428 "Display routes conforming to the prefix-list\n"
8429 "IP prefix-list name\n")
8430{
Lou Berger651b4022016-01-12 13:42:07 -05008431 safi_t safi;
8432 if (bgp_parse_safi(argv[0], &safi)) {
8433 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8434 return CMD_WARNING;
8435 }
8436 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008437 bgp_show_type_flap_prefix_list);
8438}
8439
Lou Berger651b4022016-01-12 13:42:07 -05008440ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8441 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8442 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308443 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308444 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008445 IP_STR
8446 "Address Family Modifier\n"
8447 "Address Family Modifier\n"
8448 "Address Family Modifier\n"
8449 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308450 "Display detailed information about dampening\n"
8451 "Display flap statistics of routes\n"
8452 "Display routes conforming to the prefix-list\n"
8453 "IP prefix-list name\n")
8454
Lou Berger651b4022016-01-12 13:42:07 -05008455DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8456 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8457 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008458 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008459 BGP_STR
8460 IPV6_STR
8461 "Address Family Modifier\n"
8462 "Address Family Modifier\n"
8463 "Address Family Modifier\n"
8464 "Address Family Modifier\n"
8465 "Display flap statistics of routes\n"
8466 "Display routes conforming to the prefix-list\n"
8467 "IP prefix-list name\n")
8468{
8469 safi_t safi;
8470 if (bgp_parse_safi(argv[0], &safi)) {
8471 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8472 return CMD_WARNING;
8473 }
8474 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8475 bgp_show_type_flap_prefix_list);
8476}
8477ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8478 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8479 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8480 SHOW_STR
8481 BGP_STR
8482 IPV6_STR
8483 "Address Family Modifier\n"
8484 "Address Family Modifier\n"
8485 "Address Family Modifier\n"
8486 "Address Family Modifier\n"
8487 "Display detailed information about dampening\n"
8488 "Display flap statistics of routes\n"
8489 "Display routes conforming to the prefix-list\n"
8490 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008491
8492DEFUN (show_bgp_ipv4_safi_prefix_list,
8493 show_bgp_ipv4_safi_prefix_list_cmd,
8494 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8495 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008496 BGP_STR
8497 "Address family\n"
8498 "Address Family modifier\n"
8499 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008500 "Address Family modifier\n"
8501 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008502 "Display routes conforming to the prefix-list\n"
8503 "IP prefix-list name\n")
8504{
Lou Berger651b4022016-01-12 13:42:07 -05008505 safi_t safi;
8506 if (bgp_parse_safi(argv[0], &safi)) {
8507 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8508 return CMD_WARNING;
8509 }
8510 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008511 bgp_show_type_prefix_list);
8512}
Lou Berger205e6742016-01-12 13:42:11 -05008513
Lou Berger651b4022016-01-12 13:42:07 -05008514DEFUN (show_bgp_ipv6_safi_prefix_list,
8515 show_bgp_ipv6_safi_prefix_list_cmd,
8516 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008517 SHOW_STR
8518 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008519 "Address family\n"
8520 "Address Family modifier\n"
8521 "Address Family modifier\n"
8522 "Address Family modifier\n"
8523 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008524 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008525 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008526{
Lou Berger651b4022016-01-12 13:42:07 -05008527 safi_t safi;
8528 if (bgp_parse_safi(argv[0], &safi)) {
8529 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8530 return CMD_WARNING;
8531 }
8532 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008533 bgp_show_type_prefix_list);
8534}
8535
paul94f2b392005-06-28 12:44:16 +00008536static int
paulfd79ac92004-10-13 05:06:08 +00008537bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008538 safi_t safi, enum bgp_show_type type)
8539{
8540 struct as_list *as_list;
8541
8542 as_list = as_list_lookup (filter);
8543 if (as_list == NULL)
8544 {
8545 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8546 return CMD_WARNING;
8547 }
8548
ajs5a646652004-11-05 01:25:55 +00008549 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008550}
8551
Lou Bergerf9b6c392016-01-12 13:42:09 -05008552DEFUN (show_ip_bgp_filter_list,
8553 show_ip_bgp_filter_list_cmd,
8554 "show ip bgp filter-list WORD",
8555 SHOW_STR
8556 IP_STR
8557 BGP_STR
8558 "Display routes conforming to the filter-list\n"
8559 "Regular expression access list name\n")
8560{
8561 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8562 bgp_show_type_filter_list);
8563}
8564
8565DEFUN (show_ip_bgp_flap_filter_list,
8566 show_ip_bgp_flap_filter_list_cmd,
8567 "show ip bgp flap-statistics filter-list WORD",
8568 SHOW_STR
8569 IP_STR
8570 BGP_STR
8571 "Display flap statistics of routes\n"
8572 "Display routes conforming to the filter-list\n"
8573 "Regular expression access list name\n")
8574{
8575 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8576 bgp_show_type_flap_filter_list);
8577}
8578
8579ALIAS (show_ip_bgp_flap_filter_list,
8580 show_ip_bgp_damp_flap_filter_list_cmd,
8581 "show ip bgp dampening flap-statistics filter-list WORD",
8582 SHOW_STR
8583 IP_STR
8584 BGP_STR
8585 "Display detailed information about dampening\n"
8586 "Display flap statistics of routes\n"
8587 "Display routes conforming to the filter-list\n"
8588 "Regular expression access list name\n")
8589
8590DEFUN (show_ip_bgp_ipv4_filter_list,
8591 show_ip_bgp_ipv4_filter_list_cmd,
8592 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8593 SHOW_STR
8594 IP_STR
8595 BGP_STR
8596 "Address family\n"
8597 "Address Family modifier\n"
8598 "Address Family modifier\n"
8599 "Display routes conforming to the filter-list\n"
8600 "Regular expression access list name\n")
8601{
8602 if (strncmp (argv[0], "m", 1) == 0)
8603 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8604 bgp_show_type_filter_list);
8605
8606 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8607 bgp_show_type_filter_list);
8608}
8609
Lou Bergerf9b6c392016-01-12 13:42:09 -05008610DEFUN (show_bgp_filter_list,
8611 show_bgp_filter_list_cmd,
8612 "show bgp filter-list WORD",
8613 SHOW_STR
8614 BGP_STR
8615 "Display routes conforming to the filter-list\n"
8616 "Regular expression access list name\n")
8617{
8618 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8619 bgp_show_type_filter_list);
8620}
8621
8622/* old command */
8623DEFUN (show_ipv6_bgp_filter_list,
8624 show_ipv6_bgp_filter_list_cmd,
8625 "show ipv6 bgp filter-list WORD",
8626 SHOW_STR
8627 IPV6_STR
8628 BGP_STR
8629 "Display routes conforming to the filter-list\n"
8630 "Regular expression access list name\n")
8631{
8632 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8633 bgp_show_type_filter_list);
8634}
8635
8636/* old command */
8637DEFUN (show_ipv6_mbgp_filter_list,
8638 show_ipv6_mbgp_filter_list_cmd,
8639 "show ipv6 mbgp filter-list WORD",
8640 SHOW_STR
8641 IPV6_STR
8642 MBGP_STR
8643 "Display routes conforming to the filter-list\n"
8644 "Regular expression access list name\n")
8645{
8646 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8647 bgp_show_type_filter_list);
8648}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008649
8650DEFUN (show_ip_bgp_dampening_info,
8651 show_ip_bgp_dampening_params_cmd,
8652 "show ip bgp dampening parameters",
8653 SHOW_STR
8654 IP_STR
8655 BGP_STR
8656 "Display detailed information about dampening\n"
8657 "Display detail of configured dampening parameters\n")
8658{
8659 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8660}
8661
Lou Berger651b4022016-01-12 13:42:07 -05008662DEFUN (show_bgp_ipv4_filter_list,
8663 show_bgp_ipv4_filter_list_cmd,
8664 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008665 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008666 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008667 IP_STR
paul718e3742002-12-13 20:15:29 +00008668 "Display routes conforming to the filter-list\n"
8669 "Regular expression access list name\n")
8670{
8671 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8672 bgp_show_type_filter_list);
8673}
8674
Lou Berger651b4022016-01-12 13:42:07 -05008675DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8676 show_bgp_ipv4_safi_flap_filter_list_cmd,
8677 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008678 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008679 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008680 IP_STR
8681 "Address Family modifier\n"
8682 "Address Family modifier\n"
8683 "Address Family modifier\n"
8684 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008685 "Display flap statistics of routes\n"
8686 "Display routes conforming to the filter-list\n"
8687 "Regular expression access list name\n")
8688{
Lou Berger651b4022016-01-12 13:42:07 -05008689 safi_t safi;
8690
8691 if (bgp_parse_safi(argv[0], &safi)) {
8692 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8693 return CMD_WARNING;
8694 }
8695 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008696 bgp_show_type_flap_filter_list);
8697}
8698
Lou Berger651b4022016-01-12 13:42:07 -05008699ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8700 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8701 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308702 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308703 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008704 IP_STR
8705 "Address Family modifier\n"
8706 "Address Family modifier\n"
8707 "Address Family modifier\n"
8708 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308709 "Display detailed information about dampening\n"
8710 "Display flap statistics of routes\n"
8711 "Display routes conforming to the filter-list\n"
8712 "Regular expression access list name\n")
8713
Lou Berger651b4022016-01-12 13:42:07 -05008714DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8715 show_bgp_ipv6_safi_flap_filter_list_cmd,
8716 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008717 SHOW_STR
8718 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008719 IPV6_STR
8720 "Address Family modifier\n"
8721 "Address Family modifier\n"
8722 "Address Family modifier\n"
8723 "Address Family modifier\n"
8724 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008725 "Display routes conforming to the filter-list\n"
8726 "Regular expression access list name\n")
8727{
Lou Berger651b4022016-01-12 13:42:07 -05008728 safi_t safi;
8729
8730 if (bgp_parse_safi(argv[0], &safi)) {
8731 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8732 return CMD_WARNING;
8733 }
8734 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8735 bgp_show_type_flap_filter_list);
8736}
8737ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8738 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8739 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8740 SHOW_STR
8741 BGP_STR
8742 IPV6_STR
8743 "Address Family modifier\n"
8744 "Address Family modifier\n"
8745 "Address Family modifier\n"
8746 "Address Family modifier\n"
8747 "Display detailed information about dampening\n"
8748 "Display flap statistics of routes\n"
8749 "Display routes conforming to the filter-list\n"
8750 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008751
8752DEFUN (show_bgp_ipv4_safi_filter_list,
8753 show_bgp_ipv4_safi_filter_list_cmd,
8754 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8755 SHOW_STR
8756 BGP_STR
8757 "Address Family modifier\n"
8758 "Address Family modifier\n"
8759 "Address Family modifier\n"
8760 "Address Family modifier\n"
8761 "Display routes conforming to the filter-list\n"
8762 "Regular expression access list name\n")
8763{
8764 safi_t safi;
8765
8766 if (bgp_parse_safi(argv[0], &safi)) {
8767 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8768 return CMD_WARNING;
8769 }
8770 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8771 bgp_show_type_filter_list);
8772}
Lou Berger205e6742016-01-12 13:42:11 -05008773
Lou Berger651b4022016-01-12 13:42:07 -05008774DEFUN (show_bgp_ipv6_safi_filter_list,
8775 show_bgp_ipv6_safi_filter_list_cmd,
8776 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8777 SHOW_STR
8778 BGP_STR
8779 "Address Family modifier\n"
8780 "Address Family modifier\n"
8781 "Address Family modifier\n"
8782 "Address Family modifier\n"
8783 "Display routes conforming to the filter-list\n"
8784 "Regular expression access list name\n")
8785{
8786 safi_t safi;
8787
8788 if (bgp_parse_safi(argv[0], &safi)) {
8789 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8790 return CMD_WARNING;
8791 }
8792 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8793 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008794}
8795
Lou Bergerf9b6c392016-01-12 13:42:09 -05008796DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008797 show_bgp_ipv6_filter_list_cmd,
8798 "show bgp ipv6 filter-list WORD",
8799 SHOW_STR
8800 BGP_STR
8801 "Address family\n"
8802 "Display routes conforming to the filter-list\n"
8803 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008804{
8805 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8806 bgp_show_type_filter_list);
8807}
8808
Balaji9c52cae2016-01-20 22:59:26 +05308809
8810DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8811 show_ip_bgp_ipv4_dampening_parameters_cmd,
8812 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8813 SHOW_STR
8814 IP_STR
8815 BGP_STR
8816 "Address family\n"
8817 "Address Family modifier\n"
8818 "Address Family modifier\n"
8819 "Display detailed information about dampening\n"
8820 "Display detail of configured dampening parameters\n")
8821{
8822 if (strncmp(argv[0], "m", 1) == 0)
8823 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8824
8825 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8826}
8827
8828
8829DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8830 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8831 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8832 SHOW_STR
8833 IP_STR
8834 BGP_STR
8835 "Address family\n"
8836 "Address Family modifier\n"
8837 "Address Family modifier\n"
8838 "Display detailed information about dampening\n"
8839 "Display flap statistics of routes\n")
8840{
8841 if (strncmp(argv[0], "m", 1) == 0)
8842 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8843 bgp_show_type_flap_statistics, NULL);
8844
8845 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8846 bgp_show_type_flap_statistics, NULL);
8847}
8848
8849DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8850 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8851 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8852 SHOW_STR
8853 IP_STR
8854 BGP_STR
8855 "Address family\n"
8856 "Address Family modifier\n"
8857 "Address Family modifier\n"
8858 "Display detailed information about dampening\n"
8859 "Display paths suppressed due to dampening\n")
8860{
8861 if (strncmp(argv[0], "m", 1) == 0)
8862 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8863 bgp_show_type_dampend_paths, NULL);
8864
8865 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8866 bgp_show_type_dampend_paths, NULL);
8867}
8868
paul94f2b392005-06-28 12:44:16 +00008869static int
paulfd79ac92004-10-13 05:06:08 +00008870bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008871 safi_t safi, enum bgp_show_type type)
8872{
8873 struct route_map *rmap;
8874
8875 rmap = route_map_lookup_by_name (rmap_str);
8876 if (! rmap)
8877 {
8878 vty_out (vty, "%% %s is not a valid route-map name%s",
8879 rmap_str, VTY_NEWLINE);
8880 return CMD_WARNING;
8881 }
8882
ajs5a646652004-11-05 01:25:55 +00008883 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008884}
8885
Lou Bergerf9b6c392016-01-12 13:42:09 -05008886DEFUN (show_ip_bgp_route_map,
8887 show_ip_bgp_route_map_cmd,
8888 "show ip bgp route-map WORD",
8889 SHOW_STR
8890 IP_STR
8891 BGP_STR
8892 "Display routes matching the route-map\n"
8893 "A route-map to match on\n")
8894{
8895 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8896 bgp_show_type_route_map);
8897}
8898
8899DEFUN (show_ip_bgp_flap_route_map,
8900 show_ip_bgp_flap_route_map_cmd,
8901 "show ip bgp flap-statistics route-map WORD",
8902 SHOW_STR
8903 IP_STR
8904 BGP_STR
8905 "Display flap statistics of routes\n"
8906 "Display routes matching the route-map\n"
8907 "A route-map to match on\n")
8908{
8909 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8910 bgp_show_type_flap_route_map);
8911}
8912
8913ALIAS (show_ip_bgp_flap_route_map,
8914 show_ip_bgp_damp_flap_route_map_cmd,
8915 "show ip bgp dampening flap-statistics route-map WORD",
8916 SHOW_STR
8917 IP_STR
8918 BGP_STR
8919 "Display detailed information about dampening\n"
8920 "Display flap statistics of routes\n"
8921 "Display routes matching the route-map\n"
8922 "A route-map to match on\n")
8923
8924DEFUN (show_ip_bgp_ipv4_route_map,
8925 show_ip_bgp_ipv4_route_map_cmd,
8926 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8927 SHOW_STR
8928 IP_STR
8929 BGP_STR
8930 "Address family\n"
8931 "Address Family modifier\n"
8932 "Address Family modifier\n"
8933 "Display routes matching the route-map\n"
8934 "A route-map to match on\n")
8935{
8936 if (strncmp (argv[0], "m", 1) == 0)
8937 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8938 bgp_show_type_route_map);
8939
8940 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8941 bgp_show_type_route_map);
8942}
8943
8944DEFUN (show_bgp_route_map,
8945 show_bgp_route_map_cmd,
8946 "show bgp route-map WORD",
8947 SHOW_STR
8948 BGP_STR
8949 "Display routes matching the route-map\n"
8950 "A route-map to match on\n")
8951{
8952 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8953 bgp_show_type_route_map);
8954}
8955
8956DEFUN (show_ip_bgp_cidr_only,
8957 show_ip_bgp_cidr_only_cmd,
8958 "show ip bgp cidr-only",
8959 SHOW_STR
8960 IP_STR
8961 BGP_STR
8962 "Display only routes with non-natural netmasks\n")
8963{
8964 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8965 bgp_show_type_cidr_only, NULL);
8966}
8967
8968DEFUN (show_ip_bgp_flap_cidr_only,
8969 show_ip_bgp_flap_cidr_only_cmd,
8970 "show ip bgp flap-statistics cidr-only",
8971 SHOW_STR
8972 IP_STR
8973 BGP_STR
8974 "Display flap statistics of routes\n"
8975 "Display only routes with non-natural netmasks\n")
8976{
8977 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8978 bgp_show_type_flap_cidr_only, NULL);
8979}
8980
8981ALIAS (show_ip_bgp_flap_cidr_only,
8982 show_ip_bgp_damp_flap_cidr_only_cmd,
8983 "show ip bgp dampening flap-statistics cidr-only",
8984 SHOW_STR
8985 IP_STR
8986 BGP_STR
8987 "Display detailed information about dampening\n"
8988 "Display flap statistics of routes\n"
8989 "Display only routes with non-natural netmasks\n")
8990
8991DEFUN (show_ip_bgp_ipv4_cidr_only,
8992 show_ip_bgp_ipv4_cidr_only_cmd,
8993 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8994 SHOW_STR
8995 IP_STR
8996 BGP_STR
8997 "Address family\n"
8998 "Address Family modifier\n"
8999 "Address Family modifier\n"
9000 "Display only routes with non-natural netmasks\n")
9001{
9002 if (strncmp (argv[0], "m", 1) == 0)
9003 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9004 bgp_show_type_cidr_only, NULL);
9005
9006 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9007 bgp_show_type_cidr_only, NULL);
9008}
9009
9010DEFUN (show_ip_bgp_community_all,
9011 show_ip_bgp_community_all_cmd,
9012 "show ip bgp community",
9013 SHOW_STR
9014 IP_STR
9015 BGP_STR
9016 "Display routes matching the communities\n")
9017{
9018 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9019 bgp_show_type_community_all, NULL);
9020}
9021
9022DEFUN (show_ip_bgp_ipv4_community_all,
9023 show_ip_bgp_ipv4_community_all_cmd,
9024 "show ip bgp ipv4 (unicast|multicast) community",
9025 SHOW_STR
9026 IP_STR
9027 BGP_STR
9028 "Address family\n"
9029 "Address Family modifier\n"
9030 "Address Family modifier\n"
9031 "Display routes matching the communities\n")
9032{
9033 if (strncmp (argv[0], "m", 1) == 0)
9034 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9035 bgp_show_type_community_all, NULL);
9036
9037 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9038 bgp_show_type_community_all, NULL);
9039}
9040
Lou Bergerf9b6c392016-01-12 13:42:09 -05009041DEFUN (show_bgp_community_all,
9042 show_bgp_community_all_cmd,
9043 "show bgp community",
9044 SHOW_STR
9045 BGP_STR
9046 "Display routes matching the communities\n")
9047{
9048 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9049 bgp_show_type_community_all, NULL);
9050}
9051
9052ALIAS (show_bgp_community_all,
9053 show_bgp_ipv6_community_all_cmd,
9054 "show bgp ipv6 community",
9055 SHOW_STR
9056 BGP_STR
9057 "Address family\n"
9058 "Display routes matching the communities\n")
9059
9060/* old command */
9061DEFUN (show_ipv6_bgp_community_all,
9062 show_ipv6_bgp_community_all_cmd,
9063 "show ipv6 bgp community",
9064 SHOW_STR
9065 IPV6_STR
9066 BGP_STR
9067 "Display routes matching the communities\n")
9068{
9069 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9070 bgp_show_type_community_all, NULL);
9071}
9072
9073/* old command */
9074DEFUN (show_ipv6_mbgp_community_all,
9075 show_ipv6_mbgp_community_all_cmd,
9076 "show ipv6 mbgp community",
9077 SHOW_STR
9078 IPV6_STR
9079 MBGP_STR
9080 "Display routes matching the communities\n")
9081{
9082 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9083 bgp_show_type_community_all, NULL);
9084}
Lou Bergerf9b6c392016-01-12 13:42:09 -05009085
Lou Berger651b4022016-01-12 13:42:07 -05009086DEFUN (show_bgp_ipv4_route_map,
9087 show_bgp_ipv4_route_map_cmd,
9088 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00009089 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009090 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009091 IP_STR
paul718e3742002-12-13 20:15:29 +00009092 "Display routes matching the route-map\n"
9093 "A route-map to match on\n")
9094{
9095 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9096 bgp_show_type_route_map);
9097}
9098
Lou Berger651b4022016-01-12 13:42:07 -05009099DEFUN (show_bgp_ipv4_safi_flap_route_map,
9100 show_bgp_ipv4_safi_flap_route_map_cmd,
9101 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009102 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009103 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009104 IP_STR
9105 "Address Family Modifier\n"
9106 "Address Family Modifier\n"
9107 "Address Family Modifier\n"
9108 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009109 "Display flap statistics of routes\n"
9110 "Display routes matching the route-map\n"
9111 "A route-map to match on\n")
9112{
Lou Berger651b4022016-01-12 13:42:07 -05009113 safi_t safi;
9114 if (bgp_parse_safi(argv[0], &safi)) {
9115 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9116 return CMD_WARNING;
9117 }
9118 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009119 bgp_show_type_flap_route_map);
9120}
9121
Lou Berger651b4022016-01-12 13:42:07 -05009122ALIAS (show_bgp_ipv4_safi_flap_route_map,
9123 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9124 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05309125 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309126 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009127 IP_STR
9128 "Address Family Modifier\n"
9129 "Address Family Modifier\n"
9130 "Address Family Modifier\n"
9131 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309132 "Display detailed information about dampening\n"
9133 "Display flap statistics of routes\n"
9134 "Display routes matching the route-map\n"
9135 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05009136
Lou Berger651b4022016-01-12 13:42:07 -05009137DEFUN (show_bgp_ipv6_safi_flap_route_map,
9138 show_bgp_ipv6_safi_flap_route_map_cmd,
9139 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009140 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05009141 BGP_STR
9142 IPV6_STR
9143 "Address Family Modifier\n"
9144 "Address Family Modifier\n"
9145 "Address Family Modifier\n"
9146 "Address Family Modifier\n"
9147 "Display flap statistics of routes\n"
9148 "Display routes matching the route-map\n"
9149 "A route-map to match on\n")
9150{
9151 safi_t safi;
9152 if (bgp_parse_safi(argv[0], &safi)) {
9153 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9154 return CMD_WARNING;
9155 }
9156 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9157 bgp_show_type_flap_route_map);
9158}
9159ALIAS (show_bgp_ipv6_safi_flap_route_map,
9160 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9161 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9162 SHOW_STR
9163 BGP_STR
9164 IPV6_STR
9165 "Address Family Modifier\n"
9166 "Address Family Modifier\n"
9167 "Address Family Modifier\n"
9168 "Address Family Modifier\n"
9169 "Display detailed information about dampening\n"
9170 "Display flap statistics of routes\n"
9171 "Display routes matching the route-map\n"
9172 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009173
9174DEFUN (show_bgp_ipv4_safi_route_map,
9175 show_bgp_ipv4_safi_route_map_cmd,
9176 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9177 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009178 BGP_STR
9179 "Address family\n"
9180 "Address Family modifier\n"
9181 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009182 "Address Family modifier\n"
9183 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009184 "Display routes matching the route-map\n"
9185 "A route-map to match on\n")
9186{
Lou Berger651b4022016-01-12 13:42:07 -05009187 safi_t safi;
9188 if (bgp_parse_safi(argv[0], &safi)) {
9189 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9190 return CMD_WARNING;
9191 }
9192 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009193 bgp_show_type_route_map);
9194}
Lou Berger205e6742016-01-12 13:42:11 -05009195
Lou Berger651b4022016-01-12 13:42:07 -05009196DEFUN (show_bgp_ipv6_safi_route_map,
9197 show_bgp_ipv6_safi_route_map_cmd,
9198 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009199 SHOW_STR
9200 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009201 "Address family\n"
9202 "Address Family modifier\n"
9203 "Address Family modifier\n"
9204 "Address Family modifier\n"
9205 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009206 "Display routes matching the route-map\n"
9207 "A route-map to match on\n")
9208{
Lou Berger651b4022016-01-12 13:42:07 -05009209 safi_t safi;
9210 if (bgp_parse_safi(argv[0], &safi)) {
9211 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9212 return CMD_WARNING;
9213 }
9214 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009215 bgp_show_type_route_map);
9216}
9217
Lou Berger651b4022016-01-12 13:42:07 -05009218DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009219 show_bgp_ipv6_route_map_cmd,
9220 "show bgp ipv6 route-map WORD",
9221 SHOW_STR
9222 BGP_STR
9223 "Address family\n"
9224 "Display routes matching the route-map\n"
9225 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009226{
9227 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9228 bgp_show_type_route_map);
9229}
David Lamparter6b0655a2014-06-04 06:53:35 +02009230
Lou Berger651b4022016-01-12 13:42:07 -05009231DEFUN (show_bgp_ipv4_cidr_only,
9232 show_bgp_ipv4_cidr_only_cmd,
9233 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009234 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009235 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009236 IP_STR
paul718e3742002-12-13 20:15:29 +00009237 "Display only routes with non-natural netmasks\n")
9238{
9239 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009240 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009241}
9242
Lou Berger651b4022016-01-12 13:42:07 -05009243DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9244 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9245 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009246 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009247 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009248 "Address Family\n"
9249 "Address Family Modifier\n"
9250 "Address Family Modifier\n"
9251 "Address Family Modifier\n"
9252 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009253 "Display flap statistics of routes\n"
9254 "Display only routes with non-natural netmasks\n")
9255{
Lou Berger651b4022016-01-12 13:42:07 -05009256 safi_t safi;
9257
9258 if (bgp_parse_safi(argv[0], &safi)) {
9259 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9260 return CMD_WARNING;
9261 }
9262 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009263}
9264
Lou Berger651b4022016-01-12 13:42:07 -05009265ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9266 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9267 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309268 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309269 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009270 "Address Family\n"
9271 "Address Family Modifier\n"
9272 "Address Family Modifier\n"
9273 "Address Family Modifier\n"
9274 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309275 "Display detailed information about dampening\n"
9276 "Display flap statistics of routes\n"
9277 "Display only routes with non-natural netmasks\n")
9278
Lou Berger651b4022016-01-12 13:42:07 -05009279DEFUN (show_bgp_ipv4_safi_cidr_only,
9280 show_bgp_ipv4_safi_cidr_only_cmd,
9281 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009282 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009283 BGP_STR
9284 "Address family\n"
9285 "Address Family modifier\n"
9286 "Address Family modifier\n"
9287 "Display only routes with non-natural netmasks\n")
9288{
9289 if (strncmp (argv[0], "m", 1) == 0)
9290 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009291 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009292
9293 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009294 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009295}
David Lamparter6b0655a2014-06-04 06:53:35 +02009296
Lou Berger651b4022016-01-12 13:42:07 -05009297/* new046 */
9298DEFUN (show_bgp_afi_safi_community_all,
9299 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009300 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009301 SHOW_STR
9302 BGP_STR
9303 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009304 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009305 "Address Family modifier\n"
9306 "Address Family modifier\n"
9307 "Address Family modifier\n"
9308 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009309 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009310{
9311 safi_t safi;
9312 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009313
Lou Berger651b4022016-01-12 13:42:07 -05009314 if (bgp_parse_afi(argv[0], &afi)) {
9315 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9316 return CMD_WARNING;
9317 }
9318 if (bgp_parse_safi(argv[1], &safi)) {
9319 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9320 return CMD_WARNING;
9321 }
9322
9323 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9324}
9325DEFUN (show_bgp_afi_community_all,
9326 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009327 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009328 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009329 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009330 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009331 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009332 "Display routes matching the communities\n")
9333{
Lou Berger651b4022016-01-12 13:42:07 -05009334 afi_t afi;
9335 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009336
Lou Berger651b4022016-01-12 13:42:07 -05009337 if (bgp_parse_afi(argv[0], &afi)) {
9338 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9339 return CMD_WARNING;
9340 }
9341 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009342}
David Lamparter6b0655a2014-06-04 06:53:35 +02009343
paul94f2b392005-06-28 12:44:16 +00009344static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009345bgp_show_community (struct vty *vty, const char *view_name, int argc,
9346 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009347{
9348 struct community *com;
9349 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009350 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009351 int i;
9352 char *str;
9353 int first = 0;
9354
Michael Lambert95cbbd22010-07-23 14:43:04 -04009355 /* BGP structure lookup */
9356 if (view_name)
9357 {
9358 bgp = bgp_lookup_by_name (view_name);
9359 if (bgp == NULL)
9360 {
9361 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9362 return CMD_WARNING;
9363 }
9364 }
9365 else
9366 {
9367 bgp = bgp_get_default ();
9368 if (bgp == NULL)
9369 {
9370 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9371 return CMD_WARNING;
9372 }
9373 }
9374
paul718e3742002-12-13 20:15:29 +00009375 b = buffer_new (1024);
9376 for (i = 0; i < argc; i++)
9377 {
9378 if (first)
9379 buffer_putc (b, ' ');
9380 else
9381 {
9382 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9383 continue;
9384 first = 1;
9385 }
9386
9387 buffer_putstr (b, argv[i]);
9388 }
9389 buffer_putc (b, '\0');
9390
9391 str = buffer_getstr (b);
9392 buffer_free (b);
9393
9394 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009395 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009396 if (! com)
9397 {
9398 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9399 return CMD_WARNING;
9400 }
9401
Michael Lambert95cbbd22010-07-23 14:43:04 -04009402 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009403 (exact ? bgp_show_type_community_exact :
9404 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009405}
9406
Lou Bergerf9b6c392016-01-12 13:42:09 -05009407DEFUN (show_ip_bgp_community,
9408 show_ip_bgp_community_cmd,
9409 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9410 SHOW_STR
9411 IP_STR
9412 BGP_STR
9413 "Display routes matching the communities\n"
9414 "community number\n"
9415 "Do not send outside local AS (well-known community)\n"
9416 "Do not advertise to any peer (well-known community)\n"
9417 "Do not export to next AS (well-known community)\n")
9418{
9419 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9420}
9421
9422ALIAS (show_ip_bgp_community,
9423 show_ip_bgp_community2_cmd,
9424 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9425 SHOW_STR
9426 IP_STR
9427 BGP_STR
9428 "Display routes matching the communities\n"
9429 "community number\n"
9430 "Do not send outside local AS (well-known community)\n"
9431 "Do not advertise to any peer (well-known community)\n"
9432 "Do not export to next AS (well-known community)\n"
9433 "community number\n"
9434 "Do not send outside local AS (well-known community)\n"
9435 "Do not advertise to any peer (well-known community)\n"
9436 "Do not export to next AS (well-known community)\n")
9437
9438ALIAS (show_ip_bgp_community,
9439 show_ip_bgp_community3_cmd,
9440 "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)",
9441 SHOW_STR
9442 IP_STR
9443 BGP_STR
9444 "Display routes matching the communities\n"
9445 "community number\n"
9446 "Do not send outside local AS (well-known community)\n"
9447 "Do not advertise to any peer (well-known community)\n"
9448 "Do not export to next AS (well-known community)\n"
9449 "community number\n"
9450 "Do not send outside local AS (well-known community)\n"
9451 "Do not advertise to any peer (well-known community)\n"
9452 "Do not export to next AS (well-known community)\n"
9453 "community number\n"
9454 "Do not send outside local AS (well-known community)\n"
9455 "Do not advertise to any peer (well-known community)\n"
9456 "Do not export to next AS (well-known community)\n")
9457
9458ALIAS (show_ip_bgp_community,
9459 show_ip_bgp_community4_cmd,
9460 "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)",
9461 SHOW_STR
9462 IP_STR
9463 BGP_STR
9464 "Display routes matching the communities\n"
9465 "community number\n"
9466 "Do not send outside local AS (well-known community)\n"
9467 "Do not advertise to any peer (well-known community)\n"
9468 "Do not export to next AS (well-known community)\n"
9469 "community number\n"
9470 "Do not send outside local AS (well-known community)\n"
9471 "Do not advertise to any peer (well-known community)\n"
9472 "Do not export to next AS (well-known community)\n"
9473 "community number\n"
9474 "Do not send outside local AS (well-known community)\n"
9475 "Do not advertise to any peer (well-known community)\n"
9476 "Do not export to next AS (well-known community)\n"
9477 "community number\n"
9478 "Do not send outside local AS (well-known community)\n"
9479 "Do not advertise to any peer (well-known community)\n"
9480 "Do not export to next AS (well-known community)\n")
9481
9482DEFUN (show_ip_bgp_ipv4_community,
9483 show_ip_bgp_ipv4_community_cmd,
9484 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9485 SHOW_STR
9486 IP_STR
9487 BGP_STR
9488 "Address family\n"
9489 "Address Family modifier\n"
9490 "Address Family modifier\n"
9491 "Display routes matching the communities\n"
9492 "community number\n"
9493 "Do not send outside local AS (well-known community)\n"
9494 "Do not advertise to any peer (well-known community)\n"
9495 "Do not export to next AS (well-known community)\n")
9496{
9497 if (strncmp (argv[0], "m", 1) == 0)
9498 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9499
9500 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9501}
9502
9503ALIAS (show_ip_bgp_ipv4_community,
9504 show_ip_bgp_ipv4_community2_cmd,
9505 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9506 SHOW_STR
9507 IP_STR
9508 BGP_STR
9509 "Address family\n"
9510 "Address Family modifier\n"
9511 "Address Family modifier\n"
9512 "Display routes matching the communities\n"
9513 "community number\n"
9514 "Do not send outside local AS (well-known community)\n"
9515 "Do not advertise to any peer (well-known community)\n"
9516 "Do not export to next AS (well-known community)\n"
9517 "community number\n"
9518 "Do not send outside local AS (well-known community)\n"
9519 "Do not advertise to any peer (well-known community)\n"
9520 "Do not export to next AS (well-known community)\n")
9521
9522ALIAS (show_ip_bgp_ipv4_community,
9523 show_ip_bgp_ipv4_community3_cmd,
9524 "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)",
9525 SHOW_STR
9526 IP_STR
9527 BGP_STR
9528 "Address family\n"
9529 "Address Family modifier\n"
9530 "Address Family modifier\n"
9531 "Display routes matching the communities\n"
9532 "community number\n"
9533 "Do not send outside local AS (well-known community)\n"
9534 "Do not advertise to any peer (well-known community)\n"
9535 "Do not export to next AS (well-known community)\n"
9536 "community number\n"
9537 "Do not send outside local AS (well-known community)\n"
9538 "Do not advertise to any peer (well-known community)\n"
9539 "Do not export to next AS (well-known community)\n"
9540 "community number\n"
9541 "Do not send outside local AS (well-known community)\n"
9542 "Do not advertise to any peer (well-known community)\n"
9543 "Do not export to next AS (well-known community)\n")
9544
9545ALIAS (show_ip_bgp_ipv4_community,
9546 show_ip_bgp_ipv4_community4_cmd,
9547 "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)",
9548 SHOW_STR
9549 IP_STR
9550 BGP_STR
9551 "Address family\n"
9552 "Address Family modifier\n"
9553 "Address Family modifier\n"
9554 "Display routes matching the communities\n"
9555 "community number\n"
9556 "Do not send outside local AS (well-known community)\n"
9557 "Do not advertise to any peer (well-known community)\n"
9558 "Do not export to next AS (well-known community)\n"
9559 "community number\n"
9560 "Do not send outside local AS (well-known community)\n"
9561 "Do not advertise to any peer (well-known community)\n"
9562 "Do not export to next AS (well-known community)\n"
9563 "community number\n"
9564 "Do not send outside local AS (well-known community)\n"
9565 "Do not advertise to any peer (well-known community)\n"
9566 "Do not export to next AS (well-known community)\n"
9567 "community number\n"
9568 "Do not send outside local AS (well-known community)\n"
9569 "Do not advertise to any peer (well-known community)\n"
9570 "Do not export to next AS (well-known community)\n")
9571
9572DEFUN (show_ip_bgp_community_exact,
9573 show_ip_bgp_community_exact_cmd,
9574 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9575 SHOW_STR
9576 IP_STR
9577 BGP_STR
9578 "Display routes matching the communities\n"
9579 "community number\n"
9580 "Do not send outside local AS (well-known community)\n"
9581 "Do not advertise to any peer (well-known community)\n"
9582 "Do not export to next AS (well-known community)\n"
9583 "Exact match of the communities")
9584{
9585 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9586}
9587
9588ALIAS (show_ip_bgp_community_exact,
9589 show_ip_bgp_community2_exact_cmd,
9590 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9591 SHOW_STR
9592 IP_STR
9593 BGP_STR
9594 "Display routes matching the communities\n"
9595 "community number\n"
9596 "Do not send outside local AS (well-known community)\n"
9597 "Do not advertise to any peer (well-known community)\n"
9598 "Do not export to next AS (well-known community)\n"
9599 "community number\n"
9600 "Do not send outside local AS (well-known community)\n"
9601 "Do not advertise to any peer (well-known community)\n"
9602 "Do not export to next AS (well-known community)\n"
9603 "Exact match of the communities")
9604
9605ALIAS (show_ip_bgp_community_exact,
9606 show_ip_bgp_community3_exact_cmd,
9607 "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",
9608 SHOW_STR
9609 IP_STR
9610 BGP_STR
9611 "Display routes matching the communities\n"
9612 "community number\n"
9613 "Do not send outside local AS (well-known community)\n"
9614 "Do not advertise to any peer (well-known community)\n"
9615 "Do not export to next AS (well-known community)\n"
9616 "community number\n"
9617 "Do not send outside local AS (well-known community)\n"
9618 "Do not advertise to any peer (well-known community)\n"
9619 "Do not export to next AS (well-known community)\n"
9620 "community number\n"
9621 "Do not send outside local AS (well-known community)\n"
9622 "Do not advertise to any peer (well-known community)\n"
9623 "Do not export to next AS (well-known community)\n"
9624 "Exact match of the communities")
9625
9626ALIAS (show_ip_bgp_community_exact,
9627 show_ip_bgp_community4_exact_cmd,
9628 "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",
9629 SHOW_STR
9630 IP_STR
9631 BGP_STR
9632 "Display routes matching the communities\n"
9633 "community number\n"
9634 "Do not send outside local AS (well-known community)\n"
9635 "Do not advertise to any peer (well-known community)\n"
9636 "Do not export to next AS (well-known community)\n"
9637 "community number\n"
9638 "Do not send outside local AS (well-known community)\n"
9639 "Do not advertise to any peer (well-known community)\n"
9640 "Do not export to next AS (well-known community)\n"
9641 "community number\n"
9642 "Do not send outside local AS (well-known community)\n"
9643 "Do not advertise to any peer (well-known community)\n"
9644 "Do not export to next AS (well-known community)\n"
9645 "community number\n"
9646 "Do not send outside local AS (well-known community)\n"
9647 "Do not advertise to any peer (well-known community)\n"
9648 "Do not export to next AS (well-known community)\n"
9649 "Exact match of the communities")
9650
9651DEFUN (show_ip_bgp_ipv4_community_exact,
9652 show_ip_bgp_ipv4_community_exact_cmd,
9653 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9654 SHOW_STR
9655 IP_STR
9656 BGP_STR
9657 "Address family\n"
9658 "Address Family modifier\n"
9659 "Address Family modifier\n"
9660 "Display routes matching the communities\n"
9661 "community number\n"
9662 "Do not send outside local AS (well-known community)\n"
9663 "Do not advertise to any peer (well-known community)\n"
9664 "Do not export to next AS (well-known community)\n"
9665 "Exact match of the communities")
9666{
9667 if (strncmp (argv[0], "m", 1) == 0)
9668 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9669
9670 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9671}
9672
9673ALIAS (show_ip_bgp_ipv4_community_exact,
9674 show_ip_bgp_ipv4_community2_exact_cmd,
9675 "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",
9676 SHOW_STR
9677 IP_STR
9678 BGP_STR
9679 "Address family\n"
9680 "Address Family modifier\n"
9681 "Address Family modifier\n"
9682 "Display routes matching the communities\n"
9683 "community number\n"
9684 "Do not send outside local AS (well-known community)\n"
9685 "Do not advertise to any peer (well-known community)\n"
9686 "Do not export to next AS (well-known community)\n"
9687 "community number\n"
9688 "Do not send outside local AS (well-known community)\n"
9689 "Do not advertise to any peer (well-known community)\n"
9690 "Do not export to next AS (well-known community)\n"
9691 "Exact match of the communities")
9692
9693ALIAS (show_ip_bgp_ipv4_community_exact,
9694 show_ip_bgp_ipv4_community3_exact_cmd,
9695 "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",
9696 SHOW_STR
9697 IP_STR
9698 BGP_STR
9699 "Address family\n"
9700 "Address Family modifier\n"
9701 "Address Family modifier\n"
9702 "Display routes matching the communities\n"
9703 "community number\n"
9704 "Do not send outside local AS (well-known community)\n"
9705 "Do not advertise to any peer (well-known community)\n"
9706 "Do not export to next AS (well-known community)\n"
9707 "community number\n"
9708 "Do not send outside local AS (well-known community)\n"
9709 "Do not advertise to any peer (well-known community)\n"
9710 "Do not export to next AS (well-known community)\n"
9711 "community number\n"
9712 "Do not send outside local AS (well-known community)\n"
9713 "Do not advertise to any peer (well-known community)\n"
9714 "Do not export to next AS (well-known community)\n"
9715 "Exact match of the communities")
9716
9717ALIAS (show_ip_bgp_ipv4_community_exact,
9718 show_ip_bgp_ipv4_community4_exact_cmd,
9719 "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",
9720 SHOW_STR
9721 IP_STR
9722 BGP_STR
9723 "Address family\n"
9724 "Address Family modifier\n"
9725 "Address Family modifier\n"
9726 "Display routes matching the communities\n"
9727 "community number\n"
9728 "Do not send outside local AS (well-known community)\n"
9729 "Do not advertise to any peer (well-known community)\n"
9730 "Do not export to next AS (well-known community)\n"
9731 "community number\n"
9732 "Do not send outside local AS (well-known community)\n"
9733 "Do not advertise to any peer (well-known community)\n"
9734 "Do not export to next AS (well-known community)\n"
9735 "community number\n"
9736 "Do not send outside local AS (well-known community)\n"
9737 "Do not advertise to any peer (well-known community)\n"
9738 "Do not export to next AS (well-known community)\n"
9739 "community number\n"
9740 "Do not send outside local AS (well-known community)\n"
9741 "Do not advertise to any peer (well-known community)\n"
9742 "Do not export to next AS (well-known community)\n"
9743 "Exact match of the communities")
9744
Lou Bergerf9b6c392016-01-12 13:42:09 -05009745DEFUN (show_bgp_community,
9746 show_bgp_community_cmd,
9747 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9748 SHOW_STR
9749 BGP_STR
9750 "Display routes matching the communities\n"
9751 "community number\n"
9752 "Do not send outside local AS (well-known community)\n"
9753 "Do not advertise to any peer (well-known community)\n"
9754 "Do not export to next AS (well-known community)\n")
9755{
9756 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9757}
9758
9759ALIAS (show_bgp_community,
9760 show_bgp_ipv6_community_cmd,
9761 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9762 SHOW_STR
9763 BGP_STR
9764 "Address family\n"
9765 "Display routes matching the communities\n"
9766 "community number\n"
9767 "Do not send outside local AS (well-known community)\n"
9768 "Do not advertise to any peer (well-known community)\n"
9769 "Do not export to next AS (well-known community)\n")
9770
9771ALIAS (show_bgp_community,
9772 show_bgp_community2_cmd,
9773 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9774 SHOW_STR
9775 BGP_STR
9776 "Display routes matching the communities\n"
9777 "community number\n"
9778 "Do not send outside local AS (well-known community)\n"
9779 "Do not advertise to any peer (well-known community)\n"
9780 "Do not export to next AS (well-known community)\n"
9781 "community number\n"
9782 "Do not send outside local AS (well-known community)\n"
9783 "Do not advertise to any peer (well-known community)\n"
9784 "Do not export to next AS (well-known community)\n")
9785
9786ALIAS (show_bgp_community,
9787 show_bgp_ipv6_community2_cmd,
9788 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9789 SHOW_STR
9790 BGP_STR
9791 "Address family\n"
9792 "Display routes matching the communities\n"
9793 "community number\n"
9794 "Do not send outside local AS (well-known community)\n"
9795 "Do not advertise to any peer (well-known community)\n"
9796 "Do not export to next AS (well-known community)\n"
9797 "community number\n"
9798 "Do not send outside local AS (well-known community)\n"
9799 "Do not advertise to any peer (well-known community)\n"
9800 "Do not export to next AS (well-known community)\n")
9801
9802ALIAS (show_bgp_community,
9803 show_bgp_community3_cmd,
9804 "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)",
9805 SHOW_STR
9806 BGP_STR
9807 "Display routes matching the communities\n"
9808 "community number\n"
9809 "Do not send outside local AS (well-known community)\n"
9810 "Do not advertise to any peer (well-known community)\n"
9811 "Do not export to next AS (well-known community)\n"
9812 "community number\n"
9813 "Do not send outside local AS (well-known community)\n"
9814 "Do not advertise to any peer (well-known community)\n"
9815 "Do not export to next AS (well-known community)\n"
9816 "community number\n"
9817 "Do not send outside local AS (well-known community)\n"
9818 "Do not advertise to any peer (well-known community)\n"
9819 "Do not export to next AS (well-known community)\n")
9820
9821ALIAS (show_bgp_community,
9822 show_bgp_ipv6_community3_cmd,
9823 "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)",
9824 SHOW_STR
9825 BGP_STR
9826 "Address family\n"
9827 "Display routes matching the communities\n"
9828 "community number\n"
9829 "Do not send outside local AS (well-known community)\n"
9830 "Do not advertise to any peer (well-known community)\n"
9831 "Do not export to next AS (well-known community)\n"
9832 "community number\n"
9833 "Do not send outside local AS (well-known community)\n"
9834 "Do not advertise to any peer (well-known community)\n"
9835 "Do not export to next AS (well-known community)\n"
9836 "community number\n"
9837 "Do not send outside local AS (well-known community)\n"
9838 "Do not advertise to any peer (well-known community)\n"
9839 "Do not export to next AS (well-known community)\n")
9840
9841ALIAS (show_bgp_community,
9842 show_bgp_community4_cmd,
9843 "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)",
9844 SHOW_STR
9845 BGP_STR
9846 "Display routes matching the communities\n"
9847 "community number\n"
9848 "Do not send outside local AS (well-known community)\n"
9849 "Do not advertise to any peer (well-known community)\n"
9850 "Do not export to next AS (well-known community)\n"
9851 "community number\n"
9852 "Do not send outside local AS (well-known community)\n"
9853 "Do not advertise to any peer (well-known community)\n"
9854 "Do not export to next AS (well-known community)\n"
9855 "community number\n"
9856 "Do not send outside local AS (well-known community)\n"
9857 "Do not advertise to any peer (well-known community)\n"
9858 "Do not export to next AS (well-known community)\n"
9859 "community number\n"
9860 "Do not send outside local AS (well-known community)\n"
9861 "Do not advertise to any peer (well-known community)\n"
9862 "Do not export to next AS (well-known community)\n")
9863
9864ALIAS (show_bgp_community,
9865 show_bgp_ipv6_community4_cmd,
9866 "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)",
9867 SHOW_STR
9868 BGP_STR
9869 "Address family\n"
9870 "Display routes matching the communities\n"
9871 "community number\n"
9872 "Do not send outside local AS (well-known community)\n"
9873 "Do not advertise to any peer (well-known community)\n"
9874 "Do not export to next AS (well-known community)\n"
9875 "community number\n"
9876 "Do not send outside local AS (well-known community)\n"
9877 "Do not advertise to any peer (well-known community)\n"
9878 "Do not export to next AS (well-known community)\n"
9879 "community number\n"
9880 "Do not send outside local AS (well-known community)\n"
9881 "Do not advertise to any peer (well-known community)\n"
9882 "Do not export to next AS (well-known community)\n"
9883 "community number\n"
9884 "Do not send outside local AS (well-known community)\n"
9885 "Do not advertise to any peer (well-known community)\n"
9886 "Do not export to next AS (well-known community)\n")
9887
9888/* old command */
9889DEFUN (show_ipv6_bgp_community,
9890 show_ipv6_bgp_community_cmd,
9891 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9892 SHOW_STR
9893 IPV6_STR
9894 BGP_STR
9895 "Display routes matching the communities\n"
9896 "community number\n"
9897 "Do not send outside local AS (well-known community)\n"
9898 "Do not advertise to any peer (well-known community)\n"
9899 "Do not export to next AS (well-known community)\n")
9900{
9901 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9902}
9903
9904/* old command */
9905ALIAS (show_ipv6_bgp_community,
9906 show_ipv6_bgp_community2_cmd,
9907 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9908 SHOW_STR
9909 IPV6_STR
9910 BGP_STR
9911 "Display routes matching the communities\n"
9912 "community number\n"
9913 "Do not send outside local AS (well-known community)\n"
9914 "Do not advertise to any peer (well-known community)\n"
9915 "Do not export to next AS (well-known community)\n"
9916 "community number\n"
9917 "Do not send outside local AS (well-known community)\n"
9918 "Do not advertise to any peer (well-known community)\n"
9919 "Do not export to next AS (well-known community)\n")
9920
9921/* old command */
9922ALIAS (show_ipv6_bgp_community,
9923 show_ipv6_bgp_community3_cmd,
9924 "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)",
9925 SHOW_STR
9926 IPV6_STR
9927 BGP_STR
9928 "Display routes matching the communities\n"
9929 "community number\n"
9930 "Do not send outside local AS (well-known community)\n"
9931 "Do not advertise to any peer (well-known community)\n"
9932 "Do not export to next AS (well-known community)\n"
9933 "community number\n"
9934 "Do not send outside local AS (well-known community)\n"
9935 "Do not advertise to any peer (well-known community)\n"
9936 "Do not export to next AS (well-known community)\n"
9937 "community number\n"
9938 "Do not send outside local AS (well-known community)\n"
9939 "Do not advertise to any peer (well-known community)\n"
9940 "Do not export to next AS (well-known community)\n")
9941
9942/* old command */
9943ALIAS (show_ipv6_bgp_community,
9944 show_ipv6_bgp_community4_cmd,
9945 "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)",
9946 SHOW_STR
9947 IPV6_STR
9948 BGP_STR
9949 "Display routes matching the communities\n"
9950 "community number\n"
9951 "Do not send outside local AS (well-known community)\n"
9952 "Do not advertise to any peer (well-known community)\n"
9953 "Do not export to next AS (well-known community)\n"
9954 "community number\n"
9955 "Do not send outside local AS (well-known community)\n"
9956 "Do not advertise to any peer (well-known community)\n"
9957 "Do not export to next AS (well-known community)\n"
9958 "community number\n"
9959 "Do not send outside local AS (well-known community)\n"
9960 "Do not advertise to any peer (well-known community)\n"
9961 "Do not export to next AS (well-known community)\n"
9962 "community number\n"
9963 "Do not send outside local AS (well-known community)\n"
9964 "Do not advertise to any peer (well-known community)\n"
9965 "Do not export to next AS (well-known community)\n")
9966
9967DEFUN (show_bgp_community_exact,
9968 show_bgp_community_exact_cmd,
9969 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9970 SHOW_STR
9971 BGP_STR
9972 "Display routes matching the communities\n"
9973 "community number\n"
9974 "Do not send outside local AS (well-known community)\n"
9975 "Do not advertise to any peer (well-known community)\n"
9976 "Do not export to next AS (well-known community)\n"
9977 "Exact match of the communities")
9978{
9979 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9980}
9981
9982ALIAS (show_bgp_community_exact,
9983 show_bgp_ipv6_community_exact_cmd,
9984 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9985 SHOW_STR
9986 BGP_STR
9987 "Address family\n"
9988 "Display routes matching the communities\n"
9989 "community number\n"
9990 "Do not send outside local AS (well-known community)\n"
9991 "Do not advertise to any peer (well-known community)\n"
9992 "Do not export to next AS (well-known community)\n"
9993 "Exact match of the communities")
9994
9995ALIAS (show_bgp_community_exact,
9996 show_bgp_community2_exact_cmd,
9997 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9998 SHOW_STR
9999 BGP_STR
10000 "Display routes matching the communities\n"
10001 "community number\n"
10002 "Do not send outside local AS (well-known community)\n"
10003 "Do not advertise to any peer (well-known community)\n"
10004 "Do not export to next AS (well-known community)\n"
10005 "community number\n"
10006 "Do not send outside local AS (well-known community)\n"
10007 "Do not advertise to any peer (well-known community)\n"
10008 "Do not export to next AS (well-known community)\n"
10009 "Exact match of the communities")
10010
10011ALIAS (show_bgp_community_exact,
10012 show_bgp_ipv6_community2_exact_cmd,
10013 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10014 SHOW_STR
10015 BGP_STR
10016 "Address family\n"
10017 "Display routes matching the communities\n"
10018 "community number\n"
10019 "Do not send outside local AS (well-known community)\n"
10020 "Do not advertise to any peer (well-known community)\n"
10021 "Do not export to next AS (well-known community)\n"
10022 "community number\n"
10023 "Do not send outside local AS (well-known community)\n"
10024 "Do not advertise to any peer (well-known community)\n"
10025 "Do not export to next AS (well-known community)\n"
10026 "Exact match of the communities")
10027
10028ALIAS (show_bgp_community_exact,
10029 show_bgp_community3_exact_cmd,
10030 "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",
10031 SHOW_STR
10032 BGP_STR
10033 "Display routes matching the communities\n"
10034 "community number\n"
10035 "Do not send outside local AS (well-known community)\n"
10036 "Do not advertise to any peer (well-known community)\n"
10037 "Do not export to next AS (well-known community)\n"
10038 "community number\n"
10039 "Do not send outside local AS (well-known community)\n"
10040 "Do not advertise to any peer (well-known community)\n"
10041 "Do not export to next AS (well-known community)\n"
10042 "community number\n"
10043 "Do not send outside local AS (well-known community)\n"
10044 "Do not advertise to any peer (well-known community)\n"
10045 "Do not export to next AS (well-known community)\n"
10046 "Exact match of the communities")
10047
10048ALIAS (show_bgp_community_exact,
10049 show_bgp_ipv6_community3_exact_cmd,
10050 "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",
10051 SHOW_STR
10052 BGP_STR
10053 "Address family\n"
10054 "Display routes matching the communities\n"
10055 "community number\n"
10056 "Do not send outside local AS (well-known community)\n"
10057 "Do not advertise to any peer (well-known community)\n"
10058 "Do not export to next AS (well-known community)\n"
10059 "community number\n"
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n"
10063 "community number\n"
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n"
10067 "Exact match of the communities")
10068
10069ALIAS (show_bgp_community_exact,
10070 show_bgp_community4_exact_cmd,
10071 "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",
10072 SHOW_STR
10073 BGP_STR
10074 "Display routes matching the communities\n"
10075 "community number\n"
10076 "Do not send outside local AS (well-known community)\n"
10077 "Do not advertise to any peer (well-known community)\n"
10078 "Do not export to next AS (well-known community)\n"
10079 "community number\n"
10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 "community number\n"
10084 "Do not send outside local AS (well-known community)\n"
10085 "Do not advertise to any peer (well-known community)\n"
10086 "Do not export to next AS (well-known community)\n"
10087 "community number\n"
10088 "Do not send outside local AS (well-known community)\n"
10089 "Do not advertise to any peer (well-known community)\n"
10090 "Do not export to next AS (well-known community)\n"
10091 "Exact match of the communities")
10092
10093ALIAS (show_bgp_community_exact,
10094 show_bgp_ipv6_community4_exact_cmd,
10095 "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",
10096 SHOW_STR
10097 BGP_STR
10098 "Address family\n"
10099 "Display routes matching the communities\n"
10100 "community number\n"
10101 "Do not send outside local AS (well-known community)\n"
10102 "Do not advertise to any peer (well-known community)\n"
10103 "Do not export to next AS (well-known community)\n"
10104 "community number\n"
10105 "Do not send outside local AS (well-known community)\n"
10106 "Do not advertise to any peer (well-known community)\n"
10107 "Do not export to next AS (well-known community)\n"
10108 "community number\n"
10109 "Do not send outside local AS (well-known community)\n"
10110 "Do not advertise to any peer (well-known community)\n"
10111 "Do not export to next AS (well-known community)\n"
10112 "community number\n"
10113 "Do not send outside local AS (well-known community)\n"
10114 "Do not advertise to any peer (well-known community)\n"
10115 "Do not export to next AS (well-known community)\n"
10116 "Exact match of the communities")
10117
10118/* old command */
10119DEFUN (show_ipv6_bgp_community_exact,
10120 show_ipv6_bgp_community_exact_cmd,
10121 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10122 SHOW_STR
10123 IPV6_STR
10124 BGP_STR
10125 "Display routes matching the communities\n"
10126 "community number\n"
10127 "Do not send outside local AS (well-known community)\n"
10128 "Do not advertise to any peer (well-known community)\n"
10129 "Do not export to next AS (well-known community)\n"
10130 "Exact match of the communities")
10131{
10132 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10133}
10134
10135/* old command */
10136ALIAS (show_ipv6_bgp_community_exact,
10137 show_ipv6_bgp_community2_exact_cmd,
10138 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10139 SHOW_STR
10140 IPV6_STR
10141 BGP_STR
10142 "Display routes matching the communities\n"
10143 "community number\n"
10144 "Do not send outside local AS (well-known community)\n"
10145 "Do not advertise to any peer (well-known community)\n"
10146 "Do not export to next AS (well-known community)\n"
10147 "community number\n"
10148 "Do not send outside local AS (well-known community)\n"
10149 "Do not advertise to any peer (well-known community)\n"
10150 "Do not export to next AS (well-known community)\n"
10151 "Exact match of the communities")
10152
10153/* old command */
10154ALIAS (show_ipv6_bgp_community_exact,
10155 show_ipv6_bgp_community3_exact_cmd,
10156 "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",
10157 SHOW_STR
10158 IPV6_STR
10159 BGP_STR
10160 "Display routes matching the communities\n"
10161 "community number\n"
10162 "Do not send outside local AS (well-known community)\n"
10163 "Do not advertise to any peer (well-known community)\n"
10164 "Do not export to next AS (well-known community)\n"
10165 "community number\n"
10166 "Do not send outside local AS (well-known community)\n"
10167 "Do not advertise to any peer (well-known community)\n"
10168 "Do not export to next AS (well-known community)\n"
10169 "community number\n"
10170 "Do not send outside local AS (well-known community)\n"
10171 "Do not advertise to any peer (well-known community)\n"
10172 "Do not export to next AS (well-known community)\n"
10173 "Exact match of the communities")
10174
10175/* old command */
10176ALIAS (show_ipv6_bgp_community_exact,
10177 show_ipv6_bgp_community4_exact_cmd,
10178 "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",
10179 SHOW_STR
10180 IPV6_STR
10181 BGP_STR
10182 "Display routes matching the communities\n"
10183 "community number\n"
10184 "Do not send outside local AS (well-known community)\n"
10185 "Do not advertise to any peer (well-known community)\n"
10186 "Do not export to next AS (well-known community)\n"
10187 "community number\n"
10188 "Do not send outside local AS (well-known community)\n"
10189 "Do not advertise to any peer (well-known community)\n"
10190 "Do not export to next AS (well-known community)\n"
10191 "community number\n"
10192 "Do not send outside local AS (well-known community)\n"
10193 "Do not advertise to any peer (well-known community)\n"
10194 "Do not export to next AS (well-known community)\n"
10195 "community number\n"
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n"
10199 "Exact match of the communities")
10200
10201/* old command */
10202DEFUN (show_ipv6_mbgp_community,
10203 show_ipv6_mbgp_community_cmd,
10204 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10205 SHOW_STR
10206 IPV6_STR
10207 MBGP_STR
10208 "Display routes matching the communities\n"
10209 "community number\n"
10210 "Do not send outside local AS (well-known community)\n"
10211 "Do not advertise to any peer (well-known community)\n"
10212 "Do not export to next AS (well-known community)\n")
10213{
10214 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10215}
10216
10217/* old command */
10218ALIAS (show_ipv6_mbgp_community,
10219 show_ipv6_mbgp_community2_cmd,
10220 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10221 SHOW_STR
10222 IPV6_STR
10223 MBGP_STR
10224 "Display routes matching the communities\n"
10225 "community number\n"
10226 "Do not send outside local AS (well-known community)\n"
10227 "Do not advertise to any peer (well-known community)\n"
10228 "Do not export to next AS (well-known community)\n"
10229 "community number\n"
10230 "Do not send outside local AS (well-known community)\n"
10231 "Do not advertise to any peer (well-known community)\n"
10232 "Do not export to next AS (well-known community)\n")
10233
10234/* old command */
10235ALIAS (show_ipv6_mbgp_community,
10236 show_ipv6_mbgp_community3_cmd,
10237 "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)",
10238 SHOW_STR
10239 IPV6_STR
10240 MBGP_STR
10241 "Display routes matching the communities\n"
10242 "community number\n"
10243 "Do not send outside local AS (well-known community)\n"
10244 "Do not advertise to any peer (well-known community)\n"
10245 "Do not export to next AS (well-known community)\n"
10246 "community number\n"
10247 "Do not send outside local AS (well-known community)\n"
10248 "Do not advertise to any peer (well-known community)\n"
10249 "Do not export to next AS (well-known community)\n"
10250 "community number\n"
10251 "Do not send outside local AS (well-known community)\n"
10252 "Do not advertise to any peer (well-known community)\n"
10253 "Do not export to next AS (well-known community)\n")
10254
10255/* old command */
10256ALIAS (show_ipv6_mbgp_community,
10257 show_ipv6_mbgp_community4_cmd,
10258 "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)",
10259 SHOW_STR
10260 IPV6_STR
10261 MBGP_STR
10262 "Display routes matching the communities\n"
10263 "community number\n"
10264 "Do not send outside local AS (well-known community)\n"
10265 "Do not advertise to any peer (well-known community)\n"
10266 "Do not export to next AS (well-known community)\n"
10267 "community number\n"
10268 "Do not send outside local AS (well-known community)\n"
10269 "Do not advertise to any peer (well-known community)\n"
10270 "Do not export to next AS (well-known community)\n"
10271 "community number\n"
10272 "Do not send outside local AS (well-known community)\n"
10273 "Do not advertise to any peer (well-known community)\n"
10274 "Do not export to next AS (well-known community)\n"
10275 "community number\n"
10276 "Do not send outside local AS (well-known community)\n"
10277 "Do not advertise to any peer (well-known community)\n"
10278 "Do not export to next AS (well-known community)\n")
10279
10280/* old command */
10281DEFUN (show_ipv6_mbgp_community_exact,
10282 show_ipv6_mbgp_community_exact_cmd,
10283 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10284 SHOW_STR
10285 IPV6_STR
10286 MBGP_STR
10287 "Display routes matching the communities\n"
10288 "community number\n"
10289 "Do not send outside local AS (well-known community)\n"
10290 "Do not advertise to any peer (well-known community)\n"
10291 "Do not export to next AS (well-known community)\n"
10292 "Exact match of the communities")
10293{
10294 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10295}
10296
10297/* old command */
10298ALIAS (show_ipv6_mbgp_community_exact,
10299 show_ipv6_mbgp_community2_exact_cmd,
10300 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10301 SHOW_STR
10302 IPV6_STR
10303 MBGP_STR
10304 "Display routes matching the communities\n"
10305 "community number\n"
10306 "Do not send outside local AS (well-known community)\n"
10307 "Do not advertise to any peer (well-known community)\n"
10308 "Do not export to next AS (well-known community)\n"
10309 "community number\n"
10310 "Do not send outside local AS (well-known community)\n"
10311 "Do not advertise to any peer (well-known community)\n"
10312 "Do not export to next AS (well-known community)\n"
10313 "Exact match of the communities")
10314
10315/* old command */
10316ALIAS (show_ipv6_mbgp_community_exact,
10317 show_ipv6_mbgp_community3_exact_cmd,
10318 "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",
10319 SHOW_STR
10320 IPV6_STR
10321 MBGP_STR
10322 "Display routes matching the communities\n"
10323 "community number\n"
10324 "Do not send outside local AS (well-known community)\n"
10325 "Do not advertise to any peer (well-known community)\n"
10326 "Do not export to next AS (well-known community)\n"
10327 "community number\n"
10328 "Do not send outside local AS (well-known community)\n"
10329 "Do not advertise to any peer (well-known community)\n"
10330 "Do not export to next AS (well-known community)\n"
10331 "community number\n"
10332 "Do not send outside local AS (well-known community)\n"
10333 "Do not advertise to any peer (well-known community)\n"
10334 "Do not export to next AS (well-known community)\n"
10335 "Exact match of the communities")
10336
10337/* old command */
10338ALIAS (show_ipv6_mbgp_community_exact,
10339 show_ipv6_mbgp_community4_exact_cmd,
10340 "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",
10341 SHOW_STR
10342 IPV6_STR
10343 MBGP_STR
10344 "Display routes matching the communities\n"
10345 "community number\n"
10346 "Do not send outside local AS (well-known community)\n"
10347 "Do not advertise to any peer (well-known community)\n"
10348 "Do not export to next AS (well-known community)\n"
10349 "community number\n"
10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n"
10353 "community number\n"
10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 "community number\n"
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n"
10361 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010362
Lou Berger651b4022016-01-12 13:42:07 -050010363DEFUN (show_bgp_ipv4_community,
10364 show_bgp_ipv4_community_cmd,
10365 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010366 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010367 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010368 IP_STR
paul718e3742002-12-13 20:15:29 +000010369 "Display routes matching the communities\n"
10370 "community number\n"
10371 "Do not send outside local AS (well-known community)\n"
10372 "Do not advertise to any peer (well-known community)\n"
10373 "Do not export to next AS (well-known community)\n")
10374{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010375 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010376}
10377
Lou Berger651b4022016-01-12 13:42:07 -050010378ALIAS (show_bgp_ipv4_community,
10379 show_bgp_ipv4_community2_cmd,
10380 "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 +000010381 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010382 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010383 IP_STR
paul718e3742002-12-13 20:15:29 +000010384 "Display routes matching the communities\n"
10385 "community number\n"
10386 "Do not send outside local AS (well-known community)\n"
10387 "Do not advertise to any peer (well-known community)\n"
10388 "Do not export to next AS (well-known community)\n"
10389 "community number\n"
10390 "Do not send outside local AS (well-known community)\n"
10391 "Do not advertise to any peer (well-known community)\n"
10392 "Do not export to next AS (well-known community)\n")
10393
Lou Berger651b4022016-01-12 13:42:07 -050010394ALIAS (show_bgp_ipv4_community,
10395 show_bgp_ipv4_community3_cmd,
10396 "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 +000010397 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010398 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010399 IP_STR
paul718e3742002-12-13 20:15:29 +000010400 "Display routes matching the communities\n"
10401 "community number\n"
10402 "Do not send outside local AS (well-known community)\n"
10403 "Do not advertise to any peer (well-known community)\n"
10404 "Do not export to next AS (well-known community)\n"
10405 "community number\n"
10406 "Do not send outside local AS (well-known community)\n"
10407 "Do not advertise to any peer (well-known community)\n"
10408 "Do not export to next AS (well-known community)\n"
10409 "community number\n"
10410 "Do not send outside local AS (well-known community)\n"
10411 "Do not advertise to any peer (well-known community)\n"
10412 "Do not export to next AS (well-known community)\n")
10413
Lou Berger651b4022016-01-12 13:42:07 -050010414ALIAS (show_bgp_ipv4_community,
10415 show_bgp_ipv4_community4_cmd,
10416 "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 +000010417 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010418 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010419 IP_STR
paul718e3742002-12-13 20:15:29 +000010420 "Display routes matching the communities\n"
10421 "community number\n"
10422 "Do not send outside local AS (well-known community)\n"
10423 "Do not advertise to any peer (well-known community)\n"
10424 "Do not export to next AS (well-known community)\n"
10425 "community number\n"
10426 "Do not send outside local AS (well-known community)\n"
10427 "Do not advertise to any peer (well-known community)\n"
10428 "Do not export to next AS (well-known community)\n"
10429 "community number\n"
10430 "Do not send outside local AS (well-known community)\n"
10431 "Do not advertise to any peer (well-known community)\n"
10432 "Do not export to next AS (well-known community)\n"
10433 "community number\n"
10434 "Do not send outside local AS (well-known community)\n"
10435 "Do not advertise to any peer (well-known community)\n"
10436 "Do not export to next AS (well-known community)\n")
10437
Lou Berger651b4022016-01-12 13:42:07 -050010438DEFUN (show_bgp_ipv4_safi_community,
10439 show_bgp_ipv4_safi_community_cmd,
10440 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010441 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010442 BGP_STR
10443 "Address family\n"
10444 "Address Family modifier\n"
10445 "Address Family modifier\n"
10446 "Display routes matching the communities\n"
10447 "community number\n"
10448 "Do not send outside local AS (well-known community)\n"
10449 "Do not advertise to any peer (well-known community)\n"
10450 "Do not export to next AS (well-known community)\n")
10451{
10452 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010453 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010454
Michael Lambert95cbbd22010-07-23 14:43:04 -040010455 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010456}
10457
Lou Berger651b4022016-01-12 13:42:07 -050010458ALIAS (show_bgp_ipv4_safi_community,
10459 show_bgp_ipv4_safi_community2_cmd,
10460 "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 +000010461 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010462 BGP_STR
10463 "Address family\n"
10464 "Address Family modifier\n"
10465 "Address Family modifier\n"
10466 "Display routes matching the communities\n"
10467 "community number\n"
10468 "Do not send outside local AS (well-known community)\n"
10469 "Do not advertise to any peer (well-known community)\n"
10470 "Do not export to next AS (well-known community)\n"
10471 "community number\n"
10472 "Do not send outside local AS (well-known community)\n"
10473 "Do not advertise to any peer (well-known community)\n"
10474 "Do not export to next AS (well-known community)\n")
10475
Lou Berger651b4022016-01-12 13:42:07 -050010476ALIAS (show_bgp_ipv4_safi_community,
10477 show_bgp_ipv4_safi_community3_cmd,
10478 "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 +000010479 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010480 BGP_STR
10481 "Address family\n"
10482 "Address Family modifier\n"
10483 "Address Family modifier\n"
10484 "Display routes matching the communities\n"
10485 "community number\n"
10486 "Do not send outside local AS (well-known community)\n"
10487 "Do not advertise to any peer (well-known community)\n"
10488 "Do not export to next AS (well-known community)\n"
10489 "community number\n"
10490 "Do not send outside local AS (well-known community)\n"
10491 "Do not advertise to any peer (well-known community)\n"
10492 "Do not export to next AS (well-known community)\n"
10493 "community number\n"
10494 "Do not send outside local AS (well-known community)\n"
10495 "Do not advertise to any peer (well-known community)\n"
10496 "Do not export to next AS (well-known community)\n")
10497
Lou Berger651b4022016-01-12 13:42:07 -050010498ALIAS (show_bgp_ipv4_safi_community,
10499 show_bgp_ipv4_safi_community4_cmd,
10500 "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 +000010501 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010502 BGP_STR
10503 "Address family\n"
10504 "Address Family modifier\n"
10505 "Address Family modifier\n"
10506 "Display routes matching the communities\n"
10507 "community number\n"
10508 "Do not send outside local AS (well-known community)\n"
10509 "Do not advertise to any peer (well-known community)\n"
10510 "Do not export to next AS (well-known community)\n"
10511 "community number\n"
10512 "Do not send outside local AS (well-known community)\n"
10513 "Do not advertise to any peer (well-known community)\n"
10514 "Do not export to next AS (well-known community)\n"
10515 "community number\n"
10516 "Do not send outside local AS (well-known community)\n"
10517 "Do not advertise to any peer (well-known community)\n"
10518 "Do not export to next AS (well-known community)\n"
10519 "community number\n"
10520 "Do not send outside local AS (well-known community)\n"
10521 "Do not advertise to any peer (well-known community)\n"
10522 "Do not export to next AS (well-known community)\n")
10523
Michael Lambert95cbbd22010-07-23 14:43:04 -040010524DEFUN (show_bgp_view_afi_safi_community_all,
10525 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010526 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010527 SHOW_STR
10528 BGP_STR
10529 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010530 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010531 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010532 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010533 "Address Family modifier\n"
10534 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010535 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010536{
10537 int afi;
10538 int safi;
10539 struct bgp *bgp;
10540
10541 /* BGP structure lookup. */
10542 bgp = bgp_lookup_by_name (argv[0]);
10543 if (bgp == NULL)
10544 {
10545 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10546 return CMD_WARNING;
10547 }
10548
Michael Lambert95cbbd22010-07-23 14:43:04 -040010549 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10550 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010551 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10552}
10553
10554DEFUN (show_bgp_view_afi_safi_community,
10555 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010556 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010557 SHOW_STR
10558 BGP_STR
10559 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010560 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010561 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010562 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010563 "Address family modifier\n"
10564 "Address family modifier\n"
10565 "Display routes matching the communities\n"
10566 "community number\n"
10567 "Do not send outside local AS (well-known community)\n"
10568 "Do not advertise to any peer (well-known community)\n"
10569 "Do not export to next AS (well-known community)\n")
10570{
10571 int afi;
10572 int safi;
10573
Michael Lambert95cbbd22010-07-23 14:43:04 -040010574 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10575 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10576 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010577}
10578
10579ALIAS (show_bgp_view_afi_safi_community,
10580 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010581 "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 -040010582 SHOW_STR
10583 BGP_STR
10584 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010585 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010586 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010587 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010588 "Address family modifier\n"
10589 "Address family modifier\n"
10590 "Display routes matching the communities\n"
10591 "community number\n"
10592 "Do not send outside local AS (well-known community)\n"
10593 "Do not advertise to any peer (well-known community)\n"
10594 "Do not export to next AS (well-known community)\n"
10595 "community number\n"
10596 "Do not send outside local AS (well-known community)\n"
10597 "Do not advertise to any peer (well-known community)\n"
10598 "Do not export to next AS (well-known community)\n")
10599
10600ALIAS (show_bgp_view_afi_safi_community,
10601 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010602 "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 -040010603 SHOW_STR
10604 BGP_STR
10605 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010606 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010607 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010608 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010609 "Address family modifier\n"
10610 "Address family modifier\n"
10611 "Display routes matching the communities\n"
10612 "community number\n"
10613 "Do not send outside local AS (well-known community)\n"
10614 "Do not advertise to any peer (well-known community)\n"
10615 "Do not export to next AS (well-known community)\n"
10616 "community number\n"
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
10620 "community number\n"
10621 "Do not send outside local AS (well-known community)\n"
10622 "Do not advertise to any peer (well-known community)\n"
10623 "Do not export to next AS (well-known community)\n")
10624
10625ALIAS (show_bgp_view_afi_safi_community,
10626 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010627 "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 -040010628 SHOW_STR
10629 BGP_STR
10630 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010631 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010632 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010633 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010634 "Address family modifier\n"
10635 "Address family modifier\n"
10636 "Display routes matching the communities\n"
10637 "community number\n"
10638 "Do not send outside local AS (well-known community)\n"
10639 "Do not advertise to any peer (well-known community)\n"
10640 "Do not export to next AS (well-known community)\n"
10641 "community number\n"
10642 "Do not send outside local AS (well-known community)\n"
10643 "Do not advertise to any peer (well-known community)\n"
10644 "Do not export to next AS (well-known community)\n"
10645 "community number\n"
10646 "Do not send outside local AS (well-known community)\n"
10647 "Do not advertise to any peer (well-known community)\n"
10648 "Do not export to next AS (well-known community)\n"
10649 "community number\n"
10650 "Do not send outside local AS (well-known community)\n"
10651 "Do not advertise to any peer (well-known community)\n"
10652 "Do not export to next AS (well-known community)\n")
10653
Lou Berger651b4022016-01-12 13:42:07 -050010654DEFUN (show_bgp_ipv4_community_exact,
10655 show_bgp_ipv4_community_exact_cmd,
10656 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010657 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010658 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010659 IP_STR
paul718e3742002-12-13 20:15:29 +000010660 "Display routes matching the communities\n"
10661 "community number\n"
10662 "Do not send outside local AS (well-known community)\n"
10663 "Do not advertise to any peer (well-known community)\n"
10664 "Do not export to next AS (well-known community)\n"
10665 "Exact match of the communities")
10666{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010667 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010668}
10669
Lou Berger651b4022016-01-12 13:42:07 -050010670ALIAS (show_bgp_ipv4_community_exact,
10671 show_bgp_ipv4_community2_exact_cmd,
10672 "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 +000010673 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010674 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010675 IP_STR
paul718e3742002-12-13 20:15:29 +000010676 "Display routes matching the communities\n"
10677 "community number\n"
10678 "Do not send outside local AS (well-known community)\n"
10679 "Do not advertise to any peer (well-known community)\n"
10680 "Do not export to next AS (well-known community)\n"
10681 "community number\n"
10682 "Do not send outside local AS (well-known community)\n"
10683 "Do not advertise to any peer (well-known community)\n"
10684 "Do not export to next AS (well-known community)\n"
10685 "Exact match of the communities")
10686
Lou Berger651b4022016-01-12 13:42:07 -050010687ALIAS (show_bgp_ipv4_community_exact,
10688 show_bgp_ipv4_community3_exact_cmd,
10689 "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 +000010690 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010691 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010692 IP_STR
paul718e3742002-12-13 20:15:29 +000010693 "Display routes matching the communities\n"
10694 "community number\n"
10695 "Do not send outside local AS (well-known community)\n"
10696 "Do not advertise to any peer (well-known community)\n"
10697 "Do not export to next AS (well-known community)\n"
10698 "community number\n"
10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
10702 "community number\n"
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 "Exact match of the communities")
10707
Lou Berger651b4022016-01-12 13:42:07 -050010708ALIAS (show_bgp_ipv4_community_exact,
10709 show_bgp_ipv4_community4_exact_cmd,
10710 "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 +000010711 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010712 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010713 IP_STR
paul718e3742002-12-13 20:15:29 +000010714 "Display routes matching the communities\n"
10715 "community number\n"
10716 "Do not send outside local AS (well-known community)\n"
10717 "Do not advertise to any peer (well-known community)\n"
10718 "Do not export to next AS (well-known community)\n"
10719 "community number\n"
10720 "Do not send outside local AS (well-known community)\n"
10721 "Do not advertise to any peer (well-known community)\n"
10722 "Do not export to next AS (well-known community)\n"
10723 "community number\n"
10724 "Do not send outside local AS (well-known community)\n"
10725 "Do not advertise to any peer (well-known community)\n"
10726 "Do not export to next AS (well-known community)\n"
10727 "community number\n"
10728 "Do not send outside local AS (well-known community)\n"
10729 "Do not advertise to any peer (well-known community)\n"
10730 "Do not export to next AS (well-known community)\n"
10731 "Exact match of the communities")
10732
Lou Berger651b4022016-01-12 13:42:07 -050010733DEFUN (show_bgp_ipv4_safi_community4_exact,
10734 show_bgp_ipv4_safi_community_exact_cmd,
10735 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010736 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010737 BGP_STR
10738 "Address family\n"
10739 "Address Family modifier\n"
10740 "Address Family modifier\n"
10741 "Display routes matching the communities\n"
10742 "community number\n"
10743 "Do not send outside local AS (well-known community)\n"
10744 "Do not advertise to any peer (well-known community)\n"
10745 "Do not export to next AS (well-known community)\n"
10746 "Exact match of the communities")
10747{
10748 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010749 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010750
Michael Lambert95cbbd22010-07-23 14:43:04 -040010751 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010752}
10753
Lou Berger651b4022016-01-12 13:42:07 -050010754ALIAS (show_bgp_ipv4_safi_community4_exact,
10755 show_bgp_ipv4_safi_community2_exact_cmd,
10756 "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 +000010757 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010758 BGP_STR
10759 "Address family\n"
10760 "Address Family modifier\n"
10761 "Address Family modifier\n"
10762 "Display routes matching the communities\n"
10763 "community number\n"
10764 "Do not send outside local AS (well-known community)\n"
10765 "Do not advertise to any peer (well-known community)\n"
10766 "Do not export to next AS (well-known community)\n"
10767 "community number\n"
10768 "Do not send outside local AS (well-known community)\n"
10769 "Do not advertise to any peer (well-known community)\n"
10770 "Do not export to next AS (well-known community)\n"
10771 "Exact match of the communities")
10772
Lou Berger651b4022016-01-12 13:42:07 -050010773ALIAS (show_bgp_ipv4_safi_community4_exact,
10774 show_bgp_ipv4_safi_community3_exact_cmd,
10775 "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 +000010776 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010777 BGP_STR
10778 "Address family\n"
10779 "Address Family modifier\n"
10780 "Address Family modifier\n"
10781 "Display routes matching the communities\n"
10782 "community number\n"
10783 "Do not send outside local AS (well-known community)\n"
10784 "Do not advertise to any peer (well-known community)\n"
10785 "Do not export to next AS (well-known community)\n"
10786 "community number\n"
10787 "Do not send outside local AS (well-known community)\n"
10788 "Do not advertise to any peer (well-known community)\n"
10789 "Do not export to next AS (well-known community)\n"
10790 "community number\n"
10791 "Do not send outside local AS (well-known community)\n"
10792 "Do not advertise to any peer (well-known community)\n"
10793 "Do not export to next AS (well-known community)\n"
10794 "Exact match of the communities")
10795
Lou Berger651b4022016-01-12 13:42:07 -050010796ALIAS (show_bgp_ipv4_safi_community4_exact,
10797 show_bgp_ipv4_safi_community4_exact_cmd,
10798 "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 +000010799 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010800 BGP_STR
10801 "Address family\n"
10802 "Address Family modifier\n"
10803 "Address Family modifier\n"
10804 "Display routes matching the communities\n"
10805 "community number\n"
10806 "Do not send outside local AS (well-known community)\n"
10807 "Do not advertise to any peer (well-known community)\n"
10808 "Do not export to next AS (well-known community)\n"
10809 "community number\n"
10810 "Do not send outside local AS (well-known community)\n"
10811 "Do not advertise to any peer (well-known community)\n"
10812 "Do not export to next AS (well-known community)\n"
10813 "community number\n"
10814 "Do not send outside local AS (well-known community)\n"
10815 "Do not advertise to any peer (well-known community)\n"
10816 "Do not export to next AS (well-known community)\n"
10817 "community number\n"
10818 "Do not send outside local AS (well-known community)\n"
10819 "Do not advertise to any peer (well-known community)\n"
10820 "Do not export to next AS (well-known community)\n"
10821 "Exact match of the communities")
10822
Lou Bergerf9b6c392016-01-12 13:42:09 -050010823DEFUN (show_bgp_ipv6_safi_community,
10824 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010825 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010826 SHOW_STR
10827 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010828 "Address family\n"
10829 "Address family modifier\n"
10830 "Address family modifier\n"
10831 "Address family modifier\n"
10832 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010833 "Display routes matching the communities\n"
10834 "community number\n"
10835 "Do not send outside local AS (well-known community)\n"
10836 "Do not advertise to any peer (well-known community)\n"
10837 "Do not export to next AS (well-known community)\n")
10838{
Lou Berger651b4022016-01-12 13:42:07 -050010839 safi_t safi;
10840
10841 if (bgp_parse_safi(argv[0], &safi)) {
10842 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10843 return CMD_WARNING;
10844 }
10845 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010846}
10847
Lou Bergerf9b6c392016-01-12 13:42:09 -050010848ALIAS (show_bgp_ipv6_safi_community,
10849 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010850 "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 +000010851 SHOW_STR
10852 BGP_STR
10853 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010854 "Address family modifier\n"
10855 "Address family modifier\n"
10856 "Address family modifier\n"
10857 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010858 "Display routes matching the communities\n"
10859 "community number\n"
10860 "Do not send outside local AS (well-known community)\n"
10861 "Do not advertise to any peer (well-known community)\n"
10862 "Do not export to next AS (well-known community)\n"
10863 "community number\n"
10864 "Do not send outside local AS (well-known community)\n"
10865 "Do not advertise to any peer (well-known community)\n"
10866 "Do not export to next AS (well-known community)\n")
10867
Lou Bergerf9b6c392016-01-12 13:42:09 -050010868ALIAS (show_bgp_ipv6_safi_community,
10869 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010870 "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 +000010871 SHOW_STR
10872 BGP_STR
10873 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010874 "Address family modifier\n"
10875 "Address family modifier\n"
10876 "Address family modifier\n"
10877 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010878 "Display routes matching the communities\n"
10879 "community number\n"
10880 "Do not send outside local AS (well-known community)\n"
10881 "Do not advertise to any peer (well-known community)\n"
10882 "Do not export to next AS (well-known community)\n"
10883 "community number\n"
10884 "Do not send outside local AS (well-known community)\n"
10885 "Do not advertise to any peer (well-known community)\n"
10886 "Do not export to next AS (well-known community)\n"
10887 "community number\n"
10888 "Do not send outside local AS (well-known community)\n"
10889 "Do not advertise to any peer (well-known community)\n"
10890 "Do not export to next AS (well-known community)\n")
10891
Lou Bergerf9b6c392016-01-12 13:42:09 -050010892ALIAS (show_bgp_ipv6_safi_community,
10893 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010894 "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 +000010895 SHOW_STR
10896 BGP_STR
10897 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010898 "Address family modifier\n"
10899 "Address family modifier\n"
10900 "Address family modifier\n"
10901 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010902 "Display routes matching the communities\n"
10903 "community number\n"
10904 "Do not send outside local AS (well-known community)\n"
10905 "Do not advertise to any peer (well-known community)\n"
10906 "Do not export to next AS (well-known community)\n"
10907 "community number\n"
10908 "Do not send outside local AS (well-known community)\n"
10909 "Do not advertise to any peer (well-known community)\n"
10910 "Do not export to next AS (well-known community)\n"
10911 "community number\n"
10912 "Do not send outside local AS (well-known community)\n"
10913 "Do not advertise to any peer (well-known community)\n"
10914 "Do not export to next AS (well-known community)\n"
10915 "community number\n"
10916 "Do not send outside local AS (well-known community)\n"
10917 "Do not advertise to any peer (well-known community)\n"
10918 "Do not export to next AS (well-known community)\n")
10919
paul718e3742002-12-13 20:15:29 +000010920
Lou Bergerf9b6c392016-01-12 13:42:09 -050010921DEFUN (show_bgp_ipv6_safi_community_exact,
10922 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010923 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010924 SHOW_STR
10925 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010926 "Address family\n"
10927 "Address family modifier\n"
10928 "Address family modifier\n"
10929 "Address family modifier\n"
10930 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010931 "Display routes matching the communities\n"
10932 "community number\n"
10933 "Do not send outside local AS (well-known community)\n"
10934 "Do not advertise to any peer (well-known community)\n"
10935 "Do not export to next AS (well-known community)\n"
10936 "Exact match of the communities")
10937{
Lou Berger651b4022016-01-12 13:42:07 -050010938 safi_t safi;
10939
10940 if (bgp_parse_safi(argv[0], &safi)) {
10941 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10942 return CMD_WARNING;
10943 }
10944 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010945}
10946
paul718e3742002-12-13 20:15:29 +000010947
10948ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010949 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010950 "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 +000010951 SHOW_STR
10952 BGP_STR
10953 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010954 "Address family modifier\n"
10955 "Address family modifier\n"
10956 "Address family modifier\n"
10957 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010958 "Display routes matching the communities\n"
10959 "community number\n"
10960 "Do not send outside local AS (well-known community)\n"
10961 "Do not advertise to any peer (well-known community)\n"
10962 "Do not export to next AS (well-known community)\n"
10963 "community number\n"
10964 "Do not send outside local AS (well-known community)\n"
10965 "Do not advertise to any peer (well-known community)\n"
10966 "Do not export to next AS (well-known community)\n"
10967 "Exact match of the communities")
10968
10969ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010970 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010971 "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 +000010972 SHOW_STR
10973 BGP_STR
10974 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010975 "Address family modifier\n"
10976 "Address family modifier\n"
10977 "Address family modifier\n"
10978 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010979 "Display routes matching the communities\n"
10980 "community number\n"
10981 "Do not send outside local AS (well-known community)\n"
10982 "Do not advertise to any peer (well-known community)\n"
10983 "Do not export to next AS (well-known community)\n"
10984 "community number\n"
10985 "Do not send outside local AS (well-known community)\n"
10986 "Do not advertise to any peer (well-known community)\n"
10987 "Do not export to next AS (well-known community)\n"
10988 "community number\n"
10989 "Do not send outside local AS (well-known community)\n"
10990 "Do not advertise to any peer (well-known community)\n"
10991 "Do not export to next AS (well-known community)\n"
10992 "Exact match of the communities")
10993
10994ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010995 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010996 "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 +000010997 SHOW_STR
10998 BGP_STR
10999 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011000 "Address family modifier\n"
11001 "Address family modifier\n"
11002 "Address family modifier\n"
11003 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011004 "Display routes matching the communities\n"
11005 "community number\n"
11006 "Do not send outside local AS (well-known community)\n"
11007 "Do not advertise to any peer (well-known community)\n"
11008 "Do not export to next AS (well-known community)\n"
11009 "community number\n"
11010 "Do not send outside local AS (well-known community)\n"
11011 "Do not advertise to any peer (well-known community)\n"
11012 "Do not export to next AS (well-known community)\n"
11013 "community number\n"
11014 "Do not send outside local AS (well-known community)\n"
11015 "Do not advertise to any peer (well-known community)\n"
11016 "Do not export to next AS (well-known community)\n"
11017 "community number\n"
11018 "Do not send outside local AS (well-known community)\n"
11019 "Do not advertise to any peer (well-known community)\n"
11020 "Do not export to next AS (well-known community)\n"
11021 "Exact match of the communities")
11022
paul94f2b392005-06-28 12:44:16 +000011023static int
paulfd79ac92004-10-13 05:06:08 +000011024bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040011025 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000011026{
11027 struct community_list *list;
11028
hassofee6e4e2005-02-02 16:29:31 +000011029 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000011030 if (list == NULL)
11031 {
11032 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11033 VTY_NEWLINE);
11034 return CMD_WARNING;
11035 }
11036
ajs5a646652004-11-05 01:25:55 +000011037 return bgp_show (vty, NULL, afi, safi,
11038 (exact ? bgp_show_type_community_list_exact :
11039 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000011040}
11041
Lou Bergerf9b6c392016-01-12 13:42:09 -050011042DEFUN (show_ip_bgp_community_list,
11043 show_ip_bgp_community_list_cmd,
11044 "show ip bgp community-list (<1-500>|WORD)",
11045 SHOW_STR
11046 IP_STR
11047 BGP_STR
11048 "Display routes matching the community-list\n"
11049 "community-list number\n"
11050 "community-list name\n")
11051{
11052 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11053}
11054
11055DEFUN (show_ip_bgp_ipv4_community_list,
11056 show_ip_bgp_ipv4_community_list_cmd,
11057 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11058 SHOW_STR
11059 IP_STR
11060 BGP_STR
11061 "Address family\n"
11062 "Address Family modifier\n"
11063 "Address Family modifier\n"
11064 "Display routes matching the community-list\n"
11065 "community-list number\n"
11066 "community-list name\n")
11067{
11068 if (strncmp (argv[0], "m", 1) == 0)
11069 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11070
11071 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11072}
11073
11074DEFUN (show_ip_bgp_community_list_exact,
11075 show_ip_bgp_community_list_exact_cmd,
11076 "show ip bgp community-list (<1-500>|WORD) exact-match",
11077 SHOW_STR
11078 IP_STR
11079 BGP_STR
11080 "Display routes matching the community-list\n"
11081 "community-list number\n"
11082 "community-list name\n"
11083 "Exact match of the communities\n")
11084{
11085 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11086}
11087
11088DEFUN (show_ip_bgp_ipv4_community_list_exact,
11089 show_ip_bgp_ipv4_community_list_exact_cmd,
11090 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11091 SHOW_STR
11092 IP_STR
11093 BGP_STR
11094 "Address family\n"
11095 "Address Family modifier\n"
11096 "Address Family modifier\n"
11097 "Display routes matching the community-list\n"
11098 "community-list number\n"
11099 "community-list name\n"
11100 "Exact match of the communities\n")
11101{
11102 if (strncmp (argv[0], "m", 1) == 0)
11103 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11104
11105 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11106}
11107
Lou Bergerf9b6c392016-01-12 13:42:09 -050011108DEFUN (show_bgp_community_list,
11109 show_bgp_community_list_cmd,
11110 "show bgp community-list (<1-500>|WORD)",
11111 SHOW_STR
11112 BGP_STR
11113 "Display routes matching the community-list\n"
11114 "community-list number\n"
11115 "community-list name\n")
11116{
11117 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11118}
11119
11120ALIAS (show_bgp_community_list,
11121 show_bgp_ipv6_community_list_cmd,
11122 "show bgp ipv6 community-list (<1-500>|WORD)",
11123 SHOW_STR
11124 BGP_STR
11125 "Address family\n"
11126 "Display routes matching the community-list\n"
11127 "community-list number\n"
11128 "community-list name\n")
11129
11130/* old command */
11131DEFUN (show_ipv6_bgp_community_list,
11132 show_ipv6_bgp_community_list_cmd,
11133 "show ipv6 bgp community-list WORD",
11134 SHOW_STR
11135 IPV6_STR
11136 BGP_STR
11137 "Display routes matching the community-list\n"
11138 "community-list name\n")
11139{
11140 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11141}
11142
11143/* old command */
11144DEFUN (show_ipv6_mbgp_community_list,
11145 show_ipv6_mbgp_community_list_cmd,
11146 "show ipv6 mbgp community-list WORD",
11147 SHOW_STR
11148 IPV6_STR
11149 MBGP_STR
11150 "Display routes matching the community-list\n"
11151 "community-list name\n")
11152{
11153 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11154}
11155
11156DEFUN (show_bgp_community_list_exact,
11157 show_bgp_community_list_exact_cmd,
11158 "show bgp community-list (<1-500>|WORD) exact-match",
11159 SHOW_STR
11160 BGP_STR
11161 "Display routes matching the community-list\n"
11162 "community-list number\n"
11163 "community-list name\n"
11164 "Exact match of the communities\n")
11165{
11166 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11167}
11168
11169ALIAS (show_bgp_community_list_exact,
11170 show_bgp_ipv6_community_list_exact_cmd,
11171 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11172 SHOW_STR
11173 BGP_STR
11174 "Address family\n"
11175 "Display routes matching the community-list\n"
11176 "community-list number\n"
11177 "community-list name\n"
11178 "Exact match of the communities\n")
11179
11180/* old command */
11181DEFUN (show_ipv6_bgp_community_list_exact,
11182 show_ipv6_bgp_community_list_exact_cmd,
11183 "show ipv6 bgp community-list WORD exact-match",
11184 SHOW_STR
11185 IPV6_STR
11186 BGP_STR
11187 "Display routes matching the community-list\n"
11188 "community-list name\n"
11189 "Exact match of the communities\n")
11190{
11191 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11192}
11193
11194/* old command */
11195DEFUN (show_ipv6_mbgp_community_list_exact,
11196 show_ipv6_mbgp_community_list_exact_cmd,
11197 "show ipv6 mbgp community-list WORD exact-match",
11198 SHOW_STR
11199 IPV6_STR
11200 MBGP_STR
11201 "Display routes matching the community-list\n"
11202 "community-list name\n"
11203 "Exact match of the communities\n")
11204{
11205 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11206}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011207
Lou Berger651b4022016-01-12 13:42:07 -050011208DEFUN (show_bgp_ipv4_community_list,
11209 show_bgp_ipv4_community_list_cmd,
11210 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011211 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011212 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011213 IP_STR
paul718e3742002-12-13 20:15:29 +000011214 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011215 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011216 "community-list name\n")
11217{
11218 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11219}
11220
Lou Berger651b4022016-01-12 13:42:07 -050011221DEFUN (show_bgp_ipv4_safi_community_list,
11222 show_bgp_ipv4_safi_community_list_cmd,
11223 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011224 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011225 BGP_STR
11226 "Address family\n"
11227 "Address Family modifier\n"
11228 "Address Family modifier\n"
11229 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011230 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011231 "community-list name\n")
11232{
11233 if (strncmp (argv[0], "m", 1) == 0)
11234 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11235
11236 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11237}
11238
Lou Berger651b4022016-01-12 13:42:07 -050011239DEFUN (show_bgp_ipv4_community_list_exact,
11240 show_bgp_ipv4_community_list_exact_cmd,
11241 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011242 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011243 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011244 IP_STR
paul718e3742002-12-13 20:15:29 +000011245 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011246 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011247 "community-list name\n"
11248 "Exact match of the communities\n")
11249{
11250 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11251}
11252
Lou Berger651b4022016-01-12 13:42:07 -050011253DEFUN (show_bgp_ipv4_safi_community_list_exact,
11254 show_bgp_ipv4_safi_community_list_exact_cmd,
11255 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011256 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011257 BGP_STR
11258 "Address family\n"
11259 "Address Family modifier\n"
11260 "Address Family modifier\n"
11261 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011262 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011263 "community-list name\n"
11264 "Exact match of the communities\n")
11265{
11266 if (strncmp (argv[0], "m", 1) == 0)
11267 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11268
11269 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11270}
11271
Lou Bergerf9b6c392016-01-12 13:42:09 -050011272DEFUN (show_bgp_ipv6_safi_community_list,
11273 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011274 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011275 SHOW_STR
11276 BGP_STR
11277 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011278 "Address family modifier\n"
11279 "Address family modifier\n"
11280 "Address family modifier\n"
11281 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011282 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011283 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011284 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011285{
Lou Berger651b4022016-01-12 13:42:07 -050011286 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011287
Lou Berger651b4022016-01-12 13:42:07 -050011288 if (bgp_parse_safi(argv[0], &safi)) {
11289 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11290 return CMD_WARNING;
11291 }
11292 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011293}
11294
Lou Bergerf9b6c392016-01-12 13:42:09 -050011295DEFUN (show_bgp_ipv6_safi_community_list_exact,
11296 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011297 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011298 SHOW_STR
11299 BGP_STR
11300 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011301 "Address family modifier\n"
11302 "Address family modifier\n"
11303 "Address family modifier\n"
11304 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011305 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011306 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011307 "community-list name\n"
11308 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011309{
Lou Berger651b4022016-01-12 13:42:07 -050011310 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011311
Lou Berger651b4022016-01-12 13:42:07 -050011312 if (bgp_parse_safi(argv[0], &safi)) {
11313 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11314 return CMD_WARNING;
11315 }
11316 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011317}
David Lamparter6b0655a2014-06-04 06:53:35 +020011318
paul94f2b392005-06-28 12:44:16 +000011319static int
paulfd79ac92004-10-13 05:06:08 +000011320bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011321 safi_t safi, enum bgp_show_type type)
11322{
11323 int ret;
11324 struct prefix *p;
11325
11326 p = prefix_new();
11327
11328 ret = str2prefix (prefix, p);
11329 if (! ret)
11330 {
11331 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11332 return CMD_WARNING;
11333 }
11334
ajs5a646652004-11-05 01:25:55 +000011335 ret = bgp_show (vty, NULL, afi, safi, type, p);
11336 prefix_free(p);
11337 return ret;
paul718e3742002-12-13 20:15:29 +000011338}
11339
Lou Bergerf9b6c392016-01-12 13:42:09 -050011340DEFUN (show_ip_bgp_prefix_longer,
11341 show_ip_bgp_prefix_longer_cmd,
11342 "show ip bgp A.B.C.D/M longer-prefixes",
11343 SHOW_STR
11344 IP_STR
11345 BGP_STR
11346 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11347 "Display route and more specific routes\n")
11348{
11349 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11350 bgp_show_type_prefix_longer);
11351}
11352
11353DEFUN (show_ip_bgp_flap_prefix_longer,
11354 show_ip_bgp_flap_prefix_longer_cmd,
11355 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11356 SHOW_STR
11357 IP_STR
11358 BGP_STR
11359 "Display flap statistics of routes\n"
11360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11361 "Display route and more specific routes\n")
11362{
11363 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11364 bgp_show_type_flap_prefix_longer);
11365}
11366
11367ALIAS (show_ip_bgp_flap_prefix_longer,
11368 show_ip_bgp_damp_flap_prefix_longer_cmd,
11369 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11370 SHOW_STR
11371 IP_STR
11372 BGP_STR
11373 "Display detailed information about dampening\n"
11374 "Display flap statistics of routes\n"
11375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11376 "Display route and more specific routes\n")
11377
11378DEFUN (show_ip_bgp_ipv4_prefix_longer,
11379 show_ip_bgp_ipv4_prefix_longer_cmd,
11380 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11381 SHOW_STR
11382 IP_STR
11383 BGP_STR
11384 "Address family\n"
11385 "Address Family modifier\n"
11386 "Address Family modifier\n"
11387 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11388 "Display route and more specific routes\n")
11389{
11390 if (strncmp (argv[0], "m", 1) == 0)
11391 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11392 bgp_show_type_prefix_longer);
11393
11394 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11395 bgp_show_type_prefix_longer);
11396}
11397
11398DEFUN (show_ip_bgp_flap_address,
11399 show_ip_bgp_flap_address_cmd,
11400 "show ip bgp flap-statistics A.B.C.D",
11401 SHOW_STR
11402 IP_STR
11403 BGP_STR
11404 "Display flap statistics of routes\n"
11405 "Network in the BGP routing table to display\n")
11406{
11407 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11408 bgp_show_type_flap_address);
11409}
11410
11411ALIAS (show_ip_bgp_flap_address,
11412 show_ip_bgp_damp_flap_address_cmd,
11413 "show ip bgp dampening flap-statistics A.B.C.D",
11414 SHOW_STR
11415 IP_STR
11416 BGP_STR
11417 "Display detailed information about dampening\n"
11418 "Display flap statistics of routes\n"
11419 "Network in the BGP routing table to display\n")
11420
11421DEFUN (show_ip_bgp_flap_prefix,
11422 show_ip_bgp_flap_prefix_cmd,
11423 "show ip bgp flap-statistics A.B.C.D/M",
11424 SHOW_STR
11425 IP_STR
11426 BGP_STR
11427 "Display flap statistics of routes\n"
11428 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11429{
11430 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11431 bgp_show_type_flap_prefix);
11432}
11433
11434ALIAS (show_ip_bgp_flap_prefix,
11435 show_ip_bgp_damp_flap_prefix_cmd,
11436 "show ip bgp dampening flap-statistics A.B.C.D/M",
11437 SHOW_STR
11438 IP_STR
11439 BGP_STR
11440 "Display detailed information about dampening\n"
11441 "Display flap statistics of routes\n"
11442 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11443
Lou Bergerf9b6c392016-01-12 13:42:09 -050011444DEFUN (show_bgp_prefix_longer,
11445 show_bgp_prefix_longer_cmd,
11446 "show bgp X:X::X:X/M longer-prefixes",
11447 SHOW_STR
11448 BGP_STR
11449 "IPv6 prefix <network>/<length>\n"
11450 "Display route and more specific routes\n")
11451{
11452 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11453 bgp_show_type_prefix_longer);
11454}
11455
11456/* old command */
11457DEFUN (show_ipv6_bgp_prefix_longer,
11458 show_ipv6_bgp_prefix_longer_cmd,
11459 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11460 SHOW_STR
11461 IPV6_STR
11462 BGP_STR
11463 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11464 "Display route and more specific routes\n")
11465{
11466 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11467 bgp_show_type_prefix_longer);
11468}
11469
11470/* old command */
11471DEFUN (show_ipv6_mbgp_prefix_longer,
11472 show_ipv6_mbgp_prefix_longer_cmd,
11473 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11474 SHOW_STR
11475 IPV6_STR
11476 MBGP_STR
11477 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11478 "Display route and more specific routes\n")
11479{
11480 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11481 bgp_show_type_prefix_longer);
11482}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011483
Lou Berger651b4022016-01-12 13:42:07 -050011484DEFUN (show_bgp_ipv4_prefix_longer,
11485 show_bgp_ipv4_prefix_longer_cmd,
11486 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011487 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011488 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011489 IP_STR
paul718e3742002-12-13 20:15:29 +000011490 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11491 "Display route and more specific routes\n")
11492{
11493 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11494 bgp_show_type_prefix_longer);
11495}
11496
Lou Berger651b4022016-01-12 13:42:07 -050011497DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11498 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11499 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011500 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011501 BGP_STR
11502 "Address family\n"
11503 "Address Family modifier\n"
11504 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011505 "Address Family modifier\n"
11506 "Address Family modifier\n"
11507 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011508 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11509 "Display route and more specific routes\n")
11510{
Lou Berger651b4022016-01-12 13:42:07 -050011511 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011512
Lou Berger651b4022016-01-12 13:42:07 -050011513 if (bgp_parse_safi(argv[0], &safi)) {
11514 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11515 return CMD_WARNING;
11516 }
11517 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11518 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011519}
11520
Lou Berger651b4022016-01-12 13:42:07 -050011521ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11522 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11523 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011524 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011525 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011526 "Address family\n"
11527 "Address Family modifier\n"
11528 "Address Family modifier\n"
11529 "Address Family modifier\n"
11530 "Address Family modifier\n"
11531 "Display detailed information about dampening\n"
11532 "Display flap statistics of routes\n"
11533 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11534 "Display route and more specific routes\n")
11535
Lou Berger651b4022016-01-12 13:42:07 -050011536DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11537 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11538 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11539 SHOW_STR
11540 BGP_STR
11541 "Address family\n"
11542 "Address Family modifier\n"
11543 "Address Family modifier\n"
11544 "Address Family modifier\n"
11545 "Address Family modifier\n"
11546 "Display flap statistics of routes\n"
11547 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11548 "Display route and more specific routes\n")
11549{
11550 safi_t safi;
11551
11552 if (bgp_parse_safi(argv[0], &safi)) {
11553 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11554 return CMD_WARNING;
11555 }
11556 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11557 bgp_show_type_flap_prefix_longer);
11558}
11559ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11560 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11561 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11562 SHOW_STR
11563 BGP_STR
11564 "Address family\n"
11565 "Address Family modifier\n"
11566 "Address Family modifier\n"
11567 "Address Family modifier\n"
11568 "Address Family modifier\n"
11569 "Display detailed information about dampening\n"
11570 "Display flap statistics of routes\n"
11571 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11572 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011573
11574DEFUN (show_bgp_ipv4_safi_prefix_longer,
11575 show_bgp_ipv4_safi_prefix_longer_cmd,
11576 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11577 SHOW_STR
11578 BGP_STR
11579 "Address family\n"
11580 "Address Family modifier\n"
11581 "Address Family modifier\n"
11582 "Address Family modifier\n"
11583 "Address Family modifier\n"
11584 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11585 "Display route and more specific routes\n")
11586{
11587 safi_t safi;
11588
11589 if (bgp_parse_safi(argv[0], &safi)) {
11590 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11591 return CMD_WARNING;
11592 }
11593
11594 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11595 bgp_show_type_prefix_longer);
11596}
11597
Lou Berger651b4022016-01-12 13:42:07 -050011598DEFUN (show_bgp_ipv6_safi_prefix_longer,
11599 show_bgp_ipv6_safi_prefix_longer_cmd,
11600 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11601 SHOW_STR
11602 BGP_STR
11603 "Address family\n"
11604 "Address Family modifier\n"
11605 "Address Family modifier\n"
11606 "Address Family modifier\n"
11607 "Address Family modifier\n"
11608 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11609 "Display route and more specific routes\n")
11610{
11611 safi_t safi;
11612
11613 if (bgp_parse_safi(argv[0], &safi)) {
11614 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11615 return CMD_WARNING;
11616 }
11617
11618 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11619 bgp_show_type_prefix_longer);
11620}
Lou Berger651b4022016-01-12 13:42:07 -050011621
11622DEFUN (show_bgp_ipv4_safi_flap_address,
11623 show_bgp_ipv4_safi_flap_address_cmd,
11624 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11625 SHOW_STR
11626 BGP_STR
11627 "Address family\n"
11628 "Address Family modifier\n"
11629 "Address Family modifier\n"
11630 "Address Family modifier\n"
11631 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011632 "Display flap statistics of routes\n"
11633 "Network in the BGP routing table to display\n")
11634{
Lou Berger651b4022016-01-12 13:42:07 -050011635 safi_t safi;
11636
11637 if (bgp_parse_safi(argv[0], &safi)) {
11638 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11639 return CMD_WARNING;
11640 }
11641 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011642 bgp_show_type_flap_address);
11643}
Lou Berger651b4022016-01-12 13:42:07 -050011644ALIAS (show_bgp_ipv4_safi_flap_address,
11645 show_bgp_ipv4_safi_damp_flap_address_cmd,
11646 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011647 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011648 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011649 "Address family\n"
11650 "Address Family modifier\n"
11651 "Address Family modifier\n"
11652 "Address Family modifier\n"
11653 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011654 "Display detailed information about dampening\n"
11655 "Display flap statistics of routes\n"
11656 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011657
Lou Berger651b4022016-01-12 13:42:07 -050011658DEFUN (show_bgp_ipv6_flap_address,
11659 show_bgp_ipv6_flap_address_cmd,
11660 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011661 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011662 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011663 "Address family\n"
11664 "Address Family modifier\n"
11665 "Address Family modifier\n"
11666 "Address Family modifier\n"
11667 "Address Family modifier\n"
11668 "Display flap statistics of routes\n"
11669 "Network in the BGP routing table to display\n")
11670{
11671 safi_t safi;
11672
11673 if (bgp_parse_safi(argv[0], &safi)) {
11674 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11675 return CMD_WARNING;
11676 }
11677 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11678 bgp_show_type_flap_address);
11679}
11680ALIAS (show_bgp_ipv6_flap_address,
11681 show_bgp_ipv6_damp_flap_address_cmd,
11682 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11683 SHOW_STR
11684 BGP_STR
11685 "Address family\n"
11686 "Address Family modifier\n"
11687 "Address Family modifier\n"
11688 "Address Family modifier\n"
11689 "Address Family modifier\n"
11690 "Display detailed information about dampening\n"
11691 "Display flap statistics of routes\n"
11692 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011693
11694DEFUN (show_bgp_ipv4_safi_flap_prefix,
11695 show_bgp_ipv4_safi_flap_prefix_cmd,
11696 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11697 SHOW_STR
11698 BGP_STR
11699 "Address family\n"
11700 "Address Family modifier\n"
11701 "Address Family modifier\n"
11702 "Address Family modifier\n"
11703 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011704 "Display flap statistics of routes\n"
11705 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11706{
Lou Berger651b4022016-01-12 13:42:07 -050011707 safi_t safi;
11708
11709 if (bgp_parse_safi(argv[0], &safi)) {
11710 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11711 return CMD_WARNING;
11712 }
11713 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011714 bgp_show_type_flap_prefix);
11715}
Balaji3921cc52015-05-16 23:12:17 +053011716
Lou Berger651b4022016-01-12 13:42:07 -050011717ALIAS (show_bgp_ipv4_safi_flap_prefix,
11718 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11719 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011720 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011721 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011722 "Address family\n"
11723 "Address Family modifier\n"
11724 "Address Family modifier\n"
11725 "Address Family modifier\n"
11726 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011727 "Display detailed information about dampening\n"
11728 "Display flap statistics of routes\n"
11729 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11730
Lou Berger651b4022016-01-12 13:42:07 -050011731DEFUN (show_bgp_ipv6_safi_flap_prefix,
11732 show_bgp_ipv6_safi_flap_prefix_cmd,
11733 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011734 SHOW_STR
11735 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011736 "Address family\n"
11737 "Address Family modifier\n"
11738 "Address Family modifier\n"
11739 "Address Family modifier\n"
11740 "Address Family modifier\n"
11741 "Display flap statistics of routes\n"
11742 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011743{
Lou Berger651b4022016-01-12 13:42:07 -050011744 safi_t safi;
11745
11746 if (bgp_parse_safi(argv[0], &safi)) {
11747 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11748 return CMD_WARNING;
11749 }
11750 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11751 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011752}
11753
Lou Berger651b4022016-01-12 13:42:07 -050011754ALIAS (show_bgp_ipv6_safi_flap_prefix,
11755 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11756 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11757 SHOW_STR
11758 BGP_STR
11759 "Address family\n"
11760 "Address Family modifier\n"
11761 "Address Family modifier\n"
11762 "Address Family modifier\n"
11763 "Address Family modifier\n"
11764 "Display detailed information about dampening\n"
11765 "Display flap statistics of routes\n"
11766 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11767
11768DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011769 show_bgp_ipv6_prefix_longer_cmd,
11770 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11771 SHOW_STR
11772 BGP_STR
11773 "Address family\n"
11774 "IPv6 prefix <network>/<length>\n"
11775 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011776{
11777 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11778 bgp_show_type_prefix_longer);
11779}
11780
paul94f2b392005-06-28 12:44:16 +000011781static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011782peer_lookup_in_view (struct vty *vty, const char *view_name,
11783 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011784{
11785 int ret;
11786 struct bgp *bgp;
11787 struct peer *peer;
11788 union sockunion su;
11789
11790 /* BGP structure lookup. */
11791 if (view_name)
11792 {
11793 bgp = bgp_lookup_by_name (view_name);
11794 if (! bgp)
11795 {
11796 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11797 return NULL;
11798 }
11799 }
paul5228ad22004-06-04 17:58:18 +000011800 else
paulbb46e942003-10-24 19:02:03 +000011801 {
11802 bgp = bgp_get_default ();
11803 if (! bgp)
11804 {
11805 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11806 return NULL;
11807 }
11808 }
11809
11810 /* Get peer sockunion. */
11811 ret = str2sockunion (ip_str, &su);
11812 if (ret < 0)
11813 {
11814 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11815 return NULL;
11816 }
11817
11818 /* Peer structure lookup. */
11819 peer = peer_lookup (bgp, &su);
11820 if (! peer)
11821 {
11822 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11823 return NULL;
11824 }
11825
11826 return peer;
11827}
David Lamparter6b0655a2014-06-04 06:53:35 +020011828
Paul Jakma2815e612006-09-14 02:56:07 +000011829enum bgp_stats
11830{
11831 BGP_STATS_MAXBITLEN = 0,
11832 BGP_STATS_RIB,
11833 BGP_STATS_PREFIXES,
11834 BGP_STATS_TOTPLEN,
11835 BGP_STATS_UNAGGREGATEABLE,
11836 BGP_STATS_MAX_AGGREGATEABLE,
11837 BGP_STATS_AGGREGATES,
11838 BGP_STATS_SPACE,
11839 BGP_STATS_ASPATH_COUNT,
11840 BGP_STATS_ASPATH_MAXHOPS,
11841 BGP_STATS_ASPATH_TOTHOPS,
11842 BGP_STATS_ASPATH_MAXSIZE,
11843 BGP_STATS_ASPATH_TOTSIZE,
11844 BGP_STATS_ASN_HIGHEST,
11845 BGP_STATS_MAX,
11846};
paulbb46e942003-10-24 19:02:03 +000011847
Paul Jakma2815e612006-09-14 02:56:07 +000011848static const char *table_stats_strs[] =
11849{
11850 [BGP_STATS_PREFIXES] = "Total Prefixes",
11851 [BGP_STATS_TOTPLEN] = "Average prefix length",
11852 [BGP_STATS_RIB] = "Total Advertisements",
11853 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11854 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11855 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11856 [BGP_STATS_SPACE] = "Address space advertised",
11857 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11858 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11859 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11860 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11861 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11862 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11863 [BGP_STATS_MAX] = NULL,
11864};
11865
11866struct bgp_table_stats
11867{
11868 struct bgp_table *table;
11869 unsigned long long counts[BGP_STATS_MAX];
11870};
11871
11872#if 0
11873#define TALLY_SIGFIG 100000
11874static unsigned long
11875ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11876{
11877 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11878 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11879 unsigned long ret = newtot / count;
11880
11881 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11882 return ret + 1;
11883 else
11884 return ret;
11885}
11886#endif
11887
11888static int
11889bgp_table_stats_walker (struct thread *t)
11890{
11891 struct bgp_node *rn;
11892 struct bgp_node *top;
11893 struct bgp_table_stats *ts = THREAD_ARG (t);
11894 unsigned int space = 0;
11895
Paul Jakma53d9f672006-10-15 23:41:16 +000011896 if (!(top = bgp_table_top (ts->table)))
11897 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011898
11899 switch (top->p.family)
11900 {
11901 case AF_INET:
11902 space = IPV4_MAX_BITLEN;
11903 break;
11904 case AF_INET6:
11905 space = IPV6_MAX_BITLEN;
11906 break;
11907 }
11908
11909 ts->counts[BGP_STATS_MAXBITLEN] = space;
11910
11911 for (rn = top; rn; rn = bgp_route_next (rn))
11912 {
11913 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011914 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011915 unsigned int rinum = 0;
11916
11917 if (rn == top)
11918 continue;
11919
11920 if (!rn->info)
11921 continue;
11922
11923 ts->counts[BGP_STATS_PREFIXES]++;
11924 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11925
11926#if 0
11927 ts->counts[BGP_STATS_AVGPLEN]
11928 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11929 ts->counts[BGP_STATS_AVGPLEN],
11930 rn->p.prefixlen);
11931#endif
11932
11933 /* check if the prefix is included by any other announcements */
11934 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011935 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011936
11937 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011938 {
11939 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11940 /* announced address space */
11941 if (space)
11942 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11943 }
Paul Jakma2815e612006-09-14 02:56:07 +000011944 else if (prn->info)
11945 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11946
Paul Jakma2815e612006-09-14 02:56:07 +000011947 for (ri = rn->info; ri; ri = ri->next)
11948 {
11949 rinum++;
11950 ts->counts[BGP_STATS_RIB]++;
11951
11952 if (ri->attr &&
11953 (CHECK_FLAG (ri->attr->flag,
11954 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11955 ts->counts[BGP_STATS_AGGREGATES]++;
11956
11957 /* as-path stats */
11958 if (ri->attr && ri->attr->aspath)
11959 {
11960 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11961 unsigned int size = aspath_size (ri->attr->aspath);
11962 as_t highest = aspath_highest (ri->attr->aspath);
11963
11964 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11965
11966 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11967 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11968
11969 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11970 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11971
11972 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11973 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11974#if 0
11975 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11976 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11977 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11978 hops);
11979 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11980 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11981 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11982 size);
11983#endif
11984 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11985 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11986 }
11987 }
11988 }
11989 return 0;
11990}
11991
11992static int
11993bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11994{
11995 struct bgp_table_stats ts;
11996 unsigned int i;
11997
11998 if (!bgp->rib[afi][safi])
11999 {
Donald Sharp3c964042016-01-25 23:38:53 -050012000 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
12001 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012002 return CMD_WARNING;
12003 }
12004
12005 memset (&ts, 0, sizeof (ts));
12006 ts.table = bgp->rib[afi][safi];
12007 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12008
12009 vty_out (vty, "BGP %s RIB statistics%s%s",
12010 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12011
12012 for (i = 0; i < BGP_STATS_MAX; i++)
12013 {
12014 if (!table_stats_strs[i])
12015 continue;
12016
12017 switch (i)
12018 {
12019#if 0
12020 case BGP_STATS_ASPATH_AVGHOPS:
12021 case BGP_STATS_ASPATH_AVGSIZE:
12022 case BGP_STATS_AVGPLEN:
12023 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12024 vty_out (vty, "%12.2f",
12025 (float)ts.counts[i] / (float)TALLY_SIGFIG);
12026 break;
12027#endif
12028 case BGP_STATS_ASPATH_TOTHOPS:
12029 case BGP_STATS_ASPATH_TOTSIZE:
12030 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12031 vty_out (vty, "%12.2f",
12032 ts.counts[i] ?
12033 (float)ts.counts[i] /
12034 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
12035 : 0);
12036 break;
12037 case BGP_STATS_TOTPLEN:
12038 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12039 vty_out (vty, "%12.2f",
12040 ts.counts[i] ?
12041 (float)ts.counts[i] /
12042 (float)ts.counts[BGP_STATS_PREFIXES]
12043 : 0);
12044 break;
12045 case BGP_STATS_SPACE:
12046 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12047 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
12048 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
12049 break;
Paul Jakma30a22312008-08-15 14:05:22 +010012050 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000012051 vty_out (vty, "%12.2f%s",
12052 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000012053 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000012054 VTY_NEWLINE);
12055 vty_out (vty, "%30s: ", "/8 equivalent ");
12056 vty_out (vty, "%12.2f%s",
12057 (float)ts.counts[BGP_STATS_SPACE] /
12058 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
12059 VTY_NEWLINE);
12060 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
12061 break;
12062 vty_out (vty, "%30s: ", "/24 equivalent ");
12063 vty_out (vty, "%12.2f",
12064 (float)ts.counts[BGP_STATS_SPACE] /
12065 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
12066 break;
12067 default:
12068 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12069 vty_out (vty, "%12llu", ts.counts[i]);
12070 }
12071
12072 vty_out (vty, "%s", VTY_NEWLINE);
12073 }
12074 return CMD_SUCCESS;
12075}
12076
12077static int
12078bgp_table_stats_vty (struct vty *vty, const char *name,
12079 const char *afi_str, const char *safi_str)
12080{
12081 struct bgp *bgp;
12082 afi_t afi;
12083 safi_t safi;
12084
12085 if (name)
12086 bgp = bgp_lookup_by_name (name);
12087 else
12088 bgp = bgp_get_default ();
12089
12090 if (!bgp)
12091 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012092 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012093 return CMD_WARNING;
12094 }
12095 if (strncmp (afi_str, "ipv", 3) == 0)
12096 {
12097 if (strncmp (afi_str, "ipv4", 4) == 0)
12098 afi = AFI_IP;
12099 else if (strncmp (afi_str, "ipv6", 4) == 0)
12100 afi = AFI_IP6;
12101 else
12102 {
12103 vty_out (vty, "%% Invalid address family %s%s",
12104 afi_str, VTY_NEWLINE);
12105 return CMD_WARNING;
12106 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012107 switch (safi_str[0]) {
12108 case 'm':
12109 safi = SAFI_MULTICAST;
12110 break;
12111 case 'u':
12112 safi = SAFI_UNICAST;
12113 break;
12114 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050012115 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050012116 break;
12117 case 'e':
12118 safi = SAFI_ENCAP;
12119 break;
12120 default:
12121 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012122 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012123 return CMD_WARNING;
12124 }
Paul Jakma2815e612006-09-14 02:56:07 +000012125 }
12126 else
12127 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012128 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012129 afi_str, VTY_NEWLINE);
12130 return CMD_WARNING;
12131 }
12132
Paul Jakma2815e612006-09-14 02:56:07 +000012133 return bgp_table_stats (vty, bgp, afi, safi);
12134}
12135
12136DEFUN (show_bgp_statistics,
12137 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012138 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012139 SHOW_STR
12140 BGP_STR
12141 "Address family\n"
12142 "Address family\n"
12143 "Address Family modifier\n"
12144 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012145 "Address Family modifier\n"
12146 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012147 "BGP RIB advertisement statistics\n")
12148{
12149 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12150}
12151
Lou Bergerf9b6c392016-01-12 13:42:09 -050012152ALIAS (show_bgp_statistics,
12153 show_bgp_statistics_vpnv4_cmd,
12154 "show bgp (ipv4) (vpnv4) statistics",
12155 SHOW_STR
12156 BGP_STR
12157 "Address family\n"
12158 "Address Family modifier\n"
12159 "BGP RIB advertisement statistics\n")
12160
Paul Jakma2815e612006-09-14 02:56:07 +000012161DEFUN (show_bgp_statistics_view,
12162 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012163 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012164 SHOW_STR
12165 BGP_STR
12166 "BGP view\n"
12167 "Address family\n"
12168 "Address family\n"
12169 "Address Family modifier\n"
12170 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012171 "Address Family modifier\n"
12172 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012173 "BGP RIB advertisement statistics\n")
12174{
12175 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12176}
12177
12178ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012179 show_bgp_statistics_view_vpnv4_cmd,
12180 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012181 SHOW_STR
12182 BGP_STR
12183 "BGP view\n"
12184 "Address family\n"
12185 "Address Family modifier\n"
12186 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012187
Paul Jakmaff7924f2006-09-04 01:10:36 +000012188enum bgp_pcounts
12189{
12190 PCOUNT_ADJ_IN = 0,
12191 PCOUNT_DAMPED,
12192 PCOUNT_REMOVED,
12193 PCOUNT_HISTORY,
12194 PCOUNT_STALE,
12195 PCOUNT_VALID,
12196 PCOUNT_ALL,
12197 PCOUNT_COUNTED,
12198 PCOUNT_PFCNT, /* the figure we display to users */
12199 PCOUNT_MAX,
12200};
12201
12202static const char *pcount_strs[] =
12203{
12204 [PCOUNT_ADJ_IN] = "Adj-in",
12205 [PCOUNT_DAMPED] = "Damped",
12206 [PCOUNT_REMOVED] = "Removed",
12207 [PCOUNT_HISTORY] = "History",
12208 [PCOUNT_STALE] = "Stale",
12209 [PCOUNT_VALID] = "Valid",
12210 [PCOUNT_ALL] = "All RIB",
12211 [PCOUNT_COUNTED] = "PfxCt counted",
12212 [PCOUNT_PFCNT] = "Useable",
12213 [PCOUNT_MAX] = NULL,
12214};
12215
Paul Jakma2815e612006-09-14 02:56:07 +000012216struct peer_pcounts
12217{
12218 unsigned int count[PCOUNT_MAX];
12219 const struct peer *peer;
12220 const struct bgp_table *table;
12221};
12222
Paul Jakmaff7924f2006-09-04 01:10:36 +000012223static int
Paul Jakma2815e612006-09-14 02:56:07 +000012224bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012225{
12226 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012227 struct peer_pcounts *pc = THREAD_ARG (t);
12228 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012229
Paul Jakma2815e612006-09-14 02:56:07 +000012230 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012231 {
12232 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012233 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012234
12235 for (ain = rn->adj_in; ain; ain = ain->next)
12236 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012237 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012238
Paul Jakmaff7924f2006-09-04 01:10:36 +000012239 for (ri = rn->info; ri; ri = ri->next)
12240 {
12241 char buf[SU_ADDRSTRLEN];
12242
12243 if (ri->peer != peer)
12244 continue;
12245
Paul Jakma2815e612006-09-14 02:56:07 +000012246 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012247
12248 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012249 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012250 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012251 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012252 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012253 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012254 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012255 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012256 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012257 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012258 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012259 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012260
12261 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12262 {
Paul Jakma2815e612006-09-14 02:56:07 +000012263 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012264 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012265 plog_warn (peer->log,
12266 "%s [pcount] %s/%d is counted but flags 0x%x",
12267 peer->host,
12268 inet_ntop(rn->p.family, &rn->p.u.prefix,
12269 buf, SU_ADDRSTRLEN),
12270 rn->p.prefixlen,
12271 ri->flags);
12272 }
12273 else
12274 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012275 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012276 plog_warn (peer->log,
12277 "%s [pcount] %s/%d not counted but flags 0x%x",
12278 peer->host,
12279 inet_ntop(rn->p.family, &rn->p.u.prefix,
12280 buf, SU_ADDRSTRLEN),
12281 rn->p.prefixlen,
12282 ri->flags);
12283 }
12284 }
12285 }
Paul Jakma2815e612006-09-14 02:56:07 +000012286 return 0;
12287}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012288
Paul Jakma2815e612006-09-14 02:56:07 +000012289static int
12290bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12291{
12292 struct peer_pcounts pcounts = { .peer = peer };
12293 unsigned int i;
12294
12295 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12296 || !peer->bgp->rib[afi][safi])
12297 {
12298 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12299 return CMD_WARNING;
12300 }
12301
12302 memset (&pcounts, 0, sizeof(pcounts));
12303 pcounts.peer = peer;
12304 pcounts.table = peer->bgp->rib[afi][safi];
12305
12306 /* in-place call via thread subsystem so as to record execution time
12307 * stats for the thread-walk (i.e. ensure this can't be blamed on
12308 * on just vty_read()).
12309 */
12310 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12311
Paul Jakmaff7924f2006-09-04 01:10:36 +000012312 vty_out (vty, "Prefix counts for %s, %s%s",
12313 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12314 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12315 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12316 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12317
12318 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012319 vty_out (vty, "%20s: %-10d%s",
12320 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012321
Paul Jakma2815e612006-09-14 02:56:07 +000012322 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012323 {
12324 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12325 peer->host, VTY_NEWLINE);
12326 vty_out (vty, "Please report this bug, with the above command output%s",
12327 VTY_NEWLINE);
12328 }
12329
12330 return CMD_SUCCESS;
12331}
12332
Lou Bergerf9b6c392016-01-12 13:42:09 -050012333DEFUN (show_ip_bgp_neighbor_prefix_counts,
12334 show_ip_bgp_neighbor_prefix_counts_cmd,
12335 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12336 SHOW_STR
12337 IP_STR
12338 BGP_STR
12339 "Detailed information on TCP and BGP neighbor connections\n"
12340 "Neighbor to display information about\n"
12341 "Neighbor to display information about\n"
12342 "Display detailed prefix count information\n")
12343{
12344 struct peer *peer;
12345
12346 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12347 if (! peer)
12348 return CMD_WARNING;
12349
12350 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12351}
12352
Paul Jakmaff7924f2006-09-04 01:10:36 +000012353DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12354 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12355 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12356 SHOW_STR
12357 BGP_STR
12358 "Address family\n"
12359 "Detailed information on TCP and BGP neighbor connections\n"
12360 "Neighbor to display information about\n"
12361 "Neighbor to display information about\n"
12362 "Display detailed prefix count information\n")
12363{
12364 struct peer *peer;
12365
12366 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12367 if (! peer)
12368 return CMD_WARNING;
12369
12370 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12371}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012372
12373DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12374 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12375 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12376 SHOW_STR
12377 IP_STR
12378 BGP_STR
12379 "Address family\n"
12380 "Address Family modifier\n"
12381 "Address Family modifier\n"
12382 "Detailed information on TCP and BGP neighbor connections\n"
12383 "Neighbor to display information about\n"
12384 "Neighbor to display information about\n"
12385 "Display detailed prefix count information\n")
12386{
12387 struct peer *peer;
12388
12389 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12390 if (! peer)
12391 return CMD_WARNING;
12392
12393 if (strncmp (argv[0], "m", 1) == 0)
12394 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12395
12396 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12397}
12398
12399DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12400 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12401 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12402 SHOW_STR
12403 IP_STR
12404 BGP_STR
12405 "Address family\n"
12406 "Address Family modifier\n"
12407 "Address Family modifier\n"
12408 "Detailed information on TCP and BGP neighbor connections\n"
12409 "Neighbor to display information about\n"
12410 "Neighbor to display information about\n"
12411 "Display detailed prefix count information\n")
12412{
12413 struct peer *peer;
12414
12415 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12416 if (! peer)
12417 return CMD_WARNING;
12418
12419 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12420}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012421
Lou Berger651b4022016-01-12 13:42:07 -050012422DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12423 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12424 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012425 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012426 BGP_STR
12427 "Address family\n"
12428 "Address Family modifier\n"
12429 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012430 "Address Family modifier\n"
12431 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012432 "Detailed information on TCP and BGP neighbor connections\n"
12433 "Neighbor to display information about\n"
12434 "Neighbor to display information about\n"
12435 "Display detailed prefix count information\n")
12436{
12437 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012438 safi_t safi;
12439
12440 if (bgp_parse_safi(argv[0], &safi)) {
12441 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12442 return CMD_WARNING;
12443 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012444
12445 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12446 if (! peer)
12447 return CMD_WARNING;
12448
Lou Berger651b4022016-01-12 13:42:07 -050012449 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012450}
Lou Berger205e6742016-01-12 13:42:11 -050012451
Lou Berger651b4022016-01-12 13:42:07 -050012452DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12453 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12454 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12455 SHOW_STR
12456 BGP_STR
12457 "Address family\n"
12458 "Address Family modifier\n"
12459 "Address Family modifier\n"
12460 "Address Family modifier\n"
12461 "Address Family modifier\n"
12462 "Detailed information on TCP and BGP neighbor connections\n"
12463 "Neighbor to display information about\n"
12464 "Neighbor to display information about\n"
12465 "Display detailed prefix count information\n")
12466{
12467 struct peer *peer;
12468 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012469
Lou Berger651b4022016-01-12 13:42:07 -050012470 if (bgp_parse_safi(argv[0], &safi)) {
12471 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12472 return CMD_WARNING;
12473 }
12474
12475 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12476 if (! peer)
12477 return CMD_WARNING;
12478
12479 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12480}
Lou Berger651b4022016-01-12 13:42:07 -050012481
12482DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12483 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12484 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012485 SHOW_STR
12486 IP_STR
12487 BGP_STR
12488 "Address family\n"
12489 "Address Family modifier\n"
12490 "Address Family modifier\n"
12491 "Detailed information on TCP and BGP neighbor connections\n"
12492 "Neighbor to display information about\n"
12493 "Neighbor to display information about\n"
12494 "Display detailed prefix count information\n")
12495{
12496 struct peer *peer;
12497
12498 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12499 if (! peer)
12500 return CMD_WARNING;
12501
Lou Berger651b4022016-01-12 13:42:07 -050012502 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012503}
12504
12505
paul94f2b392005-06-28 12:44:16 +000012506static void
paul718e3742002-12-13 20:15:29 +000012507show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12508 int in)
12509{
12510 struct bgp_table *table;
12511 struct bgp_adj_in *ain;
12512 struct bgp_adj_out *adj;
12513 unsigned long output_count;
12514 struct bgp_node *rn;
12515 int header1 = 1;
12516 struct bgp *bgp;
12517 int header2 = 1;
12518
paulbb46e942003-10-24 19:02:03 +000012519 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012520
12521 if (! bgp)
12522 return;
12523
12524 table = bgp->rib[afi][safi];
12525
12526 output_count = 0;
12527
12528 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12529 PEER_STATUS_DEFAULT_ORIGINATE))
12530 {
12531 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 +000012532 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12533 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012534
12535 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12536 VTY_NEWLINE, VTY_NEWLINE);
12537 header1 = 0;
12538 }
12539
12540 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12541 if (in)
12542 {
12543 for (ain = rn->adj_in; ain; ain = ain->next)
12544 if (ain->peer == peer)
12545 {
12546 if (header1)
12547 {
12548 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 +000012549 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12550 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012551 header1 = 0;
12552 }
12553 if (header2)
12554 {
12555 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12556 header2 = 0;
12557 }
12558 if (ain->attr)
12559 {
12560 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12561 output_count++;
12562 }
12563 }
12564 }
12565 else
12566 {
12567 for (adj = rn->adj_out; adj; adj = adj->next)
12568 if (adj->peer == peer)
12569 {
12570 if (header1)
12571 {
12572 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 +000012573 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12574 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012575 header1 = 0;
12576 }
12577 if (header2)
12578 {
12579 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12580 header2 = 0;
12581 }
12582 if (adj->attr)
12583 {
12584 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12585 output_count++;
12586 }
12587 }
12588 }
12589
12590 if (output_count != 0)
12591 vty_out (vty, "%sTotal number of prefixes %ld%s",
12592 VTY_NEWLINE, output_count, VTY_NEWLINE);
12593}
12594
paul94f2b392005-06-28 12:44:16 +000012595static int
paulbb46e942003-10-24 19:02:03 +000012596peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12597{
paul718e3742002-12-13 20:15:29 +000012598 if (! peer || ! peer->afc[afi][safi])
12599 {
12600 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12601 return CMD_WARNING;
12602 }
12603
12604 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12605 {
12606 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12607 VTY_NEWLINE);
12608 return CMD_WARNING;
12609 }
12610
12611 show_adj_route (vty, peer, afi, safi, in);
12612
12613 return CMD_SUCCESS;
12614}
12615
Lou Bergerf9b6c392016-01-12 13:42:09 -050012616DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12617 show_ip_bgp_view_neighbor_advertised_route_cmd,
12618 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12619 SHOW_STR
12620 IP_STR
12621 BGP_STR
12622 "BGP view\n"
12623 "View name\n"
12624 "Detailed information on TCP and BGP neighbor connections\n"
12625 "Neighbor to display information about\n"
12626 "Neighbor to display information about\n"
12627 "Display the routes advertised to a BGP neighbor\n")
12628{
12629 struct peer *peer;
12630
12631 if (argc == 2)
12632 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12633 else
12634 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12635
12636 if (! peer)
12637 return CMD_WARNING;
12638
12639 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12640}
12641
12642ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12643 show_ip_bgp_neighbor_advertised_route_cmd,
12644 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12645 SHOW_STR
12646 IP_STR
12647 BGP_STR
12648 "Detailed information on TCP and BGP neighbor connections\n"
12649 "Neighbor to display information about\n"
12650 "Neighbor to display information about\n"
12651 "Display the routes advertised to a BGP neighbor\n")
12652
12653DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12654 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12655 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12656 SHOW_STR
12657 IP_STR
12658 BGP_STR
12659 "Address family\n"
12660 "Address Family modifier\n"
12661 "Address Family modifier\n"
12662 "Detailed information on TCP and BGP neighbor connections\n"
12663 "Neighbor to display information about\n"
12664 "Neighbor to display information about\n"
12665 "Display the routes advertised to a BGP neighbor\n")
12666{
12667 struct peer *peer;
12668
12669 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12670 if (! peer)
12671 return CMD_WARNING;
12672
12673 if (strncmp (argv[0], "m", 1) == 0)
12674 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12675
12676 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12677}
12678
Lou Bergerf9b6c392016-01-12 13:42:09 -050012679DEFUN (show_bgp_view_neighbor_advertised_route,
12680 show_bgp_view_neighbor_advertised_route_cmd,
12681 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12682 SHOW_STR
12683 BGP_STR
12684 "BGP view\n"
12685 "View name\n"
12686 "Detailed information on TCP and BGP neighbor connections\n"
12687 "Neighbor to display information about\n"
12688 "Neighbor to display information about\n"
12689 "Display the routes advertised to a BGP neighbor\n")
12690{
12691 struct peer *peer;
12692
12693 if (argc == 2)
12694 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12695 else
12696 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12697
12698 if (! peer)
12699 return CMD_WARNING;
12700
12701 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12702}
12703
12704DEFUN (show_bgp_view_neighbor_received_routes,
12705 show_bgp_view_neighbor_received_routes_cmd,
12706 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12707 SHOW_STR
12708 BGP_STR
12709 "BGP view\n"
12710 "View name\n"
12711 "Detailed information on TCP and BGP neighbor connections\n"
12712 "Neighbor to display information about\n"
12713 "Neighbor to display information about\n"
12714 "Display the received routes from neighbor\n")
12715{
12716 struct peer *peer;
12717
12718 if (argc == 2)
12719 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12720 else
12721 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12722
12723 if (! peer)
12724 return CMD_WARNING;
12725
12726 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12727}
12728
12729ALIAS (show_bgp_view_neighbor_advertised_route,
12730 show_bgp_neighbor_advertised_route_cmd,
12731 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12732 SHOW_STR
12733 BGP_STR
12734 "Detailed information on TCP and BGP neighbor connections\n"
12735 "Neighbor to display information about\n"
12736 "Neighbor to display information about\n"
12737 "Display the routes advertised to a BGP neighbor\n")
12738
12739ALIAS (show_bgp_view_neighbor_advertised_route,
12740 show_bgp_ipv6_neighbor_advertised_route_cmd,
12741 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12742 SHOW_STR
12743 BGP_STR
12744 "Address family\n"
12745 "Detailed information on TCP and BGP neighbor connections\n"
12746 "Neighbor to display information about\n"
12747 "Neighbor to display information about\n"
12748 "Display the routes advertised to a BGP neighbor\n")
12749
12750/* old command */
12751ALIAS (show_bgp_view_neighbor_advertised_route,
12752 ipv6_bgp_neighbor_advertised_route_cmd,
12753 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12754 SHOW_STR
12755 IPV6_STR
12756 BGP_STR
12757 "Detailed information on TCP and BGP neighbor connections\n"
12758 "Neighbor to display information about\n"
12759 "Neighbor to display information about\n"
12760 "Display the routes advertised to a BGP neighbor\n")
12761
12762/* old command */
12763DEFUN (ipv6_mbgp_neighbor_advertised_route,
12764 ipv6_mbgp_neighbor_advertised_route_cmd,
12765 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12766 SHOW_STR
12767 IPV6_STR
12768 MBGP_STR
12769 "Detailed information on TCP and BGP neighbor connections\n"
12770 "Neighbor to display information about\n"
12771 "Neighbor to display information about\n"
12772 "Display the routes advertised to a BGP neighbor\n")
12773{
12774 struct peer *peer;
12775
12776 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12777 if (! peer)
12778 return CMD_WARNING;
12779
12780 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12781}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012782
12783DEFUN (show_ip_bgp_view_neighbor_received_routes,
12784 show_ip_bgp_view_neighbor_received_routes_cmd,
12785 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12786 SHOW_STR
12787 IP_STR
12788 BGP_STR
12789 "BGP view\n"
12790 "View name\n"
12791 "Detailed information on TCP and BGP neighbor connections\n"
12792 "Neighbor to display information about\n"
12793 "Neighbor to display information about\n"
12794 "Display the received routes from neighbor\n")
12795{
12796 struct peer *peer;
12797
12798 if (argc == 2)
12799 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12800 else
12801 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12802
12803 if (! peer)
12804 return CMD_WARNING;
12805
12806 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12807}
12808
12809ALIAS (show_ip_bgp_view_neighbor_received_routes,
12810 show_ip_bgp_neighbor_received_routes_cmd,
12811 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12812 SHOW_STR
12813 IP_STR
12814 BGP_STR
12815 "Detailed information on TCP and BGP neighbor connections\n"
12816 "Neighbor to display information about\n"
12817 "Neighbor to display information about\n"
12818 "Display the received routes from neighbor\n")
12819
12820ALIAS (show_bgp_view_neighbor_received_routes,
12821 show_bgp_ipv6_neighbor_received_routes_cmd,
12822 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12823 SHOW_STR
12824 BGP_STR
12825 "Address family\n"
12826 "Detailed information on TCP and BGP neighbor connections\n"
12827 "Neighbor to display information about\n"
12828 "Neighbor to display information about\n"
12829 "Display the received routes from neighbor\n")
12830
12831DEFUN (show_bgp_neighbor_received_prefix_filter,
12832 show_bgp_neighbor_received_prefix_filter_cmd,
12833 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12834 SHOW_STR
12835 BGP_STR
12836 "Detailed information on TCP and BGP neighbor connections\n"
12837 "Neighbor to display information about\n"
12838 "Neighbor to display information about\n"
12839 "Display information received from a BGP neighbor\n"
12840 "Display the prefixlist filter\n")
12841{
12842 char name[BUFSIZ];
12843 union sockunion su;
12844 struct peer *peer;
12845 int count, ret;
12846
12847 ret = str2sockunion (argv[0], &su);
12848 if (ret < 0)
12849 {
12850 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12851 return CMD_WARNING;
12852 }
12853
12854 peer = peer_lookup (NULL, &su);
12855 if (! peer)
12856 return CMD_WARNING;
12857
12858 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12859 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12860 if (count)
12861 {
12862 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12863 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12864 }
12865
12866 return CMD_SUCCESS;
12867}
12868
12869/* old command */
12870ALIAS (show_bgp_view_neighbor_received_routes,
12871 ipv6_bgp_neighbor_received_routes_cmd,
12872 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12873 SHOW_STR
12874 IPV6_STR
12875 BGP_STR
12876 "Detailed information on TCP and BGP neighbor connections\n"
12877 "Neighbor to display information about\n"
12878 "Neighbor to display information about\n"
12879 "Display the received routes from neighbor\n")
12880
12881/* old command */
12882DEFUN (ipv6_mbgp_neighbor_received_routes,
12883 ipv6_mbgp_neighbor_received_routes_cmd,
12884 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12885 SHOW_STR
12886 IPV6_STR
12887 MBGP_STR
12888 "Detailed information on TCP and BGP neighbor connections\n"
12889 "Neighbor to display information about\n"
12890 "Neighbor to display information about\n"
12891 "Display the received routes from neighbor\n")
12892{
12893 struct peer *peer;
12894
12895 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12896 if (! peer)
12897 return CMD_WARNING;
12898
12899 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12900}
12901
12902DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12903 show_bgp_view_neighbor_received_prefix_filter_cmd,
12904 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12905 SHOW_STR
12906 BGP_STR
12907 "BGP view\n"
12908 "View name\n"
12909 "Detailed information on TCP and BGP neighbor connections\n"
12910 "Neighbor to display information about\n"
12911 "Neighbor to display information about\n"
12912 "Display information received from a BGP neighbor\n"
12913 "Display the prefixlist filter\n")
12914{
12915 char name[BUFSIZ];
12916 union sockunion su;
12917 struct peer *peer;
12918 struct bgp *bgp;
12919 int count, ret;
12920
12921 /* BGP structure lookup. */
12922 bgp = bgp_lookup_by_name (argv[0]);
12923 if (bgp == NULL)
12924 {
12925 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12926 return CMD_WARNING;
12927 }
12928
12929 ret = str2sockunion (argv[1], &su);
12930 if (ret < 0)
12931 {
12932 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12933 return CMD_WARNING;
12934 }
12935
12936 peer = peer_lookup (bgp, &su);
12937 if (! peer)
12938 return CMD_WARNING;
12939
12940 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12941 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12942 if (count)
12943 {
12944 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12945 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12946 }
12947
12948 return CMD_SUCCESS;
12949}
12950
12951
12952DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12953 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12954 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12955 SHOW_STR
12956 IP_STR
12957 BGP_STR
12958 "Address family\n"
12959 "Address Family modifier\n"
12960 "Address Family modifier\n"
12961 "Detailed information on TCP and BGP neighbor connections\n"
12962 "Neighbor to display information about\n"
12963 "Neighbor to display information about\n"
12964 "Display the received routes from neighbor\n")
12965{
12966 struct peer *peer;
12967
12968 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12969 if (! peer)
12970 return CMD_WARNING;
12971
12972 if (strncmp (argv[0], "m", 1) == 0)
12973 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12974
12975 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12976}
12977
Lou Berger651b4022016-01-12 13:42:07 -050012978DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12979 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12980 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012981 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012982 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012983 "Address Family modifier\n"
12984 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012985 "Detailed information on TCP and BGP neighbor connections\n"
12986 "Neighbor to display information about\n"
12987 "Neighbor to display information about\n"
12988 "Display the routes advertised to a BGP neighbor\n")
12989{
12990 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012991 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012992
Lou Berger651b4022016-01-12 13:42:07 -050012993 if (bgp_parse_safi(argv[0], &safi)) {
12994 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012995 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050012996 }
paul718e3742002-12-13 20:15:29 +000012997
paulbb46e942003-10-24 19:02:03 +000012998 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12999 if (! peer)
13000 return CMD_WARNING;
13001
Lou Berger651b4022016-01-12 13:42:07 -050013002 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13003}
Lou Berger205e6742016-01-12 13:42:11 -050013004
Lou Berger651b4022016-01-12 13:42:07 -050013005DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13006 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13007 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13008 SHOW_STR
13009 BGP_STR
13010 "Address Family modifier\n"
13011 "Address Family modifier\n"
13012 "Address Family modifier\n"
13013 "Detailed information on TCP and BGP neighbor connections\n"
13014 "Neighbor to display information about\n"
13015 "Neighbor to display information about\n"
13016 "Display the routes advertised to a BGP neighbor\n")
13017{
13018 struct peer *peer;
13019 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013020
Lou Berger651b4022016-01-12 13:42:07 -050013021 if (bgp_parse_safi(argv[0], &safi)) {
13022 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13023 return CMD_WARNING;
13024 }
13025
13026 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13027 if (! peer)
13028 return CMD_WARNING;
13029
13030 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000013031}
13032
Lou Bergerf9b6c392016-01-12 13:42:09 -050013033DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050013034 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
13035 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000013036 SHOW_STR
13037 BGP_STR
13038 "BGP view\n"
13039 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013040 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013041 "Detailed information on TCP and BGP neighbor connections\n"
13042 "Neighbor to display information about\n"
13043 "Neighbor to display information about\n"
13044 "Display the routes advertised to a BGP neighbor\n")
13045{
13046 struct peer *peer;
13047
13048 if (argc == 2)
13049 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13050 else
13051 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13052
13053 if (! peer)
13054 return CMD_WARNING;
13055
13056 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13057}
13058
Lou Bergerf9b6c392016-01-12 13:42:09 -050013059DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013060 show_bgp_view_ipv6_neighbor_received_routes_cmd,
13061 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000013062 SHOW_STR
13063 BGP_STR
13064 "BGP view\n"
13065 "View name\n"
13066 "Address family\n"
13067 "Detailed information on TCP and BGP neighbor connections\n"
13068 "Neighbor to display information about\n"
13069 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013070 "Display the received routes from neighbor\n")
13071{
13072 struct peer *peer;
13073
13074 if (argc == 2)
13075 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13076 else
13077 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13078
13079 if (! peer)
13080 return CMD_WARNING;
13081
13082 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13083}
Lou Berger651b4022016-01-12 13:42:07 -050013084
13085DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13086 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13087 "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 +010013088 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013089 BGP_STR
13090 "Address family\n"
13091 "Address Family modifier\n"
13092 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013093 "Address Family modifier\n"
13094 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013095 "Detailed information on TCP and BGP neighbor connections\n"
13096 "Neighbor to display information about\n"
13097 "Neighbor to display information about\n"
13098 "Display the received routes from neighbor\n")
13099{
paulbb46e942003-10-24 19:02:03 +000013100 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013101 safi_t safi;
13102
13103 if (bgp_parse_safi(argv[0], &safi)) {
13104 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13105 return CMD_WARNING;
13106 }
paul718e3742002-12-13 20:15:29 +000013107
paulbb46e942003-10-24 19:02:03 +000013108 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13109 if (! peer)
13110 return CMD_WARNING;
13111
Lou Berger651b4022016-01-12 13:42:07 -050013112 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013113}
Lou Berger205e6742016-01-12 13:42:11 -050013114
Lou Berger651b4022016-01-12 13:42:07 -050013115DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13116 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13117 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13118 SHOW_STR
13119 BGP_STR
13120 "Address family\n"
13121 "Address Family modifier\n"
13122 "Address Family modifier\n"
13123 "Address Family modifier\n"
13124 "Address Family modifier\n"
13125 "Detailed information on TCP and BGP neighbor connections\n"
13126 "Neighbor to display information about\n"
13127 "Neighbor to display information about\n"
13128 "Display the received routes from neighbor\n")
13129{
13130 struct peer *peer;
13131 safi_t safi;
13132
13133 if (bgp_parse_safi(argv[0], &safi)) {
13134 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13135 return CMD_WARNING;
13136 }
13137
13138 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13139 if (! peer)
13140 return CMD_WARNING;
13141
13142 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13143}
paul718e3742002-12-13 20:15:29 +000013144
Michael Lambert95cbbd22010-07-23 14:43:04 -040013145DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13146 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013147 "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 -040013148 SHOW_STR
13149 BGP_STR
13150 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013151 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013152 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013153 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013154 "Address family modifier\n"
13155 "Address family modifier\n"
13156 "Detailed information on TCP and BGP neighbor connections\n"
13157 "Neighbor to display information about\n"
13158 "Neighbor to display information about\n"
13159 "Display the advertised routes to neighbor\n"
13160 "Display the received routes from neighbor\n")
13161{
13162 int afi;
13163 int safi;
13164 int in;
13165 struct peer *peer;
13166
David Lamparter94bad672015-03-03 08:52:22 +010013167 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013168
13169 if (! peer)
13170 return CMD_WARNING;
13171
Michael Lambert95cbbd22010-07-23 14:43:04 -040013172 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13173 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13174 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013175
13176 return peer_adj_routes (vty, peer, afi, safi, in);
13177}
13178
Lou Bergerf9b6c392016-01-12 13:42:09 -050013179DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13180 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13181 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13182 SHOW_STR
13183 IP_STR
13184 BGP_STR
13185 "Detailed information on TCP and BGP neighbor connections\n"
13186 "Neighbor to display information about\n"
13187 "Neighbor to display information about\n"
13188 "Display information received from a BGP neighbor\n"
13189 "Display the prefixlist filter\n")
13190{
13191 char name[BUFSIZ];
13192 union sockunion su;
13193 struct peer *peer;
13194 int count, ret;
13195
13196 ret = str2sockunion (argv[0], &su);
13197 if (ret < 0)
13198 {
13199 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13200 return CMD_WARNING;
13201 }
13202
13203 peer = peer_lookup (NULL, &su);
13204 if (! peer)
13205 return CMD_WARNING;
13206
13207 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13208 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13209 if (count)
13210 {
13211 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13212 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13213 }
13214
13215 return CMD_SUCCESS;
13216}
13217
13218DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13219 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13220 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13221 SHOW_STR
13222 IP_STR
13223 BGP_STR
13224 "Address family\n"
13225 "Address Family modifier\n"
13226 "Address Family modifier\n"
13227 "Detailed information on TCP and BGP neighbor connections\n"
13228 "Neighbor to display information about\n"
13229 "Neighbor to display information about\n"
13230 "Display information received from a BGP neighbor\n"
13231 "Display the prefixlist filter\n")
13232{
13233 char name[BUFSIZ];
13234 union sockunion su;
13235 struct peer *peer;
13236 int count, ret;
13237
13238 ret = str2sockunion (argv[1], &su);
13239 if (ret < 0)
13240 {
13241 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13242 return CMD_WARNING;
13243 }
13244
13245 peer = peer_lookup (NULL, &su);
13246 if (! peer)
13247 return CMD_WARNING;
13248
13249 if (strncmp (argv[0], "m", 1) == 0)
13250 {
13251 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13252 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13253 if (count)
13254 {
13255 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13256 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13257 }
13258 }
13259 else
13260 {
13261 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13262 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13263 if (count)
13264 {
13265 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13266 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13267 }
13268 }
13269
13270 return CMD_SUCCESS;
13271}
13272
13273ALIAS (show_bgp_view_neighbor_received_routes,
13274 show_bgp_neighbor_received_routes_cmd,
13275 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13276 SHOW_STR
13277 BGP_STR
13278 "Detailed information on TCP and BGP neighbor connections\n"
13279 "Neighbor to display information about\n"
13280 "Neighbor to display information about\n"
13281 "Display the received routes from neighbor\n")
13282
Lou Berger651b4022016-01-12 13:42:07 -050013283DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13284 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13285 "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 +000013286 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013287 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013288 IP_STR
13289 "Address Family modifier\n"
13290 "Address Family modifier\n"
13291 "Address Family modifier\n"
13292 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013293 "Detailed information on TCP and BGP neighbor connections\n"
13294 "Neighbor to display information about\n"
13295 "Neighbor to display information about\n"
13296 "Display information received from a BGP neighbor\n"
13297 "Display the prefixlist filter\n")
13298{
13299 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013300 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013301 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013302 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013303 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013304
Lou Berger651b4022016-01-12 13:42:07 -050013305 if (bgp_parse_safi(argv[0], &safi)) {
13306 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013307 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013308 }
paul718e3742002-12-13 20:15:29 +000013309
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013310 ret = str2sockunion (argv[1], &su);
13311 if (ret < 0)
13312 {
13313 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13314 return CMD_WARNING;
13315 }
paul718e3742002-12-13 20:15:29 +000013316
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013317 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013318 if (! peer)
13319 return CMD_WARNING;
13320
Lou Berger651b4022016-01-12 13:42:07 -050013321 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13322 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13323 if (count) {
13324 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13325 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13326 }
paul718e3742002-12-13 20:15:29 +000013327
13328 return CMD_SUCCESS;
13329}
Lou Berger205e6742016-01-12 13:42:11 -050013330
Lou Berger651b4022016-01-12 13:42:07 -050013331DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13332 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13333 "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 +000013334 SHOW_STR
13335 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013336 IP_STR
13337 "Address Family modifier\n"
13338 "Address Family modifier\n"
13339 "Address Family modifier\n"
13340 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013341 "Detailed information on TCP and BGP neighbor connections\n"
13342 "Neighbor to display information about\n"
13343 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013344 "Display information received from a BGP neighbor\n"
13345 "Display the prefixlist filter\n")
13346{
13347 char name[BUFSIZ];
13348 union sockunion su;
13349 struct peer *peer;
13350 int count, ret;
13351 safi_t safi;
13352
13353 if (bgp_parse_safi(argv[0], &safi)) {
13354 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13355 return CMD_WARNING;
13356 }
13357
13358 ret = str2sockunion (argv[1], &su);
13359 if (ret < 0)
13360 {
13361 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13362 return CMD_WARNING;
13363 }
13364
13365 peer = peer_lookup (NULL, &su);
13366 if (! peer)
13367 return CMD_WARNING;
13368
13369 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13370 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13371 if (count) {
13372 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13373 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13374 }
13375
13376 return CMD_SUCCESS;
13377}
paul718e3742002-12-13 20:15:29 +000013378
Lou Bergerf9b6c392016-01-12 13:42:09 -050013379DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013380 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13381 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013382 SHOW_STR
13383 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013384 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013385 "Detailed information on TCP and BGP neighbor connections\n"
13386 "Neighbor to display information about\n"
13387 "Neighbor to display information about\n"
13388 "Display information received from a BGP neighbor\n"
13389 "Display the prefixlist filter\n")
13390{
13391 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013392 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013393 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013394 int count, ret;
paul718e3742002-12-13 20:15:29 +000013395
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013396 ret = str2sockunion (argv[0], &su);
13397 if (ret < 0)
13398 {
13399 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13400 return CMD_WARNING;
13401 }
paul718e3742002-12-13 20:15:29 +000013402
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013403 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013404 if (! peer)
13405 return CMD_WARNING;
13406
13407 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13408 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13409 if (count)
13410 {
13411 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13412 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13413 }
13414
13415 return CMD_SUCCESS;
13416}
13417
Lou Bergerf9b6c392016-01-12 13:42:09 -050013418DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013419 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13420 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013421 SHOW_STR
13422 BGP_STR
13423 "BGP view\n"
13424 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013425 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013426 "Detailed information on TCP and BGP neighbor connections\n"
13427 "Neighbor to display information about\n"
13428 "Neighbor to display information about\n"
13429 "Display information received from a BGP neighbor\n"
13430 "Display the prefixlist filter\n")
13431{
13432 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013433 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013434 struct peer *peer;
13435 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013436 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013437
13438 /* BGP structure lookup. */
13439 bgp = bgp_lookup_by_name (argv[0]);
13440 if (bgp == NULL)
13441 {
13442 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13443 return CMD_WARNING;
13444 }
13445
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013446 ret = str2sockunion (argv[1], &su);
13447 if (ret < 0)
13448 {
13449 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13450 return CMD_WARNING;
13451 }
paulbb46e942003-10-24 19:02:03 +000013452
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013453 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013454 if (! peer)
13455 return CMD_WARNING;
13456
13457 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13458 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13459 if (count)
13460 {
13461 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13462 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13463 }
13464
13465 return CMD_SUCCESS;
13466}
David Lamparter6b0655a2014-06-04 06:53:35 +020013467
paul94f2b392005-06-28 12:44:16 +000013468static int
paulbb46e942003-10-24 19:02:03 +000013469bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013470 safi_t safi, enum bgp_show_type type)
13471{
paul718e3742002-12-13 20:15:29 +000013472 if (! peer || ! peer->afc[afi][safi])
13473 {
13474 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013475 return CMD_WARNING;
13476 }
13477
ajs5a646652004-11-05 01:25:55 +000013478 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013479}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013480DEFUN (show_ip_bgp_neighbor_routes,
13481 show_ip_bgp_neighbor_routes_cmd,
13482 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13483 SHOW_STR
13484 IP_STR
13485 BGP_STR
13486 "Detailed information on TCP and BGP neighbor connections\n"
13487 "Neighbor to display information about\n"
13488 "Neighbor to display information about\n"
13489 "Display routes learned from neighbor\n")
13490{
13491 struct peer *peer;
13492
13493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13494 if (! peer)
13495 return CMD_WARNING;
13496
13497 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13498 bgp_show_type_neighbor);
13499}
13500
13501DEFUN (show_ip_bgp_neighbor_flap,
13502 show_ip_bgp_neighbor_flap_cmd,
13503 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13504 SHOW_STR
13505 IP_STR
13506 BGP_STR
13507 "Detailed information on TCP and BGP neighbor connections\n"
13508 "Neighbor to display information about\n"
13509 "Neighbor to display information about\n"
13510 "Display flap statistics of the routes learned from neighbor\n")
13511{
13512 struct peer *peer;
13513
13514 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13515 if (! peer)
13516 return CMD_WARNING;
13517
13518 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13519 bgp_show_type_flap_neighbor);
13520}
13521
13522DEFUN (show_ip_bgp_neighbor_damp,
13523 show_ip_bgp_neighbor_damp_cmd,
13524 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13525 SHOW_STR
13526 IP_STR
13527 BGP_STR
13528 "Detailed information on TCP and BGP neighbor connections\n"
13529 "Neighbor to display information about\n"
13530 "Neighbor to display information about\n"
13531 "Display the dampened routes received from neighbor\n")
13532{
13533 struct peer *peer;
13534
13535 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13536 if (! peer)
13537 return CMD_WARNING;
13538
13539 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13540 bgp_show_type_damp_neighbor);
13541}
13542
13543DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13544 show_ip_bgp_ipv4_neighbor_routes_cmd,
13545 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13546 SHOW_STR
13547 IP_STR
13548 BGP_STR
13549 "Address family\n"
13550 "Address Family modifier\n"
13551 "Address Family modifier\n"
13552 "Detailed information on TCP and BGP neighbor connections\n"
13553 "Neighbor to display information about\n"
13554 "Neighbor to display information about\n"
13555 "Display routes learned from neighbor\n")
13556{
13557 struct peer *peer;
13558
13559 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13560 if (! peer)
13561 return CMD_WARNING;
13562
13563 if (strncmp (argv[0], "m", 1) == 0)
13564 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13565 bgp_show_type_neighbor);
13566
13567 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13568 bgp_show_type_neighbor);
13569}
13570
13571DEFUN (show_ip_bgp_view_rsclient,
13572 show_ip_bgp_view_rsclient_cmd,
13573 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13574 SHOW_STR
13575 IP_STR
13576 BGP_STR
13577 "BGP view\n"
13578 "View name\n"
13579 "Information about Route Server Client\n"
13580 NEIGHBOR_ADDR_STR)
13581{
13582 struct bgp_table *table;
13583 struct peer *peer;
13584
13585 if (argc == 2)
13586 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13587 else
13588 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13589
13590 if (! peer)
13591 return CMD_WARNING;
13592
13593 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13594 {
13595 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13596 VTY_NEWLINE);
13597 return CMD_WARNING;
13598 }
13599
13600 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13601 PEER_FLAG_RSERVER_CLIENT))
13602 {
13603 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13604 VTY_NEWLINE);
13605 return CMD_WARNING;
13606 }
13607
13608 table = peer->rib[AFI_IP][SAFI_UNICAST];
13609
13610 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13611}
13612
13613ALIAS (show_ip_bgp_view_rsclient,
13614 show_ip_bgp_rsclient_cmd,
13615 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13616 SHOW_STR
13617 IP_STR
13618 BGP_STR
13619 "Information about Route Server Client\n"
13620 NEIGHBOR_ADDR_STR)
13621
13622DEFUN (show_bgp_view_ipv4_safi_rsclient,
13623 show_bgp_view_ipv4_safi_rsclient_cmd,
13624 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13625 SHOW_STR
13626 BGP_STR
13627 "BGP view\n"
13628 "View name\n"
13629 "Address family\n"
13630 "Address Family modifier\n"
13631 "Address Family modifier\n"
13632 "Information about Route Server Client\n"
13633 NEIGHBOR_ADDR_STR)
13634{
13635 struct bgp_table *table;
13636 struct peer *peer;
13637 safi_t safi;
13638
13639 if (argc == 3) {
13640 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13641 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13642 } else {
13643 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13644 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13645 }
13646
13647 if (! peer)
13648 return CMD_WARNING;
13649
13650 if (! peer->afc[AFI_IP][safi])
13651 {
13652 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13653 VTY_NEWLINE);
13654 return CMD_WARNING;
13655 }
13656
13657 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13658 PEER_FLAG_RSERVER_CLIENT))
13659 {
13660 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13661 VTY_NEWLINE);
13662 return CMD_WARNING;
13663 }
13664
13665 table = peer->rib[AFI_IP][safi];
13666
13667 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13668}
13669
13670ALIAS (show_bgp_view_ipv4_safi_rsclient,
13671 show_bgp_ipv4_safi_rsclient_cmd,
13672 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13673 SHOW_STR
13674 BGP_STR
13675 "Address family\n"
13676 "Address Family modifier\n"
13677 "Address Family modifier\n"
13678 "Information about Route Server Client\n"
13679 NEIGHBOR_ADDR_STR)
13680
13681DEFUN (show_ip_bgp_view_rsclient_route,
13682 show_ip_bgp_view_rsclient_route_cmd,
13683 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13684 SHOW_STR
13685 IP_STR
13686 BGP_STR
13687 "BGP view\n"
13688 "View name\n"
13689 "Information about Route Server Client\n"
13690 NEIGHBOR_ADDR_STR
13691 "Network in the BGP routing table to display\n")
13692{
13693 struct bgp *bgp;
13694 struct peer *peer;
13695
13696 /* BGP structure lookup. */
13697 if (argc == 3)
13698 {
13699 bgp = bgp_lookup_by_name (argv[0]);
13700 if (bgp == NULL)
13701 {
13702 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13703 return CMD_WARNING;
13704 }
13705 }
13706 else
13707 {
13708 bgp = bgp_get_default ();
13709 if (bgp == NULL)
13710 {
13711 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13712 return CMD_WARNING;
13713 }
13714 }
13715
13716 if (argc == 3)
13717 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13718 else
13719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13720
13721 if (! peer)
13722 return CMD_WARNING;
13723
13724 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13725 {
13726 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13727 VTY_NEWLINE);
13728 return CMD_WARNING;
13729}
13730
13731 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13732 PEER_FLAG_RSERVER_CLIENT))
13733 {
13734 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13735 VTY_NEWLINE);
13736 return CMD_WARNING;
13737 }
13738
13739 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13740 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013741 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050013742}
13743
13744ALIAS (show_ip_bgp_view_rsclient_route,
13745 show_ip_bgp_rsclient_route_cmd,
13746 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13747 SHOW_STR
13748 IP_STR
13749 BGP_STR
13750 "Information about Route Server Client\n"
13751 NEIGHBOR_ADDR_STR
13752 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013753
Lou Berger651b4022016-01-12 13:42:07 -050013754DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13755 show_bgp_ipv4_safi_neighbor_flap_cmd,
13756 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013757 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013758 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013759 "Address Family Modifier\n"
13760 "Address Family Modifier\n"
13761 "Address Family Modifier\n"
13762 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013763 "Detailed information on TCP and BGP neighbor connections\n"
13764 "Neighbor to display information about\n"
13765 "Neighbor to display information about\n"
13766 "Display flap statistics of the routes learned from neighbor\n")
13767{
paulbb46e942003-10-24 19:02:03 +000013768 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013769 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013770
Lou Berger651b4022016-01-12 13:42:07 -050013771 if (bgp_parse_safi(argv[0], &safi)) {
13772 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13773 return CMD_WARNING;
13774 }
13775
13776 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013777 if (! peer)
13778 return CMD_WARNING;
13779
Lou Berger651b4022016-01-12 13:42:07 -050013780 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013781 bgp_show_type_flap_neighbor);
13782}
Lou Berger205e6742016-01-12 13:42:11 -050013783
Lou Berger651b4022016-01-12 13:42:07 -050013784DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13785 show_bgp_ipv6_safi_neighbor_flap_cmd,
13786 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013787 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013788 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013789 "Address Family Modifier\n"
13790 "Address Family Modifier\n"
13791 "Address Family Modifier\n"
13792 "Address Family Modifier\n"
13793 "Detailed information on TCP and BGP neighbor connections\n"
13794 "Neighbor to display information about\n"
13795 "Neighbor to display information about\n"
13796 "Display flap statistics of the routes learned from neighbor\n")
13797{
13798 struct peer *peer;
13799 safi_t safi;
13800
13801 if (bgp_parse_safi(argv[0], &safi)) {
13802 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13803 return CMD_WARNING;
13804 }
13805
13806 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13807 if (! peer)
13808 return CMD_WARNING;
13809
13810 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13811 bgp_show_type_flap_neighbor);
13812}
Lou Berger651b4022016-01-12 13:42:07 -050013813
13814DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13815 show_bgp_ipv4_safi_neighbor_damp_cmd,
13816 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13817 SHOW_STR
13818 BGP_STR
13819 "Address Family Modifier\n"
13820 "Address Family Modifier\n"
13821 "Address Family Modifier\n"
13822 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013823 "Detailed information on TCP and BGP neighbor connections\n"
13824 "Neighbor to display information about\n"
13825 "Neighbor to display information about\n"
13826 "Display the dampened routes received from neighbor\n")
13827{
paulbb46e942003-10-24 19:02:03 +000013828 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013829 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013830
Lou Berger651b4022016-01-12 13:42:07 -050013831 if (bgp_parse_safi(argv[0], &safi)) {
13832 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13833 return CMD_WARNING;
13834 }
13835
13836 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013837 if (! peer)
13838 return CMD_WARNING;
13839
Lou Berger651b4022016-01-12 13:42:07 -050013840 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013841 bgp_show_type_damp_neighbor);
13842}
Lou Berger205e6742016-01-12 13:42:11 -050013843
Lou Berger651b4022016-01-12 13:42:07 -050013844DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13845 show_bgp_ipv6_safi_neighbor_damp_cmd,
13846 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013847 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013848 BGP_STR
13849 "Address Family Modifier\n"
13850 "Address Family Modifier\n"
13851 "Address Family Modifier\n"
13852 "Address Family Modifier\n"
13853 "Detailed information on TCP and BGP neighbor connections\n"
13854 "Neighbor to display information about\n"
13855 "Neighbor to display information about\n"
13856 "Display the dampened routes received from neighbor\n")
13857{
13858 struct peer *peer;
13859 safi_t safi;
13860
13861 if (bgp_parse_safi(argv[0], &safi)) {
13862 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13863 return CMD_WARNING;
13864 }
13865
13866 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13867 if (! peer)
13868 return CMD_WARNING;
13869
13870 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13871 bgp_show_type_damp_neighbor);
13872}
Lou Berger651b4022016-01-12 13:42:07 -050013873
13874DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13875 show_bgp_ipv4_safi_neighbor_routes_cmd,
13876 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13877 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013878 BGP_STR
13879 "Address family\n"
13880 "Address Family modifier\n"
13881 "Address Family modifier\n"
13882 "Detailed information on TCP and BGP neighbor connections\n"
13883 "Neighbor to display information about\n"
13884 "Neighbor to display information about\n"
13885 "Display routes learned from neighbor\n")
13886{
paulbb46e942003-10-24 19:02:03 +000013887 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013888 safi_t safi;
13889
13890 if (bgp_parse_safi(argv[0], &safi)) {
13891 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13892 return CMD_WARNING;
13893 }
paulbb46e942003-10-24 19:02:03 +000013894
13895 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13896 if (! peer)
13897 return CMD_WARNING;
13898
Lou Berger651b4022016-01-12 13:42:07 -050013899 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013900 bgp_show_type_neighbor);
13901}
Lou Berger205e6742016-01-12 13:42:11 -050013902
Lou Berger651b4022016-01-12 13:42:07 -050013903DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13904 show_bgp_ipv6_safi_neighbor_routes_cmd,
13905 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013906 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013907 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013908 "Address family\n"
13909 "Address Family modifier\n"
13910 "Address Family modifier\n"
13911 "Detailed information on TCP and BGP neighbor connections\n"
13912 NEIGHBOR_ADDR_STR
13913 NEIGHBOR_ADDR_STR
13914 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013915{
paulfee0f4c2004-09-13 05:12:46 +000013916 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013917 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013918
Lou Berger651b4022016-01-12 13:42:07 -050013919 if (bgp_parse_safi(argv[0], &safi)) {
13920 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13921 return CMD_WARNING;
13922 }
paulfee0f4c2004-09-13 05:12:46 +000013923
Lou Berger651b4022016-01-12 13:42:07 -050013924 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013925 if (! peer)
13926 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013927
13928 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13929 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013930}
paulfee0f4c2004-09-13 05:12:46 +000013931
Michael Lambert95cbbd22010-07-23 14:43:04 -040013932DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13933 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13934 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13935 SHOW_STR
13936 BGP_STR
13937 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013938 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013939 "Address family\n"
13940 "Address Family modifier\n"
13941 "Address Family modifier\n"
13942 "Information about Route Server Client\n"
13943 NEIGHBOR_ADDR_STR
13944 "Network in the BGP routing table to display\n")
13945{
13946 struct bgp *bgp;
13947 struct peer *peer;
13948 safi_t safi;
13949
13950 /* BGP structure lookup. */
13951 if (argc == 4)
13952 {
13953 bgp = bgp_lookup_by_name (argv[0]);
13954 if (bgp == NULL)
13955 {
13956 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13957 return CMD_WARNING;
13958 }
13959 }
13960 else
13961 {
13962 bgp = bgp_get_default ();
13963 if (bgp == NULL)
13964 {
13965 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13966 return CMD_WARNING;
13967 }
13968 }
13969
13970 if (argc == 4) {
13971 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13972 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13973 } else {
13974 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13975 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13976 }
13977
13978 if (! peer)
13979 return CMD_WARNING;
13980
13981 if (! peer->afc[AFI_IP][safi])
13982 {
13983 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13984 VTY_NEWLINE);
13985 return CMD_WARNING;
13986}
13987
13988 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13989 PEER_FLAG_RSERVER_CLIENT))
13990 {
13991 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13992 VTY_NEWLINE);
13993 return CMD_WARNING;
13994 }
13995
13996 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
13997 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013998 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013999}
14000
14001ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
14002 show_bgp_ipv4_safi_rsclient_route_cmd,
14003 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14004 SHOW_STR
14005 BGP_STR
14006 "Address family\n"
14007 "Address Family modifier\n"
14008 "Address Family modifier\n"
14009 "Information about Route Server Client\n"
14010 NEIGHBOR_ADDR_STR
14011 "Network in the BGP routing table to display\n")
14012
paulfee0f4c2004-09-13 05:12:46 +000014013
Michael Lambert95cbbd22010-07-23 14:43:04 -040014014DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
14015 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
14016 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14017 SHOW_STR
14018 BGP_STR
14019 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014020 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014021 "Address family\n"
14022 "Address Family modifier\n"
14023 "Address Family modifier\n"
14024 "Information about Route Server Client\n"
14025 NEIGHBOR_ADDR_STR
14026 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14027{
14028 struct bgp *bgp;
14029 struct peer *peer;
14030 safi_t safi;
14031
14032 /* BGP structure lookup. */
14033 if (argc == 4)
14034 {
14035 bgp = bgp_lookup_by_name (argv[0]);
14036 if (bgp == NULL)
14037 {
14038 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14039 return CMD_WARNING;
14040 }
14041 }
14042 else
14043 {
14044 bgp = bgp_get_default ();
14045 if (bgp == NULL)
14046 {
14047 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14048 return CMD_WARNING;
14049 }
14050 }
14051
14052 if (argc == 4) {
14053 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14054 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14055 } else {
14056 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14057 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14058 }
14059
14060 if (! peer)
14061 return CMD_WARNING;
14062
14063 if (! peer->afc[AFI_IP][safi])
14064 {
14065 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14066 VTY_NEWLINE);
14067 return CMD_WARNING;
14068}
14069
14070 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14071 PEER_FLAG_RSERVER_CLIENT))
14072{
14073 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14074 VTY_NEWLINE);
14075 return CMD_WARNING;
14076 }
14077
14078 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14079 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014080 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014081}
14082
Lou Bergerf9b6c392016-01-12 13:42:09 -050014083DEFUN (show_ip_bgp_view_rsclient_prefix,
14084 show_ip_bgp_view_rsclient_prefix_cmd,
14085 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14086 SHOW_STR
14087 IP_STR
14088 BGP_STR
14089 "BGP view\n"
14090 "View name\n"
14091 "Information about Route Server Client\n"
14092 NEIGHBOR_ADDR_STR
14093 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14094{
14095 struct bgp *bgp;
14096 struct peer *peer;
14097
14098 /* BGP structure lookup. */
14099 if (argc == 3)
14100 {
14101 bgp = bgp_lookup_by_name (argv[0]);
14102 if (bgp == NULL)
14103 {
14104 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14105 return CMD_WARNING;
14106 }
14107 }
14108 else
14109 {
14110 bgp = bgp_get_default ();
14111 if (bgp == NULL)
14112 {
14113 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14114 return CMD_WARNING;
14115 }
14116 }
14117
14118 if (argc == 3)
14119 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14120 else
14121 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14122
14123 if (! peer)
14124 return CMD_WARNING;
14125
14126 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14127 {
14128 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14129 VTY_NEWLINE);
14130 return CMD_WARNING;
14131}
14132
14133 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14134 PEER_FLAG_RSERVER_CLIENT))
14135{
14136 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14137 VTY_NEWLINE);
14138 return CMD_WARNING;
14139 }
14140
14141 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14142 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014143 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014144}
14145
14146ALIAS (show_ip_bgp_view_rsclient_prefix,
14147 show_ip_bgp_rsclient_prefix_cmd,
14148 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14149 SHOW_STR
14150 IP_STR
14151 BGP_STR
14152 "Information about Route Server Client\n"
14153 NEIGHBOR_ADDR_STR
14154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14155
Michael Lambert95cbbd22010-07-23 14:43:04 -040014156ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14157 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14158 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14159 SHOW_STR
14160 BGP_STR
14161 "Address family\n"
14162 "Address Family modifier\n"
14163 "Address Family modifier\n"
14164 "Information about Route Server Client\n"
14165 NEIGHBOR_ADDR_STR
14166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014167
Lou Bergerf9b6c392016-01-12 13:42:09 -050014168DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014169 show_bgp_view_ipv6_neighbor_routes_cmd,
14170 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014171 SHOW_STR
14172 BGP_STR
14173 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014174 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014175 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014176 "Detailed information on TCP and BGP neighbor connections\n"
14177 "Neighbor to display information about\n"
14178 "Neighbor to display information about\n"
14179 "Display routes learned from neighbor\n")
14180{
14181 struct peer *peer;
14182
14183 if (argc == 2)
14184 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14185 else
14186 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14187
14188 if (! peer)
14189 return CMD_WARNING;
14190
14191 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14192 bgp_show_type_neighbor);
14193}
14194
Lou Berger651b4022016-01-12 13:42:07 -050014195DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014196 show_bgp_view_neighbor_damp_cmd,
14197 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14198 SHOW_STR
14199 BGP_STR
14200 "BGP view\n"
14201 "View name\n"
14202 "Detailed information on TCP and BGP neighbor connections\n"
14203 "Neighbor to display information about\n"
14204 "Neighbor to display information about\n"
14205 "Display the dampened routes received from neighbor\n")
14206{
14207 struct peer *peer;
14208
14209 if (argc == 2)
14210 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14211 else
14212 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14213
14214 if (! peer)
14215 return CMD_WARNING;
14216
14217 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14218 bgp_show_type_damp_neighbor);
14219}
14220
14221DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014222 show_bgp_view_ipv6_neighbor_damp_cmd,
14223 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014224 SHOW_STR
14225 BGP_STR
14226 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014227 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014228 "Address family\n"
14229 "Detailed information on TCP and BGP neighbor connections\n"
14230 "Neighbor to display information about\n"
14231 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014232 "Display the dampened routes received from neighbor\n")
14233{
14234 struct peer *peer;
14235
14236 if (argc == 2)
14237 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14238 else
14239 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14240
14241 if (! peer)
14242 return CMD_WARNING;
14243
14244 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14245 bgp_show_type_damp_neighbor);
14246}
14247
Lou Bergerf9b6c392016-01-12 13:42:09 -050014248DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014249 show_bgp_view_ipv6_neighbor_flap_cmd,
14250 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014251 SHOW_STR
14252 BGP_STR
14253 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014254 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014255 "Address family\n"
14256 "Detailed information on TCP and BGP neighbor connections\n"
14257 "Neighbor to display information about\n"
14258 "Neighbor to display information about\n"
14259 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014260{
14261 struct peer *peer;
14262
14263 if (argc == 2)
14264 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14265 else
14266 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14267
14268 if (! peer)
14269 return CMD_WARNING;
14270
14271 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14272 bgp_show_type_flap_neighbor);
14273}
14274
Lou Bergerf9b6c392016-01-12 13:42:09 -050014275DEFUN (show_bgp_view_neighbor_flap,
14276 show_bgp_view_neighbor_flap_cmd,
14277 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14278 SHOW_STR
14279 BGP_STR
14280 "BGP view\n"
14281 "View name\n"
14282 "Detailed information on TCP and BGP neighbor connections\n"
14283 "Neighbor to display information about\n"
14284 "Neighbor to display information about\n"
14285 "Display flap statistics of the routes learned from neighbor\n")
14286{
14287 struct peer *peer;
14288
14289 if (argc == 2)
14290 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14291 else
14292 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14293
14294 if (! peer)
14295 return CMD_WARNING;
14296
14297 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14298 bgp_show_type_flap_neighbor);
14299}
14300
14301ALIAS (show_bgp_view_neighbor_flap,
14302 show_bgp_neighbor_flap_cmd,
14303 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14304 SHOW_STR
14305 BGP_STR
14306 "Detailed information on TCP and BGP neighbor connections\n"
14307 "Neighbor to display information about\n"
14308 "Neighbor to display information about\n"
14309 "Display flap statistics of the routes learned from neighbor\n")
14310
14311ALIAS (show_bgp_view_neighbor_damp,
14312 show_bgp_neighbor_damp_cmd,
14313 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14314 SHOW_STR
14315 BGP_STR
14316 "Detailed information on TCP and BGP neighbor connections\n"
14317 "Neighbor to display information about\n"
14318 "Neighbor to display information about\n"
14319 "Display the dampened routes received from neighbor\n")
14320
14321DEFUN (show_bgp_view_neighbor_routes,
14322 show_bgp_view_neighbor_routes_cmd,
14323 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14324 SHOW_STR
14325 BGP_STR
14326 "BGP view\n"
14327 "View name\n"
14328 "Detailed information on TCP and BGP neighbor connections\n"
14329 "Neighbor to display information about\n"
14330 "Neighbor to display information about\n"
14331 "Display routes learned from neighbor\n")
14332{
14333 struct peer *peer;
14334
14335 if (argc == 2)
14336 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14337 else
14338 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14339
14340 if (! peer)
14341 return CMD_WARNING;
14342
14343 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14344 bgp_show_type_neighbor);
14345}
14346
14347ALIAS (show_bgp_view_neighbor_routes,
14348 show_bgp_neighbor_routes_cmd,
14349 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14350 SHOW_STR
14351 BGP_STR
14352 "Detailed information on TCP and BGP neighbor connections\n"
14353 "Neighbor to display information about\n"
14354 "Neighbor to display information about\n"
14355 "Display routes learned from neighbor\n")
14356
paulbb46e942003-10-24 19:02:03 +000014357ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014358 show_bgp_ipv6_neighbor_routes_cmd,
14359 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14360 SHOW_STR
14361 BGP_STR
14362 "Address family\n"
14363 "Detailed information on TCP and BGP neighbor connections\n"
14364 "Neighbor to display information about\n"
14365 "Neighbor to display information about\n"
14366 "Display routes learned from neighbor\n")
14367
Lou Bergerf9b6c392016-01-12 13:42:09 -050014368/* old command */
14369ALIAS (show_bgp_view_neighbor_routes,
14370 ipv6_bgp_neighbor_routes_cmd,
14371 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14372 SHOW_STR
14373 IPV6_STR
14374 BGP_STR
14375 "Detailed information on TCP and BGP neighbor connections\n"
14376 "Neighbor to display information about\n"
14377 "Neighbor to display information about\n"
14378 "Display routes learned from neighbor\n")
14379
14380/* old command */
14381DEFUN (ipv6_mbgp_neighbor_routes,
14382 ipv6_mbgp_neighbor_routes_cmd,
14383 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14384 SHOW_STR
14385 IPV6_STR
14386 MBGP_STR
14387 "Detailed information on TCP and BGP neighbor connections\n"
14388 "Neighbor to display information about\n"
14389 "Neighbor to display information about\n"
14390 "Display routes learned from neighbor\n")
14391{
14392 struct peer *peer;
14393
14394 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14395 if (! peer)
14396 return CMD_WARNING;
14397
14398 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14399 bgp_show_type_neighbor);
14400}
14401
paulbb46e942003-10-24 19:02:03 +000014402ALIAS (show_bgp_view_neighbor_flap,
14403 show_bgp_ipv6_neighbor_flap_cmd,
14404 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14405 SHOW_STR
14406 BGP_STR
14407 "Address family\n"
14408 "Detailed information on TCP and BGP neighbor connections\n"
14409 "Neighbor to display information about\n"
14410 "Neighbor to display information about\n"
14411 "Display flap statistics of the routes learned from neighbor\n")
14412
14413ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014414 show_bgp_ipv6_neighbor_damp_cmd,
14415 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14416 SHOW_STR
14417 BGP_STR
14418 "Address family\n"
14419 "Detailed information on TCP and BGP neighbor connections\n"
14420 "Neighbor to display information about\n"
14421 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014422 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014423
Lou Bergerf9b6c392016-01-12 13:42:09 -050014424DEFUN (show_bgp_view_rsclient,
14425 show_bgp_view_rsclient_cmd,
14426 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14427 SHOW_STR
14428 BGP_STR
14429 "BGP view\n"
14430 "View name\n"
14431 "Information about Route Server Client\n"
14432 NEIGHBOR_ADDR_STR)
14433{
14434 struct bgp_table *table;
14435 struct peer *peer;
14436
14437 if (argc == 2)
14438 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14439 else
14440 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14441
14442 if (! peer)
14443 return CMD_WARNING;
14444
14445 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14446 {
14447 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14448 VTY_NEWLINE);
14449 return CMD_WARNING;
14450 }
14451
14452 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14453 PEER_FLAG_RSERVER_CLIENT))
14454 {
14455 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14456 VTY_NEWLINE);
14457 return CMD_WARNING;
14458 }
14459
14460 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14461
14462 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14463}
14464
14465ALIAS (show_bgp_view_rsclient,
14466 show_bgp_rsclient_cmd,
14467 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14468 SHOW_STR
14469 BGP_STR
14470 "Information about Route Server Client\n"
14471 NEIGHBOR_ADDR_STR)
14472
Lou Berger651b4022016-01-12 13:42:07 -050014473DEFUN (show_bgp_view_ipv4_rsclient,
14474 show_bgp_view_ipv4_rsclient_cmd,
14475 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014476 SHOW_STR
14477 BGP_STR
14478 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014479 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014480 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014481 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014482 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014483{
Lou Berger651b4022016-01-12 13:42:07 -050014484 struct bgp_table *table;
14485 struct peer *peer;
14486
14487 if (argc == 2)
14488 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14489 else
14490 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14491
14492 if (! peer)
14493 return CMD_WARNING;
14494
14495 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14496 {
14497 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14498 VTY_NEWLINE);
14499 return CMD_WARNING;
14500 }
14501
14502 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14503 PEER_FLAG_RSERVER_CLIENT))
14504 {
14505 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14506 VTY_NEWLINE);
14507 return CMD_WARNING;
14508 }
14509
14510 table = peer->rib[AFI_IP][SAFI_UNICAST];
14511
14512 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14513}
14514DEFUN (show_bgp_view_ipv6_rsclient,
14515 show_bgp_view_ipv6_rsclient_cmd,
14516 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14517 SHOW_STR
14518 BGP_STR
14519 "BGP view\n"
14520 "BGP view name\n"
14521 "Address Family\n"
14522 "Information about Route Server Client\n"
14523 NEIGHBOR_ADDR_STR2)
14524{
14525 struct bgp_table *table;
14526 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014527
14528 if (argc == 2)
14529 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14530 else
14531 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14532
14533 if (! peer)
14534 return CMD_WARNING;
14535
14536 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14537 {
14538 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14539 VTY_NEWLINE);
14540 return CMD_WARNING;
14541 }
14542
14543 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14544 PEER_FLAG_RSERVER_CLIENT))
14545 {
14546 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14547 VTY_NEWLINE);
14548 return CMD_WARNING;
14549 }
14550
14551 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14552
ajs5a646652004-11-05 01:25:55 +000014553 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014554}
14555
Lou Berger651b4022016-01-12 13:42:07 -050014556ALIAS (show_bgp_view_ipv4_rsclient,
14557 show_bgp_ipv4_rsclient_cmd,
14558 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014559 SHOW_STR
14560 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014561 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014562 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014563 NEIGHBOR_ADDR_STR2)
14564
Lou Berger651b4022016-01-12 13:42:07 -050014565ALIAS (show_bgp_view_ipv6_rsclient,
14566 show_bgp_ipv6_rsclient_cmd,
14567 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14568 SHOW_STR
14569 BGP_STR
14570 "Address Family\n"
14571 "Information about Route Server Client\n"
14572 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014573
Michael Lambert95cbbd22010-07-23 14:43:04 -040014574DEFUN (show_bgp_view_ipv6_safi_rsclient,
14575 show_bgp_view_ipv6_safi_rsclient_cmd,
14576 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14577 SHOW_STR
14578 BGP_STR
14579 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014580 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014581 "Address family\n"
14582 "Address Family modifier\n"
14583 "Address Family modifier\n"
14584 "Information about Route Server Client\n"
14585 NEIGHBOR_ADDR_STR)
14586{
14587 struct bgp_table *table;
14588 struct peer *peer;
14589 safi_t safi;
14590
14591 if (argc == 3) {
14592 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14593 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14594 } else {
14595 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14596 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14597 }
14598
14599 if (! peer)
14600 return CMD_WARNING;
14601
14602 if (! peer->afc[AFI_IP6][safi])
14603 {
14604 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14605 VTY_NEWLINE);
14606 return CMD_WARNING;
14607 }
14608
14609 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14610 PEER_FLAG_RSERVER_CLIENT))
14611 {
14612 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14613 VTY_NEWLINE);
14614 return CMD_WARNING;
14615 }
14616
14617 table = peer->rib[AFI_IP6][safi];
14618
14619 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14620}
14621
14622ALIAS (show_bgp_view_ipv6_safi_rsclient,
14623 show_bgp_ipv6_safi_rsclient_cmd,
14624 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14625 SHOW_STR
14626 BGP_STR
14627 "Address family\n"
14628 "Address Family modifier\n"
14629 "Address Family modifier\n"
14630 "Information about Route Server Client\n"
14631 NEIGHBOR_ADDR_STR)
14632
paulfee0f4c2004-09-13 05:12:46 +000014633DEFUN (show_bgp_view_rsclient_route,
14634 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014635 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14636 SHOW_STR
14637 BGP_STR
14638 "BGP view\n"
14639 "View name\n"
14640 "Information about Route Server Client\n"
14641 NEIGHBOR_ADDR_STR
14642 "Network in the BGP routing table to display\n")
14643{
14644 struct bgp *bgp;
14645 struct peer *peer;
14646
14647 /* BGP structure lookup. */
14648 if (argc == 3)
14649 {
14650 bgp = bgp_lookup_by_name (argv[0]);
14651 if (bgp == NULL)
14652 {
14653 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14654 return CMD_WARNING;
14655 }
14656 }
14657 else
14658 {
14659 bgp = bgp_get_default ();
14660 if (bgp == NULL)
14661 {
14662 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14663 return CMD_WARNING;
14664 }
14665 }
14666
14667 if (argc == 3)
14668 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14669 else
14670 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14671
14672 if (! peer)
14673 return CMD_WARNING;
14674
14675 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14676 {
14677 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14678 VTY_NEWLINE);
14679 return CMD_WARNING;
14680 }
14681
14682 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14683 PEER_FLAG_RSERVER_CLIENT))
14684 {
14685 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14686 VTY_NEWLINE);
14687 return CMD_WARNING;
14688 }
14689
14690 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14691 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014692 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014693}
14694
14695DEFUN (show_bgp_view_ipv6_rsclient_route,
14696 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014697 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014698 SHOW_STR
14699 BGP_STR
14700 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014701 "BGP view name\n"
14702 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014703 "Information about Route Server Client\n"
14704 NEIGHBOR_ADDR_STR
14705 "Network in the BGP routing table to display\n")
14706{
14707 struct bgp *bgp;
14708 struct peer *peer;
14709
14710 /* BGP structure lookup. */
14711 if (argc == 3)
14712 {
14713 bgp = bgp_lookup_by_name (argv[0]);
14714 if (bgp == NULL)
14715 {
14716 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14717 return CMD_WARNING;
14718 }
14719 }
14720 else
14721 {
14722 bgp = bgp_get_default ();
14723 if (bgp == NULL)
14724 {
14725 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14726 return CMD_WARNING;
14727 }
14728 }
14729
14730 if (argc == 3)
14731 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14732 else
14733 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14734
14735 if (! peer)
14736 return CMD_WARNING;
14737
14738 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14739 {
14740 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14741 VTY_NEWLINE);
14742 return CMD_WARNING;
14743 }
14744
14745 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14746 PEER_FLAG_RSERVER_CLIENT))
14747 {
14748 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14749 VTY_NEWLINE);
14750 return CMD_WARNING;
14751 }
14752
14753 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14754 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014755 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014756}
14757
Lou Bergerf9b6c392016-01-12 13:42:09 -050014758ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014759 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014760 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14761 SHOW_STR
14762 BGP_STR
14763 "Information about Route Server Client\n"
14764 NEIGHBOR_ADDR_STR
14765 "Network in the BGP routing table to display\n")
14766
14767ALIAS (show_bgp_view_ipv6_rsclient_route,
14768 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014769 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014770 SHOW_STR
14771 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014772 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014773 "Information about Route Server Client\n"
14774 NEIGHBOR_ADDR_STR
14775 "Network in the BGP routing table to display\n")
14776
Michael Lambert95cbbd22010-07-23 14:43:04 -040014777DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14778 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14779 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14780 SHOW_STR
14781 BGP_STR
14782 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014783 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014784 "Address family\n"
14785 "Address Family modifier\n"
14786 "Address Family modifier\n"
14787 "Information about Route Server Client\n"
14788 NEIGHBOR_ADDR_STR
14789 "Network in the BGP routing table to display\n")
14790{
14791 struct bgp *bgp;
14792 struct peer *peer;
14793 safi_t safi;
14794
14795 /* BGP structure lookup. */
14796 if (argc == 4)
14797 {
14798 bgp = bgp_lookup_by_name (argv[0]);
14799 if (bgp == NULL)
14800 {
14801 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14802 return CMD_WARNING;
14803 }
14804 }
14805 else
14806 {
14807 bgp = bgp_get_default ();
14808 if (bgp == NULL)
14809 {
14810 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14811 return CMD_WARNING;
14812 }
14813 }
14814
14815 if (argc == 4) {
14816 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14817 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14818 } else {
14819 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14820 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14821 }
14822
14823 if (! peer)
14824 return CMD_WARNING;
14825
14826 if (! peer->afc[AFI_IP6][safi])
14827 {
14828 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14829 VTY_NEWLINE);
14830 return CMD_WARNING;
14831}
14832
14833 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14834 PEER_FLAG_RSERVER_CLIENT))
14835 {
14836 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14837 VTY_NEWLINE);
14838 return CMD_WARNING;
14839 }
14840
14841 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14842 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014843 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014844}
14845
14846ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14847 show_bgp_ipv6_safi_rsclient_route_cmd,
14848 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14849 SHOW_STR
14850 BGP_STR
14851 "Address family\n"
14852 "Address Family modifier\n"
14853 "Address Family modifier\n"
14854 "Information about Route Server Client\n"
14855 NEIGHBOR_ADDR_STR
14856 "Network in the BGP routing table to display\n")
14857
Lou Berger651b4022016-01-12 13:42:07 -050014858
paulfee0f4c2004-09-13 05:12:46 +000014859DEFUN (show_bgp_view_rsclient_prefix,
14860 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014861 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14862 SHOW_STR
14863 BGP_STR
14864 "BGP view\n"
14865 "View name\n"
14866 "Information about Route Server Client\n"
14867 NEIGHBOR_ADDR_STR
14868 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14869{
14870 struct bgp *bgp;
14871 struct peer *peer;
14872
14873 /* BGP structure lookup. */
14874 if (argc == 3)
14875 {
14876 bgp = bgp_lookup_by_name (argv[0]);
14877 if (bgp == NULL)
14878 {
14879 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14880 return CMD_WARNING;
14881 }
14882 }
14883 else
14884 {
14885 bgp = bgp_get_default ();
14886 if (bgp == NULL)
14887 {
14888 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14889 return CMD_WARNING;
14890 }
14891 }
14892
14893 if (argc == 3)
14894 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14895 else
14896 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14897
14898 if (! peer)
14899 return CMD_WARNING;
14900
14901 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14902 {
14903 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14904 VTY_NEWLINE);
14905 return CMD_WARNING;
14906 }
14907
14908 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14909 PEER_FLAG_RSERVER_CLIENT))
14910 {
14911 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14912 VTY_NEWLINE);
14913 return CMD_WARNING;
14914 }
14915
14916 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14917 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014918 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014919}
14920
14921DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14922 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014923 "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 +000014924 SHOW_STR
14925 BGP_STR
14926 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014927 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014928 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014929 "Information about Route Server Client\n"
14930 NEIGHBOR_ADDR_STR
14931 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14932{
14933 struct bgp *bgp;
14934 struct peer *peer;
14935
14936 /* BGP structure lookup. */
14937 if (argc == 3)
14938 {
14939 bgp = bgp_lookup_by_name (argv[0]);
14940 if (bgp == NULL)
14941 {
14942 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14943 return CMD_WARNING;
14944 }
14945 }
14946 else
14947 {
14948 bgp = bgp_get_default ();
14949 if (bgp == NULL)
14950 {
14951 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14952 return CMD_WARNING;
14953 }
14954 }
14955
14956 if (argc == 3)
14957 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14958 else
14959 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14960
14961 if (! peer)
14962 return CMD_WARNING;
14963
14964 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14965 {
14966 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14967 VTY_NEWLINE);
14968 return CMD_WARNING;
14969 }
14970
14971 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14972 PEER_FLAG_RSERVER_CLIENT))
14973 {
14974 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14975 VTY_NEWLINE);
14976 return CMD_WARNING;
14977 }
14978
14979 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14980 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014981 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014982}
14983
Lou Bergerf9b6c392016-01-12 13:42:09 -050014984ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014985 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014986 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14987 SHOW_STR
14988 BGP_STR
14989 "Information about Route Server Client\n"
14990 NEIGHBOR_ADDR_STR
14991 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14992
14993ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14994 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014995 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000014996 SHOW_STR
14997 BGP_STR
14998 "Information about Route Server Client\n"
14999 NEIGHBOR_ADDR_STR
15000 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15001
Michael Lambert95cbbd22010-07-23 14:43:04 -040015002DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15003 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15004 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15005 SHOW_STR
15006 BGP_STR
15007 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000015008 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040015009 "Address family\n"
15010 "Address Family modifier\n"
15011 "Address Family modifier\n"
15012 "Information about Route Server Client\n"
15013 NEIGHBOR_ADDR_STR
15014 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15015{
15016 struct bgp *bgp;
15017 struct peer *peer;
15018 safi_t safi;
15019
15020 /* BGP structure lookup. */
15021 if (argc == 4)
15022 {
15023 bgp = bgp_lookup_by_name (argv[0]);
15024 if (bgp == NULL)
15025 {
15026 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15027 return CMD_WARNING;
15028 }
15029 }
15030 else
15031 {
15032 bgp = bgp_get_default ();
15033 if (bgp == NULL)
15034 {
15035 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15036 return CMD_WARNING;
15037 }
15038 }
15039
15040 if (argc == 4) {
15041 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15042 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15043 } else {
15044 peer = peer_lookup_in_view (vty, NULL, argv[1]);
15045 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15046 }
15047
15048 if (! peer)
15049 return CMD_WARNING;
15050
15051 if (! peer->afc[AFI_IP6][safi])
15052 {
15053 vty_out (vty, "%% Activate the neighbor for the address family first%s",
15054 VTY_NEWLINE);
15055 return CMD_WARNING;
15056}
15057
15058 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15059 PEER_FLAG_RSERVER_CLIENT))
15060{
15061 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15062 VTY_NEWLINE);
15063 return CMD_WARNING;
15064 }
15065
15066 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15067 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070015068 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040015069}
15070
15071ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15072 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15073 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15074 SHOW_STR
15075 BGP_STR
15076 "Address family\n"
15077 "Address Family modifier\n"
15078 "Address Family modifier\n"
15079 "Information about Route Server Client\n"
15080 NEIGHBOR_ADDR_STR
15081 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15082
paul718e3742002-12-13 20:15:29 +000015083struct bgp_table *bgp_distance_table;
15084
15085struct bgp_distance
15086{
15087 /* Distance value for the IP source prefix. */
15088 u_char distance;
15089
15090 /* Name of the access-list to be matched. */
15091 char *access_list;
15092};
15093
paul94f2b392005-06-28 12:44:16 +000015094static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015095bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015096{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015097 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015098}
15099
paul94f2b392005-06-28 12:44:16 +000015100static void
paul718e3742002-12-13 20:15:29 +000015101bgp_distance_free (struct bgp_distance *bdistance)
15102{
15103 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15104}
15105
paul94f2b392005-06-28 12:44:16 +000015106static int
paulfd79ac92004-10-13 05:06:08 +000015107bgp_distance_set (struct vty *vty, const char *distance_str,
15108 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015109{
15110 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015111 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015112 u_char distance;
15113 struct bgp_node *rn;
15114 struct bgp_distance *bdistance;
15115
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015116 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015117 if (ret == 0)
15118 {
15119 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15120 return CMD_WARNING;
15121 }
15122
15123 distance = atoi (distance_str);
15124
15125 /* Get BGP distance node. */
15126 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15127 if (rn->info)
15128 {
15129 bdistance = rn->info;
15130 bgp_unlock_node (rn);
15131 }
15132 else
15133 {
15134 bdistance = bgp_distance_new ();
15135 rn->info = bdistance;
15136 }
15137
15138 /* Set distance value. */
15139 bdistance->distance = distance;
15140
15141 /* Reset access-list configuration. */
15142 if (bdistance->access_list)
15143 {
15144 free (bdistance->access_list);
15145 bdistance->access_list = NULL;
15146 }
15147 if (access_list_str)
15148 bdistance->access_list = strdup (access_list_str);
15149
15150 return CMD_SUCCESS;
15151}
15152
paul94f2b392005-06-28 12:44:16 +000015153static int
paulfd79ac92004-10-13 05:06:08 +000015154bgp_distance_unset (struct vty *vty, const char *distance_str,
15155 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015156{
15157 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015158 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015159 u_char distance;
15160 struct bgp_node *rn;
15161 struct bgp_distance *bdistance;
15162
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015163 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015164 if (ret == 0)
15165 {
15166 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15167 return CMD_WARNING;
15168 }
15169
15170 distance = atoi (distance_str);
15171
15172 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15173 if (! rn)
15174 {
15175 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15176 return CMD_WARNING;
15177 }
15178
15179 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015180
15181 if (bdistance->distance != distance)
15182 {
15183 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15184 return CMD_WARNING;
15185 }
15186
paul718e3742002-12-13 20:15:29 +000015187 if (bdistance->access_list)
15188 free (bdistance->access_list);
15189 bgp_distance_free (bdistance);
15190
15191 rn->info = NULL;
15192 bgp_unlock_node (rn);
15193 bgp_unlock_node (rn);
15194
15195 return CMD_SUCCESS;
15196}
15197
paul718e3742002-12-13 20:15:29 +000015198/* Apply BGP information to distance method. */
15199u_char
15200bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15201{
15202 struct bgp_node *rn;
15203 struct prefix_ipv4 q;
15204 struct peer *peer;
15205 struct bgp_distance *bdistance;
15206 struct access_list *alist;
15207 struct bgp_static *bgp_static;
15208
15209 if (! bgp)
15210 return 0;
15211
15212 if (p->family != AF_INET)
15213 return 0;
15214
15215 peer = rinfo->peer;
15216
15217 if (peer->su.sa.sa_family != AF_INET)
15218 return 0;
15219
15220 memset (&q, 0, sizeof (struct prefix_ipv4));
15221 q.family = AF_INET;
15222 q.prefix = peer->su.sin.sin_addr;
15223 q.prefixlen = IPV4_MAX_BITLEN;
15224
15225 /* Check source address. */
15226 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15227 if (rn)
15228 {
15229 bdistance = rn->info;
15230 bgp_unlock_node (rn);
15231
15232 if (bdistance->access_list)
15233 {
15234 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15235 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15236 return bdistance->distance;
15237 }
15238 else
15239 return bdistance->distance;
15240 }
15241
15242 /* Backdoor check. */
15243 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15244 if (rn)
15245 {
15246 bgp_static = rn->info;
15247 bgp_unlock_node (rn);
15248
15249 if (bgp_static->backdoor)
15250 {
15251 if (bgp->distance_local)
15252 return bgp->distance_local;
15253 else
15254 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15255 }
15256 }
15257
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015258 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015259 {
15260 if (bgp->distance_ebgp)
15261 return bgp->distance_ebgp;
15262 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15263 }
15264 else
15265 {
15266 if (bgp->distance_ibgp)
15267 return bgp->distance_ibgp;
15268 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15269 }
15270}
15271
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015272#ifdef HAVE_IPV6
15273/* Apply BGP information to ipv6 distance method. */
15274u_char
15275ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15276{
15277 struct bgp_node *rn;
15278 struct prefix_ipv6 q;
15279 struct peer *peer;
15280 struct bgp_distance *bdistance;
15281 struct access_list *alist;
15282 struct bgp_static *bgp_static;
15283
15284 if (! bgp)
15285 return 0;
15286
15287 if (p->family != AF_INET6)
15288 return 0;
15289
15290 peer = rinfo->peer;
15291
15292 if (peer->su.sa.sa_family != AF_INET6)
15293 return 0;
15294
15295 memset (&q, 0, sizeof (struct prefix_ipv6));
15296 q.family = AF_INET;
15297 q.prefix = peer->su.sin6.sin6_addr;
15298 q.prefixlen = IPV6_MAX_BITLEN;
15299
15300 /* Check source address. */
15301 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15302 if (rn)
15303 {
15304 bdistance = rn->info;
15305 bgp_unlock_node (rn);
15306
15307 if (bdistance->access_list)
15308 {
15309 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15310 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15311 return bdistance->distance;
15312 }
15313 else
15314 return bdistance->distance;
15315 }
15316 /* Backdoor check. */
15317 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15318 if (rn)
15319 {
15320 bgp_static = rn->info;
15321 bgp_unlock_node (rn);
15322
15323 if (bgp_static->backdoor)
15324 {
15325 if (bgp->ipv6_distance_local)
15326 return bgp->ipv6_distance_local;
15327 else
15328 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15329 }
15330 }
15331
15332 if (peer_sort (peer) == BGP_PEER_EBGP)
15333 {
15334 if (bgp->ipv6_distance_ebgp)
15335 return bgp->ipv6_distance_ebgp;
15336 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15337 }
15338 else
15339 {
15340 if (bgp->ipv6_distance_ibgp)
15341 return bgp->ipv6_distance_ibgp;
15342 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15343 }
15344}
15345#endif /* HAVE_IPV6 */
15346
paul718e3742002-12-13 20:15:29 +000015347DEFUN (bgp_distance,
15348 bgp_distance_cmd,
15349 "distance bgp <1-255> <1-255> <1-255>",
15350 "Define an administrative distance\n"
15351 "BGP distance\n"
15352 "Distance for routes external to the AS\n"
15353 "Distance for routes internal to the AS\n"
15354 "Distance for local routes\n")
15355{
15356 struct bgp *bgp;
15357
15358 bgp = vty->index;
15359
15360 bgp->distance_ebgp = atoi (argv[0]);
15361 bgp->distance_ibgp = atoi (argv[1]);
15362 bgp->distance_local = atoi (argv[2]);
15363 return CMD_SUCCESS;
15364}
15365
15366DEFUN (no_bgp_distance,
15367 no_bgp_distance_cmd,
15368 "no distance bgp <1-255> <1-255> <1-255>",
15369 NO_STR
15370 "Define an administrative distance\n"
15371 "BGP distance\n"
15372 "Distance for routes external to the AS\n"
15373 "Distance for routes internal to the AS\n"
15374 "Distance for local routes\n")
15375{
15376 struct bgp *bgp;
15377
15378 bgp = vty->index;
15379
15380 bgp->distance_ebgp= 0;
15381 bgp->distance_ibgp = 0;
15382 bgp->distance_local = 0;
15383 return CMD_SUCCESS;
15384}
15385
15386ALIAS (no_bgp_distance,
15387 no_bgp_distance2_cmd,
15388 "no distance bgp",
15389 NO_STR
15390 "Define an administrative distance\n"
15391 "BGP distance\n")
15392
15393DEFUN (bgp_distance_source,
15394 bgp_distance_source_cmd,
15395 "distance <1-255> A.B.C.D/M",
15396 "Define an administrative distance\n"
15397 "Administrative distance\n"
15398 "IP source prefix\n")
15399{
15400 bgp_distance_set (vty, argv[0], argv[1], NULL);
15401 return CMD_SUCCESS;
15402}
15403
15404DEFUN (no_bgp_distance_source,
15405 no_bgp_distance_source_cmd,
15406 "no distance <1-255> A.B.C.D/M",
15407 NO_STR
15408 "Define an administrative distance\n"
15409 "Administrative distance\n"
15410 "IP source prefix\n")
15411{
15412 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15413 return CMD_SUCCESS;
15414}
15415
15416DEFUN (bgp_distance_source_access_list,
15417 bgp_distance_source_access_list_cmd,
15418 "distance <1-255> A.B.C.D/M WORD",
15419 "Define an administrative distance\n"
15420 "Administrative distance\n"
15421 "IP source prefix\n"
15422 "Access list name\n")
15423{
15424 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15425 return CMD_SUCCESS;
15426}
15427
15428DEFUN (no_bgp_distance_source_access_list,
15429 no_bgp_distance_source_access_list_cmd,
15430 "no distance <1-255> A.B.C.D/M WORD",
15431 NO_STR
15432 "Define an administrative distance\n"
15433 "Administrative distance\n"
15434 "IP source prefix\n"
15435 "Access list name\n")
15436{
15437 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15438 return CMD_SUCCESS;
15439}
David Lamparter6b0655a2014-06-04 06:53:35 +020015440
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015441#ifdef HAVE_IPV6
15442DEFUN (ipv6_bgp_distance,
15443 ipv6_bgp_distance_cmd,
15444 "distance bgp <1-255> <1-255> <1-255>",
15445 "Define an administrative distance\n"
15446 "BGP distance\n"
15447 "Distance for routes external to the AS\n"
15448 "Distance for routes internal to the AS\n"
15449 "Distance for local routes\n")
15450{
15451 struct bgp *bgp;
15452
15453 bgp = vty->index;
15454
15455 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15456 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15457 bgp->ipv6_distance_local = atoi (argv[2]);
15458 return CMD_SUCCESS;
15459}
15460
15461DEFUN (no_ipv6_bgp_distance,
15462 no_ipv6_bgp_distance_cmd,
15463 "no distance bgp <1-255> <1-255> <1-255>",
15464 NO_STR
15465 "Define an administrative distance\n"
15466 "BGP distance\n"
15467 "Distance for routes external to the AS\n"
15468 "Distance for routes internal to the AS\n"
15469 "Distance for local routes\n")
15470{
15471 struct bgp *bgp;
15472
15473 bgp = vty->index;
15474
15475 bgp->ipv6_distance_ebgp= 0;
15476 bgp->ipv6_distance_ibgp = 0;
15477 bgp->ipv6_distance_local = 0;
15478 return CMD_SUCCESS;
15479}
15480
15481ALIAS (no_ipv6_bgp_distance,
15482 no_ipv6_bgp_distance2_cmd,
15483 "no distance bgp",
15484 NO_STR
15485 "Define an administrative distance\n"
15486 "BGP distance\n")
15487
15488DEFUN (ipv6_bgp_distance_source,
15489 ipv6_bgp_distance_source_cmd,
15490 "distance <1-255> X:X::X:X/M",
15491 "Define an administrative distance\n"
15492 "Administrative distance\n"
15493 "IP source prefix\n")
15494{
15495 bgp_distance_set (vty, argv[0], argv[1], NULL);
15496 return CMD_SUCCESS;
15497}
15498
15499DEFUN (no_ipv6_bgp_distance_source,
15500 no_ipv6_bgp_distance_source_cmd,
15501 "no distance <1-255> X:X::X:X/M",
15502 NO_STR
15503 "Define an administrative distance\n"
15504 "Administrative distance\n"
15505 "IP source prefix\n")
15506{
15507 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15508 return CMD_SUCCESS;
15509}
15510
15511DEFUN (ipv6_bgp_distance_source_access_list,
15512 ipv6_bgp_distance_source_access_list_cmd,
15513 "distance <1-255> X:X::X:X/M WORD",
15514 "Define an administrative distance\n"
15515 "Administrative distance\n"
15516 "IP source prefix\n"
15517 "Access list name\n")
15518{
15519 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15520 return CMD_SUCCESS;
15521}
15522
15523DEFUN (no_ipv6_bgp_distance_source_access_list,
15524 no_ipv6_bgp_distance_source_access_list_cmd,
15525 "no distance <1-255> X:X::X:X/M WORD",
15526 NO_STR
15527 "Define an administrative distance\n"
15528 "Administrative distance\n"
15529 "IP source prefix\n"
15530 "Access list name\n")
15531{
15532 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15533 return CMD_SUCCESS;
15534}
15535#endif
15536
paul718e3742002-12-13 20:15:29 +000015537DEFUN (bgp_damp_set,
15538 bgp_damp_set_cmd,
15539 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15540 "BGP Specific commands\n"
15541 "Enable route-flap dampening\n"
15542 "Half-life time for the penalty\n"
15543 "Value to start reusing a route\n"
15544 "Value to start suppressing a route\n"
15545 "Maximum duration to suppress a stable route\n")
15546{
15547 struct bgp *bgp;
15548 int half = DEFAULT_HALF_LIFE * 60;
15549 int reuse = DEFAULT_REUSE;
15550 int suppress = DEFAULT_SUPPRESS;
15551 int max = 4 * half;
15552
15553 if (argc == 4)
15554 {
15555 half = atoi (argv[0]) * 60;
15556 reuse = atoi (argv[1]);
15557 suppress = atoi (argv[2]);
15558 max = atoi (argv[3]) * 60;
15559 }
15560 else if (argc == 1)
15561 {
15562 half = atoi (argv[0]) * 60;
15563 max = 4 * half;
15564 }
15565
15566 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015567
15568 if (suppress < reuse)
15569 {
15570 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15571 VTY_NEWLINE);
15572 return 0;
15573 }
15574
paul718e3742002-12-13 20:15:29 +000015575 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15576 half, reuse, suppress, max);
15577}
15578
15579ALIAS (bgp_damp_set,
15580 bgp_damp_set2_cmd,
15581 "bgp dampening <1-45>",
15582 "BGP Specific commands\n"
15583 "Enable route-flap dampening\n"
15584 "Half-life time for the penalty\n")
15585
15586ALIAS (bgp_damp_set,
15587 bgp_damp_set3_cmd,
15588 "bgp dampening",
15589 "BGP Specific commands\n"
15590 "Enable route-flap dampening\n")
15591
15592DEFUN (bgp_damp_unset,
15593 bgp_damp_unset_cmd,
15594 "no bgp dampening",
15595 NO_STR
15596 "BGP Specific commands\n"
15597 "Enable route-flap dampening\n")
15598{
15599 struct bgp *bgp;
15600
15601 bgp = vty->index;
15602 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15603}
15604
15605ALIAS (bgp_damp_unset,
15606 bgp_damp_unset2_cmd,
15607 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15608 NO_STR
15609 "BGP Specific commands\n"
15610 "Enable route-flap dampening\n"
15611 "Half-life time for the penalty\n"
15612 "Value to start reusing a route\n"
15613 "Value to start suppressing a route\n"
15614 "Maximum duration to suppress a stable route\n")
15615
Lou Bergerf9b6c392016-01-12 13:42:09 -050015616DEFUN (show_ip_bgp_dampened_paths,
15617 show_ip_bgp_dampened_paths_cmd,
15618 "show ip bgp dampened-paths",
15619 SHOW_STR
15620 IP_STR
15621 BGP_STR
15622 "Display paths suppressed due to dampening\n")
15623{
15624 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15625 NULL);
15626}
15627
15628ALIAS (show_ip_bgp_dampened_paths,
15629 show_ip_bgp_damp_dampened_paths_cmd,
15630 "show ip bgp dampening dampened-paths",
15631 SHOW_STR
15632 IP_STR
15633 BGP_STR
15634 "Display detailed information about dampening\n"
15635 "Display paths suppressed due to dampening\n")
15636
15637DEFUN (show_ip_bgp_flap_statistics,
15638 show_ip_bgp_flap_statistics_cmd,
15639 "show ip bgp flap-statistics",
15640 SHOW_STR
15641 IP_STR
15642 BGP_STR
15643 "Display flap statistics of routes\n")
15644{
15645 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15646 bgp_show_type_flap_statistics, NULL);
15647}
15648
15649ALIAS (show_ip_bgp_flap_statistics,
15650 show_ip_bgp_damp_flap_statistics_cmd,
15651 "show ip bgp dampening flap-statistics",
15652 SHOW_STR
15653 IP_STR
15654 BGP_STR
15655 "Display detailed information about dampening\n"
15656 "Display flap statistics of routes\n")
15657
Lou Berger651b4022016-01-12 13:42:07 -050015658DEFUN (show_bgp_ipv4_safi_dampened_paths,
15659 show_bgp_ipv4_safi_dampened_paths_cmd,
15660 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015661 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015662 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015663 IP_STR
15664 "Address Family modifier\n"
15665 "Address Family modifier\n"
15666 "Address Family modifier\n"
15667 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015668 "Display paths suppressed due to dampening\n")
15669{
Lou Berger651b4022016-01-12 13:42:07 -050015670 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015671
Lou Berger651b4022016-01-12 13:42:07 -050015672 if (bgp_parse_safi(argv[0], &safi)) {
15673 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15674 return CMD_WARNING;
15675 }
15676
15677 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15678}
15679ALIAS (show_bgp_ipv4_safi_dampened_paths,
15680 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15681 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015682 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015683 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015684 IP_STR
15685 "Address Family modifier\n"
15686 "Address Family modifier\n"
15687 "Address Family modifier\n"
15688 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015689 "Display detailed information about dampening\n"
15690 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015691
Lou Berger651b4022016-01-12 13:42:07 -050015692DEFUN (show_bgp_ipv6_safi_dampened_paths,
15693 show_bgp_ipv6_safi_dampened_paths_cmd,
15694 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015695 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015696 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015697 IPV6_STR
15698 "Address Family modifier\n"
15699 "Address Family modifier\n"
15700 "Address Family modifier\n"
15701 "Address Family modifier\n"
15702 "Display paths suppressed due to dampening\n")
15703{
15704 safi_t safi;
15705
15706 if (bgp_parse_safi(argv[0], &safi)) {
15707 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15708 return CMD_WARNING;
15709 }
15710
15711 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15712}
15713ALIAS (show_bgp_ipv6_safi_dampened_paths,
15714 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15715 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15716 SHOW_STR
15717 BGP_STR
15718 IPV6_STR
15719 "Address Family modifier\n"
15720 "Address Family modifier\n"
15721 "Address Family modifier\n"
15722 "Address Family modifier\n"
15723 "Display detailed information about dampening\n"
15724 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015725
15726DEFUN (show_bgp_ipv4_safi_flap_statistics,
15727 show_bgp_ipv4_safi_flap_statistics_cmd,
15728 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15729 SHOW_STR
15730 BGP_STR
15731 "Address Family\n"
15732 "Address Family modifier\n"
15733 "Address Family modifier\n"
15734 "Address Family modifier\n"
15735 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015736 "Display flap statistics of routes\n")
15737{
Lou Berger651b4022016-01-12 13:42:07 -050015738 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015739
Lou Berger651b4022016-01-12 13:42:07 -050015740 if (bgp_parse_safi(argv[0], &safi)) {
15741 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15742 return CMD_WARNING;
15743 }
15744
15745 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15746}
15747ALIAS (show_bgp_ipv4_safi_flap_statistics,
15748 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15749 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015750 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015751 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015752 "Address Family\n"
15753 "Address Family modifier\n"
15754 "Address Family modifier\n"
15755 "Address Family modifier\n"
15756 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015757 "Display detailed information about dampening\n"
15758 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015759
Lou Berger651b4022016-01-12 13:42:07 -050015760DEFUN (show_bgp_ipv6_safi_flap_statistics,
15761 show_bgp_ipv6_safi_flap_statistics_cmd,
15762 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15763 SHOW_STR
15764 BGP_STR
15765 "Address Family\n"
15766 "Address Family modifier\n"
15767 "Address Family modifier\n"
15768 "Address Family modifier\n"
15769 "Address Family modifier\n"
15770 "Display flap statistics of routes\n")
15771{
15772 safi_t safi;
15773
15774 if (bgp_parse_safi(argv[0], &safi)) {
15775 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15776 return CMD_WARNING;
15777 }
15778
15779 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15780}
15781ALIAS (show_bgp_ipv6_safi_flap_statistics,
15782 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15783 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15784 SHOW_STR
15785 BGP_STR
15786 "Address Family\n"
15787 "Address Family modifier\n"
15788 "Address Family modifier\n"
15789 "Address Family modifier\n"
15790 "Address Family modifier\n"
15791 "Display detailed information about dampening\n"
15792 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015793
paul718e3742002-12-13 20:15:29 +000015794/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015795static int
paulfd79ac92004-10-13 05:06:08 +000015796bgp_clear_damp_route (struct vty *vty, const char *view_name,
15797 const char *ip_str, afi_t afi, safi_t safi,
15798 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015799{
15800 int ret;
15801 struct prefix match;
15802 struct bgp_node *rn;
15803 struct bgp_node *rm;
15804 struct bgp_info *ri;
15805 struct bgp_info *ri_temp;
15806 struct bgp *bgp;
15807 struct bgp_table *table;
15808
15809 /* BGP structure lookup. */
15810 if (view_name)
15811 {
15812 bgp = bgp_lookup_by_name (view_name);
15813 if (bgp == NULL)
15814 {
15815 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15816 return CMD_WARNING;
15817 }
15818 }
15819 else
15820 {
15821 bgp = bgp_get_default ();
15822 if (bgp == NULL)
15823 {
15824 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15825 return CMD_WARNING;
15826 }
15827 }
15828
15829 /* Check IP address argument. */
15830 ret = str2prefix (ip_str, &match);
15831 if (! ret)
15832 {
15833 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15834 return CMD_WARNING;
15835 }
15836
15837 match.family = afi2family (afi);
15838
Lou Berger298cc2f2016-01-12 13:42:02 -050015839 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015840 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015841 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015842 {
15843 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15844 continue;
15845
15846 if ((table = rn->info) != NULL)
15847 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015848 {
15849 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15850 {
15851 ri = rm->info;
15852 while (ri)
15853 {
15854 if (ri->extra && ri->extra->damp_info)
15855 {
15856 ri_temp = ri->next;
15857 bgp_damp_info_free (ri->extra->damp_info, 1);
15858 ri = ri_temp;
15859 }
15860 else
15861 ri = ri->next;
15862 }
15863 }
15864
15865 bgp_unlock_node (rm);
15866 }
paul718e3742002-12-13 20:15:29 +000015867 }
15868 }
15869 else
15870 {
15871 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015872 {
15873 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15874 {
15875 ri = rn->info;
15876 while (ri)
15877 {
15878 if (ri->extra && ri->extra->damp_info)
15879 {
15880 ri_temp = ri->next;
15881 bgp_damp_info_free (ri->extra->damp_info, 1);
15882 ri = ri_temp;
15883 }
15884 else
15885 ri = ri->next;
15886 }
15887 }
15888
15889 bgp_unlock_node (rn);
15890 }
paul718e3742002-12-13 20:15:29 +000015891 }
15892
15893 return CMD_SUCCESS;
15894}
15895
15896DEFUN (clear_ip_bgp_dampening,
15897 clear_ip_bgp_dampening_cmd,
15898 "clear ip bgp dampening",
15899 CLEAR_STR
15900 IP_STR
15901 BGP_STR
15902 "Clear route flap dampening information\n")
15903{
15904 bgp_damp_info_clean ();
15905 return CMD_SUCCESS;
15906}
15907
15908DEFUN (clear_ip_bgp_dampening_prefix,
15909 clear_ip_bgp_dampening_prefix_cmd,
15910 "clear ip bgp dampening A.B.C.D/M",
15911 CLEAR_STR
15912 IP_STR
15913 BGP_STR
15914 "Clear route flap dampening information\n"
15915 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15916{
15917 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15918 SAFI_UNICAST, NULL, 1);
15919}
15920
15921DEFUN (clear_ip_bgp_dampening_address,
15922 clear_ip_bgp_dampening_address_cmd,
15923 "clear ip bgp dampening A.B.C.D",
15924 CLEAR_STR
15925 IP_STR
15926 BGP_STR
15927 "Clear route flap dampening information\n"
15928 "Network to clear damping information\n")
15929{
15930 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15931 SAFI_UNICAST, NULL, 0);
15932}
15933
15934DEFUN (clear_ip_bgp_dampening_address_mask,
15935 clear_ip_bgp_dampening_address_mask_cmd,
15936 "clear ip bgp dampening A.B.C.D A.B.C.D",
15937 CLEAR_STR
15938 IP_STR
15939 BGP_STR
15940 "Clear route flap dampening information\n"
15941 "Network to clear damping information\n"
15942 "Network mask\n")
15943{
15944 int ret;
15945 char prefix_str[BUFSIZ];
15946
15947 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15948 if (! ret)
15949 {
15950 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15951 return CMD_WARNING;
15952 }
15953
15954 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15955 SAFI_UNICAST, NULL, 0);
15956}
David Lamparter6b0655a2014-06-04 06:53:35 +020015957
Lou Berger298cc2f2016-01-12 13:42:02 -050015958/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015959static int
paul718e3742002-12-13 20:15:29 +000015960bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15961 afi_t afi, safi_t safi, int *write)
15962{
15963 struct bgp_node *prn;
15964 struct bgp_node *rn;
15965 struct bgp_table *table;
15966 struct prefix *p;
15967 struct prefix_rd *prd;
15968 struct bgp_static *bgp_static;
15969 u_int32_t label;
15970 char buf[SU_ADDRSTRLEN];
15971 char rdbuf[RD_ADDRSTRLEN];
15972
15973 /* Network configuration. */
15974 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15975 if ((table = prn->info) != NULL)
15976 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15977 if ((bgp_static = rn->info) != NULL)
15978 {
15979 p = &rn->p;
15980 prd = (struct prefix_rd *) &prn->p;
15981
15982 /* "address-family" display. */
15983 bgp_config_write_family_header (vty, afi, safi, write);
15984
15985 /* "network" configuration display. */
15986 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15987 label = decode_label (bgp_static->tag);
15988
15989 vty_out (vty, " network %s/%d rd %s tag %d",
15990 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15991 p->prefixlen,
15992 rdbuf, label);
15993 vty_out (vty, "%s", VTY_NEWLINE);
15994 }
15995 return 0;
15996}
15997
15998/* Configuration of static route announcement and aggregate
15999 information. */
16000int
16001bgp_config_write_network (struct vty *vty, struct bgp *bgp,
16002 afi_t afi, safi_t safi, int *write)
16003{
16004 struct bgp_node *rn;
16005 struct prefix *p;
16006 struct bgp_static *bgp_static;
16007 struct bgp_aggregate *bgp_aggregate;
16008 char buf[SU_ADDRSTRLEN];
16009
Lou Berger298cc2f2016-01-12 13:42:02 -050016010 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000016011 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
16012
16013 /* Network configuration. */
16014 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
16015 if ((bgp_static = rn->info) != NULL)
16016 {
16017 p = &rn->p;
16018
16019 /* "address-family" display. */
16020 bgp_config_write_family_header (vty, afi, safi, write);
16021
16022 /* "network" configuration display. */
16023 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16024 {
16025 u_int32_t destination;
16026 struct in_addr netmask;
16027
16028 destination = ntohl (p->u.prefix4.s_addr);
16029 masklen2ip (p->prefixlen, &netmask);
16030 vty_out (vty, " network %s",
16031 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
16032
16033 if ((IN_CLASSC (destination) && p->prefixlen == 24)
16034 || (IN_CLASSB (destination) && p->prefixlen == 16)
16035 || (IN_CLASSA (destination) && p->prefixlen == 8)
16036 || p->u.prefix4.s_addr == 0)
16037 {
16038 /* Natural mask is not display. */
16039 }
16040 else
16041 vty_out (vty, " mask %s", inet_ntoa (netmask));
16042 }
16043 else
16044 {
16045 vty_out (vty, " network %s/%d",
16046 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16047 p->prefixlen);
16048 }
16049
16050 if (bgp_static->rmap.name)
16051 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000016052 else
16053 {
16054 if (bgp_static->backdoor)
16055 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000016056 }
paul718e3742002-12-13 20:15:29 +000016057
16058 vty_out (vty, "%s", VTY_NEWLINE);
16059 }
16060
16061 /* Aggregate-address configuration. */
16062 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
16063 if ((bgp_aggregate = rn->info) != NULL)
16064 {
16065 p = &rn->p;
16066
16067 /* "address-family" display. */
16068 bgp_config_write_family_header (vty, afi, safi, write);
16069
16070 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16071 {
16072 struct in_addr netmask;
16073
16074 masklen2ip (p->prefixlen, &netmask);
16075 vty_out (vty, " aggregate-address %s %s",
16076 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16077 inet_ntoa (netmask));
16078 }
16079 else
16080 {
16081 vty_out (vty, " aggregate-address %s/%d",
16082 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16083 p->prefixlen);
16084 }
16085
16086 if (bgp_aggregate->as_set)
16087 vty_out (vty, " as-set");
16088
16089 if (bgp_aggregate->summary_only)
16090 vty_out (vty, " summary-only");
16091
16092 vty_out (vty, "%s", VTY_NEWLINE);
16093 }
16094
16095 return 0;
16096}
16097
16098int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016099bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
16100 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000016101{
16102 struct bgp_node *rn;
16103 struct bgp_distance *bdistance;
16104
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016105 if (afi == AFI_IP && safi == SAFI_UNICAST)
16106 {
16107 /* Distance configuration. */
16108 if (bgp->distance_ebgp
16109 && bgp->distance_ibgp
16110 && bgp->distance_local
16111 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16112 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16113 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16114 vty_out (vty, " distance bgp %d %d %d%s",
16115 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
16116 VTY_NEWLINE);
16117
16118 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16119 if ((bdistance = rn->info) != NULL)
16120 {
16121 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16122 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
16123 bdistance->access_list ? bdistance->access_list : "",
16124 VTY_NEWLINE);
16125 }
16126 }
16127
16128#ifdef HAVE_IPV6
16129 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
16130 {
16131 bgp_config_write_family_header (vty, afi, safi, write);
16132 if (bgp->ipv6_distance_ebgp
16133 && bgp->ipv6_distance_ibgp
16134 && bgp->ipv6_distance_local
16135 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16136 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16137 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16138 vty_out (vty, " distance bgp %d %d %d%s",
16139 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
16140 VTY_NEWLINE);
16141
16142 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16143 if ((bdistance = rn->info) != NULL)
16144 {
16145 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16146 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
16147 bdistance->access_list ? bdistance->access_list : "",
16148 VTY_NEWLINE);
16149 }
16150 }
16151#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016152
16153 return 0;
16154}
16155
16156/* Allocate routing table structure and install commands. */
16157void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080016158bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000016159{
16160 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000016161 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000016162
16163 /* IPv4 BGP commands. */
16164 install_element (BGP_NODE, &bgp_network_cmd);
16165 install_element (BGP_NODE, &bgp_network_mask_cmd);
16166 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
16167 install_element (BGP_NODE, &bgp_network_route_map_cmd);
16168 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
16169 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
16170 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
16171 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
16172 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
16173 install_element (BGP_NODE, &no_bgp_network_cmd);
16174 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
16175 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
16176 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
16177 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
16178 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16179 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
16180 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
16181 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
16182
16183 install_element (BGP_NODE, &aggregate_address_cmd);
16184 install_element (BGP_NODE, &aggregate_address_mask_cmd);
16185 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
16186 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
16187 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
16188 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
16189 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
16190 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
16191 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
16192 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
16193 install_element (BGP_NODE, &no_aggregate_address_cmd);
16194 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
16195 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
16196 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
16197 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
16198 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
16199 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
16200 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
16201 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16202 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16203
16204 /* IPv4 unicast configuration. */
16205 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16206 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16207 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16208 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16209 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16210 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016211 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016212 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16213 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16214 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16215 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16216 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016217
paul718e3742002-12-13 20:15:29 +000016218 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16219 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16220 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16221 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16222 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16223 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16224 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16225 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16226 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16227 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16228 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16229 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16230 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16231 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16232 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16233 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16234 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16235 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16236 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16237 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16238
16239 /* IPv4 multicast configuration. */
16240 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16241 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16242 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16243 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16244 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16245 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16246 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16247 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16248 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16249 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16250 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16251 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16252 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16253 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16254 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16255 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16256 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16257 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16258 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16259 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16260 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16261 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16262 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16263 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16264 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16265 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16266 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16267 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16268 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16269 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16270 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16271 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16272
Michael Lambert95cbbd22010-07-23 14:43:04 -040016273 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016274 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016275 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16276 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16277 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16278 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16279 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16280 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16281 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16282 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16283 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016284 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016285 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16286 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16287 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16288 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16289 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16290 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16291 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16292 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16293 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16294 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16295 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16296 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16297 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16298 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16299 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16300 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16301 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16302 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16303 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16304 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16305 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16306 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16307 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16308 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16309 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16310 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16311 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16312 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016313 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16314 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16315 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16316 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16317 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016318 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16319 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16320 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16321 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16322 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16323 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16324 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16325 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16326 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16327 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16328 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16329 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16330 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16331 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16332 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16333 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16334 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16335 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16336 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016337 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016338 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16341 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16342 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16346 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16347 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16348 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16349 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16350 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16351 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16352 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16353 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16354 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16356 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16357 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16358 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16359 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16360 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16361 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16362 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16363 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16364 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16365 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16366 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16367 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16368 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16369 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16370 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16371 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16372 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16373 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16374 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16375 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16376 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16377 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16378 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16379 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16380 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16381 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16382 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016383 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016384 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016385 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016386 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016387 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016388 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016389
16390 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016391 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016392 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16393 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16394 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16395 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16396 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016397 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016398 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16399 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16400 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16401 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16402 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16403 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16404 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16405 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16406 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16407 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16408 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16409 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16410 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16411 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16412 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16413 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016414 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16415 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16416 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16417 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16418 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016419 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16420 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16421 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16422 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16423 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16424 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16425 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16426 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016427 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016428 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016429 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016430 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016431
Donald Sharp68b45cc2016-03-11 14:27:13 -050016432 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016433 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16434 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16435 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16436 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16437
paul718e3742002-12-13 20:15:29 +000016438 /* New config IPv6 BGP commands. */
16439 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16440 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16441 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16442 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16443
16444 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16445 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16446 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16447 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16448
G.Balaji73bfe0b2011-09-23 22:36:20 +053016449 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16450 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16451
paul718e3742002-12-13 20:15:29 +000016452 /* Old config IPv6 BGP commands. */
16453 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16454 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16455
16456 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16457 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16458 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16459 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16460
Michael Lambert95cbbd22010-07-23 14:43:04 -040016461 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016462 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016463 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016464 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016465 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016466 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016467 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016468 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016469 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016470 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16471 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16472 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16473 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16474 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16475 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16476 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16477 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016478 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016479 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016480 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016481 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016482 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016483 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016484 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016485 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016486 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16487 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016488 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016489 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016490 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016491 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016492 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016493 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016494 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016495 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016496 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016497 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016498 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016499 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016500 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016501 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016502 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16503 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016504 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016505 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016506 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016507 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016508 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016509
16510 /* Restricted:
16511 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16512 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016513 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016514 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016515 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016516 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016517 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16518 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16519 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16520 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16521 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16522 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16523 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16524 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16525 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016526 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016527 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016528 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016529 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016530 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016531 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016532 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016533 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016534 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016535 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016536
Paul Jakma2815e612006-09-14 02:56:07 +000016537 /* Statistics */
16538 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016539 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016540
16541 install_element (BGP_NODE, &bgp_distance_cmd);
16542 install_element (BGP_NODE, &no_bgp_distance_cmd);
16543 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16544 install_element (BGP_NODE, &bgp_distance_source_cmd);
16545 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16546 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16547 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016548#ifdef HAVE_IPV6
16549 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16550 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16551 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16552 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16553 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16554 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16555 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16556#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016557
16558 install_element (BGP_NODE, &bgp_damp_set_cmd);
16559 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16560 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16561 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16562 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16563 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16564 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16565 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16566 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16567 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016568
16569 /* IPv4 Multicast Mode */
16570 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16571 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16572 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16573 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16574 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16575
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016576
16577 /* Deprecated AS-Pathlimit commands */
16578 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16579 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16580 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16581 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16582 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16583 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16584
16585 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16586 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16587 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16588 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16589 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16590 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16591
16592 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16593 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16594 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16595 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16596 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16597 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16598
16599 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16600 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16601 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16602 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16603 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16604 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16605
16606 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16607 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16608 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16609 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16610 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16611 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16612
16613 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16614 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16615 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16616 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16617 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16618 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016619
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016620 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16621 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016622
16623 /* old style commands */
16624 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16625 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16626 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016627 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
16628 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016629 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16630 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16631 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16632 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16633 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016634 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16635 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16636 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016637 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16638 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16639 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16640 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16641 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16642 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16643 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16644 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16645 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16646 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16648 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16650 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16651 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16652 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16653 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16654 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16655 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16656 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16657 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16658 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16659 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16660 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16661 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16662 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16663 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16664 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16665 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16666 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16667 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16668 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16669 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16670 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16671 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16672 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16673 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16674 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16675 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16676 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16677 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16678 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16679 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16680 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16681 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16682 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16683 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16684 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016686 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016687 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16688 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016689 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16690 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16691 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16692 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16693 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16694 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16695 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16696 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16697 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16698 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16699 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16700 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16701 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16702 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16703 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16704 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16705 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16706 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16707 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16708 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16709 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16710 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16711 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16712 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16713 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16714 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16715 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016716
Lou Bergerf9b6c392016-01-12 13:42:09 -050016717 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016718 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
16719 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016720 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16721 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16722 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16723 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016724 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16725 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16726 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016727 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16728 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16729 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16730 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16731 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16732 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16733 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16734 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16735 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16736 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16737 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16738 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16739 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16740 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16741 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16742 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16743 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16744 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16745 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16746 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16747 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16748 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16749 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16750 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016751
16752 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16754 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016755
Lou Bergerf9b6c392016-01-12 13:42:09 -050016756 install_element (VIEW_NODE, &show_bgp_cmd);
16757 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16758 install_element (VIEW_NODE, &show_bgp_route_cmd);
16759 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016760 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
16761 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16763 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
16764 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016766 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16767 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16768 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16769 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16770 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16771 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16772 install_element (VIEW_NODE, &show_bgp_community_cmd);
16773 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16774 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16775 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16776 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16777 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16778 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16779 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16780 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16781 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16782 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16783 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16784 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16785 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16786 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16787 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16788 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16789 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16790 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16791 install_element (VIEW_NODE, &show_bgp_view_cmd);
16792 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16793 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16794 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16795 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16796 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16797 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16798 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16799 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16800 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016801
Lou Bergerf9b6c392016-01-12 13:42:09 -050016802 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16803 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016804 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
16805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16807 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
16808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016810 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16811 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16812 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16813 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16814 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16815 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16816 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16817 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16818 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16819 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16820 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016821
Lou Bergerf9b6c392016-01-12 13:42:09 -050016822 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16823 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016824
Lou Bergerf9b6c392016-01-12 13:42:09 -050016825 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16826 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16827 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16828 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16829 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16830 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16831 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16832 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16833 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16834 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16835 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16836 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16837 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16838 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16839 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16857 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16858 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16859 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16860 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016861 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016862 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016863 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016864 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016865 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016866 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016867 /* old with name safi collision */
16868 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16869 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16870 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16871 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16872 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16873 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16874 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16875 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16876 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16877 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16878 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16879 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16880 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16881 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16882 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16883 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016884
Lou Bergerf9b6c392016-01-12 13:42:09 -050016885 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16886 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016887
16888 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16889 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16890 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16891 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016892
16893 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16894 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16895 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16896 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016897}
Chris Caputo228da422009-07-18 05:44:03 +000016898
16899void
16900bgp_route_finish (void)
16901{
16902 bgp_table_unlock (bgp_distance_table);
16903 bgp_distance_table = NULL;
16904}