blob: 7f98f94f6dd655427a12008ccff8b1130b467237 [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;
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004756 u_char atomic_aggregate = 0;
paul718e3742002-12-13 20:15:29 +00004757
paul718e3742002-12-13 20:15:29 +00004758 /* ORIGIN attribute: If at least one route among routes that are
4759 aggregated has ORIGIN with the value INCOMPLETE, then the
4760 aggregated route must have the ORIGIN attribute with the value
4761 INCOMPLETE. Otherwise, if at least one route among routes that
4762 are aggregated has ORIGIN with the value EGP, then the aggregated
4763 route must have the origin attribute with the value EGP. In all
4764 other case the value of the ORIGIN attribute of the aggregated
4765 route is INTERNAL. */
4766 origin = BGP_ORIGIN_IGP;
4767
4768 table = bgp->rib[afi][safi];
4769
4770 top = bgp_node_get (table, p);
4771 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4772 if (rn->p.prefixlen > p->prefixlen)
4773 {
4774 match = 0;
4775
4776 for (ri = rn->info; ri; ri = ri->next)
4777 {
4778 if (BGP_INFO_HOLDDOWN (ri))
4779 continue;
4780
4781 if (del && ri == del)
4782 continue;
4783
4784 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004785 first = 0;
paul718e3742002-12-13 20:15:29 +00004786
4787#ifdef AGGREGATE_NEXTHOP_CHECK
4788 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4789 || ri->attr->med != med)
4790 {
4791 if (aspath)
4792 aspath_free (aspath);
4793 if (community)
4794 community_free (community);
4795 bgp_unlock_node (rn);
4796 bgp_unlock_node (top);
4797 return;
4798 }
4799#endif /* AGGREGATE_NEXTHOP_CHECK */
4800
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004801 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
4802 atomic_aggregate = 1;
4803
paul718e3742002-12-13 20:15:29 +00004804 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4805 {
4806 if (aggregate->summary_only)
4807 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004808 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004809 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004810 match++;
4811 }
4812
4813 aggregate->count++;
4814
Daniel Walton76a72802015-05-19 17:47:24 -07004815 if (origin < ri->attr->origin)
4816 origin = ri->attr->origin;
4817
paul718e3742002-12-13 20:15:29 +00004818 if (aggregate->as_set)
4819 {
paul718e3742002-12-13 20:15:29 +00004820 if (aspath)
4821 {
4822 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4823 aspath_free (aspath);
4824 aspath = asmerge;
4825 }
4826 else
4827 aspath = aspath_dup (ri->attr->aspath);
4828
4829 if (ri->attr->community)
4830 {
4831 if (community)
4832 {
4833 commerge = community_merge (community,
4834 ri->attr->community);
4835 community = community_uniq_sort (commerge);
4836 community_free (commerge);
4837 }
4838 else
4839 community = community_dup (ri->attr->community);
4840 }
4841 }
4842 }
4843 }
4844 if (match)
4845 bgp_process (bgp, rn, afi, safi);
4846 }
4847 bgp_unlock_node (top);
4848
4849 if (rinew)
4850 {
4851 aggregate->count++;
4852
4853 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004854 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004855
Daniel Walton76a72802015-05-19 17:47:24 -07004856 if (origin < rinew->attr->origin)
4857 origin = rinew->attr->origin;
4858
paul718e3742002-12-13 20:15:29 +00004859 if (aggregate->as_set)
4860 {
paul718e3742002-12-13 20:15:29 +00004861 if (aspath)
4862 {
4863 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4864 aspath_free (aspath);
4865 aspath = asmerge;
4866 }
4867 else
4868 aspath = aspath_dup (rinew->attr->aspath);
4869
4870 if (rinew->attr->community)
4871 {
4872 if (community)
4873 {
4874 commerge = community_merge (community,
4875 rinew->attr->community);
4876 community = community_uniq_sort (commerge);
4877 community_free (commerge);
4878 }
4879 else
4880 community = community_dup (rinew->attr->community);
4881 }
4882 }
4883 }
4884
4885 if (aggregate->count > 0)
4886 {
4887 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004888 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4889 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004890 aggregate->as_set,
4891 atomic_aggregate), rn);
paul718e3742002-12-13 20:15:29 +00004892 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004893
4894 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004895 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004896 bgp_process (bgp, rn, afi, safi);
4897 }
4898 else
4899 {
4900 if (aspath)
4901 aspath_free (aspath);
4902 if (community)
4903 community_free (community);
4904 }
4905}
4906
4907void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4908 struct bgp_aggregate *);
4909
4910void
4911bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4912 struct bgp_info *ri, afi_t afi, safi_t safi)
4913{
4914 struct bgp_node *child;
4915 struct bgp_node *rn;
4916 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004917 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004918
4919 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004920 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004921 return;
4922
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004923 table = bgp->aggregate[afi][safi];
4924
4925 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004926 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004927 return;
4928
paul718e3742002-12-13 20:15:29 +00004929 if (p->prefixlen == 0)
4930 return;
4931
4932 if (BGP_INFO_HOLDDOWN (ri))
4933 return;
4934
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004935 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004936
4937 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004938 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004939 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4940 {
4941 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004942 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004943 }
4944 bgp_unlock_node (child);
4945}
4946
4947void
4948bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4949 struct bgp_info *del, afi_t afi, safi_t safi)
4950{
4951 struct bgp_node *child;
4952 struct bgp_node *rn;
4953 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004954 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004955
4956 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004957 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004958 return;
4959
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004960 table = bgp->aggregate[afi][safi];
4961
4962 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004963 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004964 return;
4965
paul718e3742002-12-13 20:15:29 +00004966 if (p->prefixlen == 0)
4967 return;
4968
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004969 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004970
4971 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004972 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004973 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4974 {
4975 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004976 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004977 }
4978 bgp_unlock_node (child);
4979}
4980
Daniel Walton76a72802015-05-19 17:47:24 -07004981/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004982static void
paul718e3742002-12-13 20:15:29 +00004983bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4984 struct bgp_aggregate *aggregate)
4985{
4986 struct bgp_table *table;
4987 struct bgp_node *top;
4988 struct bgp_node *rn;
4989 struct bgp_info *new;
4990 struct bgp_info *ri;
4991 unsigned long match;
4992 u_char origin = BGP_ORIGIN_IGP;
4993 struct aspath *aspath = NULL;
4994 struct aspath *asmerge = NULL;
4995 struct community *community = NULL;
4996 struct community *commerge = NULL;
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07004997 u_char atomic_aggregate = 0;
paul718e3742002-12-13 20:15:29 +00004998
4999 table = bgp->rib[afi][safi];
5000
5001 /* Sanity check. */
5002 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5003 return;
5004 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5005 return;
5006
5007 /* If routes exists below this node, generate aggregate routes. */
5008 top = bgp_node_get (table, p);
5009 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5010 if (rn->p.prefixlen > p->prefixlen)
5011 {
5012 match = 0;
5013
5014 for (ri = rn->info; ri; ri = ri->next)
5015 {
5016 if (BGP_INFO_HOLDDOWN (ri))
5017 continue;
5018
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07005019 if (ri->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5020 atomic_aggregate = 1;
5021
paul718e3742002-12-13 20:15:29 +00005022 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5023 {
5024 /* summary-only aggregate route suppress aggregated
5025 route announcement. */
5026 if (aggregate->summary_only)
5027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005028 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005029 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005030 match++;
5031 }
Daniel Walton76a72802015-05-19 17:47:24 -07005032
5033 /* If at least one route among routes that are aggregated has
5034 * ORIGIN with the value INCOMPLETE, then the aggregated route
5035 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5036 * Otherwise, if at least one route among routes that are
5037 * aggregated has ORIGIN with the value EGP, then the aggregated
5038 * route MUST have the ORIGIN attribute with the value EGP.
5039 */
5040 if (origin < ri->attr->origin)
5041 origin = ri->attr->origin;
5042
paul718e3742002-12-13 20:15:29 +00005043 /* as-set aggregate route generate origin, as path,
5044 community aggregation. */
5045 if (aggregate->as_set)
5046 {
paul718e3742002-12-13 20:15:29 +00005047 if (aspath)
5048 {
5049 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5050 aspath_free (aspath);
5051 aspath = asmerge;
5052 }
5053 else
5054 aspath = aspath_dup (ri->attr->aspath);
5055
5056 if (ri->attr->community)
5057 {
5058 if (community)
5059 {
5060 commerge = community_merge (community,
5061 ri->attr->community);
5062 community = community_uniq_sort (commerge);
5063 community_free (commerge);
5064 }
5065 else
5066 community = community_dup (ri->attr->community);
5067 }
5068 }
5069 aggregate->count++;
5070 }
5071 }
5072
5073 /* If this node is suppressed, process the change. */
5074 if (match)
5075 bgp_process (bgp, rn, afi, safi);
5076 }
5077 bgp_unlock_node (top);
5078
5079 /* Add aggregate route to BGP table. */
5080 if (aggregate->count)
5081 {
5082 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005083 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5084 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
Daniel Waltonf2eb9ca2015-05-19 17:47:21 -07005085 aggregate->as_set,
5086 atomic_aggregate), rn);
paul718e3742002-12-13 20:15:29 +00005087 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005088
5089 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005090 bgp_unlock_node (rn);
5091
paul718e3742002-12-13 20:15:29 +00005092 /* Process change. */
5093 bgp_process (bgp, rn, afi, safi);
5094 }
Denil Virae2a92582015-08-11 13:34:59 -07005095 else
5096 {
5097 if (aspath)
5098 aspath_free (aspath);
5099 if (community)
5100 community_free (community);
5101 }
paul718e3742002-12-13 20:15:29 +00005102}
5103
5104void
5105bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5106 safi_t safi, struct bgp_aggregate *aggregate)
5107{
5108 struct bgp_table *table;
5109 struct bgp_node *top;
5110 struct bgp_node *rn;
5111 struct bgp_info *ri;
5112 unsigned long match;
5113
5114 table = bgp->rib[afi][safi];
5115
5116 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5117 return;
5118 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5119 return;
5120
5121 /* If routes exists below this node, generate aggregate routes. */
5122 top = bgp_node_get (table, p);
5123 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5124 if (rn->p.prefixlen > p->prefixlen)
5125 {
5126 match = 0;
5127
5128 for (ri = rn->info; ri; ri = ri->next)
5129 {
5130 if (BGP_INFO_HOLDDOWN (ri))
5131 continue;
5132
5133 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5134 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005135 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005136 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005137 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005138
Paul Jakmafb982c22007-05-04 20:15:47 +00005139 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005140 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005141 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005142 match++;
5143 }
5144 }
5145 aggregate->count--;
5146 }
5147 }
5148
Paul Jakmafb982c22007-05-04 20:15:47 +00005149 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005150 if (match)
5151 bgp_process (bgp, rn, afi, safi);
5152 }
5153 bgp_unlock_node (top);
5154
5155 /* Delete aggregate route from BGP table. */
5156 rn = bgp_node_get (table, p);
5157
5158 for (ri = rn->info; ri; ri = ri->next)
5159 if (ri->peer == bgp->peer_self
5160 && ri->type == ZEBRA_ROUTE_BGP
5161 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5162 break;
5163
5164 /* Withdraw static BGP route from routing table. */
5165 if (ri)
5166 {
paul718e3742002-12-13 20:15:29 +00005167 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005168 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005169 }
5170
5171 /* Unlock bgp_node_lookup. */
5172 bgp_unlock_node (rn);
5173}
5174
5175/* Aggregate route attribute. */
5176#define AGGREGATE_SUMMARY_ONLY 1
5177#define AGGREGATE_AS_SET 1
5178
paul94f2b392005-06-28 12:44:16 +00005179static int
Robert Baysf6269b42010-08-05 10:26:28 -07005180bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5181 afi_t afi, safi_t safi)
5182{
5183 int ret;
5184 struct prefix p;
5185 struct bgp_node *rn;
5186 struct bgp *bgp;
5187 struct bgp_aggregate *aggregate;
5188
5189 /* Convert string to prefix structure. */
5190 ret = str2prefix (prefix_str, &p);
5191 if (!ret)
5192 {
5193 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5194 return CMD_WARNING;
5195 }
5196 apply_mask (&p);
5197
5198 /* Get BGP structure. */
5199 bgp = vty->index;
5200
5201 /* Old configuration check. */
5202 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5203 if (! rn)
5204 {
5205 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5206 VTY_NEWLINE);
5207 return CMD_WARNING;
5208 }
5209
5210 aggregate = rn->info;
5211 if (aggregate->safi & SAFI_UNICAST)
5212 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5213 if (aggregate->safi & SAFI_MULTICAST)
5214 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5215
5216 /* Unlock aggregate address configuration. */
5217 rn->info = NULL;
5218 bgp_aggregate_free (aggregate);
5219 bgp_unlock_node (rn);
5220 bgp_unlock_node (rn);
5221
5222 return CMD_SUCCESS;
5223}
5224
5225static int
5226bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005227 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005228 u_char summary_only, u_char as_set)
5229{
5230 int ret;
5231 struct prefix p;
5232 struct bgp_node *rn;
5233 struct bgp *bgp;
5234 struct bgp_aggregate *aggregate;
5235
5236 /* Convert string to prefix structure. */
5237 ret = str2prefix (prefix_str, &p);
5238 if (!ret)
5239 {
5240 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5241 return CMD_WARNING;
5242 }
5243 apply_mask (&p);
5244
5245 /* Get BGP structure. */
5246 bgp = vty->index;
5247
5248 /* Old configuration check. */
5249 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5250
5251 if (rn->info)
5252 {
5253 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005254 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005255 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5256 if (ret)
5257 {
Robert Bays368473f2010-08-05 10:26:29 -07005258 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5259 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005260 return CMD_WARNING;
5261 }
paul718e3742002-12-13 20:15:29 +00005262 }
5263
5264 /* Make aggregate address structure. */
5265 aggregate = bgp_aggregate_new ();
5266 aggregate->summary_only = summary_only;
5267 aggregate->as_set = as_set;
5268 aggregate->safi = safi;
5269 rn->info = aggregate;
5270
5271 /* Aggregate address insert into BGP routing table. */
5272 if (safi & SAFI_UNICAST)
5273 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5274 if (safi & SAFI_MULTICAST)
5275 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5276
5277 return CMD_SUCCESS;
5278}
5279
paul718e3742002-12-13 20:15:29 +00005280DEFUN (aggregate_address,
5281 aggregate_address_cmd,
5282 "aggregate-address A.B.C.D/M",
5283 "Configure BGP aggregate entries\n"
5284 "Aggregate prefix\n")
5285{
5286 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5287}
5288
5289DEFUN (aggregate_address_mask,
5290 aggregate_address_mask_cmd,
5291 "aggregate-address A.B.C.D A.B.C.D",
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate address\n"
5294 "Aggregate mask\n")
5295{
5296 int ret;
5297 char prefix_str[BUFSIZ];
5298
5299 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5300
5301 if (! ret)
5302 {
5303 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5304 return CMD_WARNING;
5305 }
5306
5307 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5308 0, 0);
5309}
5310
5311DEFUN (aggregate_address_summary_only,
5312 aggregate_address_summary_only_cmd,
5313 "aggregate-address A.B.C.D/M summary-only",
5314 "Configure BGP aggregate entries\n"
5315 "Aggregate prefix\n"
5316 "Filter more specific routes from updates\n")
5317{
5318 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5319 AGGREGATE_SUMMARY_ONLY, 0);
5320}
5321
5322DEFUN (aggregate_address_mask_summary_only,
5323 aggregate_address_mask_summary_only_cmd,
5324 "aggregate-address A.B.C.D A.B.C.D summary-only",
5325 "Configure BGP aggregate entries\n"
5326 "Aggregate address\n"
5327 "Aggregate mask\n"
5328 "Filter more specific routes from updates\n")
5329{
5330 int ret;
5331 char prefix_str[BUFSIZ];
5332
5333 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5334
5335 if (! ret)
5336 {
5337 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5338 return CMD_WARNING;
5339 }
5340
5341 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5342 AGGREGATE_SUMMARY_ONLY, 0);
5343}
5344
5345DEFUN (aggregate_address_as_set,
5346 aggregate_address_as_set_cmd,
5347 "aggregate-address A.B.C.D/M as-set",
5348 "Configure BGP aggregate entries\n"
5349 "Aggregate prefix\n"
5350 "Generate AS set path information\n")
5351{
5352 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5353 0, AGGREGATE_AS_SET);
5354}
5355
5356DEFUN (aggregate_address_mask_as_set,
5357 aggregate_address_mask_as_set_cmd,
5358 "aggregate-address A.B.C.D A.B.C.D as-set",
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate address\n"
5361 "Aggregate mask\n"
5362 "Generate AS set path information\n")
5363{
5364 int ret;
5365 char prefix_str[BUFSIZ];
5366
5367 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5368
5369 if (! ret)
5370 {
5371 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5372 return CMD_WARNING;
5373 }
5374
5375 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5376 0, AGGREGATE_AS_SET);
5377}
5378
5379
5380DEFUN (aggregate_address_as_set_summary,
5381 aggregate_address_as_set_summary_cmd,
5382 "aggregate-address A.B.C.D/M as-set summary-only",
5383 "Configure BGP aggregate entries\n"
5384 "Aggregate prefix\n"
5385 "Generate AS set path information\n"
5386 "Filter more specific routes from updates\n")
5387{
5388 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5389 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5390}
5391
5392ALIAS (aggregate_address_as_set_summary,
5393 aggregate_address_summary_as_set_cmd,
5394 "aggregate-address A.B.C.D/M summary-only as-set",
5395 "Configure BGP aggregate entries\n"
5396 "Aggregate prefix\n"
5397 "Filter more specific routes from updates\n"
5398 "Generate AS set path information\n")
5399
5400DEFUN (aggregate_address_mask_as_set_summary,
5401 aggregate_address_mask_as_set_summary_cmd,
5402 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5403 "Configure BGP aggregate entries\n"
5404 "Aggregate address\n"
5405 "Aggregate mask\n"
5406 "Generate AS set path information\n"
5407 "Filter more specific routes from updates\n")
5408{
5409 int ret;
5410 char prefix_str[BUFSIZ];
5411
5412 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5413
5414 if (! ret)
5415 {
5416 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5417 return CMD_WARNING;
5418 }
5419
5420 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5421 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5422}
5423
5424ALIAS (aggregate_address_mask_as_set_summary,
5425 aggregate_address_mask_summary_as_set_cmd,
5426 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5427 "Configure BGP aggregate entries\n"
5428 "Aggregate address\n"
5429 "Aggregate mask\n"
5430 "Filter more specific routes from updates\n"
5431 "Generate AS set path information\n")
5432
5433DEFUN (no_aggregate_address,
5434 no_aggregate_address_cmd,
5435 "no aggregate-address A.B.C.D/M",
5436 NO_STR
5437 "Configure BGP aggregate entries\n"
5438 "Aggregate prefix\n")
5439{
5440 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5441}
5442
5443ALIAS (no_aggregate_address,
5444 no_aggregate_address_summary_only_cmd,
5445 "no aggregate-address A.B.C.D/M summary-only",
5446 NO_STR
5447 "Configure BGP aggregate entries\n"
5448 "Aggregate prefix\n"
5449 "Filter more specific routes from updates\n")
5450
5451ALIAS (no_aggregate_address,
5452 no_aggregate_address_as_set_cmd,
5453 "no aggregate-address A.B.C.D/M as-set",
5454 NO_STR
5455 "Configure BGP aggregate entries\n"
5456 "Aggregate prefix\n"
5457 "Generate AS set path information\n")
5458
5459ALIAS (no_aggregate_address,
5460 no_aggregate_address_as_set_summary_cmd,
5461 "no aggregate-address A.B.C.D/M as-set summary-only",
5462 NO_STR
5463 "Configure BGP aggregate entries\n"
5464 "Aggregate prefix\n"
5465 "Generate AS set path information\n"
5466 "Filter more specific routes from updates\n")
5467
5468ALIAS (no_aggregate_address,
5469 no_aggregate_address_summary_as_set_cmd,
5470 "no aggregate-address A.B.C.D/M summary-only as-set",
5471 NO_STR
5472 "Configure BGP aggregate entries\n"
5473 "Aggregate prefix\n"
5474 "Filter more specific routes from updates\n"
5475 "Generate AS set path information\n")
5476
5477DEFUN (no_aggregate_address_mask,
5478 no_aggregate_address_mask_cmd,
5479 "no aggregate-address A.B.C.D A.B.C.D",
5480 NO_STR
5481 "Configure BGP aggregate entries\n"
5482 "Aggregate address\n"
5483 "Aggregate mask\n")
5484{
5485 int ret;
5486 char prefix_str[BUFSIZ];
5487
5488 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5489
5490 if (! ret)
5491 {
5492 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5493 return CMD_WARNING;
5494 }
5495
5496 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5497}
5498
5499ALIAS (no_aggregate_address_mask,
5500 no_aggregate_address_mask_summary_only_cmd,
5501 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5502 NO_STR
5503 "Configure BGP aggregate entries\n"
5504 "Aggregate address\n"
5505 "Aggregate mask\n"
5506 "Filter more specific routes from updates\n")
5507
5508ALIAS (no_aggregate_address_mask,
5509 no_aggregate_address_mask_as_set_cmd,
5510 "no aggregate-address A.B.C.D A.B.C.D as-set",
5511 NO_STR
5512 "Configure BGP aggregate entries\n"
5513 "Aggregate address\n"
5514 "Aggregate mask\n"
5515 "Generate AS set path information\n")
5516
5517ALIAS (no_aggregate_address_mask,
5518 no_aggregate_address_mask_as_set_summary_cmd,
5519 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5520 NO_STR
5521 "Configure BGP aggregate entries\n"
5522 "Aggregate address\n"
5523 "Aggregate mask\n"
5524 "Generate AS set path information\n"
5525 "Filter more specific routes from updates\n")
5526
5527ALIAS (no_aggregate_address_mask,
5528 no_aggregate_address_mask_summary_as_set_cmd,
5529 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5530 NO_STR
5531 "Configure BGP aggregate entries\n"
5532 "Aggregate address\n"
5533 "Aggregate mask\n"
5534 "Filter more specific routes from updates\n"
5535 "Generate AS set path information\n")
5536
paul718e3742002-12-13 20:15:29 +00005537DEFUN (ipv6_aggregate_address,
5538 ipv6_aggregate_address_cmd,
5539 "aggregate-address X:X::X:X/M",
5540 "Configure BGP aggregate entries\n"
5541 "Aggregate prefix\n")
5542{
5543 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5544}
5545
5546DEFUN (ipv6_aggregate_address_summary_only,
5547 ipv6_aggregate_address_summary_only_cmd,
5548 "aggregate-address X:X::X:X/M summary-only",
5549 "Configure BGP aggregate entries\n"
5550 "Aggregate prefix\n"
5551 "Filter more specific routes from updates\n")
5552{
5553 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5554 AGGREGATE_SUMMARY_ONLY, 0);
5555}
5556
5557DEFUN (no_ipv6_aggregate_address,
5558 no_ipv6_aggregate_address_cmd,
5559 "no aggregate-address X:X::X:X/M",
5560 NO_STR
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate prefix\n")
5563{
5564 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5565}
5566
5567DEFUN (no_ipv6_aggregate_address_summary_only,
5568 no_ipv6_aggregate_address_summary_only_cmd,
5569 "no aggregate-address X:X::X:X/M summary-only",
5570 NO_STR
5571 "Configure BGP aggregate entries\n"
5572 "Aggregate prefix\n"
5573 "Filter more specific routes from updates\n")
5574{
5575 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5576}
5577
5578ALIAS (ipv6_aggregate_address,
5579 old_ipv6_aggregate_address_cmd,
5580 "ipv6 bgp aggregate-address X:X::X:X/M",
5581 IPV6_STR
5582 BGP_STR
5583 "Configure BGP aggregate entries\n"
5584 "Aggregate prefix\n")
5585
5586ALIAS (ipv6_aggregate_address_summary_only,
5587 old_ipv6_aggregate_address_summary_only_cmd,
5588 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5589 IPV6_STR
5590 BGP_STR
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n"
5593 "Filter more specific routes from updates\n")
5594
5595ALIAS (no_ipv6_aggregate_address,
5596 old_no_ipv6_aggregate_address_cmd,
5597 "no ipv6 bgp aggregate-address X:X::X:X/M",
5598 NO_STR
5599 IPV6_STR
5600 BGP_STR
5601 "Configure BGP aggregate entries\n"
5602 "Aggregate prefix\n")
5603
5604ALIAS (no_ipv6_aggregate_address_summary_only,
5605 old_no_ipv6_aggregate_address_summary_only_cmd,
5606 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5607 NO_STR
5608 IPV6_STR
5609 BGP_STR
5610 "Configure BGP aggregate entries\n"
5611 "Aggregate prefix\n"
5612 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005613
paul718e3742002-12-13 20:15:29 +00005614/* Redistribute route treatment. */
5615void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005616bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5617 const struct in6_addr *nexthop6,
Paul Jakma96d10602016-07-01 14:23:45 +01005618 u_int32_t metric, u_char type, route_tag_t tag)
paul718e3742002-12-13 20:15:29 +00005619{
5620 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005621 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005622 struct bgp_info *new;
5623 struct bgp_info *bi;
5624 struct bgp_info info;
5625 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005626 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005627 struct attr *new_attr;
5628 afi_t afi;
5629 int ret;
5630
5631 /* Make default attribute. */
5632 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5633 if (nexthop)
5634 attr.nexthop = *nexthop;
5635
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005636 if (nexthop6)
5637 {
5638 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5639 extra->mp_nexthop_global = *nexthop6;
5640 extra->mp_nexthop_len = 16;
5641 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005642
paul718e3742002-12-13 20:15:29 +00005643 attr.med = metric;
5644 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Piotr Chytła605aa332015-12-01 10:03:54 -05005645 attr.extra->tag = tag;
paul718e3742002-12-13 20:15:29 +00005646
paul1eb8ef22005-04-07 07:30:20 +00005647 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005648 {
5649 afi = family2afi (p->family);
5650
5651 if (bgp->redist[afi][type])
5652 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005653 struct attr attr_new;
5654 struct attr_extra extra_new;
5655
paul718e3742002-12-13 20:15:29 +00005656 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005657 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005658 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005659
5660 if (bgp->redist_metric_flag[afi][type])
5661 attr_new.med = bgp->redist_metric[afi][type];
5662
5663 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005664 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005665 {
5666 info.peer = bgp->peer_self;
5667 info.attr = &attr_new;
5668
paulfee0f4c2004-09-13 05:12:46 +00005669 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5670
paul718e3742002-12-13 20:15:29 +00005671 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5672 &info);
paulfee0f4c2004-09-13 05:12:46 +00005673
5674 bgp->peer_self->rmap_type = 0;
5675
paul718e3742002-12-13 20:15:29 +00005676 if (ret == RMAP_DENYMATCH)
5677 {
5678 /* Free uninterned attribute. */
5679 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005680
paul718e3742002-12-13 20:15:29 +00005681 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005682 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005684 bgp_redistribute_delete (p, type);
5685 return;
5686 }
5687 }
5688
Paul Jakmafb982c22007-05-04 20:15:47 +00005689 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5690 afi, SAFI_UNICAST, p, NULL);
5691
paul718e3742002-12-13 20:15:29 +00005692 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005693
paul718e3742002-12-13 20:15:29 +00005694 for (bi = bn->info; bi; bi = bi->next)
5695 if (bi->peer == bgp->peer_self
5696 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5697 break;
5698
5699 if (bi)
5700 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005701 if (attrhash_cmp (bi->attr, new_attr) &&
5702 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005703 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005704 bgp_attr_unintern (&new_attr);
5705 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005706 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005707 bgp_unlock_node (bn);
5708 return;
5709 }
5710 else
5711 {
5712 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005713 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005714
5715 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005716 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5717 bgp_info_restore(bn, bi);
5718 else
5719 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005720 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005721 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005722 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005723
5724 /* Process change. */
5725 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5726 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5727 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005728 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005729 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005730 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005731 }
paul718e3742002-12-13 20:15:29 +00005732 }
5733
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005734 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5735 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005736 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005737
5738 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5739 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005740 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005741 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5742 }
5743 }
5744
5745 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005746 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005747 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005748}
5749
5750void
5751bgp_redistribute_delete (struct prefix *p, u_char type)
5752{
5753 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005754 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005755 afi_t afi;
5756 struct bgp_node *rn;
5757 struct bgp_info *ri;
5758
paul1eb8ef22005-04-07 07:30:20 +00005759 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005760 {
5761 afi = family2afi (p->family);
5762
5763 if (bgp->redist[afi][type])
5764 {
paulfee0f4c2004-09-13 05:12:46 +00005765 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005766
5767 for (ri = rn->info; ri; ri = ri->next)
5768 if (ri->peer == bgp->peer_self
5769 && ri->type == type)
5770 break;
5771
5772 if (ri)
5773 {
5774 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005775 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005776 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005777 }
5778 bgp_unlock_node (rn);
5779 }
5780 }
5781}
5782
5783/* Withdraw specified route type's route. */
5784void
5785bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5786{
5787 struct bgp_node *rn;
5788 struct bgp_info *ri;
5789 struct bgp_table *table;
5790
5791 table = bgp->rib[afi][SAFI_UNICAST];
5792
5793 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5794 {
5795 for (ri = rn->info; ri; ri = ri->next)
5796 if (ri->peer == bgp->peer_self
5797 && ri->type == type)
5798 break;
5799
5800 if (ri)
5801 {
5802 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005803 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005804 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005805 }
5806 }
5807}
David Lamparter6b0655a2014-06-04 06:53:35 +02005808
paul718e3742002-12-13 20:15:29 +00005809/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005810static void
paul718e3742002-12-13 20:15:29 +00005811route_vty_out_route (struct prefix *p, struct vty *vty)
5812{
5813 int len;
5814 u_int32_t destination;
5815 char buf[BUFSIZ];
5816
5817 if (p->family == AF_INET)
5818 {
5819 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5820 destination = ntohl (p->u.prefix4.s_addr);
5821
5822 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5823 || (IN_CLASSB (destination) && p->prefixlen == 16)
5824 || (IN_CLASSA (destination) && p->prefixlen == 8)
5825 || p->u.prefix4.s_addr == 0)
5826 {
5827 /* When mask is natural, mask is not displayed. */
5828 }
5829 else
5830 len += vty_out (vty, "/%d", p->prefixlen);
5831 }
5832 else
5833 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5834 p->prefixlen);
5835
5836 len = 17 - len;
5837 if (len < 1)
5838 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5839 else
5840 vty_out (vty, "%*s", len, " ");
5841}
5842
paul718e3742002-12-13 20:15:29 +00005843enum bgp_display_type
5844{
5845 normal_list,
5846};
5847
paulb40d9392005-08-22 22:34:41 +00005848/* Print the short form route status for a bgp_info */
5849static void
5850route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005851{
paulb40d9392005-08-22 22:34:41 +00005852 /* Route status display. */
5853 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5854 vty_out (vty, "R");
5855 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005856 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005857 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005858 vty_out (vty, "s");
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07005859 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5860 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00005861 vty_out (vty, "*");
5862 else
5863 vty_out (vty, " ");
5864
5865 /* Selected */
5866 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5867 vty_out (vty, "h");
5868 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5869 vty_out (vty, "d");
5870 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5871 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005872 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5873 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005874 else
5875 vty_out (vty, " ");
5876
5877 /* Internal route. */
5878 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5879 vty_out (vty, "i");
5880 else
paulb40d9392005-08-22 22:34:41 +00005881 vty_out (vty, " ");
5882}
5883
5884/* called from terminal list command */
5885void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005886route_vty_out(
5887 struct vty *vty,
5888 struct prefix *p,
5889 struct bgp_info *binfo,
5890 int display,
5891 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005892{
5893 struct attr *attr;
5894
5895 /* short status lead text */
5896 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005897
5898 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005899 if (!display)
paul718e3742002-12-13 20:15:29 +00005900 route_vty_out_route (p, vty);
5901 else
5902 vty_out (vty, "%*s", 17, " ");
5903
5904 /* Print attribute */
5905 attr = binfo->attr;
5906 if (attr)
5907 {
paul718e3742002-12-13 20:15:29 +00005908
Lou Berger298cc2f2016-01-12 13:42:02 -05005909 /*
5910 * NEXTHOP start
5911 */
5912
5913 /*
5914 * For ENCAP routes, nexthop address family is not
5915 * neccessarily the same as the prefix address family.
5916 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5917 */
5918 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5919 if (attr->extra) {
5920 char buf[BUFSIZ];
5921 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5922
5923 switch (af) {
5924 case AF_INET:
5925 vty_out (vty, "%s", inet_ntop(af,
5926 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5927 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005928 case AF_INET6:
5929 vty_out (vty, "%s", inet_ntop(af,
5930 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5931 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005932 default:
5933 vty_out(vty, "?");
5934 }
5935 } else {
5936 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005937 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005938 } else {
5939
5940 if (p->family == AF_INET)
5941 {
5942 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5943 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005944 else if (p->family == AF_INET6)
5945 {
5946 int len;
5947 char buf[BUFSIZ];
5948
5949 len = vty_out (vty, "%s",
5950 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5951 buf, BUFSIZ));
5952 len = 16 - len;
5953 if (len < 1)
5954 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5955 else
5956 vty_out (vty, "%*s", len, " ");
5957 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005958 else
5959 {
5960 vty_out(vty, "?");
5961 }
5962 }
5963
5964 /*
5965 * NEXTHOP end
5966 */
5967
paul718e3742002-12-13 20:15:29 +00005968
5969 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005970 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005971 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005972 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005973
5974 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005975 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005976 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005977 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005978
Paul Jakmafb982c22007-05-04 20:15:47 +00005979 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005980
Paul Jakmab2518c12006-05-12 23:48:40 +00005981 /* Print aspath */
5982 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005983 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005984
Paul Jakmab2518c12006-05-12 23:48:40 +00005985 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005986 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005987 }
paul718e3742002-12-13 20:15:29 +00005988 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005989}
5990
5991/* called from terminal list command */
5992void
5993route_vty_out_tmp (struct vty *vty, struct prefix *p,
5994 struct attr *attr, safi_t safi)
5995{
5996 /* Route status display. */
5997 vty_out (vty, "*");
5998 vty_out (vty, ">");
5999 vty_out (vty, " ");
6000
6001 /* print prefix and mask */
6002 route_vty_out_route (p, vty);
6003
6004 /* Print attribute */
6005 if (attr)
6006 {
6007 if (p->family == AF_INET)
6008 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006009 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006010 vty_out (vty, "%-16s",
6011 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006012 else
6013 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6014 }
paul718e3742002-12-13 20:15:29 +00006015 else if (p->family == AF_INET6)
6016 {
6017 int len;
6018 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006019
6020 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006021
6022 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006023 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6024 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006025 len = 16 - len;
6026 if (len < 1)
6027 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6028 else
6029 vty_out (vty, "%*s", len, " ");
6030 }
paul718e3742002-12-13 20:15:29 +00006031
6032 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006033 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006034 else
6035 vty_out (vty, " ");
6036
6037 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006038 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006039 else
6040 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006041
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006042 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006043
Paul Jakmab2518c12006-05-12 23:48:40 +00006044 /* Print aspath */
6045 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006046 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006047
Paul Jakmab2518c12006-05-12 23:48:40 +00006048 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006049 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006050 }
paul718e3742002-12-13 20:15:29 +00006051
6052 vty_out (vty, "%s", VTY_NEWLINE);
6053}
6054
ajs5a646652004-11-05 01:25:55 +00006055void
paul718e3742002-12-13 20:15:29 +00006056route_vty_out_tag (struct vty *vty, struct prefix *p,
6057 struct bgp_info *binfo, int display, safi_t safi)
6058{
6059 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006060 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006061
6062 if (!binfo->extra)
6063 return;
6064
paulb40d9392005-08-22 22:34:41 +00006065 /* short status lead text */
6066 route_vty_short_status_out (vty, binfo);
6067
paul718e3742002-12-13 20:15:29 +00006068 /* print prefix and mask */
6069 if (! display)
6070 route_vty_out_route (p, vty);
6071 else
6072 vty_out (vty, "%*s", 17, " ");
6073
6074 /* Print attribute */
6075 attr = binfo->attr;
6076 if (attr)
6077 {
6078 if (p->family == AF_INET)
6079 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006080 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006081 vty_out (vty, "%-16s",
6082 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006083 else
6084 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6085 }
paul718e3742002-12-13 20:15:29 +00006086 else if (p->family == AF_INET6)
6087 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006088 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006089 char buf[BUFSIZ];
6090 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006091 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006092 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006093 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6094 buf, BUFSIZ));
6095 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006096 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006097 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6098 buf, BUFSIZ),
6099 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6100 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006101
6102 }
paul718e3742002-12-13 20:15:29 +00006103 }
6104
Paul Jakmafb982c22007-05-04 20:15:47 +00006105 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006106
6107 vty_out (vty, "notag/%d", label);
6108
6109 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006110}
6111
6112/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006113static void
paul718e3742002-12-13 20:15:29 +00006114damp_route_vty_out (struct vty *vty, struct prefix *p,
6115 struct bgp_info *binfo, int display, safi_t safi)
6116{
6117 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006118 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006119 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006120
paulb40d9392005-08-22 22:34:41 +00006121 /* short status lead text */
6122 route_vty_short_status_out (vty, binfo);
6123
paul718e3742002-12-13 20:15:29 +00006124 /* print prefix and mask */
6125 if (! display)
6126 route_vty_out_route (p, vty);
6127 else
6128 vty_out (vty, "%*s", 17, " ");
6129
6130 len = vty_out (vty, "%s", binfo->peer->host);
6131 len = 17 - len;
6132 if (len < 1)
6133 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6134 else
6135 vty_out (vty, "%*s", len, " ");
6136
Chris Caputo50aef6f2009-06-23 06:06:49 +00006137 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006138
6139 /* Print attribute */
6140 attr = binfo->attr;
6141 if (attr)
6142 {
6143 /* Print aspath */
6144 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006145 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006146
6147 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006148 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006149 }
6150 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006151}
6152
paul718e3742002-12-13 20:15:29 +00006153/* flap route */
ajs5a646652004-11-05 01:25:55 +00006154static void
paul718e3742002-12-13 20:15:29 +00006155flap_route_vty_out (struct vty *vty, struct prefix *p,
6156 struct bgp_info *binfo, int display, safi_t safi)
6157{
6158 struct attr *attr;
6159 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006160 char timebuf[BGP_UPTIME_LEN];
6161 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006162
6163 if (!binfo->extra)
6164 return;
6165
6166 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006167
paulb40d9392005-08-22 22:34:41 +00006168 /* short status lead text */
6169 route_vty_short_status_out (vty, binfo);
6170
paul718e3742002-12-13 20:15:29 +00006171 /* print prefix and mask */
6172 if (! display)
6173 route_vty_out_route (p, vty);
6174 else
6175 vty_out (vty, "%*s", 17, " ");
6176
6177 len = vty_out (vty, "%s", binfo->peer->host);
6178 len = 16 - len;
6179 if (len < 1)
6180 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6181 else
6182 vty_out (vty, "%*s", len, " ");
6183
6184 len = vty_out (vty, "%d", bdi->flap);
6185 len = 5 - len;
6186 if (len < 1)
6187 vty_out (vty, " ");
6188 else
6189 vty_out (vty, "%*s ", len, " ");
6190
6191 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6192 timebuf, BGP_UPTIME_LEN));
6193
6194 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6195 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006196 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006197 else
6198 vty_out (vty, "%*s ", 8, " ");
6199
6200 /* Print attribute */
6201 attr = binfo->attr;
6202 if (attr)
6203 {
6204 /* Print aspath */
6205 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006206 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006207
6208 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006209 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006210 }
6211 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006212}
6213
paul94f2b392005-06-28 12:44:16 +00006214static void
paul718e3742002-12-13 20:15:29 +00006215route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6216 struct bgp_info *binfo, afi_t afi, safi_t safi)
6217{
6218 char buf[INET6_ADDRSTRLEN];
6219 char buf1[BUFSIZ];
6220 struct attr *attr;
6221 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006222#ifdef HAVE_CLOCK_MONOTONIC
6223 time_t tbuf;
6224#endif
paul718e3742002-12-13 20:15:29 +00006225
6226 attr = binfo->attr;
6227
6228 if (attr)
6229 {
6230 /* Line1 display AS-path, Aggregator */
6231 if (attr->aspath)
6232 {
6233 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006234 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006235 vty_out (vty, "Local");
6236 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006237 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006238 }
6239
paulb40d9392005-08-22 22:34:41 +00006240 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6241 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006242 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6243 vty_out (vty, ", (stale)");
6244 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006245 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006246 attr->extra->aggregator_as,
6247 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006248 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6249 vty_out (vty, ", (Received from a RR-client)");
6250 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6251 vty_out (vty, ", (Received from a RS-client)");
6252 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6253 vty_out (vty, ", (history entry)");
6254 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6255 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006256 vty_out (vty, "%s", VTY_NEWLINE);
6257
6258 /* Line2 display Next-hop, Neighbor, Router-id */
6259 if (p->family == AF_INET)
6260 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006261 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006262 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006263 inet_ntoa (attr->nexthop));
6264 }
paul718e3742002-12-13 20:15:29 +00006265 else
6266 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006267 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006268 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006269 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006270 buf, INET6_ADDRSTRLEN));
6271 }
paul718e3742002-12-13 20:15:29 +00006272
6273 if (binfo->peer == bgp->peer_self)
6274 {
6275 vty_out (vty, " from %s ",
6276 p->family == AF_INET ? "0.0.0.0" : "::");
6277 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6278 }
6279 else
6280 {
6281 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6282 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006283 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006284 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006285 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6286 buf[0] = '?';
6287 buf[1] = 0;
6288 }
6289 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006290 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006291 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006292 else
6293 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6294 }
6295 vty_out (vty, "%s", VTY_NEWLINE);
6296
paul718e3742002-12-13 20:15:29 +00006297 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006298 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006299 {
6300 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006301 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006302 buf, INET6_ADDRSTRLEN),
6303 VTY_NEWLINE);
6304 }
paul718e3742002-12-13 20:15:29 +00006305
Piotr Chytła605aa332015-12-01 10:03:54 -05006306 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
paul718e3742002-12-13 20:15:29 +00006307 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6308
6309 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006310 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006311
6312 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006313 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006314 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006315 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006316
Paul Jakmafb982c22007-05-04 20:15:47 +00006317 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006318 vty_out (vty, ", weight %u", attr->extra->weight);
Piotr Chytła605aa332015-12-01 10:03:54 -05006319
6320 if (attr->extra && attr->extra->tag != 0)
6321 vty_out (vty, ", tag %d", attr->extra->tag);
paul718e3742002-12-13 20:15:29 +00006322
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07006323 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6324 vty_out (vty, ", invalid");
6325 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00006326 vty_out (vty, ", valid");
6327
6328 if (binfo->peer != bgp->peer_self)
6329 {
6330 if (binfo->peer->as == binfo->peer->local_as)
6331 vty_out (vty, ", internal");
6332 else
6333 vty_out (vty, ", %s",
6334 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6335 }
6336 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6337 vty_out (vty, ", aggregated, local");
6338 else if (binfo->type != ZEBRA_ROUTE_BGP)
6339 vty_out (vty, ", sourced");
6340 else
6341 vty_out (vty, ", sourced, local");
6342
6343 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6344 vty_out (vty, ", atomic-aggregate");
6345
Josh Baileyde8d5df2011-07-20 20:46:01 -07006346 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6347 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6348 bgp_info_mpath_count (binfo)))
6349 vty_out (vty, ", multipath");
6350
paul718e3742002-12-13 20:15:29 +00006351 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6352 vty_out (vty, ", best");
6353
6354 vty_out (vty, "%s", VTY_NEWLINE);
6355
6356 /* Line 4 display Community */
6357 if (attr->community)
6358 vty_out (vty, " Community: %s%s", attr->community->str,
6359 VTY_NEWLINE);
6360
6361 /* Line 5 display Extended-community */
6362 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006363 vty_out (vty, " Extended Community: %s%s",
6364 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006365
6366 /* Line 6 display Originator, Cluster-id */
6367 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6368 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6369 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006370 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006371 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006372 vty_out (vty, " Originator: %s",
6373 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006374
6375 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6376 {
6377 int i;
6378 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006379 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6380 vty_out (vty, "%s ",
6381 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006382 }
6383 vty_out (vty, "%s", VTY_NEWLINE);
6384 }
Paul Jakma41367172007-08-06 15:24:51 +00006385
Paul Jakmafb982c22007-05-04 20:15:47 +00006386 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006387 bgp_damp_info_vty (vty, binfo);
6388
6389 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006390#ifdef HAVE_CLOCK_MONOTONIC
6391 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006392 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006393#else
6394 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6395#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006396 }
6397 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006398}
6399
6400#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6401 "h history, * valid, > best, = multipath,%s"\
6402 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006403#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006404#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6405#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6406#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6407
6408enum bgp_show_type
6409{
6410 bgp_show_type_normal,
6411 bgp_show_type_regexp,
6412 bgp_show_type_prefix_list,
6413 bgp_show_type_filter_list,
6414 bgp_show_type_route_map,
6415 bgp_show_type_neighbor,
6416 bgp_show_type_cidr_only,
6417 bgp_show_type_prefix_longer,
6418 bgp_show_type_community_all,
6419 bgp_show_type_community,
6420 bgp_show_type_community_exact,
6421 bgp_show_type_community_list,
6422 bgp_show_type_community_list_exact,
6423 bgp_show_type_flap_statistics,
6424 bgp_show_type_flap_address,
6425 bgp_show_type_flap_prefix,
6426 bgp_show_type_flap_cidr_only,
6427 bgp_show_type_flap_regexp,
6428 bgp_show_type_flap_filter_list,
6429 bgp_show_type_flap_prefix_list,
6430 bgp_show_type_flap_prefix_longer,
6431 bgp_show_type_flap_route_map,
6432 bgp_show_type_flap_neighbor,
6433 bgp_show_type_dampend_paths,
6434 bgp_show_type_damp_neighbor
6435};
6436
ajs5a646652004-11-05 01:25:55 +00006437static int
paulfee0f4c2004-09-13 05:12:46 +00006438bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006439 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006440{
paul718e3742002-12-13 20:15:29 +00006441 struct bgp_info *ri;
6442 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006443 int header = 1;
paul718e3742002-12-13 20:15:29 +00006444 int display;
ajs5a646652004-11-05 01:25:55 +00006445 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006446 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006447
6448 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006449 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006450 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006451
paul718e3742002-12-13 20:15:29 +00006452 /* Start processing of routes. */
6453 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6454 if (rn->info != NULL)
6455 {
6456 display = 0;
6457
6458 for (ri = rn->info; ri; ri = ri->next)
6459 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006460 total_count++;
ajs5a646652004-11-05 01:25:55 +00006461 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006462 || type == bgp_show_type_flap_address
6463 || type == bgp_show_type_flap_prefix
6464 || type == bgp_show_type_flap_cidr_only
6465 || type == bgp_show_type_flap_regexp
6466 || type == bgp_show_type_flap_filter_list
6467 || type == bgp_show_type_flap_prefix_list
6468 || type == bgp_show_type_flap_prefix_longer
6469 || type == bgp_show_type_flap_route_map
6470 || type == bgp_show_type_flap_neighbor
6471 || type == bgp_show_type_dampend_paths
6472 || type == bgp_show_type_damp_neighbor)
6473 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006474 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006475 continue;
6476 }
6477 if (type == bgp_show_type_regexp
6478 || type == bgp_show_type_flap_regexp)
6479 {
ajs5a646652004-11-05 01:25:55 +00006480 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006481
6482 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6483 continue;
6484 }
6485 if (type == bgp_show_type_prefix_list
6486 || type == bgp_show_type_flap_prefix_list)
6487 {
ajs5a646652004-11-05 01:25:55 +00006488 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006489
6490 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6491 continue;
6492 }
6493 if (type == bgp_show_type_filter_list
6494 || type == bgp_show_type_flap_filter_list)
6495 {
ajs5a646652004-11-05 01:25:55 +00006496 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006497
6498 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6499 continue;
6500 }
6501 if (type == bgp_show_type_route_map
6502 || type == bgp_show_type_flap_route_map)
6503 {
ajs5a646652004-11-05 01:25:55 +00006504 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006505 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006506 struct attr dummy_attr;
6507 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006508 int ret;
6509
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006510 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006511 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006512
paul718e3742002-12-13 20:15:29 +00006513 binfo.peer = ri->peer;
6514 binfo.attr = &dummy_attr;
6515
6516 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006517 if (ret == RMAP_DENYMATCH)
6518 continue;
6519 }
6520 if (type == bgp_show_type_neighbor
6521 || type == bgp_show_type_flap_neighbor
6522 || type == bgp_show_type_damp_neighbor)
6523 {
ajs5a646652004-11-05 01:25:55 +00006524 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006525
6526 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6527 continue;
6528 }
6529 if (type == bgp_show_type_cidr_only
6530 || type == bgp_show_type_flap_cidr_only)
6531 {
6532 u_int32_t destination;
6533
6534 destination = ntohl (rn->p.u.prefix4.s_addr);
6535 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6536 continue;
6537 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6538 continue;
6539 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6540 continue;
6541 }
6542 if (type == bgp_show_type_prefix_longer
6543 || type == bgp_show_type_flap_prefix_longer)
6544 {
ajs5a646652004-11-05 01:25:55 +00006545 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006546
6547 if (! prefix_match (p, &rn->p))
6548 continue;
6549 }
6550 if (type == bgp_show_type_community_all)
6551 {
6552 if (! ri->attr->community)
6553 continue;
6554 }
6555 if (type == bgp_show_type_community)
6556 {
ajs5a646652004-11-05 01:25:55 +00006557 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006558
6559 if (! ri->attr->community ||
6560 ! community_match (ri->attr->community, com))
6561 continue;
6562 }
6563 if (type == bgp_show_type_community_exact)
6564 {
ajs5a646652004-11-05 01:25:55 +00006565 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006566
6567 if (! ri->attr->community ||
6568 ! community_cmp (ri->attr->community, com))
6569 continue;
6570 }
6571 if (type == bgp_show_type_community_list)
6572 {
ajs5a646652004-11-05 01:25:55 +00006573 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006574
6575 if (! community_list_match (ri->attr->community, list))
6576 continue;
6577 }
6578 if (type == bgp_show_type_community_list_exact)
6579 {
ajs5a646652004-11-05 01:25:55 +00006580 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006581
6582 if (! community_list_exact_match (ri->attr->community, list))
6583 continue;
6584 }
6585 if (type == bgp_show_type_flap_address
6586 || type == bgp_show_type_flap_prefix)
6587 {
ajs5a646652004-11-05 01:25:55 +00006588 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006589
6590 if (! prefix_match (&rn->p, p))
6591 continue;
6592
6593 if (type == bgp_show_type_flap_prefix)
6594 if (p->prefixlen != rn->p.prefixlen)
6595 continue;
6596 }
6597 if (type == bgp_show_type_dampend_paths
6598 || type == bgp_show_type_damp_neighbor)
6599 {
6600 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6601 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6602 continue;
6603 }
6604
6605 if (header)
6606 {
hasso93406d82005-02-02 14:40:33 +00006607 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6608 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6609 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006610 if (type == bgp_show_type_dampend_paths
6611 || type == bgp_show_type_damp_neighbor)
6612 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6613 else if (type == bgp_show_type_flap_statistics
6614 || type == bgp_show_type_flap_address
6615 || type == bgp_show_type_flap_prefix
6616 || type == bgp_show_type_flap_cidr_only
6617 || type == bgp_show_type_flap_regexp
6618 || type == bgp_show_type_flap_filter_list
6619 || type == bgp_show_type_flap_prefix_list
6620 || type == bgp_show_type_flap_prefix_longer
6621 || type == bgp_show_type_flap_route_map
6622 || type == bgp_show_type_flap_neighbor)
6623 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6624 else
6625 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006626 header = 0;
6627 }
6628
6629 if (type == bgp_show_type_dampend_paths
6630 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006631 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006632 else if (type == bgp_show_type_flap_statistics
6633 || type == bgp_show_type_flap_address
6634 || type == bgp_show_type_flap_prefix
6635 || type == bgp_show_type_flap_cidr_only
6636 || type == bgp_show_type_flap_regexp
6637 || type == bgp_show_type_flap_filter_list
6638 || type == bgp_show_type_flap_prefix_list
6639 || type == bgp_show_type_flap_prefix_longer
6640 || type == bgp_show_type_flap_route_map
6641 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006642 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006643 else
ajs5a646652004-11-05 01:25:55 +00006644 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006645 display++;
6646 }
6647 if (display)
ajs5a646652004-11-05 01:25:55 +00006648 output_count++;
paul718e3742002-12-13 20:15:29 +00006649 }
6650
6651 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006652 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006653 {
6654 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006655 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006656 }
6657 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006658 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6659 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006660
6661 return CMD_SUCCESS;
6662}
6663
ajs5a646652004-11-05 01:25:55 +00006664static int
paulfee0f4c2004-09-13 05:12:46 +00006665bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006666 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006667{
6668 struct bgp_table *table;
6669
6670 if (bgp == NULL) {
6671 bgp = bgp_get_default ();
6672 }
6673
6674 if (bgp == NULL)
6675 {
6676 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6677 return CMD_WARNING;
6678 }
6679
6680
6681 table = bgp->rib[afi][safi];
6682
ajs5a646652004-11-05 01:25:55 +00006683 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006684}
6685
paul718e3742002-12-13 20:15:29 +00006686/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006687static void
paul718e3742002-12-13 20:15:29 +00006688route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6689 struct bgp_node *rn,
6690 struct prefix_rd *prd, afi_t afi, safi_t safi)
6691{
6692 struct bgp_info *ri;
6693 struct prefix *p;
6694 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006695 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006696 char buf1[INET6_ADDRSTRLEN];
6697 char buf2[INET6_ADDRSTRLEN];
6698 int count = 0;
6699 int best = 0;
6700 int suppress = 0;
6701 int no_export = 0;
6702 int no_advertise = 0;
6703 int local_as = 0;
6704 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006705 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006706
6707 p = &rn->p;
6708 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006709 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6710 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006711 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6712 p->prefixlen, VTY_NEWLINE);
6713
6714 for (ri = rn->info; ri; ri = ri->next)
6715 {
6716 count++;
6717 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6718 {
6719 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006720 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006721 suppress = 1;
6722 if (ri->attr->community != NULL)
6723 {
6724 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6725 no_advertise = 1;
6726 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6727 no_export = 1;
6728 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6729 local_as = 1;
6730 }
6731 }
6732 }
6733
6734 vty_out (vty, "Paths: (%d available", count);
6735 if (best)
6736 {
6737 vty_out (vty, ", best #%d", best);
6738 if (safi == SAFI_UNICAST)
6739 vty_out (vty, ", table Default-IP-Routing-Table");
6740 }
6741 else
6742 vty_out (vty, ", no best path");
6743 if (no_advertise)
6744 vty_out (vty, ", not advertised to any peer");
6745 else if (no_export)
6746 vty_out (vty, ", not advertised to EBGP peer");
6747 else if (local_as)
6748 vty_out (vty, ", not advertised outside local AS");
6749 if (suppress)
6750 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6751 vty_out (vty, ")%s", VTY_NEWLINE);
6752
6753 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006754 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006755 {
6756 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6757 {
6758 if (! first)
6759 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6760 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6761 first = 1;
6762 }
6763 }
6764 if (! first)
6765 vty_out (vty, " Not advertised to any peer");
6766 vty_out (vty, "%s", VTY_NEWLINE);
6767}
6768
6769/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006770static int
paulfee0f4c2004-09-13 05:12:46 +00006771bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006772 struct bgp_table *rib, const char *ip_str,
6773 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006774 int prefix_check, enum bgp_path_type pathtype)
paul718e3742002-12-13 20:15:29 +00006775{
6776 int ret;
6777 int header;
6778 int display = 0;
6779 struct prefix match;
6780 struct bgp_node *rn;
6781 struct bgp_node *rm;
6782 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006783 struct bgp_table *table;
6784
Lou Berger050defe2016-01-12 13:41:59 -05006785 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006786 /* Check IP address argument. */
6787 ret = str2prefix (ip_str, &match);
6788 if (! ret)
6789 {
6790 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6791 return CMD_WARNING;
6792 }
6793
6794 match.family = afi2family (afi);
6795
Lou Berger298cc2f2016-01-12 13:42:02 -05006796 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006797 {
paulfee0f4c2004-09-13 05:12:46 +00006798 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006799 {
6800 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6801 continue;
6802
6803 if ((table = rn->info) != NULL)
6804 {
6805 header = 1;
6806
6807 if ((rm = bgp_node_match (table, &match)) != NULL)
6808 {
6809 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006810 {
6811 bgp_unlock_node (rm);
6812 continue;
6813 }
paul718e3742002-12-13 20:15:29 +00006814
6815 for (ri = rm->info; ri; ri = ri->next)
6816 {
6817 if (header)
6818 {
6819 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006820 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006821
6822 header = 0;
6823 }
6824 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006825
6826 if (pathtype == BGP_PATH_ALL ||
6827 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6828 (pathtype == BGP_PATH_MULTIPATH &&
6829 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6830 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006831 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006832
6833 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006834 }
6835 }
6836 }
6837 }
6838 else
6839 {
6840 header = 1;
6841
paulfee0f4c2004-09-13 05:12:46 +00006842 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006843 {
6844 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6845 {
6846 for (ri = rn->info; ri; ri = ri->next)
6847 {
6848 if (header)
6849 {
6850 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6851 header = 0;
6852 }
6853 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006854
6855 if (pathtype == BGP_PATH_ALL ||
6856 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6857 (pathtype == BGP_PATH_MULTIPATH &&
6858 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6859 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00006860 }
6861 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006862
6863 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006864 }
6865 }
6866
6867 if (! display)
6868 {
6869 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6870 return CMD_WARNING;
6871 }
6872
6873 return CMD_SUCCESS;
6874}
6875
paulfee0f4c2004-09-13 05:12:46 +00006876/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006877static int
paulfd79ac92004-10-13 05:06:08 +00006878bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006879 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006880 int prefix_check, enum bgp_path_type pathtype)
paulfee0f4c2004-09-13 05:12:46 +00006881{
6882 struct bgp *bgp;
6883
6884 /* BGP structure lookup. */
6885 if (view_name)
6886 {
6887 bgp = bgp_lookup_by_name (view_name);
6888 if (bgp == NULL)
6889 {
6890 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6891 return CMD_WARNING;
6892 }
6893 }
6894 else
6895 {
6896 bgp = bgp_get_default ();
6897 if (bgp == NULL)
6898 {
6899 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6900 return CMD_WARNING;
6901 }
6902 }
6903
6904 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006905 afi, safi, prd, prefix_check, pathtype);
paulfee0f4c2004-09-13 05:12:46 +00006906}
6907
paul718e3742002-12-13 20:15:29 +00006908/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006909DEFUN (show_ip_bgp,
6910 show_ip_bgp_cmd,
6911 "show ip bgp",
6912 SHOW_STR
6913 IP_STR
6914 BGP_STR)
6915{
6916 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6917}
6918
6919DEFUN (show_ip_bgp_ipv4,
6920 show_ip_bgp_ipv4_cmd,
6921 "show ip bgp ipv4 (unicast|multicast)",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "Address family\n"
6926 "Address Family modifier\n"
6927 "Address Family modifier\n")
6928{
6929 if (strncmp (argv[0], "m", 1) == 0)
6930 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6931 NULL);
6932
6933 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6934}
6935
6936DEFUN (show_ip_bgp_route,
6937 show_ip_bgp_route_cmd,
6938 "show ip bgp A.B.C.D",
6939 SHOW_STR
6940 IP_STR
6941 BGP_STR
6942 "Network in the BGP routing table to display\n")
6943{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006944 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
6945}
6946
6947DEFUN (show_ip_bgp_route_pathtype,
6948 show_ip_bgp_route_pathtype_cmd,
6949 "show ip bgp A.B.C.D (bestpath|multipath)",
6950 SHOW_STR
6951 IP_STR
6952 BGP_STR
6953 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6954 "Display only the bestpath\n"
6955 "Display only multipaths\n")
6956{
6957 if (strncmp (argv[1], "b", 1) == 0)
6958 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6959 else
6960 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
6961}
6962
6963DEFUN (show_bgp_ipv4_safi_route_pathtype,
6964 show_bgp_ipv4_safi_route_pathtype_cmd,
6965 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
6966 SHOW_STR
6967 BGP_STR
6968 "Address family\n"
6969 "Address Family modifier\n"
6970 "Address Family modifier\n"
6971 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6972 "Display only the bestpath\n"
6973 "Display only multipaths\n")
6974{
6975 if (strncmp (argv[0], "m", 1) == 0)
6976 if (strncmp (argv[2], "b", 1) == 0)
6977 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
6978 else
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
6980 else
6981 if (strncmp (argv[2], "b", 1) == 0)
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6983 else
6984 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006985}
6986
6987DEFUN (show_ip_bgp_ipv4_route,
6988 show_ip_bgp_ipv4_route_cmd,
6989 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6990 SHOW_STR
6991 IP_STR
6992 BGP_STR
6993 "Address family\n"
6994 "Address Family modifier\n"
6995 "Address Family modifier\n"
6996 "Network in the BGP routing table to display\n")
6997{
6998 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006999 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007000
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007001 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007002}
7003
7004DEFUN (show_ip_bgp_vpnv4_all_route,
7005 show_ip_bgp_vpnv4_all_route_cmd,
7006 "show ip bgp vpnv4 all A.B.C.D",
7007 SHOW_STR
7008 IP_STR
7009 BGP_STR
7010 "Display VPNv4 NLRI specific information\n"
7011 "Display information about all VPNv4 NLRIs\n"
7012 "Network in the BGP routing table to display\n")
7013{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007014 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 -05007015}
7016
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007017
Lou Bergerf9b6c392016-01-12 13:42:09 -05007018DEFUN (show_ip_bgp_vpnv4_rd_route,
7019 show_ip_bgp_vpnv4_rd_route_cmd,
7020 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7021 SHOW_STR
7022 IP_STR
7023 BGP_STR
7024 "Display VPNv4 NLRI specific information\n"
7025 "Display information for a route distinguisher\n"
7026 "VPN Route Distinguisher\n"
7027 "Network in the BGP routing table to display\n")
7028{
7029 int ret;
7030 struct prefix_rd prd;
7031
7032 ret = str2prefix_rd (argv[0], &prd);
7033 if (! ret)
7034 {
7035 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7036 return CMD_WARNING;
7037 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007038 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 -05007039}
7040
7041DEFUN (show_ip_bgp_prefix,
7042 show_ip_bgp_prefix_cmd,
7043 "show ip bgp A.B.C.D/M",
7044 SHOW_STR
7045 IP_STR
7046 BGP_STR
7047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7048{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007049 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7050}
7051
7052DEFUN (show_ip_bgp_prefix_pathtype,
7053 show_ip_bgp_prefix_pathtype_cmd,
7054 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7055 SHOW_STR
7056 IP_STR
7057 BGP_STR
7058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7059 "Display only the bestpath\n"
7060 "Display only multipaths\n")
7061{
7062 if (strncmp (argv[1], "b", 1) == 0)
7063 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7064 else
7065 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007066}
7067
7068DEFUN (show_ip_bgp_ipv4_prefix,
7069 show_ip_bgp_ipv4_prefix_cmd,
7070 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7071 SHOW_STR
7072 IP_STR
7073 BGP_STR
7074 "Address family\n"
7075 "Address Family modifier\n"
7076 "Address Family modifier\n"
7077 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7078{
7079 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007080 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007081
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007082 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007083}
7084
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007085DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7086 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7087 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7088 SHOW_STR
7089 IP_STR
7090 BGP_STR
7091 "Address family\n"
7092 "Address Family modifier\n"
7093 "Address Family modifier\n"
7094 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7095 "Display only the bestpath\n"
7096 "Display only multipaths\n")
7097{
7098 if (strncmp (argv[0], "m", 1) == 0)
7099 if (strncmp (argv[2], "b", 1) == 0)
7100 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7101 else
7102 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7103 else
7104 if (strncmp (argv[2], "b", 1) == 0)
7105 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7106 else
7107 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7108}
7109
7110ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7111 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7112 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7113 SHOW_STR
7114 BGP_STR
7115 "Address family\n"
7116 "Address Family modifier\n"
7117 "Address Family modifier\n"
7118 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7119 "Display only the bestpath\n"
7120 "Display only multipaths\n")
7121
Lou Bergerf9b6c392016-01-12 13:42:09 -05007122DEFUN (show_ip_bgp_vpnv4_all_prefix,
7123 show_ip_bgp_vpnv4_all_prefix_cmd,
7124 "show ip bgp vpnv4 all A.B.C.D/M",
7125 SHOW_STR
7126 IP_STR
7127 BGP_STR
7128 "Display VPNv4 NLRI specific information\n"
7129 "Display information about all VPNv4 NLRIs\n"
7130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7131{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007132 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 -05007133}
7134
7135DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7136 show_ip_bgp_vpnv4_rd_prefix_cmd,
7137 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7138 SHOW_STR
7139 IP_STR
7140 BGP_STR
7141 "Display VPNv4 NLRI specific information\n"
7142 "Display information for a route distinguisher\n"
7143 "VPN Route Distinguisher\n"
7144 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7145{
7146 int ret;
7147 struct prefix_rd prd;
7148
7149 ret = str2prefix_rd (argv[0], &prd);
7150 if (! ret)
7151 {
7152 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7153 return CMD_WARNING;
7154 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007155 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 -05007156}
7157
7158DEFUN (show_ip_bgp_view,
7159 show_ip_bgp_view_cmd,
7160 "show ip bgp view WORD",
7161 SHOW_STR
7162 IP_STR
7163 BGP_STR
7164 "BGP view\n"
7165 "View name\n")
7166{
7167 struct bgp *bgp;
7168
7169 /* BGP structure lookup. */
7170 bgp = bgp_lookup_by_name (argv[0]);
7171 if (bgp == NULL)
7172 {
7173 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7174 return CMD_WARNING;
7175 }
7176
7177 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7178}
7179
7180DEFUN (show_ip_bgp_view_route,
7181 show_ip_bgp_view_route_cmd,
7182 "show ip bgp view WORD A.B.C.D",
7183 SHOW_STR
7184 IP_STR
7185 BGP_STR
7186 "BGP view\n"
7187 "View name\n"
7188 "Network in the BGP routing table to display\n")
7189{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007190 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 -05007191}
7192
7193DEFUN (show_ip_bgp_view_prefix,
7194 show_ip_bgp_view_prefix_cmd,
7195 "show ip bgp view WORD A.B.C.D/M",
7196 SHOW_STR
7197 IP_STR
7198 BGP_STR
7199 "BGP view\n"
7200 "View name\n"
7201 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7202{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007203 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 -05007204}
7205
7206DEFUN (show_bgp,
7207 show_bgp_cmd,
7208 "show bgp",
7209 SHOW_STR
7210 BGP_STR)
7211{
7212 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7213 NULL);
7214}
7215
7216ALIAS (show_bgp,
7217 show_bgp_ipv6_cmd,
7218 "show bgp ipv6",
7219 SHOW_STR
7220 BGP_STR
7221 "Address family\n")
7222
7223/* old command */
7224DEFUN (show_ipv6_bgp,
7225 show_ipv6_bgp_cmd,
7226 "show ipv6 bgp",
7227 SHOW_STR
7228 IP_STR
7229 BGP_STR)
7230{
7231 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7232 NULL);
7233}
7234
7235DEFUN (show_bgp_route,
7236 show_bgp_route_cmd,
7237 "show bgp X:X::X:X",
7238 SHOW_STR
7239 BGP_STR
7240 "Network in the BGP routing table to display\n")
7241{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007242 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007243}
7244
Lou Berger35c36862016-01-12 13:42:06 -05007245DEFUN (show_bgp_ipv4_safi,
7246 show_bgp_ipv4_safi_cmd,
7247 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007248 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007249 BGP_STR
7250 "Address family\n"
7251 "Address Family modifier\n"
7252 "Address Family modifier\n")
7253{
7254 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007255 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7256 NULL);
paul718e3742002-12-13 20:15:29 +00007257
ajs5a646652004-11-05 01:25:55 +00007258 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007259}
7260
Lou Berger35c36862016-01-12 13:42:06 -05007261DEFUN (show_bgp_ipv4_safi_route,
7262 show_bgp_ipv4_safi_route_cmd,
7263 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007264 SHOW_STR
7265 BGP_STR
7266 "Address family\n"
7267 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007268 "Address Family modifier\n"
7269 "Network in the BGP routing table to display\n")
7270{
7271 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007272 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007273
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007274 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7275}
7276
7277DEFUN (show_bgp_route_pathtype,
7278 show_bgp_route_pathtype_cmd,
7279 "show bgp X:X::X:X (bestpath|multipath)",
7280 SHOW_STR
7281 BGP_STR
7282 "Network in the BGP routing table to display\n"
7283 "Display only the bestpath\n"
7284 "Display only multipaths\n")
7285{
7286 if (strncmp (argv[1], "b", 1) == 0)
7287 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7288 else
7289 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7290}
7291
7292ALIAS (show_bgp_route_pathtype,
7293 show_bgp_ipv6_route_pathtype_cmd,
7294 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7295 SHOW_STR
7296 BGP_STR
7297 "Address family\n"
7298 "Network in the BGP routing table to display\n"
7299 "Display only the bestpath\n"
7300 "Display only multipaths\n")
7301
7302DEFUN (show_bgp_ipv6_safi_route_pathtype,
7303 show_bgp_ipv6_safi_route_pathtype_cmd,
7304 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7305 SHOW_STR
7306 BGP_STR
7307 "Address family\n"
7308 "Address Family modifier\n"
7309 "Address Family modifier\n"
7310 "Network in the BGP routing table to display\n"
7311 "Display only the bestpath\n"
7312 "Display only multipaths\n")
7313{
7314 if (strncmp (argv[0], "m", 1) == 0)
7315 if (strncmp (argv[2], "b", 1) == 0)
7316 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7317 else
7318 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7319 else
7320 if (strncmp (argv[2], "b", 1) == 0)
7321 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7322 else
7323 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007324}
7325
Lou Berger35c36862016-01-12 13:42:06 -05007326DEFUN (show_bgp_ipv4_vpn_route,
7327 show_bgp_ipv4_vpn_route_cmd,
7328 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007329 SHOW_STR
7330 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007331 "Address Family\n"
7332 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007333 "Network in the BGP routing table to display\n")
7334{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007335 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007336}
7337
Lou Berger35c36862016-01-12 13:42:06 -05007338DEFUN (show_bgp_ipv6_vpn_route,
7339 show_bgp_ipv6_vpn_route_cmd,
7340 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007341 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007342 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007343 "Address Family\n"
7344 "Display VPN NLRI specific information\n"
7345 "Network in the BGP routing table to display\n")
7346{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007347 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 -05007348}
Lou Berger35c36862016-01-12 13:42:06 -05007349
7350DEFUN (show_bgp_ipv4_vpn_rd_route,
7351 show_bgp_ipv4_vpn_rd_route_cmd,
7352 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7353 SHOW_STR
7354 BGP_STR
7355 IP_STR
7356 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007357 "Display information for a route distinguisher\n"
7358 "VPN Route Distinguisher\n"
7359 "Network in the BGP routing table to display\n")
7360{
7361 int ret;
7362 struct prefix_rd prd;
7363
7364 ret = str2prefix_rd (argv[0], &prd);
7365 if (! ret)
7366 {
7367 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7368 return CMD_WARNING;
7369 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007370 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007371}
7372
Lou Berger35c36862016-01-12 13:42:06 -05007373DEFUN (show_bgp_ipv6_vpn_rd_route,
7374 show_bgp_ipv6_vpn_rd_route_cmd,
7375 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007376 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007377 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007378 "Address Family\n"
7379 "Display VPN NLRI specific information\n"
7380 "Display information for a route distinguisher\n"
7381 "VPN Route Distinguisher\n"
7382 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007383{
Lou Berger35c36862016-01-12 13:42:06 -05007384 int ret;
7385 struct prefix_rd prd;
7386
7387 ret = str2prefix_rd (argv[0], &prd);
7388 if (! ret)
7389 {
7390 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7391 return CMD_WARNING;
7392 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007393 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7394}
7395
7396DEFUN (show_bgp_prefix_pathtype,
7397 show_bgp_prefix_pathtype_cmd,
7398 "show bgp X:X::X:X/M (bestpath|multipath)",
7399 SHOW_STR
7400 BGP_STR
7401 "IPv6 prefix <network>/<length>\n"
7402 "Display only the bestpath\n"
7403 "Display only multipaths\n")
7404{
7405 if (strncmp (argv[1], "b", 1) == 0)
7406 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7407 else
7408 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7409}
7410
7411ALIAS (show_bgp_prefix_pathtype,
7412 show_bgp_ipv6_prefix_pathtype_cmd,
7413 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7414 SHOW_STR
7415 BGP_STR
7416 "Address family\n"
7417 "IPv6 prefix <network>/<length>\n"
7418 "Display only the bestpath\n"
7419 "Display only multipaths\n")
7420
7421DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7422 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7423 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7424 SHOW_STR
7425 BGP_STR
7426 "Address family\n"
7427 "Address Family modifier\n"
7428 "Address Family modifier\n"
7429 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7430 "Display only the bestpath\n"
7431 "Display only multipaths\n")
7432{
7433 if (strncmp (argv[0], "m", 1) == 0)
7434 if (strncmp (argv[2], "b", 1) == 0)
7435 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7436 else
7437 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7438 else
7439 if (strncmp (argv[2], "b", 1) == 0)
7440 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7441 else
7442 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007443}
7444
Lou Berger651b4022016-01-12 13:42:07 -05007445DEFUN (show_bgp_ipv4_encap_route,
7446 show_bgp_ipv4_encap_route_cmd,
7447 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007448 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007449 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007450 IP_STR
7451 "Display ENCAP NLRI specific information\n"
7452 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007453{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007454 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007455}
7456
Lou Berger651b4022016-01-12 13:42:07 -05007457DEFUN (show_bgp_ipv6_encap_route,
7458 show_bgp_ipv6_encap_route_cmd,
7459 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007460 SHOW_STR
7461 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007462 IP6_STR
7463 "Display ENCAP NLRI specific information\n"
7464 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007465{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007466 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007467}
7468
Lou Berger651b4022016-01-12 13:42:07 -05007469DEFUN (show_bgp_ipv4_safi_rd_route,
7470 show_bgp_ipv4_safi_rd_route_cmd,
7471 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007472 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007473 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007474 "Address Family\n"
7475 "Address Family Modifier\n"
7476 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007477 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007478 "ENCAP Route Distinguisher\n"
7479 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007480{
7481 int ret;
7482 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007483 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007484
Lou Berger651b4022016-01-12 13:42:07 -05007485 if (bgp_parse_safi(argv[0], &safi)) {
7486 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7487 return CMD_WARNING;
7488 }
7489 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007490 if (! ret)
7491 {
7492 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7493 return CMD_WARNING;
7494 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007495 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007496}
7497
Lou Berger651b4022016-01-12 13:42:07 -05007498DEFUN (show_bgp_ipv6_safi_rd_route,
7499 show_bgp_ipv6_safi_rd_route_cmd,
7500 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007501 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007502 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007503 "Address Family\n"
7504 "Address Family Modifier\n"
7505 "Address Family Modifier\n"
7506 "Display information for a route distinguisher\n"
7507 "ENCAP Route Distinguisher\n"
7508 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007509{
Lou Berger651b4022016-01-12 13:42:07 -05007510 int ret;
7511 struct prefix_rd prd;
7512 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007513
Lou Berger651b4022016-01-12 13:42:07 -05007514 if (bgp_parse_safi(argv[0], &safi)) {
7515 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7516 return CMD_WARNING;
7517 }
7518 ret = str2prefix_rd (argv[1], &prd);
7519 if (! ret)
7520 {
7521 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7522 return CMD_WARNING;
7523 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007524 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007525}
7526
Lou Berger35c36862016-01-12 13:42:06 -05007527DEFUN (show_bgp_ipv4_prefix,
7528 show_bgp_ipv4_prefix_cmd,
7529 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007530 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007531 BGP_STR
paul718e3742002-12-13 20:15:29 +00007532 IP_STR
paul718e3742002-12-13 20:15:29 +00007533 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7534{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007535 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007536}
7537
Lou Berger35c36862016-01-12 13:42:06 -05007538DEFUN (show_bgp_ipv4_safi_prefix,
7539 show_bgp_ipv4_safi_prefix_cmd,
7540 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007541 SHOW_STR
7542 BGP_STR
7543 "Address family\n"
7544 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007545 "Address Family modifier\n"
7546 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007547{
7548 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007549 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007550
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007551 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007552}
7553
Lou Berger35c36862016-01-12 13:42:06 -05007554DEFUN (show_bgp_ipv4_vpn_prefix,
7555 show_bgp_ipv4_vpn_prefix_cmd,
7556 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007557 SHOW_STR
7558 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007559 IP_STR
7560 "Display VPN NLRI specific information\n"
7561 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007562{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007563 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007564}
7565
Lou Berger35c36862016-01-12 13:42:06 -05007566DEFUN (show_bgp_ipv6_vpn_prefix,
7567 show_bgp_ipv6_vpn_prefix_cmd,
7568 "show bgp ipv6 vpn X:X::X:X/M",
7569 SHOW_STR
7570 BGP_STR
7571 "Address Family\n"
7572 "Display VPN NLRI specific information\n"
7573 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7574{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007575 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 -05007576}
Lou Berger35c36862016-01-12 13:42:06 -05007577
Lou Berger651b4022016-01-12 13:42:07 -05007578DEFUN (show_bgp_ipv4_encap_prefix,
7579 show_bgp_ipv4_encap_prefix_cmd,
7580 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007581 SHOW_STR
7582 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007583 IP_STR
7584 "Display ENCAP NLRI specific information\n"
7585 "Display information about ENCAP NLRIs\n"
7586 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7587{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007588 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007589}
paul718e3742002-12-13 20:15:29 +00007590
Lou Berger651b4022016-01-12 13:42:07 -05007591DEFUN (show_bgp_ipv6_encap_prefix,
7592 show_bgp_ipv6_encap_prefix_cmd,
7593 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007594 SHOW_STR
7595 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007596 IP_STR
7597 "Display ENCAP NLRI specific information\n"
7598 "Display information about ENCAP NLRIs\n"
7599 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7600{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007601 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007602}
Lou Berger651b4022016-01-12 13:42:07 -05007603
7604DEFUN (show_bgp_ipv4_safi_rd_prefix,
7605 show_bgp_ipv4_safi_rd_prefix_cmd,
7606 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7607 SHOW_STR
7608 BGP_STR
7609 "Address Family\n"
7610 "Address Family Modifier\n"
7611 "Address Family Modifier\n"
7612 "Display information for a route distinguisher\n"
7613 "ENCAP Route Distinguisher\n"
7614 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7615{
7616 int ret;
7617 struct prefix_rd prd;
7618 safi_t safi;
7619
7620 if (bgp_parse_safi(argv[0], &safi)) {
7621 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7622 return CMD_WARNING;
7623 }
7624
7625 ret = str2prefix_rd (argv[1], &prd);
7626 if (! ret)
7627 {
7628 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7629 return CMD_WARNING;
7630 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007631 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007632}
7633
Lou Berger651b4022016-01-12 13:42:07 -05007634DEFUN (show_bgp_ipv6_safi_rd_prefix,
7635 show_bgp_ipv6_safi_rd_prefix_cmd,
7636 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7637 SHOW_STR
7638 BGP_STR
7639 "Address Family\n"
7640 "Address Family Modifier\n"
7641 "Address Family Modifier\n"
7642 "Display information for a route distinguisher\n"
7643 "ENCAP Route Distinguisher\n"
7644 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7645{
7646 int ret;
7647 struct prefix_rd prd;
7648 safi_t safi;
7649
7650 if (bgp_parse_safi(argv[0], &safi)) {
7651 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7652 return CMD_WARNING;
7653 }
7654
7655 ret = str2prefix_rd (argv[1], &prd);
7656 if (! ret)
7657 {
7658 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7659 return CMD_WARNING;
7660 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007661 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007662}
Lou Berger651b4022016-01-12 13:42:07 -05007663
7664DEFUN (show_bgp_afi_safi_view,
7665 show_bgp_afi_safi_view_cmd,
7666 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7667 SHOW_STR
7668 BGP_STR
7669 "BGP view\n"
7670 "BGP view name\n"
7671 "Address Family\n"
7672 "Address Family\n"
7673 "Address Family Modifier\n"
7674 "Address Family Modifier\n"
7675 "Address Family Modifier\n"
7676 "Address Family Modifier\n"
7677 )
7678{
7679 struct bgp *bgp;
7680 safi_t safi;
7681 afi_t afi;
7682
7683 if (bgp_parse_afi(argv[1], &afi)) {
7684 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7685 return CMD_WARNING;
7686 }
7687 if (bgp_parse_safi(argv[2], &safi)) {
7688 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7689 return CMD_WARNING;
7690 }
7691
7692 /* BGP structure lookup. */
7693 bgp = bgp_lookup_by_name (argv[0]);
7694 if (bgp == NULL)
7695 {
7696 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7697 return CMD_WARNING;
7698 }
7699
7700 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7701}
7702
7703DEFUN (show_bgp_view_afi_safi_route,
7704 show_bgp_view_afi_safi_route_cmd,
7705 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7706 SHOW_STR
7707 BGP_STR
7708 "BGP view\n"
7709 "View name\n"
7710 "Address Family\n"
7711 "Address Family\n"
7712 "Address Family Modifier\n"
7713 "Address Family Modifier\n"
7714 "Address Family Modifier\n"
7715 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007716 "Network in the BGP routing table to display\n")
7717{
Lou Berger651b4022016-01-12 13:42:07 -05007718 safi_t safi;
7719 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007720
Lou Berger651b4022016-01-12 13:42:07 -05007721 if (bgp_parse_afi(argv[1], &afi)) {
7722 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7723 return CMD_WARNING;
7724 }
7725 if (bgp_parse_safi(argv[2], &safi)) {
7726 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7727 return CMD_WARNING;
7728 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007729 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007730}
7731
7732DEFUN (show_bgp_view_afi_safi_prefix,
7733 show_bgp_view_afi_safi_prefix_cmd,
7734 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7735 SHOW_STR
7736 BGP_STR
7737 "BGP view\n"
7738 "View name\n"
7739 "Address Family\n"
7740 "Address Family\n"
7741 "Address Family Modifier\n"
7742 "Address Family Modifier\n"
7743 "Address Family Modifier\n"
7744 "Address Family Modifier\n"
7745 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7746{
7747 safi_t safi;
7748 afi_t afi;
7749
7750 if (bgp_parse_afi(argv[1], &afi)) {
7751 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7752 return CMD_WARNING;
7753 }
7754 if (bgp_parse_safi(argv[2], &safi)) {
7755 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7756 return CMD_WARNING;
7757 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007758 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007759}
7760
7761/* new001 */
7762DEFUN (show_bgp_afi,
7763 show_bgp_afi_cmd,
7764 "show bgp (ipv4|ipv6)",
7765 SHOW_STR
7766 BGP_STR
7767 "Address family\n"
7768 "Address family\n")
7769{
7770 afi_t afi;
7771
7772 if (bgp_parse_afi(argv[0], &afi)) {
7773 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7774 return CMD_WARNING;
7775 }
7776 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7777 NULL);
7778}
7779
Lou Berger651b4022016-01-12 13:42:07 -05007780DEFUN (show_bgp_ipv6_safi,
7781 show_bgp_ipv6_safi_cmd,
7782 "show bgp ipv6 (unicast|multicast)",
7783 SHOW_STR
7784 BGP_STR
7785 "Address family\n"
7786 "Address Family modifier\n"
7787 "Address Family modifier\n")
7788{
7789 if (strncmp (argv[0], "m", 1) == 0)
7790 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7791 NULL);
7792
7793 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007794}
7795
Lou Berger35c36862016-01-12 13:42:06 -05007796DEFUN (show_bgp_ipv6_route,
7797 show_bgp_ipv6_route_cmd,
7798 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007799 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007800 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007801 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007802 "Network in the BGP routing table to display\n")
7803{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007804 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007805}
7806
Lou Berger35c36862016-01-12 13:42:06 -05007807DEFUN (show_bgp_ipv6_safi_route,
7808 show_bgp_ipv6_safi_route_cmd,
7809 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007810 SHOW_STR
7811 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007812 "Address family\n"
7813 "Address Family modifier\n"
7814 "Address Family modifier\n"
7815 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007816{
Lou Berger35c36862016-01-12 13:42:06 -05007817 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007818 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007819
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007820 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007821}
7822
Lou Bergerf9b6c392016-01-12 13:42:09 -05007823/* old command */
7824DEFUN (show_ipv6_bgp_route,
7825 show_ipv6_bgp_route_cmd,
7826 "show ipv6 bgp X:X::X:X",
7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "Network in the BGP routing table to display\n")
7831{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007832 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007833}
7834
7835DEFUN (show_bgp_prefix,
7836 show_bgp_prefix_cmd,
7837 "show bgp X:X::X:X/M",
7838 SHOW_STR
7839 BGP_STR
7840 "IPv6 prefix <network>/<length>\n")
7841{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007842 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007843}
7844
7845
Lou Berger35c36862016-01-12 13:42:06 -05007846/* new002 */
7847DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007848 show_bgp_ipv6_prefix_cmd,
7849 "show bgp ipv6 X:X::X:X/M",
7850 SHOW_STR
7851 BGP_STR
7852 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007853 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7854{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007855 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007856}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007857DEFUN (show_bgp_ipv6_safi_prefix,
7858 show_bgp_ipv6_safi_prefix_cmd,
7859 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7860 SHOW_STR
7861 BGP_STR
7862 "Address family\n"
7863 "Address Family modifier\n"
7864 "Address Family modifier\n"
7865 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7866{
7867 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007868 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007869
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007870 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007871}
7872
Lou Bergerf9b6c392016-01-12 13:42:09 -05007873/* old command */
7874DEFUN (show_ipv6_bgp_prefix,
7875 show_ipv6_bgp_prefix_cmd,
7876 "show ipv6 bgp X:X::X:X/M",
7877 SHOW_STR
7878 IP_STR
7879 BGP_STR
7880 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7881{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007882 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007883}
7884
paulbb46e942003-10-24 19:02:03 +00007885DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007886 show_bgp_view_cmd,
7887 "show bgp view WORD",
7888 SHOW_STR
7889 BGP_STR
7890 "BGP view\n"
7891 "View name\n")
7892{
7893 struct bgp *bgp;
7894
7895 /* BGP structure lookup. */
7896 bgp = bgp_lookup_by_name (argv[0]);
7897 if (bgp == NULL)
7898 {
7899 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7900 return CMD_WARNING;
7901 }
7902
7903 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7904}
7905
7906DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007907 show_bgp_view_ipv6_cmd,
7908 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007909 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007910 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007911 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007912 "View name\n"
7913 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007914{
7915 struct bgp *bgp;
7916
7917 /* BGP structure lookup. */
7918 bgp = bgp_lookup_by_name (argv[0]);
7919 if (bgp == NULL)
7920 {
7921 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7922 return CMD_WARNING;
7923 }
7924
ajs5a646652004-11-05 01:25:55 +00007925 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007926}
paulbb46e942003-10-24 19:02:03 +00007927
7928DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007929 show_bgp_view_route_cmd,
7930 "show bgp view WORD X:X::X:X",
7931 SHOW_STR
7932 BGP_STR
7933 "BGP view\n"
7934 "View name\n"
7935 "Network in the BGP routing table to display\n")
7936{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007937 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 -05007938}
7939
7940DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007941 show_bgp_view_ipv6_route_cmd,
7942 "show bgp view WORD ipv6 X:X::X:X",
7943 SHOW_STR
7944 BGP_STR
7945 "BGP view\n"
7946 "View name\n"
7947 "Address family\n"
7948 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007949{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007950 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulbb46e942003-10-24 19:02:03 +00007951}
7952
Lou Bergerf9b6c392016-01-12 13:42:09 -05007953/* old command */
7954DEFUN (show_ipv6_mbgp,
7955 show_ipv6_mbgp_cmd,
7956 "show ipv6 mbgp",
7957 SHOW_STR
7958 IP_STR
7959 MBGP_STR)
7960{
7961 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7962 NULL);
7963}
7964
7965/* old command */
7966DEFUN (show_ipv6_mbgp_route,
7967 show_ipv6_mbgp_route_cmd,
7968 "show ipv6 mbgp X:X::X:X",
7969 SHOW_STR
7970 IP_STR
7971 MBGP_STR
7972 "Network in the MBGP routing table to display\n")
7973{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007974 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007975}
7976
7977/* old command */
7978DEFUN (show_ipv6_mbgp_prefix,
7979 show_ipv6_mbgp_prefix_cmd,
7980 "show ipv6 mbgp X:X::X:X/M",
7981 SHOW_STR
7982 IP_STR
7983 MBGP_STR
7984 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7985{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007986 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007987}
7988
Lou Berger35c36862016-01-12 13:42:06 -05007989DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007990 show_bgp_view_prefix_cmd,
7991 "show bgp view WORD X:X::X:X/M",
7992 SHOW_STR
7993 BGP_STR
7994 "BGP view\n"
7995 "View name\n"
7996 "IPv6 prefix <network>/<length>\n")
7997{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007998 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 -05007999}
8000
8001DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00008002 show_bgp_view_ipv6_prefix_cmd,
8003 "show bgp view WORD ipv6 X:X::X:X/M",
8004 SHOW_STR
8005 BGP_STR
8006 "BGP view\n"
8007 "View name\n"
8008 "Address family\n"
8009 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00008010{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07008011 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00008012}
8013
paul94f2b392005-06-28 12:44:16 +00008014static int
paulfd79ac92004-10-13 05:06:08 +00008015bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008016 safi_t safi, enum bgp_show_type type)
8017{
8018 int i;
8019 struct buffer *b;
8020 char *regstr;
8021 int first;
8022 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00008023 int rc;
paul718e3742002-12-13 20:15:29 +00008024
8025 first = 0;
8026 b = buffer_new (1024);
8027 for (i = 0; i < argc; i++)
8028 {
8029 if (first)
8030 buffer_putc (b, ' ');
8031 else
8032 {
8033 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8034 continue;
8035 first = 1;
8036 }
8037
8038 buffer_putstr (b, argv[i]);
8039 }
8040 buffer_putc (b, '\0');
8041
8042 regstr = buffer_getstr (b);
8043 buffer_free (b);
8044
8045 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00008046 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00008047 if (! regex)
8048 {
8049 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8050 VTY_NEWLINE);
8051 return CMD_WARNING;
8052 }
8053
ajs5a646652004-11-05 01:25:55 +00008054 rc = bgp_show (vty, NULL, afi, safi, type, regex);
8055 bgp_regex_free (regex);
8056 return rc;
paul718e3742002-12-13 20:15:29 +00008057}
8058
Lou Bergerf9b6c392016-01-12 13:42:09 -05008059
8060DEFUN (show_ip_bgp_regexp,
8061 show_ip_bgp_regexp_cmd,
8062 "show ip bgp regexp .LINE",
8063 SHOW_STR
8064 IP_STR
8065 BGP_STR
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_regexp);
8071}
8072
8073DEFUN (show_ip_bgp_flap_regexp,
8074 show_ip_bgp_flap_regexp_cmd,
8075 "show ip bgp flap-statistics regexp .LINE",
8076 SHOW_STR
8077 IP_STR
8078 BGP_STR
8079 "Display flap statistics of routes\n"
8080 "Display routes matching the AS path regular expression\n"
8081 "A regular-expression to match the BGP AS paths\n")
8082{
8083 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8084 bgp_show_type_flap_regexp);
8085}
8086
8087ALIAS (show_ip_bgp_flap_regexp,
8088 show_ip_bgp_damp_flap_regexp_cmd,
8089 "show ip bgp dampening flap-statistics regexp .LINE",
8090 SHOW_STR
8091 IP_STR
8092 BGP_STR
8093 "Display detailed information about dampening\n"
8094 "Display flap statistics of routes\n"
8095 "Display routes matching the AS path regular expression\n"
8096 "A regular-expression to match the BGP AS paths\n")
8097
8098DEFUN (show_ip_bgp_ipv4_regexp,
8099 show_ip_bgp_ipv4_regexp_cmd,
8100 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8101 SHOW_STR
8102 IP_STR
8103 BGP_STR
8104 "Address family\n"
8105 "Address Family modifier\n"
8106 "Address Family modifier\n"
8107 "Display routes matching the AS path regular expression\n"
8108 "A regular-expression to match the BGP AS paths\n")
8109{
8110 if (strncmp (argv[0], "m", 1) == 0)
8111 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8112 bgp_show_type_regexp);
8113
8114 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8115 bgp_show_type_regexp);
8116}
8117
Lou Bergerf9b6c392016-01-12 13:42:09 -05008118DEFUN (show_bgp_regexp,
8119 show_bgp_regexp_cmd,
8120 "show bgp regexp .LINE",
8121 SHOW_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_bgp_regexp,
8132 show_ipv6_bgp_regexp_cmd,
8133 "show ipv6 bgp 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 BGP AS paths\n")
8139{
8140 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8141 bgp_show_type_regexp);
8142}
8143
8144/* old command */
8145DEFUN (show_ipv6_mbgp_regexp,
8146 show_ipv6_mbgp_regexp_cmd,
8147 "show ipv6 mbgp regexp .LINE",
8148 SHOW_STR
8149 IP_STR
8150 BGP_STR
8151 "Display routes matching the AS path regular expression\n"
8152 "A regular-expression to match the MBGP AS paths\n")
8153{
8154 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8155 bgp_show_type_regexp);
8156}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008157
Lou Berger651b4022016-01-12 13:42:07 -05008158DEFUN (show_bgp_ipv4_safi_flap_regexp,
8159 show_bgp_ipv4_safi_flap_regexp_cmd,
8160 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008161 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008162 BGP_STR
paul718e3742002-12-13 20:15:29 +00008163 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008164 "Address Family Modifier\n"
8165 "Address Family Modifier\n"
8166 "Address Family Modifier\n"
8167 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008168 "Display flap statistics of routes\n"
8169 "Display routes matching the AS path regular expression\n"
8170 "A regular-expression to match the BGP AS paths\n")
8171{
Lou Berger651b4022016-01-12 13:42:07 -05008172 safi_t safi;
8173
8174 if (bgp_parse_safi(argv[0], &safi)) {
8175 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8176 return CMD_WARNING;
8177 }
8178 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8179 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008180}
8181
Lou Berger651b4022016-01-12 13:42:07 -05008182ALIAS (show_bgp_ipv4_safi_flap_regexp,
8183 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8184 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308185 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308186 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008187 IP_STR
8188 "Address Family Modifier\n"
8189 "Address Family Modifier\n"
8190 "Address Family Modifier\n"
8191 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308192 "Display detailed information about dampening\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
Lou Berger651b4022016-01-12 13:42:07 -05008197DEFUN (show_bgp_ipv6_safi_flap_regexp,
8198 show_bgp_ipv6_safi_flap_regexp_cmd,
8199 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008200 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008201 BGP_STR
8202 IPV6_STR
8203 "Address Family Modifier\n"
8204 "Address Family Modifier\n"
8205 "Address Family Modifier\n"
8206 "Address Family Modifier\n"
8207 "Display flap statistics of routes\n"
8208 "Display routes matching the AS path regular expression\n"
8209 "A regular-expression to match the BGP AS paths\n")
8210{
8211 safi_t safi;
8212
8213 if (bgp_parse_safi(argv[0], &safi)) {
8214 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8215 return CMD_WARNING;
8216 }
8217 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8218 bgp_show_type_flap_regexp);
8219}
8220
8221ALIAS (show_bgp_ipv6_safi_flap_regexp,
8222 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8223 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8224 SHOW_STR
8225 BGP_STR
8226 IPV6_STR
8227 "Address Family Modifier\n"
8228 "Address Family Modifier\n"
8229 "Address Family Modifier\n"
8230 "Address Family Modifier\n"
8231 "Display detailed information about dampening\n"
8232 "Display flap statistics of routes\n"
8233 "Display routes matching the AS path regular expression\n"
8234 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008235
8236DEFUN (show_bgp_ipv4_safi_regexp,
8237 show_bgp_ipv4_safi_regexp_cmd,
8238 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8239 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008240 BGP_STR
8241 "Address family\n"
8242 "Address Family modifier\n"
8243 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008244 "Address Family modifier\n"
8245 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008246 "Display routes matching the AS path regular expression\n"
8247 "A regular-expression to match the BGP AS paths\n")
8248{
Lou Berger651b4022016-01-12 13:42:07 -05008249 safi_t safi;
8250 if (bgp_parse_safi(argv[0], &safi)) {
8251 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8252 return CMD_WARNING;
8253 }
paul718e3742002-12-13 20:15:29 +00008254
Lou Berger651b4022016-01-12 13:42:07 -05008255 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008256 bgp_show_type_regexp);
8257}
Lou Berger205e6742016-01-12 13:42:11 -05008258
Lou Berger651b4022016-01-12 13:42:07 -05008259DEFUN (show_bgp_ipv6_safi_regexp,
8260 show_bgp_ipv6_safi_regexp_cmd,
8261 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008262 SHOW_STR
8263 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008264 "Address family\n"
8265 "Address Family modifier\n"
8266 "Address Family modifier\n"
8267 "Address Family modifier\n"
8268 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008269 "Display routes matching the AS path regular expression\n"
8270 "A regular-expression to match the BGP AS paths\n")
8271{
Lou Berger651b4022016-01-12 13:42:07 -05008272 safi_t safi;
8273 if (bgp_parse_safi(argv[0], &safi)) {
8274 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8275 return CMD_WARNING;
8276 }
8277
8278 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008279 bgp_show_type_regexp);
8280}
8281
Lou Berger651b4022016-01-12 13:42:07 -05008282DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008283 show_bgp_ipv6_regexp_cmd,
8284 "show bgp ipv6 regexp .LINE",
8285 SHOW_STR
8286 BGP_STR
8287 "Address family\n"
8288 "Display routes matching the AS path regular expression\n"
8289 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008290{
8291 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8292 bgp_show_type_regexp);
8293}
8294
paul94f2b392005-06-28 12:44:16 +00008295static int
paulfd79ac92004-10-13 05:06:08 +00008296bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008297 safi_t safi, enum bgp_show_type type)
8298{
8299 struct prefix_list *plist;
8300
8301 plist = prefix_list_lookup (afi, prefix_list_str);
8302 if (plist == NULL)
8303 {
8304 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8305 prefix_list_str, VTY_NEWLINE);
8306 return CMD_WARNING;
8307 }
8308
ajs5a646652004-11-05 01:25:55 +00008309 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008310}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008311DEFUN (show_ip_bgp_prefix_list,
8312 show_ip_bgp_prefix_list_cmd,
8313 "show ip bgp prefix-list WORD",
8314 SHOW_STR
8315 IP_STR
8316 BGP_STR
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_prefix_list);
8322}
8323
8324DEFUN (show_ip_bgp_flap_prefix_list,
8325 show_ip_bgp_flap_prefix_list_cmd,
8326 "show ip bgp flap-statistics prefix-list WORD",
8327 SHOW_STR
8328 IP_STR
8329 BGP_STR
8330 "Display flap statistics of routes\n"
8331 "Display routes conforming to the prefix-list\n"
8332 "IP prefix-list name\n")
8333{
8334 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8335 bgp_show_type_flap_prefix_list);
8336}
8337
8338ALIAS (show_ip_bgp_flap_prefix_list,
8339 show_ip_bgp_damp_flap_prefix_list_cmd,
8340 "show ip bgp dampening flap-statistics prefix-list WORD",
8341 SHOW_STR
8342 IP_STR
8343 BGP_STR
8344 "Display detailed information about dampening\n"
8345 "Display flap statistics of routes\n"
8346 "Display routes conforming to the prefix-list\n"
8347 "IP prefix-list name\n")
8348
8349DEFUN (show_ip_bgp_ipv4_prefix_list,
8350 show_ip_bgp_ipv4_prefix_list_cmd,
8351 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8352 SHOW_STR
8353 IP_STR
8354 BGP_STR
8355 "Address family\n"
8356 "Address Family modifier\n"
8357 "Address Family modifier\n"
8358 "Display routes conforming to the prefix-list\n"
8359 "IP prefix-list name\n")
8360{
8361 if (strncmp (argv[0], "m", 1) == 0)
8362 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8363 bgp_show_type_prefix_list);
8364
8365 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8366 bgp_show_type_prefix_list);
8367}
8368
Lou Bergerf9b6c392016-01-12 13:42:09 -05008369DEFUN (show_bgp_prefix_list,
8370 show_bgp_prefix_list_cmd,
8371 "show bgp prefix-list WORD",
8372 SHOW_STR
8373 BGP_STR
8374 "Display routes conforming to the prefix-list\n"
8375 "IPv6 prefix-list name\n")
8376{
8377 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8378 bgp_show_type_prefix_list);
8379}
8380
8381ALIAS (show_bgp_prefix_list,
8382 show_bgp_ipv6_prefix_list_cmd,
8383 "show bgp ipv6 prefix-list WORD",
8384 SHOW_STR
8385 BGP_STR
8386 "Address family\n"
8387 "Display routes conforming to the prefix-list\n"
8388 "IPv6 prefix-list name\n")
8389
8390/* old command */
8391DEFUN (show_ipv6_bgp_prefix_list,
8392 show_ipv6_bgp_prefix_list_cmd,
8393 "show ipv6 bgp prefix-list WORD",
8394 SHOW_STR
8395 IPV6_STR
8396 BGP_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_UNICAST,
8401 bgp_show_type_prefix_list);
8402}
8403
8404/* old command */
8405DEFUN (show_ipv6_mbgp_prefix_list,
8406 show_ipv6_mbgp_prefix_list_cmd,
8407 "show ipv6 mbgp prefix-list WORD",
8408 SHOW_STR
8409 IPV6_STR
8410 MBGP_STR
8411 "Display routes matching the prefix-list\n"
8412 "IPv6 prefix-list name\n")
8413{
8414 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8415 bgp_show_type_prefix_list);
8416}
paul718e3742002-12-13 20:15:29 +00008417
Lou Berger35c36862016-01-12 13:42:06 -05008418DEFUN (show_bgp_ipv4_prefix_list,
8419 show_bgp_ipv4_prefix_list_cmd,
8420 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008421 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008422 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008423 IP_STR
paul718e3742002-12-13 20:15:29 +00008424 "Display routes conforming to the prefix-list\n"
8425 "IP prefix-list name\n")
8426{
8427 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8428 bgp_show_type_prefix_list);
8429}
8430
Lou Berger651b4022016-01-12 13:42:07 -05008431DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8432 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8433 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008434 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008435 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008436 IP_STR
8437 "Address Family Modifier\n"
8438 "Address Family Modifier\n"
8439 "Address Family Modifier\n"
8440 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008441 "Display flap statistics of routes\n"
8442 "Display routes conforming to the prefix-list\n"
8443 "IP prefix-list name\n")
8444{
Lou Berger651b4022016-01-12 13:42:07 -05008445 safi_t safi;
8446 if (bgp_parse_safi(argv[0], &safi)) {
8447 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8448 return CMD_WARNING;
8449 }
8450 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008451 bgp_show_type_flap_prefix_list);
8452}
8453
Lou Berger651b4022016-01-12 13:42:07 -05008454ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8455 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8456 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308457 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308458 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008459 IP_STR
8460 "Address Family Modifier\n"
8461 "Address Family Modifier\n"
8462 "Address Family Modifier\n"
8463 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308464 "Display detailed information about dampening\n"
8465 "Display flap statistics of routes\n"
8466 "Display routes conforming to the prefix-list\n"
8467 "IP prefix-list name\n")
8468
Lou Berger651b4022016-01-12 13:42:07 -05008469DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8470 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8471 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008472 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008473 BGP_STR
8474 IPV6_STR
8475 "Address Family Modifier\n"
8476 "Address Family Modifier\n"
8477 "Address Family Modifier\n"
8478 "Address Family Modifier\n"
8479 "Display flap statistics of routes\n"
8480 "Display routes conforming to the prefix-list\n"
8481 "IP prefix-list name\n")
8482{
8483 safi_t safi;
8484 if (bgp_parse_safi(argv[0], &safi)) {
8485 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8486 return CMD_WARNING;
8487 }
8488 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8489 bgp_show_type_flap_prefix_list);
8490}
8491ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8492 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8493 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8494 SHOW_STR
8495 BGP_STR
8496 IPV6_STR
8497 "Address Family Modifier\n"
8498 "Address Family Modifier\n"
8499 "Address Family Modifier\n"
8500 "Address Family Modifier\n"
8501 "Display detailed information about dampening\n"
8502 "Display flap statistics of routes\n"
8503 "Display routes conforming to the prefix-list\n"
8504 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008505
8506DEFUN (show_bgp_ipv4_safi_prefix_list,
8507 show_bgp_ipv4_safi_prefix_list_cmd,
8508 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8509 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008510 BGP_STR
8511 "Address family\n"
8512 "Address Family modifier\n"
8513 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008514 "Address Family modifier\n"
8515 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008516 "Display routes conforming to the prefix-list\n"
8517 "IP prefix-list name\n")
8518{
Lou Berger651b4022016-01-12 13:42:07 -05008519 safi_t safi;
8520 if (bgp_parse_safi(argv[0], &safi)) {
8521 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8522 return CMD_WARNING;
8523 }
8524 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008525 bgp_show_type_prefix_list);
8526}
Lou Berger205e6742016-01-12 13:42:11 -05008527
Lou Berger651b4022016-01-12 13:42:07 -05008528DEFUN (show_bgp_ipv6_safi_prefix_list,
8529 show_bgp_ipv6_safi_prefix_list_cmd,
8530 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008531 SHOW_STR
8532 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008533 "Address family\n"
8534 "Address Family modifier\n"
8535 "Address Family modifier\n"
8536 "Address Family modifier\n"
8537 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008538 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008539 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008540{
Lou Berger651b4022016-01-12 13:42:07 -05008541 safi_t safi;
8542 if (bgp_parse_safi(argv[0], &safi)) {
8543 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8544 return CMD_WARNING;
8545 }
8546 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008547 bgp_show_type_prefix_list);
8548}
8549
paul94f2b392005-06-28 12:44:16 +00008550static int
paulfd79ac92004-10-13 05:06:08 +00008551bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008552 safi_t safi, enum bgp_show_type type)
8553{
8554 struct as_list *as_list;
8555
8556 as_list = as_list_lookup (filter);
8557 if (as_list == NULL)
8558 {
8559 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8560 return CMD_WARNING;
8561 }
8562
ajs5a646652004-11-05 01:25:55 +00008563 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008564}
8565
Lou Bergerf9b6c392016-01-12 13:42:09 -05008566DEFUN (show_ip_bgp_filter_list,
8567 show_ip_bgp_filter_list_cmd,
8568 "show ip bgp filter-list WORD",
8569 SHOW_STR
8570 IP_STR
8571 BGP_STR
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_filter_list);
8577}
8578
8579DEFUN (show_ip_bgp_flap_filter_list,
8580 show_ip_bgp_flap_filter_list_cmd,
8581 "show ip bgp flap-statistics filter-list WORD",
8582 SHOW_STR
8583 IP_STR
8584 BGP_STR
8585 "Display flap statistics of routes\n"
8586 "Display routes conforming to the filter-list\n"
8587 "Regular expression access list name\n")
8588{
8589 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8590 bgp_show_type_flap_filter_list);
8591}
8592
8593ALIAS (show_ip_bgp_flap_filter_list,
8594 show_ip_bgp_damp_flap_filter_list_cmd,
8595 "show ip bgp dampening flap-statistics filter-list WORD",
8596 SHOW_STR
8597 IP_STR
8598 BGP_STR
8599 "Display detailed information about dampening\n"
8600 "Display flap statistics of routes\n"
8601 "Display routes conforming to the filter-list\n"
8602 "Regular expression access list name\n")
8603
8604DEFUN (show_ip_bgp_ipv4_filter_list,
8605 show_ip_bgp_ipv4_filter_list_cmd,
8606 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8607 SHOW_STR
8608 IP_STR
8609 BGP_STR
8610 "Address family\n"
8611 "Address Family modifier\n"
8612 "Address Family modifier\n"
8613 "Display routes conforming to the filter-list\n"
8614 "Regular expression access list name\n")
8615{
8616 if (strncmp (argv[0], "m", 1) == 0)
8617 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8618 bgp_show_type_filter_list);
8619
8620 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8621 bgp_show_type_filter_list);
8622}
8623
Lou Bergerf9b6c392016-01-12 13:42:09 -05008624DEFUN (show_bgp_filter_list,
8625 show_bgp_filter_list_cmd,
8626 "show bgp filter-list WORD",
8627 SHOW_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_bgp_filter_list,
8638 show_ipv6_bgp_filter_list_cmd,
8639 "show ipv6 bgp filter-list WORD",
8640 SHOW_STR
8641 IPV6_STR
8642 BGP_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_UNICAST,
8647 bgp_show_type_filter_list);
8648}
8649
8650/* old command */
8651DEFUN (show_ipv6_mbgp_filter_list,
8652 show_ipv6_mbgp_filter_list_cmd,
8653 "show ipv6 mbgp filter-list WORD",
8654 SHOW_STR
8655 IPV6_STR
8656 MBGP_STR
8657 "Display routes conforming to the filter-list\n"
8658 "Regular expression access list name\n")
8659{
8660 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8661 bgp_show_type_filter_list);
8662}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008663
8664DEFUN (show_ip_bgp_dampening_info,
8665 show_ip_bgp_dampening_params_cmd,
8666 "show ip bgp dampening parameters",
8667 SHOW_STR
8668 IP_STR
8669 BGP_STR
8670 "Display detailed information about dampening\n"
8671 "Display detail of configured dampening parameters\n")
8672{
8673 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8674}
8675
Lou Berger651b4022016-01-12 13:42:07 -05008676DEFUN (show_bgp_ipv4_filter_list,
8677 show_bgp_ipv4_filter_list_cmd,
8678 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008679 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008680 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008681 IP_STR
paul718e3742002-12-13 20:15:29 +00008682 "Display routes conforming to the filter-list\n"
8683 "Regular expression access list name\n")
8684{
8685 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8686 bgp_show_type_filter_list);
8687}
8688
Lou Berger651b4022016-01-12 13:42:07 -05008689DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8690 show_bgp_ipv4_safi_flap_filter_list_cmd,
8691 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008692 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008693 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008694 IP_STR
8695 "Address Family modifier\n"
8696 "Address Family modifier\n"
8697 "Address Family modifier\n"
8698 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008699 "Display flap statistics of routes\n"
8700 "Display routes conforming to the filter-list\n"
8701 "Regular expression access list name\n")
8702{
Lou Berger651b4022016-01-12 13:42:07 -05008703 safi_t safi;
8704
8705 if (bgp_parse_safi(argv[0], &safi)) {
8706 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8707 return CMD_WARNING;
8708 }
8709 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008710 bgp_show_type_flap_filter_list);
8711}
8712
Lou Berger651b4022016-01-12 13:42:07 -05008713ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8714 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8715 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308716 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308717 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008718 IP_STR
8719 "Address Family modifier\n"
8720 "Address Family modifier\n"
8721 "Address Family modifier\n"
8722 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308723 "Display detailed information about dampening\n"
8724 "Display flap statistics of routes\n"
8725 "Display routes conforming to the filter-list\n"
8726 "Regular expression access list name\n")
8727
Lou Berger651b4022016-01-12 13:42:07 -05008728DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8729 show_bgp_ipv6_safi_flap_filter_list_cmd,
8730 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008731 SHOW_STR
8732 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008733 IPV6_STR
8734 "Address Family modifier\n"
8735 "Address Family modifier\n"
8736 "Address Family modifier\n"
8737 "Address Family modifier\n"
8738 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008739 "Display routes conforming to the filter-list\n"
8740 "Regular expression access list name\n")
8741{
Lou Berger651b4022016-01-12 13:42:07 -05008742 safi_t safi;
8743
8744 if (bgp_parse_safi(argv[0], &safi)) {
8745 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8746 return CMD_WARNING;
8747 }
8748 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8749 bgp_show_type_flap_filter_list);
8750}
8751ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8752 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8753 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8754 SHOW_STR
8755 BGP_STR
8756 IPV6_STR
8757 "Address Family modifier\n"
8758 "Address Family modifier\n"
8759 "Address Family modifier\n"
8760 "Address Family modifier\n"
8761 "Display detailed information about dampening\n"
8762 "Display flap statistics of routes\n"
8763 "Display routes conforming to the filter-list\n"
8764 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008765
8766DEFUN (show_bgp_ipv4_safi_filter_list,
8767 show_bgp_ipv4_safi_filter_list_cmd,
8768 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8769 SHOW_STR
8770 BGP_STR
8771 "Address Family modifier\n"
8772 "Address Family modifier\n"
8773 "Address Family modifier\n"
8774 "Address Family modifier\n"
8775 "Display routes conforming to the filter-list\n"
8776 "Regular expression access list name\n")
8777{
8778 safi_t safi;
8779
8780 if (bgp_parse_safi(argv[0], &safi)) {
8781 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8782 return CMD_WARNING;
8783 }
8784 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8785 bgp_show_type_filter_list);
8786}
Lou Berger205e6742016-01-12 13:42:11 -05008787
Lou Berger651b4022016-01-12 13:42:07 -05008788DEFUN (show_bgp_ipv6_safi_filter_list,
8789 show_bgp_ipv6_safi_filter_list_cmd,
8790 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8791 SHOW_STR
8792 BGP_STR
8793 "Address Family modifier\n"
8794 "Address Family modifier\n"
8795 "Address Family modifier\n"
8796 "Address Family modifier\n"
8797 "Display routes conforming to the filter-list\n"
8798 "Regular expression access list name\n")
8799{
8800 safi_t safi;
8801
8802 if (bgp_parse_safi(argv[0], &safi)) {
8803 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8804 return CMD_WARNING;
8805 }
8806 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8807 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008808}
8809
Lou Bergerf9b6c392016-01-12 13:42:09 -05008810DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008811 show_bgp_ipv6_filter_list_cmd,
8812 "show bgp ipv6 filter-list WORD",
8813 SHOW_STR
8814 BGP_STR
8815 "Address family\n"
8816 "Display routes conforming to the filter-list\n"
8817 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008818{
8819 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8820 bgp_show_type_filter_list);
8821}
8822
Balaji9c52cae2016-01-20 22:59:26 +05308823
8824DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8825 show_ip_bgp_ipv4_dampening_parameters_cmd,
8826 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8827 SHOW_STR
8828 IP_STR
8829 BGP_STR
8830 "Address family\n"
8831 "Address Family modifier\n"
8832 "Address Family modifier\n"
8833 "Display detailed information about dampening\n"
8834 "Display detail of configured dampening parameters\n")
8835{
8836 if (strncmp(argv[0], "m", 1) == 0)
8837 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8838
8839 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8840}
8841
8842
8843DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8844 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8845 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8846 SHOW_STR
8847 IP_STR
8848 BGP_STR
8849 "Address family\n"
8850 "Address Family modifier\n"
8851 "Address Family modifier\n"
8852 "Display detailed information about dampening\n"
8853 "Display flap statistics of routes\n")
8854{
8855 if (strncmp(argv[0], "m", 1) == 0)
8856 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8857 bgp_show_type_flap_statistics, NULL);
8858
8859 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8860 bgp_show_type_flap_statistics, NULL);
8861}
8862
8863DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8864 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8865 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8866 SHOW_STR
8867 IP_STR
8868 BGP_STR
8869 "Address family\n"
8870 "Address Family modifier\n"
8871 "Address Family modifier\n"
8872 "Display detailed information about dampening\n"
8873 "Display paths suppressed due to dampening\n")
8874{
8875 if (strncmp(argv[0], "m", 1) == 0)
8876 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8877 bgp_show_type_dampend_paths, NULL);
8878
8879 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8880 bgp_show_type_dampend_paths, NULL);
8881}
8882
paul94f2b392005-06-28 12:44:16 +00008883static int
paulfd79ac92004-10-13 05:06:08 +00008884bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008885 safi_t safi, enum bgp_show_type type)
8886{
8887 struct route_map *rmap;
8888
8889 rmap = route_map_lookup_by_name (rmap_str);
8890 if (! rmap)
8891 {
8892 vty_out (vty, "%% %s is not a valid route-map name%s",
8893 rmap_str, VTY_NEWLINE);
8894 return CMD_WARNING;
8895 }
8896
ajs5a646652004-11-05 01:25:55 +00008897 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008898}
8899
Lou Bergerf9b6c392016-01-12 13:42:09 -05008900DEFUN (show_ip_bgp_route_map,
8901 show_ip_bgp_route_map_cmd,
8902 "show ip bgp route-map WORD",
8903 SHOW_STR
8904 IP_STR
8905 BGP_STR
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_route_map);
8911}
8912
8913DEFUN (show_ip_bgp_flap_route_map,
8914 show_ip_bgp_flap_route_map_cmd,
8915 "show ip bgp flap-statistics route-map WORD",
8916 SHOW_STR
8917 IP_STR
8918 BGP_STR
8919 "Display flap statistics of routes\n"
8920 "Display routes matching the route-map\n"
8921 "A route-map to match on\n")
8922{
8923 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8924 bgp_show_type_flap_route_map);
8925}
8926
8927ALIAS (show_ip_bgp_flap_route_map,
8928 show_ip_bgp_damp_flap_route_map_cmd,
8929 "show ip bgp dampening flap-statistics route-map WORD",
8930 SHOW_STR
8931 IP_STR
8932 BGP_STR
8933 "Display detailed information about dampening\n"
8934 "Display flap statistics of routes\n"
8935 "Display routes matching the route-map\n"
8936 "A route-map to match on\n")
8937
8938DEFUN (show_ip_bgp_ipv4_route_map,
8939 show_ip_bgp_ipv4_route_map_cmd,
8940 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8941 SHOW_STR
8942 IP_STR
8943 BGP_STR
8944 "Address family\n"
8945 "Address Family modifier\n"
8946 "Address Family modifier\n"
8947 "Display routes matching the route-map\n"
8948 "A route-map to match on\n")
8949{
8950 if (strncmp (argv[0], "m", 1) == 0)
8951 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8952 bgp_show_type_route_map);
8953
8954 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8955 bgp_show_type_route_map);
8956}
8957
8958DEFUN (show_bgp_route_map,
8959 show_bgp_route_map_cmd,
8960 "show bgp route-map WORD",
8961 SHOW_STR
8962 BGP_STR
8963 "Display routes matching the route-map\n"
8964 "A route-map to match on\n")
8965{
8966 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8967 bgp_show_type_route_map);
8968}
8969
8970DEFUN (show_ip_bgp_cidr_only,
8971 show_ip_bgp_cidr_only_cmd,
8972 "show ip bgp cidr-only",
8973 SHOW_STR
8974 IP_STR
8975 BGP_STR
8976 "Display only routes with non-natural netmasks\n")
8977{
8978 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8979 bgp_show_type_cidr_only, NULL);
8980}
8981
8982DEFUN (show_ip_bgp_flap_cidr_only,
8983 show_ip_bgp_flap_cidr_only_cmd,
8984 "show ip bgp flap-statistics cidr-only",
8985 SHOW_STR
8986 IP_STR
8987 BGP_STR
8988 "Display flap statistics of routes\n"
8989 "Display only routes with non-natural netmasks\n")
8990{
8991 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8992 bgp_show_type_flap_cidr_only, NULL);
8993}
8994
8995ALIAS (show_ip_bgp_flap_cidr_only,
8996 show_ip_bgp_damp_flap_cidr_only_cmd,
8997 "show ip bgp dampening flap-statistics cidr-only",
8998 SHOW_STR
8999 IP_STR
9000 BGP_STR
9001 "Display detailed information about dampening\n"
9002 "Display flap statistics of routes\n"
9003 "Display only routes with non-natural netmasks\n")
9004
9005DEFUN (show_ip_bgp_ipv4_cidr_only,
9006 show_ip_bgp_ipv4_cidr_only_cmd,
9007 "show ip bgp ipv4 (unicast|multicast) cidr-only",
9008 SHOW_STR
9009 IP_STR
9010 BGP_STR
9011 "Address family\n"
9012 "Address Family modifier\n"
9013 "Address Family modifier\n"
9014 "Display only routes with non-natural netmasks\n")
9015{
9016 if (strncmp (argv[0], "m", 1) == 0)
9017 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9018 bgp_show_type_cidr_only, NULL);
9019
9020 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9021 bgp_show_type_cidr_only, NULL);
9022}
9023
9024DEFUN (show_ip_bgp_community_all,
9025 show_ip_bgp_community_all_cmd,
9026 "show ip bgp community",
9027 SHOW_STR
9028 IP_STR
9029 BGP_STR
9030 "Display routes matching the communities\n")
9031{
9032 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9033 bgp_show_type_community_all, NULL);
9034}
9035
9036DEFUN (show_ip_bgp_ipv4_community_all,
9037 show_ip_bgp_ipv4_community_all_cmd,
9038 "show ip bgp ipv4 (unicast|multicast) community",
9039 SHOW_STR
9040 IP_STR
9041 BGP_STR
9042 "Address family\n"
9043 "Address Family modifier\n"
9044 "Address Family modifier\n"
9045 "Display routes matching the communities\n")
9046{
9047 if (strncmp (argv[0], "m", 1) == 0)
9048 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9049 bgp_show_type_community_all, NULL);
9050
9051 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9052 bgp_show_type_community_all, NULL);
9053}
9054
Lou Bergerf9b6c392016-01-12 13:42:09 -05009055DEFUN (show_bgp_community_all,
9056 show_bgp_community_all_cmd,
9057 "show bgp community",
9058 SHOW_STR
9059 BGP_STR
9060 "Display routes matching the communities\n")
9061{
9062 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9063 bgp_show_type_community_all, NULL);
9064}
9065
9066ALIAS (show_bgp_community_all,
9067 show_bgp_ipv6_community_all_cmd,
9068 "show bgp ipv6 community",
9069 SHOW_STR
9070 BGP_STR
9071 "Address family\n"
9072 "Display routes matching the communities\n")
9073
9074/* old command */
9075DEFUN (show_ipv6_bgp_community_all,
9076 show_ipv6_bgp_community_all_cmd,
9077 "show ipv6 bgp community",
9078 SHOW_STR
9079 IPV6_STR
9080 BGP_STR
9081 "Display routes matching the communities\n")
9082{
9083 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9084 bgp_show_type_community_all, NULL);
9085}
9086
9087/* old command */
9088DEFUN (show_ipv6_mbgp_community_all,
9089 show_ipv6_mbgp_community_all_cmd,
9090 "show ipv6 mbgp community",
9091 SHOW_STR
9092 IPV6_STR
9093 MBGP_STR
9094 "Display routes matching the communities\n")
9095{
9096 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9097 bgp_show_type_community_all, NULL);
9098}
Lou Bergerf9b6c392016-01-12 13:42:09 -05009099
Lou Berger651b4022016-01-12 13:42:07 -05009100DEFUN (show_bgp_ipv4_route_map,
9101 show_bgp_ipv4_route_map_cmd,
9102 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00009103 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009104 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009105 IP_STR
paul718e3742002-12-13 20:15:29 +00009106 "Display routes matching the route-map\n"
9107 "A route-map to match on\n")
9108{
9109 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9110 bgp_show_type_route_map);
9111}
9112
Lou Berger651b4022016-01-12 13:42:07 -05009113DEFUN (show_bgp_ipv4_safi_flap_route_map,
9114 show_bgp_ipv4_safi_flap_route_map_cmd,
9115 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009116 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009117 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009118 IP_STR
9119 "Address Family Modifier\n"
9120 "Address Family Modifier\n"
9121 "Address Family Modifier\n"
9122 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009123 "Display flap statistics of routes\n"
9124 "Display routes matching the route-map\n"
9125 "A route-map to match on\n")
9126{
Lou Berger651b4022016-01-12 13:42:07 -05009127 safi_t safi;
9128 if (bgp_parse_safi(argv[0], &safi)) {
9129 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9130 return CMD_WARNING;
9131 }
9132 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009133 bgp_show_type_flap_route_map);
9134}
9135
Lou Berger651b4022016-01-12 13:42:07 -05009136ALIAS (show_bgp_ipv4_safi_flap_route_map,
9137 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9138 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05309139 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309140 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009141 IP_STR
9142 "Address Family Modifier\n"
9143 "Address Family Modifier\n"
9144 "Address Family Modifier\n"
9145 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309146 "Display detailed information about dampening\n"
9147 "Display flap statistics of routes\n"
9148 "Display routes matching the route-map\n"
9149 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05009150
Lou Berger651b4022016-01-12 13:42:07 -05009151DEFUN (show_bgp_ipv6_safi_flap_route_map,
9152 show_bgp_ipv6_safi_flap_route_map_cmd,
9153 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009154 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05009155 BGP_STR
9156 IPV6_STR
9157 "Address Family Modifier\n"
9158 "Address Family Modifier\n"
9159 "Address Family Modifier\n"
9160 "Address Family Modifier\n"
9161 "Display flap statistics of routes\n"
9162 "Display routes matching the route-map\n"
9163 "A route-map to match on\n")
9164{
9165 safi_t safi;
9166 if (bgp_parse_safi(argv[0], &safi)) {
9167 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9168 return CMD_WARNING;
9169 }
9170 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9171 bgp_show_type_flap_route_map);
9172}
9173ALIAS (show_bgp_ipv6_safi_flap_route_map,
9174 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9175 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9176 SHOW_STR
9177 BGP_STR
9178 IPV6_STR
9179 "Address Family Modifier\n"
9180 "Address Family Modifier\n"
9181 "Address Family Modifier\n"
9182 "Address Family Modifier\n"
9183 "Display detailed information about dampening\n"
9184 "Display flap statistics of routes\n"
9185 "Display routes matching the route-map\n"
9186 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009187
9188DEFUN (show_bgp_ipv4_safi_route_map,
9189 show_bgp_ipv4_safi_route_map_cmd,
9190 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9191 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009192 BGP_STR
9193 "Address family\n"
9194 "Address Family modifier\n"
9195 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009196 "Address Family modifier\n"
9197 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009198 "Display routes matching the route-map\n"
9199 "A route-map to match on\n")
9200{
Lou Berger651b4022016-01-12 13:42:07 -05009201 safi_t safi;
9202 if (bgp_parse_safi(argv[0], &safi)) {
9203 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9204 return CMD_WARNING;
9205 }
9206 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009207 bgp_show_type_route_map);
9208}
Lou Berger205e6742016-01-12 13:42:11 -05009209
Lou Berger651b4022016-01-12 13:42:07 -05009210DEFUN (show_bgp_ipv6_safi_route_map,
9211 show_bgp_ipv6_safi_route_map_cmd,
9212 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009213 SHOW_STR
9214 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009215 "Address family\n"
9216 "Address Family modifier\n"
9217 "Address Family modifier\n"
9218 "Address Family modifier\n"
9219 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009220 "Display routes matching the route-map\n"
9221 "A route-map to match on\n")
9222{
Lou Berger651b4022016-01-12 13:42:07 -05009223 safi_t safi;
9224 if (bgp_parse_safi(argv[0], &safi)) {
9225 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9226 return CMD_WARNING;
9227 }
9228 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009229 bgp_show_type_route_map);
9230}
9231
Lou Berger651b4022016-01-12 13:42:07 -05009232DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009233 show_bgp_ipv6_route_map_cmd,
9234 "show bgp ipv6 route-map WORD",
9235 SHOW_STR
9236 BGP_STR
9237 "Address family\n"
9238 "Display routes matching the route-map\n"
9239 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009240{
9241 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9242 bgp_show_type_route_map);
9243}
David Lamparter6b0655a2014-06-04 06:53:35 +02009244
Lou Berger651b4022016-01-12 13:42:07 -05009245DEFUN (show_bgp_ipv4_cidr_only,
9246 show_bgp_ipv4_cidr_only_cmd,
9247 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009248 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009249 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009250 IP_STR
paul718e3742002-12-13 20:15:29 +00009251 "Display only routes with non-natural netmasks\n")
9252{
9253 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009254 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009255}
9256
Lou Berger651b4022016-01-12 13:42:07 -05009257DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9258 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9259 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009260 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009261 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009262 "Address Family\n"
9263 "Address Family Modifier\n"
9264 "Address Family Modifier\n"
9265 "Address Family Modifier\n"
9266 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009267 "Display flap statistics of routes\n"
9268 "Display only routes with non-natural netmasks\n")
9269{
Lou Berger651b4022016-01-12 13:42:07 -05009270 safi_t safi;
9271
9272 if (bgp_parse_safi(argv[0], &safi)) {
9273 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9274 return CMD_WARNING;
9275 }
9276 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009277}
9278
Lou Berger651b4022016-01-12 13:42:07 -05009279ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9280 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9281 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309282 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309283 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009284 "Address Family\n"
9285 "Address Family Modifier\n"
9286 "Address Family Modifier\n"
9287 "Address Family Modifier\n"
9288 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309289 "Display detailed information about dampening\n"
9290 "Display flap statistics of routes\n"
9291 "Display only routes with non-natural netmasks\n")
9292
Lou Berger651b4022016-01-12 13:42:07 -05009293DEFUN (show_bgp_ipv4_safi_cidr_only,
9294 show_bgp_ipv4_safi_cidr_only_cmd,
9295 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009296 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009297 BGP_STR
9298 "Address family\n"
9299 "Address Family modifier\n"
9300 "Address Family modifier\n"
9301 "Display only routes with non-natural netmasks\n")
9302{
9303 if (strncmp (argv[0], "m", 1) == 0)
9304 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009305 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009306
9307 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009308 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009309}
David Lamparter6b0655a2014-06-04 06:53:35 +02009310
Lou Berger651b4022016-01-12 13:42:07 -05009311/* new046 */
9312DEFUN (show_bgp_afi_safi_community_all,
9313 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009314 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009315 SHOW_STR
9316 BGP_STR
9317 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009318 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009319 "Address Family modifier\n"
9320 "Address Family modifier\n"
9321 "Address Family modifier\n"
9322 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009323 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009324{
9325 safi_t safi;
9326 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009327
Lou Berger651b4022016-01-12 13:42:07 -05009328 if (bgp_parse_afi(argv[0], &afi)) {
9329 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9330 return CMD_WARNING;
9331 }
9332 if (bgp_parse_safi(argv[1], &safi)) {
9333 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9334 return CMD_WARNING;
9335 }
9336
9337 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9338}
9339DEFUN (show_bgp_afi_community_all,
9340 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009341 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009342 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009343 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009344 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009345 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009346 "Display routes matching the communities\n")
9347{
Lou Berger651b4022016-01-12 13:42:07 -05009348 afi_t afi;
9349 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009350
Lou Berger651b4022016-01-12 13:42:07 -05009351 if (bgp_parse_afi(argv[0], &afi)) {
9352 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9353 return CMD_WARNING;
9354 }
9355 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009356}
David Lamparter6b0655a2014-06-04 06:53:35 +02009357
paul94f2b392005-06-28 12:44:16 +00009358static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009359bgp_show_community (struct vty *vty, const char *view_name, int argc,
9360 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009361{
9362 struct community *com;
9363 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009364 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009365 int i;
9366 char *str;
9367 int first = 0;
9368
Michael Lambert95cbbd22010-07-23 14:43:04 -04009369 /* BGP structure lookup */
9370 if (view_name)
9371 {
9372 bgp = bgp_lookup_by_name (view_name);
9373 if (bgp == NULL)
9374 {
9375 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9376 return CMD_WARNING;
9377 }
9378 }
9379 else
9380 {
9381 bgp = bgp_get_default ();
9382 if (bgp == NULL)
9383 {
9384 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9385 return CMD_WARNING;
9386 }
9387 }
9388
paul718e3742002-12-13 20:15:29 +00009389 b = buffer_new (1024);
9390 for (i = 0; i < argc; i++)
9391 {
9392 if (first)
9393 buffer_putc (b, ' ');
9394 else
9395 {
9396 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9397 continue;
9398 first = 1;
9399 }
9400
9401 buffer_putstr (b, argv[i]);
9402 }
9403 buffer_putc (b, '\0');
9404
9405 str = buffer_getstr (b);
9406 buffer_free (b);
9407
9408 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009409 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009410 if (! com)
9411 {
9412 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9413 return CMD_WARNING;
9414 }
9415
Michael Lambert95cbbd22010-07-23 14:43:04 -04009416 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009417 (exact ? bgp_show_type_community_exact :
9418 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009419}
9420
Lou Bergerf9b6c392016-01-12 13:42:09 -05009421DEFUN (show_ip_bgp_community,
9422 show_ip_bgp_community_cmd,
9423 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9424 SHOW_STR
9425 IP_STR
9426 BGP_STR
9427 "Display routes matching the communities\n"
9428 "community number\n"
9429 "Do not send outside local AS (well-known community)\n"
9430 "Do not advertise to any peer (well-known community)\n"
9431 "Do not export to next AS (well-known community)\n")
9432{
9433 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9434}
9435
9436ALIAS (show_ip_bgp_community,
9437 show_ip_bgp_community2_cmd,
9438 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9439 SHOW_STR
9440 IP_STR
9441 BGP_STR
9442 "Display routes matching the communities\n"
9443 "community number\n"
9444 "Do not send outside local AS (well-known community)\n"
9445 "Do not advertise to any peer (well-known community)\n"
9446 "Do not export to next AS (well-known community)\n"
9447 "community number\n"
9448 "Do not send outside local AS (well-known community)\n"
9449 "Do not advertise to any peer (well-known community)\n"
9450 "Do not export to next AS (well-known community)\n")
9451
9452ALIAS (show_ip_bgp_community,
9453 show_ip_bgp_community3_cmd,
9454 "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)",
9455 SHOW_STR
9456 IP_STR
9457 BGP_STR
9458 "Display routes matching the communities\n"
9459 "community number\n"
9460 "Do not send outside local AS (well-known community)\n"
9461 "Do not advertise to any peer (well-known community)\n"
9462 "Do not export to next AS (well-known community)\n"
9463 "community number\n"
9464 "Do not send outside local AS (well-known community)\n"
9465 "Do not advertise to any peer (well-known community)\n"
9466 "Do not export to next AS (well-known community)\n"
9467 "community number\n"
9468 "Do not send outside local AS (well-known community)\n"
9469 "Do not advertise to any peer (well-known community)\n"
9470 "Do not export to next AS (well-known community)\n")
9471
9472ALIAS (show_ip_bgp_community,
9473 show_ip_bgp_community4_cmd,
9474 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9475 SHOW_STR
9476 IP_STR
9477 BGP_STR
9478 "Display routes matching the communities\n"
9479 "community number\n"
9480 "Do not send outside local AS (well-known community)\n"
9481 "Do not advertise to any peer (well-known community)\n"
9482 "Do not export to next AS (well-known community)\n"
9483 "community number\n"
9484 "Do not send outside local AS (well-known community)\n"
9485 "Do not advertise to any peer (well-known community)\n"
9486 "Do not export to next AS (well-known community)\n"
9487 "community number\n"
9488 "Do not send outside local AS (well-known community)\n"
9489 "Do not advertise to any peer (well-known community)\n"
9490 "Do not export to next AS (well-known community)\n"
9491 "community number\n"
9492 "Do not send outside local AS (well-known community)\n"
9493 "Do not advertise to any peer (well-known community)\n"
9494 "Do not export to next AS (well-known community)\n")
9495
9496DEFUN (show_ip_bgp_ipv4_community,
9497 show_ip_bgp_ipv4_community_cmd,
9498 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9499 SHOW_STR
9500 IP_STR
9501 BGP_STR
9502 "Address family\n"
9503 "Address Family modifier\n"
9504 "Address Family modifier\n"
9505 "Display routes matching the communities\n"
9506 "community number\n"
9507 "Do not send outside local AS (well-known community)\n"
9508 "Do not advertise to any peer (well-known community)\n"
9509 "Do not export to next AS (well-known community)\n")
9510{
9511 if (strncmp (argv[0], "m", 1) == 0)
9512 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9513
9514 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9515}
9516
9517ALIAS (show_ip_bgp_ipv4_community,
9518 show_ip_bgp_ipv4_community2_cmd,
9519 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9520 SHOW_STR
9521 IP_STR
9522 BGP_STR
9523 "Address family\n"
9524 "Address Family modifier\n"
9525 "Address Family modifier\n"
9526 "Display routes matching the communities\n"
9527 "community number\n"
9528 "Do not send outside local AS (well-known community)\n"
9529 "Do not advertise to any peer (well-known community)\n"
9530 "Do not export to next AS (well-known community)\n"
9531 "community number\n"
9532 "Do not send outside local AS (well-known community)\n"
9533 "Do not advertise to any peer (well-known community)\n"
9534 "Do not export to next AS (well-known community)\n")
9535
9536ALIAS (show_ip_bgp_ipv4_community,
9537 show_ip_bgp_ipv4_community3_cmd,
9538 "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)",
9539 SHOW_STR
9540 IP_STR
9541 BGP_STR
9542 "Address family\n"
9543 "Address Family modifier\n"
9544 "Address Family modifier\n"
9545 "Display routes matching the communities\n"
9546 "community number\n"
9547 "Do not send outside local AS (well-known community)\n"
9548 "Do not advertise to any peer (well-known community)\n"
9549 "Do not export to next AS (well-known community)\n"
9550 "community number\n"
9551 "Do not send outside local AS (well-known community)\n"
9552 "Do not advertise to any peer (well-known community)\n"
9553 "Do not export to next AS (well-known community)\n"
9554 "community number\n"
9555 "Do not send outside local AS (well-known community)\n"
9556 "Do not advertise to any peer (well-known community)\n"
9557 "Do not export to next AS (well-known community)\n")
9558
9559ALIAS (show_ip_bgp_ipv4_community,
9560 show_ip_bgp_ipv4_community4_cmd,
9561 "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)",
9562 SHOW_STR
9563 IP_STR
9564 BGP_STR
9565 "Address family\n"
9566 "Address Family modifier\n"
9567 "Address Family modifier\n"
9568 "Display routes matching the communities\n"
9569 "community number\n"
9570 "Do not send outside local AS (well-known community)\n"
9571 "Do not advertise to any peer (well-known community)\n"
9572 "Do not export to next AS (well-known community)\n"
9573 "community number\n"
9574 "Do not send outside local AS (well-known community)\n"
9575 "Do not advertise to any peer (well-known community)\n"
9576 "Do not export to next AS (well-known community)\n"
9577 "community number\n"
9578 "Do not send outside local AS (well-known community)\n"
9579 "Do not advertise to any peer (well-known community)\n"
9580 "Do not export to next AS (well-known community)\n"
9581 "community number\n"
9582 "Do not send outside local AS (well-known community)\n"
9583 "Do not advertise to any peer (well-known community)\n"
9584 "Do not export to next AS (well-known community)\n")
9585
9586DEFUN (show_ip_bgp_community_exact,
9587 show_ip_bgp_community_exact_cmd,
9588 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9589 SHOW_STR
9590 IP_STR
9591 BGP_STR
9592 "Display routes matching the communities\n"
9593 "community number\n"
9594 "Do not send outside local AS (well-known community)\n"
9595 "Do not advertise to any peer (well-known community)\n"
9596 "Do not export to next AS (well-known community)\n"
9597 "Exact match of the communities")
9598{
9599 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9600}
9601
9602ALIAS (show_ip_bgp_community_exact,
9603 show_ip_bgp_community2_exact_cmd,
9604 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9605 SHOW_STR
9606 IP_STR
9607 BGP_STR
9608 "Display routes matching the communities\n"
9609 "community number\n"
9610 "Do not send outside local AS (well-known community)\n"
9611 "Do not advertise to any peer (well-known community)\n"
9612 "Do not export to next AS (well-known community)\n"
9613 "community number\n"
9614 "Do not send outside local AS (well-known community)\n"
9615 "Do not advertise to any peer (well-known community)\n"
9616 "Do not export to next AS (well-known community)\n"
9617 "Exact match of the communities")
9618
9619ALIAS (show_ip_bgp_community_exact,
9620 show_ip_bgp_community3_exact_cmd,
9621 "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",
9622 SHOW_STR
9623 IP_STR
9624 BGP_STR
9625 "Display routes matching the communities\n"
9626 "community number\n"
9627 "Do not send outside local AS (well-known community)\n"
9628 "Do not advertise to any peer (well-known community)\n"
9629 "Do not export to next AS (well-known community)\n"
9630 "community number\n"
9631 "Do not send outside local AS (well-known community)\n"
9632 "Do not advertise to any peer (well-known community)\n"
9633 "Do not export to next AS (well-known community)\n"
9634 "community number\n"
9635 "Do not send outside local AS (well-known community)\n"
9636 "Do not advertise to any peer (well-known community)\n"
9637 "Do not export to next AS (well-known community)\n"
9638 "Exact match of the communities")
9639
9640ALIAS (show_ip_bgp_community_exact,
9641 show_ip_bgp_community4_exact_cmd,
9642 "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",
9643 SHOW_STR
9644 IP_STR
9645 BGP_STR
9646 "Display routes matching the communities\n"
9647 "community number\n"
9648 "Do not send outside local AS (well-known community)\n"
9649 "Do not advertise to any peer (well-known community)\n"
9650 "Do not export to next AS (well-known community)\n"
9651 "community number\n"
9652 "Do not send outside local AS (well-known community)\n"
9653 "Do not advertise to any peer (well-known community)\n"
9654 "Do not export to next AS (well-known community)\n"
9655 "community number\n"
9656 "Do not send outside local AS (well-known community)\n"
9657 "Do not advertise to any peer (well-known community)\n"
9658 "Do not export to next AS (well-known community)\n"
9659 "community number\n"
9660 "Do not send outside local AS (well-known community)\n"
9661 "Do not advertise to any peer (well-known community)\n"
9662 "Do not export to next AS (well-known community)\n"
9663 "Exact match of the communities")
9664
9665DEFUN (show_ip_bgp_ipv4_community_exact,
9666 show_ip_bgp_ipv4_community_exact_cmd,
9667 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9668 SHOW_STR
9669 IP_STR
9670 BGP_STR
9671 "Address family\n"
9672 "Address Family modifier\n"
9673 "Address Family modifier\n"
9674 "Display routes matching the communities\n"
9675 "community number\n"
9676 "Do not send outside local AS (well-known community)\n"
9677 "Do not advertise to any peer (well-known community)\n"
9678 "Do not export to next AS (well-known community)\n"
9679 "Exact match of the communities")
9680{
9681 if (strncmp (argv[0], "m", 1) == 0)
9682 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9683
9684 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9685}
9686
9687ALIAS (show_ip_bgp_ipv4_community_exact,
9688 show_ip_bgp_ipv4_community2_exact_cmd,
9689 "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",
9690 SHOW_STR
9691 IP_STR
9692 BGP_STR
9693 "Address family\n"
9694 "Address Family modifier\n"
9695 "Address Family modifier\n"
9696 "Display routes matching the communities\n"
9697 "community number\n"
9698 "Do not send outside local AS (well-known community)\n"
9699 "Do not advertise to any peer (well-known community)\n"
9700 "Do not export to next AS (well-known community)\n"
9701 "community number\n"
9702 "Do not send outside local AS (well-known community)\n"
9703 "Do not advertise to any peer (well-known community)\n"
9704 "Do not export to next AS (well-known community)\n"
9705 "Exact match of the communities")
9706
9707ALIAS (show_ip_bgp_ipv4_community_exact,
9708 show_ip_bgp_ipv4_community3_exact_cmd,
9709 "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",
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "Address family\n"
9714 "Address Family modifier\n"
9715 "Address Family modifier\n"
9716 "Display routes matching the communities\n"
9717 "community number\n"
9718 "Do not send outside local AS (well-known community)\n"
9719 "Do not advertise to any peer (well-known community)\n"
9720 "Do not export to next AS (well-known community)\n"
9721 "community number\n"
9722 "Do not send outside local AS (well-known community)\n"
9723 "Do not advertise to any peer (well-known community)\n"
9724 "Do not export to next AS (well-known community)\n"
9725 "community number\n"
9726 "Do not send outside local AS (well-known community)\n"
9727 "Do not advertise to any peer (well-known community)\n"
9728 "Do not export to next AS (well-known community)\n"
9729 "Exact match of the communities")
9730
9731ALIAS (show_ip_bgp_ipv4_community_exact,
9732 show_ip_bgp_ipv4_community4_exact_cmd,
9733 "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",
9734 SHOW_STR
9735 IP_STR
9736 BGP_STR
9737 "Address family\n"
9738 "Address Family modifier\n"
9739 "Address Family modifier\n"
9740 "Display routes matching the communities\n"
9741 "community number\n"
9742 "Do not send outside local AS (well-known community)\n"
9743 "Do not advertise to any peer (well-known community)\n"
9744 "Do not export to next AS (well-known community)\n"
9745 "community number\n"
9746 "Do not send outside local AS (well-known community)\n"
9747 "Do not advertise to any peer (well-known community)\n"
9748 "Do not export to next AS (well-known community)\n"
9749 "community number\n"
9750 "Do not send outside local AS (well-known community)\n"
9751 "Do not advertise to any peer (well-known community)\n"
9752 "Do not export to next AS (well-known community)\n"
9753 "community number\n"
9754 "Do not send outside local AS (well-known community)\n"
9755 "Do not advertise to any peer (well-known community)\n"
9756 "Do not export to next AS (well-known community)\n"
9757 "Exact match of the communities")
9758
Lou Bergerf9b6c392016-01-12 13:42:09 -05009759DEFUN (show_bgp_community,
9760 show_bgp_community_cmd,
9761 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9762 SHOW_STR
9763 BGP_STR
9764 "Display routes matching the communities\n"
9765 "community number\n"
9766 "Do not send outside local AS (well-known community)\n"
9767 "Do not advertise to any peer (well-known community)\n"
9768 "Do not export to next AS (well-known community)\n")
9769{
9770 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9771}
9772
9773ALIAS (show_bgp_community,
9774 show_bgp_ipv6_community_cmd,
9775 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9776 SHOW_STR
9777 BGP_STR
9778 "Address family\n"
9779 "Display routes matching the communities\n"
9780 "community number\n"
9781 "Do not send outside local AS (well-known community)\n"
9782 "Do not advertise to any peer (well-known community)\n"
9783 "Do not export to next AS (well-known community)\n")
9784
9785ALIAS (show_bgp_community,
9786 show_bgp_community2_cmd,
9787 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9788 SHOW_STR
9789 BGP_STR
9790 "Display routes matching the communities\n"
9791 "community number\n"
9792 "Do not send outside local AS (well-known community)\n"
9793 "Do not advertise to any peer (well-known community)\n"
9794 "Do not export to next AS (well-known community)\n"
9795 "community number\n"
9796 "Do not send outside local AS (well-known community)\n"
9797 "Do not advertise to any peer (well-known community)\n"
9798 "Do not export to next AS (well-known community)\n")
9799
9800ALIAS (show_bgp_community,
9801 show_bgp_ipv6_community2_cmd,
9802 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9803 SHOW_STR
9804 BGP_STR
9805 "Address family\n"
9806 "Display routes matching the communities\n"
9807 "community number\n"
9808 "Do not send outside local AS (well-known community)\n"
9809 "Do not advertise to any peer (well-known community)\n"
9810 "Do not export to next AS (well-known community)\n"
9811 "community number\n"
9812 "Do not send outside local AS (well-known community)\n"
9813 "Do not advertise to any peer (well-known community)\n"
9814 "Do not export to next AS (well-known community)\n")
9815
9816ALIAS (show_bgp_community,
9817 show_bgp_community3_cmd,
9818 "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)",
9819 SHOW_STR
9820 BGP_STR
9821 "Display routes matching the communities\n"
9822 "community number\n"
9823 "Do not send outside local AS (well-known community)\n"
9824 "Do not advertise to any peer (well-known community)\n"
9825 "Do not export to next AS (well-known community)\n"
9826 "community number\n"
9827 "Do not send outside local AS (well-known community)\n"
9828 "Do not advertise to any peer (well-known community)\n"
9829 "Do not export to next AS (well-known community)\n"
9830 "community number\n"
9831 "Do not send outside local AS (well-known community)\n"
9832 "Do not advertise to any peer (well-known community)\n"
9833 "Do not export to next AS (well-known community)\n")
9834
9835ALIAS (show_bgp_community,
9836 show_bgp_ipv6_community3_cmd,
9837 "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)",
9838 SHOW_STR
9839 BGP_STR
9840 "Address family\n"
9841 "Display routes matching the communities\n"
9842 "community number\n"
9843 "Do not send outside local AS (well-known community)\n"
9844 "Do not advertise to any peer (well-known community)\n"
9845 "Do not export to next AS (well-known community)\n"
9846 "community number\n"
9847 "Do not send outside local AS (well-known community)\n"
9848 "Do not advertise to any peer (well-known community)\n"
9849 "Do not export to next AS (well-known community)\n"
9850 "community number\n"
9851 "Do not send outside local AS (well-known community)\n"
9852 "Do not advertise to any peer (well-known community)\n"
9853 "Do not export to next AS (well-known community)\n")
9854
9855ALIAS (show_bgp_community,
9856 show_bgp_community4_cmd,
9857 "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)",
9858 SHOW_STR
9859 BGP_STR
9860 "Display routes matching the communities\n"
9861 "community number\n"
9862 "Do not send outside local AS (well-known community)\n"
9863 "Do not advertise to any peer (well-known community)\n"
9864 "Do not export to next AS (well-known community)\n"
9865 "community number\n"
9866 "Do not send outside local AS (well-known community)\n"
9867 "Do not advertise to any peer (well-known community)\n"
9868 "Do not export to next AS (well-known community)\n"
9869 "community number\n"
9870 "Do not send outside local AS (well-known community)\n"
9871 "Do not advertise to any peer (well-known community)\n"
9872 "Do not export to next AS (well-known community)\n"
9873 "community number\n"
9874 "Do not send outside local AS (well-known community)\n"
9875 "Do not advertise to any peer (well-known community)\n"
9876 "Do not export to next AS (well-known community)\n")
9877
9878ALIAS (show_bgp_community,
9879 show_bgp_ipv6_community4_cmd,
9880 "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)",
9881 SHOW_STR
9882 BGP_STR
9883 "Address family\n"
9884 "Display routes matching the communities\n"
9885 "community number\n"
9886 "Do not send outside local AS (well-known community)\n"
9887 "Do not advertise to any peer (well-known community)\n"
9888 "Do not export to next AS (well-known community)\n"
9889 "community number\n"
9890 "Do not send outside local AS (well-known community)\n"
9891 "Do not advertise to any peer (well-known community)\n"
9892 "Do not export to next AS (well-known community)\n"
9893 "community number\n"
9894 "Do not send outside local AS (well-known community)\n"
9895 "Do not advertise to any peer (well-known community)\n"
9896 "Do not export to next AS (well-known community)\n"
9897 "community number\n"
9898 "Do not send outside local AS (well-known community)\n"
9899 "Do not advertise to any peer (well-known community)\n"
9900 "Do not export to next AS (well-known community)\n")
9901
9902/* old command */
9903DEFUN (show_ipv6_bgp_community,
9904 show_ipv6_bgp_community_cmd,
9905 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9906 SHOW_STR
9907 IPV6_STR
9908 BGP_STR
9909 "Display routes matching the communities\n"
9910 "community number\n"
9911 "Do not send outside local AS (well-known community)\n"
9912 "Do not advertise to any peer (well-known community)\n"
9913 "Do not export to next AS (well-known community)\n")
9914{
9915 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9916}
9917
9918/* old command */
9919ALIAS (show_ipv6_bgp_community,
9920 show_ipv6_bgp_community2_cmd,
9921 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9922 SHOW_STR
9923 IPV6_STR
9924 BGP_STR
9925 "Display routes matching the communities\n"
9926 "community number\n"
9927 "Do not send outside local AS (well-known community)\n"
9928 "Do not advertise to any peer (well-known community)\n"
9929 "Do not export to next AS (well-known community)\n"
9930 "community number\n"
9931 "Do not send outside local AS (well-known community)\n"
9932 "Do not advertise to any peer (well-known community)\n"
9933 "Do not export to next AS (well-known community)\n")
9934
9935/* old command */
9936ALIAS (show_ipv6_bgp_community,
9937 show_ipv6_bgp_community3_cmd,
9938 "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)",
9939 SHOW_STR
9940 IPV6_STR
9941 BGP_STR
9942 "Display routes matching the communities\n"
9943 "community number\n"
9944 "Do not send outside local AS (well-known community)\n"
9945 "Do not advertise to any peer (well-known community)\n"
9946 "Do not export to next AS (well-known community)\n"
9947 "community number\n"
9948 "Do not send outside local AS (well-known community)\n"
9949 "Do not advertise to any peer (well-known community)\n"
9950 "Do not export to next AS (well-known community)\n"
9951 "community number\n"
9952 "Do not send outside local AS (well-known community)\n"
9953 "Do not advertise to any peer (well-known community)\n"
9954 "Do not export to next AS (well-known community)\n")
9955
9956/* old command */
9957ALIAS (show_ipv6_bgp_community,
9958 show_ipv6_bgp_community4_cmd,
9959 "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)",
9960 SHOW_STR
9961 IPV6_STR
9962 BGP_STR
9963 "Display routes matching the communities\n"
9964 "community number\n"
9965 "Do not send outside local AS (well-known community)\n"
9966 "Do not advertise to any peer (well-known community)\n"
9967 "Do not export to next AS (well-known community)\n"
9968 "community number\n"
9969 "Do not send outside local AS (well-known community)\n"
9970 "Do not advertise to any peer (well-known community)\n"
9971 "Do not export to next AS (well-known community)\n"
9972 "community number\n"
9973 "Do not send outside local AS (well-known community)\n"
9974 "Do not advertise to any peer (well-known community)\n"
9975 "Do not export to next AS (well-known community)\n"
9976 "community number\n"
9977 "Do not send outside local AS (well-known community)\n"
9978 "Do not advertise to any peer (well-known community)\n"
9979 "Do not export to next AS (well-known community)\n")
9980
9981DEFUN (show_bgp_community_exact,
9982 show_bgp_community_exact_cmd,
9983 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9984 SHOW_STR
9985 BGP_STR
9986 "Display routes matching the communities\n"
9987 "community number\n"
9988 "Do not send outside local AS (well-known community)\n"
9989 "Do not advertise to any peer (well-known community)\n"
9990 "Do not export to next AS (well-known community)\n"
9991 "Exact match of the communities")
9992{
9993 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9994}
9995
9996ALIAS (show_bgp_community_exact,
9997 show_bgp_ipv6_community_exact_cmd,
9998 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9999 SHOW_STR
10000 BGP_STR
10001 "Address family\n"
10002 "Display routes matching the communities\n"
10003 "community number\n"
10004 "Do not send outside local AS (well-known community)\n"
10005 "Do not advertise to any peer (well-known community)\n"
10006 "Do not export to next AS (well-known community)\n"
10007 "Exact match of the communities")
10008
10009ALIAS (show_bgp_community_exact,
10010 show_bgp_community2_exact_cmd,
10011 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10012 SHOW_STR
10013 BGP_STR
10014 "Display routes matching the communities\n"
10015 "community number\n"
10016 "Do not send outside local AS (well-known community)\n"
10017 "Do not advertise to any peer (well-known community)\n"
10018 "Do not export to next AS (well-known community)\n"
10019 "community number\n"
10020 "Do not send outside local AS (well-known community)\n"
10021 "Do not advertise to any peer (well-known community)\n"
10022 "Do not export to next AS (well-known community)\n"
10023 "Exact match of the communities")
10024
10025ALIAS (show_bgp_community_exact,
10026 show_bgp_ipv6_community2_exact_cmd,
10027 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10028 SHOW_STR
10029 BGP_STR
10030 "Address family\n"
10031 "Display routes matching the communities\n"
10032 "community number\n"
10033 "Do not send outside local AS (well-known community)\n"
10034 "Do not advertise to any peer (well-known community)\n"
10035 "Do not export to next AS (well-known community)\n"
10036 "community number\n"
10037 "Do not send outside local AS (well-known community)\n"
10038 "Do not advertise to any peer (well-known community)\n"
10039 "Do not export to next AS (well-known community)\n"
10040 "Exact match of the communities")
10041
10042ALIAS (show_bgp_community_exact,
10043 show_bgp_community3_exact_cmd,
10044 "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",
10045 SHOW_STR
10046 BGP_STR
10047 "Display routes matching the communities\n"
10048 "community number\n"
10049 "Do not send outside local AS (well-known community)\n"
10050 "Do not advertise to any peer (well-known community)\n"
10051 "Do not export to next AS (well-known community)\n"
10052 "community number\n"
10053 "Do not send outside local AS (well-known community)\n"
10054 "Do not advertise to any peer (well-known community)\n"
10055 "Do not export to next AS (well-known community)\n"
10056 "community number\n"
10057 "Do not send outside local AS (well-known community)\n"
10058 "Do not advertise to any peer (well-known community)\n"
10059 "Do not export to next AS (well-known community)\n"
10060 "Exact match of the communities")
10061
10062ALIAS (show_bgp_community_exact,
10063 show_bgp_ipv6_community3_exact_cmd,
10064 "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",
10065 SHOW_STR
10066 BGP_STR
10067 "Address family\n"
10068 "Display routes matching the communities\n"
10069 "community number\n"
10070 "Do not send outside local AS (well-known community)\n"
10071 "Do not advertise to any peer (well-known community)\n"
10072 "Do not export to next AS (well-known community)\n"
10073 "community number\n"
10074 "Do not send outside local AS (well-known community)\n"
10075 "Do not advertise to any peer (well-known community)\n"
10076 "Do not export to next AS (well-known community)\n"
10077 "community number\n"
10078 "Do not send outside local AS (well-known community)\n"
10079 "Do not advertise to any peer (well-known community)\n"
10080 "Do not export to next AS (well-known community)\n"
10081 "Exact match of the communities")
10082
10083ALIAS (show_bgp_community_exact,
10084 show_bgp_community4_exact_cmd,
10085 "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",
10086 SHOW_STR
10087 BGP_STR
10088 "Display routes matching the communities\n"
10089 "community number\n"
10090 "Do not send outside local AS (well-known community)\n"
10091 "Do not advertise to any peer (well-known community)\n"
10092 "Do not export to next AS (well-known community)\n"
10093 "community number\n"
10094 "Do not send outside local AS (well-known community)\n"
10095 "Do not advertise to any peer (well-known community)\n"
10096 "Do not export to next AS (well-known community)\n"
10097 "community number\n"
10098 "Do not send outside local AS (well-known community)\n"
10099 "Do not advertise to any peer (well-known community)\n"
10100 "Do not export to next AS (well-known community)\n"
10101 "community number\n"
10102 "Do not send outside local AS (well-known community)\n"
10103 "Do not advertise to any peer (well-known community)\n"
10104 "Do not export to next AS (well-known community)\n"
10105 "Exact match of the communities")
10106
10107ALIAS (show_bgp_community_exact,
10108 show_bgp_ipv6_community4_exact_cmd,
10109 "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",
10110 SHOW_STR
10111 BGP_STR
10112 "Address family\n"
10113 "Display routes matching the communities\n"
10114 "community number\n"
10115 "Do not send outside local AS (well-known community)\n"
10116 "Do not advertise to any peer (well-known community)\n"
10117 "Do not export to next AS (well-known community)\n"
10118 "community number\n"
10119 "Do not send outside local AS (well-known community)\n"
10120 "Do not advertise to any peer (well-known community)\n"
10121 "Do not export to next AS (well-known community)\n"
10122 "community number\n"
10123 "Do not send outside local AS (well-known community)\n"
10124 "Do not advertise to any peer (well-known community)\n"
10125 "Do not export to next AS (well-known community)\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/* old command */
10133DEFUN (show_ipv6_bgp_community_exact,
10134 show_ipv6_bgp_community_exact_cmd,
10135 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10136 SHOW_STR
10137 IPV6_STR
10138 BGP_STR
10139 "Display routes matching the communities\n"
10140 "community number\n"
10141 "Do not send outside local AS (well-known community)\n"
10142 "Do not advertise to any peer (well-known community)\n"
10143 "Do not export to next AS (well-known community)\n"
10144 "Exact match of the communities")
10145{
10146 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10147}
10148
10149/* old command */
10150ALIAS (show_ipv6_bgp_community_exact,
10151 show_ipv6_bgp_community2_exact_cmd,
10152 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10153 SHOW_STR
10154 IPV6_STR
10155 BGP_STR
10156 "Display routes matching the communities\n"
10157 "community number\n"
10158 "Do not send outside local AS (well-known community)\n"
10159 "Do not advertise to any peer (well-known community)\n"
10160 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10166
10167/* old command */
10168ALIAS (show_ipv6_bgp_community_exact,
10169 show_ipv6_bgp_community3_exact_cmd,
10170 "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",
10171 SHOW_STR
10172 IPV6_STR
10173 BGP_STR
10174 "Display routes matching the communities\n"
10175 "community number\n"
10176 "Do not send outside local AS (well-known community)\n"
10177 "Do not advertise to any peer (well-known community)\n"
10178 "Do not export to next AS (well-known community)\n"
10179 "community number\n"
10180 "Do not send outside local AS (well-known community)\n"
10181 "Do not advertise to any peer (well-known community)\n"
10182 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10188
10189/* old command */
10190ALIAS (show_ipv6_bgp_community_exact,
10191 show_ipv6_bgp_community4_exact_cmd,
10192 "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",
10193 SHOW_STR
10194 IPV6_STR
10195 BGP_STR
10196 "Display routes matching the communities\n"
10197 "community number\n"
10198 "Do not send outside local AS (well-known community)\n"
10199 "Do not advertise to any peer (well-known community)\n"
10200 "Do not export to next AS (well-known community)\n"
10201 "community number\n"
10202 "Do not send outside local AS (well-known community)\n"
10203 "Do not advertise to any peer (well-known community)\n"
10204 "Do not export to next AS (well-known community)\n"
10205 "community number\n"
10206 "Do not send outside local AS (well-known community)\n"
10207 "Do not advertise to any peer (well-known community)\n"
10208 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10214
10215/* old command */
10216DEFUN (show_ipv6_mbgp_community,
10217 show_ipv6_mbgp_community_cmd,
10218 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10219 SHOW_STR
10220 IPV6_STR
10221 MBGP_STR
10222 "Display routes matching the communities\n"
10223 "community number\n"
10224 "Do not send outside local AS (well-known community)\n"
10225 "Do not advertise to any peer (well-known community)\n"
10226 "Do not export to next AS (well-known community)\n")
10227{
10228 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10229}
10230
10231/* old command */
10232ALIAS (show_ipv6_mbgp_community,
10233 show_ipv6_mbgp_community2_cmd,
10234 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10235 SHOW_STR
10236 IPV6_STR
10237 MBGP_STR
10238 "Display routes matching the communities\n"
10239 "community number\n"
10240 "Do not send outside local AS (well-known community)\n"
10241 "Do not advertise to any peer (well-known community)\n"
10242 "Do not export to next AS (well-known community)\n"
10243 "community number\n"
10244 "Do not send outside local AS (well-known community)\n"
10245 "Do not advertise to any peer (well-known community)\n"
10246 "Do not export to next AS (well-known community)\n")
10247
10248/* old command */
10249ALIAS (show_ipv6_mbgp_community,
10250 show_ipv6_mbgp_community3_cmd,
10251 "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)",
10252 SHOW_STR
10253 IPV6_STR
10254 MBGP_STR
10255 "Display routes matching the communities\n"
10256 "community number\n"
10257 "Do not send outside local AS (well-known community)\n"
10258 "Do not advertise to any peer (well-known community)\n"
10259 "Do not export to next AS (well-known community)\n"
10260 "community number\n"
10261 "Do not send outside local AS (well-known community)\n"
10262 "Do not advertise to any peer (well-known community)\n"
10263 "Do not export to next AS (well-known community)\n"
10264 "community number\n"
10265 "Do not send outside local AS (well-known community)\n"
10266 "Do not advertise to any peer (well-known community)\n"
10267 "Do not export to next AS (well-known community)\n")
10268
10269/* old command */
10270ALIAS (show_ipv6_mbgp_community,
10271 show_ipv6_mbgp_community4_cmd,
10272 "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)",
10273 SHOW_STR
10274 IPV6_STR
10275 MBGP_STR
10276 "Display routes matching the communities\n"
10277 "community number\n"
10278 "Do not send outside local AS (well-known community)\n"
10279 "Do not advertise to any peer (well-known community)\n"
10280 "Do not export to next AS (well-known community)\n"
10281 "community number\n"
10282 "Do not send outside local AS (well-known community)\n"
10283 "Do not advertise to any peer (well-known community)\n"
10284 "Do not export to next AS (well-known community)\n"
10285 "community number\n"
10286 "Do not send outside local AS (well-known community)\n"
10287 "Do not advertise to any peer (well-known community)\n"
10288 "Do not export to next AS (well-known community)\n"
10289 "community number\n"
10290 "Do not send outside local AS (well-known community)\n"
10291 "Do not advertise to any peer (well-known community)\n"
10292 "Do not export to next AS (well-known community)\n")
10293
10294/* old command */
10295DEFUN (show_ipv6_mbgp_community_exact,
10296 show_ipv6_mbgp_community_exact_cmd,
10297 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10298 SHOW_STR
10299 IPV6_STR
10300 MBGP_STR
10301 "Display routes matching the communities\n"
10302 "community number\n"
10303 "Do not send outside local AS (well-known community)\n"
10304 "Do not advertise to any peer (well-known community)\n"
10305 "Do not export to next AS (well-known community)\n"
10306 "Exact match of the communities")
10307{
10308 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10309}
10310
10311/* old command */
10312ALIAS (show_ipv6_mbgp_community_exact,
10313 show_ipv6_mbgp_community2_exact_cmd,
10314 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10315 SHOW_STR
10316 IPV6_STR
10317 MBGP_STR
10318 "Display routes matching the communities\n"
10319 "community number\n"
10320 "Do not send outside local AS (well-known community)\n"
10321 "Do not advertise to any peer (well-known community)\n"
10322 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10328
10329/* old command */
10330ALIAS (show_ipv6_mbgp_community_exact,
10331 show_ipv6_mbgp_community3_exact_cmd,
10332 "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",
10333 SHOW_STR
10334 IPV6_STR
10335 MBGP_STR
10336 "Display routes matching the communities\n"
10337 "community number\n"
10338 "Do not send outside local AS (well-known community)\n"
10339 "Do not advertise to any peer (well-known community)\n"
10340 "Do not export to next AS (well-known community)\n"
10341 "community number\n"
10342 "Do not send outside local AS (well-known community)\n"
10343 "Do not advertise to any peer (well-known community)\n"
10344 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
10350
10351/* old command */
10352ALIAS (show_ipv6_mbgp_community_exact,
10353 show_ipv6_mbgp_community4_exact_cmd,
10354 "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",
10355 SHOW_STR
10356 IPV6_STR
10357 MBGP_STR
10358 "Display routes matching the communities\n"
10359 "community number\n"
10360 "Do not send outside local AS (well-known community)\n"
10361 "Do not advertise to any peer (well-known community)\n"
10362 "Do not export to next AS (well-known community)\n"
10363 "community number\n"
10364 "Do not send outside local AS (well-known community)\n"
10365 "Do not advertise to any peer (well-known community)\n"
10366 "Do not export to next AS (well-known community)\n"
10367 "community number\n"
10368 "Do not send outside local AS (well-known community)\n"
10369 "Do not advertise to any peer (well-known community)\n"
10370 "Do not export to next AS (well-known community)\n"
10371 "community number\n"
10372 "Do not send outside local AS (well-known community)\n"
10373 "Do not advertise to any peer (well-known community)\n"
10374 "Do not export to next AS (well-known community)\n"
10375 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010376
Lou Berger651b4022016-01-12 13:42:07 -050010377DEFUN (show_bgp_ipv4_community,
10378 show_bgp_ipv4_community_cmd,
10379 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010380 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010381 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010382 IP_STR
paul718e3742002-12-13 20:15:29 +000010383 "Display routes matching the communities\n"
10384 "community number\n"
10385 "Do not send outside local AS (well-known community)\n"
10386 "Do not advertise to any peer (well-known community)\n"
10387 "Do not export to next AS (well-known community)\n")
10388{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010389 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010390}
10391
Lou Berger651b4022016-01-12 13:42:07 -050010392ALIAS (show_bgp_ipv4_community,
10393 show_bgp_ipv4_community2_cmd,
10394 "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 +000010395 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010396 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010397 IP_STR
paul718e3742002-12-13 20:15:29 +000010398 "Display routes matching the communities\n"
10399 "community number\n"
10400 "Do not send outside local AS (well-known community)\n"
10401 "Do not advertise to any peer (well-known community)\n"
10402 "Do not export to next AS (well-known community)\n"
10403 "community number\n"
10404 "Do not send outside local AS (well-known community)\n"
10405 "Do not advertise to any peer (well-known community)\n"
10406 "Do not export to next AS (well-known community)\n")
10407
Lou Berger651b4022016-01-12 13:42:07 -050010408ALIAS (show_bgp_ipv4_community,
10409 show_bgp_ipv4_community3_cmd,
10410 "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 +000010411 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010412 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010413 IP_STR
paul718e3742002-12-13 20:15:29 +000010414 "Display routes matching the communities\n"
10415 "community number\n"
10416 "Do not send outside local AS (well-known community)\n"
10417 "Do not advertise to any peer (well-known community)\n"
10418 "Do not export to next AS (well-known community)\n"
10419 "community number\n"
10420 "Do not send outside local AS (well-known community)\n"
10421 "Do not advertise to any peer (well-known community)\n"
10422 "Do not export to next AS (well-known community)\n"
10423 "community number\n"
10424 "Do not send outside local AS (well-known community)\n"
10425 "Do not advertise to any peer (well-known community)\n"
10426 "Do not export to next AS (well-known community)\n")
10427
Lou Berger651b4022016-01-12 13:42:07 -050010428ALIAS (show_bgp_ipv4_community,
10429 show_bgp_ipv4_community4_cmd,
10430 "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 +000010431 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010432 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010433 IP_STR
paul718e3742002-12-13 20:15:29 +000010434 "Display routes matching the communities\n"
10435 "community number\n"
10436 "Do not send outside local AS (well-known community)\n"
10437 "Do not advertise to any peer (well-known community)\n"
10438 "Do not export to next AS (well-known community)\n"
10439 "community number\n"
10440 "Do not send outside local AS (well-known community)\n"
10441 "Do not advertise to any peer (well-known community)\n"
10442 "Do not export to next AS (well-known community)\n"
10443 "community number\n"
10444 "Do not send outside local AS (well-known community)\n"
10445 "Do not advertise to any peer (well-known community)\n"
10446 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010452DEFUN (show_bgp_ipv4_safi_community,
10453 show_bgp_ipv4_safi_community_cmd,
10454 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010455 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010456 BGP_STR
10457 "Address family\n"
10458 "Address Family modifier\n"
10459 "Address Family modifier\n"
10460 "Display routes matching the communities\n"
10461 "community number\n"
10462 "Do not send outside local AS (well-known community)\n"
10463 "Do not advertise to any peer (well-known community)\n"
10464 "Do not export to next AS (well-known community)\n")
10465{
10466 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010467 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010468
Michael Lambert95cbbd22010-07-23 14:43:04 -040010469 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010470}
10471
Lou Berger651b4022016-01-12 13:42:07 -050010472ALIAS (show_bgp_ipv4_safi_community,
10473 show_bgp_ipv4_safi_community2_cmd,
10474 "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 +000010475 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010476 BGP_STR
10477 "Address family\n"
10478 "Address Family modifier\n"
10479 "Address Family modifier\n"
10480 "Display routes matching the communities\n"
10481 "community number\n"
10482 "Do not send outside local AS (well-known community)\n"
10483 "Do not advertise to any peer (well-known community)\n"
10484 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010490ALIAS (show_bgp_ipv4_safi_community,
10491 show_bgp_ipv4_safi_community3_cmd,
10492 "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 +000010493 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010494 BGP_STR
10495 "Address family\n"
10496 "Address Family modifier\n"
10497 "Address Family modifier\n"
10498 "Display routes matching the communities\n"
10499 "community number\n"
10500 "Do not send outside local AS (well-known community)\n"
10501 "Do not advertise to any peer (well-known community)\n"
10502 "Do not export to next AS (well-known community)\n"
10503 "community number\n"
10504 "Do not send outside local AS (well-known community)\n"
10505 "Do not advertise to any peer (well-known community)\n"
10506 "Do not export to next AS (well-known community)\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
Lou Berger651b4022016-01-12 13:42:07 -050010512ALIAS (show_bgp_ipv4_safi_community,
10513 show_bgp_ipv4_safi_community4_cmd,
10514 "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 +000010515 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010516 BGP_STR
10517 "Address family\n"
10518 "Address Family modifier\n"
10519 "Address Family modifier\n"
10520 "Display routes matching the communities\n"
10521 "community number\n"
10522 "Do not send outside local AS (well-known community)\n"
10523 "Do not advertise to any peer (well-known community)\n"
10524 "Do not export to next AS (well-known community)\n"
10525 "community number\n"
10526 "Do not send outside local AS (well-known community)\n"
10527 "Do not advertise to any peer (well-known community)\n"
10528 "Do not export to next AS (well-known community)\n"
10529 "community number\n"
10530 "Do not send outside local AS (well-known community)\n"
10531 "Do not advertise to any peer (well-known community)\n"
10532 "Do not export to next AS (well-known community)\n"
10533 "community number\n"
10534 "Do not send outside local AS (well-known community)\n"
10535 "Do not advertise to any peer (well-known community)\n"
10536 "Do not export to next AS (well-known community)\n")
10537
Michael Lambert95cbbd22010-07-23 14:43:04 -040010538DEFUN (show_bgp_view_afi_safi_community_all,
10539 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010540 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010541 SHOW_STR
10542 BGP_STR
10543 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010544 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010545 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010546 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010547 "Address Family modifier\n"
10548 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010549 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010550{
10551 int afi;
10552 int safi;
10553 struct bgp *bgp;
10554
10555 /* BGP structure lookup. */
10556 bgp = bgp_lookup_by_name (argv[0]);
10557 if (bgp == NULL)
10558 {
10559 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10560 return CMD_WARNING;
10561 }
10562
Michael Lambert95cbbd22010-07-23 14:43:04 -040010563 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10564 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010565 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10566}
10567
10568DEFUN (show_bgp_view_afi_safi_community,
10569 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010570 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010571 SHOW_STR
10572 BGP_STR
10573 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010574 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010575 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010576 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010577 "Address family modifier\n"
10578 "Address family modifier\n"
10579 "Display routes matching the communities\n"
10580 "community number\n"
10581 "Do not send outside local AS (well-known community)\n"
10582 "Do not advertise to any peer (well-known community)\n"
10583 "Do not export to next AS (well-known community)\n")
10584{
10585 int afi;
10586 int safi;
10587
Michael Lambert95cbbd22010-07-23 14:43:04 -040010588 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10589 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10590 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010591}
10592
10593ALIAS (show_bgp_view_afi_safi_community,
10594 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010595 "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 -040010596 SHOW_STR
10597 BGP_STR
10598 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010599 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010600 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010601 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010602 "Address family modifier\n"
10603 "Address family modifier\n"
10604 "Display routes matching the communities\n"
10605 "community number\n"
10606 "Do not send outside local AS (well-known community)\n"
10607 "Do not advertise to any peer (well-known community)\n"
10608 "Do not export to next AS (well-known community)\n"
10609 "community number\n"
10610 "Do not send outside local AS (well-known community)\n"
10611 "Do not advertise to any peer (well-known community)\n"
10612 "Do not export to next AS (well-known community)\n")
10613
10614ALIAS (show_bgp_view_afi_safi_community,
10615 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010616 "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 -040010617 SHOW_STR
10618 BGP_STR
10619 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010620 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010621 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010622 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010623 "Address family modifier\n"
10624 "Address family modifier\n"
10625 "Display routes matching the communities\n"
10626 "community number\n"
10627 "Do not send outside local AS (well-known community)\n"
10628 "Do not advertise to any peer (well-known community)\n"
10629 "Do not export to next AS (well-known community)\n"
10630 "community number\n"
10631 "Do not send outside local AS (well-known community)\n"
10632 "Do not advertise to any peer (well-known community)\n"
10633 "Do not export to next AS (well-known community)\n"
10634 "community number\n"
10635 "Do not send outside local AS (well-known community)\n"
10636 "Do not advertise to any peer (well-known community)\n"
10637 "Do not export to next AS (well-known community)\n")
10638
10639ALIAS (show_bgp_view_afi_safi_community,
10640 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010641 "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 -040010642 SHOW_STR
10643 BGP_STR
10644 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010645 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010646 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010647 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010648 "Address family modifier\n"
10649 "Address family modifier\n"
10650 "Display routes matching the communities\n"
10651 "community number\n"
10652 "Do not send outside local AS (well-known community)\n"
10653 "Do not advertise to any peer (well-known community)\n"
10654 "Do not export to next AS (well-known community)\n"
10655 "community number\n"
10656 "Do not send outside local AS (well-known community)\n"
10657 "Do not advertise to any peer (well-known community)\n"
10658 "Do not export to next AS (well-known community)\n"
10659 "community number\n"
10660 "Do not send outside local AS (well-known community)\n"
10661 "Do not advertise to any peer (well-known community)\n"
10662 "Do not export to next AS (well-known community)\n"
10663 "community number\n"
10664 "Do not send outside local AS (well-known community)\n"
10665 "Do not advertise to any peer (well-known community)\n"
10666 "Do not export to next AS (well-known community)\n")
10667
Lou Berger651b4022016-01-12 13:42:07 -050010668DEFUN (show_bgp_ipv4_community_exact,
10669 show_bgp_ipv4_community_exact_cmd,
10670 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010671 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010672 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010673 IP_STR
paul718e3742002-12-13 20:15:29 +000010674 "Display routes matching the communities\n"
10675 "community number\n"
10676 "Do not send outside local AS (well-known community)\n"
10677 "Do not advertise to any peer (well-known community)\n"
10678 "Do not export to next AS (well-known community)\n"
10679 "Exact match of the communities")
10680{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010681 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010682}
10683
Lou Berger651b4022016-01-12 13:42:07 -050010684ALIAS (show_bgp_ipv4_community_exact,
10685 show_bgp_ipv4_community2_exact_cmd,
10686 "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 +000010687 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010688 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010689 IP_STR
paul718e3742002-12-13 20:15:29 +000010690 "Display routes matching the communities\n"
10691 "community number\n"
10692 "Do not send outside local AS (well-known community)\n"
10693 "Do not advertise to any peer (well-known community)\n"
10694 "Do not export to next AS (well-known community)\n"
10695 "community number\n"
10696 "Do not send outside local AS (well-known community)\n"
10697 "Do not advertise to any peer (well-known community)\n"
10698 "Do not export to next AS (well-known community)\n"
10699 "Exact match of the communities")
10700
Lou Berger651b4022016-01-12 13:42:07 -050010701ALIAS (show_bgp_ipv4_community_exact,
10702 show_bgp_ipv4_community3_exact_cmd,
10703 "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 +000010704 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010705 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010706 IP_STR
paul718e3742002-12-13 20:15:29 +000010707 "Display routes matching the communities\n"
10708 "community number\n"
10709 "Do not send outside local AS (well-known community)\n"
10710 "Do not advertise to any peer (well-known community)\n"
10711 "Do not export to next AS (well-known community)\n"
10712 "community number\n"
10713 "Do not send outside local AS (well-known community)\n"
10714 "Do not advertise to any peer (well-known community)\n"
10715 "Do not export to next AS (well-known community)\n"
10716 "community number\n"
10717 "Do not send outside local AS (well-known community)\n"
10718 "Do not advertise to any peer (well-known community)\n"
10719 "Do not export to next AS (well-known community)\n"
10720 "Exact match of the communities")
10721
Lou Berger651b4022016-01-12 13:42:07 -050010722ALIAS (show_bgp_ipv4_community_exact,
10723 show_bgp_ipv4_community4_exact_cmd,
10724 "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 +000010725 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010726 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010727 IP_STR
paul718e3742002-12-13 20:15:29 +000010728 "Display routes matching the communities\n"
10729 "community number\n"
10730 "Do not send outside local AS (well-known community)\n"
10731 "Do not advertise to any peer (well-known community)\n"
10732 "Do not export to next AS (well-known community)\n"
10733 "community number\n"
10734 "Do not send outside local AS (well-known community)\n"
10735 "Do not advertise to any peer (well-known community)\n"
10736 "Do not export to next AS (well-known community)\n"
10737 "community number\n"
10738 "Do not send outside local AS (well-known community)\n"
10739 "Do not advertise to any peer (well-known community)\n"
10740 "Do not export to next AS (well-known community)\n"
10741 "community number\n"
10742 "Do not send outside local AS (well-known community)\n"
10743 "Do not advertise to any peer (well-known community)\n"
10744 "Do not export to next AS (well-known community)\n"
10745 "Exact match of the communities")
10746
Lou Berger651b4022016-01-12 13:42:07 -050010747DEFUN (show_bgp_ipv4_safi_community4_exact,
10748 show_bgp_ipv4_safi_community_exact_cmd,
10749 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010750 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010751 BGP_STR
10752 "Address family\n"
10753 "Address Family modifier\n"
10754 "Address Family modifier\n"
10755 "Display routes matching the communities\n"
10756 "community number\n"
10757 "Do not send outside local AS (well-known community)\n"
10758 "Do not advertise to any peer (well-known community)\n"
10759 "Do not export to next AS (well-known community)\n"
10760 "Exact match of the communities")
10761{
10762 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010763 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010764
Michael Lambert95cbbd22010-07-23 14:43:04 -040010765 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010766}
10767
Lou Berger651b4022016-01-12 13:42:07 -050010768ALIAS (show_bgp_ipv4_safi_community4_exact,
10769 show_bgp_ipv4_safi_community2_exact_cmd,
10770 "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 +000010771 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010772 BGP_STR
10773 "Address family\n"
10774 "Address Family modifier\n"
10775 "Address Family modifier\n"
10776 "Display routes matching the communities\n"
10777 "community number\n"
10778 "Do not send outside local AS (well-known community)\n"
10779 "Do not advertise to any peer (well-known community)\n"
10780 "Do not export to next AS (well-known community)\n"
10781 "community number\n"
10782 "Do not send outside local AS (well-known community)\n"
10783 "Do not advertise to any peer (well-known community)\n"
10784 "Do not export to next AS (well-known community)\n"
10785 "Exact match of the communities")
10786
Lou Berger651b4022016-01-12 13:42:07 -050010787ALIAS (show_bgp_ipv4_safi_community4_exact,
10788 show_bgp_ipv4_safi_community3_exact_cmd,
10789 "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 +000010790 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010791 BGP_STR
10792 "Address family\n"
10793 "Address Family modifier\n"
10794 "Address Family modifier\n"
10795 "Display routes matching the communities\n"
10796 "community number\n"
10797 "Do not send outside local AS (well-known community)\n"
10798 "Do not advertise to any peer (well-known community)\n"
10799 "Do not export to next AS (well-known community)\n"
10800 "community number\n"
10801 "Do not send outside local AS (well-known community)\n"
10802 "Do not advertise to any peer (well-known community)\n"
10803 "Do not export to next AS (well-known community)\n"
10804 "community number\n"
10805 "Do not send outside local AS (well-known community)\n"
10806 "Do not advertise to any peer (well-known community)\n"
10807 "Do not export to next AS (well-known community)\n"
10808 "Exact match of the communities")
10809
Lou Berger651b4022016-01-12 13:42:07 -050010810ALIAS (show_bgp_ipv4_safi_community4_exact,
10811 show_bgp_ipv4_safi_community4_exact_cmd,
10812 "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 +000010813 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010814 BGP_STR
10815 "Address family\n"
10816 "Address Family modifier\n"
10817 "Address Family modifier\n"
10818 "Display routes matching the communities\n"
10819 "community number\n"
10820 "Do not send outside local AS (well-known community)\n"
10821 "Do not advertise to any peer (well-known community)\n"
10822 "Do not export to next AS (well-known community)\n"
10823 "community number\n"
10824 "Do not send outside local AS (well-known community)\n"
10825 "Do not advertise to any peer (well-known community)\n"
10826 "Do not export to next AS (well-known community)\n"
10827 "community number\n"
10828 "Do not send outside local AS (well-known community)\n"
10829 "Do not advertise to any peer (well-known community)\n"
10830 "Do not export to next AS (well-known community)\n"
10831 "community number\n"
10832 "Do not send outside local AS (well-known community)\n"
10833 "Do not advertise to any peer (well-known community)\n"
10834 "Do not export to next AS (well-known community)\n"
10835 "Exact match of the communities")
10836
Lou Bergerf9b6c392016-01-12 13:42:09 -050010837DEFUN (show_bgp_ipv6_safi_community,
10838 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010839 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010840 SHOW_STR
10841 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010842 "Address family\n"
10843 "Address family modifier\n"
10844 "Address family modifier\n"
10845 "Address family modifier\n"
10846 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010847 "Display routes matching the communities\n"
10848 "community number\n"
10849 "Do not send outside local AS (well-known community)\n"
10850 "Do not advertise to any peer (well-known community)\n"
10851 "Do not export to next AS (well-known community)\n")
10852{
Lou Berger651b4022016-01-12 13:42:07 -050010853 safi_t safi;
10854
10855 if (bgp_parse_safi(argv[0], &safi)) {
10856 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10857 return CMD_WARNING;
10858 }
10859 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010860}
10861
Lou Bergerf9b6c392016-01-12 13:42:09 -050010862ALIAS (show_bgp_ipv6_safi_community,
10863 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010864 "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 +000010865 SHOW_STR
10866 BGP_STR
10867 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010868 "Address family modifier\n"
10869 "Address family modifier\n"
10870 "Address family modifier\n"
10871 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010872 "Display routes matching the communities\n"
10873 "community number\n"
10874 "Do not send outside local AS (well-known community)\n"
10875 "Do not advertise to any peer (well-known community)\n"
10876 "Do not export to next AS (well-known community)\n"
10877 "community number\n"
10878 "Do not send outside local AS (well-known community)\n"
10879 "Do not advertise to any peer (well-known community)\n"
10880 "Do not export to next AS (well-known community)\n")
10881
Lou Bergerf9b6c392016-01-12 13:42:09 -050010882ALIAS (show_bgp_ipv6_safi_community,
10883 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010884 "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 +000010885 SHOW_STR
10886 BGP_STR
10887 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010888 "Address family modifier\n"
10889 "Address family modifier\n"
10890 "Address family modifier\n"
10891 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010892 "Display routes matching the communities\n"
10893 "community number\n"
10894 "Do not send outside local AS (well-known community)\n"
10895 "Do not advertise to any peer (well-known community)\n"
10896 "Do not export to next AS (well-known community)\n"
10897 "community number\n"
10898 "Do not send outside local AS (well-known community)\n"
10899 "Do not advertise to any peer (well-known community)\n"
10900 "Do not export to next AS (well-known community)\n"
10901 "community number\n"
10902 "Do not send outside local AS (well-known community)\n"
10903 "Do not advertise to any peer (well-known community)\n"
10904 "Do not export to next AS (well-known community)\n")
10905
Lou Bergerf9b6c392016-01-12 13:42:09 -050010906ALIAS (show_bgp_ipv6_safi_community,
10907 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010908 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010909 SHOW_STR
10910 BGP_STR
10911 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010912 "Address family modifier\n"
10913 "Address family modifier\n"
10914 "Address family modifier\n"
10915 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010916 "Display routes matching the communities\n"
10917 "community number\n"
10918 "Do not send outside local AS (well-known community)\n"
10919 "Do not advertise to any peer (well-known community)\n"
10920 "Do not export to next AS (well-known community)\n"
10921 "community number\n"
10922 "Do not send outside local AS (well-known community)\n"
10923 "Do not advertise to any peer (well-known community)\n"
10924 "Do not export to next AS (well-known community)\n"
10925 "community number\n"
10926 "Do not send outside local AS (well-known community)\n"
10927 "Do not advertise to any peer (well-known community)\n"
10928 "Do not export to next AS (well-known community)\n"
10929 "community number\n"
10930 "Do not send outside local AS (well-known community)\n"
10931 "Do not advertise to any peer (well-known community)\n"
10932 "Do not export to next AS (well-known community)\n")
10933
paul718e3742002-12-13 20:15:29 +000010934
Lou Bergerf9b6c392016-01-12 13:42:09 -050010935DEFUN (show_bgp_ipv6_safi_community_exact,
10936 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010937 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010938 SHOW_STR
10939 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010940 "Address family\n"
10941 "Address family modifier\n"
10942 "Address family modifier\n"
10943 "Address family modifier\n"
10944 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010945 "Display routes matching the communities\n"
10946 "community number\n"
10947 "Do not send outside local AS (well-known community)\n"
10948 "Do not advertise to any peer (well-known community)\n"
10949 "Do not export to next AS (well-known community)\n"
10950 "Exact match of the communities")
10951{
Lou Berger651b4022016-01-12 13:42:07 -050010952 safi_t safi;
10953
10954 if (bgp_parse_safi(argv[0], &safi)) {
10955 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10956 return CMD_WARNING;
10957 }
10958 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010959}
10960
paul718e3742002-12-13 20:15:29 +000010961
10962ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010963 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010964 "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 +000010965 SHOW_STR
10966 BGP_STR
10967 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010968 "Address family modifier\n"
10969 "Address family modifier\n"
10970 "Address family modifier\n"
10971 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010972 "Display routes matching the communities\n"
10973 "community number\n"
10974 "Do not send outside local AS (well-known community)\n"
10975 "Do not advertise to any peer (well-known community)\n"
10976 "Do not export to next AS (well-known community)\n"
10977 "community number\n"
10978 "Do not send outside local AS (well-known community)\n"
10979 "Do not advertise to any peer (well-known community)\n"
10980 "Do not export to next AS (well-known community)\n"
10981 "Exact match of the communities")
10982
10983ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010984 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010985 "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 +000010986 SHOW_STR
10987 BGP_STR
10988 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010989 "Address family modifier\n"
10990 "Address family modifier\n"
10991 "Address family modifier\n"
10992 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010993 "Display routes matching the communities\n"
10994 "community number\n"
10995 "Do not send outside local AS (well-known community)\n"
10996 "Do not advertise to any peer (well-known community)\n"
10997 "Do not export to next AS (well-known community)\n"
10998 "community number\n"
10999 "Do not send outside local AS (well-known community)\n"
11000 "Do not advertise to any peer (well-known community)\n"
11001 "Do not export to next AS (well-known community)\n"
11002 "community number\n"
11003 "Do not send outside local AS (well-known community)\n"
11004 "Do not advertise to any peer (well-known community)\n"
11005 "Do not export to next AS (well-known community)\n"
11006 "Exact match of the communities")
11007
11008ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050011009 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011010 "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 +000011011 SHOW_STR
11012 BGP_STR
11013 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011014 "Address family modifier\n"
11015 "Address family modifier\n"
11016 "Address family modifier\n"
11017 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011018 "Display routes matching the communities\n"
11019 "community number\n"
11020 "Do not send outside local AS (well-known community)\n"
11021 "Do not advertise to any peer (well-known community)\n"
11022 "Do not export to next AS (well-known community)\n"
11023 "community number\n"
11024 "Do not send outside local AS (well-known community)\n"
11025 "Do not advertise to any peer (well-known community)\n"
11026 "Do not export to next AS (well-known community)\n"
11027 "community number\n"
11028 "Do not send outside local AS (well-known community)\n"
11029 "Do not advertise to any peer (well-known community)\n"
11030 "Do not export to next AS (well-known community)\n"
11031 "community number\n"
11032 "Do not send outside local AS (well-known community)\n"
11033 "Do not advertise to any peer (well-known community)\n"
11034 "Do not export to next AS (well-known community)\n"
11035 "Exact match of the communities")
11036
paul94f2b392005-06-28 12:44:16 +000011037static int
paulfd79ac92004-10-13 05:06:08 +000011038bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040011039 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000011040{
11041 struct community_list *list;
11042
hassofee6e4e2005-02-02 16:29:31 +000011043 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000011044 if (list == NULL)
11045 {
11046 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11047 VTY_NEWLINE);
11048 return CMD_WARNING;
11049 }
11050
ajs5a646652004-11-05 01:25:55 +000011051 return bgp_show (vty, NULL, afi, safi,
11052 (exact ? bgp_show_type_community_list_exact :
11053 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000011054}
11055
Lou Bergerf9b6c392016-01-12 13:42:09 -050011056DEFUN (show_ip_bgp_community_list,
11057 show_ip_bgp_community_list_cmd,
11058 "show ip bgp community-list (<1-500>|WORD)",
11059 SHOW_STR
11060 IP_STR
11061 BGP_STR
11062 "Display routes matching the community-list\n"
11063 "community-list number\n"
11064 "community-list name\n")
11065{
11066 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11067}
11068
11069DEFUN (show_ip_bgp_ipv4_community_list,
11070 show_ip_bgp_ipv4_community_list_cmd,
11071 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11072 SHOW_STR
11073 IP_STR
11074 BGP_STR
11075 "Address family\n"
11076 "Address Family modifier\n"
11077 "Address Family modifier\n"
11078 "Display routes matching the community-list\n"
11079 "community-list number\n"
11080 "community-list name\n")
11081{
11082 if (strncmp (argv[0], "m", 1) == 0)
11083 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11084
11085 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11086}
11087
11088DEFUN (show_ip_bgp_community_list_exact,
11089 show_ip_bgp_community_list_exact_cmd,
11090 "show ip bgp community-list (<1-500>|WORD) exact-match",
11091 SHOW_STR
11092 IP_STR
11093 BGP_STR
11094 "Display routes matching the community-list\n"
11095 "community-list number\n"
11096 "community-list name\n"
11097 "Exact match of the communities\n")
11098{
11099 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11100}
11101
11102DEFUN (show_ip_bgp_ipv4_community_list_exact,
11103 show_ip_bgp_ipv4_community_list_exact_cmd,
11104 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11105 SHOW_STR
11106 IP_STR
11107 BGP_STR
11108 "Address family\n"
11109 "Address Family modifier\n"
11110 "Address Family modifier\n"
11111 "Display routes matching the community-list\n"
11112 "community-list number\n"
11113 "community-list name\n"
11114 "Exact match of the communities\n")
11115{
11116 if (strncmp (argv[0], "m", 1) == 0)
11117 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11118
11119 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11120}
11121
Lou Bergerf9b6c392016-01-12 13:42:09 -050011122DEFUN (show_bgp_community_list,
11123 show_bgp_community_list_cmd,
11124 "show bgp community-list (<1-500>|WORD)",
11125 SHOW_STR
11126 BGP_STR
11127 "Display routes matching the community-list\n"
11128 "community-list number\n"
11129 "community-list name\n")
11130{
11131 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11132}
11133
11134ALIAS (show_bgp_community_list,
11135 show_bgp_ipv6_community_list_cmd,
11136 "show bgp ipv6 community-list (<1-500>|WORD)",
11137 SHOW_STR
11138 BGP_STR
11139 "Address family\n"
11140 "Display routes matching the community-list\n"
11141 "community-list number\n"
11142 "community-list name\n")
11143
11144/* old command */
11145DEFUN (show_ipv6_bgp_community_list,
11146 show_ipv6_bgp_community_list_cmd,
11147 "show ipv6 bgp community-list WORD",
11148 SHOW_STR
11149 IPV6_STR
11150 BGP_STR
11151 "Display routes matching the community-list\n"
11152 "community-list name\n")
11153{
11154 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11155}
11156
11157/* old command */
11158DEFUN (show_ipv6_mbgp_community_list,
11159 show_ipv6_mbgp_community_list_cmd,
11160 "show ipv6 mbgp community-list WORD",
11161 SHOW_STR
11162 IPV6_STR
11163 MBGP_STR
11164 "Display routes matching the community-list\n"
11165 "community-list name\n")
11166{
11167 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11168}
11169
11170DEFUN (show_bgp_community_list_exact,
11171 show_bgp_community_list_exact_cmd,
11172 "show bgp community-list (<1-500>|WORD) exact-match",
11173 SHOW_STR
11174 BGP_STR
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 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11181}
11182
11183ALIAS (show_bgp_community_list_exact,
11184 show_bgp_ipv6_community_list_exact_cmd,
11185 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11186 SHOW_STR
11187 BGP_STR
11188 "Address family\n"
11189 "Display routes matching the community-list\n"
11190 "community-list number\n"
11191 "community-list name\n"
11192 "Exact match of the communities\n")
11193
11194/* old command */
11195DEFUN (show_ipv6_bgp_community_list_exact,
11196 show_ipv6_bgp_community_list_exact_cmd,
11197 "show ipv6 bgp community-list WORD exact-match",
11198 SHOW_STR
11199 IPV6_STR
11200 BGP_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_UNICAST);
11206}
11207
11208/* old command */
11209DEFUN (show_ipv6_mbgp_community_list_exact,
11210 show_ipv6_mbgp_community_list_exact_cmd,
11211 "show ipv6 mbgp community-list WORD exact-match",
11212 SHOW_STR
11213 IPV6_STR
11214 MBGP_STR
11215 "Display routes matching the community-list\n"
11216 "community-list name\n"
11217 "Exact match of the communities\n")
11218{
11219 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11220}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011221
Lou Berger651b4022016-01-12 13:42:07 -050011222DEFUN (show_bgp_ipv4_community_list,
11223 show_bgp_ipv4_community_list_cmd,
11224 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011225 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011226 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011227 IP_STR
paul718e3742002-12-13 20:15:29 +000011228 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011229 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011230 "community-list name\n")
11231{
11232 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11233}
11234
Lou Berger651b4022016-01-12 13:42:07 -050011235DEFUN (show_bgp_ipv4_safi_community_list,
11236 show_bgp_ipv4_safi_community_list_cmd,
11237 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011238 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011239 BGP_STR
11240 "Address family\n"
11241 "Address Family modifier\n"
11242 "Address Family modifier\n"
11243 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011244 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011245 "community-list name\n")
11246{
11247 if (strncmp (argv[0], "m", 1) == 0)
11248 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11249
11250 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11251}
11252
Lou Berger651b4022016-01-12 13:42:07 -050011253DEFUN (show_bgp_ipv4_community_list_exact,
11254 show_bgp_ipv4_community_list_exact_cmd,
11255 "show bgp ipv4 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
Lou Berger651b4022016-01-12 13:42:07 -050011258 IP_STR
paul718e3742002-12-13 20:15:29 +000011259 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011260 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011261 "community-list name\n"
11262 "Exact match of the communities\n")
11263{
11264 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11265}
11266
Lou Berger651b4022016-01-12 13:42:07 -050011267DEFUN (show_bgp_ipv4_safi_community_list_exact,
11268 show_bgp_ipv4_safi_community_list_exact_cmd,
11269 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011270 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011271 BGP_STR
11272 "Address family\n"
11273 "Address Family modifier\n"
11274 "Address Family modifier\n"
11275 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011276 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011277 "community-list name\n"
11278 "Exact match of the communities\n")
11279{
11280 if (strncmp (argv[0], "m", 1) == 0)
11281 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11282
11283 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11284}
11285
Lou Bergerf9b6c392016-01-12 13:42:09 -050011286DEFUN (show_bgp_ipv6_safi_community_list,
11287 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011288 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011289 SHOW_STR
11290 BGP_STR
11291 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011292 "Address family modifier\n"
11293 "Address family modifier\n"
11294 "Address family modifier\n"
11295 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011296 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011297 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011298 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011299{
Lou Berger651b4022016-01-12 13:42:07 -050011300 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011301
Lou Berger651b4022016-01-12 13:42:07 -050011302 if (bgp_parse_safi(argv[0], &safi)) {
11303 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11304 return CMD_WARNING;
11305 }
11306 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011307}
11308
Lou Bergerf9b6c392016-01-12 13:42:09 -050011309DEFUN (show_bgp_ipv6_safi_community_list_exact,
11310 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011311 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011312 SHOW_STR
11313 BGP_STR
11314 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011315 "Address family modifier\n"
11316 "Address family modifier\n"
11317 "Address family modifier\n"
11318 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011319 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011320 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011321 "community-list name\n"
11322 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011323{
Lou Berger651b4022016-01-12 13:42:07 -050011324 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011325
Lou Berger651b4022016-01-12 13:42:07 -050011326 if (bgp_parse_safi(argv[0], &safi)) {
11327 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11328 return CMD_WARNING;
11329 }
11330 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011331}
David Lamparter6b0655a2014-06-04 06:53:35 +020011332
paul94f2b392005-06-28 12:44:16 +000011333static int
paulfd79ac92004-10-13 05:06:08 +000011334bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011335 safi_t safi, enum bgp_show_type type)
11336{
11337 int ret;
11338 struct prefix *p;
11339
11340 p = prefix_new();
11341
11342 ret = str2prefix (prefix, p);
11343 if (! ret)
11344 {
11345 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11346 return CMD_WARNING;
11347 }
11348
ajs5a646652004-11-05 01:25:55 +000011349 ret = bgp_show (vty, NULL, afi, safi, type, p);
11350 prefix_free(p);
11351 return ret;
paul718e3742002-12-13 20:15:29 +000011352}
11353
Lou Bergerf9b6c392016-01-12 13:42:09 -050011354DEFUN (show_ip_bgp_prefix_longer,
11355 show_ip_bgp_prefix_longer_cmd,
11356 "show ip bgp A.B.C.D/M longer-prefixes",
11357 SHOW_STR
11358 IP_STR
11359 BGP_STR
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_prefix_longer);
11365}
11366
11367DEFUN (show_ip_bgp_flap_prefix_longer,
11368 show_ip_bgp_flap_prefix_longer_cmd,
11369 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11370 SHOW_STR
11371 IP_STR
11372 BGP_STR
11373 "Display flap statistics of routes\n"
11374 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11375 "Display route and more specific routes\n")
11376{
11377 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11378 bgp_show_type_flap_prefix_longer);
11379}
11380
11381ALIAS (show_ip_bgp_flap_prefix_longer,
11382 show_ip_bgp_damp_flap_prefix_longer_cmd,
11383 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11384 SHOW_STR
11385 IP_STR
11386 BGP_STR
11387 "Display detailed information about dampening\n"
11388 "Display flap statistics of routes\n"
11389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11390 "Display route and more specific routes\n")
11391
11392DEFUN (show_ip_bgp_ipv4_prefix_longer,
11393 show_ip_bgp_ipv4_prefix_longer_cmd,
11394 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11395 SHOW_STR
11396 IP_STR
11397 BGP_STR
11398 "Address family\n"
11399 "Address Family modifier\n"
11400 "Address Family modifier\n"
11401 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11402 "Display route and more specific routes\n")
11403{
11404 if (strncmp (argv[0], "m", 1) == 0)
11405 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11406 bgp_show_type_prefix_longer);
11407
11408 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11409 bgp_show_type_prefix_longer);
11410}
11411
11412DEFUN (show_ip_bgp_flap_address,
11413 show_ip_bgp_flap_address_cmd,
11414 "show ip bgp flap-statistics A.B.C.D",
11415 SHOW_STR
11416 IP_STR
11417 BGP_STR
11418 "Display flap statistics of routes\n"
11419 "Network in the BGP routing table to display\n")
11420{
11421 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11422 bgp_show_type_flap_address);
11423}
11424
11425ALIAS (show_ip_bgp_flap_address,
11426 show_ip_bgp_damp_flap_address_cmd,
11427 "show ip bgp dampening flap-statistics A.B.C.D",
11428 SHOW_STR
11429 IP_STR
11430 BGP_STR
11431 "Display detailed information about dampening\n"
11432 "Display flap statistics of routes\n"
11433 "Network in the BGP routing table to display\n")
11434
11435DEFUN (show_ip_bgp_flap_prefix,
11436 show_ip_bgp_flap_prefix_cmd,
11437 "show ip bgp flap-statistics A.B.C.D/M",
11438 SHOW_STR
11439 IP_STR
11440 BGP_STR
11441 "Display flap statistics of routes\n"
11442 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11443{
11444 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11445 bgp_show_type_flap_prefix);
11446}
11447
11448ALIAS (show_ip_bgp_flap_prefix,
11449 show_ip_bgp_damp_flap_prefix_cmd,
11450 "show ip bgp dampening flap-statistics A.B.C.D/M",
11451 SHOW_STR
11452 IP_STR
11453 BGP_STR
11454 "Display detailed information about dampening\n"
11455 "Display flap statistics of routes\n"
11456 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11457
Lou Bergerf9b6c392016-01-12 13:42:09 -050011458DEFUN (show_bgp_prefix_longer,
11459 show_bgp_prefix_longer_cmd,
11460 "show bgp X:X::X:X/M longer-prefixes",
11461 SHOW_STR
11462 BGP_STR
11463 "IPv6 prefix <network>/<length>\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_bgp_prefix_longer,
11472 show_ipv6_bgp_prefix_longer_cmd,
11473 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11474 SHOW_STR
11475 IPV6_STR
11476 BGP_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_UNICAST,
11481 bgp_show_type_prefix_longer);
11482}
11483
11484/* old command */
11485DEFUN (show_ipv6_mbgp_prefix_longer,
11486 show_ipv6_mbgp_prefix_longer_cmd,
11487 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11488 SHOW_STR
11489 IPV6_STR
11490 MBGP_STR
11491 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11492 "Display route and more specific routes\n")
11493{
11494 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11495 bgp_show_type_prefix_longer);
11496}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011497
Lou Berger651b4022016-01-12 13:42:07 -050011498DEFUN (show_bgp_ipv4_prefix_longer,
11499 show_bgp_ipv4_prefix_longer_cmd,
11500 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011501 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011502 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011503 IP_STR
paul718e3742002-12-13 20:15:29 +000011504 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11505 "Display route and more specific routes\n")
11506{
11507 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11508 bgp_show_type_prefix_longer);
11509}
11510
Lou Berger651b4022016-01-12 13:42:07 -050011511DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11512 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11513 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011514 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011515 BGP_STR
11516 "Address family\n"
11517 "Address Family modifier\n"
11518 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011519 "Address Family modifier\n"
11520 "Address Family modifier\n"
11521 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011522 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11523 "Display route and more specific routes\n")
11524{
Lou Berger651b4022016-01-12 13:42:07 -050011525 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011526
Lou Berger651b4022016-01-12 13:42:07 -050011527 if (bgp_parse_safi(argv[0], &safi)) {
11528 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11529 return CMD_WARNING;
11530 }
11531 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11532 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011533}
11534
Lou Berger651b4022016-01-12 13:42:07 -050011535ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11536 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11537 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011538 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011539 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011540 "Address family\n"
11541 "Address Family modifier\n"
11542 "Address Family modifier\n"
11543 "Address Family modifier\n"
11544 "Address Family modifier\n"
11545 "Display detailed information about dampening\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
Lou Berger651b4022016-01-12 13:42:07 -050011550DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11551 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11552 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11553 SHOW_STR
11554 BGP_STR
11555 "Address family\n"
11556 "Address Family modifier\n"
11557 "Address Family modifier\n"
11558 "Address Family modifier\n"
11559 "Address Family modifier\n"
11560 "Display flap statistics of routes\n"
11561 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11562 "Display route and more specific routes\n")
11563{
11564 safi_t safi;
11565
11566 if (bgp_parse_safi(argv[0], &safi)) {
11567 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11568 return CMD_WARNING;
11569 }
11570 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11571 bgp_show_type_flap_prefix_longer);
11572}
11573ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11574 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11575 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11576 SHOW_STR
11577 BGP_STR
11578 "Address family\n"
11579 "Address Family modifier\n"
11580 "Address Family modifier\n"
11581 "Address Family modifier\n"
11582 "Address Family modifier\n"
11583 "Display detailed information about dampening\n"
11584 "Display flap statistics of routes\n"
11585 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11586 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011587
11588DEFUN (show_bgp_ipv4_safi_prefix_longer,
11589 show_bgp_ipv4_safi_prefix_longer_cmd,
11590 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11591 SHOW_STR
11592 BGP_STR
11593 "Address family\n"
11594 "Address Family modifier\n"
11595 "Address Family modifier\n"
11596 "Address Family modifier\n"
11597 "Address Family modifier\n"
11598 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11599 "Display route and more specific routes\n")
11600{
11601 safi_t safi;
11602
11603 if (bgp_parse_safi(argv[0], &safi)) {
11604 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11605 return CMD_WARNING;
11606 }
11607
11608 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11609 bgp_show_type_prefix_longer);
11610}
11611
Lou Berger651b4022016-01-12 13:42:07 -050011612DEFUN (show_bgp_ipv6_safi_prefix_longer,
11613 show_bgp_ipv6_safi_prefix_longer_cmd,
11614 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11615 SHOW_STR
11616 BGP_STR
11617 "Address family\n"
11618 "Address Family modifier\n"
11619 "Address Family modifier\n"
11620 "Address Family modifier\n"
11621 "Address Family modifier\n"
11622 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11623 "Display route and more specific routes\n")
11624{
11625 safi_t safi;
11626
11627 if (bgp_parse_safi(argv[0], &safi)) {
11628 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11629 return CMD_WARNING;
11630 }
11631
11632 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11633 bgp_show_type_prefix_longer);
11634}
Lou Berger651b4022016-01-12 13:42:07 -050011635
11636DEFUN (show_bgp_ipv4_safi_flap_address,
11637 show_bgp_ipv4_safi_flap_address_cmd,
11638 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11639 SHOW_STR
11640 BGP_STR
11641 "Address family\n"
11642 "Address Family modifier\n"
11643 "Address Family modifier\n"
11644 "Address Family modifier\n"
11645 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011646 "Display flap statistics of routes\n"
11647 "Network in the BGP routing table to display\n")
11648{
Lou Berger651b4022016-01-12 13:42:07 -050011649 safi_t safi;
11650
11651 if (bgp_parse_safi(argv[0], &safi)) {
11652 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11653 return CMD_WARNING;
11654 }
11655 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011656 bgp_show_type_flap_address);
11657}
Lou Berger651b4022016-01-12 13:42:07 -050011658ALIAS (show_bgp_ipv4_safi_flap_address,
11659 show_bgp_ipv4_safi_damp_flap_address_cmd,
11660 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011661 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011662 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"
Balaji3921cc52015-05-16 23:12:17 +053011668 "Display detailed information about dampening\n"
11669 "Display flap statistics of routes\n"
11670 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011671
Lou Berger651b4022016-01-12 13:42:07 -050011672DEFUN (show_bgp_ipv6_flap_address,
11673 show_bgp_ipv6_flap_address_cmd,
11674 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011675 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011676 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011677 "Address family\n"
11678 "Address Family modifier\n"
11679 "Address Family modifier\n"
11680 "Address Family modifier\n"
11681 "Address Family modifier\n"
11682 "Display flap statistics of routes\n"
11683 "Network in the BGP routing table to display\n")
11684{
11685 safi_t safi;
11686
11687 if (bgp_parse_safi(argv[0], &safi)) {
11688 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11689 return CMD_WARNING;
11690 }
11691 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11692 bgp_show_type_flap_address);
11693}
11694ALIAS (show_bgp_ipv6_flap_address,
11695 show_bgp_ipv6_damp_flap_address_cmd,
11696 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
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"
11704 "Display detailed information about dampening\n"
11705 "Display flap statistics of routes\n"
11706 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011707
11708DEFUN (show_bgp_ipv4_safi_flap_prefix,
11709 show_bgp_ipv4_safi_flap_prefix_cmd,
11710 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11711 SHOW_STR
11712 BGP_STR
11713 "Address family\n"
11714 "Address Family modifier\n"
11715 "Address Family modifier\n"
11716 "Address Family modifier\n"
11717 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011718 "Display flap statistics of routes\n"
11719 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11720{
Lou Berger651b4022016-01-12 13:42:07 -050011721 safi_t safi;
11722
11723 if (bgp_parse_safi(argv[0], &safi)) {
11724 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11725 return CMD_WARNING;
11726 }
11727 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011728 bgp_show_type_flap_prefix);
11729}
Balaji3921cc52015-05-16 23:12:17 +053011730
Lou Berger651b4022016-01-12 13:42:07 -050011731ALIAS (show_bgp_ipv4_safi_flap_prefix,
11732 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11733 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011734 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011735 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"
Balaji3921cc52015-05-16 23:12:17 +053011741 "Display detailed information about dampening\n"
11742 "Display flap statistics of routes\n"
11743 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11744
Lou Berger651b4022016-01-12 13:42:07 -050011745DEFUN (show_bgp_ipv6_safi_flap_prefix,
11746 show_bgp_ipv6_safi_flap_prefix_cmd,
11747 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011748 SHOW_STR
11749 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011750 "Address family\n"
11751 "Address Family modifier\n"
11752 "Address Family modifier\n"
11753 "Address Family modifier\n"
11754 "Address Family modifier\n"
11755 "Display flap statistics of routes\n"
11756 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011757{
Lou Berger651b4022016-01-12 13:42:07 -050011758 safi_t safi;
11759
11760 if (bgp_parse_safi(argv[0], &safi)) {
11761 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11762 return CMD_WARNING;
11763 }
11764 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11765 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011766}
11767
Lou Berger651b4022016-01-12 13:42:07 -050011768ALIAS (show_bgp_ipv6_safi_flap_prefix,
11769 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11770 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11771 SHOW_STR
11772 BGP_STR
11773 "Address family\n"
11774 "Address Family modifier\n"
11775 "Address Family modifier\n"
11776 "Address Family modifier\n"
11777 "Address Family modifier\n"
11778 "Display detailed information about dampening\n"
11779 "Display flap statistics of routes\n"
11780 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11781
11782DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011783 show_bgp_ipv6_prefix_longer_cmd,
11784 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11785 SHOW_STR
11786 BGP_STR
11787 "Address family\n"
11788 "IPv6 prefix <network>/<length>\n"
11789 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011790{
11791 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11792 bgp_show_type_prefix_longer);
11793}
11794
paul94f2b392005-06-28 12:44:16 +000011795static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011796peer_lookup_in_view (struct vty *vty, const char *view_name,
11797 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011798{
11799 int ret;
11800 struct bgp *bgp;
11801 struct peer *peer;
11802 union sockunion su;
11803
11804 /* BGP structure lookup. */
11805 if (view_name)
11806 {
11807 bgp = bgp_lookup_by_name (view_name);
11808 if (! bgp)
11809 {
11810 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11811 return NULL;
11812 }
11813 }
paul5228ad22004-06-04 17:58:18 +000011814 else
paulbb46e942003-10-24 19:02:03 +000011815 {
11816 bgp = bgp_get_default ();
11817 if (! bgp)
11818 {
11819 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11820 return NULL;
11821 }
11822 }
11823
11824 /* Get peer sockunion. */
11825 ret = str2sockunion (ip_str, &su);
11826 if (ret < 0)
11827 {
11828 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11829 return NULL;
11830 }
11831
11832 /* Peer structure lookup. */
11833 peer = peer_lookup (bgp, &su);
11834 if (! peer)
11835 {
11836 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11837 return NULL;
11838 }
11839
11840 return peer;
11841}
David Lamparter6b0655a2014-06-04 06:53:35 +020011842
Paul Jakma2815e612006-09-14 02:56:07 +000011843enum bgp_stats
11844{
11845 BGP_STATS_MAXBITLEN = 0,
11846 BGP_STATS_RIB,
11847 BGP_STATS_PREFIXES,
11848 BGP_STATS_TOTPLEN,
11849 BGP_STATS_UNAGGREGATEABLE,
11850 BGP_STATS_MAX_AGGREGATEABLE,
11851 BGP_STATS_AGGREGATES,
11852 BGP_STATS_SPACE,
11853 BGP_STATS_ASPATH_COUNT,
11854 BGP_STATS_ASPATH_MAXHOPS,
11855 BGP_STATS_ASPATH_TOTHOPS,
11856 BGP_STATS_ASPATH_MAXSIZE,
11857 BGP_STATS_ASPATH_TOTSIZE,
11858 BGP_STATS_ASN_HIGHEST,
11859 BGP_STATS_MAX,
11860};
paulbb46e942003-10-24 19:02:03 +000011861
Paul Jakma2815e612006-09-14 02:56:07 +000011862static const char *table_stats_strs[] =
11863{
11864 [BGP_STATS_PREFIXES] = "Total Prefixes",
11865 [BGP_STATS_TOTPLEN] = "Average prefix length",
11866 [BGP_STATS_RIB] = "Total Advertisements",
11867 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11868 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11869 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11870 [BGP_STATS_SPACE] = "Address space advertised",
11871 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11872 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11873 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11874 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11875 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11876 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11877 [BGP_STATS_MAX] = NULL,
11878};
11879
11880struct bgp_table_stats
11881{
11882 struct bgp_table *table;
11883 unsigned long long counts[BGP_STATS_MAX];
11884};
11885
11886#if 0
11887#define TALLY_SIGFIG 100000
11888static unsigned long
11889ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11890{
11891 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11892 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11893 unsigned long ret = newtot / count;
11894
11895 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11896 return ret + 1;
11897 else
11898 return ret;
11899}
11900#endif
11901
11902static int
11903bgp_table_stats_walker (struct thread *t)
11904{
11905 struct bgp_node *rn;
11906 struct bgp_node *top;
11907 struct bgp_table_stats *ts = THREAD_ARG (t);
11908 unsigned int space = 0;
11909
Paul Jakma53d9f672006-10-15 23:41:16 +000011910 if (!(top = bgp_table_top (ts->table)))
11911 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011912
11913 switch (top->p.family)
11914 {
11915 case AF_INET:
11916 space = IPV4_MAX_BITLEN;
11917 break;
11918 case AF_INET6:
11919 space = IPV6_MAX_BITLEN;
11920 break;
11921 }
11922
11923 ts->counts[BGP_STATS_MAXBITLEN] = space;
11924
11925 for (rn = top; rn; rn = bgp_route_next (rn))
11926 {
11927 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011928 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011929 unsigned int rinum = 0;
11930
11931 if (rn == top)
11932 continue;
11933
11934 if (!rn->info)
11935 continue;
11936
11937 ts->counts[BGP_STATS_PREFIXES]++;
11938 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11939
11940#if 0
11941 ts->counts[BGP_STATS_AVGPLEN]
11942 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11943 ts->counts[BGP_STATS_AVGPLEN],
11944 rn->p.prefixlen);
11945#endif
11946
11947 /* check if the prefix is included by any other announcements */
11948 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011949 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011950
11951 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011952 {
11953 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11954 /* announced address space */
11955 if (space)
11956 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11957 }
Paul Jakma2815e612006-09-14 02:56:07 +000011958 else if (prn->info)
11959 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11960
Paul Jakma2815e612006-09-14 02:56:07 +000011961 for (ri = rn->info; ri; ri = ri->next)
11962 {
11963 rinum++;
11964 ts->counts[BGP_STATS_RIB]++;
11965
11966 if (ri->attr &&
11967 (CHECK_FLAG (ri->attr->flag,
11968 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11969 ts->counts[BGP_STATS_AGGREGATES]++;
11970
11971 /* as-path stats */
11972 if (ri->attr && ri->attr->aspath)
11973 {
11974 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11975 unsigned int size = aspath_size (ri->attr->aspath);
11976 as_t highest = aspath_highest (ri->attr->aspath);
11977
11978 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11979
11980 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11981 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11982
11983 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11984 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11985
11986 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11987 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11988#if 0
11989 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11990 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11991 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11992 hops);
11993 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11994 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11995 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11996 size);
11997#endif
11998 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11999 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
12000 }
12001 }
12002 }
12003 return 0;
12004}
12005
12006static int
12007bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
12008{
12009 struct bgp_table_stats ts;
12010 unsigned int i;
12011
12012 if (!bgp->rib[afi][safi])
12013 {
Donald Sharp3c964042016-01-25 23:38:53 -050012014 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
12015 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012016 return CMD_WARNING;
12017 }
12018
12019 memset (&ts, 0, sizeof (ts));
12020 ts.table = bgp->rib[afi][safi];
12021 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12022
12023 vty_out (vty, "BGP %s RIB statistics%s%s",
12024 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12025
12026 for (i = 0; i < BGP_STATS_MAX; i++)
12027 {
12028 if (!table_stats_strs[i])
12029 continue;
12030
12031 switch (i)
12032 {
12033#if 0
12034 case BGP_STATS_ASPATH_AVGHOPS:
12035 case BGP_STATS_ASPATH_AVGSIZE:
12036 case BGP_STATS_AVGPLEN:
12037 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12038 vty_out (vty, "%12.2f",
12039 (float)ts.counts[i] / (float)TALLY_SIGFIG);
12040 break;
12041#endif
12042 case BGP_STATS_ASPATH_TOTHOPS:
12043 case BGP_STATS_ASPATH_TOTSIZE:
12044 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12045 vty_out (vty, "%12.2f",
12046 ts.counts[i] ?
12047 (float)ts.counts[i] /
12048 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
12049 : 0);
12050 break;
12051 case BGP_STATS_TOTPLEN:
12052 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12053 vty_out (vty, "%12.2f",
12054 ts.counts[i] ?
12055 (float)ts.counts[i] /
12056 (float)ts.counts[BGP_STATS_PREFIXES]
12057 : 0);
12058 break;
12059 case BGP_STATS_SPACE:
12060 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12061 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
12062 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
12063 break;
Paul Jakma30a22312008-08-15 14:05:22 +010012064 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000012065 vty_out (vty, "%12.2f%s",
12066 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000012067 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000012068 VTY_NEWLINE);
12069 vty_out (vty, "%30s: ", "/8 equivalent ");
12070 vty_out (vty, "%12.2f%s",
12071 (float)ts.counts[BGP_STATS_SPACE] /
12072 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
12073 VTY_NEWLINE);
12074 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
12075 break;
12076 vty_out (vty, "%30s: ", "/24 equivalent ");
12077 vty_out (vty, "%12.2f",
12078 (float)ts.counts[BGP_STATS_SPACE] /
12079 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
12080 break;
12081 default:
12082 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12083 vty_out (vty, "%12llu", ts.counts[i]);
12084 }
12085
12086 vty_out (vty, "%s", VTY_NEWLINE);
12087 }
12088 return CMD_SUCCESS;
12089}
12090
12091static int
12092bgp_table_stats_vty (struct vty *vty, const char *name,
12093 const char *afi_str, const char *safi_str)
12094{
12095 struct bgp *bgp;
12096 afi_t afi;
12097 safi_t safi;
12098
12099 if (name)
12100 bgp = bgp_lookup_by_name (name);
12101 else
12102 bgp = bgp_get_default ();
12103
12104 if (!bgp)
12105 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012106 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012107 return CMD_WARNING;
12108 }
12109 if (strncmp (afi_str, "ipv", 3) == 0)
12110 {
12111 if (strncmp (afi_str, "ipv4", 4) == 0)
12112 afi = AFI_IP;
12113 else if (strncmp (afi_str, "ipv6", 4) == 0)
12114 afi = AFI_IP6;
12115 else
12116 {
12117 vty_out (vty, "%% Invalid address family %s%s",
12118 afi_str, VTY_NEWLINE);
12119 return CMD_WARNING;
12120 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012121 switch (safi_str[0]) {
12122 case 'm':
12123 safi = SAFI_MULTICAST;
12124 break;
12125 case 'u':
12126 safi = SAFI_UNICAST;
12127 break;
12128 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050012129 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050012130 break;
12131 case 'e':
12132 safi = SAFI_ENCAP;
12133 break;
12134 default:
12135 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012136 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012137 return CMD_WARNING;
12138 }
Paul Jakma2815e612006-09-14 02:56:07 +000012139 }
12140 else
12141 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012142 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012143 afi_str, VTY_NEWLINE);
12144 return CMD_WARNING;
12145 }
12146
Paul Jakma2815e612006-09-14 02:56:07 +000012147 return bgp_table_stats (vty, bgp, afi, safi);
12148}
12149
12150DEFUN (show_bgp_statistics,
12151 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012152 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012153 SHOW_STR
12154 BGP_STR
12155 "Address family\n"
12156 "Address family\n"
12157 "Address Family modifier\n"
12158 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012159 "Address Family modifier\n"
12160 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012161 "BGP RIB advertisement statistics\n")
12162{
12163 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12164}
12165
Lou Bergerf9b6c392016-01-12 13:42:09 -050012166ALIAS (show_bgp_statistics,
12167 show_bgp_statistics_vpnv4_cmd,
12168 "show bgp (ipv4) (vpnv4) statistics",
12169 SHOW_STR
12170 BGP_STR
12171 "Address family\n"
12172 "Address Family modifier\n"
12173 "BGP RIB advertisement statistics\n")
12174
Paul Jakma2815e612006-09-14 02:56:07 +000012175DEFUN (show_bgp_statistics_view,
12176 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012177 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012178 SHOW_STR
12179 BGP_STR
12180 "BGP view\n"
12181 "Address family\n"
12182 "Address family\n"
12183 "Address Family modifier\n"
12184 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012185 "Address Family modifier\n"
12186 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012187 "BGP RIB advertisement statistics\n")
12188{
12189 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12190}
12191
12192ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012193 show_bgp_statistics_view_vpnv4_cmd,
12194 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012195 SHOW_STR
12196 BGP_STR
12197 "BGP view\n"
12198 "Address family\n"
12199 "Address Family modifier\n"
12200 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012201
Paul Jakmaff7924f2006-09-04 01:10:36 +000012202enum bgp_pcounts
12203{
12204 PCOUNT_ADJ_IN = 0,
12205 PCOUNT_DAMPED,
12206 PCOUNT_REMOVED,
12207 PCOUNT_HISTORY,
12208 PCOUNT_STALE,
12209 PCOUNT_VALID,
12210 PCOUNT_ALL,
12211 PCOUNT_COUNTED,
12212 PCOUNT_PFCNT, /* the figure we display to users */
12213 PCOUNT_MAX,
12214};
12215
12216static const char *pcount_strs[] =
12217{
12218 [PCOUNT_ADJ_IN] = "Adj-in",
12219 [PCOUNT_DAMPED] = "Damped",
12220 [PCOUNT_REMOVED] = "Removed",
12221 [PCOUNT_HISTORY] = "History",
12222 [PCOUNT_STALE] = "Stale",
12223 [PCOUNT_VALID] = "Valid",
12224 [PCOUNT_ALL] = "All RIB",
12225 [PCOUNT_COUNTED] = "PfxCt counted",
12226 [PCOUNT_PFCNT] = "Useable",
12227 [PCOUNT_MAX] = NULL,
12228};
12229
Paul Jakma2815e612006-09-14 02:56:07 +000012230struct peer_pcounts
12231{
12232 unsigned int count[PCOUNT_MAX];
12233 const struct peer *peer;
12234 const struct bgp_table *table;
12235};
12236
Paul Jakmaff7924f2006-09-04 01:10:36 +000012237static int
Paul Jakma2815e612006-09-14 02:56:07 +000012238bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012239{
12240 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012241 struct peer_pcounts *pc = THREAD_ARG (t);
12242 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012243
Paul Jakma2815e612006-09-14 02:56:07 +000012244 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012245 {
12246 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012247 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012248
12249 for (ain = rn->adj_in; ain; ain = ain->next)
12250 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012251 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012252
Paul Jakmaff7924f2006-09-04 01:10:36 +000012253 for (ri = rn->info; ri; ri = ri->next)
12254 {
12255 char buf[SU_ADDRSTRLEN];
12256
12257 if (ri->peer != peer)
12258 continue;
12259
Paul Jakma2815e612006-09-14 02:56:07 +000012260 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012261
12262 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012263 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012264 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012265 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012266 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012267 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012268 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012269 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012270 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012271 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012272 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012273 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012274
12275 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12276 {
Paul Jakma2815e612006-09-14 02:56:07 +000012277 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012278 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012279 plog_warn (peer->log,
12280 "%s [pcount] %s/%d is counted but flags 0x%x",
12281 peer->host,
12282 inet_ntop(rn->p.family, &rn->p.u.prefix,
12283 buf, SU_ADDRSTRLEN),
12284 rn->p.prefixlen,
12285 ri->flags);
12286 }
12287 else
12288 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012289 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012290 plog_warn (peer->log,
12291 "%s [pcount] %s/%d not counted but flags 0x%x",
12292 peer->host,
12293 inet_ntop(rn->p.family, &rn->p.u.prefix,
12294 buf, SU_ADDRSTRLEN),
12295 rn->p.prefixlen,
12296 ri->flags);
12297 }
12298 }
12299 }
Paul Jakma2815e612006-09-14 02:56:07 +000012300 return 0;
12301}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012302
Paul Jakma2815e612006-09-14 02:56:07 +000012303static int
12304bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12305{
12306 struct peer_pcounts pcounts = { .peer = peer };
12307 unsigned int i;
12308
12309 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12310 || !peer->bgp->rib[afi][safi])
12311 {
12312 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12313 return CMD_WARNING;
12314 }
12315
12316 memset (&pcounts, 0, sizeof(pcounts));
12317 pcounts.peer = peer;
12318 pcounts.table = peer->bgp->rib[afi][safi];
12319
12320 /* in-place call via thread subsystem so as to record execution time
12321 * stats for the thread-walk (i.e. ensure this can't be blamed on
12322 * on just vty_read()).
12323 */
12324 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12325
Paul Jakmaff7924f2006-09-04 01:10:36 +000012326 vty_out (vty, "Prefix counts for %s, %s%s",
12327 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12328 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12329 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12330 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12331
12332 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012333 vty_out (vty, "%20s: %-10d%s",
12334 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012335
Paul Jakma2815e612006-09-14 02:56:07 +000012336 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012337 {
12338 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12339 peer->host, VTY_NEWLINE);
12340 vty_out (vty, "Please report this bug, with the above command output%s",
12341 VTY_NEWLINE);
12342 }
12343
12344 return CMD_SUCCESS;
12345}
12346
Lou Bergerf9b6c392016-01-12 13:42:09 -050012347DEFUN (show_ip_bgp_neighbor_prefix_counts,
12348 show_ip_bgp_neighbor_prefix_counts_cmd,
12349 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12350 SHOW_STR
12351 IP_STR
12352 BGP_STR
12353 "Detailed information on TCP and BGP neighbor connections\n"
12354 "Neighbor to display information about\n"
12355 "Neighbor to display information about\n"
12356 "Display detailed prefix count information\n")
12357{
12358 struct peer *peer;
12359
12360 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12361 if (! peer)
12362 return CMD_WARNING;
12363
12364 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12365}
12366
Paul Jakmaff7924f2006-09-04 01:10:36 +000012367DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12368 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12369 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12370 SHOW_STR
12371 BGP_STR
12372 "Address family\n"
12373 "Detailed information on TCP and BGP neighbor connections\n"
12374 "Neighbor to display information about\n"
12375 "Neighbor to display information about\n"
12376 "Display detailed prefix count information\n")
12377{
12378 struct peer *peer;
12379
12380 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12381 if (! peer)
12382 return CMD_WARNING;
12383
12384 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12385}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012386
12387DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12388 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12389 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12390 SHOW_STR
12391 IP_STR
12392 BGP_STR
12393 "Address family\n"
12394 "Address Family modifier\n"
12395 "Address Family modifier\n"
12396 "Detailed information on TCP and BGP neighbor connections\n"
12397 "Neighbor to display information about\n"
12398 "Neighbor to display information about\n"
12399 "Display detailed prefix count information\n")
12400{
12401 struct peer *peer;
12402
12403 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12404 if (! peer)
12405 return CMD_WARNING;
12406
12407 if (strncmp (argv[0], "m", 1) == 0)
12408 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12409
12410 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12411}
12412
12413DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12414 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12415 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12416 SHOW_STR
12417 IP_STR
12418 BGP_STR
12419 "Address family\n"
12420 "Address Family modifier\n"
12421 "Address Family modifier\n"
12422 "Detailed information on TCP and BGP neighbor connections\n"
12423 "Neighbor to display information about\n"
12424 "Neighbor to display information about\n"
12425 "Display detailed prefix count information\n")
12426{
12427 struct peer *peer;
12428
12429 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12430 if (! peer)
12431 return CMD_WARNING;
12432
12433 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12434}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012435
Lou Berger651b4022016-01-12 13:42:07 -050012436DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12437 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12438 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012439 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012440 BGP_STR
12441 "Address family\n"
12442 "Address Family modifier\n"
12443 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012444 "Address Family modifier\n"
12445 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012446 "Detailed information on TCP and BGP neighbor connections\n"
12447 "Neighbor to display information about\n"
12448 "Neighbor to display information about\n"
12449 "Display detailed prefix count information\n")
12450{
12451 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012452 safi_t safi;
12453
12454 if (bgp_parse_safi(argv[0], &safi)) {
12455 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12456 return CMD_WARNING;
12457 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012458
12459 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12460 if (! peer)
12461 return CMD_WARNING;
12462
Lou Berger651b4022016-01-12 13:42:07 -050012463 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012464}
Lou Berger205e6742016-01-12 13:42:11 -050012465
Lou Berger651b4022016-01-12 13:42:07 -050012466DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12467 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12468 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12469 SHOW_STR
12470 BGP_STR
12471 "Address family\n"
12472 "Address Family modifier\n"
12473 "Address Family modifier\n"
12474 "Address Family modifier\n"
12475 "Address Family modifier\n"
12476 "Detailed information on TCP and BGP neighbor connections\n"
12477 "Neighbor to display information about\n"
12478 "Neighbor to display information about\n"
12479 "Display detailed prefix count information\n")
12480{
12481 struct peer *peer;
12482 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012483
Lou Berger651b4022016-01-12 13:42:07 -050012484 if (bgp_parse_safi(argv[0], &safi)) {
12485 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12486 return CMD_WARNING;
12487 }
12488
12489 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12490 if (! peer)
12491 return CMD_WARNING;
12492
12493 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12494}
Lou Berger651b4022016-01-12 13:42:07 -050012495
12496DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12497 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12498 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012499 SHOW_STR
12500 IP_STR
12501 BGP_STR
12502 "Address family\n"
12503 "Address Family modifier\n"
12504 "Address Family modifier\n"
12505 "Detailed information on TCP and BGP neighbor connections\n"
12506 "Neighbor to display information about\n"
12507 "Neighbor to display information about\n"
12508 "Display detailed prefix count information\n")
12509{
12510 struct peer *peer;
12511
12512 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12513 if (! peer)
12514 return CMD_WARNING;
12515
Lou Berger651b4022016-01-12 13:42:07 -050012516 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012517}
12518
12519
paul94f2b392005-06-28 12:44:16 +000012520static void
paul718e3742002-12-13 20:15:29 +000012521show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12522 int in)
12523{
12524 struct bgp_table *table;
12525 struct bgp_adj_in *ain;
12526 struct bgp_adj_out *adj;
12527 unsigned long output_count;
12528 struct bgp_node *rn;
12529 int header1 = 1;
12530 struct bgp *bgp;
12531 int header2 = 1;
12532
paulbb46e942003-10-24 19:02:03 +000012533 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012534
12535 if (! bgp)
12536 return;
12537
12538 table = bgp->rib[afi][safi];
12539
12540 output_count = 0;
12541
12542 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12543 PEER_STATUS_DEFAULT_ORIGINATE))
12544 {
12545 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
hasso93406d82005-02-02 14:40:33 +000012546 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12547 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012548
12549 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12550 VTY_NEWLINE, VTY_NEWLINE);
12551 header1 = 0;
12552 }
12553
12554 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12555 if (in)
12556 {
12557 for (ain = rn->adj_in; ain; ain = ain->next)
12558 if (ain->peer == peer)
12559 {
12560 if (header1)
12561 {
12562 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 +000012563 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12564 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012565 header1 = 0;
12566 }
12567 if (header2)
12568 {
12569 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12570 header2 = 0;
12571 }
12572 if (ain->attr)
12573 {
12574 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12575 output_count++;
12576 }
12577 }
12578 }
12579 else
12580 {
12581 for (adj = rn->adj_out; adj; adj = adj->next)
12582 if (adj->peer == peer)
12583 {
12584 if (header1)
12585 {
12586 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 +000012587 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12588 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012589 header1 = 0;
12590 }
12591 if (header2)
12592 {
12593 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12594 header2 = 0;
12595 }
12596 if (adj->attr)
12597 {
12598 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12599 output_count++;
12600 }
12601 }
12602 }
12603
12604 if (output_count != 0)
12605 vty_out (vty, "%sTotal number of prefixes %ld%s",
12606 VTY_NEWLINE, output_count, VTY_NEWLINE);
12607}
12608
paul94f2b392005-06-28 12:44:16 +000012609static int
paulbb46e942003-10-24 19:02:03 +000012610peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12611{
paul718e3742002-12-13 20:15:29 +000012612 if (! peer || ! peer->afc[afi][safi])
12613 {
12614 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12615 return CMD_WARNING;
12616 }
12617
12618 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12619 {
12620 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12621 VTY_NEWLINE);
12622 return CMD_WARNING;
12623 }
12624
12625 show_adj_route (vty, peer, afi, safi, in);
12626
12627 return CMD_SUCCESS;
12628}
12629
Lou Bergerf9b6c392016-01-12 13:42:09 -050012630DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12631 show_ip_bgp_view_neighbor_advertised_route_cmd,
12632 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12633 SHOW_STR
12634 IP_STR
12635 BGP_STR
12636 "BGP view\n"
12637 "View name\n"
12638 "Detailed information on TCP and BGP neighbor connections\n"
12639 "Neighbor to display information about\n"
12640 "Neighbor to display information about\n"
12641 "Display the routes advertised to a BGP neighbor\n")
12642{
12643 struct peer *peer;
12644
12645 if (argc == 2)
12646 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12647 else
12648 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12649
12650 if (! peer)
12651 return CMD_WARNING;
12652
12653 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12654}
12655
12656ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12657 show_ip_bgp_neighbor_advertised_route_cmd,
12658 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12659 SHOW_STR
12660 IP_STR
12661 BGP_STR
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
12667DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12668 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12669 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12670 SHOW_STR
12671 IP_STR
12672 BGP_STR
12673 "Address family\n"
12674 "Address Family modifier\n"
12675 "Address Family modifier\n"
12676 "Detailed information on TCP and BGP neighbor connections\n"
12677 "Neighbor to display information about\n"
12678 "Neighbor to display information about\n"
12679 "Display the routes advertised to a BGP neighbor\n")
12680{
12681 struct peer *peer;
12682
12683 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12684 if (! peer)
12685 return CMD_WARNING;
12686
12687 if (strncmp (argv[0], "m", 1) == 0)
12688 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12689
12690 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12691}
12692
Lou Bergerf9b6c392016-01-12 13:42:09 -050012693DEFUN (show_bgp_view_neighbor_advertised_route,
12694 show_bgp_view_neighbor_advertised_route_cmd,
12695 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12696 SHOW_STR
12697 BGP_STR
12698 "BGP view\n"
12699 "View name\n"
12700 "Detailed information on TCP and BGP neighbor connections\n"
12701 "Neighbor to display information about\n"
12702 "Neighbor to display information about\n"
12703 "Display the routes advertised to a BGP neighbor\n")
12704{
12705 struct peer *peer;
12706
12707 if (argc == 2)
12708 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12709 else
12710 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12711
12712 if (! peer)
12713 return CMD_WARNING;
12714
12715 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12716}
12717
12718DEFUN (show_bgp_view_neighbor_received_routes,
12719 show_bgp_view_neighbor_received_routes_cmd,
12720 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12721 SHOW_STR
12722 BGP_STR
12723 "BGP view\n"
12724 "View name\n"
12725 "Detailed information on TCP and BGP neighbor connections\n"
12726 "Neighbor to display information about\n"
12727 "Neighbor to display information about\n"
12728 "Display the received routes from neighbor\n")
12729{
12730 struct peer *peer;
12731
12732 if (argc == 2)
12733 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12734 else
12735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12736
12737 if (! peer)
12738 return CMD_WARNING;
12739
12740 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12741}
12742
12743ALIAS (show_bgp_view_neighbor_advertised_route,
12744 show_bgp_neighbor_advertised_route_cmd,
12745 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12746 SHOW_STR
12747 BGP_STR
12748 "Detailed information on TCP and BGP neighbor connections\n"
12749 "Neighbor to display information about\n"
12750 "Neighbor to display information about\n"
12751 "Display the routes advertised to a BGP neighbor\n")
12752
12753ALIAS (show_bgp_view_neighbor_advertised_route,
12754 show_bgp_ipv6_neighbor_advertised_route_cmd,
12755 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12756 SHOW_STR
12757 BGP_STR
12758 "Address family\n"
12759 "Detailed information on TCP and BGP neighbor connections\n"
12760 "Neighbor to display information about\n"
12761 "Neighbor to display information about\n"
12762 "Display the routes advertised to a BGP neighbor\n")
12763
12764/* old command */
12765ALIAS (show_bgp_view_neighbor_advertised_route,
12766 ipv6_bgp_neighbor_advertised_route_cmd,
12767 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12768 SHOW_STR
12769 IPV6_STR
12770 BGP_STR
12771 "Detailed information on TCP and BGP neighbor connections\n"
12772 "Neighbor to display information about\n"
12773 "Neighbor to display information about\n"
12774 "Display the routes advertised to a BGP neighbor\n")
12775
12776/* old command */
12777DEFUN (ipv6_mbgp_neighbor_advertised_route,
12778 ipv6_mbgp_neighbor_advertised_route_cmd,
12779 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12780 SHOW_STR
12781 IPV6_STR
12782 MBGP_STR
12783 "Detailed information on TCP and BGP neighbor connections\n"
12784 "Neighbor to display information about\n"
12785 "Neighbor to display information about\n"
12786 "Display the routes advertised to a BGP neighbor\n")
12787{
12788 struct peer *peer;
12789
12790 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12791 if (! peer)
12792 return CMD_WARNING;
12793
12794 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12795}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012796
12797DEFUN (show_ip_bgp_view_neighbor_received_routes,
12798 show_ip_bgp_view_neighbor_received_routes_cmd,
12799 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12800 SHOW_STR
12801 IP_STR
12802 BGP_STR
12803 "BGP view\n"
12804 "View name\n"
12805 "Detailed information on TCP and BGP neighbor connections\n"
12806 "Neighbor to display information about\n"
12807 "Neighbor to display information about\n"
12808 "Display the received routes from neighbor\n")
12809{
12810 struct peer *peer;
12811
12812 if (argc == 2)
12813 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12814 else
12815 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12816
12817 if (! peer)
12818 return CMD_WARNING;
12819
12820 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12821}
12822
12823ALIAS (show_ip_bgp_view_neighbor_received_routes,
12824 show_ip_bgp_neighbor_received_routes_cmd,
12825 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12826 SHOW_STR
12827 IP_STR
12828 BGP_STR
12829 "Detailed information on TCP and BGP neighbor connections\n"
12830 "Neighbor to display information about\n"
12831 "Neighbor to display information about\n"
12832 "Display the received routes from neighbor\n")
12833
12834ALIAS (show_bgp_view_neighbor_received_routes,
12835 show_bgp_ipv6_neighbor_received_routes_cmd,
12836 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12837 SHOW_STR
12838 BGP_STR
12839 "Address family\n"
12840 "Detailed information on TCP and BGP neighbor connections\n"
12841 "Neighbor to display information about\n"
12842 "Neighbor to display information about\n"
12843 "Display the received routes from neighbor\n")
12844
12845DEFUN (show_bgp_neighbor_received_prefix_filter,
12846 show_bgp_neighbor_received_prefix_filter_cmd,
12847 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12848 SHOW_STR
12849 BGP_STR
12850 "Detailed information on TCP and BGP neighbor connections\n"
12851 "Neighbor to display information about\n"
12852 "Neighbor to display information about\n"
12853 "Display information received from a BGP neighbor\n"
12854 "Display the prefixlist filter\n")
12855{
12856 char name[BUFSIZ];
12857 union sockunion su;
12858 struct peer *peer;
12859 int count, ret;
12860
12861 ret = str2sockunion (argv[0], &su);
12862 if (ret < 0)
12863 {
12864 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12865 return CMD_WARNING;
12866 }
12867
12868 peer = peer_lookup (NULL, &su);
12869 if (! peer)
12870 return CMD_WARNING;
12871
12872 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12873 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12874 if (count)
12875 {
12876 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12877 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12878 }
12879
12880 return CMD_SUCCESS;
12881}
12882
12883/* old command */
12884ALIAS (show_bgp_view_neighbor_received_routes,
12885 ipv6_bgp_neighbor_received_routes_cmd,
12886 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12887 SHOW_STR
12888 IPV6_STR
12889 BGP_STR
12890 "Detailed information on TCP and BGP neighbor connections\n"
12891 "Neighbor to display information about\n"
12892 "Neighbor to display information about\n"
12893 "Display the received routes from neighbor\n")
12894
12895/* old command */
12896DEFUN (ipv6_mbgp_neighbor_received_routes,
12897 ipv6_mbgp_neighbor_received_routes_cmd,
12898 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12899 SHOW_STR
12900 IPV6_STR
12901 MBGP_STR
12902 "Detailed information on TCP and BGP neighbor connections\n"
12903 "Neighbor to display information about\n"
12904 "Neighbor to display information about\n"
12905 "Display the received routes from neighbor\n")
12906{
12907 struct peer *peer;
12908
12909 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12910 if (! peer)
12911 return CMD_WARNING;
12912
12913 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12914}
12915
12916DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12917 show_bgp_view_neighbor_received_prefix_filter_cmd,
12918 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12919 SHOW_STR
12920 BGP_STR
12921 "BGP view\n"
12922 "View name\n"
12923 "Detailed information on TCP and BGP neighbor connections\n"
12924 "Neighbor to display information about\n"
12925 "Neighbor to display information about\n"
12926 "Display information received from a BGP neighbor\n"
12927 "Display the prefixlist filter\n")
12928{
12929 char name[BUFSIZ];
12930 union sockunion su;
12931 struct peer *peer;
12932 struct bgp *bgp;
12933 int count, ret;
12934
12935 /* BGP structure lookup. */
12936 bgp = bgp_lookup_by_name (argv[0]);
12937 if (bgp == NULL)
12938 {
12939 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12940 return CMD_WARNING;
12941 }
12942
12943 ret = str2sockunion (argv[1], &su);
12944 if (ret < 0)
12945 {
12946 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12947 return CMD_WARNING;
12948 }
12949
12950 peer = peer_lookup (bgp, &su);
12951 if (! peer)
12952 return CMD_WARNING;
12953
12954 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12955 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12956 if (count)
12957 {
12958 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12959 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12960 }
12961
12962 return CMD_SUCCESS;
12963}
12964
12965
12966DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12967 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12968 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12969 SHOW_STR
12970 IP_STR
12971 BGP_STR
12972 "Address family\n"
12973 "Address Family modifier\n"
12974 "Address Family modifier\n"
12975 "Detailed information on TCP and BGP neighbor connections\n"
12976 "Neighbor to display information about\n"
12977 "Neighbor to display information about\n"
12978 "Display the received routes from neighbor\n")
12979{
12980 struct peer *peer;
12981
12982 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12983 if (! peer)
12984 return CMD_WARNING;
12985
12986 if (strncmp (argv[0], "m", 1) == 0)
12987 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12988
12989 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12990}
12991
Lou Berger651b4022016-01-12 13:42:07 -050012992DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12993 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12994 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012995 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012996 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012997 "Address Family modifier\n"
12998 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012999 "Detailed information on TCP and BGP neighbor connections\n"
13000 "Neighbor to display information about\n"
13001 "Neighbor to display information about\n"
13002 "Display the routes advertised to a BGP neighbor\n")
13003{
13004 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013005 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013006
Lou Berger651b4022016-01-12 13:42:07 -050013007 if (bgp_parse_safi(argv[0], &safi)) {
13008 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013009 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013010 }
paul718e3742002-12-13 20:15:29 +000013011
paulbb46e942003-10-24 19:02:03 +000013012 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13013 if (! peer)
13014 return CMD_WARNING;
13015
Lou Berger651b4022016-01-12 13:42:07 -050013016 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13017}
Lou Berger205e6742016-01-12 13:42:11 -050013018
Lou Berger651b4022016-01-12 13:42:07 -050013019DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13020 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13021 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13022 SHOW_STR
13023 BGP_STR
13024 "Address Family modifier\n"
13025 "Address Family modifier\n"
13026 "Address Family modifier\n"
13027 "Detailed information on TCP and BGP neighbor connections\n"
13028 "Neighbor to display information about\n"
13029 "Neighbor to display information about\n"
13030 "Display the routes advertised to a BGP neighbor\n")
13031{
13032 struct peer *peer;
13033 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013034
Lou Berger651b4022016-01-12 13:42:07 -050013035 if (bgp_parse_safi(argv[0], &safi)) {
13036 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13037 return CMD_WARNING;
13038 }
13039
13040 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13041 if (! peer)
13042 return CMD_WARNING;
13043
13044 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000013045}
13046
Lou Bergerf9b6c392016-01-12 13:42:09 -050013047DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050013048 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
13049 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000013050 SHOW_STR
13051 BGP_STR
13052 "BGP view\n"
13053 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013054 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013055 "Detailed information on TCP and BGP neighbor connections\n"
13056 "Neighbor to display information about\n"
13057 "Neighbor to display information about\n"
13058 "Display the routes advertised to a BGP neighbor\n")
13059{
13060 struct peer *peer;
13061
13062 if (argc == 2)
13063 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13064 else
13065 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13066
13067 if (! peer)
13068 return CMD_WARNING;
13069
13070 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13071}
13072
Lou Bergerf9b6c392016-01-12 13:42:09 -050013073DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013074 show_bgp_view_ipv6_neighbor_received_routes_cmd,
13075 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000013076 SHOW_STR
13077 BGP_STR
13078 "BGP view\n"
13079 "View name\n"
13080 "Address family\n"
13081 "Detailed information on TCP and BGP neighbor connections\n"
13082 "Neighbor to display information about\n"
13083 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013084 "Display the received routes from neighbor\n")
13085{
13086 struct peer *peer;
13087
13088 if (argc == 2)
13089 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13090 else
13091 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13092
13093 if (! peer)
13094 return CMD_WARNING;
13095
13096 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13097}
Lou Berger651b4022016-01-12 13:42:07 -050013098
13099DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13100 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13101 "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 +010013102 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013103 BGP_STR
13104 "Address family\n"
13105 "Address Family modifier\n"
13106 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013107 "Address Family modifier\n"
13108 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013109 "Detailed information on TCP and BGP neighbor connections\n"
13110 "Neighbor to display information about\n"
13111 "Neighbor to display information about\n"
13112 "Display the received routes from neighbor\n")
13113{
paulbb46e942003-10-24 19:02:03 +000013114 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013115 safi_t safi;
13116
13117 if (bgp_parse_safi(argv[0], &safi)) {
13118 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13119 return CMD_WARNING;
13120 }
paul718e3742002-12-13 20:15:29 +000013121
paulbb46e942003-10-24 19:02:03 +000013122 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13123 if (! peer)
13124 return CMD_WARNING;
13125
Lou Berger651b4022016-01-12 13:42:07 -050013126 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013127}
Lou Berger205e6742016-01-12 13:42:11 -050013128
Lou Berger651b4022016-01-12 13:42:07 -050013129DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13130 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13131 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13132 SHOW_STR
13133 BGP_STR
13134 "Address family\n"
13135 "Address Family modifier\n"
13136 "Address Family modifier\n"
13137 "Address Family modifier\n"
13138 "Address Family modifier\n"
13139 "Detailed information on TCP and BGP neighbor connections\n"
13140 "Neighbor to display information about\n"
13141 "Neighbor to display information about\n"
13142 "Display the received routes from neighbor\n")
13143{
13144 struct peer *peer;
13145 safi_t safi;
13146
13147 if (bgp_parse_safi(argv[0], &safi)) {
13148 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13149 return CMD_WARNING;
13150 }
13151
13152 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13153 if (! peer)
13154 return CMD_WARNING;
13155
13156 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13157}
paul718e3742002-12-13 20:15:29 +000013158
Michael Lambert95cbbd22010-07-23 14:43:04 -040013159DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13160 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013161 "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 -040013162 SHOW_STR
13163 BGP_STR
13164 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013165 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013166 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013167 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013168 "Address family modifier\n"
13169 "Address family modifier\n"
13170 "Detailed information on TCP and BGP neighbor connections\n"
13171 "Neighbor to display information about\n"
13172 "Neighbor to display information about\n"
13173 "Display the advertised routes to neighbor\n"
13174 "Display the received routes from neighbor\n")
13175{
13176 int afi;
13177 int safi;
13178 int in;
13179 struct peer *peer;
13180
David Lamparter94bad672015-03-03 08:52:22 +010013181 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013182
13183 if (! peer)
13184 return CMD_WARNING;
13185
Michael Lambert95cbbd22010-07-23 14:43:04 -040013186 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13187 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13188 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013189
13190 return peer_adj_routes (vty, peer, afi, safi, in);
13191}
13192
Lou Bergerf9b6c392016-01-12 13:42:09 -050013193DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13194 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13195 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13196 SHOW_STR
13197 IP_STR
13198 BGP_STR
13199 "Detailed information on TCP and BGP neighbor connections\n"
13200 "Neighbor to display information about\n"
13201 "Neighbor to display information about\n"
13202 "Display information received from a BGP neighbor\n"
13203 "Display the prefixlist filter\n")
13204{
13205 char name[BUFSIZ];
13206 union sockunion su;
13207 struct peer *peer;
13208 int count, ret;
13209
13210 ret = str2sockunion (argv[0], &su);
13211 if (ret < 0)
13212 {
13213 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13214 return CMD_WARNING;
13215 }
13216
13217 peer = peer_lookup (NULL, &su);
13218 if (! peer)
13219 return CMD_WARNING;
13220
13221 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13222 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13223 if (count)
13224 {
13225 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13226 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13227 }
13228
13229 return CMD_SUCCESS;
13230}
13231
13232DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13233 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13234 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13235 SHOW_STR
13236 IP_STR
13237 BGP_STR
13238 "Address family\n"
13239 "Address Family modifier\n"
13240 "Address Family modifier\n"
13241 "Detailed information on TCP and BGP neighbor connections\n"
13242 "Neighbor to display information about\n"
13243 "Neighbor to display information about\n"
13244 "Display information received from a BGP neighbor\n"
13245 "Display the prefixlist filter\n")
13246{
13247 char name[BUFSIZ];
13248 union sockunion su;
13249 struct peer *peer;
13250 int count, ret;
13251
13252 ret = str2sockunion (argv[1], &su);
13253 if (ret < 0)
13254 {
13255 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13256 return CMD_WARNING;
13257 }
13258
13259 peer = peer_lookup (NULL, &su);
13260 if (! peer)
13261 return CMD_WARNING;
13262
13263 if (strncmp (argv[0], "m", 1) == 0)
13264 {
13265 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13266 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13267 if (count)
13268 {
13269 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13270 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13271 }
13272 }
13273 else
13274 {
13275 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13276 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13277 if (count)
13278 {
13279 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13280 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13281 }
13282 }
13283
13284 return CMD_SUCCESS;
13285}
13286
13287ALIAS (show_bgp_view_neighbor_received_routes,
13288 show_bgp_neighbor_received_routes_cmd,
13289 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13290 SHOW_STR
13291 BGP_STR
13292 "Detailed information on TCP and BGP neighbor connections\n"
13293 "Neighbor to display information about\n"
13294 "Neighbor to display information about\n"
13295 "Display the received routes from neighbor\n")
13296
Lou Berger651b4022016-01-12 13:42:07 -050013297DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13298 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13299 "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 +000013300 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013301 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013302 IP_STR
13303 "Address Family modifier\n"
13304 "Address Family modifier\n"
13305 "Address Family modifier\n"
13306 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013307 "Detailed information on TCP and BGP neighbor connections\n"
13308 "Neighbor to display information about\n"
13309 "Neighbor to display information about\n"
13310 "Display information received from a BGP neighbor\n"
13311 "Display the prefixlist filter\n")
13312{
13313 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013314 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013315 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013316 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013317 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013318
Lou Berger651b4022016-01-12 13:42:07 -050013319 if (bgp_parse_safi(argv[0], &safi)) {
13320 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013321 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013322 }
paul718e3742002-12-13 20:15:29 +000013323
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013324 ret = str2sockunion (argv[1], &su);
13325 if (ret < 0)
13326 {
13327 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13328 return CMD_WARNING;
13329 }
paul718e3742002-12-13 20:15:29 +000013330
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013331 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013332 if (! peer)
13333 return CMD_WARNING;
13334
Lou Berger651b4022016-01-12 13:42:07 -050013335 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13336 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13337 if (count) {
13338 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13339 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13340 }
paul718e3742002-12-13 20:15:29 +000013341
13342 return CMD_SUCCESS;
13343}
Lou Berger205e6742016-01-12 13:42:11 -050013344
Lou Berger651b4022016-01-12 13:42:07 -050013345DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13346 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13347 "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 +000013348 SHOW_STR
13349 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013350 IP_STR
13351 "Address Family modifier\n"
13352 "Address Family modifier\n"
13353 "Address Family modifier\n"
13354 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013355 "Detailed information on TCP and BGP neighbor connections\n"
13356 "Neighbor to display information about\n"
13357 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013358 "Display information received from a BGP neighbor\n"
13359 "Display the prefixlist filter\n")
13360{
13361 char name[BUFSIZ];
13362 union sockunion su;
13363 struct peer *peer;
13364 int count, ret;
13365 safi_t safi;
13366
13367 if (bgp_parse_safi(argv[0], &safi)) {
13368 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13369 return CMD_WARNING;
13370 }
13371
13372 ret = str2sockunion (argv[1], &su);
13373 if (ret < 0)
13374 {
13375 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13376 return CMD_WARNING;
13377 }
13378
13379 peer = peer_lookup (NULL, &su);
13380 if (! peer)
13381 return CMD_WARNING;
13382
13383 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13384 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13385 if (count) {
13386 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13387 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13388 }
13389
13390 return CMD_SUCCESS;
13391}
paul718e3742002-12-13 20:15:29 +000013392
Lou Bergerf9b6c392016-01-12 13:42:09 -050013393DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013394 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13395 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013396 SHOW_STR
13397 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013398 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013399 "Detailed information on TCP and BGP neighbor connections\n"
13400 "Neighbor to display information about\n"
13401 "Neighbor to display information about\n"
13402 "Display information received from a BGP neighbor\n"
13403 "Display the prefixlist filter\n")
13404{
13405 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013406 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013407 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013408 int count, ret;
paul718e3742002-12-13 20:15:29 +000013409
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013410 ret = str2sockunion (argv[0], &su);
13411 if (ret < 0)
13412 {
13413 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13414 return CMD_WARNING;
13415 }
paul718e3742002-12-13 20:15:29 +000013416
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013417 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013418 if (! peer)
13419 return CMD_WARNING;
13420
13421 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13422 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13423 if (count)
13424 {
13425 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13426 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13427 }
13428
13429 return CMD_SUCCESS;
13430}
13431
Lou Bergerf9b6c392016-01-12 13:42:09 -050013432DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013433 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13434 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013435 SHOW_STR
13436 BGP_STR
13437 "BGP view\n"
13438 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013439 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013440 "Detailed information on TCP and BGP neighbor connections\n"
13441 "Neighbor to display information about\n"
13442 "Neighbor to display information about\n"
13443 "Display information received from a BGP neighbor\n"
13444 "Display the prefixlist filter\n")
13445{
13446 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013447 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013448 struct peer *peer;
13449 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013450 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013451
13452 /* BGP structure lookup. */
13453 bgp = bgp_lookup_by_name (argv[0]);
13454 if (bgp == NULL)
13455 {
13456 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13457 return CMD_WARNING;
13458 }
13459
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013460 ret = str2sockunion (argv[1], &su);
13461 if (ret < 0)
13462 {
13463 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13464 return CMD_WARNING;
13465 }
paulbb46e942003-10-24 19:02:03 +000013466
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013467 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013468 if (! peer)
13469 return CMD_WARNING;
13470
13471 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13472 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13473 if (count)
13474 {
13475 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13476 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13477 }
13478
13479 return CMD_SUCCESS;
13480}
David Lamparter6b0655a2014-06-04 06:53:35 +020013481
paul94f2b392005-06-28 12:44:16 +000013482static int
paulbb46e942003-10-24 19:02:03 +000013483bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013484 safi_t safi, enum bgp_show_type type)
13485{
paul718e3742002-12-13 20:15:29 +000013486 if (! peer || ! peer->afc[afi][safi])
13487 {
13488 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013489 return CMD_WARNING;
13490 }
13491
ajs5a646652004-11-05 01:25:55 +000013492 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013493}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013494DEFUN (show_ip_bgp_neighbor_routes,
13495 show_ip_bgp_neighbor_routes_cmd,
13496 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13497 SHOW_STR
13498 IP_STR
13499 BGP_STR
13500 "Detailed information on TCP and BGP neighbor connections\n"
13501 "Neighbor to display information about\n"
13502 "Neighbor to display information about\n"
13503 "Display routes learned from neighbor\n")
13504{
13505 struct peer *peer;
13506
13507 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13508 if (! peer)
13509 return CMD_WARNING;
13510
13511 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13512 bgp_show_type_neighbor);
13513}
13514
13515DEFUN (show_ip_bgp_neighbor_flap,
13516 show_ip_bgp_neighbor_flap_cmd,
13517 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13518 SHOW_STR
13519 IP_STR
13520 BGP_STR
13521 "Detailed information on TCP and BGP neighbor connections\n"
13522 "Neighbor to display information about\n"
13523 "Neighbor to display information about\n"
13524 "Display flap statistics of the routes learned from neighbor\n")
13525{
13526 struct peer *peer;
13527
13528 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13529 if (! peer)
13530 return CMD_WARNING;
13531
13532 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13533 bgp_show_type_flap_neighbor);
13534}
13535
13536DEFUN (show_ip_bgp_neighbor_damp,
13537 show_ip_bgp_neighbor_damp_cmd,
13538 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13539 SHOW_STR
13540 IP_STR
13541 BGP_STR
13542 "Detailed information on TCP and BGP neighbor connections\n"
13543 "Neighbor to display information about\n"
13544 "Neighbor to display information about\n"
13545 "Display the dampened routes received from neighbor\n")
13546{
13547 struct peer *peer;
13548
13549 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13550 if (! peer)
13551 return CMD_WARNING;
13552
13553 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13554 bgp_show_type_damp_neighbor);
13555}
13556
13557DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13558 show_ip_bgp_ipv4_neighbor_routes_cmd,
13559 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13560 SHOW_STR
13561 IP_STR
13562 BGP_STR
13563 "Address family\n"
13564 "Address Family modifier\n"
13565 "Address Family modifier\n"
13566 "Detailed information on TCP and BGP neighbor connections\n"
13567 "Neighbor to display information about\n"
13568 "Neighbor to display information about\n"
13569 "Display routes learned from neighbor\n")
13570{
13571 struct peer *peer;
13572
13573 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13574 if (! peer)
13575 return CMD_WARNING;
13576
13577 if (strncmp (argv[0], "m", 1) == 0)
13578 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13579 bgp_show_type_neighbor);
13580
13581 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13582 bgp_show_type_neighbor);
13583}
13584
13585DEFUN (show_ip_bgp_view_rsclient,
13586 show_ip_bgp_view_rsclient_cmd,
13587 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13588 SHOW_STR
13589 IP_STR
13590 BGP_STR
13591 "BGP view\n"
13592 "View name\n"
13593 "Information about Route Server Client\n"
13594 NEIGHBOR_ADDR_STR)
13595{
13596 struct bgp_table *table;
13597 struct peer *peer;
13598
13599 if (argc == 2)
13600 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13601 else
13602 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13603
13604 if (! peer)
13605 return CMD_WARNING;
13606
13607 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13608 {
13609 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13610 VTY_NEWLINE);
13611 return CMD_WARNING;
13612 }
13613
13614 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13615 PEER_FLAG_RSERVER_CLIENT))
13616 {
13617 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13618 VTY_NEWLINE);
13619 return CMD_WARNING;
13620 }
13621
13622 table = peer->rib[AFI_IP][SAFI_UNICAST];
13623
13624 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13625}
13626
13627ALIAS (show_ip_bgp_view_rsclient,
13628 show_ip_bgp_rsclient_cmd,
13629 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13630 SHOW_STR
13631 IP_STR
13632 BGP_STR
13633 "Information about Route Server Client\n"
13634 NEIGHBOR_ADDR_STR)
13635
13636DEFUN (show_bgp_view_ipv4_safi_rsclient,
13637 show_bgp_view_ipv4_safi_rsclient_cmd,
13638 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13639 SHOW_STR
13640 BGP_STR
13641 "BGP view\n"
13642 "View name\n"
13643 "Address family\n"
13644 "Address Family modifier\n"
13645 "Address Family modifier\n"
13646 "Information about Route Server Client\n"
13647 NEIGHBOR_ADDR_STR)
13648{
13649 struct bgp_table *table;
13650 struct peer *peer;
13651 safi_t safi;
13652
13653 if (argc == 3) {
13654 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13655 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13656 } else {
13657 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13658 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13659 }
13660
13661 if (! peer)
13662 return CMD_WARNING;
13663
13664 if (! peer->afc[AFI_IP][safi])
13665 {
13666 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13667 VTY_NEWLINE);
13668 return CMD_WARNING;
13669 }
13670
13671 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13672 PEER_FLAG_RSERVER_CLIENT))
13673 {
13674 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13675 VTY_NEWLINE);
13676 return CMD_WARNING;
13677 }
13678
13679 table = peer->rib[AFI_IP][safi];
13680
13681 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13682}
13683
13684ALIAS (show_bgp_view_ipv4_safi_rsclient,
13685 show_bgp_ipv4_safi_rsclient_cmd,
13686 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13687 SHOW_STR
13688 BGP_STR
13689 "Address family\n"
13690 "Address Family modifier\n"
13691 "Address Family modifier\n"
13692 "Information about Route Server Client\n"
13693 NEIGHBOR_ADDR_STR)
13694
13695DEFUN (show_ip_bgp_view_rsclient_route,
13696 show_ip_bgp_view_rsclient_route_cmd,
13697 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13698 SHOW_STR
13699 IP_STR
13700 BGP_STR
13701 "BGP view\n"
13702 "View name\n"
13703 "Information about Route Server Client\n"
13704 NEIGHBOR_ADDR_STR
13705 "Network in the BGP routing table to display\n")
13706{
13707 struct bgp *bgp;
13708 struct peer *peer;
13709
13710 /* BGP structure lookup. */
13711 if (argc == 3)
13712 {
13713 bgp = bgp_lookup_by_name (argv[0]);
13714 if (bgp == NULL)
13715 {
13716 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13717 return CMD_WARNING;
13718 }
13719 }
13720 else
13721 {
13722 bgp = bgp_get_default ();
13723 if (bgp == NULL)
13724 {
13725 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13726 return CMD_WARNING;
13727 }
13728 }
13729
13730 if (argc == 3)
13731 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13732 else
13733 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13734
13735 if (! peer)
13736 return CMD_WARNING;
13737
13738 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13739 {
13740 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13741 VTY_NEWLINE);
13742 return CMD_WARNING;
13743}
13744
13745 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13746 PEER_FLAG_RSERVER_CLIENT))
13747 {
13748 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13749 VTY_NEWLINE);
13750 return CMD_WARNING;
13751 }
13752
13753 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13754 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013755 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050013756}
13757
13758ALIAS (show_ip_bgp_view_rsclient_route,
13759 show_ip_bgp_rsclient_route_cmd,
13760 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13761 SHOW_STR
13762 IP_STR
13763 BGP_STR
13764 "Information about Route Server Client\n"
13765 NEIGHBOR_ADDR_STR
13766 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013767
Lou Berger651b4022016-01-12 13:42:07 -050013768DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13769 show_bgp_ipv4_safi_neighbor_flap_cmd,
13770 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013771 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013772 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013773 "Address Family Modifier\n"
13774 "Address Family Modifier\n"
13775 "Address Family Modifier\n"
13776 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013777 "Detailed information on TCP and BGP neighbor connections\n"
13778 "Neighbor to display information about\n"
13779 "Neighbor to display information about\n"
13780 "Display flap statistics of the routes learned from neighbor\n")
13781{
paulbb46e942003-10-24 19:02:03 +000013782 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013783 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013784
Lou Berger651b4022016-01-12 13:42:07 -050013785 if (bgp_parse_safi(argv[0], &safi)) {
13786 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13787 return CMD_WARNING;
13788 }
13789
13790 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013791 if (! peer)
13792 return CMD_WARNING;
13793
Lou Berger651b4022016-01-12 13:42:07 -050013794 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013795 bgp_show_type_flap_neighbor);
13796}
Lou Berger205e6742016-01-12 13:42:11 -050013797
Lou Berger651b4022016-01-12 13:42:07 -050013798DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13799 show_bgp_ipv6_safi_neighbor_flap_cmd,
13800 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013801 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013802 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013803 "Address Family Modifier\n"
13804 "Address Family Modifier\n"
13805 "Address Family Modifier\n"
13806 "Address Family Modifier\n"
13807 "Detailed information on TCP and BGP neighbor connections\n"
13808 "Neighbor to display information about\n"
13809 "Neighbor to display information about\n"
13810 "Display flap statistics of the routes learned from neighbor\n")
13811{
13812 struct peer *peer;
13813 safi_t safi;
13814
13815 if (bgp_parse_safi(argv[0], &safi)) {
13816 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13817 return CMD_WARNING;
13818 }
13819
13820 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13821 if (! peer)
13822 return CMD_WARNING;
13823
13824 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13825 bgp_show_type_flap_neighbor);
13826}
Lou Berger651b4022016-01-12 13:42:07 -050013827
13828DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13829 show_bgp_ipv4_safi_neighbor_damp_cmd,
13830 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13831 SHOW_STR
13832 BGP_STR
13833 "Address Family Modifier\n"
13834 "Address Family Modifier\n"
13835 "Address Family Modifier\n"
13836 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013837 "Detailed information on TCP and BGP neighbor connections\n"
13838 "Neighbor to display information about\n"
13839 "Neighbor to display information about\n"
13840 "Display the dampened routes received from neighbor\n")
13841{
paulbb46e942003-10-24 19:02:03 +000013842 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013843 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013844
Lou Berger651b4022016-01-12 13:42:07 -050013845 if (bgp_parse_safi(argv[0], &safi)) {
13846 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13847 return CMD_WARNING;
13848 }
13849
13850 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013851 if (! peer)
13852 return CMD_WARNING;
13853
Lou Berger651b4022016-01-12 13:42:07 -050013854 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013855 bgp_show_type_damp_neighbor);
13856}
Lou Berger205e6742016-01-12 13:42:11 -050013857
Lou Berger651b4022016-01-12 13:42:07 -050013858DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13859 show_bgp_ipv6_safi_neighbor_damp_cmd,
13860 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013861 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013862 BGP_STR
13863 "Address Family Modifier\n"
13864 "Address Family Modifier\n"
13865 "Address Family Modifier\n"
13866 "Address Family Modifier\n"
13867 "Detailed information on TCP and BGP neighbor connections\n"
13868 "Neighbor to display information about\n"
13869 "Neighbor to display information about\n"
13870 "Display the dampened routes received from neighbor\n")
13871{
13872 struct peer *peer;
13873 safi_t safi;
13874
13875 if (bgp_parse_safi(argv[0], &safi)) {
13876 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13877 return CMD_WARNING;
13878 }
13879
13880 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13881 if (! peer)
13882 return CMD_WARNING;
13883
13884 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13885 bgp_show_type_damp_neighbor);
13886}
Lou Berger651b4022016-01-12 13:42:07 -050013887
13888DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13889 show_bgp_ipv4_safi_neighbor_routes_cmd,
13890 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13891 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013892 BGP_STR
13893 "Address family\n"
13894 "Address Family modifier\n"
13895 "Address Family modifier\n"
13896 "Detailed information on TCP and BGP neighbor connections\n"
13897 "Neighbor to display information about\n"
13898 "Neighbor to display information about\n"
13899 "Display routes learned from neighbor\n")
13900{
paulbb46e942003-10-24 19:02:03 +000013901 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013902 safi_t safi;
13903
13904 if (bgp_parse_safi(argv[0], &safi)) {
13905 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13906 return CMD_WARNING;
13907 }
paulbb46e942003-10-24 19:02:03 +000013908
13909 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13910 if (! peer)
13911 return CMD_WARNING;
13912
Lou Berger651b4022016-01-12 13:42:07 -050013913 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013914 bgp_show_type_neighbor);
13915}
Lou Berger205e6742016-01-12 13:42:11 -050013916
Lou Berger651b4022016-01-12 13:42:07 -050013917DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13918 show_bgp_ipv6_safi_neighbor_routes_cmd,
13919 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013920 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013921 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013922 "Address family\n"
13923 "Address Family modifier\n"
13924 "Address Family modifier\n"
13925 "Detailed information on TCP and BGP neighbor connections\n"
13926 NEIGHBOR_ADDR_STR
13927 NEIGHBOR_ADDR_STR
13928 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013929{
paulfee0f4c2004-09-13 05:12:46 +000013930 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013931 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013932
Lou Berger651b4022016-01-12 13:42:07 -050013933 if (bgp_parse_safi(argv[0], &safi)) {
13934 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13935 return CMD_WARNING;
13936 }
paulfee0f4c2004-09-13 05:12:46 +000013937
Lou Berger651b4022016-01-12 13:42:07 -050013938 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013939 if (! peer)
13940 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013941
13942 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13943 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013944}
paulfee0f4c2004-09-13 05:12:46 +000013945
Michael Lambert95cbbd22010-07-23 14:43:04 -040013946DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13947 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13948 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13949 SHOW_STR
13950 BGP_STR
13951 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013952 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013953 "Address family\n"
13954 "Address Family modifier\n"
13955 "Address Family modifier\n"
13956 "Information about Route Server Client\n"
13957 NEIGHBOR_ADDR_STR
13958 "Network in the BGP routing table to display\n")
13959{
13960 struct bgp *bgp;
13961 struct peer *peer;
13962 safi_t safi;
13963
13964 /* BGP structure lookup. */
13965 if (argc == 4)
13966 {
13967 bgp = bgp_lookup_by_name (argv[0]);
13968 if (bgp == NULL)
13969 {
13970 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13971 return CMD_WARNING;
13972 }
13973 }
13974 else
13975 {
13976 bgp = bgp_get_default ();
13977 if (bgp == NULL)
13978 {
13979 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13980 return CMD_WARNING;
13981 }
13982 }
13983
13984 if (argc == 4) {
13985 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13986 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13987 } else {
13988 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13989 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13990 }
13991
13992 if (! peer)
13993 return CMD_WARNING;
13994
13995 if (! peer->afc[AFI_IP][safi])
13996 {
13997 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13998 VTY_NEWLINE);
13999 return CMD_WARNING;
14000}
14001
14002 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14003 PEER_FLAG_RSERVER_CLIENT))
14004 {
14005 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14006 VTY_NEWLINE);
14007 return CMD_WARNING;
14008 }
14009
14010 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14011 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014012 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014013}
14014
14015ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
14016 show_bgp_ipv4_safi_rsclient_route_cmd,
14017 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14018 SHOW_STR
14019 BGP_STR
14020 "Address family\n"
14021 "Address Family modifier\n"
14022 "Address Family modifier\n"
14023 "Information about Route Server Client\n"
14024 NEIGHBOR_ADDR_STR
14025 "Network in the BGP routing table to display\n")
14026
paulfee0f4c2004-09-13 05:12:46 +000014027
Michael Lambert95cbbd22010-07-23 14:43:04 -040014028DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
14029 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
14030 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14031 SHOW_STR
14032 BGP_STR
14033 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014034 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014035 "Address family\n"
14036 "Address Family modifier\n"
14037 "Address Family modifier\n"
14038 "Information about Route Server Client\n"
14039 NEIGHBOR_ADDR_STR
14040 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14041{
14042 struct bgp *bgp;
14043 struct peer *peer;
14044 safi_t safi;
14045
14046 /* BGP structure lookup. */
14047 if (argc == 4)
14048 {
14049 bgp = bgp_lookup_by_name (argv[0]);
14050 if (bgp == NULL)
14051 {
14052 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14053 return CMD_WARNING;
14054 }
14055 }
14056 else
14057 {
14058 bgp = bgp_get_default ();
14059 if (bgp == NULL)
14060 {
14061 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14062 return CMD_WARNING;
14063 }
14064 }
14065
14066 if (argc == 4) {
14067 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14068 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14069 } else {
14070 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14071 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14072 }
14073
14074 if (! peer)
14075 return CMD_WARNING;
14076
14077 if (! peer->afc[AFI_IP][safi])
14078 {
14079 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14080 VTY_NEWLINE);
14081 return CMD_WARNING;
14082}
14083
14084 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14085 PEER_FLAG_RSERVER_CLIENT))
14086{
14087 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14088 VTY_NEWLINE);
14089 return CMD_WARNING;
14090 }
14091
14092 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14093 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014094 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014095}
14096
Lou Bergerf9b6c392016-01-12 13:42:09 -050014097DEFUN (show_ip_bgp_view_rsclient_prefix,
14098 show_ip_bgp_view_rsclient_prefix_cmd,
14099 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14100 SHOW_STR
14101 IP_STR
14102 BGP_STR
14103 "BGP view\n"
14104 "View name\n"
14105 "Information about Route Server Client\n"
14106 NEIGHBOR_ADDR_STR
14107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14108{
14109 struct bgp *bgp;
14110 struct peer *peer;
14111
14112 /* BGP structure lookup. */
14113 if (argc == 3)
14114 {
14115 bgp = bgp_lookup_by_name (argv[0]);
14116 if (bgp == NULL)
14117 {
14118 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14119 return CMD_WARNING;
14120 }
14121 }
14122 else
14123 {
14124 bgp = bgp_get_default ();
14125 if (bgp == NULL)
14126 {
14127 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14128 return CMD_WARNING;
14129 }
14130 }
14131
14132 if (argc == 3)
14133 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14134 else
14135 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14136
14137 if (! peer)
14138 return CMD_WARNING;
14139
14140 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14141 {
14142 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14143 VTY_NEWLINE);
14144 return CMD_WARNING;
14145}
14146
14147 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14148 PEER_FLAG_RSERVER_CLIENT))
14149{
14150 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14151 VTY_NEWLINE);
14152 return CMD_WARNING;
14153 }
14154
14155 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14156 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014157 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014158}
14159
14160ALIAS (show_ip_bgp_view_rsclient_prefix,
14161 show_ip_bgp_rsclient_prefix_cmd,
14162 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14163 SHOW_STR
14164 IP_STR
14165 BGP_STR
14166 "Information about Route Server Client\n"
14167 NEIGHBOR_ADDR_STR
14168 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14169
Michael Lambert95cbbd22010-07-23 14:43:04 -040014170ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14171 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14172 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14173 SHOW_STR
14174 BGP_STR
14175 "Address family\n"
14176 "Address Family modifier\n"
14177 "Address Family modifier\n"
14178 "Information about Route Server Client\n"
14179 NEIGHBOR_ADDR_STR
14180 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014181
Lou Bergerf9b6c392016-01-12 13:42:09 -050014182DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014183 show_bgp_view_ipv6_neighbor_routes_cmd,
14184 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014185 SHOW_STR
14186 BGP_STR
14187 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014188 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014189 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014190 "Detailed information on TCP and BGP neighbor connections\n"
14191 "Neighbor to display information about\n"
14192 "Neighbor to display information about\n"
14193 "Display routes learned from neighbor\n")
14194{
14195 struct peer *peer;
14196
14197 if (argc == 2)
14198 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14199 else
14200 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14201
14202 if (! peer)
14203 return CMD_WARNING;
14204
14205 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14206 bgp_show_type_neighbor);
14207}
14208
Lou Berger651b4022016-01-12 13:42:07 -050014209DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014210 show_bgp_view_neighbor_damp_cmd,
14211 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14212 SHOW_STR
14213 BGP_STR
14214 "BGP view\n"
14215 "View name\n"
14216 "Detailed information on TCP and BGP neighbor connections\n"
14217 "Neighbor to display information about\n"
14218 "Neighbor to display information about\n"
14219 "Display the dampened routes received from neighbor\n")
14220{
14221 struct peer *peer;
14222
14223 if (argc == 2)
14224 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14225 else
14226 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14227
14228 if (! peer)
14229 return CMD_WARNING;
14230
14231 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14232 bgp_show_type_damp_neighbor);
14233}
14234
14235DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014236 show_bgp_view_ipv6_neighbor_damp_cmd,
14237 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014238 SHOW_STR
14239 BGP_STR
14240 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014241 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014242 "Address family\n"
14243 "Detailed information on TCP and BGP neighbor connections\n"
14244 "Neighbor to display information about\n"
14245 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014246 "Display the dampened routes received from neighbor\n")
14247{
14248 struct peer *peer;
14249
14250 if (argc == 2)
14251 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14252 else
14253 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14254
14255 if (! peer)
14256 return CMD_WARNING;
14257
14258 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14259 bgp_show_type_damp_neighbor);
14260}
14261
Lou Bergerf9b6c392016-01-12 13:42:09 -050014262DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014263 show_bgp_view_ipv6_neighbor_flap_cmd,
14264 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014265 SHOW_STR
14266 BGP_STR
14267 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014268 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014269 "Address family\n"
14270 "Detailed information on TCP and BGP neighbor connections\n"
14271 "Neighbor to display information about\n"
14272 "Neighbor to display information about\n"
14273 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014274{
14275 struct peer *peer;
14276
14277 if (argc == 2)
14278 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14279 else
14280 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14281
14282 if (! peer)
14283 return CMD_WARNING;
14284
14285 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14286 bgp_show_type_flap_neighbor);
14287}
14288
Lou Bergerf9b6c392016-01-12 13:42:09 -050014289DEFUN (show_bgp_view_neighbor_flap,
14290 show_bgp_view_neighbor_flap_cmd,
14291 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14292 SHOW_STR
14293 BGP_STR
14294 "BGP view\n"
14295 "View name\n"
14296 "Detailed information on TCP and BGP neighbor connections\n"
14297 "Neighbor to display information about\n"
14298 "Neighbor to display information about\n"
14299 "Display flap statistics of the routes learned from neighbor\n")
14300{
14301 struct peer *peer;
14302
14303 if (argc == 2)
14304 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14305 else
14306 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14307
14308 if (! peer)
14309 return CMD_WARNING;
14310
14311 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14312 bgp_show_type_flap_neighbor);
14313}
14314
14315ALIAS (show_bgp_view_neighbor_flap,
14316 show_bgp_neighbor_flap_cmd,
14317 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14318 SHOW_STR
14319 BGP_STR
14320 "Detailed information on TCP and BGP neighbor connections\n"
14321 "Neighbor to display information about\n"
14322 "Neighbor to display information about\n"
14323 "Display flap statistics of the routes learned from neighbor\n")
14324
14325ALIAS (show_bgp_view_neighbor_damp,
14326 show_bgp_neighbor_damp_cmd,
14327 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14328 SHOW_STR
14329 BGP_STR
14330 "Detailed information on TCP and BGP neighbor connections\n"
14331 "Neighbor to display information about\n"
14332 "Neighbor to display information about\n"
14333 "Display the dampened routes received from neighbor\n")
14334
14335DEFUN (show_bgp_view_neighbor_routes,
14336 show_bgp_view_neighbor_routes_cmd,
14337 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14338 SHOW_STR
14339 BGP_STR
14340 "BGP view\n"
14341 "View name\n"
14342 "Detailed information on TCP and BGP neighbor connections\n"
14343 "Neighbor to display information about\n"
14344 "Neighbor to display information about\n"
14345 "Display routes learned from neighbor\n")
14346{
14347 struct peer *peer;
14348
14349 if (argc == 2)
14350 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14351 else
14352 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14353
14354 if (! peer)
14355 return CMD_WARNING;
14356
14357 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14358 bgp_show_type_neighbor);
14359}
14360
14361ALIAS (show_bgp_view_neighbor_routes,
14362 show_bgp_neighbor_routes_cmd,
14363 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14364 SHOW_STR
14365 BGP_STR
14366 "Detailed information on TCP and BGP neighbor connections\n"
14367 "Neighbor to display information about\n"
14368 "Neighbor to display information about\n"
14369 "Display routes learned from neighbor\n")
14370
paulbb46e942003-10-24 19:02:03 +000014371ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014372 show_bgp_ipv6_neighbor_routes_cmd,
14373 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14374 SHOW_STR
14375 BGP_STR
14376 "Address family\n"
14377 "Detailed information on TCP and BGP neighbor connections\n"
14378 "Neighbor to display information about\n"
14379 "Neighbor to display information about\n"
14380 "Display routes learned from neighbor\n")
14381
Lou Bergerf9b6c392016-01-12 13:42:09 -050014382/* old command */
14383ALIAS (show_bgp_view_neighbor_routes,
14384 ipv6_bgp_neighbor_routes_cmd,
14385 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14386 SHOW_STR
14387 IPV6_STR
14388 BGP_STR
14389 "Detailed information on TCP and BGP neighbor connections\n"
14390 "Neighbor to display information about\n"
14391 "Neighbor to display information about\n"
14392 "Display routes learned from neighbor\n")
14393
14394/* old command */
14395DEFUN (ipv6_mbgp_neighbor_routes,
14396 ipv6_mbgp_neighbor_routes_cmd,
14397 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14398 SHOW_STR
14399 IPV6_STR
14400 MBGP_STR
14401 "Detailed information on TCP and BGP neighbor connections\n"
14402 "Neighbor to display information about\n"
14403 "Neighbor to display information about\n"
14404 "Display routes learned from neighbor\n")
14405{
14406 struct peer *peer;
14407
14408 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14409 if (! peer)
14410 return CMD_WARNING;
14411
14412 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14413 bgp_show_type_neighbor);
14414}
14415
paulbb46e942003-10-24 19:02:03 +000014416ALIAS (show_bgp_view_neighbor_flap,
14417 show_bgp_ipv6_neighbor_flap_cmd,
14418 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14419 SHOW_STR
14420 BGP_STR
14421 "Address family\n"
14422 "Detailed information on TCP and BGP neighbor connections\n"
14423 "Neighbor to display information about\n"
14424 "Neighbor to display information about\n"
14425 "Display flap statistics of the routes learned from neighbor\n")
14426
14427ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014428 show_bgp_ipv6_neighbor_damp_cmd,
14429 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14430 SHOW_STR
14431 BGP_STR
14432 "Address family\n"
14433 "Detailed information on TCP and BGP neighbor connections\n"
14434 "Neighbor to display information about\n"
14435 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014436 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014437
Lou Bergerf9b6c392016-01-12 13:42:09 -050014438DEFUN (show_bgp_view_rsclient,
14439 show_bgp_view_rsclient_cmd,
14440 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14441 SHOW_STR
14442 BGP_STR
14443 "BGP view\n"
14444 "View name\n"
14445 "Information about Route Server Client\n"
14446 NEIGHBOR_ADDR_STR)
14447{
14448 struct bgp_table *table;
14449 struct peer *peer;
14450
14451 if (argc == 2)
14452 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14453 else
14454 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14455
14456 if (! peer)
14457 return CMD_WARNING;
14458
14459 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14460 {
14461 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14462 VTY_NEWLINE);
14463 return CMD_WARNING;
14464 }
14465
14466 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14467 PEER_FLAG_RSERVER_CLIENT))
14468 {
14469 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14470 VTY_NEWLINE);
14471 return CMD_WARNING;
14472 }
14473
14474 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14475
14476 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14477}
14478
14479ALIAS (show_bgp_view_rsclient,
14480 show_bgp_rsclient_cmd,
14481 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14482 SHOW_STR
14483 BGP_STR
14484 "Information about Route Server Client\n"
14485 NEIGHBOR_ADDR_STR)
14486
Lou Berger651b4022016-01-12 13:42:07 -050014487DEFUN (show_bgp_view_ipv4_rsclient,
14488 show_bgp_view_ipv4_rsclient_cmd,
14489 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014490 SHOW_STR
14491 BGP_STR
14492 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014493 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014494 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014495 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014496 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014497{
Lou Berger651b4022016-01-12 13:42:07 -050014498 struct bgp_table *table;
14499 struct peer *peer;
14500
14501 if (argc == 2)
14502 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14503 else
14504 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14505
14506 if (! peer)
14507 return CMD_WARNING;
14508
14509 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14510 {
14511 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14512 VTY_NEWLINE);
14513 return CMD_WARNING;
14514 }
14515
14516 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14517 PEER_FLAG_RSERVER_CLIENT))
14518 {
14519 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14520 VTY_NEWLINE);
14521 return CMD_WARNING;
14522 }
14523
14524 table = peer->rib[AFI_IP][SAFI_UNICAST];
14525
14526 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14527}
14528DEFUN (show_bgp_view_ipv6_rsclient,
14529 show_bgp_view_ipv6_rsclient_cmd,
14530 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14531 SHOW_STR
14532 BGP_STR
14533 "BGP view\n"
14534 "BGP view name\n"
14535 "Address Family\n"
14536 "Information about Route Server Client\n"
14537 NEIGHBOR_ADDR_STR2)
14538{
14539 struct bgp_table *table;
14540 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014541
14542 if (argc == 2)
14543 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14544 else
14545 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14546
14547 if (! peer)
14548 return CMD_WARNING;
14549
14550 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14551 {
14552 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14553 VTY_NEWLINE);
14554 return CMD_WARNING;
14555 }
14556
14557 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14558 PEER_FLAG_RSERVER_CLIENT))
14559 {
14560 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14561 VTY_NEWLINE);
14562 return CMD_WARNING;
14563 }
14564
14565 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14566
ajs5a646652004-11-05 01:25:55 +000014567 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014568}
14569
Lou Berger651b4022016-01-12 13:42:07 -050014570ALIAS (show_bgp_view_ipv4_rsclient,
14571 show_bgp_ipv4_rsclient_cmd,
14572 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014573 SHOW_STR
14574 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014575 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014576 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014577 NEIGHBOR_ADDR_STR2)
14578
Lou Berger651b4022016-01-12 13:42:07 -050014579ALIAS (show_bgp_view_ipv6_rsclient,
14580 show_bgp_ipv6_rsclient_cmd,
14581 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14582 SHOW_STR
14583 BGP_STR
14584 "Address Family\n"
14585 "Information about Route Server Client\n"
14586 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014587
Michael Lambert95cbbd22010-07-23 14:43:04 -040014588DEFUN (show_bgp_view_ipv6_safi_rsclient,
14589 show_bgp_view_ipv6_safi_rsclient_cmd,
14590 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14591 SHOW_STR
14592 BGP_STR
14593 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014594 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014595 "Address family\n"
14596 "Address Family modifier\n"
14597 "Address Family modifier\n"
14598 "Information about Route Server Client\n"
14599 NEIGHBOR_ADDR_STR)
14600{
14601 struct bgp_table *table;
14602 struct peer *peer;
14603 safi_t safi;
14604
14605 if (argc == 3) {
14606 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14607 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14608 } else {
14609 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14610 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14611 }
14612
14613 if (! peer)
14614 return CMD_WARNING;
14615
14616 if (! peer->afc[AFI_IP6][safi])
14617 {
14618 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14619 VTY_NEWLINE);
14620 return CMD_WARNING;
14621 }
14622
14623 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14624 PEER_FLAG_RSERVER_CLIENT))
14625 {
14626 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14627 VTY_NEWLINE);
14628 return CMD_WARNING;
14629 }
14630
14631 table = peer->rib[AFI_IP6][safi];
14632
14633 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14634}
14635
14636ALIAS (show_bgp_view_ipv6_safi_rsclient,
14637 show_bgp_ipv6_safi_rsclient_cmd,
14638 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14639 SHOW_STR
14640 BGP_STR
14641 "Address family\n"
14642 "Address Family modifier\n"
14643 "Address Family modifier\n"
14644 "Information about Route Server Client\n"
14645 NEIGHBOR_ADDR_STR)
14646
paulfee0f4c2004-09-13 05:12:46 +000014647DEFUN (show_bgp_view_rsclient_route,
14648 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014649 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14650 SHOW_STR
14651 BGP_STR
14652 "BGP view\n"
14653 "View name\n"
14654 "Information about Route Server Client\n"
14655 NEIGHBOR_ADDR_STR
14656 "Network in the BGP routing table to display\n")
14657{
14658 struct bgp *bgp;
14659 struct peer *peer;
14660
14661 /* BGP structure lookup. */
14662 if (argc == 3)
14663 {
14664 bgp = bgp_lookup_by_name (argv[0]);
14665 if (bgp == NULL)
14666 {
14667 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14668 return CMD_WARNING;
14669 }
14670 }
14671 else
14672 {
14673 bgp = bgp_get_default ();
14674 if (bgp == NULL)
14675 {
14676 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14677 return CMD_WARNING;
14678 }
14679 }
14680
14681 if (argc == 3)
14682 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14683 else
14684 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14685
14686 if (! peer)
14687 return CMD_WARNING;
14688
14689 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14690 {
14691 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14692 VTY_NEWLINE);
14693 return CMD_WARNING;
14694 }
14695
14696 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14697 PEER_FLAG_RSERVER_CLIENT))
14698 {
14699 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14700 VTY_NEWLINE);
14701 return CMD_WARNING;
14702 }
14703
14704 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14705 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014706 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014707}
14708
14709DEFUN (show_bgp_view_ipv6_rsclient_route,
14710 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014711 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014712 SHOW_STR
14713 BGP_STR
14714 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014715 "BGP view name\n"
14716 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014717 "Information about Route Server Client\n"
14718 NEIGHBOR_ADDR_STR
14719 "Network in the BGP routing table to display\n")
14720{
14721 struct bgp *bgp;
14722 struct peer *peer;
14723
14724 /* BGP structure lookup. */
14725 if (argc == 3)
14726 {
14727 bgp = bgp_lookup_by_name (argv[0]);
14728 if (bgp == NULL)
14729 {
14730 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14731 return CMD_WARNING;
14732 }
14733 }
14734 else
14735 {
14736 bgp = bgp_get_default ();
14737 if (bgp == NULL)
14738 {
14739 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14740 return CMD_WARNING;
14741 }
14742 }
14743
14744 if (argc == 3)
14745 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14746 else
14747 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14748
14749 if (! peer)
14750 return CMD_WARNING;
14751
14752 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14753 {
14754 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14755 VTY_NEWLINE);
14756 return CMD_WARNING;
14757 }
14758
14759 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14760 PEER_FLAG_RSERVER_CLIENT))
14761 {
14762 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14763 VTY_NEWLINE);
14764 return CMD_WARNING;
14765 }
14766
14767 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14768 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014769 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014770}
14771
Lou Bergerf9b6c392016-01-12 13:42:09 -050014772ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014773 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014774 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14775 SHOW_STR
14776 BGP_STR
14777 "Information about Route Server Client\n"
14778 NEIGHBOR_ADDR_STR
14779 "Network in the BGP routing table to display\n")
14780
14781ALIAS (show_bgp_view_ipv6_rsclient_route,
14782 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014783 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014784 SHOW_STR
14785 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014786 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014787 "Information about Route Server Client\n"
14788 NEIGHBOR_ADDR_STR
14789 "Network in the BGP routing table to display\n")
14790
Michael Lambert95cbbd22010-07-23 14:43:04 -040014791DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14792 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14793 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14794 SHOW_STR
14795 BGP_STR
14796 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014797 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014798 "Address family\n"
14799 "Address Family modifier\n"
14800 "Address Family modifier\n"
14801 "Information about Route Server Client\n"
14802 NEIGHBOR_ADDR_STR
14803 "Network in the BGP routing table to display\n")
14804{
14805 struct bgp *bgp;
14806 struct peer *peer;
14807 safi_t safi;
14808
14809 /* BGP structure lookup. */
14810 if (argc == 4)
14811 {
14812 bgp = bgp_lookup_by_name (argv[0]);
14813 if (bgp == NULL)
14814 {
14815 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14816 return CMD_WARNING;
14817 }
14818 }
14819 else
14820 {
14821 bgp = bgp_get_default ();
14822 if (bgp == NULL)
14823 {
14824 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14825 return CMD_WARNING;
14826 }
14827 }
14828
14829 if (argc == 4) {
14830 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14831 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14832 } else {
14833 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14834 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14835 }
14836
14837 if (! peer)
14838 return CMD_WARNING;
14839
14840 if (! peer->afc[AFI_IP6][safi])
14841 {
14842 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14843 VTY_NEWLINE);
14844 return CMD_WARNING;
14845}
14846
14847 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14848 PEER_FLAG_RSERVER_CLIENT))
14849 {
14850 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14851 VTY_NEWLINE);
14852 return CMD_WARNING;
14853 }
14854
14855 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14856 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014857 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014858}
14859
14860ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14861 show_bgp_ipv6_safi_rsclient_route_cmd,
14862 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14863 SHOW_STR
14864 BGP_STR
14865 "Address family\n"
14866 "Address Family modifier\n"
14867 "Address Family modifier\n"
14868 "Information about Route Server Client\n"
14869 NEIGHBOR_ADDR_STR
14870 "Network in the BGP routing table to display\n")
14871
Lou Berger651b4022016-01-12 13:42:07 -050014872
paulfee0f4c2004-09-13 05:12:46 +000014873DEFUN (show_bgp_view_rsclient_prefix,
14874 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014875 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14876 SHOW_STR
14877 BGP_STR
14878 "BGP view\n"
14879 "View name\n"
14880 "Information about Route Server Client\n"
14881 NEIGHBOR_ADDR_STR
14882 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14883{
14884 struct bgp *bgp;
14885 struct peer *peer;
14886
14887 /* BGP structure lookup. */
14888 if (argc == 3)
14889 {
14890 bgp = bgp_lookup_by_name (argv[0]);
14891 if (bgp == NULL)
14892 {
14893 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14894 return CMD_WARNING;
14895 }
14896 }
14897 else
14898 {
14899 bgp = bgp_get_default ();
14900 if (bgp == NULL)
14901 {
14902 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14903 return CMD_WARNING;
14904 }
14905 }
14906
14907 if (argc == 3)
14908 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14909 else
14910 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14911
14912 if (! peer)
14913 return CMD_WARNING;
14914
14915 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14916 {
14917 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14918 VTY_NEWLINE);
14919 return CMD_WARNING;
14920 }
14921
14922 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14923 PEER_FLAG_RSERVER_CLIENT))
14924 {
14925 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14926 VTY_NEWLINE);
14927 return CMD_WARNING;
14928 }
14929
14930 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14931 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014932 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014933}
14934
14935DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14936 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014937 "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 +000014938 SHOW_STR
14939 BGP_STR
14940 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014941 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014942 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014943 "Information about Route Server Client\n"
14944 NEIGHBOR_ADDR_STR
14945 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14946{
14947 struct bgp *bgp;
14948 struct peer *peer;
14949
14950 /* BGP structure lookup. */
14951 if (argc == 3)
14952 {
14953 bgp = bgp_lookup_by_name (argv[0]);
14954 if (bgp == NULL)
14955 {
14956 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14957 return CMD_WARNING;
14958 }
14959 }
14960 else
14961 {
14962 bgp = bgp_get_default ();
14963 if (bgp == NULL)
14964 {
14965 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14966 return CMD_WARNING;
14967 }
14968 }
14969
14970 if (argc == 3)
14971 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14972 else
14973 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14974
14975 if (! peer)
14976 return CMD_WARNING;
14977
14978 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14979 {
14980 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14981 VTY_NEWLINE);
14982 return CMD_WARNING;
14983 }
14984
14985 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14986 PEER_FLAG_RSERVER_CLIENT))
14987 {
14988 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14989 VTY_NEWLINE);
14990 return CMD_WARNING;
14991 }
14992
14993 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14994 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014995 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014996}
14997
Lou Bergerf9b6c392016-01-12 13:42:09 -050014998ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014999 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050015000 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15001 SHOW_STR
15002 BGP_STR
15003 "Information about Route Server Client\n"
15004 NEIGHBOR_ADDR_STR
15005 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15006
15007ALIAS (show_bgp_view_ipv6_rsclient_prefix,
15008 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050015009 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000015010 SHOW_STR
15011 BGP_STR
15012 "Information about Route Server Client\n"
15013 NEIGHBOR_ADDR_STR
15014 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15015
Michael Lambert95cbbd22010-07-23 14:43:04 -040015016DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15017 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15018 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15019 SHOW_STR
15020 BGP_STR
15021 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000015022 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040015023 "Address family\n"
15024 "Address Family modifier\n"
15025 "Address Family modifier\n"
15026 "Information about Route Server Client\n"
15027 NEIGHBOR_ADDR_STR
15028 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15029{
15030 struct bgp *bgp;
15031 struct peer *peer;
15032 safi_t safi;
15033
15034 /* BGP structure lookup. */
15035 if (argc == 4)
15036 {
15037 bgp = bgp_lookup_by_name (argv[0]);
15038 if (bgp == NULL)
15039 {
15040 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15041 return CMD_WARNING;
15042 }
15043 }
15044 else
15045 {
15046 bgp = bgp_get_default ();
15047 if (bgp == NULL)
15048 {
15049 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15050 return CMD_WARNING;
15051 }
15052 }
15053
15054 if (argc == 4) {
15055 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15056 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15057 } else {
15058 peer = peer_lookup_in_view (vty, NULL, argv[1]);
15059 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15060 }
15061
15062 if (! peer)
15063 return CMD_WARNING;
15064
15065 if (! peer->afc[AFI_IP6][safi])
15066 {
15067 vty_out (vty, "%% Activate the neighbor for the address family first%s",
15068 VTY_NEWLINE);
15069 return CMD_WARNING;
15070}
15071
15072 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15073 PEER_FLAG_RSERVER_CLIENT))
15074{
15075 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15076 VTY_NEWLINE);
15077 return CMD_WARNING;
15078 }
15079
15080 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15081 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070015082 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040015083}
15084
15085ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15086 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15087 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15088 SHOW_STR
15089 BGP_STR
15090 "Address family\n"
15091 "Address Family modifier\n"
15092 "Address Family modifier\n"
15093 "Information about Route Server Client\n"
15094 NEIGHBOR_ADDR_STR
15095 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15096
paul718e3742002-12-13 20:15:29 +000015097struct bgp_table *bgp_distance_table;
15098
15099struct bgp_distance
15100{
15101 /* Distance value for the IP source prefix. */
15102 u_char distance;
15103
15104 /* Name of the access-list to be matched. */
15105 char *access_list;
15106};
15107
paul94f2b392005-06-28 12:44:16 +000015108static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015109bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015110{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015111 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015112}
15113
paul94f2b392005-06-28 12:44:16 +000015114static void
paul718e3742002-12-13 20:15:29 +000015115bgp_distance_free (struct bgp_distance *bdistance)
15116{
15117 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15118}
15119
paul94f2b392005-06-28 12:44:16 +000015120static int
paulfd79ac92004-10-13 05:06:08 +000015121bgp_distance_set (struct vty *vty, const char *distance_str,
15122 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015123{
15124 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015125 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015126 u_char distance;
15127 struct bgp_node *rn;
15128 struct bgp_distance *bdistance;
15129
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015130 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015131 if (ret == 0)
15132 {
15133 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15134 return CMD_WARNING;
15135 }
15136
15137 distance = atoi (distance_str);
15138
15139 /* Get BGP distance node. */
15140 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15141 if (rn->info)
15142 {
15143 bdistance = rn->info;
15144 bgp_unlock_node (rn);
15145 }
15146 else
15147 {
15148 bdistance = bgp_distance_new ();
15149 rn->info = bdistance;
15150 }
15151
15152 /* Set distance value. */
15153 bdistance->distance = distance;
15154
15155 /* Reset access-list configuration. */
15156 if (bdistance->access_list)
15157 {
15158 free (bdistance->access_list);
15159 bdistance->access_list = NULL;
15160 }
15161 if (access_list_str)
15162 bdistance->access_list = strdup (access_list_str);
15163
15164 return CMD_SUCCESS;
15165}
15166
paul94f2b392005-06-28 12:44:16 +000015167static int
paulfd79ac92004-10-13 05:06:08 +000015168bgp_distance_unset (struct vty *vty, const char *distance_str,
15169 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015170{
15171 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015172 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015173 u_char distance;
15174 struct bgp_node *rn;
15175 struct bgp_distance *bdistance;
15176
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015177 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015178 if (ret == 0)
15179 {
15180 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15181 return CMD_WARNING;
15182 }
15183
15184 distance = atoi (distance_str);
15185
15186 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15187 if (! rn)
15188 {
15189 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15190 return CMD_WARNING;
15191 }
15192
15193 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015194
15195 if (bdistance->distance != distance)
15196 {
15197 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15198 return CMD_WARNING;
15199 }
15200
paul718e3742002-12-13 20:15:29 +000015201 if (bdistance->access_list)
15202 free (bdistance->access_list);
15203 bgp_distance_free (bdistance);
15204
15205 rn->info = NULL;
15206 bgp_unlock_node (rn);
15207 bgp_unlock_node (rn);
15208
15209 return CMD_SUCCESS;
15210}
15211
paul718e3742002-12-13 20:15:29 +000015212/* Apply BGP information to distance method. */
15213u_char
15214bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15215{
15216 struct bgp_node *rn;
15217 struct prefix_ipv4 q;
15218 struct peer *peer;
15219 struct bgp_distance *bdistance;
15220 struct access_list *alist;
15221 struct bgp_static *bgp_static;
15222
15223 if (! bgp)
15224 return 0;
15225
15226 if (p->family != AF_INET)
15227 return 0;
15228
15229 peer = rinfo->peer;
15230
15231 if (peer->su.sa.sa_family != AF_INET)
15232 return 0;
15233
15234 memset (&q, 0, sizeof (struct prefix_ipv4));
15235 q.family = AF_INET;
15236 q.prefix = peer->su.sin.sin_addr;
15237 q.prefixlen = IPV4_MAX_BITLEN;
15238
15239 /* Check source address. */
15240 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15241 if (rn)
15242 {
15243 bdistance = rn->info;
15244 bgp_unlock_node (rn);
15245
15246 if (bdistance->access_list)
15247 {
15248 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15249 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15250 return bdistance->distance;
15251 }
15252 else
15253 return bdistance->distance;
15254 }
15255
15256 /* Backdoor check. */
15257 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15258 if (rn)
15259 {
15260 bgp_static = rn->info;
15261 bgp_unlock_node (rn);
15262
15263 if (bgp_static->backdoor)
15264 {
15265 if (bgp->distance_local)
15266 return bgp->distance_local;
15267 else
15268 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15269 }
15270 }
15271
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015272 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015273 {
15274 if (bgp->distance_ebgp)
15275 return bgp->distance_ebgp;
15276 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15277 }
15278 else
15279 {
15280 if (bgp->distance_ibgp)
15281 return bgp->distance_ibgp;
15282 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15283 }
15284}
15285
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015286#ifdef HAVE_IPV6
15287/* Apply BGP information to ipv6 distance method. */
15288u_char
15289ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15290{
15291 struct bgp_node *rn;
15292 struct prefix_ipv6 q;
15293 struct peer *peer;
15294 struct bgp_distance *bdistance;
15295 struct access_list *alist;
15296 struct bgp_static *bgp_static;
15297
15298 if (! bgp)
15299 return 0;
15300
15301 if (p->family != AF_INET6)
15302 return 0;
15303
15304 peer = rinfo->peer;
15305
15306 if (peer->su.sa.sa_family != AF_INET6)
15307 return 0;
15308
15309 memset (&q, 0, sizeof (struct prefix_ipv6));
15310 q.family = AF_INET;
15311 q.prefix = peer->su.sin6.sin6_addr;
15312 q.prefixlen = IPV6_MAX_BITLEN;
15313
15314 /* Check source address. */
15315 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15316 if (rn)
15317 {
15318 bdistance = rn->info;
15319 bgp_unlock_node (rn);
15320
15321 if (bdistance->access_list)
15322 {
15323 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15324 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15325 return bdistance->distance;
15326 }
15327 else
15328 return bdistance->distance;
15329 }
15330 /* Backdoor check. */
15331 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15332 if (rn)
15333 {
15334 bgp_static = rn->info;
15335 bgp_unlock_node (rn);
15336
15337 if (bgp_static->backdoor)
15338 {
15339 if (bgp->ipv6_distance_local)
15340 return bgp->ipv6_distance_local;
15341 else
15342 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15343 }
15344 }
15345
15346 if (peer_sort (peer) == BGP_PEER_EBGP)
15347 {
15348 if (bgp->ipv6_distance_ebgp)
15349 return bgp->ipv6_distance_ebgp;
15350 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15351 }
15352 else
15353 {
15354 if (bgp->ipv6_distance_ibgp)
15355 return bgp->ipv6_distance_ibgp;
15356 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15357 }
15358}
15359#endif /* HAVE_IPV6 */
15360
paul718e3742002-12-13 20:15:29 +000015361DEFUN (bgp_distance,
15362 bgp_distance_cmd,
15363 "distance bgp <1-255> <1-255> <1-255>",
15364 "Define an administrative distance\n"
15365 "BGP distance\n"
15366 "Distance for routes external to the AS\n"
15367 "Distance for routes internal to the AS\n"
15368 "Distance for local routes\n")
15369{
15370 struct bgp *bgp;
15371
15372 bgp = vty->index;
15373
15374 bgp->distance_ebgp = atoi (argv[0]);
15375 bgp->distance_ibgp = atoi (argv[1]);
15376 bgp->distance_local = atoi (argv[2]);
15377 return CMD_SUCCESS;
15378}
15379
15380DEFUN (no_bgp_distance,
15381 no_bgp_distance_cmd,
15382 "no distance bgp <1-255> <1-255> <1-255>",
15383 NO_STR
15384 "Define an administrative distance\n"
15385 "BGP distance\n"
15386 "Distance for routes external to the AS\n"
15387 "Distance for routes internal to the AS\n"
15388 "Distance for local routes\n")
15389{
15390 struct bgp *bgp;
15391
15392 bgp = vty->index;
15393
15394 bgp->distance_ebgp= 0;
15395 bgp->distance_ibgp = 0;
15396 bgp->distance_local = 0;
15397 return CMD_SUCCESS;
15398}
15399
15400ALIAS (no_bgp_distance,
15401 no_bgp_distance2_cmd,
15402 "no distance bgp",
15403 NO_STR
15404 "Define an administrative distance\n"
15405 "BGP distance\n")
15406
15407DEFUN (bgp_distance_source,
15408 bgp_distance_source_cmd,
15409 "distance <1-255> A.B.C.D/M",
15410 "Define an administrative distance\n"
15411 "Administrative distance\n"
15412 "IP source prefix\n")
15413{
15414 bgp_distance_set (vty, argv[0], argv[1], NULL);
15415 return CMD_SUCCESS;
15416}
15417
15418DEFUN (no_bgp_distance_source,
15419 no_bgp_distance_source_cmd,
15420 "no distance <1-255> A.B.C.D/M",
15421 NO_STR
15422 "Define an administrative distance\n"
15423 "Administrative distance\n"
15424 "IP source prefix\n")
15425{
15426 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15427 return CMD_SUCCESS;
15428}
15429
15430DEFUN (bgp_distance_source_access_list,
15431 bgp_distance_source_access_list_cmd,
15432 "distance <1-255> A.B.C.D/M WORD",
15433 "Define an administrative distance\n"
15434 "Administrative distance\n"
15435 "IP source prefix\n"
15436 "Access list name\n")
15437{
15438 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15439 return CMD_SUCCESS;
15440}
15441
15442DEFUN (no_bgp_distance_source_access_list,
15443 no_bgp_distance_source_access_list_cmd,
15444 "no distance <1-255> A.B.C.D/M WORD",
15445 NO_STR
15446 "Define an administrative distance\n"
15447 "Administrative distance\n"
15448 "IP source prefix\n"
15449 "Access list name\n")
15450{
15451 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15452 return CMD_SUCCESS;
15453}
David Lamparter6b0655a2014-06-04 06:53:35 +020015454
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015455#ifdef HAVE_IPV6
15456DEFUN (ipv6_bgp_distance,
15457 ipv6_bgp_distance_cmd,
15458 "distance bgp <1-255> <1-255> <1-255>",
15459 "Define an administrative distance\n"
15460 "BGP distance\n"
15461 "Distance for routes external to the AS\n"
15462 "Distance for routes internal to the AS\n"
15463 "Distance for local routes\n")
15464{
15465 struct bgp *bgp;
15466
15467 bgp = vty->index;
15468
15469 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15470 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15471 bgp->ipv6_distance_local = atoi (argv[2]);
15472 return CMD_SUCCESS;
15473}
15474
15475DEFUN (no_ipv6_bgp_distance,
15476 no_ipv6_bgp_distance_cmd,
15477 "no distance bgp <1-255> <1-255> <1-255>",
15478 NO_STR
15479 "Define an administrative distance\n"
15480 "BGP distance\n"
15481 "Distance for routes external to the AS\n"
15482 "Distance for routes internal to the AS\n"
15483 "Distance for local routes\n")
15484{
15485 struct bgp *bgp;
15486
15487 bgp = vty->index;
15488
15489 bgp->ipv6_distance_ebgp= 0;
15490 bgp->ipv6_distance_ibgp = 0;
15491 bgp->ipv6_distance_local = 0;
15492 return CMD_SUCCESS;
15493}
15494
15495ALIAS (no_ipv6_bgp_distance,
15496 no_ipv6_bgp_distance2_cmd,
15497 "no distance bgp",
15498 NO_STR
15499 "Define an administrative distance\n"
15500 "BGP distance\n")
15501
15502DEFUN (ipv6_bgp_distance_source,
15503 ipv6_bgp_distance_source_cmd,
15504 "distance <1-255> X:X::X:X/M",
15505 "Define an administrative distance\n"
15506 "Administrative distance\n"
15507 "IP source prefix\n")
15508{
15509 bgp_distance_set (vty, argv[0], argv[1], NULL);
15510 return CMD_SUCCESS;
15511}
15512
15513DEFUN (no_ipv6_bgp_distance_source,
15514 no_ipv6_bgp_distance_source_cmd,
15515 "no distance <1-255> X:X::X:X/M",
15516 NO_STR
15517 "Define an administrative distance\n"
15518 "Administrative distance\n"
15519 "IP source prefix\n")
15520{
15521 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15522 return CMD_SUCCESS;
15523}
15524
15525DEFUN (ipv6_bgp_distance_source_access_list,
15526 ipv6_bgp_distance_source_access_list_cmd,
15527 "distance <1-255> X:X::X:X/M WORD",
15528 "Define an administrative distance\n"
15529 "Administrative distance\n"
15530 "IP source prefix\n"
15531 "Access list name\n")
15532{
15533 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15534 return CMD_SUCCESS;
15535}
15536
15537DEFUN (no_ipv6_bgp_distance_source_access_list,
15538 no_ipv6_bgp_distance_source_access_list_cmd,
15539 "no distance <1-255> X:X::X:X/M WORD",
15540 NO_STR
15541 "Define an administrative distance\n"
15542 "Administrative distance\n"
15543 "IP source prefix\n"
15544 "Access list name\n")
15545{
15546 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15547 return CMD_SUCCESS;
15548}
15549#endif
15550
paul718e3742002-12-13 20:15:29 +000015551DEFUN (bgp_damp_set,
15552 bgp_damp_set_cmd,
15553 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15554 "BGP Specific commands\n"
15555 "Enable route-flap dampening\n"
15556 "Half-life time for the penalty\n"
15557 "Value to start reusing a route\n"
15558 "Value to start suppressing a route\n"
15559 "Maximum duration to suppress a stable route\n")
15560{
15561 struct bgp *bgp;
15562 int half = DEFAULT_HALF_LIFE * 60;
15563 int reuse = DEFAULT_REUSE;
15564 int suppress = DEFAULT_SUPPRESS;
15565 int max = 4 * half;
15566
15567 if (argc == 4)
15568 {
15569 half = atoi (argv[0]) * 60;
15570 reuse = atoi (argv[1]);
15571 suppress = atoi (argv[2]);
15572 max = atoi (argv[3]) * 60;
15573 }
15574 else if (argc == 1)
15575 {
15576 half = atoi (argv[0]) * 60;
15577 max = 4 * half;
15578 }
15579
15580 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015581
15582 if (suppress < reuse)
15583 {
15584 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15585 VTY_NEWLINE);
15586 return 0;
15587 }
15588
paul718e3742002-12-13 20:15:29 +000015589 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15590 half, reuse, suppress, max);
15591}
15592
15593ALIAS (bgp_damp_set,
15594 bgp_damp_set2_cmd,
15595 "bgp dampening <1-45>",
15596 "BGP Specific commands\n"
15597 "Enable route-flap dampening\n"
15598 "Half-life time for the penalty\n")
15599
15600ALIAS (bgp_damp_set,
15601 bgp_damp_set3_cmd,
15602 "bgp dampening",
15603 "BGP Specific commands\n"
15604 "Enable route-flap dampening\n")
15605
15606DEFUN (bgp_damp_unset,
15607 bgp_damp_unset_cmd,
15608 "no bgp dampening",
15609 NO_STR
15610 "BGP Specific commands\n"
15611 "Enable route-flap dampening\n")
15612{
15613 struct bgp *bgp;
15614
15615 bgp = vty->index;
15616 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15617}
15618
15619ALIAS (bgp_damp_unset,
15620 bgp_damp_unset2_cmd,
15621 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15622 NO_STR
15623 "BGP Specific commands\n"
15624 "Enable route-flap dampening\n"
15625 "Half-life time for the penalty\n"
15626 "Value to start reusing a route\n"
15627 "Value to start suppressing a route\n"
15628 "Maximum duration to suppress a stable route\n")
15629
Lou Bergerf9b6c392016-01-12 13:42:09 -050015630DEFUN (show_ip_bgp_dampened_paths,
15631 show_ip_bgp_dampened_paths_cmd,
15632 "show ip bgp dampened-paths",
15633 SHOW_STR
15634 IP_STR
15635 BGP_STR
15636 "Display paths suppressed due to dampening\n")
15637{
15638 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15639 NULL);
15640}
15641
15642ALIAS (show_ip_bgp_dampened_paths,
15643 show_ip_bgp_damp_dampened_paths_cmd,
15644 "show ip bgp dampening dampened-paths",
15645 SHOW_STR
15646 IP_STR
15647 BGP_STR
15648 "Display detailed information about dampening\n"
15649 "Display paths suppressed due to dampening\n")
15650
15651DEFUN (show_ip_bgp_flap_statistics,
15652 show_ip_bgp_flap_statistics_cmd,
15653 "show ip bgp flap-statistics",
15654 SHOW_STR
15655 IP_STR
15656 BGP_STR
15657 "Display flap statistics of routes\n")
15658{
15659 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15660 bgp_show_type_flap_statistics, NULL);
15661}
15662
15663ALIAS (show_ip_bgp_flap_statistics,
15664 show_ip_bgp_damp_flap_statistics_cmd,
15665 "show ip bgp dampening flap-statistics",
15666 SHOW_STR
15667 IP_STR
15668 BGP_STR
15669 "Display detailed information about dampening\n"
15670 "Display flap statistics of routes\n")
15671
Lou Berger651b4022016-01-12 13:42:07 -050015672DEFUN (show_bgp_ipv4_safi_dampened_paths,
15673 show_bgp_ipv4_safi_dampened_paths_cmd,
15674 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015675 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015676 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015677 IP_STR
15678 "Address Family modifier\n"
15679 "Address Family modifier\n"
15680 "Address Family modifier\n"
15681 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015682 "Display paths suppressed due to dampening\n")
15683{
Lou Berger651b4022016-01-12 13:42:07 -050015684 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015685
Lou Berger651b4022016-01-12 13:42:07 -050015686 if (bgp_parse_safi(argv[0], &safi)) {
15687 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15688 return CMD_WARNING;
15689 }
15690
15691 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15692}
15693ALIAS (show_bgp_ipv4_safi_dampened_paths,
15694 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15695 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015696 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015697 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015698 IP_STR
15699 "Address Family modifier\n"
15700 "Address Family modifier\n"
15701 "Address Family modifier\n"
15702 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015703 "Display detailed information about dampening\n"
15704 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015705
Lou Berger651b4022016-01-12 13:42:07 -050015706DEFUN (show_bgp_ipv6_safi_dampened_paths,
15707 show_bgp_ipv6_safi_dampened_paths_cmd,
15708 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015709 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015710 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015711 IPV6_STR
15712 "Address Family modifier\n"
15713 "Address Family modifier\n"
15714 "Address Family modifier\n"
15715 "Address Family modifier\n"
15716 "Display paths suppressed due to dampening\n")
15717{
15718 safi_t safi;
15719
15720 if (bgp_parse_safi(argv[0], &safi)) {
15721 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15722 return CMD_WARNING;
15723 }
15724
15725 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15726}
15727ALIAS (show_bgp_ipv6_safi_dampened_paths,
15728 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15729 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15730 SHOW_STR
15731 BGP_STR
15732 IPV6_STR
15733 "Address Family modifier\n"
15734 "Address Family modifier\n"
15735 "Address Family modifier\n"
15736 "Address Family modifier\n"
15737 "Display detailed information about dampening\n"
15738 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015739
15740DEFUN (show_bgp_ipv4_safi_flap_statistics,
15741 show_bgp_ipv4_safi_flap_statistics_cmd,
15742 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15743 SHOW_STR
15744 BGP_STR
15745 "Address Family\n"
15746 "Address Family modifier\n"
15747 "Address Family modifier\n"
15748 "Address Family modifier\n"
15749 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015750 "Display flap statistics of routes\n")
15751{
Lou Berger651b4022016-01-12 13:42:07 -050015752 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015753
Lou Berger651b4022016-01-12 13:42:07 -050015754 if (bgp_parse_safi(argv[0], &safi)) {
15755 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15756 return CMD_WARNING;
15757 }
15758
15759 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15760}
15761ALIAS (show_bgp_ipv4_safi_flap_statistics,
15762 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15763 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015764 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015765 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015766 "Address Family\n"
15767 "Address Family modifier\n"
15768 "Address Family modifier\n"
15769 "Address Family modifier\n"
15770 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015771 "Display detailed information about dampening\n"
15772 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015773
Lou Berger651b4022016-01-12 13:42:07 -050015774DEFUN (show_bgp_ipv6_safi_flap_statistics,
15775 show_bgp_ipv6_safi_flap_statistics_cmd,
15776 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15777 SHOW_STR
15778 BGP_STR
15779 "Address Family\n"
15780 "Address Family modifier\n"
15781 "Address Family modifier\n"
15782 "Address Family modifier\n"
15783 "Address Family modifier\n"
15784 "Display flap statistics of routes\n")
15785{
15786 safi_t safi;
15787
15788 if (bgp_parse_safi(argv[0], &safi)) {
15789 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15790 return CMD_WARNING;
15791 }
15792
15793 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15794}
15795ALIAS (show_bgp_ipv6_safi_flap_statistics,
15796 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15797 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15798 SHOW_STR
15799 BGP_STR
15800 "Address Family\n"
15801 "Address Family modifier\n"
15802 "Address Family modifier\n"
15803 "Address Family modifier\n"
15804 "Address Family modifier\n"
15805 "Display detailed information about dampening\n"
15806 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015807
paul718e3742002-12-13 20:15:29 +000015808/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015809static int
paulfd79ac92004-10-13 05:06:08 +000015810bgp_clear_damp_route (struct vty *vty, const char *view_name,
15811 const char *ip_str, afi_t afi, safi_t safi,
15812 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015813{
15814 int ret;
15815 struct prefix match;
15816 struct bgp_node *rn;
15817 struct bgp_node *rm;
15818 struct bgp_info *ri;
15819 struct bgp_info *ri_temp;
15820 struct bgp *bgp;
15821 struct bgp_table *table;
15822
15823 /* BGP structure lookup. */
15824 if (view_name)
15825 {
15826 bgp = bgp_lookup_by_name (view_name);
15827 if (bgp == NULL)
15828 {
15829 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15830 return CMD_WARNING;
15831 }
15832 }
15833 else
15834 {
15835 bgp = bgp_get_default ();
15836 if (bgp == NULL)
15837 {
15838 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15839 return CMD_WARNING;
15840 }
15841 }
15842
15843 /* Check IP address argument. */
15844 ret = str2prefix (ip_str, &match);
15845 if (! ret)
15846 {
15847 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15848 return CMD_WARNING;
15849 }
15850
15851 match.family = afi2family (afi);
15852
Lou Berger298cc2f2016-01-12 13:42:02 -050015853 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015854 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015855 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015856 {
15857 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15858 continue;
15859
15860 if ((table = rn->info) != NULL)
15861 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015862 {
15863 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15864 {
15865 ri = rm->info;
15866 while (ri)
15867 {
15868 if (ri->extra && ri->extra->damp_info)
15869 {
15870 ri_temp = ri->next;
15871 bgp_damp_info_free (ri->extra->damp_info, 1);
15872 ri = ri_temp;
15873 }
15874 else
15875 ri = ri->next;
15876 }
15877 }
15878
15879 bgp_unlock_node (rm);
15880 }
paul718e3742002-12-13 20:15:29 +000015881 }
15882 }
15883 else
15884 {
15885 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015886 {
15887 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15888 {
15889 ri = rn->info;
15890 while (ri)
15891 {
15892 if (ri->extra && ri->extra->damp_info)
15893 {
15894 ri_temp = ri->next;
15895 bgp_damp_info_free (ri->extra->damp_info, 1);
15896 ri = ri_temp;
15897 }
15898 else
15899 ri = ri->next;
15900 }
15901 }
15902
15903 bgp_unlock_node (rn);
15904 }
paul718e3742002-12-13 20:15:29 +000015905 }
15906
15907 return CMD_SUCCESS;
15908}
15909
15910DEFUN (clear_ip_bgp_dampening,
15911 clear_ip_bgp_dampening_cmd,
15912 "clear ip bgp dampening",
15913 CLEAR_STR
15914 IP_STR
15915 BGP_STR
15916 "Clear route flap dampening information\n")
15917{
15918 bgp_damp_info_clean ();
15919 return CMD_SUCCESS;
15920}
15921
15922DEFUN (clear_ip_bgp_dampening_prefix,
15923 clear_ip_bgp_dampening_prefix_cmd,
15924 "clear ip bgp dampening A.B.C.D/M",
15925 CLEAR_STR
15926 IP_STR
15927 BGP_STR
15928 "Clear route flap dampening information\n"
15929 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15930{
15931 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15932 SAFI_UNICAST, NULL, 1);
15933}
15934
15935DEFUN (clear_ip_bgp_dampening_address,
15936 clear_ip_bgp_dampening_address_cmd,
15937 "clear ip bgp dampening A.B.C.D",
15938 CLEAR_STR
15939 IP_STR
15940 BGP_STR
15941 "Clear route flap dampening information\n"
15942 "Network to clear damping information\n")
15943{
15944 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15945 SAFI_UNICAST, NULL, 0);
15946}
15947
15948DEFUN (clear_ip_bgp_dampening_address_mask,
15949 clear_ip_bgp_dampening_address_mask_cmd,
15950 "clear ip bgp dampening A.B.C.D A.B.C.D",
15951 CLEAR_STR
15952 IP_STR
15953 BGP_STR
15954 "Clear route flap dampening information\n"
15955 "Network to clear damping information\n"
15956 "Network mask\n")
15957{
15958 int ret;
15959 char prefix_str[BUFSIZ];
15960
15961 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15962 if (! ret)
15963 {
15964 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15965 return CMD_WARNING;
15966 }
15967
15968 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15969 SAFI_UNICAST, NULL, 0);
15970}
David Lamparter6b0655a2014-06-04 06:53:35 +020015971
Lou Berger298cc2f2016-01-12 13:42:02 -050015972/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015973static int
paul718e3742002-12-13 20:15:29 +000015974bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15975 afi_t afi, safi_t safi, int *write)
15976{
15977 struct bgp_node *prn;
15978 struct bgp_node *rn;
15979 struct bgp_table *table;
15980 struct prefix *p;
15981 struct prefix_rd *prd;
15982 struct bgp_static *bgp_static;
15983 u_int32_t label;
15984 char buf[SU_ADDRSTRLEN];
15985 char rdbuf[RD_ADDRSTRLEN];
15986
15987 /* Network configuration. */
15988 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15989 if ((table = prn->info) != NULL)
15990 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15991 if ((bgp_static = rn->info) != NULL)
15992 {
15993 p = &rn->p;
15994 prd = (struct prefix_rd *) &prn->p;
15995
15996 /* "address-family" display. */
15997 bgp_config_write_family_header (vty, afi, safi, write);
15998
15999 /* "network" configuration display. */
16000 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
16001 label = decode_label (bgp_static->tag);
16002
16003 vty_out (vty, " network %s/%d rd %s tag %d",
16004 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16005 p->prefixlen,
16006 rdbuf, label);
16007 vty_out (vty, "%s", VTY_NEWLINE);
16008 }
16009 return 0;
16010}
16011
16012/* Configuration of static route announcement and aggregate
16013 information. */
16014int
16015bgp_config_write_network (struct vty *vty, struct bgp *bgp,
16016 afi_t afi, safi_t safi, int *write)
16017{
16018 struct bgp_node *rn;
16019 struct prefix *p;
16020 struct bgp_static *bgp_static;
16021 struct bgp_aggregate *bgp_aggregate;
16022 char buf[SU_ADDRSTRLEN];
16023
Lou Berger298cc2f2016-01-12 13:42:02 -050016024 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000016025 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
16026
16027 /* Network configuration. */
16028 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
16029 if ((bgp_static = rn->info) != NULL)
16030 {
16031 p = &rn->p;
16032
16033 /* "address-family" display. */
16034 bgp_config_write_family_header (vty, afi, safi, write);
16035
16036 /* "network" configuration display. */
16037 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16038 {
16039 u_int32_t destination;
16040 struct in_addr netmask;
16041
16042 destination = ntohl (p->u.prefix4.s_addr);
16043 masklen2ip (p->prefixlen, &netmask);
16044 vty_out (vty, " network %s",
16045 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
16046
16047 if ((IN_CLASSC (destination) && p->prefixlen == 24)
16048 || (IN_CLASSB (destination) && p->prefixlen == 16)
16049 || (IN_CLASSA (destination) && p->prefixlen == 8)
16050 || p->u.prefix4.s_addr == 0)
16051 {
16052 /* Natural mask is not display. */
16053 }
16054 else
16055 vty_out (vty, " mask %s", inet_ntoa (netmask));
16056 }
16057 else
16058 {
16059 vty_out (vty, " network %s/%d",
16060 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16061 p->prefixlen);
16062 }
16063
16064 if (bgp_static->rmap.name)
16065 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000016066 else
16067 {
16068 if (bgp_static->backdoor)
16069 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000016070 }
paul718e3742002-12-13 20:15:29 +000016071
16072 vty_out (vty, "%s", VTY_NEWLINE);
16073 }
16074
16075 /* Aggregate-address configuration. */
16076 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
16077 if ((bgp_aggregate = rn->info) != NULL)
16078 {
16079 p = &rn->p;
16080
16081 /* "address-family" display. */
16082 bgp_config_write_family_header (vty, afi, safi, write);
16083
16084 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16085 {
16086 struct in_addr netmask;
16087
16088 masklen2ip (p->prefixlen, &netmask);
16089 vty_out (vty, " aggregate-address %s %s",
16090 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16091 inet_ntoa (netmask));
16092 }
16093 else
16094 {
16095 vty_out (vty, " aggregate-address %s/%d",
16096 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16097 p->prefixlen);
16098 }
16099
16100 if (bgp_aggregate->as_set)
16101 vty_out (vty, " as-set");
16102
16103 if (bgp_aggregate->summary_only)
16104 vty_out (vty, " summary-only");
16105
16106 vty_out (vty, "%s", VTY_NEWLINE);
16107 }
16108
16109 return 0;
16110}
16111
16112int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016113bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
16114 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000016115{
16116 struct bgp_node *rn;
16117 struct bgp_distance *bdistance;
16118
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016119 if (afi == AFI_IP && safi == SAFI_UNICAST)
16120 {
16121 /* Distance configuration. */
16122 if (bgp->distance_ebgp
16123 && bgp->distance_ibgp
16124 && bgp->distance_local
16125 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16126 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16127 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16128 vty_out (vty, " distance bgp %d %d %d%s",
16129 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
16130 VTY_NEWLINE);
16131
16132 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16133 if ((bdistance = rn->info) != NULL)
16134 {
16135 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16136 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
16137 bdistance->access_list ? bdistance->access_list : "",
16138 VTY_NEWLINE);
16139 }
16140 }
16141
16142#ifdef HAVE_IPV6
16143 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
16144 {
16145 bgp_config_write_family_header (vty, afi, safi, write);
16146 if (bgp->ipv6_distance_ebgp
16147 && bgp->ipv6_distance_ibgp
16148 && bgp->ipv6_distance_local
16149 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16150 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16151 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16152 vty_out (vty, " distance bgp %d %d %d%s",
16153 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
16154 VTY_NEWLINE);
16155
16156 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16157 if ((bdistance = rn->info) != NULL)
16158 {
16159 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16160 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
16161 bdistance->access_list ? bdistance->access_list : "",
16162 VTY_NEWLINE);
16163 }
16164 }
16165#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016166
16167 return 0;
16168}
16169
16170/* Allocate routing table structure and install commands. */
16171void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080016172bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000016173{
16174 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000016175 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000016176
16177 /* IPv4 BGP commands. */
16178 install_element (BGP_NODE, &bgp_network_cmd);
16179 install_element (BGP_NODE, &bgp_network_mask_cmd);
16180 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
16181 install_element (BGP_NODE, &bgp_network_route_map_cmd);
16182 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
16183 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
16184 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
16185 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
16186 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
16187 install_element (BGP_NODE, &no_bgp_network_cmd);
16188 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
16189 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
16190 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
16191 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
16192 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16193 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
16194 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
16195 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
16196
16197 install_element (BGP_NODE, &aggregate_address_cmd);
16198 install_element (BGP_NODE, &aggregate_address_mask_cmd);
16199 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
16200 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
16201 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
16202 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
16203 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
16204 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
16205 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
16206 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
16207 install_element (BGP_NODE, &no_aggregate_address_cmd);
16208 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
16209 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
16210 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
16211 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
16212 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
16213 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
16214 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
16215 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16216 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16217
16218 /* IPv4 unicast configuration. */
16219 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16220 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16221 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16222 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16223 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16224 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016225 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016226 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16227 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16228 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16229 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16230 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016231
paul718e3742002-12-13 20:15:29 +000016232 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16233 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16234 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16235 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16236 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16237 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16238 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16239 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16240 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16241 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16242 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16243 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16244 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16245 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16246 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16247 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16248 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16249 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16250 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16251 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16252
16253 /* IPv4 multicast configuration. */
16254 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16255 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16256 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16257 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16258 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16259 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16260 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16261 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16262 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16263 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16264 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16265 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16266 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16267 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16268 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16269 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16270 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16271 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16272 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16273 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16274 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16275 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16276 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16277 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16278 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16279 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16280 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16281 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16282 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16283 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16284 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16285 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16286
Michael Lambert95cbbd22010-07-23 14:43:04 -040016287 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016288 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016289 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16290 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16291 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16292 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16293 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16294 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16295 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16296 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16297 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016298 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016299 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16300 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16301 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16302 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16303 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16304 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16305 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16306 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16307 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16308 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16309 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16310 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16311 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16312 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16313 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16314 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16315 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16316 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16317 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16318 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16319 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16320 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16321 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16322 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16323 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16324 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16325 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16326 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016327 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16328 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16329 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16330 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16331 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016332 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16333 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16334 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16335 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16336 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16337 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16338 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16341 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16342 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16346 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16347 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16348 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16349 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16350 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016351 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016352 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16353 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16354 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16356 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16357 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16358 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16359 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16360 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16361 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16362 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16363 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16364 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16365 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16366 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16367 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16368 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16369 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16370 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16371 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16372 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16373 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16374 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16375 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16376 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16377 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16378 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16379 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16380 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16381 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16382 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16383 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16384 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16385 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16386 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16387 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16388 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16389 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16390 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16391 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16392 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16393 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16394 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16395 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16396 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016397 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016398 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016399 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016400 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016401 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016402 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016403
16404 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016405 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016406 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16407 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16408 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16409 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16410 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016411 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016412 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16413 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16414 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16415 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16416 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16417 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16418 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16419 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16420 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16421 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16422 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16423 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16424 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16425 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16426 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16427 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016428 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16429 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16430 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16431 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16432 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016433 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16434 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16435 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16436 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16437 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16438 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16439 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16440 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016441 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016442 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016443 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016444 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016445
Donald Sharp68b45cc2016-03-11 14:27:13 -050016446 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016447 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16448 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16449 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16450 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16451
paul718e3742002-12-13 20:15:29 +000016452 /* New config IPv6 BGP commands. */
16453 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16454 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16455 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16456 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16457
16458 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16459 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16460 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16461 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16462
G.Balaji73bfe0b2011-09-23 22:36:20 +053016463 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16464 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16465
paul718e3742002-12-13 20:15:29 +000016466 /* Old config IPv6 BGP commands. */
16467 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16468 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16469
16470 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16471 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16472 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16473 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16474
Michael Lambert95cbbd22010-07-23 14:43:04 -040016475 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016476 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016477 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016478 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016479 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016480 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016481 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016482 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016483 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016484 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16485 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16486 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16487 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16488 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16489 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16490 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16491 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016492 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016493 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016494 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016495 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016496 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016497 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016498 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016499 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016500 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16501 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016502 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016503 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016504 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016505 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016506 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016507 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016508 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016509 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016510 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016511 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016512 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016513 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016514 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016515 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016516 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16517 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016518 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016519 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016520 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016521 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016522 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016523
16524 /* Restricted:
16525 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16526 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016527 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016528 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016529 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016530 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016531 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16532 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16533 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16534 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16535 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16536 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16537 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16538 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16539 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016540 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016541 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016542 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016543 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016544 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016545 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016546 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016547 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016548 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016549 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016550
Paul Jakma2815e612006-09-14 02:56:07 +000016551 /* Statistics */
16552 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016553 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016554
16555 install_element (BGP_NODE, &bgp_distance_cmd);
16556 install_element (BGP_NODE, &no_bgp_distance_cmd);
16557 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16558 install_element (BGP_NODE, &bgp_distance_source_cmd);
16559 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16560 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16561 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016562#ifdef HAVE_IPV6
16563 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16564 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16565 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16566 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16567 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16568 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16569 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16570#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016571
16572 install_element (BGP_NODE, &bgp_damp_set_cmd);
16573 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16574 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16575 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16576 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16577 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16578 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16579 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16580 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16581 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016582
16583 /* IPv4 Multicast Mode */
16584 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16585 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16586 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16587 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16588 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16589
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016590
16591 /* Deprecated AS-Pathlimit commands */
16592 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16593 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16594 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16595 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16596 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16597 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16598
16599 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16600 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16601 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16602 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16603 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16604 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16605
16606 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16607 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16608 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16609 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16610 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16611 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16612
16613 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16614 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16615 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16616 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16617 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16618 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16619
16620 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16621 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16622 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16623 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16624 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16625 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16626
16627 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16628 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16629 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16630 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16631 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16632 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016633
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016634 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16635 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016636
16637 /* old style commands */
16638 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16639 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16640 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016641 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
16642 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016643 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16644 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16645 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16646 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016648 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16649 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16650 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016651 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16652 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16653 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16654 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16655 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16656 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16657 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16658 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16659 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16660 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16661 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16662 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16663 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16664 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16665 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16666 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16667 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16668 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16669 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16670 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16671 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16673 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16674 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16675 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16676 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16677 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16678 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16679 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16680 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16681 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16682 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16683 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16684 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16686 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16687 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16688 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16689 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16690 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16691 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16692 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16693 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16694 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16695 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16696 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16697 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16698 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016699 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016700 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016701 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16702 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016703 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16704 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16705 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16706 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16707 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16708 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16709 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16710 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16711 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16712 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16713 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16714 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16715 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16716 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16717 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16718 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16719 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16720 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16721 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16722 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16723 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16724 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16725 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16726 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16727 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16728 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16729 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016730
Lou Bergerf9b6c392016-01-12 13:42:09 -050016731 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016732 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
16733 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016734 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16735 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16736 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16737 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016738 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16739 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16740 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016741 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16742 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16743 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16744 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16745 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16746 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16747 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16748 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16749 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16750 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16751 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16752 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16753 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16754 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16755 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16756 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16757 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16758 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16759 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16760 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16761 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16762 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16763 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16764 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016765
16766 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16767 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16768 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016769
Lou Bergerf9b6c392016-01-12 13:42:09 -050016770 install_element (VIEW_NODE, &show_bgp_cmd);
16771 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16772 install_element (VIEW_NODE, &show_bgp_route_cmd);
16773 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016774 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
16775 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16776 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16777 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
16778 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16779 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016780 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16781 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16782 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16783 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16784 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16785 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16786 install_element (VIEW_NODE, &show_bgp_community_cmd);
16787 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16788 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16789 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16790 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16791 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16792 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16793 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16794 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16795 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16796 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16797 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16798 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16799 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16800 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16801 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16802 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16803 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16804 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16805 install_element (VIEW_NODE, &show_bgp_view_cmd);
16806 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16807 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16808 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16809 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16810 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16811 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16812 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16813 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16814 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016815
Lou Bergerf9b6c392016-01-12 13:42:09 -050016816 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16817 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016818 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
16819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16821 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
16822 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016824 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16825 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16826 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16827 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16828 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16829 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16830 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16831 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16832 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16833 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16834 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016835
Lou Bergerf9b6c392016-01-12 13:42:09 -050016836 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16837 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016838
Lou Bergerf9b6c392016-01-12 13:42:09 -050016839 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16857 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16858 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16859 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16860 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16861 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16862 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16863 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16864 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16865 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16866 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16867 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16868 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16869 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16870 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16871 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16872 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16873 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16874 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016875 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016876 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016877 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016878 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016879 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016880 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016881 /* old with name safi collision */
16882 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16883 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16884 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16885 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16886 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16887 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16888 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16889 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16890 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16891 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16892 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16893 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16894 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16895 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16896 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16897 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016898
Lou Bergerf9b6c392016-01-12 13:42:09 -050016899 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16900 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016901
16902 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16903 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16904 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16905 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016906
16907 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16908 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16909 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16910 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016911}
Chris Caputo228da422009-07-18 05:44:03 +000016912
16913void
16914bgp_route_finish (void)
16915{
16916 bgp_table_unlock (bgp_distance_table);
16917 bgp_distance_table = NULL;
16918}