blob: 78cd53b1bd75735abe34b5015c75b22791106bac [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -050058#include "bgpd/bgp_nht.c"
paul718e3742002-12-13 20:15:29 +000059
60/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070061extern const char *bgp_origin_str[];
62extern const char *bgp_origin_long_str[];
David Lamparter6b0655a2014-06-04 06:53:35 +020063
paul94f2b392005-06-28 12:44:16 +000064static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000065bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000066 struct prefix_rd *prd)
67{
68 struct bgp_node *rn;
69 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000070
71 assert (table);
72 if (!table)
73 return NULL;
74
Lou Berger298cc2f2016-01-12 13:42:02 -050075 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000076 {
paulfee0f4c2004-09-13 05:12:46 +000077 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000078
79 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000080 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000081 else
82 bgp_unlock_node (prn);
83 table = prn->info;
84 }
paul718e3742002-12-13 20:15:29 +000085
86 rn = bgp_node_get (table, p);
87
Lou Berger298cc2f2016-01-12 13:42:02 -050088 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000089 rn->prn = prn;
90
91 return rn;
92}
David Lamparter6b0655a2014-06-04 06:53:35 +020093
Paul Jakmafb982c22007-05-04 20:15:47 +000094/* Allocate bgp_info_extra */
95static struct bgp_info_extra *
96bgp_info_extra_new (void)
97{
98 struct bgp_info_extra *new;
99 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
100 return new;
101}
102
103static void
104bgp_info_extra_free (struct bgp_info_extra **extra)
105{
106 if (extra && *extra)
107 {
108 if ((*extra)->damp_info)
109 bgp_damp_info_free ((*extra)->damp_info, 0);
110
111 (*extra)->damp_info = NULL;
112
113 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
114
115 *extra = NULL;
116 }
117}
118
119/* Get bgp_info extra information for the given bgp_info, lazy allocated
120 * if required.
121 */
122struct bgp_info_extra *
123bgp_info_extra_get (struct bgp_info *ri)
124{
125 if (!ri->extra)
126 ri->extra = bgp_info_extra_new();
127 return ri->extra;
128}
129
paul718e3742002-12-13 20:15:29 +0000130/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000131static void
paul718e3742002-12-13 20:15:29 +0000132bgp_info_free (struct bgp_info *binfo)
133{
134 if (binfo->attr)
Paul Jakmaf6f434b2010-11-23 21:28:03 +0000135 bgp_attr_unintern (&binfo->attr);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -0500136
137 bgp_unlink_nexthop(binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +0000138 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700139 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000140
paul200df112005-06-01 11:17:05 +0000141 peer_unlock (binfo->peer); /* bgp_info peer reference */
142
paul718e3742002-12-13 20:15:29 +0000143 XFREE (MTYPE_BGP_ROUTE, binfo);
144}
145
paul200df112005-06-01 11:17:05 +0000146struct bgp_info *
147bgp_info_lock (struct bgp_info *binfo)
148{
149 binfo->lock++;
150 return binfo;
151}
152
153struct bgp_info *
154bgp_info_unlock (struct bgp_info *binfo)
155{
156 assert (binfo && binfo->lock > 0);
157 binfo->lock--;
158
159 if (binfo->lock == 0)
160 {
161#if 0
162 zlog_debug ("%s: unlocked and freeing", __func__);
163 zlog_backtrace (LOG_DEBUG);
164#endif
165 bgp_info_free (binfo);
166 return NULL;
167 }
168
169#if 0
170 if (binfo->lock == 1)
171 {
172 zlog_debug ("%s: unlocked to 1", __func__);
173 zlog_backtrace (LOG_DEBUG);
174 }
175#endif
176
177 return binfo;
178}
179
paul718e3742002-12-13 20:15:29 +0000180void
181bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
182{
183 struct bgp_info *top;
184
185 top = rn->info;
paul200df112005-06-01 11:17:05 +0000186
paul718e3742002-12-13 20:15:29 +0000187 ri->next = rn->info;
188 ri->prev = NULL;
189 if (top)
190 top->prev = ri;
191 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000192
193 bgp_info_lock (ri);
194 bgp_lock_node (rn);
195 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000196}
197
paulb40d9392005-08-22 22:34:41 +0000198/* Do the actual removal of info from RIB, for use by bgp_process
199 completion callback *only* */
200static void
201bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000202{
203 if (ri->next)
204 ri->next->prev = ri->prev;
205 if (ri->prev)
206 ri->prev->next = ri->next;
207 else
208 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000209
Josh Baileyde8d5df2011-07-20 20:46:01 -0700210 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000211 bgp_info_unlock (ri);
212 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000213}
214
paulb40d9392005-08-22 22:34:41 +0000215void
216bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
217{
Paul Jakma1a392d42006-09-07 00:24:49 +0000218 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
219 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000220 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
221}
222
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000223/* undo the effects of a previous call to bgp_info_delete; typically
224 called when a route is deleted and then quickly re-added before the
225 deletion has been processed */
226static void
227bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
228{
229 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
230 /* unset of previous already took care of pcount */
231 SET_FLAG (ri->flags, BGP_INFO_VALID);
232}
233
Paul Jakma1a392d42006-09-07 00:24:49 +0000234/* Adjust pcount as required */
235static void
236bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
237{
Avneesh Sachdev67174042012-08-17 08:19:49 -0700238 struct bgp_table *table;
239
240 assert (rn && bgp_node_table (rn));
Paul Jakma6f585442006-10-22 19:13:07 +0000241 assert (ri && ri->peer && ri->peer->bgp);
242
Avneesh Sachdev67174042012-08-17 08:19:49 -0700243 table = bgp_node_table (rn);
244
Paul Jakma1a392d42006-09-07 00:24:49 +0000245 /* Ignore 'pcount' for RS-client tables */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700246 if (table->type != BGP_TABLE_MAIN
Paul Jakma1a392d42006-09-07 00:24:49 +0000247 || ri->peer == ri->peer->bgp->peer_self)
248 return;
249
250 if (BGP_INFO_HOLDDOWN (ri)
251 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
252 {
253
254 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
255
256 /* slight hack, but more robust against errors. */
Avneesh Sachdev67174042012-08-17 08:19:49 -0700257 if (ri->peer->pcount[table->afi][table->safi])
258 ri->peer->pcount[table->afi][table->safi]--;
Paul Jakma1a392d42006-09-07 00:24:49 +0000259 else
260 {
261 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
262 __func__, ri->peer->host);
263 zlog_backtrace (LOG_WARNING);
264 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
265 }
266 }
267 else if (!BGP_INFO_HOLDDOWN (ri)
268 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
269 {
270 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
Avneesh Sachdev67174042012-08-17 08:19:49 -0700271 ri->peer->pcount[table->afi][table->safi]++;
Paul Jakma1a392d42006-09-07 00:24:49 +0000272 }
273}
274
275
276/* Set/unset bgp_info flags, adjusting any other state as needed.
277 * This is here primarily to keep prefix-count in check.
278 */
279void
280bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
281{
282 SET_FLAG (ri->flags, flag);
283
284 /* early bath if we know it's not a flag that changes useability state */
285 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
286 return;
287
288 bgp_pcount_adjust (rn, ri);
289}
290
291void
292bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
293{
294 UNSET_FLAG (ri->flags, flag);
295
296 /* early bath if we know it's not a flag that changes useability state */
297 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
298 return;
299
300 bgp_pcount_adjust (rn, ri);
301}
302
paul718e3742002-12-13 20:15:29 +0000303/* Get MED value. If MED value is missing and "bgp bestpath
304 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000305static u_int32_t
paul718e3742002-12-13 20:15:29 +0000306bgp_med_value (struct attr *attr, struct bgp *bgp)
307{
308 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
309 return attr->med;
310 else
311 {
312 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000313 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000314 else
315 return 0;
316 }
317}
318
Paul Jakma6d4742b2015-11-25 17:14:37 +0000319/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
320 * is preferred, or 0 if they are the same (usually will only occur if
321 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000322static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700323bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000325{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000326 struct attr *newattr, *existattr;
327 struct attr_extra *newattre, *existattre;
328 bgp_peer_sort_t new_sort;
329 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000330 u_int32_t new_pref;
331 u_int32_t exist_pref;
332 u_int32_t new_med;
333 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000334 u_int32_t new_weight;
335 u_int32_t exist_weight;
336 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000337 struct in_addr new_id;
338 struct in_addr exist_id;
339 int new_cluster;
340 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000341 int internal_as_route;
342 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000343 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700344
paul718e3742002-12-13 20:15:29 +0000345 /* 0. Null check. */
346 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000348 if (exist == NULL)
349 return -1;
paul718e3742002-12-13 20:15:29 +0000350
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000351 newattr = new->attr;
352 existattr = exist->attr;
353 newattre = newattr->extra;
354 existattre = existattr->extra;
355
paul718e3742002-12-13 20:15:29 +0000356 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000357 new_weight = exist_weight = 0;
358
359 if (newattre)
360 new_weight = newattre->weight;
361 if (existattre)
362 exist_weight = existattre->weight;
363
Paul Jakmafb982c22007-05-04 20:15:47 +0000364 if (new_weight > exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000365 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000366 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000367 return 1;
paul718e3742002-12-13 20:15:29 +0000368
369 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000370 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000371
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000372 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
373 new_pref = newattr->local_pref;
374 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
375 exist_pref = existattr->local_pref;
376
paul718e3742002-12-13 20:15:29 +0000377 if (new_pref > exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000378 return -1;
paul718e3742002-12-13 20:15:29 +0000379 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000380 return 1;
paul718e3742002-12-13 20:15:29 +0000381
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000382 /* 3. Local route check. We prefer:
383 * - BGP_ROUTE_STATIC
384 * - BGP_ROUTE_AGGREGATE
385 * - BGP_ROUTE_REDISTRIBUTE
386 */
387 if (! (new->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000388 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000389 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000390 return 1;
paul718e3742002-12-13 20:15:29 +0000391
392 /* 4. AS path length check. */
393 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
394 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000395 int exist_hops = aspath_count_hops (existattr->aspath);
396 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000397
hasso68118452005-04-08 15:40:36 +0000398 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
399 {
paulfe69a502005-09-10 16:55:02 +0000400 int aspath_hops;
401
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000402 aspath_hops = aspath_count_hops (newattr->aspath);
403 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000404
405 if ( aspath_hops < (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000406 return -1;
paulfe69a502005-09-10 16:55:02 +0000407 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000408 return 1;
hasso68118452005-04-08 15:40:36 +0000409 }
410 else
411 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000412 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000413
414 if (newhops < exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000415 return -1;
paulfe69a502005-09-10 16:55:02 +0000416 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000417 return 1;
hasso68118452005-04-08 15:40:36 +0000418 }
paul718e3742002-12-13 20:15:29 +0000419 }
420
421 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000422 if (newattr->origin < existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000423 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000424 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000425 return 1;
paul718e3742002-12-13 20:15:29 +0000426
427 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000428 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
429 && aspath_count_hops (existattr->aspath) == 0);
430 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
431 && aspath_count_confeds (existattr->aspath) > 0
432 && aspath_count_hops (newattr->aspath) == 0
433 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000434
435 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
436 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
437 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000438 || aspath_cmp_left (newattr->aspath, existattr->aspath)
439 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000440 || internal_as_route)
441 {
442 new_med = bgp_med_value (new->attr, bgp);
443 exist_med = bgp_med_value (exist->attr, bgp);
444
445 if (new_med < exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000446 return -1;
paul718e3742002-12-13 20:15:29 +0000447 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000448 return 1;
paul718e3742002-12-13 20:15:29 +0000449 }
450
451 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000452 new_sort = new->peer->sort;
453 exist_sort = exist->peer->sort;
454
455 if (new_sort == BGP_PEER_EBGP
456 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000457 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000458 if (exist_sort == BGP_PEER_EBGP
459 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000460 return 1;
paul718e3742002-12-13 20:15:29 +0000461
462 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000463 newm = existm = 0;
464
465 if (new->extra)
466 newm = new->extra->igpmetric;
467 if (exist->extra)
468 existm = exist->extra->igpmetric;
469
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm < existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000471 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000473 return 1;
paul718e3742002-12-13 20:15:29 +0000474
475 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000478 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
479 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000480 /*
481 * For the two paths, all comparison steps till IGP metric
482 * have succeeded - including AS_PATH hop count. Since 'bgp
483 * bestpath as-path multipath-relax' knob is on, we don't need
484 * an exact match of AS_PATH. Thus, mark the paths are equal.
485 * That will trigger both these paths to get into the multipath
486 * array.
487 */
488 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000489 }
490 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000491 {
492 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
493 return 0;
494 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700495 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700497 }
paul718e3742002-12-13 20:15:29 +0000498
499 /* 10. If both paths are external, prefer the path that was received
500 first (the oldest one). This step minimizes route-flap, since a
501 newer path won't displace an older one, even if it was the
502 preferred route based on the additional decision criteria below. */
503 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000504 && new_sort == BGP_PEER_EBGP
505 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000506 {
507 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000508 return -1;
paul718e3742002-12-13 20:15:29 +0000509 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000510 return 1;
paul718e3742002-12-13 20:15:29 +0000511 }
512
vivekbd4b7f12014-09-30 15:54:45 -0700513 /* 11. Router-ID comparision. */
514 /* If one of the paths is "stale", the corresponding peer router-id will
515 * be 0 and would always win over the other path. If originator id is
516 * used for the comparision, it will decide which path is better.
517 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000518 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
519 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000520 else
521 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000522 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
523 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000524 else
525 exist_id.s_addr = exist->peer->remote_id.s_addr;
526
527 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000528 return -1;
paul718e3742002-12-13 20:15:29 +0000529 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000530 return 1;
paul718e3742002-12-13 20:15:29 +0000531
532 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000533 new_cluster = exist_cluster = 0;
534
535 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
536 new_cluster = newattre->cluster->length;
537 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
538 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000539
540 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000541 return -1;
paul718e3742002-12-13 20:15:29 +0000542 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000543 return 1;
paul718e3742002-12-13 20:15:29 +0000544
545 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700546 /* Do this only if neither path is "stale" as stale paths do not have
547 * valid peer information (as the connection may or may not be up).
548 */
549 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000550 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700551 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000552 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300553 /* locally configured routes to advertise do not have su_remote */
554 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300555 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000556 if (exist->peer->su_remote == NULL)
557 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558
paul718e3742002-12-13 20:15:29 +0000559 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
560
561 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000562 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000563 if (ret == -1)
564 return -1;
paul718e3742002-12-13 20:15:29 +0000565
Paul Jakma6d4742b2015-11-25 17:14:37 +0000566 return -1;
paul718e3742002-12-13 20:15:29 +0000567}
568
paul94f2b392005-06-28 12:44:16 +0000569static enum filter_type
paul718e3742002-12-13 20:15:29 +0000570bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
571 afi_t afi, safi_t safi)
572{
573 struct bgp_filter *filter;
574
575 filter = &peer->filter[afi][safi];
576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577#define FILTER_EXIST_WARN(F,f,filter) \
578 if (BGP_DEBUG (update, UPDATE_IN) \
579 && !(F ## _IN (filter))) \
580 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
581 peer->host, #f, F ## _IN_NAME(filter));
582
583 if (DISTRIBUTE_IN_NAME (filter)) {
584 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
585
paul718e3742002-12-13 20:15:29 +0000586 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
587 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100588 }
paul718e3742002-12-13 20:15:29 +0000589
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 if (PREFIX_LIST_IN_NAME (filter)) {
591 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
592
paul718e3742002-12-13 20:15:29 +0000593 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
594 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 }
paul718e3742002-12-13 20:15:29 +0000596
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 if (FILTER_LIST_IN_NAME (filter)) {
598 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
603
paul718e3742002-12-13 20:15:29 +0000604 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100605#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000606}
607
paul94f2b392005-06-28 12:44:16 +0000608static enum filter_type
paul718e3742002-12-13 20:15:29 +0000609bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
610 afi_t afi, safi_t safi)
611{
612 struct bgp_filter *filter;
613
614 filter = &peer->filter[afi][safi];
615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616#define FILTER_EXIST_WARN(F,f,filter) \
617 if (BGP_DEBUG (update, UPDATE_OUT) \
618 && !(F ## _OUT (filter))) \
619 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
620 peer->host, #f, F ## _OUT_NAME(filter));
621
622 if (DISTRIBUTE_OUT_NAME (filter)) {
623 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
624
paul718e3742002-12-13 20:15:29 +0000625 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
626 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100627 }
paul718e3742002-12-13 20:15:29 +0000628
Paul Jakma650f76c2009-06-25 18:06:31 +0100629 if (PREFIX_LIST_OUT_NAME (filter)) {
630 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
631
paul718e3742002-12-13 20:15:29 +0000632 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
633 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 }
paul718e3742002-12-13 20:15:29 +0000635
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 if (FILTER_LIST_OUT_NAME (filter)) {
637 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
638
paul718e3742002-12-13 20:15:29 +0000639 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
640 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 }
paul718e3742002-12-13 20:15:29 +0000642
643 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100644#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000645}
646
647/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000648static int
paul718e3742002-12-13 20:15:29 +0000649bgp_community_filter (struct peer *peer, struct attr *attr)
650{
651 if (attr->community)
652 {
653 /* NO_ADVERTISE check. */
654 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
655 return 1;
656
657 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000658 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000659 community_include (attr->community, COMMUNITY_NO_EXPORT))
660 return 1;
661
662 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP
664 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000665 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
666 return 1;
667 }
668 return 0;
669}
670
671/* Route reflection loop check. */
672static int
673bgp_cluster_filter (struct peer *peer, struct attr *attr)
674{
675 struct in_addr cluster_id;
676
Paul Jakmafb982c22007-05-04 20:15:47 +0000677 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000678 {
679 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
680 cluster_id = peer->bgp->cluster_id;
681 else
682 cluster_id = peer->bgp->router_id;
683
Paul Jakmafb982c22007-05-04 20:15:47 +0000684 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000685 return 1;
686 }
687 return 0;
688}
David Lamparter6b0655a2014-06-04 06:53:35 +0200689
paul94f2b392005-06-28 12:44:16 +0000690static int
paul718e3742002-12-13 20:15:29 +0000691bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
692 afi_t afi, safi_t safi)
693{
694 struct bgp_filter *filter;
695 struct bgp_info info;
696 route_map_result_t ret;
697
698 filter = &peer->filter[afi][safi];
699
700 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000701 if (peer->weight)
702 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000703
704 /* Route map apply. */
705 if (ROUTE_MAP_IN_NAME (filter))
706 {
707 /* Duplicate current value to new strucutre for modification. */
708 info.peer = peer;
709 info.attr = attr;
710
paulac41b2a2003-08-12 05:32:27 +0000711 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
712
paul718e3742002-12-13 20:15:29 +0000713 /* Apply BGP route map to the attribute. */
714 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000715
716 peer->rmap_type = 0;
717
paul718e3742002-12-13 20:15:29 +0000718 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200719 /* caller has multiple error paths with bgp_attr_flush() */
720 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000721 }
722 return RMAP_PERMIT;
723}
David Lamparter6b0655a2014-06-04 06:53:35 +0200724
paul94f2b392005-06-28 12:44:16 +0000725static int
paulfee0f4c2004-09-13 05:12:46 +0000726bgp_export_modifier (struct peer *rsclient, struct peer *peer,
727 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
728{
729 struct bgp_filter *filter;
730 struct bgp_info info;
731 route_map_result_t ret;
732
733 filter = &peer->filter[afi][safi];
734
735 /* Route map apply. */
736 if (ROUTE_MAP_EXPORT_NAME (filter))
737 {
738 /* Duplicate current value to new strucutre for modification. */
739 info.peer = rsclient;
740 info.attr = attr;
741
742 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
743
744 /* Apply BGP route map to the attribute. */
745 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
746
747 rsclient->rmap_type = 0;
748
749 if (ret == RMAP_DENYMATCH)
750 {
751 /* Free newly generated AS path and community by route-map. */
752 bgp_attr_flush (attr);
753 return RMAP_DENY;
754 }
755 }
756 return RMAP_PERMIT;
757}
758
paul94f2b392005-06-28 12:44:16 +0000759static int
paulfee0f4c2004-09-13 05:12:46 +0000760bgp_import_modifier (struct peer *rsclient, struct peer *peer,
761 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
762{
763 struct bgp_filter *filter;
764 struct bgp_info info;
765 route_map_result_t ret;
766
767 filter = &rsclient->filter[afi][safi];
768
769 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000770 if (peer->weight)
771 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000772
773 /* Route map apply. */
774 if (ROUTE_MAP_IMPORT_NAME (filter))
775 {
776 /* Duplicate current value to new strucutre for modification. */
777 info.peer = peer;
778 info.attr = attr;
779
780 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
781
782 /* Apply BGP route map to the attribute. */
783 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
784
785 peer->rmap_type = 0;
786
787 if (ret == RMAP_DENYMATCH)
788 {
789 /* Free newly generated AS path and community by route-map. */
790 bgp_attr_flush (attr);
791 return RMAP_DENY;
792 }
793 }
794 return RMAP_PERMIT;
795}
David Lamparter6b0655a2014-06-04 06:53:35 +0200796
paul94f2b392005-06-28 12:44:16 +0000797static int
paul718e3742002-12-13 20:15:29 +0000798bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
799 struct attr *attr, afi_t afi, safi_t safi)
800{
801 int ret;
802 char buf[SU_ADDRSTRLEN];
803 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000804 struct peer *from;
805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000806 int transparent;
807 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000809
810 from = ri->peer;
811 filter = &peer->filter[afi][safi];
812 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000814
Paul Jakma750e8142008-07-22 21:11:48 +0000815 if (DISABLE_BGP_ANNOUNCE)
816 return 0;
paul718e3742002-12-13 20:15:29 +0000817
paulfee0f4c2004-09-13 05:12:46 +0000818 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
819 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
820 return 0;
821
paul718e3742002-12-13 20:15:29 +0000822 /* Do not send back route to sender. */
823 if (from == peer)
824 return 0;
825
826 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000827 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000828 if (! UNSUPPRESS_MAP_NAME (filter))
829 return 0;
830
831 /* Default route check. */
832 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
833 {
834 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
835 return 0;
paul718e3742002-12-13 20:15:29 +0000836 else if (p->family == AF_INET6 && p->prefixlen == 0)
837 return 0;
paul718e3742002-12-13 20:15:29 +0000838 }
839
paul286e1e72003-08-08 00:24:31 +0000840 /* Transparency check. */
841 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
842 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
843 transparent = 1;
844 else
845 transparent = 0;
846
paul718e3742002-12-13 20:15:29 +0000847 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000849 return 0;
850
851 /* If the attribute has originator-id and it is same as remote
852 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700853 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000854 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000856 {
857 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000858 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000859 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
860 peer->host,
861 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
862 p->prefixlen);
863 return 0;
864 }
865 }
866
867 /* ORF prefix-list filter check */
868 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
869 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
870 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
871 if (peer->orf_plist[afi][safi])
872 {
873 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
874 return 0;
875 }
876
877 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700878 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000879 {
880 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000881 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000882 "%s [Update:SEND] %s/%d is filtered",
883 peer->host,
884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
885 p->prefixlen);
886 return 0;
887 }
888
889#ifdef BGP_SEND_ASPATH_CHECK
890 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700891 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000892 {
893 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000894 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400895 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000896 peer->host, peer->as);
897 return 0;
898 }
899#endif /* BGP_SEND_ASPATH_CHECK */
900
901 /* If we're a CONFED we need to loop check the CONFED ID too */
902 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
903 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700904 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000905 {
906 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000907 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400908 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000909 peer->host,
910 bgp->confed_id);
911 return 0;
912 }
913 }
914
915 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000916 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000917 reflect = 1;
918 else
919 reflect = 0;
920
921 /* IBGP reflection check. */
922 if (reflect)
923 {
924 /* A route from a Client peer. */
925 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
926 {
927 /* Reflect to all the Non-Client peers and also to the
928 Client peers other than the originator. Originator check
929 is already done. So there is noting to do. */
930 /* no bgp client-to-client reflection check. */
931 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
932 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 return 0;
934 }
935 else
936 {
937 /* A route from a Non-client peer. Reflect to all other
938 clients. */
939 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 }
Paul Jakma41367172007-08-06 15:24:51 +0000943
paul718e3742002-12-13 20:15:29 +0000944 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700945 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000946
paul718e3742002-12-13 20:15:29 +0000947 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000948 if ((peer->sort == BGP_PEER_IBGP
949 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000950 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
951 {
952 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
953 attr->local_pref = bgp->default_local_pref;
954 }
955
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000956 /* If originator-id is not set and the route is to be reflected,
957 set the originator id */
958 if (peer && from && peer->sort == BGP_PEER_IBGP &&
959 from->sort == BGP_PEER_IBGP &&
960 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
961 {
962 attr->extra = bgp_attr_extra_get(attr);
963 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
964 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
965 }
966
paul718e3742002-12-13 20:15:29 +0000967 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000968 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000969 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
970 {
971 if (ri->peer != bgp->peer_self && ! transparent
972 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
973 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
974 }
975
Lou Berger298cc2f2016-01-12 13:42:02 -0500976
977#define NEXTHOP_IS_V4 (\
978 (safi != SAFI_ENCAP && p->family == AF_INET) || \
979 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
980
Lou Berger298cc2f2016-01-12 13:42:02 -0500981#define NEXTHOP_IS_V6 (\
982 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
983 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
Lou Berger298cc2f2016-01-12 13:42:02 -0500984
paul718e3742002-12-13 20:15:29 +0000985 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300986 if (transparent
987 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000988 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500989 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
Lou Berger298cc2f2016-01-12 13:42:02 -0500990 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000991 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -0500997 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001000 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001001 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1002 {
1003 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001004 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001005 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001006 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1008 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001009 else
1010 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1011 }
paul718e3742002-12-13 20:15:29 +00001012 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001013 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001014 {
1015 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001017 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001019 }
paul718e3742002-12-13 20:15:29 +00001020 }
1021
Lou Berger298cc2f2016-01-12 13:42:02 -05001022 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001023 {
paulfee0f4c2004-09-13 05:12:46 +00001024 /* Left nexthop_local unchanged if so configured. */
1025 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1026 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1029 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001030 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001031 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001032 }
1033
1034 /* Default nexthop_local treatment for non-RS-Clients */
1035 else
1036 {
paul718e3742002-12-13 20:15:29 +00001037 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001039
1040 /* Set link-local address for shared network peer. */
1041 if (peer->shared_network
1042 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001045 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001047 }
1048
1049 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1050 address.*/
1051 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001052 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001053
1054 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1055 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001056 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001057 }
paulfee0f4c2004-09-13 05:12:46 +00001058
1059 }
paul718e3742002-12-13 20:15:29 +00001060
1061 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001062 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001063 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1064 && aspath_private_as_check (attr->aspath))
1065 attr->aspath = aspath_empty_get ();
1066
1067 /* Route map & unsuppress-map apply. */
1068 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001069 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001070 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001071 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001072 struct attr dummy_attr;
1073 struct attr_extra dummy_extra;
1074
1075 dummy_attr.extra = &dummy_extra;
1076
paul718e3742002-12-13 20:15:29 +00001077 info.peer = peer;
1078 info.attr = attr;
1079
1080 /* The route reflector is not allowed to modify the attributes
Dinesh Dutt083e5e22015-11-09 20:21:54 -05001081 of the reflected IBGP routes, unless configured to allow it */
1082 if ((from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP) &&
1083 !bgp_flag_check(bgp, BGP_FLAG_RR_ALLOW_OUTBOUND_POLICY))
paul718e3742002-12-13 20:15:29 +00001084 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001085 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001086 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001087 }
paulac41b2a2003-08-12 05:32:27 +00001088
1089 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1090
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001092 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1093 else
1094 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1095
paulac41b2a2003-08-12 05:32:27 +00001096 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001097
paul718e3742002-12-13 20:15:29 +00001098 if (ret == RMAP_DENYMATCH)
1099 {
1100 bgp_attr_flush (attr);
1101 return 0;
1102 }
1103 }
1104 return 1;
1105}
1106
paul94f2b392005-06-28 12:44:16 +00001107static int
paulfee0f4c2004-09-13 05:12:46 +00001108bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1109 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001110{
paulfee0f4c2004-09-13 05:12:46 +00001111 int ret;
1112 char buf[SU_ADDRSTRLEN];
1113 struct bgp_filter *filter;
1114 struct bgp_info info;
1115 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001116 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001117
1118 from = ri->peer;
1119 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001120 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001121
Paul Jakma750e8142008-07-22 21:11:48 +00001122 if (DISABLE_BGP_ANNOUNCE)
1123 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001124
1125 /* Do not send back route to sender. */
1126 if (from == rsclient)
1127 return 0;
1128
1129 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001130 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001131 if (! UNSUPPRESS_MAP_NAME (filter))
1132 return 0;
1133
1134 /* Default route check. */
1135 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1136 PEER_STATUS_DEFAULT_ORIGINATE))
1137 {
1138 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1139 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001140 else if (p->family == AF_INET6 && p->prefixlen == 0)
1141 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001142 }
1143
1144 /* If the attribute has originator-id and it is same as remote
1145 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001146 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001148 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001149 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159 }
1160
1161 /* ORF prefix-list filter check */
1162 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1163 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1164 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1165 if (rsclient->orf_plist[afi][safi])
1166 {
1167 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1168 return 0;
1169 }
1170
1171 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001172 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001173 {
1174 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001175 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001176 "%s [Update:SEND] %s/%d is filtered",
1177 rsclient->host,
1178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1179 p->prefixlen);
1180 return 0;
1181 }
1182
1183#ifdef BGP_SEND_ASPATH_CHECK
1184 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001185 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001186 {
1187 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001188 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001189 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001190 rsclient->host, rsclient->as);
1191 return 0;
1192 }
1193#endif /* BGP_SEND_ASPATH_CHECK */
1194
1195 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001196 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001197
1198 /* next-hop-set */
1199 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
paulfee0f4c2004-09-13 05:12:46 +00001200 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001202 )
1203 {
1204 /* Set IPv4 nexthop. */
1205 if (p->family == AF_INET)
1206 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001207 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001208 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001209 IPV4_MAX_BYTELEN);
1210 else
1211 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1212 }
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Set IPv6 nexthop. */
1214 if (p->family == AF_INET6)
1215 {
1216 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001218 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001220 }
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
paulfee0f4c2004-09-13 05:12:46 +00001223 if (p->family == AF_INET6)
1224 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001226
paulfee0f4c2004-09-13 05:12:46 +00001227 /* Left nexthop_local unchanged if so configured. */
1228 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1229 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Default nexthop_local treatment for RS-Clients */
1238 else
1239 {
1240 /* Announcer and RS-Client are both in the same network */
1241 if (rsclient->shared_network && from->shared_network &&
1242 (rsclient->ifindex == from->ifindex))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Set link-local address for shared network peer. */
1251 else if (rsclient->shared_network
1252 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1253 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001254 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001255 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001256 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001257 }
1258
1259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 }
paulfee0f4c2004-09-13 05:12:46 +00001264
1265 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001266 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001267 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1268 && aspath_private_as_check (attr->aspath))
1269 attr->aspath = aspath_empty_get ();
1270
1271 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001273 {
1274 info.peer = rsclient;
1275 info.attr = attr;
1276
1277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1278
Paul Jakmafb982c22007-05-04 20:15:47 +00001279 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001280 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1281 else
1282 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1283
1284 rsclient->rmap_type = 0;
1285
1286 if (ret == RMAP_DENYMATCH)
1287 {
1288 bgp_attr_flush (attr);
1289 return 0;
1290 }
1291 }
1292
1293 return 1;
1294}
1295
1296struct bgp_info_pair
1297{
1298 struct bgp_info *old;
1299 struct bgp_info *new;
1300};
1301
paul94f2b392005-06-28 12:44:16 +00001302static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001303bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001304 struct bgp_info_pair *result,
1305 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001306{
paul718e3742002-12-13 20:15:29 +00001307 struct bgp_info *new_select;
1308 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001309 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001310 struct bgp_info *ri1;
1311 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001312 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001313 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001314 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001315
1316 result->old = result->new = NULL;
1317
1318 if (rn->info == NULL)
1319 {
1320 char buf[PREFIX_STRLEN];
1321 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1322 __func__,
1323 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1324 return;
1325 }
1326
Josh Bailey96450fa2011-07-20 20:45:12 -07001327 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001329
paul718e3742002-12-13 20:15:29 +00001330 /* bgp deterministic-med */
1331 new_select = NULL;
1332 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1333 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1334 {
1335 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1336 continue;
1337 if (BGP_INFO_HOLDDOWN (ri1))
1338 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001339 if (ri1->peer && ri1->peer != bgp->peer_self)
1340 if (ri1->peer->status != Established)
1341 continue;
paul718e3742002-12-13 20:15:29 +00001342
1343 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath)
1345 bgp_mp_list_add (&mp_list, ri1);
1346 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001347 if (ri1->next)
1348 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1349 {
1350 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri2))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri2->peer &&
1355 ri2->peer != bgp->peer_self &&
1356 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1357 if (ri2->peer->status != Established)
1358 continue;
paul718e3742002-12-13 20:15:29 +00001359
1360 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1361 || aspath_cmp_left_confed (ri1->attr->aspath,
1362 ri2->attr->aspath))
1363 {
Josh Bailey6918e742011-07-20 20:48:20 -07001364 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1365 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001366 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1367 == -1)
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
1371 }
1372
Paul Jakma6d4742b2015-11-25 17:14:37 +00001373 if (do_mpath)
1374 {
1375 if (cmpret != 0)
1376 bgp_mp_list_clear (&mp_list);
1377
1378 if (cmpret == 0 || cmpret == -1)
1379 bgp_mp_list_add (&mp_list, ri2);
1380 }
Josh Bailey6918e742011-07-20 20:48:20 -07001381
Paul Jakma1a392d42006-09-07 00:24:49 +00001382 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001383 }
1384 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1386 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001389 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001390 }
1391
1392 /* Check old selected route and new selected route. */
1393 old_select = NULL;
1394 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001395 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001396 {
1397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1398 old_select = ri;
1399
1400 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001401 {
1402 /* reap REMOVED routes, if needs be
1403 * selected route must stay for a while longer though
1404 */
1405 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1406 && (ri != old_select))
1407 bgp_info_reap (rn, ri);
1408
1409 continue;
1410 }
paul718e3742002-12-13 20:15:29 +00001411
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001412 if (ri->peer &&
1413 ri->peer != bgp->peer_self &&
1414 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1415 if (ri->peer->status != Established)
1416 continue;
1417
paul718e3742002-12-13 20:15:29 +00001418 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1419 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1420 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001421 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001422 continue;
1423 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001424 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1425 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001426
Paul Jakma6d4742b2015-11-25 17:14:37 +00001427 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001428 {
Josh Bailey6918e742011-07-20 20:48:20 -07001429 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1430 bgp_mp_dmed_deselect (new_select);
1431
Josh Bailey96450fa2011-07-20 20:45:12 -07001432 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001433 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001434 else if (cmpret == 1 && do_mpath
1435 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001436 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001437
Paul Jakma6d4742b2015-11-25 17:14:37 +00001438 if (do_mpath)
1439 {
1440 if (cmpret != 0)
1441 bgp_mp_list_clear (&mp_list);
1442
1443 if (cmpret == 0 || cmpret == -1)
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
paul718e3742002-12-13 20:15:29 +00001446 }
paulfee0f4c2004-09-13 05:12:46 +00001447
Josh Bailey6918e742011-07-20 20:48:20 -07001448 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001450
Josh Bailey0b597ef2011-07-20 20:49:11 -07001451 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452 bgp_mp_list_clear (&mp_list);
1453
1454 result->old = old_select;
1455 result->new = new_select;
1456
1457 return;
paulfee0f4c2004-09-13 05:12:46 +00001458}
1459
paul94f2b392005-06-28 12:44:16 +00001460static int
paulfee0f4c2004-09-13 05:12:46 +00001461bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 struct bgp_node *rn, afi_t afi, safi_t safi)
1463{
paulfee0f4c2004-09-13 05:12:46 +00001464 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001465 struct attr attr;
1466 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001467
Lou Berger050defe2016-01-12 13:41:59 -05001468 memset (&attr, 0, sizeof(struct attr));
1469 memset (&extra, 0, sizeof(struct attr_extra));
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 p = &rn->p;
1472
Paul Jakma9eda90c2007-08-30 13:36:17 +00001473 /* Announce route to Established peer. */
1474 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001475 return 0;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Address family configuration check. */
1478 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001482 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1483 PEER_STATUS_ORF_WAIT_REFRESH))
1484 return 0;
1485
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001486 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1487 attr.extra = &extra;
1488
Avneesh Sachdev67174042012-08-17 08:19:49 -07001489 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001490 {
1491 case BGP_TABLE_MAIN:
1492 /* Announcement to peer->conf. If the route is filtered,
1493 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001494 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1495 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001496 else
1497 bgp_adj_out_unset (rn, peer, p, afi, safi);
1498 break;
1499 case BGP_TABLE_RSCLIENT:
1500 /* Announcement to peer->conf. If the route is filtered,
1501 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001502 if (selected &&
1503 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1504 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1505 else
1506 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001507 break;
1508 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001509
Lou Berger050defe2016-01-12 13:41:59 -05001510 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001511 return 0;
paul200df112005-06-01 11:17:05 +00001512}
paulfee0f4c2004-09-13 05:12:46 +00001513
paul200df112005-06-01 11:17:05 +00001514struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001515{
paul200df112005-06-01 11:17:05 +00001516 struct bgp *bgp;
1517 struct bgp_node *rn;
1518 afi_t afi;
1519 safi_t safi;
1520};
1521
1522static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001523bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001524{
paul0fb58d52005-11-14 14:31:49 +00001525 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001526 struct bgp *bgp = pq->bgp;
1527 struct bgp_node *rn = pq->rn;
1528 afi_t afi = pq->afi;
1529 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct bgp_info *new_select;
1531 struct bgp_info *old_select;
1532 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001533 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001534 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001535
paulfee0f4c2004-09-13 05:12:46 +00001536 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001537 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001538 new_select = old_and_new.new;
1539 old_select = old_and_new.old;
1540
paul200df112005-06-01 11:17:05 +00001541 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1542 {
Chris Caputo228da422009-07-18 05:44:03 +00001543 if (rsclient->group)
1544 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1545 {
1546 /* Nothing to do. */
1547 if (old_select && old_select == new_select)
1548 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1549 continue;
paulfee0f4c2004-09-13 05:12:46 +00001550
Chris Caputo228da422009-07-18 05:44:03 +00001551 if (old_select)
1552 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1553 if (new_select)
1554 {
1555 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1556 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001557 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1558 }
paulfee0f4c2004-09-13 05:12:46 +00001559
Chris Caputo228da422009-07-18 05:44:03 +00001560 bgp_process_announce_selected (rsclient, new_select, rn,
1561 afi, safi);
1562 }
paul200df112005-06-01 11:17:05 +00001563 }
1564 else
1565 {
hassob7395792005-08-26 12:58:38 +00001566 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001568 if (new_select)
1569 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001573 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001574 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001575 }
paulfee0f4c2004-09-13 05:12:46 +00001576
paulb40d9392005-08-22 22:34:41 +00001577 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1578 bgp_info_reap (rn, old_select);
1579
paul200df112005-06-01 11:17:05 +00001580 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1581 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001582}
1583
paul200df112005-06-01 11:17:05 +00001584static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001585bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001586{
paul0fb58d52005-11-14 14:31:49 +00001587 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001588 struct bgp *bgp = pq->bgp;
1589 struct bgp_node *rn = pq->rn;
1590 afi_t afi = pq->afi;
1591 safi_t safi = pq->safi;
1592 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001593 struct bgp_info *new_select;
1594 struct bgp_info *old_select;
1595 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001596 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001597 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001598
paulfee0f4c2004-09-13 05:12:46 +00001599 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001600 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001601 old_select = old_and_new.old;
1602 new_select = old_and_new.new;
1603
1604 /* Nothing to do. */
Daniel Walton325fcfb2015-05-19 17:58:10 -07001605 if (old_select && old_select == new_select
1606 && !CHECK_FLAG(rn->flags, BGP_NODE_USER_CLEAR))
paulfee0f4c2004-09-13 05:12:46 +00001607 {
1608 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001609 {
Josh Bailey8196f132011-07-20 20:47:07 -07001610 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1611 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001612 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001613
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001615 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1616 return WQ_SUCCESS;
1617 }
paulfee0f4c2004-09-13 05:12:46 +00001618 }
paul718e3742002-12-13 20:15:29 +00001619
Daniel Walton325fcfb2015-05-19 17:58:10 -07001620 /* If the user did "clear ip bgp prefix x.x.x.x" this flag will be set */
1621 UNSET_FLAG(rn->flags, BGP_NODE_USER_CLEAR);
1622
hasso338b3422005-02-23 14:27:24 +00001623 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001624 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001625 if (new_select)
1626 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001627 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1628 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001629 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001630 }
1631
1632
paul718e3742002-12-13 20:15:29 +00001633 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001634 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001635 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001636 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001637 }
1638
1639 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001640 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1641 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001642 {
1643 if (new_select
1644 && new_select->type == ZEBRA_ROUTE_BGP
1645 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001646 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001647 else
1648 {
1649 /* Withdraw the route from the kernel. */
1650 if (old_select
1651 && old_select->type == ZEBRA_ROUTE_BGP
1652 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001654 }
1655 }
paulb40d9392005-08-22 22:34:41 +00001656
Lou Berger050defe2016-01-12 13:41:59 -05001657 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001658 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1659 bgp_info_reap (rn, old_select);
1660
paul200df112005-06-01 11:17:05 +00001661 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1662 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001663}
1664
paul200df112005-06-01 11:17:05 +00001665static void
paul0fb58d52005-11-14 14:31:49 +00001666bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001667{
paul0fb58d52005-11-14 14:31:49 +00001668 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001669 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001670
Chris Caputo228da422009-07-18 05:44:03 +00001671 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001672 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001673 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001674 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1675}
1676
1677static void
1678bgp_process_queue_init (void)
1679{
1680 bm->process_main_queue
1681 = work_queue_new (bm->master, "process_main_queue");
1682 bm->process_rsclient_queue
1683 = work_queue_new (bm->master, "process_rsclient_queue");
1684
1685 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1686 {
1687 zlog_err ("%s: Failed to allocate work queue", __func__);
1688 exit (1);
1689 }
1690
1691 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001692 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001693 bm->process_main_queue->spec.max_retries = 0;
1694 bm->process_main_queue->spec.hold = 50;
1695
Paul Jakma838bbde2010-01-08 14:05:32 +00001696 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001697 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1698 bm->process_rsclient_queue->spec.max_retries = 0;
1699 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001700}
1701
1702void
paulfee0f4c2004-09-13 05:12:46 +00001703bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1704{
paul200df112005-06-01 11:17:05 +00001705 struct bgp_process_queue *pqnode;
1706
1707 /* already scheduled for processing? */
1708 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1709 return;
1710
Paul Jakma91b9e852015-12-01 14:32:11 +00001711 if (rn->info == NULL)
1712 {
1713 /* XXX: Perhaps remove before next release, after we've flushed out
1714 * any obvious cases
1715 */
1716 assert (rn->info != NULL);
1717 char buf[PREFIX_STRLEN];
1718 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1719 __func__,
1720 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1721 return;
1722 }
1723
paul200df112005-06-01 11:17:05 +00001724 if ( (bm->process_main_queue == NULL) ||
1725 (bm->process_rsclient_queue == NULL) )
1726 bgp_process_queue_init ();
1727
1728 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1729 sizeof (struct bgp_process_queue));
1730 if (!pqnode)
1731 return;
Chris Caputo228da422009-07-18 05:44:03 +00001732
1733 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001734 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001735 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001736 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001737 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001738 pqnode->afi = afi;
1739 pqnode->safi = safi;
1740
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001742 {
paul200df112005-06-01 11:17:05 +00001743 case BGP_TABLE_MAIN:
1744 work_queue_add (bm->process_main_queue, pqnode);
1745 break;
1746 case BGP_TABLE_RSCLIENT:
1747 work_queue_add (bm->process_rsclient_queue, pqnode);
1748 break;
paulfee0f4c2004-09-13 05:12:46 +00001749 }
paul200df112005-06-01 11:17:05 +00001750
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001751 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001752 return;
paulfee0f4c2004-09-13 05:12:46 +00001753}
hasso0a486e52005-02-01 20:57:17 +00001754
paul94f2b392005-06-28 12:44:16 +00001755static int
hasso0a486e52005-02-01 20:57:17 +00001756bgp_maximum_prefix_restart_timer (struct thread *thread)
1757{
1758 struct peer *peer;
1759
1760 peer = THREAD_ARG (thread);
1761 peer->t_pmax_restart = NULL;
1762
1763 if (BGP_DEBUG (events, EVENTS))
1764 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1765 peer->host);
1766
1767 peer_clear (peer);
1768
1769 return 0;
1770}
1771
paulfee0f4c2004-09-13 05:12:46 +00001772int
paul5228ad22004-06-04 17:58:18 +00001773bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1774 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001775{
hassoe0701b72004-05-20 09:19:34 +00001776 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1777 return 0;
1778
1779 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001780 {
hassoe0701b72004-05-20 09:19:34 +00001781 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1782 && ! always)
1783 return 0;
paul718e3742002-12-13 20:15:29 +00001784
hassoe0701b72004-05-20 09:19:34 +00001785 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001786 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1787 "limit %ld", afi_safi_print (afi, safi), peer->host,
1788 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001789 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001790
hassoe0701b72004-05-20 09:19:34 +00001791 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1792 return 0;
paul718e3742002-12-13 20:15:29 +00001793
hassoe0701b72004-05-20 09:19:34 +00001794 {
paul5228ad22004-06-04 17:58:18 +00001795 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001796
1797 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001798 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001799
1800 ndata[0] = (afi >> 8);
1801 ndata[1] = afi;
1802 ndata[2] = safi;
1803 ndata[3] = (peer->pmax[afi][safi] >> 24);
1804 ndata[4] = (peer->pmax[afi][safi] >> 16);
1805 ndata[5] = (peer->pmax[afi][safi] >> 8);
1806 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001807
1808 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1809 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1810 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1811 }
hasso0a486e52005-02-01 20:57:17 +00001812
1813 /* restart timer start */
1814 if (peer->pmax_restart[afi][safi])
1815 {
1816 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1817
1818 if (BGP_DEBUG (events, EVENTS))
1819 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1820 peer->host, peer->v_pmax_restart);
1821
1822 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1823 peer->v_pmax_restart);
1824 }
1825
hassoe0701b72004-05-20 09:19:34 +00001826 return 1;
paul718e3742002-12-13 20:15:29 +00001827 }
hassoe0701b72004-05-20 09:19:34 +00001828 else
1829 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1830
1831 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1832 {
1833 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1834 && ! always)
1835 return 0;
1836
1837 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001838 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1839 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1840 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001841 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1842 }
1843 else
1844 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001845 return 0;
1846}
1847
paulb40d9392005-08-22 22:34:41 +00001848/* Unconditionally remove the route from the RIB, without taking
1849 * damping into consideration (eg, because the session went down)
1850 */
paul94f2b392005-06-28 12:44:16 +00001851static void
paul718e3742002-12-13 20:15:29 +00001852bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1853 afi_t afi, safi_t safi)
1854{
paul902212c2006-02-05 17:51:19 +00001855 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1856
1857 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1858 bgp_info_delete (rn, ri); /* keep historical info */
1859
paulb40d9392005-08-22 22:34:41 +00001860 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001861}
1862
paul94f2b392005-06-28 12:44:16 +00001863static void
paul718e3742002-12-13 20:15:29 +00001864bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001865 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001866{
paul718e3742002-12-13 20:15:29 +00001867 int status = BGP_DAMP_NONE;
1868
paulb40d9392005-08-22 22:34:41 +00001869 /* apply dampening, if result is suppressed, we'll be retaining
1870 * the bgp_info in the RIB for historical reference.
1871 */
1872 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001873 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001874 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1875 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001876 {
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878 return;
1879 }
1880
1881 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001882}
1883
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05001884static struct bgp_info *
1885info_make (int type, int sub_type, struct peer *peer, struct attr *attr,
1886 struct bgp_node *rn)
1887{
1888 struct bgp_info *new;
1889
1890 /* Make new BGP info. */
1891 new = XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
1892 new->type = type;
1893 new->sub_type = sub_type;
1894 new->peer = peer;
1895 new->attr = attr;
1896 new->uptime = bgp_clock ();
1897 new->net = rn;
1898 return new;
1899}
1900
paul94f2b392005-06-28 12:44:16 +00001901static void
paulfee0f4c2004-09-13 05:12:46 +00001902bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1903 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1904 int sub_type, struct prefix_rd *prd, u_char *tag)
1905{
1906 struct bgp_node *rn;
1907 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001908 struct attr new_attr;
1909 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001910 struct attr *attr_new;
1911 struct attr *attr_new2;
1912 struct bgp_info *ri;
1913 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001914 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001915 char buf[SU_ADDRSTRLEN];
1916
1917 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1918 if (peer == rsclient)
1919 return;
1920
1921 bgp = peer->bgp;
1922 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1923
1924 /* Check previously received route. */
1925 for (ri = rn->info; ri; ri = ri->next)
1926 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1927 break;
1928
1929 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001930 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001931 {
1932 reason = "as-path contains our own AS;";
1933 goto filtered;
1934 }
1935
1936 /* Route reflector originator ID check. */
1937 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001938 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001939 {
1940 reason = "originator is us;";
1941 goto filtered;
1942 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001943
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001944 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001945 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Apply export policy. */
1948 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1949 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1950 {
1951 reason = "export-policy;";
1952 goto filtered;
1953 }
1954
1955 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001956
paulfee0f4c2004-09-13 05:12:46 +00001957 /* Apply import policy. */
1958 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1959 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001960 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001961
1962 reason = "import-policy;";
1963 goto filtered;
1964 }
1965
1966 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001967 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001968
1969 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001970 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001971 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001972 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001973 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001974 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001975 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001976 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 reason = "martian next-hop;";
1979 goto filtered;
1980 }
1981 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001982
paulfee0f4c2004-09-13 05:12:46 +00001983 /* If the update is implicit withdraw. */
1984 if (ri)
1985 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001986 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001987
1988 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001989 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1990 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001991 {
1992
Paul Jakma1a392d42006-09-07 00:24:49 +00001993 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001994
1995 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001996 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001997 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1998 peer->host,
1999 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2000 p->prefixlen, rsclient->host);
2001
Chris Caputo228da422009-07-18 05:44:03 +00002002 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002003 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002004 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002005 return;
paulfee0f4c2004-09-13 05:12:46 +00002006 }
2007
Paul Jakma16d2e242007-04-10 19:32:10 +00002008 /* Withdraw/Announce before we fully processed the withdraw */
2009 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2010 bgp_info_restore (rn, ri);
2011
paulfee0f4c2004-09-13 05:12:46 +00002012 /* Received Logging. */
2013 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002014 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002015 peer->host,
2016 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2017 p->prefixlen, rsclient->host);
2018
2019 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002021
2022 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002023 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002024 ri->attr = attr_new;
2025
2026 /* Update MPLS tag. */
2027 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002028 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002029
Paul Jakma1a392d42006-09-07 00:24:49 +00002030 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002031
2032 /* Process change. */
2033 bgp_process (bgp, rn, afi, safi);
2034 bgp_unlock_node (rn);
2035
2036 return;
2037 }
2038
2039 /* Received Logging. */
2040 if (BGP_DEBUG (update, UPDATE_IN))
2041 {
ajsd2c1f162004-12-08 21:10:20 +00002042 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002043 peer->host,
2044 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2045 p->prefixlen, rsclient->host);
2046 }
2047
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002048 new = info_make(type, sub_type, peer, attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00002049
2050 /* Update MPLS tag. */
2051 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002053
Paul Jakma1a392d42006-09-07 00:24:49 +00002054 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002055
2056 /* Register new BGP information. */
2057 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002058
2059 /* route_node_get lock */
2060 bgp_unlock_node (rn);
2061
paulfee0f4c2004-09-13 05:12:46 +00002062 /* Process change. */
2063 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002064
paulfee0f4c2004-09-13 05:12:46 +00002065 return;
2066
2067 filtered:
2068
2069 /* This BGP update is filtered. Log the reason then update BGP entry. */
2070 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002071 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002072 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2073 peer->host,
2074 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2075 p->prefixlen, rsclient->host, reason);
2076
2077 if (ri)
paulb40d9392005-08-22 22:34:41 +00002078 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002079
2080 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002081
paulfee0f4c2004-09-13 05:12:46 +00002082 return;
2083}
2084
paul94f2b392005-06-28 12:44:16 +00002085static void
paulfee0f4c2004-09-13 05:12:46 +00002086bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2087 struct peer *peer, struct prefix *p, int type, int sub_type,
2088 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002089{
paulfee0f4c2004-09-13 05:12:46 +00002090 struct bgp_node *rn;
2091 struct bgp_info *ri;
2092 char buf[SU_ADDRSTRLEN];
2093
2094 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002095 return;
paulfee0f4c2004-09-13 05:12:46 +00002096
2097 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2098
2099 /* Lookup withdrawn route. */
2100 for (ri = rn->info; ri; ri = ri->next)
2101 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2102 break;
2103
2104 /* Withdraw specified route from routing table. */
2105 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002106 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002107 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002108 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002109 "%s Can't find the route %s/%d", peer->host,
2110 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2111 p->prefixlen);
2112
2113 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002114 bgp_unlock_node (rn);
2115}
paulfee0f4c2004-09-13 05:12:46 +00002116
paul94f2b392005-06-28 12:44:16 +00002117static int
paulfee0f4c2004-09-13 05:12:46 +00002118bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002119 afi_t afi, safi_t safi, int type, int sub_type,
2120 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2121{
2122 int ret;
2123 int aspath_loop_count = 0;
2124 struct bgp_node *rn;
2125 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002126 struct attr new_attr;
2127 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002128 struct attr *attr_new;
2129 struct bgp_info *ri;
2130 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002131 const char *reason;
paul718e3742002-12-13 20:15:29 +00002132 char buf[SU_ADDRSTRLEN];
2133
Lou Berger370b7e52016-02-04 21:29:49 -05002134 memset (&new_attr, 0, sizeof(struct attr));
2135 memset (&new_extra, 0, sizeof(struct attr_extra));
2136
paul718e3742002-12-13 20:15:29 +00002137 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002138 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002139
paul718e3742002-12-13 20:15:29 +00002140 /* When peer's soft reconfiguration enabled. Record input packet in
2141 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002142 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2143 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002144 bgp_adj_in_set (rn, peer, attr);
2145
2146 /* Check previously received route. */
2147 for (ri = rn->info; ri; ri = ri->next)
2148 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2149 break;
2150
2151 /* AS path local-as loop check. */
2152 if (peer->change_local_as)
2153 {
2154 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2155 aspath_loop_count = 1;
2156
2157 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2158 {
2159 reason = "as-path contains our own AS;";
2160 goto filtered;
2161 }
2162 }
2163
2164 /* AS path loop check. */
2165 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2166 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2167 && aspath_loop_check(attr->aspath, bgp->confed_id)
2168 > peer->allowas_in[afi][safi]))
2169 {
2170 reason = "as-path contains our own AS;";
2171 goto filtered;
2172 }
2173
2174 /* Route reflector originator ID check. */
2175 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002176 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002177 {
2178 reason = "originator is us;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector cluster ID check. */
2183 if (bgp_cluster_filter (peer, attr))
2184 {
2185 reason = "reflected from the same cluster;";
2186 goto filtered;
2187 }
2188
2189 /* Apply incoming filter. */
2190 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2191 {
2192 reason = "filter;";
2193 goto filtered;
2194 }
2195
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002196 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002197 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002198
David Lamparterc460e572014-06-04 00:54:58 +02002199 /* Apply incoming route-map.
2200 * NB: new_attr may now contain newly allocated values from route-map "set"
2201 * commands, so we need bgp_attr_flush in the error paths, until we intern
2202 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002203 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2204 {
2205 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002206 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002207 goto filtered;
2208 }
2209
2210 /* IPv4 unicast next hop check. */
2211 if (afi == AFI_IP && safi == SAFI_UNICAST)
2212 {
2213 /* If the peer is EBGP and nexthop is not on connected route,
2214 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002215 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002216 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002217 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002218 {
2219 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002220 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002221 goto filtered;
2222 }
2223
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002224 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002225 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002226 if (new_attr.nexthop.s_addr == 0
2227 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2228 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002229 {
2230 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002231 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002232 goto filtered;
2233 }
2234 }
2235
2236 attr_new = bgp_attr_intern (&new_attr);
2237
2238 /* If the update is implicit withdraw. */
2239 if (ri)
2240 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002241 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002242
2243 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002244 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2245 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002246 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002247 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002248
2249 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002250 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002251 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 {
2253 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002254 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002255 peer->host,
2256 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2257 p->prefixlen);
2258
paul902212c2006-02-05 17:51:19 +00002259 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2260 {
2261 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2262 bgp_process (bgp, rn, afi, safi);
2263 }
paul718e3742002-12-13 20:15:29 +00002264 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002265 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002266 {
2267 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002268 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002269 "%s rcvd %s/%d...duplicate ignored",
2270 peer->host,
2271 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2272 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002273
2274 /* graceful restart STALE flag unset. */
2275 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2276 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002277 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002278 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002279 }
paul718e3742002-12-13 20:15:29 +00002280 }
2281
2282 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002283 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002284 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002285
paul718e3742002-12-13 20:15:29 +00002286 return 0;
2287 }
2288
Paul Jakma16d2e242007-04-10 19:32:10 +00002289 /* Withdraw/Announce before we fully processed the withdraw */
2290 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2291 {
2292 if (BGP_DEBUG (update, UPDATE_IN))
2293 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2294 peer->host,
2295 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2296 p->prefixlen);
2297 bgp_info_restore (rn, ri);
2298 }
2299
paul718e3742002-12-13 20:15:29 +00002300 /* Received Logging. */
2301 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002302 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002303 peer->host,
2304 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2305 p->prefixlen);
2306
hasso93406d82005-02-02 14:40:33 +00002307 /* graceful restart STALE flag unset. */
2308 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002310
paul718e3742002-12-13 20:15:29 +00002311 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002312 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002313
2314 /* implicit withdraw, decrement aggregate and pcount here.
2315 * only if update is accepted, they'll increment below.
2316 */
paul902212c2006-02-05 17:51:19 +00002317 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2318
paul718e3742002-12-13 20:15:29 +00002319 /* Update bgp route dampening information. */
2320 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002321 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002322 {
2323 /* This is implicit withdraw so we should update dampening
2324 information. */
2325 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2326 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002327 }
2328
paul718e3742002-12-13 20:15:29 +00002329 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002330 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002331 ri->attr = attr_new;
2332
2333 /* Update MPLS tag. */
2334 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002335 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002336
Lou Berger050defe2016-01-12 13:41:59 -05002337 bgp_attr_flush (&new_attr);
2338
paul718e3742002-12-13 20:15:29 +00002339 /* Update bgp route dampening information. */
2340 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002341 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002342 {
2343 /* Now we do normal update dampening. */
2344 ret = bgp_damp_update (ri, rn, afi, safi);
2345 if (ret == BGP_DAMP_SUPPRESSED)
2346 {
2347 bgp_unlock_node (rn);
2348 return 0;
2349 }
2350 }
2351
2352 /* Nexthop reachability check. */
2353 if ((afi == AFI_IP || afi == AFI_IP6)
2354 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002355 && (peer->sort == BGP_PEER_IBGP
2356 || peer->sort == BGP_PEER_CONFED
2357 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002358 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002359 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002360 if (bgp_find_or_add_nexthop (afi, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002361 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364 }
2365 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002366 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002367
Lou Berger050defe2016-01-12 13:41:59 -05002368 bgp_attr_flush (&new_attr);
2369
paul718e3742002-12-13 20:15:29 +00002370 /* Process change. */
2371 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2372
2373 bgp_process (bgp, rn, afi, safi);
2374 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002375
paul718e3742002-12-13 20:15:29 +00002376 return 0;
2377 }
2378
2379 /* Received Logging. */
2380 if (BGP_DEBUG (update, UPDATE_IN))
2381 {
ajsd2c1f162004-12-08 21:10:20 +00002382 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002383 peer->host,
2384 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2385 p->prefixlen);
2386 }
2387
paul718e3742002-12-13 20:15:29 +00002388 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002389 new = info_make(type, sub_type, peer, attr_new, rn);
paul718e3742002-12-13 20:15:29 +00002390
2391 /* Update MPLS tag. */
2392 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002393 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002394
2395 /* Nexthop reachability check. */
2396 if ((afi == AFI_IP || afi == AFI_IP6)
2397 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002398 && (peer->sort == BGP_PEER_IBGP
2399 || peer->sort == BGP_PEER_CONFED
2400 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002401 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002402 {
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05002403 if (bgp_find_or_add_nexthop (afi, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002404 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002405 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407 }
2408 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002409 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002410
paul902212c2006-02-05 17:51:19 +00002411 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002412 bgp_aggregate_increment (bgp, p, new, afi, safi);
2413
2414 /* Register new BGP information. */
2415 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002416
2417 /* route_node_get lock */
2418 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002419
Lou Berger050defe2016-01-12 13:41:59 -05002420 bgp_attr_flush (&new_attr);
2421
paul718e3742002-12-13 20:15:29 +00002422 /* If maximum prefix count is configured and current prefix
2423 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002424 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2425 return -1;
paul718e3742002-12-13 20:15:29 +00002426
2427 /* Process change. */
2428 bgp_process (bgp, rn, afi, safi);
2429
2430 return 0;
2431
2432 /* This BGP update is filtered. Log the reason then update BGP
2433 entry. */
2434 filtered:
2435 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002436 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002437 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2438 peer->host,
2439 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2440 p->prefixlen, reason);
2441
2442 if (ri)
paulb40d9392005-08-22 22:34:41 +00002443 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002444
2445 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002446 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002447
paul718e3742002-12-13 20:15:29 +00002448 return 0;
2449}
2450
2451int
paulfee0f4c2004-09-13 05:12:46 +00002452bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2453 afi_t afi, safi_t safi, int type, int sub_type,
2454 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2455{
2456 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002457 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002458 struct bgp *bgp;
2459 int ret;
2460
2461 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2462 soft_reconfig);
2463
2464 bgp = peer->bgp;
2465
2466 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002467 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002468 {
2469 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2470 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2471 sub_type, prd, tag);
2472 }
2473
2474 return ret;
2475}
2476
2477int
paul718e3742002-12-13 20:15:29 +00002478bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002479 afi_t afi, safi_t safi, int type, int sub_type,
2480 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002481{
2482 struct bgp *bgp;
2483 char buf[SU_ADDRSTRLEN];
2484 struct bgp_node *rn;
2485 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002486 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002487 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002488
2489 bgp = peer->bgp;
2490
David Lamparter4584c232015-04-13 09:50:00 +02002491 /* Lookup node. */
2492 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2493
2494 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2495 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2496 * the iteration over all RS clients.
2497 * Since we need to remove the entry from adj_in anyway, do that first and
2498 * if there was no entry, we don't need to do anything more. */
2499 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2500 && peer != bgp->peer_self)
2501 if (!bgp_adj_in_unset (rn, peer))
2502 {
2503 if (BGP_DEBUG (update, UPDATE_IN))
2504 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2505 "not in adj-in", peer->host,
2506 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2507 p->prefixlen);
2508 bgp_unlock_node (rn);
2509 return 0;
2510 }
2511
paulfee0f4c2004-09-13 05:12:46 +00002512 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002513 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002514 {
2515 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2516 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2517 }
2518
paul718e3742002-12-13 20:15:29 +00002519 /* Logging. */
2520 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002521 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002522 peer->host,
2523 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2524 p->prefixlen);
2525
paul718e3742002-12-13 20:15:29 +00002526 /* Lookup withdrawn route. */
2527 for (ri = rn->info; ri; ri = ri->next)
2528 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2529 break;
2530
2531 /* Withdraw specified route from routing table. */
2532 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002533 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002534 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002535 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002536 "%s Can't find the route %s/%d", peer->host,
2537 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2538 p->prefixlen);
2539
2540 /* Unlock bgp_node_get() lock. */
2541 bgp_unlock_node (rn);
2542
2543 return 0;
2544}
David Lamparter6b0655a2014-06-04 06:53:35 +02002545
paul718e3742002-12-13 20:15:29 +00002546void
2547bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2548{
2549 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002550 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002551 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002552 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002553 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002554 struct bgp_node *rn;
2555 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002556 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002557
Paul Jakmab2497022007-06-14 11:17:58 +00002558 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002559 return;
2560
paul718e3742002-12-13 20:15:29 +00002561 bgp = peer->bgp;
2562 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002563
paul718e3742002-12-13 20:15:29 +00002564 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2565 aspath = attr.aspath;
2566 attr.local_pref = bgp->default_local_pref;
2567 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2568
2569 if (afi == AFI_IP)
2570 str2prefix ("0.0.0.0/0", &p);
paul718e3742002-12-13 20:15:29 +00002571 else if (afi == AFI_IP6)
2572 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002573 struct attr_extra *ae = attr.extra;
2574
paul718e3742002-12-13 20:15:29 +00002575 str2prefix ("::/0", &p);
2576
2577 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002579 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002580 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002581
2582 /* If the peer is on shared nextwork and we have link-local
2583 nexthop set it. */
2584 if (peer->shared_network
2585 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2586 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002587 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002588 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002589 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002590 }
2591 }
paul718e3742002-12-13 20:15:29 +00002592
2593 if (peer->default_rmap[afi][safi].name)
2594 {
paulfee0f4c2004-09-13 05:12:46 +00002595 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2597 {
2598 for (ri = rn->info; ri; ri = ri->next)
2599 {
2600 struct attr dummy_attr;
2601 struct attr_extra dummy_extra;
2602 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002603
Christian Frankedcab1bb2012-12-07 16:45:52 +00002604 /* Provide dummy so the route-map can't modify the attributes */
2605 dummy_attr.extra = &dummy_extra;
2606 bgp_attr_dup(&dummy_attr, ri->attr);
2607 info.peer = ri->peer;
2608 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002609
Christian Frankedcab1bb2012-12-07 16:45:52 +00002610 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2611 RMAP_BGP, &info);
2612
2613 /* The route map might have set attributes. If we don't flush them
2614 * here, they will be leaked. */
2615 bgp_attr_flush(&dummy_attr);
2616 if (ret != RMAP_DENYMATCH)
2617 break;
2618 }
2619 if (ret != RMAP_DENYMATCH)
2620 break;
2621 }
paulfee0f4c2004-09-13 05:12:46 +00002622 bgp->peer_self->rmap_type = 0;
2623
paul718e3742002-12-13 20:15:29 +00002624 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002626 }
2627
2628 if (withdraw)
2629 {
2630 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2631 bgp_default_withdraw_send (peer, afi, safi);
2632 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2633 }
2634 else
2635 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002636 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2637 {
2638 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2639 bgp_default_update_send (peer, &attr, afi, safi, from);
2640 }
paul718e3742002-12-13 20:15:29 +00002641 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002642
2643 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002644 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002645}
David Lamparter6b0655a2014-06-04 06:53:35 +02002646
paul718e3742002-12-13 20:15:29 +00002647static void
2648bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002649 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002650{
2651 struct bgp_node *rn;
2652 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002653 struct attr attr;
2654 struct attr_extra extra;
2655
Lou Berger298cc2f2016-01-12 13:42:02 -05002656 memset(&extra, 0, sizeof(extra));
2657
paul718e3742002-12-13 20:15:29 +00002658 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002659 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002660
Lou Berger298cc2f2016-01-12 13:42:02 -05002661 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002662 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2663 bgp_default_originate (peer, afi, safi, 0);
2664
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002665 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2666 attr.extra = &extra;
2667
paul718e3742002-12-13 20:15:29 +00002668 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2669 for (ri = rn->info; ri; ri = ri->next)
2670 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2671 {
paulfee0f4c2004-09-13 05:12:46 +00002672 if ( (rsclient) ?
2673 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2674 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002675 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2676 else
2677 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2678 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002679
2680 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002681}
2682
2683void
2684bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2685{
2686 struct bgp_node *rn;
2687 struct bgp_table *table;
2688
2689 if (peer->status != Established)
2690 return;
2691
2692 if (! peer->afc_nego[afi][safi])
2693 return;
2694
2695 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2696 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2697 return;
2698
Lou Berger298cc2f2016-01-12 13:42:02 -05002699 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002700 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002701 else
2702 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2703 rn = bgp_route_next(rn))
2704 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_announce_table (peer, afi, safi, table, 0);
2706
2707 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2708 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002709}
2710
2711void
2712bgp_announce_route_all (struct peer *peer)
2713{
2714 afi_t afi;
2715 safi_t safi;
2716
2717 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2718 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2719 bgp_announce_route (peer, afi, safi);
2720}
David Lamparter6b0655a2014-06-04 06:53:35 +02002721
paul718e3742002-12-13 20:15:29 +00002722static void
paulfee0f4c2004-09-13 05:12:46 +00002723bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002724 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002725{
2726 struct bgp_node *rn;
2727 struct bgp_adj_in *ain;
2728
2729 if (! table)
2730 table = rsclient->bgp->rib[afi][safi];
2731
2732 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2733 for (ain = rn->adj_in; ain; ain = ain->next)
2734 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737
paulfee0f4c2004-09-13 05:12:46 +00002738 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002739 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002740 }
2741}
2742
2743void
2744bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2745{
2746 struct bgp_table *table;
2747 struct bgp_node *rn;
2748
Lou Berger298cc2f2016-01-12 13:42:02 -05002749 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002751
2752 else
2753 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2754 rn = bgp_route_next (rn))
2755 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 {
2757 struct prefix_rd prd;
2758 prd.family = AF_UNSPEC;
2759 prd.prefixlen = 64;
2760 memcpy(&prd.val, rn->p.u.val, 8);
2761
2762 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2763 }
paulfee0f4c2004-09-13 05:12:46 +00002764}
David Lamparter6b0655a2014-06-04 06:53:35 +02002765
paulfee0f4c2004-09-13 05:12:46 +00002766static void
paul718e3742002-12-13 20:15:29 +00002767bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002768 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002769{
2770 int ret;
2771 struct bgp_node *rn;
2772 struct bgp_adj_in *ain;
2773
2774 if (! table)
2775 table = peer->bgp->rib[afi][safi];
2776
2777 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2778 for (ain = rn->adj_in; ain; ain = ain->next)
2779 {
2780 if (ain->peer == peer)
2781 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002782 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2786 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002787 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002788
paul718e3742002-12-13 20:15:29 +00002789 if (ret < 0)
2790 {
2791 bgp_unlock_node (rn);
2792 return;
2793 }
2794 continue;
2795 }
2796 }
2797}
2798
2799void
2800bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2801{
2802 struct bgp_node *rn;
2803 struct bgp_table *table;
2804
2805 if (peer->status != Established)
2806 return;
2807
Lou Berger298cc2f2016-01-12 13:42:02 -05002808 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002809 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002810 else
2811 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2812 rn = bgp_route_next (rn))
2813 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002814 {
2815 struct prefix_rd prd;
2816 prd.family = AF_UNSPEC;
2817 prd.prefixlen = 64;
2818 memcpy(&prd.val, rn->p.u.val, 8);
2819
2820 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2821 }
paul718e3742002-12-13 20:15:29 +00002822}
David Lamparter6b0655a2014-06-04 06:53:35 +02002823
Chris Caputo228da422009-07-18 05:44:03 +00002824
2825struct bgp_clear_node_queue
2826{
2827 struct bgp_node *rn;
2828 enum bgp_clear_route_type purpose;
2829};
2830
paul200df112005-06-01 11:17:05 +00002831static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002837 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002838 afi_t afi = bgp_node_table (rn)->afi;
2839 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002840
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002842
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002844 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002845 {
2846 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2848 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002849 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002850 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2851 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002852 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002853 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002854 break;
2855 }
paul200df112005-06-01 11:17:05 +00002856 return WQ_SUCCESS;
2857}
2858
2859static void
paul0fb58d52005-11-14 14:31:49 +00002860bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002861{
Chris Caputo228da422009-07-18 05:44:03 +00002862 struct bgp_clear_node_queue *cnq = data;
2863 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002864 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002865
2866 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002867 bgp_table_unlock (table);
2868 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002869}
2870
2871static void
paul94f2b392005-06-28 12:44:16 +00002872bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002873{
Paul Jakma64e580a2006-02-21 01:09:01 +00002874 struct peer *peer = wq->spec.data;
2875
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002876 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002877 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002878
2879 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002880}
2881
2882static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002883bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002884{
Paul Jakmaa2943652009-07-21 14:02:04 +01002885 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002886
Paul Jakmaa2943652009-07-21 14:02:04 +01002887 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002888#undef CLEAR_QUEUE_NAME_LEN
2889
2890 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002891 {
2892 zlog_err ("%s: Failed to allocate work queue", __func__);
2893 exit (1);
2894 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002895 peer->clear_node_queue->spec.hold = 10;
2896 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2897 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2898 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2899 peer->clear_node_queue->spec.max_retries = 0;
2900
2901 /* we only 'lock' this peer reference when the queue is actually active */
2902 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002903}
2904
paul718e3742002-12-13 20:15:29 +00002905static void
2906bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002907 struct bgp_table *table, struct peer *rsclient,
2908 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002909{
2910 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002911
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002912
paul718e3742002-12-13 20:15:29 +00002913 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002914 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002915
hasso6cf159b2005-03-21 10:28:14 +00002916 /* If still no table => afi/safi isn't configured at all or smth. */
2917 if (! table)
2918 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002919
2920 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2921 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002922 struct bgp_info *ri;
2923 struct bgp_adj_in *ain;
2924 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002925
2926 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2927 * queued for every clearing peer, regardless of whether it is
2928 * relevant to the peer at hand.
2929 *
2930 * Overview: There are 3 different indices which need to be
2931 * scrubbed, potentially, when a peer is removed:
2932 *
2933 * 1 peer's routes visible via the RIB (ie accepted routes)
2934 * 2 peer's routes visible by the (optional) peer's adj-in index
2935 * 3 other routes visible by the peer's adj-out index
2936 *
2937 * 3 there is no hurry in scrubbing, once the struct peer is
2938 * removed from bgp->peer, we could just GC such deleted peer's
2939 * adj-outs at our leisure.
2940 *
2941 * 1 and 2 must be 'scrubbed' in some way, at least made
2942 * invisible via RIB index before peer session is allowed to be
2943 * brought back up. So one needs to know when such a 'search' is
2944 * complete.
2945 *
2946 * Ideally:
2947 *
2948 * - there'd be a single global queue or a single RIB walker
2949 * - rather than tracking which route_nodes still need to be
2950 * examined on a peer basis, we'd track which peers still
2951 * aren't cleared
2952 *
2953 * Given that our per-peer prefix-counts now should be reliable,
2954 * this may actually be achievable. It doesn't seem to be a huge
2955 * problem at this time,
2956 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002957 for (ain = rn->adj_in; ain; ain = ain->next)
2958 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2959 {
2960 bgp_adj_in_remove (rn, ain);
2961 bgp_unlock_node (rn);
2962 break;
2963 }
2964 for (aout = rn->adj_out; aout; aout = aout->next)
2965 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2966 {
2967 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2968 bgp_unlock_node (rn);
2969 break;
2970 }
2971
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002972 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002973 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 {
Chris Caputo228da422009-07-18 05:44:03 +00002975 struct bgp_clear_node_queue *cnq;
2976
2977 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002978 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002979 bgp_lock_node (rn);
2980 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2981 sizeof (struct bgp_clear_node_queue));
2982 cnq->rn = rn;
2983 cnq->purpose = purpose;
2984 work_queue_add (peer->clear_node_queue, cnq);
2985 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002986 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002987 }
2988 return;
2989}
2990
2991void
Chris Caputo228da422009-07-18 05:44:03 +00002992bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2993 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002994{
2995 struct bgp_node *rn;
2996 struct bgp_table *table;
2997 struct peer *rsclient;
2998 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002999
Paul Jakma64e580a2006-02-21 01:09:01 +00003000 if (peer->clear_node_queue == NULL)
3001 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003002
Paul Jakmaca058a32006-09-14 02:58:49 +00003003 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3004 * Idle until it receives a Clearing_Completed event. This protects
3005 * against peers which flap faster than we can we clear, which could
3006 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003007 *
3008 * a) race with routes from the new session being installed before
3009 * clear_route_node visits the node (to delete the route of that
3010 * peer)
3011 * b) resource exhaustion, clear_route_node likely leads to an entry
3012 * on the process_main queue. Fast-flapping could cause that queue
3013 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003014 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003015
3016 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3017 * the unlock will happen upon work-queue completion; other wise, the
3018 * unlock happens at the end of this function.
3019 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003020 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003021 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003022 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003023 {
Chris Caputo228da422009-07-18 05:44:03 +00003024 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003025 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003026 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3027 else
3028 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3029 rn = bgp_route_next (rn))
3030 if ((table = rn->info) != NULL)
3031 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3032
3033 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3034 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3035 PEER_FLAG_RSERVER_CLIENT))
3036 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3037 break;
3038
3039 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003040 /*
3041 * gpz 091009: TBD why don't we have special handling for
3042 * SAFI_MPLS_VPN here in the original quagga code?
3043 * (and, by extension, for SAFI_ENCAP)
3044 */
Chris Caputo228da422009-07-18 05:44:03 +00003045 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3046 break;
3047
3048 default:
3049 assert (0);
3050 break;
paulfee0f4c2004-09-13 05:12:46 +00003051 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003052
3053 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003054 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003055 peer_unlock (peer);
3056
paul718e3742002-12-13 20:15:29 +00003057}
3058
3059void
3060bgp_clear_route_all (struct peer *peer)
3061{
3062 afi_t afi;
3063 safi_t safi;
3064
3065 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3066 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003067 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003068}
3069
Lou Berger82dd7072016-01-12 13:41:57 -05003070/*
3071 * Finish freeing things when exiting
3072 */
3073static void
3074bgp_drain_workqueue_immediate (struct work_queue *wq)
3075{
3076 if (!wq)
3077 return;
3078
3079 if (!wq->thread)
3080 {
3081 /*
3082 * no thread implies no queued items
3083 */
3084 assert(!wq->items->count);
3085 return;
3086 }
3087
3088 while (wq->items->count)
3089 {
3090 if (wq->thread)
3091 thread_cancel(wq->thread);
3092 work_queue_run(wq->thread);
3093 }
3094}
3095
3096/*
3097 * Special function to process clear node queue when bgpd is exiting
3098 * and the thread scheduler is no longer running.
3099 */
3100void
3101bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3102{
3103 if (!peer)
3104 return;
3105
3106 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3107}
3108
3109/*
3110 * The work queues are not specific to a BGP instance, but the
3111 * items in them refer to BGP instances, so this should be called
3112 * before each BGP instance is deleted.
3113 */
3114void
3115bgp_process_queues_drain_immediate(void)
3116{
3117 bgp_drain_workqueue_immediate(bm->process_main_queue);
3118 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3119}
3120
paul718e3742002-12-13 20:15:29 +00003121void
3122bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3123{
3124 struct bgp_table *table;
3125 struct bgp_node *rn;
3126 struct bgp_adj_in *ain;
3127
3128 table = peer->bgp->rib[afi][safi];
3129
3130 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3131 for (ain = rn->adj_in; ain ; ain = ain->next)
3132 if (ain->peer == peer)
3133 {
3134 bgp_adj_in_remove (rn, ain);
3135 bgp_unlock_node (rn);
3136 break;
3137 }
3138}
hasso93406d82005-02-02 14:40:33 +00003139
3140void
3141bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3142{
3143 struct bgp_node *rn;
3144 struct bgp_info *ri;
3145 struct bgp_table *table;
3146
3147 table = peer->bgp->rib[afi][safi];
3148
3149 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3150 {
3151 for (ri = rn->info; ri; ri = ri->next)
3152 if (ri->peer == peer)
3153 {
3154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3155 bgp_rib_remove (rn, ri, peer, afi, safi);
3156 break;
3157 }
3158 }
3159}
David Lamparter6b0655a2014-06-04 06:53:35 +02003160
Lou Berger82dd7072016-01-12 13:41:57 -05003161static void
3162bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3163{
3164 struct bgp_node *rn;
3165 struct bgp_info *ri;
3166 struct bgp_info *next;
3167
3168 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3169 for (ri = rn->info; ri; ri = next)
3170 {
3171 next = ri->next;
3172 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3173 && ri->type == ZEBRA_ROUTE_BGP
3174 && ri->sub_type == BGP_ROUTE_NORMAL)
3175 bgp_zebra_withdraw (&rn->p, ri, safi);
3176 }
3177}
3178
paul718e3742002-12-13 20:15:29 +00003179/* Delete all kernel routes. */
3180void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003181bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003182{
3183 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003184 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003185 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003186
paul1eb8ef22005-04-07 07:30:20 +00003187 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003188 {
Lou Berger82dd7072016-01-12 13:41:57 -05003189 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3190 {
3191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003192
Lou Berger82dd7072016-01-12 13:41:57 -05003193 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003194
Lou Berger82dd7072016-01-12 13:41:57 -05003195 /*
3196 * VPN and ENCAP tables are two-level (RD is top level)
3197 */
3198 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3199 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003200 {
3201 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003202 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003203 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3204 bgp_table_finish ((struct bgp_table **)&(rn->info));
3205 rn->info = NULL;
3206 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003207 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003208 }
3209
3210 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3211 rn = bgp_route_next (rn))
3212 {
3213 if (rn->info)
3214 {
3215 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3216 bgp_table_finish ((struct bgp_table **)&(rn->info));
3217 rn->info = NULL;
3218 bgp_unlock_node(rn);
3219 }
3220 }
Lou Berger82dd7072016-01-12 13:41:57 -05003221 }
paul718e3742002-12-13 20:15:29 +00003222 }
3223}
3224
3225void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003226bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003227{
3228 vty_reset ();
3229 bgp_zclient_reset ();
3230 access_list_reset ();
3231 prefix_list_reset ();
3232}
David Lamparter6b0655a2014-06-04 06:53:35 +02003233
paul718e3742002-12-13 20:15:29 +00003234/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3235 value. */
3236int
Paul Jakma518a4b72016-02-04 13:27:04 +00003237bgp_nlri_parse_ip (struct peer *peer, struct attr *attr,
3238 struct bgp_nlri *packet)
paul718e3742002-12-13 20:15:29 +00003239{
3240 u_char *pnt;
3241 u_char *lim;
3242 struct prefix p;
3243 int psize;
3244 int ret;
3245
3246 /* Check peer status. */
3247 if (peer->status != Established)
3248 return 0;
3249
3250 pnt = packet->nlri;
3251 lim = pnt + packet->length;
3252
Paul Jakma405e9e12016-02-04 17:00:18 +00003253 /* RFC4771 6.3 The NLRI field in the UPDATE message is checked for
3254 syntactic validity. If the field is syntactically incorrect,
3255 then the Error Subcode is set to Invalid Network Field. */
paul718e3742002-12-13 20:15:29 +00003256 for (; pnt < lim; pnt += psize)
3257 {
3258 /* Clear prefix structure. */
3259 memset (&p, 0, sizeof (struct prefix));
3260
3261 /* Fetch prefix length. */
3262 p.prefixlen = *pnt++;
Paul Jakma405e9e12016-02-04 17:00:18 +00003263 /* afi/safi validity already verified by caller, bgp_update_receive */
paul718e3742002-12-13 20:15:29 +00003264 p.family = afi2family (packet->afi);
3265
Paul Jakma405e9e12016-02-04 17:00:18 +00003266 /* Prefix length check. */
3267 if (p.prefixlen > prefix_blen (&p) * 8)
3268 {
3269 plog_err (peer->log,
3270 "%s [Error] Update packet error"
3271 " (wrong prefix length %u for afi %u)",
3272 peer->host, p.prefixlen, packet->afi);
3273 return -1;
3274 }
3275
paul718e3742002-12-13 20:15:29 +00003276 /* Packet size overflow check. */
3277 psize = PSIZE (p.prefixlen);
3278
3279 /* When packet overflow occur return immediately. */
3280 if (pnt + psize > lim)
Paul Jakma405e9e12016-02-04 17:00:18 +00003281 {
3282 plog_err (peer->log,
3283 "%s [Error] Update packet error"
3284 " (prefix length %u overflows packet)",
3285 peer->host, p.prefixlen);
3286 return -1;
3287 }
3288
3289 /* Defensive coding, double-check the psize fits in a struct prefix */
3290 if (psize > (ssize_t) sizeof(p.u))
3291 {
3292 plog_err (peer->log,
3293 "%s [Error] Update packet error"
3294 " (prefix length %u too large for prefix storage %zu!?!!",
3295 peer->host, p.prefixlen, sizeof(p.u));
3296 return -1;
3297 }
paul718e3742002-12-13 20:15:29 +00003298
3299 /* Fetch prefix from NLRI packet. */
3300 memcpy (&p.u.prefix, pnt, psize);
3301
3302 /* Check address. */
3303 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3304 {
3305 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3306 {
paulf5ba3872004-07-09 12:11:31 +00003307 /*
Paul Jakma405e9e12016-02-04 17:00:18 +00003308 * From RFC4271 Section 6.3:
3309 *
3310 * If a prefix in the NLRI field is semantically incorrect
3311 * (e.g., an unexpected multicast IP address), an error SHOULD
3312 * be logged locally, and the prefix SHOULD be ignored.
paulf5ba3872004-07-09 12:11:31 +00003313 */
paul718e3742002-12-13 20:15:29 +00003314 zlog (peer->log, LOG_ERR,
Paul Jakma405e9e12016-02-04 17:00:18 +00003315 "%s: IPv4 unicast NLRI is multicast address %s, ignoring",
3316 peer->host, inet_ntoa (p.u.prefix4));
3317 continue;
paul718e3742002-12-13 20:15:29 +00003318 }
3319 }
3320
paul718e3742002-12-13 20:15:29 +00003321 /* Check address. */
3322 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3323 {
3324 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3325 {
3326 char buf[BUFSIZ];
3327
Paul Jakma405e9e12016-02-04 17:00:18 +00003328 zlog (peer->log, LOG_ERR,
3329 "%s: IPv6 unicast NLRI is link-local address %s, ignoring",
3330 peer->host,
paul718e3742002-12-13 20:15:29 +00003331 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00003332 continue;
3333 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003334 if (IN6_IS_ADDR_MULTICAST (&p.u.prefix6))
3335 {
3336 char buf[BUFSIZ];
3337
3338 zlog (peer->log, LOG_ERR,
3339 "%s: IPv6 unicast NLRI is multicast address %s, ignoring",
3340 peer->host,
3341 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3342 continue;
3343 }
3344 }
paul718e3742002-12-13 20:15:29 +00003345
3346 /* Normal process. */
3347 if (attr)
3348 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3349 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3350 else
3351 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3352 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3353
3354 /* Address family configuration mismatch or maximum-prefix count
3355 overflow. */
3356 if (ret < 0)
3357 return -1;
3358 }
3359
3360 /* Packet length consistency check. */
3361 if (pnt != lim)
paul718e3742002-12-13 20:15:29 +00003362 {
3363 plog_err (peer->log,
Paul Jakma405e9e12016-02-04 17:00:18 +00003364 "%s [Error] Update packet error"
3365 " (prefix length mismatch with total length)",
3366 peer->host);
paul718e3742002-12-13 20:15:29 +00003367 return -1;
3368 }
Paul Jakma405e9e12016-02-04 17:00:18 +00003369
paul718e3742002-12-13 20:15:29 +00003370 return 0;
3371}
David Lamparter6b0655a2014-06-04 06:53:35 +02003372
paul94f2b392005-06-28 12:44:16 +00003373static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003374bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003375{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003376 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003377}
3378
paul94f2b392005-06-28 12:44:16 +00003379static void
paul718e3742002-12-13 20:15:29 +00003380bgp_static_free (struct bgp_static *bgp_static)
3381{
3382 if (bgp_static->rmap.name)
3383 free (bgp_static->rmap.name);
3384 XFREE (MTYPE_BGP_STATIC, bgp_static);
3385}
3386
paul94f2b392005-06-28 12:44:16 +00003387static void
paulfee0f4c2004-09-13 05:12:46 +00003388bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3389 struct prefix *p, afi_t afi, safi_t safi)
3390{
3391 struct bgp_node *rn;
3392 struct bgp_info *ri;
3393
3394 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3395
3396 /* Check selected route and self inserted route. */
3397 for (ri = rn->info; ri; ri = ri->next)
3398 if (ri->peer == bgp->peer_self
3399 && ri->type == ZEBRA_ROUTE_BGP
3400 && ri->sub_type == BGP_ROUTE_STATIC)
3401 break;
3402
3403 /* Withdraw static BGP route from routing table. */
3404 if (ri)
3405 {
paulfee0f4c2004-09-13 05:12:46 +00003406 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003407 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003408 }
3409
3410 /* Unlock bgp_node_lookup. */
3411 bgp_unlock_node (rn);
3412}
3413
paul94f2b392005-06-28 12:44:16 +00003414static void
paulfee0f4c2004-09-13 05:12:46 +00003415bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003416 struct bgp_static *bgp_static,
3417 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003418{
3419 struct bgp_node *rn;
3420 struct bgp_info *ri;
3421 struct bgp_info *new;
3422 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003423 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003424 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003425 struct attr new_attr;
3426 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003427 struct bgp *bgp;
3428 int ret;
3429 char buf[SU_ADDRSTRLEN];
3430
3431 bgp = rsclient->bgp;
3432
Paul Jakma06e110f2006-05-12 23:29:22 +00003433 assert (bgp_static);
3434 if (!bgp_static)
3435 return;
3436
paulfee0f4c2004-09-13 05:12:46 +00003437 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3438
3439 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003440
3441 attr.nexthop = bgp_static->igpnexthop;
3442 attr.med = bgp_static->igpmetric;
3443 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003444
Paul Jakma41367172007-08-06 15:24:51 +00003445 if (bgp_static->atomic)
3446 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3447
paulfee0f4c2004-09-13 05:12:46 +00003448 /* Apply network route-map for export to this rsclient. */
3449 if (bgp_static->rmap.name)
3450 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003451 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003452 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 info.attr = &attr_tmp;
3454
paulfee0f4c2004-09-13 05:12:46 +00003455 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3456 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3457
3458 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3459
3460 rsclient->rmap_type = 0;
3461
3462 if (ret == RMAP_DENYMATCH)
3463 {
3464 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003465 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003466
3467 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003468 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003469 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003470 bgp_attr_extra_free (&attr);
3471
paulfee0f4c2004-09-13 05:12:46 +00003472 return;
3473 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003474 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003475 }
3476 else
3477 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003478
3479 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003480 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3483
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3485 == RMAP_DENY)
3486 {
paulfee0f4c2004-09-13 05:12:46 +00003487 /* This BGP update is filtered. Log the reason then update BGP entry. */
3488 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003489 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003490 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3491 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3492 p->prefixlen, rsclient->host);
3493
3494 bgp->peer_self->rmap_type = 0;
3495
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 bgp_attr_unintern (&attr_new);
3497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003498 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003499
3500 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3501
3502 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 }
paulfee0f4c2004-09-13 05:12:46 +00003504
3505 bgp->peer_self->rmap_type = 0;
3506
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003507 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003508 attr_new = bgp_attr_intern (&new_attr);
3509
3510 for (ri = rn->info; ri; ri = ri->next)
3511 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3512 && ri->sub_type == BGP_ROUTE_STATIC)
3513 break;
3514
3515 if (ri)
3516 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003517 if (attrhash_cmp (ri->attr, attr_new) &&
3518 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003519 {
3520 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003521 bgp_attr_unintern (&attr_new);
3522 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003523 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003524 return;
3525 }
3526 else
3527 {
3528 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003529 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003530
3531 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003532 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3533 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003534 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003535 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003536 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003537
3538 /* Process change. */
3539 bgp_process (bgp, rn, afi, safi);
3540 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003542 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003543 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003544 }
paulfee0f4c2004-09-13 05:12:46 +00003545 }
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003546
paulfee0f4c2004-09-13 05:12:46 +00003547 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003548 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3549 attr_new, rn);
paulfee0f4c2004-09-13 05:12:46 +00003550 SET_FLAG (new->flags, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00003551
3552 /* Register new BGP information. */
3553 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003554
3555 /* route_node_get lock */
3556 bgp_unlock_node (rn);
3557
paulfee0f4c2004-09-13 05:12:46 +00003558 /* Process change. */
3559 bgp_process (bgp, rn, afi, safi);
3560
3561 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003564}
3565
paul94f2b392005-06-28 12:44:16 +00003566static void
paulfee0f4c2004-09-13 05:12:46 +00003567bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003568 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3569{
3570 struct bgp_node *rn;
3571 struct bgp_info *ri;
3572 struct bgp_info *new;
3573 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003574 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003575 struct attr *attr_new;
3576 int ret;
3577
Paul Jakmadd8103a2006-05-12 23:27:30 +00003578 assert (bgp_static);
3579 if (!bgp_static)
3580 return;
3581
paulfee0f4c2004-09-13 05:12:46 +00003582 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003583
3584 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003585
3586 attr.nexthop = bgp_static->igpnexthop;
3587 attr.med = bgp_static->igpmetric;
3588 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003589
Paul Jakma41367172007-08-06 15:24:51 +00003590 if (bgp_static->atomic)
3591 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3592
paul718e3742002-12-13 20:15:29 +00003593 /* Apply route-map. */
3594 if (bgp_static->rmap.name)
3595 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003596 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003597 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003598 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003599
paulfee0f4c2004-09-13 05:12:46 +00003600 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3601
paul718e3742002-12-13 20:15:29 +00003602 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003603
paulfee0f4c2004-09-13 05:12:46 +00003604 bgp->peer_self->rmap_type = 0;
3605
paul718e3742002-12-13 20:15:29 +00003606 if (ret == RMAP_DENYMATCH)
3607 {
3608 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003609 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003610
3611 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003612 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003613 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003614 bgp_static_withdraw (bgp, p, afi, safi);
3615 return;
3616 }
paul286e1e72003-08-08 00:24:31 +00003617 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003618 }
paul286e1e72003-08-08 00:24:31 +00003619 else
3620 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003621
3622 for (ri = rn->info; ri; ri = ri->next)
3623 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3624 && ri->sub_type == BGP_ROUTE_STATIC)
3625 break;
3626
3627 if (ri)
3628 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003629 if (attrhash_cmp (ri->attr, attr_new) &&
3630 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003631 {
3632 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003633 bgp_attr_unintern (&attr_new);
3634 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003635 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003636 return;
3637 }
3638 else
3639 {
3640 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003641 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003642
3643 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003644 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3645 bgp_info_restore(rn, ri);
3646 else
3647 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003648 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003649 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003650 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003651
3652 /* Process change. */
3653 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3654 bgp_process (bgp, rn, afi, safi);
3655 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003656 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003657 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003658 return;
3659 }
3660 }
3661
3662 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003663 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self, attr_new,
3664 rn);
paul718e3742002-12-13 20:15:29 +00003665 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003666
3667 /* Aggregate address increment. */
3668 bgp_aggregate_increment (bgp, p, new, afi, safi);
3669
3670 /* Register new BGP information. */
3671 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003672
3673 /* route_node_get lock */
3674 bgp_unlock_node (rn);
3675
paul718e3742002-12-13 20:15:29 +00003676 /* Process change. */
3677 bgp_process (bgp, rn, afi, safi);
3678
3679 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003680 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003681 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003682}
3683
3684void
paulfee0f4c2004-09-13 05:12:46 +00003685bgp_static_update (struct bgp *bgp, struct prefix *p,
3686 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3687{
3688 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003689 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003690
3691 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3692
paul1eb8ef22005-04-07 07:30:20 +00003693 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003694 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003695 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3696 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003697 }
3698}
3699
paul718e3742002-12-13 20:15:29 +00003700void
3701bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3702 safi_t safi)
3703{
3704 struct bgp_node *rn;
3705 struct bgp_info *ri;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003706 struct bgp_info *new;
paul718e3742002-12-13 20:15:29 +00003707
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003708 /* Make new BGP info. */
3709 rn = bgp_node_get (bgp->rib[afi][safi], p);
3710 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3711 bgp_attr_default_intern(BGP_ORIGIN_IGP), rn);
3712
3713 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00003714
3715 /* Check selected route and self inserted route. */
3716 for (ri = rn->info; ri; ri = ri->next)
3717 if (ri->peer == bgp->peer_self
3718 && ri->type == ZEBRA_ROUTE_BGP
3719 && ri->sub_type == BGP_ROUTE_STATIC)
3720 break;
3721
3722 /* Withdraw static BGP route from routing table. */
3723 if (ri)
3724 {
3725 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003726 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003727 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003728 }
3729
3730 /* Unlock bgp_node_lookup. */
3731 bgp_unlock_node (rn);
3732}
3733
3734void
paulfee0f4c2004-09-13 05:12:46 +00003735bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3736{
3737 struct bgp_static *bgp_static;
3738 struct bgp *bgp;
3739 struct bgp_node *rn;
3740 struct prefix *p;
3741
3742 bgp = rsclient->bgp;
3743
3744 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3745 if ((bgp_static = rn->info) != NULL)
3746 {
3747 p = &rn->p;
3748
3749 bgp_static_update_rsclient (rsclient, p, bgp_static,
3750 afi, safi);
3751 }
3752}
3753
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754/*
3755 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3756 */
paul94f2b392005-06-28 12:44:16 +00003757static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003758bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3759 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003760{
3761 struct bgp_node *rn;
3762 struct bgp_info *ri;
3763
paulfee0f4c2004-09-13 05:12:46 +00003764 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003765
3766 /* Check selected route and self inserted route. */
3767 for (ri = rn->info; ri; ri = ri->next)
3768 if (ri->peer == bgp->peer_self
3769 && ri->type == ZEBRA_ROUTE_BGP
3770 && ri->sub_type == BGP_ROUTE_STATIC)
3771 break;
3772
3773 /* Withdraw static BGP route from routing table. */
3774 if (ri)
3775 {
3776 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003777 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003778 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003779 }
3780
3781 /* Unlock bgp_node_lookup. */
3782 bgp_unlock_node (rn);
3783}
3784
Lou Bergera76d9ca2016-01-12 13:41:53 -05003785static void
3786bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3787 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3788{
3789 struct bgp_node *rn;
3790 struct bgp_info *new;
3791 struct attr *attr_new;
3792 struct attr attr = { 0 };
3793 struct bgp_info *ri;
3794
3795 assert (bgp_static);
3796
3797 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3798
3799 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3800
3801 attr.nexthop = bgp_static->igpnexthop;
3802 attr.med = bgp_static->igpmetric;
3803 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3804
3805 /* Apply route-map. */
3806 if (bgp_static->rmap.name)
3807 {
3808 struct attr attr_tmp = attr;
3809 struct bgp_info info;
3810 int ret;
3811
3812 info.peer = bgp->peer_self;
3813 info.attr = &attr_tmp;
3814
3815 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3816
3817 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3818
3819 bgp->peer_self->rmap_type = 0;
3820
3821 if (ret == RMAP_DENYMATCH)
3822 {
3823 /* Free uninterned attribute. */
3824 bgp_attr_flush (&attr_tmp);
3825
3826 /* Unintern original. */
3827 aspath_unintern (&attr.aspath);
3828 bgp_attr_extra_free (&attr);
3829 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3830 bgp_static->tag);
3831 return;
3832 }
3833
3834 attr_new = bgp_attr_intern (&attr_tmp);
3835 }
3836 else
3837 {
3838 attr_new = bgp_attr_intern (&attr);
3839 }
3840
3841 for (ri = rn->info; ri; ri = ri->next)
3842 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3843 && ri->sub_type == BGP_ROUTE_STATIC)
3844 break;
3845
3846 if (ri)
3847 {
3848 if (attrhash_cmp (ri->attr, attr_new) &&
3849 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3850 {
3851 bgp_unlock_node (rn);
3852 bgp_attr_unintern (&attr_new);
3853 aspath_unintern (&attr.aspath);
3854 bgp_attr_extra_free (&attr);
3855 return;
3856 }
3857 else
3858 {
3859 /* The attribute is changed. */
3860 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3861
3862 /* Rewrite BGP route information. */
3863 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3864 bgp_info_restore(rn, ri);
3865 else
3866 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3867 bgp_attr_unintern (&ri->attr);
3868 ri->attr = attr_new;
3869 ri->uptime = bgp_clock ();
3870
3871 /* Process change. */
3872 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3873 bgp_process (bgp, rn, afi, safi);
3874 bgp_unlock_node (rn);
3875 aspath_unintern (&attr.aspath);
3876 bgp_attr_extra_free (&attr);
3877 return;
3878 }
3879 }
3880
3881
3882 /* Make new BGP info. */
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05003883 new = info_make (ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, bgp->peer_self,
3884 attr_new, rn);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003885 SET_FLAG (new->flags, BGP_INFO_VALID);
Lou Bergera76d9ca2016-01-12 13:41:53 -05003886 new->extra = bgp_info_extra_new();
3887 memcpy (new->extra->tag, bgp_static->tag, 3);
3888
3889 /* Aggregate address increment. */
3890 bgp_aggregate_increment (bgp, p, new, afi, safi);
3891
3892 /* Register new BGP information. */
3893 bgp_info_add (rn, new);
3894
3895 /* route_node_get lock */
3896 bgp_unlock_node (rn);
3897
3898 /* Process change. */
3899 bgp_process (bgp, rn, afi, safi);
3900
3901 /* Unintern original. */
3902 aspath_unintern (&attr.aspath);
3903 bgp_attr_extra_free (&attr);
3904}
3905
paul718e3742002-12-13 20:15:29 +00003906/* Configure static BGP network. When user don't run zebra, static
3907 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003908static int
paulfd79ac92004-10-13 05:06:08 +00003909bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003910 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003911{
3912 int ret;
3913 struct prefix p;
3914 struct bgp_static *bgp_static;
3915 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003916 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003917
3918 /* Convert IP prefix string to struct prefix. */
3919 ret = str2prefix (ip_str, &p);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
paul718e3742002-12-13 20:15:29 +00003925 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3926 {
3927 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3928 VTY_NEWLINE);
3929 return CMD_WARNING;
3930 }
paul718e3742002-12-13 20:15:29 +00003931
3932 apply_mask (&p);
3933
3934 /* Set BGP static route configuration. */
3935 rn = bgp_node_get (bgp->route[afi][safi], &p);
3936
3937 if (rn->info)
3938 {
3939 /* Configuration change. */
3940 bgp_static = rn->info;
3941
3942 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003943 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3944 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003945
paul718e3742002-12-13 20:15:29 +00003946 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003947
paul718e3742002-12-13 20:15:29 +00003948 if (rmap)
3949 {
3950 if (bgp_static->rmap.name)
3951 free (bgp_static->rmap.name);
3952 bgp_static->rmap.name = strdup (rmap);
3953 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3954 }
3955 else
3956 {
3957 if (bgp_static->rmap.name)
3958 free (bgp_static->rmap.name);
3959 bgp_static->rmap.name = NULL;
3960 bgp_static->rmap.map = NULL;
3961 bgp_static->valid = 0;
3962 }
3963 bgp_unlock_node (rn);
3964 }
3965 else
3966 {
3967 /* New configuration. */
3968 bgp_static = bgp_static_new ();
3969 bgp_static->backdoor = backdoor;
3970 bgp_static->valid = 0;
3971 bgp_static->igpmetric = 0;
3972 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003973
paul718e3742002-12-13 20:15:29 +00003974 if (rmap)
3975 {
3976 if (bgp_static->rmap.name)
3977 free (bgp_static->rmap.name);
3978 bgp_static->rmap.name = strdup (rmap);
3979 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3980 }
3981 rn->info = bgp_static;
3982 }
3983
3984 /* If BGP scan is not enabled, we should install this route here. */
3985 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3986 {
3987 bgp_static->valid = 1;
3988
3989 if (need_update)
3990 bgp_static_withdraw (bgp, &p, afi, safi);
3991
3992 if (! bgp_static->backdoor)
3993 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3994 }
3995
3996 return CMD_SUCCESS;
3997}
3998
3999/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004000static int
paulfd79ac92004-10-13 05:06:08 +00004001bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004002 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004003{
4004 int ret;
4005 struct prefix p;
4006 struct bgp_static *bgp_static;
4007 struct bgp_node *rn;
4008
4009 /* Convert IP prefix string to struct prefix. */
4010 ret = str2prefix (ip_str, &p);
4011 if (! ret)
4012 {
4013 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4014 return CMD_WARNING;
4015 }
paul718e3742002-12-13 20:15:29 +00004016 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4017 {
4018 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4019 VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
paul718e3742002-12-13 20:15:29 +00004022
4023 apply_mask (&p);
4024
4025 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4026 if (! rn)
4027 {
4028 vty_out (vty, "%% Can't find specified static route configuration.%s",
4029 VTY_NEWLINE);
4030 return CMD_WARNING;
4031 }
4032
4033 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004034
paul718e3742002-12-13 20:15:29 +00004035 /* Update BGP RIB. */
4036 if (! bgp_static->backdoor)
4037 bgp_static_withdraw (bgp, &p, afi, safi);
4038
4039 /* Clear configuration. */
4040 bgp_static_free (bgp_static);
4041 rn->info = NULL;
4042 bgp_unlock_node (rn);
4043 bgp_unlock_node (rn);
4044
4045 return CMD_SUCCESS;
4046}
4047
4048/* Called from bgp_delete(). Delete all static routes from the BGP
4049 instance. */
4050void
4051bgp_static_delete (struct bgp *bgp)
4052{
4053 afi_t afi;
4054 safi_t safi;
4055 struct bgp_node *rn;
4056 struct bgp_node *rm;
4057 struct bgp_table *table;
4058 struct bgp_static *bgp_static;
4059
4060 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4061 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4062 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4063 if (rn->info != NULL)
4064 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004065 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004066 {
4067 table = rn->info;
4068
4069 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4070 {
4071 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004072 bgp_static_withdraw_safi (bgp, &rm->p,
4073 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004074 (struct prefix_rd *)&rn->p,
4075 bgp_static->tag);
4076 bgp_static_free (bgp_static);
4077 rn->info = NULL;
4078 bgp_unlock_node (rn);
4079 }
4080 }
4081 else
4082 {
4083 bgp_static = rn->info;
4084 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4085 bgp_static_free (bgp_static);
4086 rn->info = NULL;
4087 bgp_unlock_node (rn);
4088 }
4089 }
4090}
4091
Lou Bergera76d9ca2016-01-12 13:41:53 -05004092/*
4093 * gpz 110624
4094 * Currently this is used to set static routes for VPN and ENCAP.
4095 * I think it can probably be factored with bgp_static_set.
4096 */
paul718e3742002-12-13 20:15:29 +00004097int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004098bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4099 const char *rd_str, const char *tag_str,
4100 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004101{
4102 int ret;
4103 struct prefix p;
4104 struct prefix_rd prd;
4105 struct bgp *bgp;
4106 struct bgp_node *prn;
4107 struct bgp_node *rn;
4108 struct bgp_table *table;
4109 struct bgp_static *bgp_static;
4110 u_char tag[3];
4111
4112 bgp = vty->index;
4113
4114 ret = str2prefix (ip_str, &p);
4115 if (! ret)
4116 {
4117 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4118 return CMD_WARNING;
4119 }
4120 apply_mask (&p);
4121
4122 ret = str2prefix_rd (rd_str, &prd);
4123 if (! ret)
4124 {
4125 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4126 return CMD_WARNING;
4127 }
4128
4129 ret = str2tag (tag_str, tag);
4130 if (! ret)
4131 {
4132 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4133 return CMD_WARNING;
4134 }
4135
Lou Bergera76d9ca2016-01-12 13:41:53 -05004136 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004137 (struct prefix *)&prd);
4138 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004139 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004140 else
4141 bgp_unlock_node (prn);
4142 table = prn->info;
4143
4144 rn = bgp_node_get (table, &p);
4145
4146 if (rn->info)
4147 {
4148 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4149 bgp_unlock_node (rn);
4150 }
4151 else
4152 {
4153 /* New configuration. */
4154 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004155 bgp_static->backdoor = 0;
4156 bgp_static->valid = 0;
4157 bgp_static->igpmetric = 0;
4158 bgp_static->igpnexthop.s_addr = 0;
4159 memcpy(bgp_static->tag, tag, 3);
4160 bgp_static->prd = prd;
4161
4162 if (rmap_str)
4163 {
4164 if (bgp_static->rmap.name)
4165 free (bgp_static->rmap.name);
4166 bgp_static->rmap.name = strdup (rmap_str);
4167 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4168 }
paul718e3742002-12-13 20:15:29 +00004169 rn->info = bgp_static;
4170
Lou Bergera76d9ca2016-01-12 13:41:53 -05004171 bgp_static->valid = 1;
4172 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004173 }
4174
4175 return CMD_SUCCESS;
4176}
4177
4178/* Configure static BGP network. */
4179int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004180bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4181 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004182{
4183 int ret;
4184 struct bgp *bgp;
4185 struct prefix p;
4186 struct prefix_rd prd;
4187 struct bgp_node *prn;
4188 struct bgp_node *rn;
4189 struct bgp_table *table;
4190 struct bgp_static *bgp_static;
4191 u_char tag[3];
4192
4193 bgp = vty->index;
4194
4195 /* Convert IP prefix string to struct prefix. */
4196 ret = str2prefix (ip_str, &p);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202 apply_mask (&p);
4203
4204 ret = str2prefix_rd (rd_str, &prd);
4205 if (! ret)
4206 {
4207 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4208 return CMD_WARNING;
4209 }
4210
4211 ret = str2tag (tag_str, tag);
4212 if (! ret)
4213 {
4214 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4215 return CMD_WARNING;
4216 }
4217
Lou Bergera76d9ca2016-01-12 13:41:53 -05004218 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004219 (struct prefix *)&prd);
4220 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004221 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004222 else
4223 bgp_unlock_node (prn);
4224 table = prn->info;
4225
4226 rn = bgp_node_lookup (table, &p);
4227
4228 if (rn)
4229 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004230 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004231
4232 bgp_static = rn->info;
4233 bgp_static_free (bgp_static);
4234 rn->info = NULL;
4235 bgp_unlock_node (rn);
4236 bgp_unlock_node (rn);
4237 }
4238 else
4239 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4240
4241 return CMD_SUCCESS;
4242}
David Lamparter6b0655a2014-06-04 06:53:35 +02004243
paul718e3742002-12-13 20:15:29 +00004244DEFUN (bgp_network,
4245 bgp_network_cmd,
4246 "network A.B.C.D/M",
4247 "Specify a network to announce via BGP\n"
4248 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4249{
4250 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004251 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004252}
4253
4254DEFUN (bgp_network_route_map,
4255 bgp_network_route_map_cmd,
4256 "network A.B.C.D/M route-map WORD",
4257 "Specify a network to announce via BGP\n"
4258 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4259 "Route-map to modify the attributes\n"
4260 "Name of the route map\n")
4261{
4262 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004263 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004264}
4265
4266DEFUN (bgp_network_backdoor,
4267 bgp_network_backdoor_cmd,
4268 "network A.B.C.D/M backdoor",
4269 "Specify a network to announce via BGP\n"
4270 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4271 "Specify a BGP backdoor route\n")
4272{
Paul Jakma41367172007-08-06 15:24:51 +00004273 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004274 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004275}
4276
4277DEFUN (bgp_network_mask,
4278 bgp_network_mask_cmd,
4279 "network A.B.C.D mask A.B.C.D",
4280 "Specify a network to announce via BGP\n"
4281 "Network number\n"
4282 "Network mask\n"
4283 "Network mask\n")
4284{
4285 int ret;
4286 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004287
paul718e3742002-12-13 20:15:29 +00004288 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4289 if (! ret)
4290 {
4291 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4292 return CMD_WARNING;
4293 }
4294
4295 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004296 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004297}
4298
4299DEFUN (bgp_network_mask_route_map,
4300 bgp_network_mask_route_map_cmd,
4301 "network A.B.C.D mask A.B.C.D route-map WORD",
4302 "Specify a network to announce via BGP\n"
4303 "Network number\n"
4304 "Network mask\n"
4305 "Network mask\n"
4306 "Route-map to modify the attributes\n"
4307 "Name of the route map\n")
4308{
4309 int ret;
4310 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004311
paul718e3742002-12-13 20:15:29 +00004312 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4313 if (! ret)
4314 {
4315 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4316 return CMD_WARNING;
4317 }
4318
4319 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004320 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004321}
4322
4323DEFUN (bgp_network_mask_backdoor,
4324 bgp_network_mask_backdoor_cmd,
4325 "network A.B.C.D mask A.B.C.D backdoor",
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n")
4331{
4332 int ret;
4333 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004334
paul718e3742002-12-13 20:15:29 +00004335 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4336 if (! ret)
4337 {
4338 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4339 return CMD_WARNING;
4340 }
4341
Paul Jakma41367172007-08-06 15:24:51 +00004342 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004343 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004344}
4345
4346DEFUN (bgp_network_mask_natural,
4347 bgp_network_mask_natural_cmd,
4348 "network A.B.C.D",
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n")
4351{
4352 int ret;
4353 char prefix_str[BUFSIZ];
4354
4355 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
4362 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004363 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004364}
4365
4366DEFUN (bgp_network_mask_natural_route_map,
4367 bgp_network_mask_natural_route_map_cmd,
4368 "network A.B.C.D route-map WORD",
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n"
4371 "Route-map to modify the attributes\n"
4372 "Name of the route map\n")
4373{
4374 int ret;
4375 char prefix_str[BUFSIZ];
4376
4377 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4378 if (! ret)
4379 {
4380 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4381 return CMD_WARNING;
4382 }
4383
4384 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004385 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004386}
4387
4388DEFUN (bgp_network_mask_natural_backdoor,
4389 bgp_network_mask_natural_backdoor_cmd,
4390 "network A.B.C.D backdoor",
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n"
4393 "Specify a BGP backdoor route\n")
4394{
4395 int ret;
4396 char prefix_str[BUFSIZ];
4397
4398 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4399 if (! ret)
4400 {
4401 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4402 return CMD_WARNING;
4403 }
4404
Paul Jakma41367172007-08-06 15:24:51 +00004405 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004406 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004407}
4408
4409DEFUN (no_bgp_network,
4410 no_bgp_network_cmd,
4411 "no network A.B.C.D/M",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4415{
4416 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4417 bgp_node_safi (vty));
4418}
4419
4420ALIAS (no_bgp_network,
4421 no_bgp_network_route_map_cmd,
4422 "no network A.B.C.D/M route-map WORD",
4423 NO_STR
4424 "Specify a network to announce via BGP\n"
4425 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4426 "Route-map to modify the attributes\n"
4427 "Name of the route map\n")
4428
4429ALIAS (no_bgp_network,
4430 no_bgp_network_backdoor_cmd,
4431 "no network A.B.C.D/M backdoor",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4435 "Specify a BGP backdoor route\n")
4436
4437DEFUN (no_bgp_network_mask,
4438 no_bgp_network_mask_cmd,
4439 "no network A.B.C.D mask A.B.C.D",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "Network number\n"
4443 "Network mask\n"
4444 "Network mask\n")
4445{
4446 int ret;
4447 char prefix_str[BUFSIZ];
4448
4449 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4450 if (! ret)
4451 {
4452 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4453 return CMD_WARNING;
4454 }
4455
4456 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4457 bgp_node_safi (vty));
4458}
4459
4460ALIAS (no_bgp_network_mask,
4461 no_bgp_network_mask_route_map_cmd,
4462 "no network A.B.C.D mask A.B.C.D route-map WORD",
4463 NO_STR
4464 "Specify a network to announce via BGP\n"
4465 "Network number\n"
4466 "Network mask\n"
4467 "Network mask\n"
4468 "Route-map to modify the attributes\n"
4469 "Name of the route map\n")
4470
4471ALIAS (no_bgp_network_mask,
4472 no_bgp_network_mask_backdoor_cmd,
4473 "no network A.B.C.D mask A.B.C.D backdoor",
4474 NO_STR
4475 "Specify a network to announce via BGP\n"
4476 "Network number\n"
4477 "Network mask\n"
4478 "Network mask\n"
4479 "Specify a BGP backdoor route\n")
4480
4481DEFUN (no_bgp_network_mask_natural,
4482 no_bgp_network_mask_natural_cmd,
4483 "no network A.B.C.D",
4484 NO_STR
4485 "Specify a network to announce via BGP\n"
4486 "Network number\n")
4487{
4488 int ret;
4489 char prefix_str[BUFSIZ];
4490
4491 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4492 if (! ret)
4493 {
4494 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4495 return CMD_WARNING;
4496 }
4497
4498 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4499 bgp_node_safi (vty));
4500}
4501
4502ALIAS (no_bgp_network_mask_natural,
4503 no_bgp_network_mask_natural_route_map_cmd,
4504 "no network A.B.C.D route-map WORD",
4505 NO_STR
4506 "Specify a network to announce via BGP\n"
4507 "Network number\n"
4508 "Route-map to modify the attributes\n"
4509 "Name of the route map\n")
4510
4511ALIAS (no_bgp_network_mask_natural,
4512 no_bgp_network_mask_natural_backdoor_cmd,
4513 "no network A.B.C.D backdoor",
4514 NO_STR
4515 "Specify a network to announce via BGP\n"
4516 "Network number\n"
4517 "Specify a BGP backdoor route\n")
4518
paul718e3742002-12-13 20:15:29 +00004519DEFUN (ipv6_bgp_network,
4520 ipv6_bgp_network_cmd,
4521 "network X:X::X:X/M",
4522 "Specify a network to announce via BGP\n"
4523 "IPv6 prefix <network>/<length>\n")
4524{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304525 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004526 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004527}
4528
4529DEFUN (ipv6_bgp_network_route_map,
4530 ipv6_bgp_network_route_map_cmd,
4531 "network X:X::X:X/M route-map WORD",
4532 "Specify a network to announce via BGP\n"
4533 "IPv6 prefix <network>/<length>\n"
4534 "Route-map to modify the attributes\n"
4535 "Name of the route map\n")
4536{
4537 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004538 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004539}
4540
4541DEFUN (no_ipv6_bgp_network,
4542 no_ipv6_bgp_network_cmd,
4543 "no network X:X::X:X/M",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "IPv6 prefix <network>/<length>\n")
4547{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304548 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004549}
4550
4551ALIAS (no_ipv6_bgp_network,
4552 no_ipv6_bgp_network_route_map_cmd,
4553 "no network X:X::X:X/M route-map WORD",
4554 NO_STR
4555 "Specify a network to announce via BGP\n"
4556 "IPv6 prefix <network>/<length>\n"
4557 "Route-map to modify the attributes\n"
4558 "Name of the route map\n")
4559
4560ALIAS (ipv6_bgp_network,
4561 old_ipv6_bgp_network_cmd,
4562 "ipv6 bgp network X:X::X:X/M",
4563 IPV6_STR
4564 BGP_STR
4565 "Specify a network to announce via BGP\n"
4566 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4567
4568ALIAS (no_ipv6_bgp_network,
4569 old_no_ipv6_bgp_network_cmd,
4570 "no ipv6 bgp network X:X::X:X/M",
4571 NO_STR
4572 IPV6_STR
4573 BGP_STR
4574 "Specify a network to announce via BGP\n"
4575 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004576
4577/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4578ALIAS_DEPRECATED (bgp_network,
4579 bgp_network_ttl_cmd,
4580 "network A.B.C.D/M pathlimit <0-255>",
4581 "Specify a network to announce via BGP\n"
4582 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4583 "AS-Path hopcount limit attribute\n"
4584 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4585ALIAS_DEPRECATED (bgp_network_backdoor,
4586 bgp_network_backdoor_ttl_cmd,
4587 "network A.B.C.D/M backdoor pathlimit <0-255>",
4588 "Specify a network to announce via BGP\n"
4589 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4590 "Specify a BGP backdoor route\n"
4591 "AS-Path hopcount limit attribute\n"
4592 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4593ALIAS_DEPRECATED (bgp_network_mask,
4594 bgp_network_mask_ttl_cmd,
4595 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4596 "Specify a network to announce via BGP\n"
4597 "Network number\n"
4598 "Network mask\n"
4599 "Network mask\n"
4600 "AS-Path hopcount limit attribute\n"
4601 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4602ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4603 bgp_network_mask_backdoor_ttl_cmd,
4604 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4605 "Specify a network to announce via BGP\n"
4606 "Network number\n"
4607 "Network mask\n"
4608 "Network mask\n"
4609 "Specify a BGP backdoor route\n"
4610 "AS-Path hopcount limit attribute\n"
4611 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4612ALIAS_DEPRECATED (bgp_network_mask_natural,
4613 bgp_network_mask_natural_ttl_cmd,
4614 "network A.B.C.D pathlimit <0-255>",
4615 "Specify a network to announce via BGP\n"
4616 "Network number\n"
4617 "AS-Path hopcount limit attribute\n"
4618 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4619ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4620 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004621 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004622 "Specify a network to announce via BGP\n"
4623 "Network number\n"
4624 "Specify a BGP backdoor route\n"
4625 "AS-Path hopcount limit attribute\n"
4626 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4627ALIAS_DEPRECATED (no_bgp_network,
4628 no_bgp_network_ttl_cmd,
4629 "no network A.B.C.D/M pathlimit <0-255>",
4630 NO_STR
4631 "Specify a network to announce via BGP\n"
4632 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4633 "AS-Path hopcount limit attribute\n"
4634 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4635ALIAS_DEPRECATED (no_bgp_network,
4636 no_bgp_network_backdoor_ttl_cmd,
4637 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4638 NO_STR
4639 "Specify a network to announce via BGP\n"
4640 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4641 "Specify a BGP backdoor route\n"
4642 "AS-Path hopcount limit attribute\n"
4643 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4644ALIAS_DEPRECATED (no_bgp_network,
4645 no_bgp_network_mask_ttl_cmd,
4646 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4647 NO_STR
4648 "Specify a network to announce via BGP\n"
4649 "Network number\n"
4650 "Network mask\n"
4651 "Network mask\n"
4652 "AS-Path hopcount limit attribute\n"
4653 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4654ALIAS_DEPRECATED (no_bgp_network_mask,
4655 no_bgp_network_mask_backdoor_ttl_cmd,
4656 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4657 NO_STR
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "Specify a BGP backdoor route\n"
4663 "AS-Path hopcount limit attribute\n"
4664 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4665ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4666 no_bgp_network_mask_natural_ttl_cmd,
4667 "no network A.B.C.D pathlimit <0-255>",
4668 NO_STR
4669 "Specify a network to announce via BGP\n"
4670 "Network number\n"
4671 "AS-Path hopcount limit attribute\n"
4672 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4673ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4674 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4675 "no network A.B.C.D backdoor pathlimit <0-255>",
4676 NO_STR
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "Specify a BGP backdoor route\n"
4680 "AS-Path hopcount limit attribute\n"
4681 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4682ALIAS_DEPRECATED (ipv6_bgp_network,
4683 ipv6_bgp_network_ttl_cmd,
4684 "network X:X::X:X/M pathlimit <0-255>",
4685 "Specify a network to announce via BGP\n"
4686 "IPv6 prefix <network>/<length>\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_ipv6_bgp_network,
4690 no_ipv6_bgp_network_ttl_cmd,
4691 "no network X:X::X:X/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IPv6 prefix <network>/<length>\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02004697
paul718e3742002-12-13 20:15:29 +00004698/* Aggreagete address:
4699
4700 advertise-map Set condition to advertise attribute
4701 as-set Generate AS set path information
4702 attribute-map Set attributes of aggregate
4703 route-map Set parameters of aggregate
4704 summary-only Filter more specific routes from updates
4705 suppress-map Conditionally filter more specific routes from updates
4706 <cr>
4707 */
4708struct bgp_aggregate
4709{
4710 /* Summary-only flag. */
4711 u_char summary_only;
4712
4713 /* AS set generation. */
4714 u_char as_set;
4715
4716 /* Route-map for aggregated route. */
4717 struct route_map *map;
4718
4719 /* Suppress-count. */
4720 unsigned long count;
4721
4722 /* SAFI configuration. */
4723 safi_t safi;
4724};
4725
paul94f2b392005-06-28 12:44:16 +00004726static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004727bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004728{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004729 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004730}
4731
paul94f2b392005-06-28 12:44:16 +00004732static void
paul718e3742002-12-13 20:15:29 +00004733bgp_aggregate_free (struct bgp_aggregate *aggregate)
4734{
4735 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4736}
4737
Daniel Walton76a72802015-05-19 17:47:24 -07004738/* Update an aggregate as routes are added/removed from the BGP table */
paul94f2b392005-06-28 12:44:16 +00004739static void
paul718e3742002-12-13 20:15:29 +00004740bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4741 afi_t afi, safi_t safi, struct bgp_info *del,
4742 struct bgp_aggregate *aggregate)
4743{
4744 struct bgp_table *table;
4745 struct bgp_node *top;
4746 struct bgp_node *rn;
4747 u_char origin;
4748 struct aspath *aspath = NULL;
4749 struct aspath *asmerge = NULL;
4750 struct community *community = NULL;
4751 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004752 struct bgp_info *ri;
4753 struct bgp_info *new;
4754 int first = 1;
4755 unsigned long match = 0;
4756
paul718e3742002-12-13 20:15:29 +00004757 /* ORIGIN attribute: If at least one route among routes that are
4758 aggregated has ORIGIN with the value INCOMPLETE, then the
4759 aggregated route must have the ORIGIN attribute with the value
4760 INCOMPLETE. Otherwise, if at least one route among routes that
4761 are aggregated has ORIGIN with the value EGP, then the aggregated
4762 route must have the origin attribute with the value EGP. In all
4763 other case the value of the ORIGIN attribute of the aggregated
4764 route is INTERNAL. */
4765 origin = BGP_ORIGIN_IGP;
4766
4767 table = bgp->rib[afi][safi];
4768
4769 top = bgp_node_get (table, p);
4770 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4771 if (rn->p.prefixlen > p->prefixlen)
4772 {
4773 match = 0;
4774
4775 for (ri = rn->info; ri; ri = ri->next)
4776 {
4777 if (BGP_INFO_HOLDDOWN (ri))
4778 continue;
4779
4780 if (del && ri == del)
4781 continue;
4782
4783 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004784 first = 0;
paul718e3742002-12-13 20:15:29 +00004785
4786#ifdef AGGREGATE_NEXTHOP_CHECK
4787 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4788 || ri->attr->med != med)
4789 {
4790 if (aspath)
4791 aspath_free (aspath);
4792 if (community)
4793 community_free (community);
4794 bgp_unlock_node (rn);
4795 bgp_unlock_node (top);
4796 return;
4797 }
4798#endif /* AGGREGATE_NEXTHOP_CHECK */
4799
4800 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4801 {
4802 if (aggregate->summary_only)
4803 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004804 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004805 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004806 match++;
4807 }
4808
4809 aggregate->count++;
4810
Daniel Walton76a72802015-05-19 17:47:24 -07004811 if (origin < ri->attr->origin)
4812 origin = ri->attr->origin;
4813
paul718e3742002-12-13 20:15:29 +00004814 if (aggregate->as_set)
4815 {
paul718e3742002-12-13 20:15:29 +00004816 if (aspath)
4817 {
4818 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4819 aspath_free (aspath);
4820 aspath = asmerge;
4821 }
4822 else
4823 aspath = aspath_dup (ri->attr->aspath);
4824
4825 if (ri->attr->community)
4826 {
4827 if (community)
4828 {
4829 commerge = community_merge (community,
4830 ri->attr->community);
4831 community = community_uniq_sort (commerge);
4832 community_free (commerge);
4833 }
4834 else
4835 community = community_dup (ri->attr->community);
4836 }
4837 }
4838 }
4839 }
4840 if (match)
4841 bgp_process (bgp, rn, afi, safi);
4842 }
4843 bgp_unlock_node (top);
4844
4845 if (rinew)
4846 {
4847 aggregate->count++;
4848
4849 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004850 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004851
Daniel Walton76a72802015-05-19 17:47:24 -07004852 if (origin < rinew->attr->origin)
4853 origin = rinew->attr->origin;
4854
paul718e3742002-12-13 20:15:29 +00004855 if (aggregate->as_set)
4856 {
paul718e3742002-12-13 20:15:29 +00004857 if (aspath)
4858 {
4859 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4860 aspath_free (aspath);
4861 aspath = asmerge;
4862 }
4863 else
4864 aspath = aspath_dup (rinew->attr->aspath);
4865
4866 if (rinew->attr->community)
4867 {
4868 if (community)
4869 {
4870 commerge = community_merge (community,
4871 rinew->attr->community);
4872 community = community_uniq_sort (commerge);
4873 community_free (commerge);
4874 }
4875 else
4876 community = community_dup (rinew->attr->community);
4877 }
4878 }
4879 }
4880
4881 if (aggregate->count > 0)
4882 {
4883 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05004884 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
4885 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
4886 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00004887 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00004888
4889 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004890 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004891 bgp_process (bgp, rn, afi, safi);
4892 }
4893 else
4894 {
4895 if (aspath)
4896 aspath_free (aspath);
4897 if (community)
4898 community_free (community);
4899 }
4900}
4901
4902void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4903 struct bgp_aggregate *);
4904
4905void
4906bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4907 struct bgp_info *ri, afi_t afi, safi_t safi)
4908{
4909 struct bgp_node *child;
4910 struct bgp_node *rn;
4911 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004912 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004913
4914 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004915 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004916 return;
4917
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004918 table = bgp->aggregate[afi][safi];
4919
4920 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004921 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004922 return;
4923
paul718e3742002-12-13 20:15:29 +00004924 if (p->prefixlen == 0)
4925 return;
4926
4927 if (BGP_INFO_HOLDDOWN (ri))
4928 return;
4929
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004930 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004931
4932 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004933 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004934 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4935 {
4936 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004937 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004938 }
4939 bgp_unlock_node (child);
4940}
4941
4942void
4943bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4944 struct bgp_info *del, afi_t afi, safi_t safi)
4945{
4946 struct bgp_node *child;
4947 struct bgp_node *rn;
4948 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004949 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004950
4951 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004952 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004953 return;
4954
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004955 table = bgp->aggregate[afi][safi];
4956
4957 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004958 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004959 return;
4960
paul718e3742002-12-13 20:15:29 +00004961 if (p->prefixlen == 0)
4962 return;
4963
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004964 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004965
4966 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004967 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004968 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4969 {
4970 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004971 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004972 }
4973 bgp_unlock_node (child);
4974}
4975
Daniel Walton76a72802015-05-19 17:47:24 -07004976/* Called via bgp_aggregate_set when the user configures aggregate-address */
paul94f2b392005-06-28 12:44:16 +00004977static void
paul718e3742002-12-13 20:15:29 +00004978bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4979 struct bgp_aggregate *aggregate)
4980{
4981 struct bgp_table *table;
4982 struct bgp_node *top;
4983 struct bgp_node *rn;
4984 struct bgp_info *new;
4985 struct bgp_info *ri;
4986 unsigned long match;
4987 u_char origin = BGP_ORIGIN_IGP;
4988 struct aspath *aspath = NULL;
4989 struct aspath *asmerge = NULL;
4990 struct community *community = NULL;
4991 struct community *commerge = NULL;
4992
4993 table = bgp->rib[afi][safi];
4994
4995 /* Sanity check. */
4996 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4997 return;
4998 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4999 return;
5000
5001 /* If routes exists below this node, generate aggregate routes. */
5002 top = bgp_node_get (table, p);
5003 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5004 if (rn->p.prefixlen > p->prefixlen)
5005 {
5006 match = 0;
5007
5008 for (ri = rn->info; ri; ri = ri->next)
5009 {
5010 if (BGP_INFO_HOLDDOWN (ri))
5011 continue;
5012
5013 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5014 {
5015 /* summary-only aggregate route suppress aggregated
5016 route announcement. */
5017 if (aggregate->summary_only)
5018 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005019 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005020 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005021 match++;
5022 }
Daniel Walton76a72802015-05-19 17:47:24 -07005023
5024 /* If at least one route among routes that are aggregated has
5025 * ORIGIN with the value INCOMPLETE, then the aggregated route
5026 * MUST have the ORIGIN attribute with the value INCOMPLETE.
5027 * Otherwise, if at least one route among routes that are
5028 * aggregated has ORIGIN with the value EGP, then the aggregated
5029 * route MUST have the ORIGIN attribute with the value EGP.
5030 */
5031 if (origin < ri->attr->origin)
5032 origin = ri->attr->origin;
5033
paul718e3742002-12-13 20:15:29 +00005034 /* as-set aggregate route generate origin, as path,
5035 community aggregation. */
5036 if (aggregate->as_set)
5037 {
paul718e3742002-12-13 20:15:29 +00005038 if (aspath)
5039 {
5040 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5041 aspath_free (aspath);
5042 aspath = asmerge;
5043 }
5044 else
5045 aspath = aspath_dup (ri->attr->aspath);
5046
5047 if (ri->attr->community)
5048 {
5049 if (community)
5050 {
5051 commerge = community_merge (community,
5052 ri->attr->community);
5053 community = community_uniq_sort (commerge);
5054 community_free (commerge);
5055 }
5056 else
5057 community = community_dup (ri->attr->community);
5058 }
5059 }
5060 aggregate->count++;
5061 }
5062 }
5063
5064 /* If this node is suppressed, process the change. */
5065 if (match)
5066 bgp_process (bgp, rn, afi, safi);
5067 }
5068 bgp_unlock_node (top);
5069
5070 /* Add aggregate route to BGP table. */
5071 if (aggregate->count)
5072 {
5073 rn = bgp_node_get (table, p);
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005074 new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_AGGREGATE, bgp->peer_self,
5075 bgp_attr_aggregate_intern(bgp, origin, aspath, community,
5076 aggregate->as_set), rn);
paul718e3742002-12-13 20:15:29 +00005077 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005078
5079 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005080 bgp_unlock_node (rn);
5081
paul718e3742002-12-13 20:15:29 +00005082 /* Process change. */
5083 bgp_process (bgp, rn, afi, safi);
5084 }
Denil Virae2a92582015-08-11 13:34:59 -07005085 else
5086 {
5087 if (aspath)
5088 aspath_free (aspath);
5089 if (community)
5090 community_free (community);
5091 }
paul718e3742002-12-13 20:15:29 +00005092}
5093
5094void
5095bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5096 safi_t safi, struct bgp_aggregate *aggregate)
5097{
5098 struct bgp_table *table;
5099 struct bgp_node *top;
5100 struct bgp_node *rn;
5101 struct bgp_info *ri;
5102 unsigned long match;
5103
5104 table = bgp->rib[afi][safi];
5105
5106 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5107 return;
5108 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5109 return;
5110
5111 /* If routes exists below this node, generate aggregate routes. */
5112 top = bgp_node_get (table, p);
5113 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5114 if (rn->p.prefixlen > p->prefixlen)
5115 {
5116 match = 0;
5117
5118 for (ri = rn->info; ri; ri = ri->next)
5119 {
5120 if (BGP_INFO_HOLDDOWN (ri))
5121 continue;
5122
5123 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5124 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005125 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005127 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005128
Paul Jakmafb982c22007-05-04 20:15:47 +00005129 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005130 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005131 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005132 match++;
5133 }
5134 }
5135 aggregate->count--;
5136 }
5137 }
5138
Paul Jakmafb982c22007-05-04 20:15:47 +00005139 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005140 if (match)
5141 bgp_process (bgp, rn, afi, safi);
5142 }
5143 bgp_unlock_node (top);
5144
5145 /* Delete aggregate route from BGP table. */
5146 rn = bgp_node_get (table, p);
5147
5148 for (ri = rn->info; ri; ri = ri->next)
5149 if (ri->peer == bgp->peer_self
5150 && ri->type == ZEBRA_ROUTE_BGP
5151 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5152 break;
5153
5154 /* Withdraw static BGP route from routing table. */
5155 if (ri)
5156 {
paul718e3742002-12-13 20:15:29 +00005157 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005158 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005159 }
5160
5161 /* Unlock bgp_node_lookup. */
5162 bgp_unlock_node (rn);
5163}
5164
5165/* Aggregate route attribute. */
5166#define AGGREGATE_SUMMARY_ONLY 1
5167#define AGGREGATE_AS_SET 1
5168
paul94f2b392005-06-28 12:44:16 +00005169static int
Robert Baysf6269b42010-08-05 10:26:28 -07005170bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5171 afi_t afi, safi_t safi)
5172{
5173 int ret;
5174 struct prefix p;
5175 struct bgp_node *rn;
5176 struct bgp *bgp;
5177 struct bgp_aggregate *aggregate;
5178
5179 /* Convert string to prefix structure. */
5180 ret = str2prefix (prefix_str, &p);
5181 if (!ret)
5182 {
5183 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186 apply_mask (&p);
5187
5188 /* Get BGP structure. */
5189 bgp = vty->index;
5190
5191 /* Old configuration check. */
5192 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5193 if (! rn)
5194 {
5195 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5196 VTY_NEWLINE);
5197 return CMD_WARNING;
5198 }
5199
5200 aggregate = rn->info;
5201 if (aggregate->safi & SAFI_UNICAST)
5202 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5203 if (aggregate->safi & SAFI_MULTICAST)
5204 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5205
5206 /* Unlock aggregate address configuration. */
5207 rn->info = NULL;
5208 bgp_aggregate_free (aggregate);
5209 bgp_unlock_node (rn);
5210 bgp_unlock_node (rn);
5211
5212 return CMD_SUCCESS;
5213}
5214
5215static int
5216bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005217 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005218 u_char summary_only, u_char as_set)
5219{
5220 int ret;
5221 struct prefix p;
5222 struct bgp_node *rn;
5223 struct bgp *bgp;
5224 struct bgp_aggregate *aggregate;
5225
5226 /* Convert string to prefix structure. */
5227 ret = str2prefix (prefix_str, &p);
5228 if (!ret)
5229 {
5230 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5231 return CMD_WARNING;
5232 }
5233 apply_mask (&p);
5234
5235 /* Get BGP structure. */
5236 bgp = vty->index;
5237
5238 /* Old configuration check. */
5239 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5240
5241 if (rn->info)
5242 {
5243 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005244 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005245 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5246 if (ret)
5247 {
Robert Bays368473f2010-08-05 10:26:29 -07005248 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5249 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005250 return CMD_WARNING;
5251 }
paul718e3742002-12-13 20:15:29 +00005252 }
5253
5254 /* Make aggregate address structure. */
5255 aggregate = bgp_aggregate_new ();
5256 aggregate->summary_only = summary_only;
5257 aggregate->as_set = as_set;
5258 aggregate->safi = safi;
5259 rn->info = aggregate;
5260
5261 /* Aggregate address insert into BGP routing table. */
5262 if (safi & SAFI_UNICAST)
5263 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (safi & SAFI_MULTICAST)
5265 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 return CMD_SUCCESS;
5268}
5269
paul718e3742002-12-13 20:15:29 +00005270DEFUN (aggregate_address,
5271 aggregate_address_cmd,
5272 "aggregate-address A.B.C.D/M",
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n")
5275{
5276 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5277}
5278
5279DEFUN (aggregate_address_mask,
5280 aggregate_address_mask_cmd,
5281 "aggregate-address A.B.C.D A.B.C.D",
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n")
5285{
5286 int ret;
5287 char prefix_str[BUFSIZ];
5288
5289 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5290
5291 if (! ret)
5292 {
5293 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5294 return CMD_WARNING;
5295 }
5296
5297 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5298 0, 0);
5299}
5300
5301DEFUN (aggregate_address_summary_only,
5302 aggregate_address_summary_only_cmd,
5303 "aggregate-address A.B.C.D/M summary-only",
5304 "Configure BGP aggregate entries\n"
5305 "Aggregate prefix\n"
5306 "Filter more specific routes from updates\n")
5307{
5308 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5309 AGGREGATE_SUMMARY_ONLY, 0);
5310}
5311
5312DEFUN (aggregate_address_mask_summary_only,
5313 aggregate_address_mask_summary_only_cmd,
5314 "aggregate-address A.B.C.D A.B.C.D summary-only",
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n")
5319{
5320 int ret;
5321 char prefix_str[BUFSIZ];
5322
5323 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5324
5325 if (! ret)
5326 {
5327 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5328 return CMD_WARNING;
5329 }
5330
5331 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5332 AGGREGATE_SUMMARY_ONLY, 0);
5333}
5334
5335DEFUN (aggregate_address_as_set,
5336 aggregate_address_as_set_cmd,
5337 "aggregate-address A.B.C.D/M as-set",
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Generate AS set path information\n")
5341{
5342 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5343 0, AGGREGATE_AS_SET);
5344}
5345
5346DEFUN (aggregate_address_mask_as_set,
5347 aggregate_address_mask_as_set_cmd,
5348 "aggregate-address A.B.C.D A.B.C.D as-set",
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate address\n"
5351 "Aggregate mask\n"
5352 "Generate AS set path information\n")
5353{
5354 int ret;
5355 char prefix_str[BUFSIZ];
5356
5357 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5358
5359 if (! ret)
5360 {
5361 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5362 return CMD_WARNING;
5363 }
5364
5365 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5366 0, AGGREGATE_AS_SET);
5367}
5368
5369
5370DEFUN (aggregate_address_as_set_summary,
5371 aggregate_address_as_set_summary_cmd,
5372 "aggregate-address A.B.C.D/M as-set summary-only",
5373 "Configure BGP aggregate entries\n"
5374 "Aggregate prefix\n"
5375 "Generate AS set path information\n"
5376 "Filter more specific routes from updates\n")
5377{
5378 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5379 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5380}
5381
5382ALIAS (aggregate_address_as_set_summary,
5383 aggregate_address_summary_as_set_cmd,
5384 "aggregate-address A.B.C.D/M summary-only as-set",
5385 "Configure BGP aggregate entries\n"
5386 "Aggregate prefix\n"
5387 "Filter more specific routes from updates\n"
5388 "Generate AS set path information\n")
5389
5390DEFUN (aggregate_address_mask_as_set_summary,
5391 aggregate_address_mask_as_set_summary_cmd,
5392 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate address\n"
5395 "Aggregate mask\n"
5396 "Generate AS set path information\n"
5397 "Filter more specific routes from updates\n")
5398{
5399 int ret;
5400 char prefix_str[BUFSIZ];
5401
5402 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5403
5404 if (! ret)
5405 {
5406 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5407 return CMD_WARNING;
5408 }
5409
5410 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5411 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5412}
5413
5414ALIAS (aggregate_address_mask_as_set_summary,
5415 aggregate_address_mask_summary_as_set_cmd,
5416 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5417 "Configure BGP aggregate entries\n"
5418 "Aggregate address\n"
5419 "Aggregate mask\n"
5420 "Filter more specific routes from updates\n"
5421 "Generate AS set path information\n")
5422
5423DEFUN (no_aggregate_address,
5424 no_aggregate_address_cmd,
5425 "no aggregate-address A.B.C.D/M",
5426 NO_STR
5427 "Configure BGP aggregate entries\n"
5428 "Aggregate prefix\n")
5429{
5430 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5431}
5432
5433ALIAS (no_aggregate_address,
5434 no_aggregate_address_summary_only_cmd,
5435 "no aggregate-address A.B.C.D/M summary-only",
5436 NO_STR
5437 "Configure BGP aggregate entries\n"
5438 "Aggregate prefix\n"
5439 "Filter more specific routes from updates\n")
5440
5441ALIAS (no_aggregate_address,
5442 no_aggregate_address_as_set_cmd,
5443 "no aggregate-address A.B.C.D/M as-set",
5444 NO_STR
5445 "Configure BGP aggregate entries\n"
5446 "Aggregate prefix\n"
5447 "Generate AS set path information\n")
5448
5449ALIAS (no_aggregate_address,
5450 no_aggregate_address_as_set_summary_cmd,
5451 "no aggregate-address A.B.C.D/M as-set summary-only",
5452 NO_STR
5453 "Configure BGP aggregate entries\n"
5454 "Aggregate prefix\n"
5455 "Generate AS set path information\n"
5456 "Filter more specific routes from updates\n")
5457
5458ALIAS (no_aggregate_address,
5459 no_aggregate_address_summary_as_set_cmd,
5460 "no aggregate-address A.B.C.D/M summary-only as-set",
5461 NO_STR
5462 "Configure BGP aggregate entries\n"
5463 "Aggregate prefix\n"
5464 "Filter more specific routes from updates\n"
5465 "Generate AS set path information\n")
5466
5467DEFUN (no_aggregate_address_mask,
5468 no_aggregate_address_mask_cmd,
5469 "no aggregate-address A.B.C.D A.B.C.D",
5470 NO_STR
5471 "Configure BGP aggregate entries\n"
5472 "Aggregate address\n"
5473 "Aggregate mask\n")
5474{
5475 int ret;
5476 char prefix_str[BUFSIZ];
5477
5478 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5479
5480 if (! ret)
5481 {
5482 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5483 return CMD_WARNING;
5484 }
5485
5486 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5487}
5488
5489ALIAS (no_aggregate_address_mask,
5490 no_aggregate_address_mask_summary_only_cmd,
5491 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5492 NO_STR
5493 "Configure BGP aggregate entries\n"
5494 "Aggregate address\n"
5495 "Aggregate mask\n"
5496 "Filter more specific routes from updates\n")
5497
5498ALIAS (no_aggregate_address_mask,
5499 no_aggregate_address_mask_as_set_cmd,
5500 "no aggregate-address A.B.C.D A.B.C.D as-set",
5501 NO_STR
5502 "Configure BGP aggregate entries\n"
5503 "Aggregate address\n"
5504 "Aggregate mask\n"
5505 "Generate AS set path information\n")
5506
5507ALIAS (no_aggregate_address_mask,
5508 no_aggregate_address_mask_as_set_summary_cmd,
5509 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5510 NO_STR
5511 "Configure BGP aggregate entries\n"
5512 "Aggregate address\n"
5513 "Aggregate mask\n"
5514 "Generate AS set path information\n"
5515 "Filter more specific routes from updates\n")
5516
5517ALIAS (no_aggregate_address_mask,
5518 no_aggregate_address_mask_summary_as_set_cmd,
5519 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5520 NO_STR
5521 "Configure BGP aggregate entries\n"
5522 "Aggregate address\n"
5523 "Aggregate mask\n"
5524 "Filter more specific routes from updates\n"
5525 "Generate AS set path information\n")
5526
paul718e3742002-12-13 20:15:29 +00005527DEFUN (ipv6_aggregate_address,
5528 ipv6_aggregate_address_cmd,
5529 "aggregate-address X:X::X:X/M",
5530 "Configure BGP aggregate entries\n"
5531 "Aggregate prefix\n")
5532{
5533 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5534}
5535
5536DEFUN (ipv6_aggregate_address_summary_only,
5537 ipv6_aggregate_address_summary_only_cmd,
5538 "aggregate-address X:X::X:X/M summary-only",
5539 "Configure BGP aggregate entries\n"
5540 "Aggregate prefix\n"
5541 "Filter more specific routes from updates\n")
5542{
5543 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5544 AGGREGATE_SUMMARY_ONLY, 0);
5545}
5546
5547DEFUN (no_ipv6_aggregate_address,
5548 no_ipv6_aggregate_address_cmd,
5549 "no aggregate-address X:X::X:X/M",
5550 NO_STR
5551 "Configure BGP aggregate entries\n"
5552 "Aggregate prefix\n")
5553{
5554 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5555}
5556
5557DEFUN (no_ipv6_aggregate_address_summary_only,
5558 no_ipv6_aggregate_address_summary_only_cmd,
5559 "no aggregate-address X:X::X:X/M summary-only",
5560 NO_STR
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate prefix\n"
5563 "Filter more specific routes from updates\n")
5564{
5565 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5566}
5567
5568ALIAS (ipv6_aggregate_address,
5569 old_ipv6_aggregate_address_cmd,
5570 "ipv6 bgp aggregate-address X:X::X:X/M",
5571 IPV6_STR
5572 BGP_STR
5573 "Configure BGP aggregate entries\n"
5574 "Aggregate prefix\n")
5575
5576ALIAS (ipv6_aggregate_address_summary_only,
5577 old_ipv6_aggregate_address_summary_only_cmd,
5578 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5579 IPV6_STR
5580 BGP_STR
5581 "Configure BGP aggregate entries\n"
5582 "Aggregate prefix\n"
5583 "Filter more specific routes from updates\n")
5584
5585ALIAS (no_ipv6_aggregate_address,
5586 old_no_ipv6_aggregate_address_cmd,
5587 "no ipv6 bgp aggregate-address X:X::X:X/M",
5588 NO_STR
5589 IPV6_STR
5590 BGP_STR
5591 "Configure BGP aggregate entries\n"
5592 "Aggregate prefix\n")
5593
5594ALIAS (no_ipv6_aggregate_address_summary_only,
5595 old_no_ipv6_aggregate_address_summary_only_cmd,
5596 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5597 NO_STR
5598 IPV6_STR
5599 BGP_STR
5600 "Configure BGP aggregate entries\n"
5601 "Aggregate prefix\n"
5602 "Filter more specific routes from updates\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02005603
paul718e3742002-12-13 20:15:29 +00005604/* Redistribute route treatment. */
5605void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005606bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5607 const struct in6_addr *nexthop6,
Paul Jakma96d10602016-07-01 14:23:45 +01005608 u_int32_t metric, u_char type, route_tag_t tag)
paul718e3742002-12-13 20:15:29 +00005609{
5610 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005611 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005612 struct bgp_info *new;
5613 struct bgp_info *bi;
5614 struct bgp_info info;
5615 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005616 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005617 struct attr *new_attr;
5618 afi_t afi;
5619 int ret;
5620
5621 /* Make default attribute. */
5622 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5623 if (nexthop)
5624 attr.nexthop = *nexthop;
5625
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005626 if (nexthop6)
5627 {
5628 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5629 extra->mp_nexthop_global = *nexthop6;
5630 extra->mp_nexthop_len = 16;
5631 }
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005632
paul718e3742002-12-13 20:15:29 +00005633 attr.med = metric;
5634 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Piotr Chytła605aa332015-12-01 10:03:54 -05005635 attr.extra->tag = tag;
paul718e3742002-12-13 20:15:29 +00005636
paul1eb8ef22005-04-07 07:30:20 +00005637 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005638 {
5639 afi = family2afi (p->family);
5640
5641 if (bgp->redist[afi][type])
5642 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005643 struct attr attr_new;
5644 struct attr_extra extra_new;
5645
paul718e3742002-12-13 20:15:29 +00005646 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005647 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005648 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005649
5650 if (bgp->redist_metric_flag[afi][type])
5651 attr_new.med = bgp->redist_metric[afi][type];
5652
5653 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005654 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005655 {
5656 info.peer = bgp->peer_self;
5657 info.attr = &attr_new;
5658
paulfee0f4c2004-09-13 05:12:46 +00005659 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5660
paul718e3742002-12-13 20:15:29 +00005661 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5662 &info);
paulfee0f4c2004-09-13 05:12:46 +00005663
5664 bgp->peer_self->rmap_type = 0;
5665
paul718e3742002-12-13 20:15:29 +00005666 if (ret == RMAP_DENYMATCH)
5667 {
5668 /* Free uninterned attribute. */
5669 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005670
paul718e3742002-12-13 20:15:29 +00005671 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005672 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005673 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005674 bgp_redistribute_delete (p, type);
5675 return;
5676 }
5677 }
5678
Paul Jakmafb982c22007-05-04 20:15:47 +00005679 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5680 afi, SAFI_UNICAST, p, NULL);
5681
paul718e3742002-12-13 20:15:29 +00005682 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005683
paul718e3742002-12-13 20:15:29 +00005684 for (bi = bn->info; bi; bi = bi->next)
5685 if (bi->peer == bgp->peer_self
5686 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5687 break;
5688
5689 if (bi)
5690 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005691 if (attrhash_cmp (bi->attr, new_attr) &&
5692 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005693 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005694 bgp_attr_unintern (&new_attr);
5695 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005696 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005697 bgp_unlock_node (bn);
5698 return;
5699 }
5700 else
5701 {
5702 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005703 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005704
5705 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005706 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5707 bgp_info_restore(bn, bi);
5708 else
5709 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005710 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005711 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005712 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005713
5714 /* Process change. */
5715 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5716 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5717 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005718 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005719 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005720 return;
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005721 }
paul718e3742002-12-13 20:15:29 +00005722 }
5723
Pradosh Mohapatra60cc9592015-11-09 20:21:41 -05005724 new = info_make(type, BGP_ROUTE_REDISTRIBUTE, bgp->peer_self,
5725 new_attr, bn);
paul718e3742002-12-13 20:15:29 +00005726 SET_FLAG (new->flags, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00005727
5728 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5729 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005730 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005731 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5732 }
5733 }
5734
5735 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005736 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005738}
5739
5740void
5741bgp_redistribute_delete (struct prefix *p, u_char type)
5742{
5743 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005744 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005745 afi_t afi;
5746 struct bgp_node *rn;
5747 struct bgp_info *ri;
5748
paul1eb8ef22005-04-07 07:30:20 +00005749 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005750 {
5751 afi = family2afi (p->family);
5752
5753 if (bgp->redist[afi][type])
5754 {
paulfee0f4c2004-09-13 05:12:46 +00005755 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005756
5757 for (ri = rn->info; ri; ri = ri->next)
5758 if (ri->peer == bgp->peer_self
5759 && ri->type == type)
5760 break;
5761
5762 if (ri)
5763 {
5764 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005765 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005766 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005767 }
5768 bgp_unlock_node (rn);
5769 }
5770 }
5771}
5772
5773/* Withdraw specified route type's route. */
5774void
5775bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5776{
5777 struct bgp_node *rn;
5778 struct bgp_info *ri;
5779 struct bgp_table *table;
5780
5781 table = bgp->rib[afi][SAFI_UNICAST];
5782
5783 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5784 {
5785 for (ri = rn->info; ri; ri = ri->next)
5786 if (ri->peer == bgp->peer_self
5787 && ri->type == type)
5788 break;
5789
5790 if (ri)
5791 {
5792 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005793 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005794 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005795 }
5796 }
5797}
David Lamparter6b0655a2014-06-04 06:53:35 +02005798
paul718e3742002-12-13 20:15:29 +00005799/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005800static void
paul718e3742002-12-13 20:15:29 +00005801route_vty_out_route (struct prefix *p, struct vty *vty)
5802{
5803 int len;
5804 u_int32_t destination;
5805 char buf[BUFSIZ];
5806
5807 if (p->family == AF_INET)
5808 {
5809 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5810 destination = ntohl (p->u.prefix4.s_addr);
5811
5812 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5813 || (IN_CLASSB (destination) && p->prefixlen == 16)
5814 || (IN_CLASSA (destination) && p->prefixlen == 8)
5815 || p->u.prefix4.s_addr == 0)
5816 {
5817 /* When mask is natural, mask is not displayed. */
5818 }
5819 else
5820 len += vty_out (vty, "/%d", p->prefixlen);
5821 }
5822 else
5823 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5824 p->prefixlen);
5825
5826 len = 17 - len;
5827 if (len < 1)
5828 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5829 else
5830 vty_out (vty, "%*s", len, " ");
5831}
5832
paul718e3742002-12-13 20:15:29 +00005833enum bgp_display_type
5834{
5835 normal_list,
5836};
5837
paulb40d9392005-08-22 22:34:41 +00005838/* Print the short form route status for a bgp_info */
5839static void
5840route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005841{
paulb40d9392005-08-22 22:34:41 +00005842 /* Route status display. */
5843 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5844 vty_out (vty, "R");
5845 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005846 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005847 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005848 vty_out (vty, "s");
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07005849 else if (CHECK_FLAG (binfo->flags, BGP_INFO_VALID) &&
5850 ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00005851 vty_out (vty, "*");
5852 else
5853 vty_out (vty, " ");
5854
5855 /* Selected */
5856 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5857 vty_out (vty, "h");
5858 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5859 vty_out (vty, "d");
5860 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5861 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005862 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5863 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005864 else
5865 vty_out (vty, " ");
5866
5867 /* Internal route. */
5868 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5869 vty_out (vty, "i");
5870 else
paulb40d9392005-08-22 22:34:41 +00005871 vty_out (vty, " ");
5872}
5873
5874/* called from terminal list command */
5875void
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005876route_vty_out(
5877 struct vty *vty,
5878 struct prefix *p,
5879 struct bgp_info *binfo,
5880 int display,
5881 safi_t safi)
paulb40d9392005-08-22 22:34:41 +00005882{
5883 struct attr *attr;
5884
5885 /* short status lead text */
5886 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005887
5888 /* print prefix and mask */
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005889 if (!display)
paul718e3742002-12-13 20:15:29 +00005890 route_vty_out_route (p, vty);
5891 else
5892 vty_out (vty, "%*s", 17, " ");
5893
5894 /* Print attribute */
5895 attr = binfo->attr;
5896 if (attr)
5897 {
paul718e3742002-12-13 20:15:29 +00005898
Lou Berger298cc2f2016-01-12 13:42:02 -05005899 /*
5900 * NEXTHOP start
5901 */
5902
5903 /*
5904 * For ENCAP routes, nexthop address family is not
5905 * neccessarily the same as the prefix address family.
5906 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5907 */
5908 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5909 if (attr->extra) {
5910 char buf[BUFSIZ];
5911 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5912
5913 switch (af) {
5914 case AF_INET:
5915 vty_out (vty, "%s", inet_ntop(af,
5916 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5917 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005918 case AF_INET6:
5919 vty_out (vty, "%s", inet_ntop(af,
5920 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5921 break;
Lou Berger298cc2f2016-01-12 13:42:02 -05005922 default:
5923 vty_out(vty, "?");
5924 }
5925 } else {
5926 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005927 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005928 } else {
5929
5930 if (p->family == AF_INET)
5931 {
5932 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5933 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005934 else if (p->family == AF_INET6)
5935 {
5936 int len;
5937 char buf[BUFSIZ];
5938
5939 len = vty_out (vty, "%s",
5940 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5941 buf, BUFSIZ));
5942 len = 16 - len;
5943 if (len < 1)
5944 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5945 else
5946 vty_out (vty, "%*s", len, " ");
5947 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005948 else
5949 {
5950 vty_out(vty, "?");
5951 }
5952 }
5953
5954 /*
5955 * NEXTHOP end
5956 */
5957
paul718e3742002-12-13 20:15:29 +00005958
5959 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005960 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00005961 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005962 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005963
5964 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005965 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005966 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05005967 vty_out (vty, " ");
paul718e3742002-12-13 20:15:29 +00005968
Paul Jakmafb982c22007-05-04 20:15:47 +00005969 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005970
Paul Jakmab2518c12006-05-12 23:48:40 +00005971 /* Print aspath */
5972 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005973 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005974
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005976 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005977 }
paul718e3742002-12-13 20:15:29 +00005978 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005979}
5980
5981/* called from terminal list command */
5982void
5983route_vty_out_tmp (struct vty *vty, struct prefix *p,
5984 struct attr *attr, safi_t safi)
5985{
5986 /* Route status display. */
5987 vty_out (vty, "*");
5988 vty_out (vty, ">");
5989 vty_out (vty, " ");
5990
5991 /* print prefix and mask */
5992 route_vty_out_route (p, vty);
5993
5994 /* Print attribute */
5995 if (attr)
5996 {
5997 if (p->family == AF_INET)
5998 {
Lou Berger298cc2f2016-01-12 13:42:02 -05005999 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006000 vty_out (vty, "%-16s",
6001 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006002 else
6003 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6004 }
paul718e3742002-12-13 20:15:29 +00006005 else if (p->family == AF_INET6)
6006 {
6007 int len;
6008 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006009
6010 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006011
6012 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006013 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6014 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006015 len = 16 - len;
6016 if (len < 1)
6017 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6018 else
6019 vty_out (vty, "%*s", len, " ");
6020 }
paul718e3742002-12-13 20:15:29 +00006021
6022 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006023 vty_out (vty, "%10u ", attr->med);
paul718e3742002-12-13 20:15:29 +00006024 else
6025 vty_out (vty, " ");
6026
6027 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006028 vty_out (vty, "%7u ", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006029 else
6030 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006031
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006032 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006033
Paul Jakmab2518c12006-05-12 23:48:40 +00006034 /* Print aspath */
6035 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006036 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006037
Paul Jakmab2518c12006-05-12 23:48:40 +00006038 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006039 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006040 }
paul718e3742002-12-13 20:15:29 +00006041
6042 vty_out (vty, "%s", VTY_NEWLINE);
6043}
6044
ajs5a646652004-11-05 01:25:55 +00006045void
paul718e3742002-12-13 20:15:29 +00006046route_vty_out_tag (struct vty *vty, struct prefix *p,
6047 struct bgp_info *binfo, int display, safi_t safi)
6048{
6049 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006050 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006051
6052 if (!binfo->extra)
6053 return;
6054
paulb40d9392005-08-22 22:34:41 +00006055 /* short status lead text */
6056 route_vty_short_status_out (vty, binfo);
6057
paul718e3742002-12-13 20:15:29 +00006058 /* print prefix and mask */
6059 if (! display)
6060 route_vty_out_route (p, vty);
6061 else
6062 vty_out (vty, "%*s", 17, " ");
6063
6064 /* Print attribute */
6065 attr = binfo->attr;
6066 if (attr)
6067 {
6068 if (p->family == AF_INET)
6069 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006070 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 vty_out (vty, "%-16s",
6072 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006073 else
6074 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6075 }
paul718e3742002-12-13 20:15:29 +00006076 else if (p->family == AF_INET6)
6077 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006079 char buf[BUFSIZ];
6080 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006081 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006082 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006083 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6084 buf, BUFSIZ));
6085 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006086 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006087 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6088 buf, BUFSIZ),
6089 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6090 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006091
6092 }
paul718e3742002-12-13 20:15:29 +00006093 }
6094
Paul Jakmafb982c22007-05-04 20:15:47 +00006095 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006096
6097 vty_out (vty, "notag/%d", label);
6098
6099 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006100}
6101
6102/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006103static void
paul718e3742002-12-13 20:15:29 +00006104damp_route_vty_out (struct vty *vty, struct prefix *p,
6105 struct bgp_info *binfo, int display, safi_t safi)
6106{
6107 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006108 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006109 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006110
paulb40d9392005-08-22 22:34:41 +00006111 /* short status lead text */
6112 route_vty_short_status_out (vty, binfo);
6113
paul718e3742002-12-13 20:15:29 +00006114 /* print prefix and mask */
6115 if (! display)
6116 route_vty_out_route (p, vty);
6117 else
6118 vty_out (vty, "%*s", 17, " ");
6119
6120 len = vty_out (vty, "%s", binfo->peer->host);
6121 len = 17 - len;
6122 if (len < 1)
6123 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6124 else
6125 vty_out (vty, "%*s", len, " ");
6126
Chris Caputo50aef6f2009-06-23 06:06:49 +00006127 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006128
6129 /* Print attribute */
6130 attr = binfo->attr;
6131 if (attr)
6132 {
6133 /* Print aspath */
6134 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006135 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006136
6137 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006138 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006139 }
6140 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006141}
6142
paul718e3742002-12-13 20:15:29 +00006143/* flap route */
ajs5a646652004-11-05 01:25:55 +00006144static void
paul718e3742002-12-13 20:15:29 +00006145flap_route_vty_out (struct vty *vty, struct prefix *p,
6146 struct bgp_info *binfo, int display, safi_t safi)
6147{
6148 struct attr *attr;
6149 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006150 char timebuf[BGP_UPTIME_LEN];
6151 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006152
6153 if (!binfo->extra)
6154 return;
6155
6156 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006157
paulb40d9392005-08-22 22:34:41 +00006158 /* short status lead text */
6159 route_vty_short_status_out (vty, binfo);
6160
paul718e3742002-12-13 20:15:29 +00006161 /* print prefix and mask */
6162 if (! display)
6163 route_vty_out_route (p, vty);
6164 else
6165 vty_out (vty, "%*s", 17, " ");
6166
6167 len = vty_out (vty, "%s", binfo->peer->host);
6168 len = 16 - len;
6169 if (len < 1)
6170 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6171 else
6172 vty_out (vty, "%*s", len, " ");
6173
6174 len = vty_out (vty, "%d", bdi->flap);
6175 len = 5 - len;
6176 if (len < 1)
6177 vty_out (vty, " ");
6178 else
6179 vty_out (vty, "%*s ", len, " ");
6180
6181 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6182 timebuf, BGP_UPTIME_LEN));
6183
6184 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6185 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006186 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006187 else
6188 vty_out (vty, "%*s ", 8, " ");
6189
6190 /* Print attribute */
6191 attr = binfo->attr;
6192 if (attr)
6193 {
6194 /* Print aspath */
6195 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006196 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006197
6198 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006199 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006200 }
6201 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006202}
6203
paul94f2b392005-06-28 12:44:16 +00006204static void
paul718e3742002-12-13 20:15:29 +00006205route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6206 struct bgp_info *binfo, afi_t afi, safi_t safi)
6207{
6208 char buf[INET6_ADDRSTRLEN];
6209 char buf1[BUFSIZ];
6210 struct attr *attr;
6211 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006212#ifdef HAVE_CLOCK_MONOTONIC
6213 time_t tbuf;
6214#endif
paul718e3742002-12-13 20:15:29 +00006215
6216 attr = binfo->attr;
6217
6218 if (attr)
6219 {
6220 /* Line1 display AS-path, Aggregator */
6221 if (attr->aspath)
6222 {
6223 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006224 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006225 vty_out (vty, "Local");
6226 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006227 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006228 }
6229
paulb40d9392005-08-22 22:34:41 +00006230 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6231 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006232 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6233 vty_out (vty, ", (stale)");
6234 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006235 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006236 attr->extra->aggregator_as,
6237 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006238 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6239 vty_out (vty, ", (Received from a RR-client)");
6240 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6241 vty_out (vty, ", (Received from a RS-client)");
6242 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6243 vty_out (vty, ", (history entry)");
6244 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6245 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006246 vty_out (vty, "%s", VTY_NEWLINE);
6247
6248 /* Line2 display Next-hop, Neighbor, Router-id */
6249 if (p->family == AF_INET)
6250 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006251 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006252 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006253 inet_ntoa (attr->nexthop));
6254 }
paul718e3742002-12-13 20:15:29 +00006255 else
6256 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006257 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006258 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006259 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006260 buf, INET6_ADDRSTRLEN));
6261 }
paul718e3742002-12-13 20:15:29 +00006262
6263 if (binfo->peer == bgp->peer_self)
6264 {
6265 vty_out (vty, " from %s ",
6266 p->family == AF_INET ? "0.0.0.0" : "::");
6267 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6268 }
6269 else
6270 {
6271 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6272 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006273 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006274 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006275 if (!sockunion2str (&binfo->peer->su, buf, sizeof(buf))) {
6276 buf[0] = '?';
6277 buf[1] = 0;
6278 }
6279 vty_out (vty, " from %s", buf);
paul718e3742002-12-13 20:15:29 +00006280 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006281 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006282 else
6283 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6284 }
6285 vty_out (vty, "%s", VTY_NEWLINE);
6286
paul718e3742002-12-13 20:15:29 +00006287 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006288 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006289 {
6290 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006291 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006292 buf, INET6_ADDRSTRLEN),
6293 VTY_NEWLINE);
6294 }
paul718e3742002-12-13 20:15:29 +00006295
Piotr Chytła605aa332015-12-01 10:03:54 -05006296 /* Line 3 display Origin, Med, Locpref, Weight, Tag, valid, Int/Ext/Local, Atomic, best */
paul718e3742002-12-13 20:15:29 +00006297 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6298
6299 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006300 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006301
6302 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006303 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006304 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006305 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006306
Paul Jakmafb982c22007-05-04 20:15:47 +00006307 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006308 vty_out (vty, ", weight %u", attr->extra->weight);
Piotr Chytła605aa332015-12-01 10:03:54 -05006309
6310 if (attr->extra && attr->extra->tag != 0)
6311 vty_out (vty, ", tag %d", attr->extra->tag);
paul718e3742002-12-13 20:15:29 +00006312
Daniel Waltone2a0ebf2015-05-19 18:03:43 -07006313 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6314 vty_out (vty, ", invalid");
6315 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
paul718e3742002-12-13 20:15:29 +00006316 vty_out (vty, ", valid");
6317
6318 if (binfo->peer != bgp->peer_self)
6319 {
6320 if (binfo->peer->as == binfo->peer->local_as)
6321 vty_out (vty, ", internal");
6322 else
6323 vty_out (vty, ", %s",
6324 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6325 }
6326 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6327 vty_out (vty, ", aggregated, local");
6328 else if (binfo->type != ZEBRA_ROUTE_BGP)
6329 vty_out (vty, ", sourced");
6330 else
6331 vty_out (vty, ", sourced, local");
6332
6333 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6334 vty_out (vty, ", atomic-aggregate");
6335
Josh Baileyde8d5df2011-07-20 20:46:01 -07006336 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6337 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6338 bgp_info_mpath_count (binfo)))
6339 vty_out (vty, ", multipath");
6340
paul718e3742002-12-13 20:15:29 +00006341 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6342 vty_out (vty, ", best");
6343
6344 vty_out (vty, "%s", VTY_NEWLINE);
6345
6346 /* Line 4 display Community */
6347 if (attr->community)
6348 vty_out (vty, " Community: %s%s", attr->community->str,
6349 VTY_NEWLINE);
6350
6351 /* Line 5 display Extended-community */
6352 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006353 vty_out (vty, " Extended Community: %s%s",
6354 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006355
6356 /* Line 6 display Originator, Cluster-id */
6357 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6358 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6359 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006360 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006361 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 vty_out (vty, " Originator: %s",
6363 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006364
6365 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6366 {
6367 int i;
6368 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006369 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6370 vty_out (vty, "%s ",
6371 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006372 }
6373 vty_out (vty, "%s", VTY_NEWLINE);
6374 }
Paul Jakma41367172007-08-06 15:24:51 +00006375
Paul Jakmafb982c22007-05-04 20:15:47 +00006376 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006377 bgp_damp_info_vty (vty, binfo);
6378
6379 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006380#ifdef HAVE_CLOCK_MONOTONIC
6381 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006382 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006383#else
6384 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6385#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006386 }
6387 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006388}
6389
6390#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6391 "h history, * valid, > best, = multipath,%s"\
6392 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006393#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006394#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6395#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6396#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6397
6398enum bgp_show_type
6399{
6400 bgp_show_type_normal,
6401 bgp_show_type_regexp,
6402 bgp_show_type_prefix_list,
6403 bgp_show_type_filter_list,
6404 bgp_show_type_route_map,
6405 bgp_show_type_neighbor,
6406 bgp_show_type_cidr_only,
6407 bgp_show_type_prefix_longer,
6408 bgp_show_type_community_all,
6409 bgp_show_type_community,
6410 bgp_show_type_community_exact,
6411 bgp_show_type_community_list,
6412 bgp_show_type_community_list_exact,
6413 bgp_show_type_flap_statistics,
6414 bgp_show_type_flap_address,
6415 bgp_show_type_flap_prefix,
6416 bgp_show_type_flap_cidr_only,
6417 bgp_show_type_flap_regexp,
6418 bgp_show_type_flap_filter_list,
6419 bgp_show_type_flap_prefix_list,
6420 bgp_show_type_flap_prefix_longer,
6421 bgp_show_type_flap_route_map,
6422 bgp_show_type_flap_neighbor,
6423 bgp_show_type_dampend_paths,
6424 bgp_show_type_damp_neighbor
6425};
6426
ajs5a646652004-11-05 01:25:55 +00006427static int
paulfee0f4c2004-09-13 05:12:46 +00006428bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006429 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006430{
paul718e3742002-12-13 20:15:29 +00006431 struct bgp_info *ri;
6432 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006433 int header = 1;
paul718e3742002-12-13 20:15:29 +00006434 int display;
ajs5a646652004-11-05 01:25:55 +00006435 unsigned long output_count;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006436 unsigned long total_count;
paul718e3742002-12-13 20:15:29 +00006437
6438 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006439 output_count = 0;
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006440 total_count = 0;
paul718e3742002-12-13 20:15:29 +00006441
paul718e3742002-12-13 20:15:29 +00006442 /* Start processing of routes. */
6443 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6444 if (rn->info != NULL)
6445 {
6446 display = 0;
6447
6448 for (ri = rn->info; ri; ri = ri->next)
6449 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006450 total_count++;
ajs5a646652004-11-05 01:25:55 +00006451 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006452 || type == bgp_show_type_flap_address
6453 || type == bgp_show_type_flap_prefix
6454 || type == bgp_show_type_flap_cidr_only
6455 || type == bgp_show_type_flap_regexp
6456 || type == bgp_show_type_flap_filter_list
6457 || type == bgp_show_type_flap_prefix_list
6458 || type == bgp_show_type_flap_prefix_longer
6459 || type == bgp_show_type_flap_route_map
6460 || type == bgp_show_type_flap_neighbor
6461 || type == bgp_show_type_dampend_paths
6462 || type == bgp_show_type_damp_neighbor)
6463 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006464 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006465 continue;
6466 }
6467 if (type == bgp_show_type_regexp
6468 || type == bgp_show_type_flap_regexp)
6469 {
ajs5a646652004-11-05 01:25:55 +00006470 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006471
6472 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6473 continue;
6474 }
6475 if (type == bgp_show_type_prefix_list
6476 || type == bgp_show_type_flap_prefix_list)
6477 {
ajs5a646652004-11-05 01:25:55 +00006478 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006479
6480 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6481 continue;
6482 }
6483 if (type == bgp_show_type_filter_list
6484 || type == bgp_show_type_flap_filter_list)
6485 {
ajs5a646652004-11-05 01:25:55 +00006486 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006487
6488 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6489 continue;
6490 }
6491 if (type == bgp_show_type_route_map
6492 || type == bgp_show_type_flap_route_map)
6493 {
ajs5a646652004-11-05 01:25:55 +00006494 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006495 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006496 struct attr dummy_attr;
6497 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006498 int ret;
6499
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006500 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006501 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006502
paul718e3742002-12-13 20:15:29 +00006503 binfo.peer = ri->peer;
6504 binfo.attr = &dummy_attr;
6505
6506 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006507 if (ret == RMAP_DENYMATCH)
6508 continue;
6509 }
6510 if (type == bgp_show_type_neighbor
6511 || type == bgp_show_type_flap_neighbor
6512 || type == bgp_show_type_damp_neighbor)
6513 {
ajs5a646652004-11-05 01:25:55 +00006514 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006515
6516 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6517 continue;
6518 }
6519 if (type == bgp_show_type_cidr_only
6520 || type == bgp_show_type_flap_cidr_only)
6521 {
6522 u_int32_t destination;
6523
6524 destination = ntohl (rn->p.u.prefix4.s_addr);
6525 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6526 continue;
6527 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6528 continue;
6529 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6530 continue;
6531 }
6532 if (type == bgp_show_type_prefix_longer
6533 || type == bgp_show_type_flap_prefix_longer)
6534 {
ajs5a646652004-11-05 01:25:55 +00006535 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006536
6537 if (! prefix_match (p, &rn->p))
6538 continue;
6539 }
6540 if (type == bgp_show_type_community_all)
6541 {
6542 if (! ri->attr->community)
6543 continue;
6544 }
6545 if (type == bgp_show_type_community)
6546 {
ajs5a646652004-11-05 01:25:55 +00006547 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006548
6549 if (! ri->attr->community ||
6550 ! community_match (ri->attr->community, com))
6551 continue;
6552 }
6553 if (type == bgp_show_type_community_exact)
6554 {
ajs5a646652004-11-05 01:25:55 +00006555 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006556
6557 if (! ri->attr->community ||
6558 ! community_cmp (ri->attr->community, com))
6559 continue;
6560 }
6561 if (type == bgp_show_type_community_list)
6562 {
ajs5a646652004-11-05 01:25:55 +00006563 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006564
6565 if (! community_list_match (ri->attr->community, list))
6566 continue;
6567 }
6568 if (type == bgp_show_type_community_list_exact)
6569 {
ajs5a646652004-11-05 01:25:55 +00006570 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006571
6572 if (! community_list_exact_match (ri->attr->community, list))
6573 continue;
6574 }
6575 if (type == bgp_show_type_flap_address
6576 || type == bgp_show_type_flap_prefix)
6577 {
ajs5a646652004-11-05 01:25:55 +00006578 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006579
6580 if (! prefix_match (&rn->p, p))
6581 continue;
6582
6583 if (type == bgp_show_type_flap_prefix)
6584 if (p->prefixlen != rn->p.prefixlen)
6585 continue;
6586 }
6587 if (type == bgp_show_type_dampend_paths
6588 || type == bgp_show_type_damp_neighbor)
6589 {
6590 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6591 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6592 continue;
6593 }
6594
6595 if (header)
6596 {
hasso93406d82005-02-02 14:40:33 +00006597 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6598 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6599 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006600 if (type == bgp_show_type_dampend_paths
6601 || type == bgp_show_type_damp_neighbor)
6602 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6603 else if (type == bgp_show_type_flap_statistics
6604 || type == bgp_show_type_flap_address
6605 || type == bgp_show_type_flap_prefix
6606 || type == bgp_show_type_flap_cidr_only
6607 || type == bgp_show_type_flap_regexp
6608 || type == bgp_show_type_flap_filter_list
6609 || type == bgp_show_type_flap_prefix_list
6610 || type == bgp_show_type_flap_prefix_longer
6611 || type == bgp_show_type_flap_route_map
6612 || type == bgp_show_type_flap_neighbor)
6613 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6614 else
6615 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006616 header = 0;
6617 }
6618
6619 if (type == bgp_show_type_dampend_paths
6620 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006621 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006622 else if (type == bgp_show_type_flap_statistics
6623 || type == bgp_show_type_flap_address
6624 || type == bgp_show_type_flap_prefix
6625 || type == bgp_show_type_flap_cidr_only
6626 || type == bgp_show_type_flap_regexp
6627 || type == bgp_show_type_flap_filter_list
6628 || type == bgp_show_type_flap_prefix_list
6629 || type == bgp_show_type_flap_prefix_longer
6630 || type == bgp_show_type_flap_route_map
6631 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006632 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006633 else
ajs5a646652004-11-05 01:25:55 +00006634 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006635 display++;
6636 }
6637 if (display)
ajs5a646652004-11-05 01:25:55 +00006638 output_count++;
paul718e3742002-12-13 20:15:29 +00006639 }
6640
6641 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006642 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006643 {
6644 if (type == bgp_show_type_normal)
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006645 vty_out (vty, "No BGP prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006646 }
6647 else
Lou Bergerbf1ae6c2016-01-12 13:42:08 -05006648 vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
6649 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006650
6651 return CMD_SUCCESS;
6652}
6653
ajs5a646652004-11-05 01:25:55 +00006654static int
paulfee0f4c2004-09-13 05:12:46 +00006655bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006656 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006657{
6658 struct bgp_table *table;
6659
6660 if (bgp == NULL) {
6661 bgp = bgp_get_default ();
6662 }
6663
6664 if (bgp == NULL)
6665 {
6666 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6667 return CMD_WARNING;
6668 }
6669
6670
6671 table = bgp->rib[afi][safi];
6672
ajs5a646652004-11-05 01:25:55 +00006673 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006674}
6675
paul718e3742002-12-13 20:15:29 +00006676/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006677static void
paul718e3742002-12-13 20:15:29 +00006678route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6679 struct bgp_node *rn,
6680 struct prefix_rd *prd, afi_t afi, safi_t safi)
6681{
6682 struct bgp_info *ri;
6683 struct prefix *p;
6684 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006685 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006686 char buf1[INET6_ADDRSTRLEN];
6687 char buf2[INET6_ADDRSTRLEN];
6688 int count = 0;
6689 int best = 0;
6690 int suppress = 0;
6691 int no_export = 0;
6692 int no_advertise = 0;
6693 int local_as = 0;
6694 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006695 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006696
6697 p = &rn->p;
6698 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006699 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6700 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006701 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6702 p->prefixlen, VTY_NEWLINE);
6703
6704 for (ri = rn->info; ri; ri = ri->next)
6705 {
6706 count++;
6707 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6708 {
6709 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006710 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006711 suppress = 1;
6712 if (ri->attr->community != NULL)
6713 {
6714 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6715 no_advertise = 1;
6716 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6717 no_export = 1;
6718 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6719 local_as = 1;
6720 }
6721 }
6722 }
6723
6724 vty_out (vty, "Paths: (%d available", count);
6725 if (best)
6726 {
6727 vty_out (vty, ", best #%d", best);
6728 if (safi == SAFI_UNICAST)
6729 vty_out (vty, ", table Default-IP-Routing-Table");
6730 }
6731 else
6732 vty_out (vty, ", no best path");
6733 if (no_advertise)
6734 vty_out (vty, ", not advertised to any peer");
6735 else if (no_export)
6736 vty_out (vty, ", not advertised to EBGP peer");
6737 else if (local_as)
6738 vty_out (vty, ", not advertised outside local AS");
6739 if (suppress)
6740 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6741 vty_out (vty, ")%s", VTY_NEWLINE);
6742
6743 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006744 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006745 {
6746 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6747 {
6748 if (! first)
6749 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6750 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6751 first = 1;
6752 }
6753 }
6754 if (! first)
6755 vty_out (vty, " Not advertised to any peer");
6756 vty_out (vty, "%s", VTY_NEWLINE);
6757}
6758
6759/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006760static int
paulfee0f4c2004-09-13 05:12:46 +00006761bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006762 struct bgp_table *rib, const char *ip_str,
6763 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006764 int prefix_check, enum bgp_path_type pathtype)
paul718e3742002-12-13 20:15:29 +00006765{
6766 int ret;
6767 int header;
6768 int display = 0;
6769 struct prefix match;
6770 struct bgp_node *rn;
6771 struct bgp_node *rm;
6772 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006773 struct bgp_table *table;
6774
Lou Berger050defe2016-01-12 13:41:59 -05006775 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006776 /* Check IP address argument. */
6777 ret = str2prefix (ip_str, &match);
6778 if (! ret)
6779 {
6780 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6781 return CMD_WARNING;
6782 }
6783
6784 match.family = afi2family (afi);
6785
Lou Berger298cc2f2016-01-12 13:42:02 -05006786 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006787 {
paulfee0f4c2004-09-13 05:12:46 +00006788 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006789 {
6790 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6791 continue;
6792
6793 if ((table = rn->info) != NULL)
6794 {
6795 header = 1;
6796
6797 if ((rm = bgp_node_match (table, &match)) != NULL)
6798 {
6799 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006800 {
6801 bgp_unlock_node (rm);
6802 continue;
6803 }
paul718e3742002-12-13 20:15:29 +00006804
6805 for (ri = rm->info; ri; ri = ri->next)
6806 {
6807 if (header)
6808 {
6809 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006810 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006811
6812 header = 0;
6813 }
6814 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006815
6816 if (pathtype == BGP_PATH_ALL ||
6817 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6818 (pathtype == BGP_PATH_MULTIPATH &&
6819 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6820 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006821 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006822
6823 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006824 }
6825 }
6826 }
6827 }
6828 else
6829 {
6830 header = 1;
6831
paulfee0f4c2004-09-13 05:12:46 +00006832 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006833 {
6834 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6835 {
6836 for (ri = rn->info; ri; ri = ri->next)
6837 {
6838 if (header)
6839 {
6840 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6841 header = 0;
6842 }
6843 display++;
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006844
6845 if (pathtype == BGP_PATH_ALL ||
6846 (pathtype == BGP_PATH_BESTPATH && CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)) ||
6847 (pathtype == BGP_PATH_MULTIPATH &&
6848 (CHECK_FLAG (ri->flags, BGP_INFO_MULTIPATH) || CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))))
6849 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00006850 }
6851 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006852
6853 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006854 }
6855 }
6856
6857 if (! display)
6858 {
6859 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6860 return CMD_WARNING;
6861 }
6862
6863 return CMD_SUCCESS;
6864}
6865
paulfee0f4c2004-09-13 05:12:46 +00006866/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006867static int
paulfd79ac92004-10-13 05:06:08 +00006868bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006869 afi_t afi, safi_t safi, struct prefix_rd *prd,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006870 int prefix_check, enum bgp_path_type pathtype)
paulfee0f4c2004-09-13 05:12:46 +00006871{
6872 struct bgp *bgp;
6873
6874 /* BGP structure lookup. */
6875 if (view_name)
6876 {
6877 bgp = bgp_lookup_by_name (view_name);
6878 if (bgp == NULL)
6879 {
6880 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6881 return CMD_WARNING;
6882 }
6883 }
6884 else
6885 {
6886 bgp = bgp_get_default ();
6887 if (bgp == NULL)
6888 {
6889 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6890 return CMD_WARNING;
6891 }
6892 }
6893
6894 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006895 afi, safi, prd, prefix_check, pathtype);
paulfee0f4c2004-09-13 05:12:46 +00006896}
6897
paul718e3742002-12-13 20:15:29 +00006898/* BGP route print out function. */
Lou Bergerf9b6c392016-01-12 13:42:09 -05006899DEFUN (show_ip_bgp,
6900 show_ip_bgp_cmd,
6901 "show ip bgp",
6902 SHOW_STR
6903 IP_STR
6904 BGP_STR)
6905{
6906 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6907}
6908
6909DEFUN (show_ip_bgp_ipv4,
6910 show_ip_bgp_ipv4_cmd,
6911 "show ip bgp ipv4 (unicast|multicast)",
6912 SHOW_STR
6913 IP_STR
6914 BGP_STR
6915 "Address family\n"
6916 "Address Family modifier\n"
6917 "Address Family modifier\n")
6918{
6919 if (strncmp (argv[0], "m", 1) == 0)
6920 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6921 NULL);
6922
6923 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
6924}
6925
6926DEFUN (show_ip_bgp_route,
6927 show_ip_bgp_route_cmd,
6928 "show ip bgp A.B.C.D",
6929 SHOW_STR
6930 IP_STR
6931 BGP_STR
6932 "Network in the BGP routing table to display\n")
6933{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006934 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
6935}
6936
6937DEFUN (show_ip_bgp_route_pathtype,
6938 show_ip_bgp_route_pathtype_cmd,
6939 "show ip bgp A.B.C.D (bestpath|multipath)",
6940 SHOW_STR
6941 IP_STR
6942 BGP_STR
6943 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6944 "Display only the bestpath\n"
6945 "Display only multipaths\n")
6946{
6947 if (strncmp (argv[1], "b", 1) == 0)
6948 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6949 else
6950 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
6951}
6952
6953DEFUN (show_bgp_ipv4_safi_route_pathtype,
6954 show_bgp_ipv4_safi_route_pathtype_cmd,
6955 "show bgp ipv4 (unicast|multicast) A.B.C.D (bestpath|multipath)",
6956 SHOW_STR
6957 BGP_STR
6958 "Address family\n"
6959 "Address Family modifier\n"
6960 "Address Family modifier\n"
6961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
6962 "Display only the bestpath\n"
6963 "Display only multipaths\n")
6964{
6965 if (strncmp (argv[0], "m", 1) == 0)
6966 if (strncmp (argv[2], "b", 1) == 0)
6967 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
6968 else
6969 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
6970 else
6971 if (strncmp (argv[2], "b", 1) == 0)
6972 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
6973 else
6974 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006975}
6976
6977DEFUN (show_ip_bgp_ipv4_route,
6978 show_ip_bgp_ipv4_route_cmd,
6979 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6980 SHOW_STR
6981 IP_STR
6982 BGP_STR
6983 "Address family\n"
6984 "Address Family modifier\n"
6985 "Address Family modifier\n"
6986 "Network in the BGP routing table to display\n")
6987{
6988 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006989 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006990
Daniel Walton59fe0ee2015-05-19 17:58:11 -07006991 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05006992}
6993
6994DEFUN (show_ip_bgp_vpnv4_all_route,
6995 show_ip_bgp_vpnv4_all_route_cmd,
6996 "show ip bgp vpnv4 all A.B.C.D",
6997 SHOW_STR
6998 IP_STR
6999 BGP_STR
7000 "Display VPNv4 NLRI specific information\n"
7001 "Display information about all VPNv4 NLRIs\n"
7002 "Network in the BGP routing table to display\n")
7003{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007004 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 -05007005}
7006
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007007
Lou Bergerf9b6c392016-01-12 13:42:09 -05007008DEFUN (show_ip_bgp_vpnv4_rd_route,
7009 show_ip_bgp_vpnv4_rd_route_cmd,
7010 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7011 SHOW_STR
7012 IP_STR
7013 BGP_STR
7014 "Display VPNv4 NLRI specific information\n"
7015 "Display information for a route distinguisher\n"
7016 "VPN Route Distinguisher\n"
7017 "Network in the BGP routing table to display\n")
7018{
7019 int ret;
7020 struct prefix_rd prd;
7021
7022 ret = str2prefix_rd (argv[0], &prd);
7023 if (! ret)
7024 {
7025 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7026 return CMD_WARNING;
7027 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007028 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 -05007029}
7030
7031DEFUN (show_ip_bgp_prefix,
7032 show_ip_bgp_prefix_cmd,
7033 "show ip bgp A.B.C.D/M",
7034 SHOW_STR
7035 IP_STR
7036 BGP_STR
7037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7038{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007039 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
7040}
7041
7042DEFUN (show_ip_bgp_prefix_pathtype,
7043 show_ip_bgp_prefix_pathtype_cmd,
7044 "show ip bgp A.B.C.D/M (bestpath|multipath)",
7045 SHOW_STR
7046 IP_STR
7047 BGP_STR
7048 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7049 "Display only the bestpath\n"
7050 "Display only multipaths\n")
7051{
7052 if (strncmp (argv[1], "b", 1) == 0)
7053 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7054 else
7055 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007056}
7057
7058DEFUN (show_ip_bgp_ipv4_prefix,
7059 show_ip_bgp_ipv4_prefix_cmd,
7060 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7061 SHOW_STR
7062 IP_STR
7063 BGP_STR
7064 "Address family\n"
7065 "Address Family modifier\n"
7066 "Address Family modifier\n"
7067 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7068{
7069 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007070 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007071
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007072 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007073}
7074
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007075DEFUN (show_ip_bgp_ipv4_prefix_pathtype,
7076 show_ip_bgp_ipv4_prefix_pathtype_cmd,
7077 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7078 SHOW_STR
7079 IP_STR
7080 BGP_STR
7081 "Address family\n"
7082 "Address Family modifier\n"
7083 "Address Family modifier\n"
7084 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7085 "Display only the bestpath\n"
7086 "Display only multipaths\n")
7087{
7088 if (strncmp (argv[0], "m", 1) == 0)
7089 if (strncmp (argv[2], "b", 1) == 0)
7090 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7091 else
7092 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7093 else
7094 if (strncmp (argv[2], "b", 1) == 0)
7095 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7096 else
7097 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7098}
7099
7100ALIAS (show_ip_bgp_ipv4_prefix_pathtype,
7101 show_bgp_ipv4_safi_prefix_pathtype_cmd,
7102 "show bgp ipv4 (unicast|multicast) A.B.C.D/M (bestpath|multipath)",
7103 SHOW_STR
7104 BGP_STR
7105 "Address family\n"
7106 "Address Family modifier\n"
7107 "Address Family modifier\n"
7108 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
7109 "Display only the bestpath\n"
7110 "Display only multipaths\n")
7111
Lou Bergerf9b6c392016-01-12 13:42:09 -05007112DEFUN (show_ip_bgp_vpnv4_all_prefix,
7113 show_ip_bgp_vpnv4_all_prefix_cmd,
7114 "show ip bgp vpnv4 all A.B.C.D/M",
7115 SHOW_STR
7116 IP_STR
7117 BGP_STR
7118 "Display VPNv4 NLRI specific information\n"
7119 "Display information about all VPNv4 NLRIs\n"
7120 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7121{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007122 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 -05007123}
7124
7125DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7126 show_ip_bgp_vpnv4_rd_prefix_cmd,
7127 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7128 SHOW_STR
7129 IP_STR
7130 BGP_STR
7131 "Display VPNv4 NLRI specific information\n"
7132 "Display information for a route distinguisher\n"
7133 "VPN Route Distinguisher\n"
7134 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7135{
7136 int ret;
7137 struct prefix_rd prd;
7138
7139 ret = str2prefix_rd (argv[0], &prd);
7140 if (! ret)
7141 {
7142 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7143 return CMD_WARNING;
7144 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007145 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 -05007146}
7147
7148DEFUN (show_ip_bgp_view,
7149 show_ip_bgp_view_cmd,
7150 "show ip bgp view WORD",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "BGP view\n"
7155 "View name\n")
7156{
7157 struct bgp *bgp;
7158
7159 /* BGP structure lookup. */
7160 bgp = bgp_lookup_by_name (argv[0]);
7161 if (bgp == NULL)
7162 {
7163 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7164 return CMD_WARNING;
7165 }
7166
7167 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
7168}
7169
7170DEFUN (show_ip_bgp_view_route,
7171 show_ip_bgp_view_route_cmd,
7172 "show ip bgp view WORD A.B.C.D",
7173 SHOW_STR
7174 IP_STR
7175 BGP_STR
7176 "BGP view\n"
7177 "View name\n"
7178 "Network in the BGP routing table to display\n")
7179{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007180 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 -05007181}
7182
7183DEFUN (show_ip_bgp_view_prefix,
7184 show_ip_bgp_view_prefix_cmd,
7185 "show ip bgp view WORD A.B.C.D/M",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "BGP view\n"
7190 "View name\n"
7191 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7192{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007193 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 -05007194}
7195
7196DEFUN (show_bgp,
7197 show_bgp_cmd,
7198 "show bgp",
7199 SHOW_STR
7200 BGP_STR)
7201{
7202 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7203 NULL);
7204}
7205
7206ALIAS (show_bgp,
7207 show_bgp_ipv6_cmd,
7208 "show bgp ipv6",
7209 SHOW_STR
7210 BGP_STR
7211 "Address family\n")
7212
7213/* old command */
7214DEFUN (show_ipv6_bgp,
7215 show_ipv6_bgp_cmd,
7216 "show ipv6 bgp",
7217 SHOW_STR
7218 IP_STR
7219 BGP_STR)
7220{
7221 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7222 NULL);
7223}
7224
7225DEFUN (show_bgp_route,
7226 show_bgp_route_cmd,
7227 "show bgp X:X::X:X",
7228 SHOW_STR
7229 BGP_STR
7230 "Network in the BGP routing table to display\n")
7231{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007232 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007233}
7234
Lou Berger35c36862016-01-12 13:42:06 -05007235DEFUN (show_bgp_ipv4_safi,
7236 show_bgp_ipv4_safi_cmd,
7237 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00007238 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007239 BGP_STR
7240 "Address family\n"
7241 "Address Family modifier\n"
7242 "Address Family modifier\n")
7243{
7244 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00007245 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
7246 NULL);
paul718e3742002-12-13 20:15:29 +00007247
ajs5a646652004-11-05 01:25:55 +00007248 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007249}
7250
Lou Berger35c36862016-01-12 13:42:06 -05007251DEFUN (show_bgp_ipv4_safi_route,
7252 show_bgp_ipv4_safi_route_cmd,
7253 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007254 SHOW_STR
7255 BGP_STR
7256 "Address family\n"
7257 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00007258 "Address Family modifier\n"
7259 "Network in the BGP routing table to display\n")
7260{
7261 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007262 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007263
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007264 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
7265}
7266
7267DEFUN (show_bgp_route_pathtype,
7268 show_bgp_route_pathtype_cmd,
7269 "show bgp X:X::X:X (bestpath|multipath)",
7270 SHOW_STR
7271 BGP_STR
7272 "Network in the BGP routing table to display\n"
7273 "Display only the bestpath\n"
7274 "Display only multipaths\n")
7275{
7276 if (strncmp (argv[1], "b", 1) == 0)
7277 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7278 else
7279 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
7280}
7281
7282ALIAS (show_bgp_route_pathtype,
7283 show_bgp_ipv6_route_pathtype_cmd,
7284 "show bgp ipv6 X:X::X:X (bestpath|multipath)",
7285 SHOW_STR
7286 BGP_STR
7287 "Address family\n"
7288 "Network in the BGP routing table to display\n"
7289 "Display only the bestpath\n"
7290 "Display only multipaths\n")
7291
7292DEFUN (show_bgp_ipv6_safi_route_pathtype,
7293 show_bgp_ipv6_safi_route_pathtype_cmd,
7294 "show bgp ipv6 (unicast|multicast) X:X::X:X (bestpath|multipath)",
7295 SHOW_STR
7296 BGP_STR
7297 "Address family\n"
7298 "Address Family modifier\n"
7299 "Address Family modifier\n"
7300 "Network in the BGP routing table to display\n"
7301 "Display only the bestpath\n"
7302 "Display only multipaths\n")
7303{
7304 if (strncmp (argv[0], "m", 1) == 0)
7305 if (strncmp (argv[2], "b", 1) == 0)
7306 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_BESTPATH);
7307 else
7308 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_MULTIPATH);
7309 else
7310 if (strncmp (argv[2], "b", 1) == 0)
7311 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_BESTPATH);
7312 else
7313 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007314}
7315
Lou Berger35c36862016-01-12 13:42:06 -05007316DEFUN (show_bgp_ipv4_vpn_route,
7317 show_bgp_ipv4_vpn_route_cmd,
7318 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007319 SHOW_STR
7320 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007321 "Address Family\n"
7322 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007323 "Network in the BGP routing table to display\n")
7324{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007325 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007326}
7327
Lou Berger35c36862016-01-12 13:42:06 -05007328DEFUN (show_bgp_ipv6_vpn_route,
7329 show_bgp_ipv6_vpn_route_cmd,
7330 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007331 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007332 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007333 "Address Family\n"
7334 "Display VPN NLRI specific information\n"
7335 "Network in the BGP routing table to display\n")
7336{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007337 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 -05007338}
Lou Berger35c36862016-01-12 13:42:06 -05007339
7340DEFUN (show_bgp_ipv4_vpn_rd_route,
7341 show_bgp_ipv4_vpn_rd_route_cmd,
7342 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7343 SHOW_STR
7344 BGP_STR
7345 IP_STR
7346 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007347 "Display information for a route distinguisher\n"
7348 "VPN Route Distinguisher\n"
7349 "Network in the BGP routing table to display\n")
7350{
7351 int ret;
7352 struct prefix_rd prd;
7353
7354 ret = str2prefix_rd (argv[0], &prd);
7355 if (! ret)
7356 {
7357 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7358 return CMD_WARNING;
7359 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007360 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007361}
7362
Lou Berger35c36862016-01-12 13:42:06 -05007363DEFUN (show_bgp_ipv6_vpn_rd_route,
7364 show_bgp_ipv6_vpn_rd_route_cmd,
7365 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007366 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007367 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007368 "Address Family\n"
7369 "Display VPN NLRI specific information\n"
7370 "Display information for a route distinguisher\n"
7371 "VPN Route Distinguisher\n"
7372 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007373{
Lou Berger35c36862016-01-12 13:42:06 -05007374 int ret;
7375 struct prefix_rd prd;
7376
7377 ret = str2prefix_rd (argv[0], &prd);
7378 if (! ret)
7379 {
7380 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7381 return CMD_WARNING;
7382 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007383 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0, BGP_PATH_ALL);
7384}
7385
7386DEFUN (show_bgp_prefix_pathtype,
7387 show_bgp_prefix_pathtype_cmd,
7388 "show bgp X:X::X:X/M (bestpath|multipath)",
7389 SHOW_STR
7390 BGP_STR
7391 "IPv6 prefix <network>/<length>\n"
7392 "Display only the bestpath\n"
7393 "Display only multipaths\n")
7394{
7395 if (strncmp (argv[1], "b", 1) == 0)
7396 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7397 else
7398 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
7399}
7400
7401ALIAS (show_bgp_prefix_pathtype,
7402 show_bgp_ipv6_prefix_pathtype_cmd,
7403 "show bgp ipv6 X:X::X:X/M (bestpath|multipath)",
7404 SHOW_STR
7405 BGP_STR
7406 "Address family\n"
7407 "IPv6 prefix <network>/<length>\n"
7408 "Display only the bestpath\n"
7409 "Display only multipaths\n")
7410
7411DEFUN (show_bgp_ipv6_safi_prefix_pathtype,
7412 show_bgp_ipv6_safi_prefix_pathtype_cmd,
7413 "show bgp ipv6 (unicast|multicast) X:X::X:X/M (bestpath|multipath)",
7414 SHOW_STR
7415 BGP_STR
7416 "Address family\n"
7417 "Address Family modifier\n"
7418 "Address Family modifier\n"
7419 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
7420 "Display only the bestpath\n"
7421 "Display only multipaths\n")
7422{
7423 if (strncmp (argv[0], "m", 1) == 0)
7424 if (strncmp (argv[2], "b", 1) == 0)
7425 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_BESTPATH);
7426 else
7427 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_MULTIPATH);
7428 else
7429 if (strncmp (argv[2], "b", 1) == 0)
7430 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_BESTPATH);
7431 else
7432 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_MULTIPATH);
paul718e3742002-12-13 20:15:29 +00007433}
7434
Lou Berger651b4022016-01-12 13:42:07 -05007435DEFUN (show_bgp_ipv4_encap_route,
7436 show_bgp_ipv4_encap_route_cmd,
7437 "show bgp ipv4 encap A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007438 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007439 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007440 IP_STR
7441 "Display ENCAP NLRI specific information\n"
7442 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007443{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007444 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007445}
7446
Lou Berger651b4022016-01-12 13:42:07 -05007447DEFUN (show_bgp_ipv6_encap_route,
7448 show_bgp_ipv6_encap_route_cmd,
7449 "show bgp ipv6 encap X:X::X:X",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007450 SHOW_STR
7451 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007452 IP6_STR
7453 "Display ENCAP NLRI specific information\n"
7454 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007455{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007456 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007457}
7458
Lou Berger651b4022016-01-12 13:42:07 -05007459DEFUN (show_bgp_ipv4_safi_rd_route,
7460 show_bgp_ipv4_safi_rd_route_cmd,
7461 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D",
paul718e3742002-12-13 20:15:29 +00007462 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007463 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007464 "Address Family\n"
7465 "Address Family Modifier\n"
7466 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00007467 "Display information for a route distinguisher\n"
Lou Berger651b4022016-01-12 13:42:07 -05007468 "ENCAP Route Distinguisher\n"
7469 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007470{
7471 int ret;
7472 struct prefix_rd prd;
Lou Berger651b4022016-01-12 13:42:07 -05007473 safi_t safi;
paul718e3742002-12-13 20:15:29 +00007474
Lou Berger651b4022016-01-12 13:42:07 -05007475 if (bgp_parse_safi(argv[0], &safi)) {
7476 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7477 return CMD_WARNING;
7478 }
7479 ret = str2prefix_rd (argv[1], &prd);
paul718e3742002-12-13 20:15:29 +00007480 if (! ret)
7481 {
7482 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7483 return CMD_WARNING;
7484 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007485 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007486}
7487
Lou Berger651b4022016-01-12 13:42:07 -05007488DEFUN (show_bgp_ipv6_safi_rd_route,
7489 show_bgp_ipv6_safi_rd_route_cmd,
7490 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007491 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007492 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007493 "Address Family\n"
7494 "Address Family Modifier\n"
7495 "Address Family Modifier\n"
7496 "Display information for a route distinguisher\n"
7497 "ENCAP Route Distinguisher\n"
7498 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007499{
Lou Berger651b4022016-01-12 13:42:07 -05007500 int ret;
7501 struct prefix_rd prd;
7502 safi_t safi;
paulbb46e942003-10-24 19:02:03 +00007503
Lou Berger651b4022016-01-12 13:42:07 -05007504 if (bgp_parse_safi(argv[0], &safi)) {
7505 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7506 return CMD_WARNING;
7507 }
7508 ret = str2prefix_rd (argv[1], &prd);
7509 if (! ret)
7510 {
7511 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7512 return CMD_WARNING;
7513 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007514 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, SAFI_ENCAP, &prd, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007515}
7516
Lou Berger35c36862016-01-12 13:42:06 -05007517DEFUN (show_bgp_ipv4_prefix,
7518 show_bgp_ipv4_prefix_cmd,
7519 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007520 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007521 BGP_STR
paul718e3742002-12-13 20:15:29 +00007522 IP_STR
paul718e3742002-12-13 20:15:29 +00007523 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7524{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007525 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007526}
7527
Lou Berger35c36862016-01-12 13:42:06 -05007528DEFUN (show_bgp_ipv4_safi_prefix,
7529 show_bgp_ipv4_safi_prefix_cmd,
7530 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007531 SHOW_STR
7532 BGP_STR
7533 "Address family\n"
7534 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007535 "Address Family modifier\n"
7536 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007537{
7538 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007539 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007540
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007541 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007542}
7543
Lou Berger35c36862016-01-12 13:42:06 -05007544DEFUN (show_bgp_ipv4_vpn_prefix,
7545 show_bgp_ipv4_vpn_prefix_cmd,
7546 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007547 SHOW_STR
7548 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007549 IP_STR
7550 "Display VPN NLRI specific information\n"
7551 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007552{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007553 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007554}
7555
Lou Berger35c36862016-01-12 13:42:06 -05007556DEFUN (show_bgp_ipv6_vpn_prefix,
7557 show_bgp_ipv6_vpn_prefix_cmd,
7558 "show bgp ipv6 vpn X:X::X:X/M",
7559 SHOW_STR
7560 BGP_STR
7561 "Address Family\n"
7562 "Display VPN NLRI specific information\n"
7563 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7564{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007565 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 -05007566}
Lou Berger35c36862016-01-12 13:42:06 -05007567
Lou Berger651b4022016-01-12 13:42:07 -05007568DEFUN (show_bgp_ipv4_encap_prefix,
7569 show_bgp_ipv4_encap_prefix_cmd,
7570 "show bgp ipv4 encap A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007571 SHOW_STR
7572 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007573 IP_STR
7574 "Display ENCAP NLRI specific information\n"
7575 "Display information about ENCAP NLRIs\n"
7576 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7577{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007578 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007579}
paul718e3742002-12-13 20:15:29 +00007580
Lou Berger651b4022016-01-12 13:42:07 -05007581DEFUN (show_bgp_ipv6_encap_prefix,
7582 show_bgp_ipv6_encap_prefix_cmd,
7583 "show bgp ipv6 encap X:X::X:X/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007584 SHOW_STR
7585 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05007586 IP_STR
7587 "Display ENCAP NLRI specific information\n"
7588 "Display information about ENCAP NLRIs\n"
7589 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7590{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007591 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_ENCAP, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007592}
Lou Berger651b4022016-01-12 13:42:07 -05007593
7594DEFUN (show_bgp_ipv4_safi_rd_prefix,
7595 show_bgp_ipv4_safi_rd_prefix_cmd,
7596 "show bgp ipv4 (encap|vpn) rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7597 SHOW_STR
7598 BGP_STR
7599 "Address Family\n"
7600 "Address Family Modifier\n"
7601 "Address Family Modifier\n"
7602 "Display information for a route distinguisher\n"
7603 "ENCAP Route Distinguisher\n"
7604 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7605{
7606 int ret;
7607 struct prefix_rd prd;
7608 safi_t safi;
7609
7610 if (bgp_parse_safi(argv[0], &safi)) {
7611 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7612 return CMD_WARNING;
7613 }
7614
7615 ret = str2prefix_rd (argv[1], &prd);
7616 if (! ret)
7617 {
7618 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7619 return CMD_WARNING;
7620 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007621 return bgp_show_route (vty, NULL, argv[2], AFI_IP, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007622}
7623
Lou Berger651b4022016-01-12 13:42:07 -05007624DEFUN (show_bgp_ipv6_safi_rd_prefix,
7625 show_bgp_ipv6_safi_rd_prefix_cmd,
7626 "show bgp ipv6 (encap|vpn) rd ASN:nn_or_IP-address:nn X:X::X:X/M",
7627 SHOW_STR
7628 BGP_STR
7629 "Address Family\n"
7630 "Address Family Modifier\n"
7631 "Address Family Modifier\n"
7632 "Display information for a route distinguisher\n"
7633 "ENCAP Route Distinguisher\n"
7634 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7635{
7636 int ret;
7637 struct prefix_rd prd;
7638 safi_t safi;
7639
7640 if (bgp_parse_safi(argv[0], &safi)) {
7641 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
7642 return CMD_WARNING;
7643 }
7644
7645 ret = str2prefix_rd (argv[1], &prd);
7646 if (! ret)
7647 {
7648 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7649 return CMD_WARNING;
7650 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007651 return bgp_show_route (vty, NULL, argv[2], AFI_IP6, safi, &prd, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007652}
Lou Berger651b4022016-01-12 13:42:07 -05007653
7654DEFUN (show_bgp_afi_safi_view,
7655 show_bgp_afi_safi_view_cmd,
7656 "show bgp view WORD (ipv4|ipv6) (encap|mulicast|unicast|vpn)",
7657 SHOW_STR
7658 BGP_STR
7659 "BGP view\n"
7660 "BGP view name\n"
7661 "Address Family\n"
7662 "Address Family\n"
7663 "Address Family Modifier\n"
7664 "Address Family Modifier\n"
7665 "Address Family Modifier\n"
7666 "Address Family Modifier\n"
7667 )
7668{
7669 struct bgp *bgp;
7670 safi_t safi;
7671 afi_t afi;
7672
7673 if (bgp_parse_afi(argv[1], &afi)) {
7674 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7675 return CMD_WARNING;
7676 }
7677 if (bgp_parse_safi(argv[2], &safi)) {
7678 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7679 return CMD_WARNING;
7680 }
7681
7682 /* BGP structure lookup. */
7683 bgp = bgp_lookup_by_name (argv[0]);
7684 if (bgp == NULL)
7685 {
7686 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7687 return CMD_WARNING;
7688 }
7689
7690 return bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL);
7691}
7692
7693DEFUN (show_bgp_view_afi_safi_route,
7694 show_bgp_view_afi_safi_route_cmd,
7695 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D",
7696 SHOW_STR
7697 BGP_STR
7698 "BGP view\n"
7699 "View name\n"
7700 "Address Family\n"
7701 "Address Family\n"
7702 "Address Family Modifier\n"
7703 "Address Family Modifier\n"
7704 "Address Family Modifier\n"
7705 "Address Family Modifier\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007706 "Network in the BGP routing table to display\n")
7707{
Lou Berger651b4022016-01-12 13:42:07 -05007708 safi_t safi;
7709 afi_t afi;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007710
Lou Berger651b4022016-01-12 13:42:07 -05007711 if (bgp_parse_afi(argv[1], &afi)) {
7712 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7713 return CMD_WARNING;
7714 }
7715 if (bgp_parse_safi(argv[2], &safi)) {
7716 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7717 return CMD_WARNING;
7718 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007719 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 0, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007720}
7721
7722DEFUN (show_bgp_view_afi_safi_prefix,
7723 show_bgp_view_afi_safi_prefix_cmd,
7724 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) A.B.C.D/M",
7725 SHOW_STR
7726 BGP_STR
7727 "BGP view\n"
7728 "View name\n"
7729 "Address Family\n"
7730 "Address Family\n"
7731 "Address Family Modifier\n"
7732 "Address Family Modifier\n"
7733 "Address Family Modifier\n"
7734 "Address Family Modifier\n"
7735 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7736{
7737 safi_t safi;
7738 afi_t afi;
7739
7740 if (bgp_parse_afi(argv[1], &afi)) {
7741 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7742 return CMD_WARNING;
7743 }
7744 if (bgp_parse_safi(argv[2], &safi)) {
7745 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
7746 return CMD_WARNING;
7747 }
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007748 return bgp_show_route (vty, argv[0], argv[3], afi, safi, NULL, 1, BGP_PATH_ALL);
Lou Berger651b4022016-01-12 13:42:07 -05007749}
7750
7751/* new001 */
7752DEFUN (show_bgp_afi,
7753 show_bgp_afi_cmd,
7754 "show bgp (ipv4|ipv6)",
7755 SHOW_STR
7756 BGP_STR
7757 "Address family\n"
7758 "Address family\n")
7759{
7760 afi_t afi;
7761
7762 if (bgp_parse_afi(argv[0], &afi)) {
7763 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
7764 return CMD_WARNING;
7765 }
7766 return bgp_show (vty, NULL, afi, SAFI_UNICAST, bgp_show_type_normal,
7767 NULL);
7768}
7769
Lou Berger651b4022016-01-12 13:42:07 -05007770DEFUN (show_bgp_ipv6_safi,
7771 show_bgp_ipv6_safi_cmd,
7772 "show bgp ipv6 (unicast|multicast)",
7773 SHOW_STR
7774 BGP_STR
7775 "Address family\n"
7776 "Address Family modifier\n"
7777 "Address Family modifier\n")
7778{
7779 if (strncmp (argv[0], "m", 1) == 0)
7780 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7781 NULL);
7782
7783 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007784}
7785
Lou Berger35c36862016-01-12 13:42:06 -05007786DEFUN (show_bgp_ipv6_route,
7787 show_bgp_ipv6_route_cmd,
7788 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007789 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007790 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007791 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007792 "Network in the BGP routing table to display\n")
7793{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007794 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007795}
7796
Lou Berger35c36862016-01-12 13:42:06 -05007797DEFUN (show_bgp_ipv6_safi_route,
7798 show_bgp_ipv6_safi_route_cmd,
7799 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007800 SHOW_STR
7801 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007802 "Address family\n"
7803 "Address Family modifier\n"
7804 "Address Family modifier\n"
7805 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007806{
Lou Berger35c36862016-01-12 13:42:06 -05007807 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007808 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007809
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007810 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00007811}
7812
Lou Bergerf9b6c392016-01-12 13:42:09 -05007813/* old command */
7814DEFUN (show_ipv6_bgp_route,
7815 show_ipv6_bgp_route_cmd,
7816 "show ipv6 bgp X:X::X:X",
7817 SHOW_STR
7818 IP_STR
7819 BGP_STR
7820 "Network in the BGP routing table to display\n")
7821{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007822 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007823}
7824
7825DEFUN (show_bgp_prefix,
7826 show_bgp_prefix_cmd,
7827 "show bgp X:X::X:X/M",
7828 SHOW_STR
7829 BGP_STR
7830 "IPv6 prefix <network>/<length>\n")
7831{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007832 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007833}
7834
7835
Lou Berger35c36862016-01-12 13:42:06 -05007836/* new002 */
7837DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007838 show_bgp_ipv6_prefix_cmd,
7839 "show bgp ipv6 X:X::X:X/M",
7840 SHOW_STR
7841 BGP_STR
7842 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007843 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7844{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007845 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Berger35c36862016-01-12 13:42:06 -05007846}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007847DEFUN (show_bgp_ipv6_safi_prefix,
7848 show_bgp_ipv6_safi_prefix_cmd,
7849 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7850 SHOW_STR
7851 BGP_STR
7852 "Address family\n"
7853 "Address Family modifier\n"
7854 "Address Family modifier\n"
7855 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7856{
7857 if (strncmp (argv[0], "m", 1) == 0)
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007858 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007859
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007860 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007861}
7862
Lou Bergerf9b6c392016-01-12 13:42:09 -05007863/* old command */
7864DEFUN (show_ipv6_bgp_prefix,
7865 show_ipv6_bgp_prefix_cmd,
7866 "show ipv6 bgp X:X::X:X/M",
7867 SHOW_STR
7868 IP_STR
7869 BGP_STR
7870 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7871{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007872 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007873}
7874
paulbb46e942003-10-24 19:02:03 +00007875DEFUN (show_bgp_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007876 show_bgp_view_cmd,
7877 "show bgp view WORD",
7878 SHOW_STR
7879 BGP_STR
7880 "BGP view\n"
7881 "View name\n")
7882{
7883 struct bgp *bgp;
7884
7885 /* BGP structure lookup. */
7886 bgp = bgp_lookup_by_name (argv[0]);
7887 if (bgp == NULL)
7888 {
7889 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7890 return CMD_WARNING;
7891 }
7892
7893 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7894}
7895
7896DEFUN (show_bgp_view_ipv6,
Lou Berger35c36862016-01-12 13:42:06 -05007897 show_bgp_view_ipv6_cmd,
7898 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007899 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007900 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007901 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007902 "View name\n"
7903 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007904{
7905 struct bgp *bgp;
7906
7907 /* BGP structure lookup. */
7908 bgp = bgp_lookup_by_name (argv[0]);
7909 if (bgp == NULL)
7910 {
7911 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7912 return CMD_WARNING;
7913 }
7914
ajs5a646652004-11-05 01:25:55 +00007915 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007916}
paulbb46e942003-10-24 19:02:03 +00007917
7918DEFUN (show_bgp_view_route,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007919 show_bgp_view_route_cmd,
7920 "show bgp view WORD X:X::X:X",
7921 SHOW_STR
7922 BGP_STR
7923 "BGP view\n"
7924 "View name\n"
7925 "Network in the BGP routing table to display\n")
7926{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007927 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 -05007928}
7929
7930DEFUN (show_bgp_view_ipv6_route,
paulbb46e942003-10-24 19:02:03 +00007931 show_bgp_view_ipv6_route_cmd,
7932 "show bgp view WORD ipv6 X:X::X:X",
7933 SHOW_STR
7934 BGP_STR
7935 "BGP view\n"
7936 "View name\n"
7937 "Address family\n"
7938 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007939{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007940 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulbb46e942003-10-24 19:02:03 +00007941}
7942
Lou Bergerf9b6c392016-01-12 13:42:09 -05007943/* old command */
7944DEFUN (show_ipv6_mbgp,
7945 show_ipv6_mbgp_cmd,
7946 "show ipv6 mbgp",
7947 SHOW_STR
7948 IP_STR
7949 MBGP_STR)
7950{
7951 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7952 NULL);
7953}
7954
7955/* old command */
7956DEFUN (show_ipv6_mbgp_route,
7957 show_ipv6_mbgp_route_cmd,
7958 "show ipv6 mbgp X:X::X:X",
7959 SHOW_STR
7960 IP_STR
7961 MBGP_STR
7962 "Network in the MBGP routing table to display\n")
7963{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007964 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007965}
7966
7967/* old command */
7968DEFUN (show_ipv6_mbgp_prefix,
7969 show_ipv6_mbgp_prefix_cmd,
7970 "show ipv6 mbgp X:X::X:X/M",
7971 SHOW_STR
7972 IP_STR
7973 MBGP_STR
7974 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7975{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007976 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -05007977}
7978
Lou Berger35c36862016-01-12 13:42:06 -05007979DEFUN (show_bgp_view_prefix,
Lou Bergerf9b6c392016-01-12 13:42:09 -05007980 show_bgp_view_prefix_cmd,
7981 "show bgp view WORD X:X::X:X/M",
7982 SHOW_STR
7983 BGP_STR
7984 "BGP view\n"
7985 "View name\n"
7986 "IPv6 prefix <network>/<length>\n")
7987{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07007988 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 -05007989}
7990
7991DEFUN (show_bgp_view_ipv6_prefix,
paulbb46e942003-10-24 19:02:03 +00007992 show_bgp_view_ipv6_prefix_cmd,
7993 "show bgp view WORD ipv6 X:X::X:X/M",
7994 SHOW_STR
7995 BGP_STR
7996 "BGP view\n"
7997 "View name\n"
7998 "Address family\n"
7999 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00008000{
Daniel Walton59fe0ee2015-05-19 17:58:11 -07008001 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paul718e3742002-12-13 20:15:29 +00008002}
8003
paul94f2b392005-06-28 12:44:16 +00008004static int
paulfd79ac92004-10-13 05:06:08 +00008005bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008006 safi_t safi, enum bgp_show_type type)
8007{
8008 int i;
8009 struct buffer *b;
8010 char *regstr;
8011 int first;
8012 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00008013 int rc;
paul718e3742002-12-13 20:15:29 +00008014
8015 first = 0;
8016 b = buffer_new (1024);
8017 for (i = 0; i < argc; i++)
8018 {
8019 if (first)
8020 buffer_putc (b, ' ');
8021 else
8022 {
8023 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8024 continue;
8025 first = 1;
8026 }
8027
8028 buffer_putstr (b, argv[i]);
8029 }
8030 buffer_putc (b, '\0');
8031
8032 regstr = buffer_getstr (b);
8033 buffer_free (b);
8034
8035 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00008036 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00008037 if (! regex)
8038 {
8039 vty_out (vty, "Can't compile regexp %s%s", argv[0],
8040 VTY_NEWLINE);
8041 return CMD_WARNING;
8042 }
8043
ajs5a646652004-11-05 01:25:55 +00008044 rc = bgp_show (vty, NULL, afi, safi, type, regex);
8045 bgp_regex_free (regex);
8046 return rc;
paul718e3742002-12-13 20:15:29 +00008047}
8048
Lou Bergerf9b6c392016-01-12 13:42:09 -05008049
8050DEFUN (show_ip_bgp_regexp,
8051 show_ip_bgp_regexp_cmd,
8052 "show ip bgp regexp .LINE",
8053 SHOW_STR
8054 IP_STR
8055 BGP_STR
8056 "Display routes matching the AS path regular expression\n"
8057 "A regular-expression to match the BGP AS paths\n")
8058{
8059 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8060 bgp_show_type_regexp);
8061}
8062
8063DEFUN (show_ip_bgp_flap_regexp,
8064 show_ip_bgp_flap_regexp_cmd,
8065 "show ip bgp flap-statistics regexp .LINE",
8066 SHOW_STR
8067 IP_STR
8068 BGP_STR
8069 "Display flap statistics of routes\n"
8070 "Display routes matching the AS path regular expression\n"
8071 "A regular-expression to match the BGP AS paths\n")
8072{
8073 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8074 bgp_show_type_flap_regexp);
8075}
8076
8077ALIAS (show_ip_bgp_flap_regexp,
8078 show_ip_bgp_damp_flap_regexp_cmd,
8079 "show ip bgp dampening flap-statistics regexp .LINE",
8080 SHOW_STR
8081 IP_STR
8082 BGP_STR
8083 "Display detailed information about dampening\n"
8084 "Display flap statistics of routes\n"
8085 "Display routes matching the AS path regular expression\n"
8086 "A regular-expression to match the BGP AS paths\n")
8087
8088DEFUN (show_ip_bgp_ipv4_regexp,
8089 show_ip_bgp_ipv4_regexp_cmd,
8090 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
8091 SHOW_STR
8092 IP_STR
8093 BGP_STR
8094 "Address family\n"
8095 "Address Family modifier\n"
8096 "Address Family modifier\n"
8097 "Display routes matching the AS path regular expression\n"
8098 "A regular-expression to match the BGP AS paths\n")
8099{
8100 if (strncmp (argv[0], "m", 1) == 0)
8101 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
8102 bgp_show_type_regexp);
8103
8104 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
8105 bgp_show_type_regexp);
8106}
8107
Lou Bergerf9b6c392016-01-12 13:42:09 -05008108DEFUN (show_bgp_regexp,
8109 show_bgp_regexp_cmd,
8110 "show bgp regexp .LINE",
8111 SHOW_STR
8112 BGP_STR
8113 "Display routes matching the AS path regular expression\n"
8114 "A regular-expression to match the BGP AS paths\n")
8115{
8116 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8117 bgp_show_type_regexp);
8118}
8119
8120/* old command */
8121DEFUN (show_ipv6_bgp_regexp,
8122 show_ipv6_bgp_regexp_cmd,
8123 "show ipv6 bgp regexp .LINE",
8124 SHOW_STR
8125 IP_STR
8126 BGP_STR
8127 "Display routes matching the AS path regular expression\n"
8128 "A regular-expression to match the BGP AS paths\n")
8129{
8130 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8131 bgp_show_type_regexp);
8132}
8133
8134/* old command */
8135DEFUN (show_ipv6_mbgp_regexp,
8136 show_ipv6_mbgp_regexp_cmd,
8137 "show ipv6 mbgp regexp .LINE",
8138 SHOW_STR
8139 IP_STR
8140 BGP_STR
8141 "Display routes matching the AS path regular expression\n"
8142 "A regular-expression to match the MBGP AS paths\n")
8143{
8144 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
8145 bgp_show_type_regexp);
8146}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008147
Lou Berger651b4022016-01-12 13:42:07 -05008148DEFUN (show_bgp_ipv4_safi_flap_regexp,
8149 show_bgp_ipv4_safi_flap_regexp_cmd,
8150 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008151 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008152 BGP_STR
paul718e3742002-12-13 20:15:29 +00008153 IP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008154 "Address Family Modifier\n"
8155 "Address Family Modifier\n"
8156 "Address Family Modifier\n"
8157 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008158 "Display flap statistics of routes\n"
8159 "Display routes matching the AS path regular expression\n"
8160 "A regular-expression to match the BGP AS paths\n")
8161{
Lou Berger651b4022016-01-12 13:42:07 -05008162 safi_t safi;
8163
8164 if (bgp_parse_safi(argv[0], &safi)) {
8165 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8166 return CMD_WARNING;
8167 }
8168 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
8169 bgp_show_type_flap_regexp);
paul718e3742002-12-13 20:15:29 +00008170}
8171
Lou Berger651b4022016-01-12 13:42:07 -05008172ALIAS (show_bgp_ipv4_safi_flap_regexp,
8173 show_bgp_ipv4_safi_damp_flap_regexp_cmd,
8174 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
Balaji3921cc52015-05-16 23:12:17 +05308175 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308176 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008177 IP_STR
8178 "Address Family Modifier\n"
8179 "Address Family Modifier\n"
8180 "Address Family Modifier\n"
8181 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308182 "Display detailed information about dampening\n"
8183 "Display flap statistics of routes\n"
8184 "Display routes matching the AS path regular expression\n"
8185 "A regular-expression to match the BGP AS paths\n")
8186
Lou Berger651b4022016-01-12 13:42:07 -05008187DEFUN (show_bgp_ipv6_safi_flap_regexp,
8188 show_bgp_ipv6_safi_flap_regexp_cmd,
8189 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008190 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008191 BGP_STR
8192 IPV6_STR
8193 "Address Family Modifier\n"
8194 "Address Family Modifier\n"
8195 "Address Family Modifier\n"
8196 "Address Family Modifier\n"
8197 "Display flap statistics of routes\n"
8198 "Display routes matching the AS path regular expression\n"
8199 "A regular-expression to match the BGP AS paths\n")
8200{
8201 safi_t safi;
8202
8203 if (bgp_parse_safi(argv[0], &safi)) {
8204 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
8205 return CMD_WARNING;
8206 }
8207 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
8208 bgp_show_type_flap_regexp);
8209}
8210
8211ALIAS (show_bgp_ipv6_safi_flap_regexp,
8212 show_bgp_ipv6_safi_damp_flap_regexp_cmd,
8213 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics regexp .LINE",
8214 SHOW_STR
8215 BGP_STR
8216 IPV6_STR
8217 "Address Family Modifier\n"
8218 "Address Family Modifier\n"
8219 "Address Family Modifier\n"
8220 "Address Family Modifier\n"
8221 "Display detailed information about dampening\n"
8222 "Display flap statistics of routes\n"
8223 "Display routes matching the AS path regular expression\n"
8224 "A regular-expression to match the BGP AS paths\n")
Lou Berger651b4022016-01-12 13:42:07 -05008225
8226DEFUN (show_bgp_ipv4_safi_regexp,
8227 show_bgp_ipv4_safi_regexp_cmd,
8228 "show bgp ipv4 (encap|multicast|unicast|vpn) regexp .LINE",
8229 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008230 BGP_STR
8231 "Address family\n"
8232 "Address Family modifier\n"
8233 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008234 "Address Family modifier\n"
8235 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008236 "Display routes matching the AS path regular expression\n"
8237 "A regular-expression to match the BGP AS paths\n")
8238{
Lou Berger651b4022016-01-12 13:42:07 -05008239 safi_t safi;
8240 if (bgp_parse_safi(argv[0], &safi)) {
8241 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8242 return CMD_WARNING;
8243 }
paul718e3742002-12-13 20:15:29 +00008244
Lou Berger651b4022016-01-12 13:42:07 -05008245 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008246 bgp_show_type_regexp);
8247}
Lou Berger205e6742016-01-12 13:42:11 -05008248
Lou Berger651b4022016-01-12 13:42:07 -05008249DEFUN (show_bgp_ipv6_safi_regexp,
8250 show_bgp_ipv6_safi_regexp_cmd,
8251 "show bgp ipv6 (encap|multicast|unicast|vpn) regexp .LINE",
paul718e3742002-12-13 20:15:29 +00008252 SHOW_STR
8253 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008254 "Address family\n"
8255 "Address Family modifier\n"
8256 "Address Family modifier\n"
8257 "Address Family modifier\n"
8258 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008259 "Display routes matching the AS path regular expression\n"
8260 "A regular-expression to match the BGP AS paths\n")
8261{
Lou Berger651b4022016-01-12 13:42:07 -05008262 safi_t safi;
8263 if (bgp_parse_safi(argv[0], &safi)) {
8264 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8265 return CMD_WARNING;
8266 }
8267
8268 return bgp_show_regexp (vty, argc-1, argv+1, AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008269 bgp_show_type_regexp);
8270}
8271
Lou Berger651b4022016-01-12 13:42:07 -05008272DEFUN (show_bgp_ipv6_regexp,
paul718e3742002-12-13 20:15:29 +00008273 show_bgp_ipv6_regexp_cmd,
8274 "show bgp ipv6 regexp .LINE",
8275 SHOW_STR
8276 BGP_STR
8277 "Address family\n"
8278 "Display routes matching the AS path regular expression\n"
8279 "A regular-expression to match the BGP AS paths\n")
paul718e3742002-12-13 20:15:29 +00008280{
8281 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
8282 bgp_show_type_regexp);
8283}
8284
paul94f2b392005-06-28 12:44:16 +00008285static int
paulfd79ac92004-10-13 05:06:08 +00008286bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008287 safi_t safi, enum bgp_show_type type)
8288{
8289 struct prefix_list *plist;
8290
8291 plist = prefix_list_lookup (afi, prefix_list_str);
8292 if (plist == NULL)
8293 {
8294 vty_out (vty, "%% %s is not a valid prefix-list name%s",
8295 prefix_list_str, VTY_NEWLINE);
8296 return CMD_WARNING;
8297 }
8298
ajs5a646652004-11-05 01:25:55 +00008299 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00008300}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008301DEFUN (show_ip_bgp_prefix_list,
8302 show_ip_bgp_prefix_list_cmd,
8303 "show ip bgp prefix-list WORD",
8304 SHOW_STR
8305 IP_STR
8306 BGP_STR
8307 "Display routes conforming to the prefix-list\n"
8308 "IP prefix-list name\n")
8309{
8310 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8311 bgp_show_type_prefix_list);
8312}
8313
8314DEFUN (show_ip_bgp_flap_prefix_list,
8315 show_ip_bgp_flap_prefix_list_cmd,
8316 "show ip bgp flap-statistics prefix-list WORD",
8317 SHOW_STR
8318 IP_STR
8319 BGP_STR
8320 "Display flap statistics of routes\n"
8321 "Display routes conforming to the prefix-list\n"
8322 "IP prefix-list name\n")
8323{
8324 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8325 bgp_show_type_flap_prefix_list);
8326}
8327
8328ALIAS (show_ip_bgp_flap_prefix_list,
8329 show_ip_bgp_damp_flap_prefix_list_cmd,
8330 "show ip bgp dampening flap-statistics prefix-list WORD",
8331 SHOW_STR
8332 IP_STR
8333 BGP_STR
8334 "Display detailed information about dampening\n"
8335 "Display flap statistics of routes\n"
8336 "Display routes conforming to the prefix-list\n"
8337 "IP prefix-list name\n")
8338
8339DEFUN (show_ip_bgp_ipv4_prefix_list,
8340 show_ip_bgp_ipv4_prefix_list_cmd,
8341 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
8342 SHOW_STR
8343 IP_STR
8344 BGP_STR
8345 "Address family\n"
8346 "Address Family modifier\n"
8347 "Address Family modifier\n"
8348 "Display routes conforming to the prefix-list\n"
8349 "IP prefix-list name\n")
8350{
8351 if (strncmp (argv[0], "m", 1) == 0)
8352 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8353 bgp_show_type_prefix_list);
8354
8355 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8356 bgp_show_type_prefix_list);
8357}
8358
Lou Bergerf9b6c392016-01-12 13:42:09 -05008359DEFUN (show_bgp_prefix_list,
8360 show_bgp_prefix_list_cmd,
8361 "show bgp prefix-list WORD",
8362 SHOW_STR
8363 BGP_STR
8364 "Display routes conforming to the prefix-list\n"
8365 "IPv6 prefix-list name\n")
8366{
8367 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8368 bgp_show_type_prefix_list);
8369}
8370
8371ALIAS (show_bgp_prefix_list,
8372 show_bgp_ipv6_prefix_list_cmd,
8373 "show bgp ipv6 prefix-list WORD",
8374 SHOW_STR
8375 BGP_STR
8376 "Address family\n"
8377 "Display routes conforming to the prefix-list\n"
8378 "IPv6 prefix-list name\n")
8379
8380/* old command */
8381DEFUN (show_ipv6_bgp_prefix_list,
8382 show_ipv6_bgp_prefix_list_cmd,
8383 "show ipv6 bgp prefix-list WORD",
8384 SHOW_STR
8385 IPV6_STR
8386 BGP_STR
8387 "Display routes matching the prefix-list\n"
8388 "IPv6 prefix-list name\n")
8389{
8390 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8391 bgp_show_type_prefix_list);
8392}
8393
8394/* old command */
8395DEFUN (show_ipv6_mbgp_prefix_list,
8396 show_ipv6_mbgp_prefix_list_cmd,
8397 "show ipv6 mbgp prefix-list WORD",
8398 SHOW_STR
8399 IPV6_STR
8400 MBGP_STR
8401 "Display routes matching the prefix-list\n"
8402 "IPv6 prefix-list name\n")
8403{
8404 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8405 bgp_show_type_prefix_list);
8406}
paul718e3742002-12-13 20:15:29 +00008407
Lou Berger35c36862016-01-12 13:42:06 -05008408DEFUN (show_bgp_ipv4_prefix_list,
8409 show_bgp_ipv4_prefix_list_cmd,
8410 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008411 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008412 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05008413 IP_STR
paul718e3742002-12-13 20:15:29 +00008414 "Display routes conforming to the prefix-list\n"
8415 "IP prefix-list name\n")
8416{
8417 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8418 bgp_show_type_prefix_list);
8419}
8420
Lou Berger651b4022016-01-12 13:42:07 -05008421DEFUN (show_bgp_ipv4_safi_flap_prefix_list,
8422 show_bgp_ipv4_safi_flap_prefix_list_cmd,
8423 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008424 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008425 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008426 IP_STR
8427 "Address Family Modifier\n"
8428 "Address Family Modifier\n"
8429 "Address Family Modifier\n"
8430 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00008431 "Display flap statistics of routes\n"
8432 "Display routes conforming to the prefix-list\n"
8433 "IP prefix-list name\n")
8434{
Lou Berger651b4022016-01-12 13:42:07 -05008435 safi_t safi;
8436 if (bgp_parse_safi(argv[0], &safi)) {
8437 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8438 return CMD_WARNING;
8439 }
8440 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008441 bgp_show_type_flap_prefix_list);
8442}
8443
Lou Berger651b4022016-01-12 13:42:07 -05008444ALIAS (show_bgp_ipv4_safi_flap_prefix_list,
8445 show_bgp_ipv4_safi_damp_flap_prefix_list_cmd,
8446 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308447 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308448 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008449 IP_STR
8450 "Address Family Modifier\n"
8451 "Address Family Modifier\n"
8452 "Address Family Modifier\n"
8453 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308454 "Display detailed information about dampening\n"
8455 "Display flap statistics of routes\n"
8456 "Display routes conforming to the prefix-list\n"
8457 "IP prefix-list name\n")
8458
Lou Berger651b4022016-01-12 13:42:07 -05008459DEFUN (show_bgp_ipv6_safi_flap_prefix_list,
8460 show_bgp_ipv6_safi_flap_prefix_list_cmd,
8461 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008462 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05008463 BGP_STR
8464 IPV6_STR
8465 "Address Family Modifier\n"
8466 "Address Family Modifier\n"
8467 "Address Family Modifier\n"
8468 "Address Family Modifier\n"
8469 "Display flap statistics of routes\n"
8470 "Display routes conforming to the prefix-list\n"
8471 "IP prefix-list name\n")
8472{
8473 safi_t safi;
8474 if (bgp_parse_safi(argv[0], &safi)) {
8475 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8476 return CMD_WARNING;
8477 }
8478 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
8479 bgp_show_type_flap_prefix_list);
8480}
8481ALIAS (show_bgp_ipv6_safi_flap_prefix_list,
8482 show_bgp_ipv6_safi_damp_flap_prefix_list_cmd,
8483 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics prefix-list WORD",
8484 SHOW_STR
8485 BGP_STR
8486 IPV6_STR
8487 "Address Family Modifier\n"
8488 "Address Family Modifier\n"
8489 "Address Family Modifier\n"
8490 "Address Family Modifier\n"
8491 "Display detailed information about dampening\n"
8492 "Display flap statistics of routes\n"
8493 "Display routes conforming to the prefix-list\n"
8494 "IP prefix-list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008495
8496DEFUN (show_bgp_ipv4_safi_prefix_list,
8497 show_bgp_ipv4_safi_prefix_list_cmd,
8498 "show bgp ipv4 (encap|multicast|unicast|vpn) prefix-list WORD",
8499 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008500 BGP_STR
8501 "Address family\n"
8502 "Address Family modifier\n"
8503 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05008504 "Address Family modifier\n"
8505 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008506 "Display routes conforming to the prefix-list\n"
8507 "IP prefix-list name\n")
8508{
Lou Berger651b4022016-01-12 13:42:07 -05008509 safi_t safi;
8510 if (bgp_parse_safi(argv[0], &safi)) {
8511 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8512 return CMD_WARNING;
8513 }
8514 return bgp_show_prefix_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008515 bgp_show_type_prefix_list);
8516}
Lou Berger205e6742016-01-12 13:42:11 -05008517
Lou Berger651b4022016-01-12 13:42:07 -05008518DEFUN (show_bgp_ipv6_safi_prefix_list,
8519 show_bgp_ipv6_safi_prefix_list_cmd,
8520 "show bgp ipv6 (encap|multicast|unicast|vpn) prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00008521 SHOW_STR
8522 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008523 "Address family\n"
8524 "Address Family modifier\n"
8525 "Address Family modifier\n"
8526 "Address Family modifier\n"
8527 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008528 "Display routes conforming to the prefix-list\n"
Lou Berger651b4022016-01-12 13:42:07 -05008529 "IP prefix-list name\n")
paul718e3742002-12-13 20:15:29 +00008530{
Lou Berger651b4022016-01-12 13:42:07 -05008531 safi_t safi;
8532 if (bgp_parse_safi(argv[0], &safi)) {
8533 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8534 return CMD_WARNING;
8535 }
8536 return bgp_show_prefix_list (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00008537 bgp_show_type_prefix_list);
8538}
8539
paul94f2b392005-06-28 12:44:16 +00008540static int
paulfd79ac92004-10-13 05:06:08 +00008541bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008542 safi_t safi, enum bgp_show_type type)
8543{
8544 struct as_list *as_list;
8545
8546 as_list = as_list_lookup (filter);
8547 if (as_list == NULL)
8548 {
8549 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
8550 return CMD_WARNING;
8551 }
8552
ajs5a646652004-11-05 01:25:55 +00008553 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00008554}
8555
Lou Bergerf9b6c392016-01-12 13:42:09 -05008556DEFUN (show_ip_bgp_filter_list,
8557 show_ip_bgp_filter_list_cmd,
8558 "show ip bgp filter-list WORD",
8559 SHOW_STR
8560 IP_STR
8561 BGP_STR
8562 "Display routes conforming to the filter-list\n"
8563 "Regular expression access list name\n")
8564{
8565 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8566 bgp_show_type_filter_list);
8567}
8568
8569DEFUN (show_ip_bgp_flap_filter_list,
8570 show_ip_bgp_flap_filter_list_cmd,
8571 "show ip bgp flap-statistics filter-list WORD",
8572 SHOW_STR
8573 IP_STR
8574 BGP_STR
8575 "Display flap statistics of routes\n"
8576 "Display routes conforming to the filter-list\n"
8577 "Regular expression access list name\n")
8578{
8579 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8580 bgp_show_type_flap_filter_list);
8581}
8582
8583ALIAS (show_ip_bgp_flap_filter_list,
8584 show_ip_bgp_damp_flap_filter_list_cmd,
8585 "show ip bgp dampening flap-statistics filter-list WORD",
8586 SHOW_STR
8587 IP_STR
8588 BGP_STR
8589 "Display detailed information about dampening\n"
8590 "Display flap statistics of routes\n"
8591 "Display routes conforming to the filter-list\n"
8592 "Regular expression access list name\n")
8593
8594DEFUN (show_ip_bgp_ipv4_filter_list,
8595 show_ip_bgp_ipv4_filter_list_cmd,
8596 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
8597 SHOW_STR
8598 IP_STR
8599 BGP_STR
8600 "Address family\n"
8601 "Address Family modifier\n"
8602 "Address Family modifier\n"
8603 "Display routes conforming to the filter-list\n"
8604 "Regular expression access list name\n")
8605{
8606 if (strncmp (argv[0], "m", 1) == 0)
8607 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8608 bgp_show_type_filter_list);
8609
8610 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
8611 bgp_show_type_filter_list);
8612}
8613
Lou Bergerf9b6c392016-01-12 13:42:09 -05008614DEFUN (show_bgp_filter_list,
8615 show_bgp_filter_list_cmd,
8616 "show bgp filter-list WORD",
8617 SHOW_STR
8618 BGP_STR
8619 "Display routes conforming to the filter-list\n"
8620 "Regular expression access list name\n")
8621{
8622 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8623 bgp_show_type_filter_list);
8624}
8625
8626/* old command */
8627DEFUN (show_ipv6_bgp_filter_list,
8628 show_ipv6_bgp_filter_list_cmd,
8629 "show ipv6 bgp filter-list WORD",
8630 SHOW_STR
8631 IPV6_STR
8632 BGP_STR
8633 "Display routes conforming to the filter-list\n"
8634 "Regular expression access list name\n")
8635{
8636 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8637 bgp_show_type_filter_list);
8638}
8639
8640/* old command */
8641DEFUN (show_ipv6_mbgp_filter_list,
8642 show_ipv6_mbgp_filter_list_cmd,
8643 "show ipv6 mbgp filter-list WORD",
8644 SHOW_STR
8645 IPV6_STR
8646 MBGP_STR
8647 "Display routes conforming to the filter-list\n"
8648 "Regular expression access list name\n")
8649{
8650 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8651 bgp_show_type_filter_list);
8652}
Lou Bergerf9b6c392016-01-12 13:42:09 -05008653
8654DEFUN (show_ip_bgp_dampening_info,
8655 show_ip_bgp_dampening_params_cmd,
8656 "show ip bgp dampening parameters",
8657 SHOW_STR
8658 IP_STR
8659 BGP_STR
8660 "Display detailed information about dampening\n"
8661 "Display detail of configured dampening parameters\n")
8662{
8663 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8664}
8665
Lou Berger651b4022016-01-12 13:42:07 -05008666DEFUN (show_bgp_ipv4_filter_list,
8667 show_bgp_ipv4_filter_list_cmd,
8668 "show bgp ipv4 filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008669 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008670 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008671 IP_STR
paul718e3742002-12-13 20:15:29 +00008672 "Display routes conforming to the filter-list\n"
8673 "Regular expression access list name\n")
8674{
8675 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
8676 bgp_show_type_filter_list);
8677}
8678
Lou Berger651b4022016-01-12 13:42:07 -05008679DEFUN (show_bgp_ipv4_safi_flap_filter_list,
8680 show_bgp_ipv4_safi_flap_filter_list_cmd,
8681 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008682 SHOW_STR
paul718e3742002-12-13 20:15:29 +00008683 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008684 IP_STR
8685 "Address Family modifier\n"
8686 "Address Family modifier\n"
8687 "Address Family modifier\n"
8688 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00008689 "Display flap statistics of routes\n"
8690 "Display routes conforming to the filter-list\n"
8691 "Regular expression access list name\n")
8692{
Lou Berger651b4022016-01-12 13:42:07 -05008693 safi_t safi;
8694
8695 if (bgp_parse_safi(argv[0], &safi)) {
8696 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8697 return CMD_WARNING;
8698 }
8699 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00008700 bgp_show_type_flap_filter_list);
8701}
8702
Lou Berger651b4022016-01-12 13:42:07 -05008703ALIAS (show_bgp_ipv4_safi_flap_filter_list,
8704 show_bgp_ipv4_safi_damp_flap_filter_list_cmd,
8705 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
Balaji3921cc52015-05-16 23:12:17 +05308706 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05308707 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008708 IP_STR
8709 "Address Family modifier\n"
8710 "Address Family modifier\n"
8711 "Address Family modifier\n"
8712 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05308713 "Display detailed information about dampening\n"
8714 "Display flap statistics of routes\n"
8715 "Display routes conforming to the filter-list\n"
8716 "Regular expression access list name\n")
8717
Lou Berger651b4022016-01-12 13:42:07 -05008718DEFUN (show_bgp_ipv6_safi_flap_filter_list,
8719 show_bgp_ipv6_safi_flap_filter_list_cmd,
8720 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics filter-list WORD",
paul718e3742002-12-13 20:15:29 +00008721 SHOW_STR
8722 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05008723 IPV6_STR
8724 "Address Family modifier\n"
8725 "Address Family modifier\n"
8726 "Address Family modifier\n"
8727 "Address Family modifier\n"
8728 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +00008729 "Display routes conforming to the filter-list\n"
8730 "Regular expression access list name\n")
8731{
Lou Berger651b4022016-01-12 13:42:07 -05008732 safi_t safi;
8733
8734 if (bgp_parse_safi(argv[0], &safi)) {
8735 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8736 return CMD_WARNING;
8737 }
8738 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8739 bgp_show_type_flap_filter_list);
8740}
8741ALIAS (show_bgp_ipv6_safi_flap_filter_list,
8742 show_bgp_ipv6_safi_damp_flap_filter_list_cmd,
8743 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics filter-list WORD",
8744 SHOW_STR
8745 BGP_STR
8746 IPV6_STR
8747 "Address Family modifier\n"
8748 "Address Family modifier\n"
8749 "Address Family modifier\n"
8750 "Address Family modifier\n"
8751 "Display detailed information about dampening\n"
8752 "Display flap statistics of routes\n"
8753 "Display routes conforming to the filter-list\n"
8754 "Regular expression access list name\n")
Lou Berger651b4022016-01-12 13:42:07 -05008755
8756DEFUN (show_bgp_ipv4_safi_filter_list,
8757 show_bgp_ipv4_safi_filter_list_cmd,
8758 "show bgp ipv4 (encap|multicast|unicast|vpn) filter-list WORD",
8759 SHOW_STR
8760 BGP_STR
8761 "Address Family modifier\n"
8762 "Address Family modifier\n"
8763 "Address Family modifier\n"
8764 "Address Family modifier\n"
8765 "Display routes conforming to the filter-list\n"
8766 "Regular expression access list name\n")
8767{
8768 safi_t safi;
8769
8770 if (bgp_parse_safi(argv[0], &safi)) {
8771 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8772 return CMD_WARNING;
8773 }
8774 return bgp_show_filter_list (vty, argv[1], AFI_IP, safi,
8775 bgp_show_type_filter_list);
8776}
Lou Berger205e6742016-01-12 13:42:11 -05008777
Lou Berger651b4022016-01-12 13:42:07 -05008778DEFUN (show_bgp_ipv6_safi_filter_list,
8779 show_bgp_ipv6_safi_filter_list_cmd,
8780 "show bgp ipv6 (encap|multicast|unicast|vpn) filter-list WORD",
8781 SHOW_STR
8782 BGP_STR
8783 "Address Family modifier\n"
8784 "Address Family modifier\n"
8785 "Address Family modifier\n"
8786 "Address Family modifier\n"
8787 "Display routes conforming to the filter-list\n"
8788 "Regular expression access list name\n")
8789{
8790 safi_t safi;
8791
8792 if (bgp_parse_safi(argv[0], &safi)) {
8793 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
8794 return CMD_WARNING;
8795 }
8796 return bgp_show_filter_list (vty, argv[1], AFI_IP6, safi,
8797 bgp_show_type_filter_list);
paul718e3742002-12-13 20:15:29 +00008798}
8799
Lou Bergerf9b6c392016-01-12 13:42:09 -05008800DEFUN (show_bgp_ipv6_filter_list,
paul718e3742002-12-13 20:15:29 +00008801 show_bgp_ipv6_filter_list_cmd,
8802 "show bgp ipv6 filter-list WORD",
8803 SHOW_STR
8804 BGP_STR
8805 "Address family\n"
8806 "Display routes conforming to the filter-list\n"
8807 "Regular expression access list name\n")
paul718e3742002-12-13 20:15:29 +00008808{
8809 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8810 bgp_show_type_filter_list);
8811}
8812
Balaji9c52cae2016-01-20 22:59:26 +05308813
8814DEFUN (show_ip_bgp_ipv4_dampening_parameters,
8815 show_ip_bgp_ipv4_dampening_parameters_cmd,
8816 "show ip bgp ipv4 (unicast|multicast) dampening parameters",
8817 SHOW_STR
8818 IP_STR
8819 BGP_STR
8820 "Address family\n"
8821 "Address Family modifier\n"
8822 "Address Family modifier\n"
8823 "Display detailed information about dampening\n"
8824 "Display detail of configured dampening parameters\n")
8825{
8826 if (strncmp(argv[0], "m", 1) == 0)
8827 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_MULTICAST);
8828
8829 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
8830}
8831
8832
8833DEFUN (show_ip_bgp_ipv4_dampening_flap_stats,
8834 show_ip_bgp_ipv4_dampening_flap_stats_cmd,
8835 "show ip bgp ipv4 (unicast|multicast) dampening flap-statistics",
8836 SHOW_STR
8837 IP_STR
8838 BGP_STR
8839 "Address family\n"
8840 "Address Family modifier\n"
8841 "Address Family modifier\n"
8842 "Display detailed information about dampening\n"
8843 "Display flap statistics of routes\n")
8844{
8845 if (strncmp(argv[0], "m", 1) == 0)
8846 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8847 bgp_show_type_flap_statistics, NULL);
8848
8849 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8850 bgp_show_type_flap_statistics, NULL);
8851}
8852
8853DEFUN (show_ip_bgp_ipv4_dampening_dampd_paths,
8854 show_ip_bgp_ipv4_dampening_dampd_paths_cmd,
8855 "show ip bgp ipv4 (unicast|multicast) dampening dampened-paths",
8856 SHOW_STR
8857 IP_STR
8858 BGP_STR
8859 "Address family\n"
8860 "Address Family modifier\n"
8861 "Address Family modifier\n"
8862 "Display detailed information about dampening\n"
8863 "Display paths suppressed due to dampening\n")
8864{
8865 if (strncmp(argv[0], "m", 1) == 0)
8866 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8867 bgp_show_type_dampend_paths, NULL);
8868
8869 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
8870 bgp_show_type_dampend_paths, NULL);
8871}
8872
paul94f2b392005-06-28 12:44:16 +00008873static int
paulfd79ac92004-10-13 05:06:08 +00008874bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008875 safi_t safi, enum bgp_show_type type)
8876{
8877 struct route_map *rmap;
8878
8879 rmap = route_map_lookup_by_name (rmap_str);
8880 if (! rmap)
8881 {
8882 vty_out (vty, "%% %s is not a valid route-map name%s",
8883 rmap_str, VTY_NEWLINE);
8884 return CMD_WARNING;
8885 }
8886
ajs5a646652004-11-05 01:25:55 +00008887 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00008888}
8889
Lou Bergerf9b6c392016-01-12 13:42:09 -05008890DEFUN (show_ip_bgp_route_map,
8891 show_ip_bgp_route_map_cmd,
8892 "show ip bgp route-map WORD",
8893 SHOW_STR
8894 IP_STR
8895 BGP_STR
8896 "Display routes matching the route-map\n"
8897 "A route-map to match on\n")
8898{
8899 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8900 bgp_show_type_route_map);
8901}
8902
8903DEFUN (show_ip_bgp_flap_route_map,
8904 show_ip_bgp_flap_route_map_cmd,
8905 "show ip bgp flap-statistics route-map WORD",
8906 SHOW_STR
8907 IP_STR
8908 BGP_STR
8909 "Display flap statistics of routes\n"
8910 "Display routes matching the route-map\n"
8911 "A route-map to match on\n")
8912{
8913 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
8914 bgp_show_type_flap_route_map);
8915}
8916
8917ALIAS (show_ip_bgp_flap_route_map,
8918 show_ip_bgp_damp_flap_route_map_cmd,
8919 "show ip bgp dampening flap-statistics route-map WORD",
8920 SHOW_STR
8921 IP_STR
8922 BGP_STR
8923 "Display detailed information about dampening\n"
8924 "Display flap statistics of routes\n"
8925 "Display routes matching the route-map\n"
8926 "A route-map to match on\n")
8927
8928DEFUN (show_ip_bgp_ipv4_route_map,
8929 show_ip_bgp_ipv4_route_map_cmd,
8930 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
8931 SHOW_STR
8932 IP_STR
8933 BGP_STR
8934 "Address family\n"
8935 "Address Family modifier\n"
8936 "Address Family modifier\n"
8937 "Display routes matching the route-map\n"
8938 "A route-map to match on\n")
8939{
8940 if (strncmp (argv[0], "m", 1) == 0)
8941 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8942 bgp_show_type_route_map);
8943
8944 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
8945 bgp_show_type_route_map);
8946}
8947
8948DEFUN (show_bgp_route_map,
8949 show_bgp_route_map_cmd,
8950 "show bgp route-map WORD",
8951 SHOW_STR
8952 BGP_STR
8953 "Display routes matching the route-map\n"
8954 "A route-map to match on\n")
8955{
8956 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8957 bgp_show_type_route_map);
8958}
8959
8960DEFUN (show_ip_bgp_cidr_only,
8961 show_ip_bgp_cidr_only_cmd,
8962 "show ip bgp cidr-only",
8963 SHOW_STR
8964 IP_STR
8965 BGP_STR
8966 "Display only routes with non-natural netmasks\n")
8967{
8968 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8969 bgp_show_type_cidr_only, NULL);
8970}
8971
8972DEFUN (show_ip_bgp_flap_cidr_only,
8973 show_ip_bgp_flap_cidr_only_cmd,
8974 "show ip bgp flap-statistics cidr-only",
8975 SHOW_STR
8976 IP_STR
8977 BGP_STR
8978 "Display flap statistics of routes\n"
8979 "Display only routes with non-natural netmasks\n")
8980{
8981 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
8982 bgp_show_type_flap_cidr_only, NULL);
8983}
8984
8985ALIAS (show_ip_bgp_flap_cidr_only,
8986 show_ip_bgp_damp_flap_cidr_only_cmd,
8987 "show ip bgp dampening flap-statistics cidr-only",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "Display detailed information about dampening\n"
8992 "Display flap statistics of routes\n"
8993 "Display only routes with non-natural netmasks\n")
8994
8995DEFUN (show_ip_bgp_ipv4_cidr_only,
8996 show_ip_bgp_ipv4_cidr_only_cmd,
8997 "show ip bgp ipv4 (unicast|multicast) cidr-only",
8998 SHOW_STR
8999 IP_STR
9000 BGP_STR
9001 "Address family\n"
9002 "Address Family modifier\n"
9003 "Address Family modifier\n"
9004 "Display only routes with non-natural netmasks\n")
9005{
9006 if (strncmp (argv[0], "m", 1) == 0)
9007 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9008 bgp_show_type_cidr_only, NULL);
9009
9010 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9011 bgp_show_type_cidr_only, NULL);
9012}
9013
9014DEFUN (show_ip_bgp_community_all,
9015 show_ip_bgp_community_all_cmd,
9016 "show ip bgp community",
9017 SHOW_STR
9018 IP_STR
9019 BGP_STR
9020 "Display routes matching the communities\n")
9021{
9022 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9023 bgp_show_type_community_all, NULL);
9024}
9025
9026DEFUN (show_ip_bgp_ipv4_community_all,
9027 show_ip_bgp_ipv4_community_all_cmd,
9028 "show ip bgp ipv4 (unicast|multicast) community",
9029 SHOW_STR
9030 IP_STR
9031 BGP_STR
9032 "Address family\n"
9033 "Address Family modifier\n"
9034 "Address Family modifier\n"
9035 "Display routes matching the communities\n")
9036{
9037 if (strncmp (argv[0], "m", 1) == 0)
9038 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
9039 bgp_show_type_community_all, NULL);
9040
9041 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
9042 bgp_show_type_community_all, NULL);
9043}
9044
Lou Bergerf9b6c392016-01-12 13:42:09 -05009045DEFUN (show_bgp_community_all,
9046 show_bgp_community_all_cmd,
9047 "show bgp community",
9048 SHOW_STR
9049 BGP_STR
9050 "Display routes matching the communities\n")
9051{
9052 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9053 bgp_show_type_community_all, NULL);
9054}
9055
9056ALIAS (show_bgp_community_all,
9057 show_bgp_ipv6_community_all_cmd,
9058 "show bgp ipv6 community",
9059 SHOW_STR
9060 BGP_STR
9061 "Address family\n"
9062 "Display routes matching the communities\n")
9063
9064/* old command */
9065DEFUN (show_ipv6_bgp_community_all,
9066 show_ipv6_bgp_community_all_cmd,
9067 "show ipv6 bgp community",
9068 SHOW_STR
9069 IPV6_STR
9070 BGP_STR
9071 "Display routes matching the communities\n")
9072{
9073 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
9074 bgp_show_type_community_all, NULL);
9075}
9076
9077/* old command */
9078DEFUN (show_ipv6_mbgp_community_all,
9079 show_ipv6_mbgp_community_all_cmd,
9080 "show ipv6 mbgp community",
9081 SHOW_STR
9082 IPV6_STR
9083 MBGP_STR
9084 "Display routes matching the communities\n")
9085{
9086 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
9087 bgp_show_type_community_all, NULL);
9088}
Lou Bergerf9b6c392016-01-12 13:42:09 -05009089
Lou Berger651b4022016-01-12 13:42:07 -05009090DEFUN (show_bgp_ipv4_route_map,
9091 show_bgp_ipv4_route_map_cmd,
9092 "show bgp ipv4 route-map WORD",
paul718e3742002-12-13 20:15:29 +00009093 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009094 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009095 IP_STR
paul718e3742002-12-13 20:15:29 +00009096 "Display routes matching the route-map\n"
9097 "A route-map to match on\n")
9098{
9099 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
9100 bgp_show_type_route_map);
9101}
9102
Lou Berger651b4022016-01-12 13:42:07 -05009103DEFUN (show_bgp_ipv4_safi_flap_route_map,
9104 show_bgp_ipv4_safi_flap_route_map_cmd,
9105 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009106 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009107 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009108 IP_STR
9109 "Address Family Modifier\n"
9110 "Address Family Modifier\n"
9111 "Address Family Modifier\n"
9112 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009113 "Display flap statistics of routes\n"
9114 "Display routes matching the route-map\n"
9115 "A route-map to match on\n")
9116{
Lou Berger651b4022016-01-12 13:42:07 -05009117 safi_t safi;
9118 if (bgp_parse_safi(argv[0], &safi)) {
9119 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9120 return CMD_WARNING;
9121 }
9122 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009123 bgp_show_type_flap_route_map);
9124}
9125
Lou Berger651b4022016-01-12 13:42:07 -05009126ALIAS (show_bgp_ipv4_safi_flap_route_map,
9127 show_bgp_ipv4_safi_damp_flap_route_map_cmd,
9128 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
Balaji3921cc52015-05-16 23:12:17 +05309129 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309130 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009131 IP_STR
9132 "Address Family Modifier\n"
9133 "Address Family Modifier\n"
9134 "Address Family Modifier\n"
9135 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309136 "Display detailed information about dampening\n"
9137 "Display flap statistics of routes\n"
9138 "Display routes matching the route-map\n"
9139 "A route-map to match on\n")
Lou Berger205e6742016-01-12 13:42:11 -05009140
Lou Berger651b4022016-01-12 13:42:07 -05009141DEFUN (show_bgp_ipv6_safi_flap_route_map,
9142 show_bgp_ipv6_safi_flap_route_map_cmd,
9143 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics route-map WORD",
paul718e3742002-12-13 20:15:29 +00009144 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -05009145 BGP_STR
9146 IPV6_STR
9147 "Address Family Modifier\n"
9148 "Address Family Modifier\n"
9149 "Address Family Modifier\n"
9150 "Address Family Modifier\n"
9151 "Display flap statistics of routes\n"
9152 "Display routes matching the route-map\n"
9153 "A route-map to match on\n")
9154{
9155 safi_t safi;
9156 if (bgp_parse_safi(argv[0], &safi)) {
9157 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9158 return CMD_WARNING;
9159 }
9160 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
9161 bgp_show_type_flap_route_map);
9162}
9163ALIAS (show_bgp_ipv6_safi_flap_route_map,
9164 show_bgp_ipv6_safi_damp_flap_route_map_cmd,
9165 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics route-map WORD",
9166 SHOW_STR
9167 BGP_STR
9168 IPV6_STR
9169 "Address Family Modifier\n"
9170 "Address Family Modifier\n"
9171 "Address Family Modifier\n"
9172 "Address Family Modifier\n"
9173 "Display detailed information about dampening\n"
9174 "Display flap statistics of routes\n"
9175 "Display routes matching the route-map\n"
9176 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009177
9178DEFUN (show_bgp_ipv4_safi_route_map,
9179 show_bgp_ipv4_safi_route_map_cmd,
9180 "show bgp ipv4 (encap|multicast|unicast|vpn) route-map WORD",
9181 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009182 BGP_STR
9183 "Address family\n"
9184 "Address Family modifier\n"
9185 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -05009186 "Address Family modifier\n"
9187 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009188 "Display routes matching the route-map\n"
9189 "A route-map to match on\n")
9190{
Lou Berger651b4022016-01-12 13:42:07 -05009191 safi_t safi;
9192 if (bgp_parse_safi(argv[0], &safi)) {
9193 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9194 return CMD_WARNING;
9195 }
9196 return bgp_show_route_map (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00009197 bgp_show_type_route_map);
9198}
Lou Berger205e6742016-01-12 13:42:11 -05009199
Lou Berger651b4022016-01-12 13:42:07 -05009200DEFUN (show_bgp_ipv6_safi_route_map,
9201 show_bgp_ipv6_safi_route_map_cmd,
9202 "show bgp ipv6 (encap|multicast|unicast|vpn) route-map WORD",
paul718e3742002-12-13 20:15:29 +00009203 SHOW_STR
9204 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009205 "Address family\n"
9206 "Address Family modifier\n"
9207 "Address Family modifier\n"
9208 "Address Family modifier\n"
9209 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009210 "Display routes matching the route-map\n"
9211 "A route-map to match on\n")
9212{
Lou Berger651b4022016-01-12 13:42:07 -05009213 safi_t safi;
9214 if (bgp_parse_safi(argv[0], &safi)) {
9215 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9216 return CMD_WARNING;
9217 }
9218 return bgp_show_route_map (vty, argv[1], AFI_IP6, safi,
paul718e3742002-12-13 20:15:29 +00009219 bgp_show_type_route_map);
9220}
9221
Lou Berger651b4022016-01-12 13:42:07 -05009222DEFUN (show_bgp_ipv6_route_map,
paul718e3742002-12-13 20:15:29 +00009223 show_bgp_ipv6_route_map_cmd,
9224 "show bgp ipv6 route-map WORD",
9225 SHOW_STR
9226 BGP_STR
9227 "Address family\n"
9228 "Display routes matching the route-map\n"
9229 "A route-map to match on\n")
Lou Berger651b4022016-01-12 13:42:07 -05009230{
9231 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9232 bgp_show_type_route_map);
9233}
David Lamparter6b0655a2014-06-04 06:53:35 +02009234
Lou Berger651b4022016-01-12 13:42:07 -05009235DEFUN (show_bgp_ipv4_cidr_only,
9236 show_bgp_ipv4_cidr_only_cmd,
9237 "show bgp ipv4 cidr-only",
paul718e3742002-12-13 20:15:29 +00009238 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009239 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009240 IP_STR
paul718e3742002-12-13 20:15:29 +00009241 "Display only routes with non-natural netmasks\n")
9242{
9243 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009244 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009245}
9246
Lou Berger651b4022016-01-12 13:42:07 -05009247DEFUN (show_bgp_ipv4_safi_flap_cidr_only,
9248 show_bgp_ipv4_safi_flap_cidr_only_cmd,
9249 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics cidr-only",
paul718e3742002-12-13 20:15:29 +00009250 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009251 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009252 "Address Family\n"
9253 "Address Family Modifier\n"
9254 "Address Family Modifier\n"
9255 "Address Family Modifier\n"
9256 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +00009257 "Display flap statistics of routes\n"
9258 "Display only routes with non-natural netmasks\n")
9259{
Lou Berger651b4022016-01-12 13:42:07 -05009260 safi_t safi;
9261
9262 if (bgp_parse_safi(argv[0], &safi)) {
9263 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
9264 return CMD_WARNING;
9265 }
9266 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009267}
9268
Lou Berger651b4022016-01-12 13:42:07 -05009269ALIAS (show_bgp_ipv4_safi_flap_cidr_only,
9270 show_bgp_ipv4_safi_damp_flap_cidr_only_cmd,
9271 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics cidr-only",
Balaji3921cc52015-05-16 23:12:17 +05309272 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +05309273 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009274 "Address Family\n"
9275 "Address Family Modifier\n"
9276 "Address Family Modifier\n"
9277 "Address Family Modifier\n"
9278 "Address Family Modifier\n"
Balaji3921cc52015-05-16 23:12:17 +05309279 "Display detailed information about dampening\n"
9280 "Display flap statistics of routes\n"
9281 "Display only routes with non-natural netmasks\n")
9282
Lou Berger651b4022016-01-12 13:42:07 -05009283DEFUN (show_bgp_ipv4_safi_cidr_only,
9284 show_bgp_ipv4_safi_cidr_only_cmd,
9285 "show bgp ipv4 (unicast|multicast) cidr-only",
paul718e3742002-12-13 20:15:29 +00009286 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009287 BGP_STR
9288 "Address family\n"
9289 "Address Family modifier\n"
9290 "Address Family modifier\n"
9291 "Display only routes with non-natural netmasks\n")
9292{
9293 if (strncmp (argv[0], "m", 1) == 0)
9294 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00009295 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009296
9297 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00009298 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00009299}
David Lamparter6b0655a2014-06-04 06:53:35 +02009300
Lou Berger651b4022016-01-12 13:42:07 -05009301/* new046 */
9302DEFUN (show_bgp_afi_safi_community_all,
9303 show_bgp_afi_safi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009304 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) community",
paul718e3742002-12-13 20:15:29 +00009305 SHOW_STR
9306 BGP_STR
9307 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009308 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009309 "Address Family modifier\n"
9310 "Address Family modifier\n"
9311 "Address Family modifier\n"
9312 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00009313 "Display routes matching the communities\n")
Lou Berger651b4022016-01-12 13:42:07 -05009314{
9315 safi_t safi;
9316 afi_t afi;
paul718e3742002-12-13 20:15:29 +00009317
Lou Berger651b4022016-01-12 13:42:07 -05009318 if (bgp_parse_afi(argv[0], &afi)) {
9319 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9320 return CMD_WARNING;
9321 }
9322 if (bgp_parse_safi(argv[1], &safi)) {
9323 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
9324 return CMD_WARNING;
9325 }
9326
9327 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
9328}
9329DEFUN (show_bgp_afi_community_all,
9330 show_bgp_afi_community_all_cmd,
Lou Berger651b4022016-01-12 13:42:07 -05009331 "show bgp (ipv4|ipv6) community",
paul718e3742002-12-13 20:15:29 +00009332 SHOW_STR
paul718e3742002-12-13 20:15:29 +00009333 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -05009334 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -05009335 "Address family\n"
paul718e3742002-12-13 20:15:29 +00009336 "Display routes matching the communities\n")
9337{
Lou Berger651b4022016-01-12 13:42:07 -05009338 afi_t afi;
9339 safi_t safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +00009340
Lou Berger651b4022016-01-12 13:42:07 -05009341 if (bgp_parse_afi(argv[0], &afi)) {
9342 vty_out (vty, "Error: Bad AFI: %s%s", argv[0], VTY_NEWLINE);
9343 return CMD_WARNING;
9344 }
9345 return bgp_show (vty, NULL, afi, safi, bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00009346}
David Lamparter6b0655a2014-06-04 06:53:35 +02009347
paul94f2b392005-06-28 12:44:16 +00009348static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04009349bgp_show_community (struct vty *vty, const char *view_name, int argc,
9350 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009351{
9352 struct community *com;
9353 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04009354 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00009355 int i;
9356 char *str;
9357 int first = 0;
9358
Michael Lambert95cbbd22010-07-23 14:43:04 -04009359 /* BGP structure lookup */
9360 if (view_name)
9361 {
9362 bgp = bgp_lookup_by_name (view_name);
9363 if (bgp == NULL)
9364 {
9365 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9366 return CMD_WARNING;
9367 }
9368 }
9369 else
9370 {
9371 bgp = bgp_get_default ();
9372 if (bgp == NULL)
9373 {
9374 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9375 return CMD_WARNING;
9376 }
9377 }
9378
paul718e3742002-12-13 20:15:29 +00009379 b = buffer_new (1024);
9380 for (i = 0; i < argc; i++)
9381 {
9382 if (first)
9383 buffer_putc (b, ' ');
9384 else
9385 {
9386 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
9387 continue;
9388 first = 1;
9389 }
9390
9391 buffer_putstr (b, argv[i]);
9392 }
9393 buffer_putc (b, '\0');
9394
9395 str = buffer_getstr (b);
9396 buffer_free (b);
9397
9398 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00009399 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00009400 if (! com)
9401 {
9402 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
9403 return CMD_WARNING;
9404 }
9405
Michael Lambert95cbbd22010-07-23 14:43:04 -04009406 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00009407 (exact ? bgp_show_type_community_exact :
9408 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00009409}
9410
Lou Bergerf9b6c392016-01-12 13:42:09 -05009411DEFUN (show_ip_bgp_community,
9412 show_ip_bgp_community_cmd,
9413 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
9414 SHOW_STR
9415 IP_STR
9416 BGP_STR
9417 "Display routes matching the communities\n"
9418 "community number\n"
9419 "Do not send outside local AS (well-known community)\n"
9420 "Do not advertise to any peer (well-known community)\n"
9421 "Do not export to next AS (well-known community)\n")
9422{
9423 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9424}
9425
9426ALIAS (show_ip_bgp_community,
9427 show_ip_bgp_community2_cmd,
9428 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9429 SHOW_STR
9430 IP_STR
9431 BGP_STR
9432 "Display routes matching the communities\n"
9433 "community number\n"
9434 "Do not send outside local AS (well-known community)\n"
9435 "Do not advertise to any peer (well-known community)\n"
9436 "Do not export to next AS (well-known community)\n"
9437 "community number\n"
9438 "Do not send outside local AS (well-known community)\n"
9439 "Do not advertise to any peer (well-known community)\n"
9440 "Do not export to next AS (well-known community)\n")
9441
9442ALIAS (show_ip_bgp_community,
9443 show_ip_bgp_community3_cmd,
9444 "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)",
9445 SHOW_STR
9446 IP_STR
9447 BGP_STR
9448 "Display routes matching the communities\n"
9449 "community number\n"
9450 "Do not send outside local AS (well-known community)\n"
9451 "Do not advertise to any peer (well-known community)\n"
9452 "Do not export to next AS (well-known community)\n"
9453 "community number\n"
9454 "Do not send outside local AS (well-known community)\n"
9455 "Do not advertise to any peer (well-known community)\n"
9456 "Do not export to next AS (well-known community)\n"
9457 "community number\n"
9458 "Do not send outside local AS (well-known community)\n"
9459 "Do not advertise to any peer (well-known community)\n"
9460 "Do not export to next AS (well-known community)\n")
9461
9462ALIAS (show_ip_bgp_community,
9463 show_ip_bgp_community4_cmd,
9464 "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)",
9465 SHOW_STR
9466 IP_STR
9467 BGP_STR
9468 "Display routes matching the communities\n"
9469 "community number\n"
9470 "Do not send outside local AS (well-known community)\n"
9471 "Do not advertise to any peer (well-known community)\n"
9472 "Do not export to next AS (well-known community)\n"
9473 "community number\n"
9474 "Do not send outside local AS (well-known community)\n"
9475 "Do not advertise to any peer (well-known community)\n"
9476 "Do not export to next AS (well-known community)\n"
9477 "community number\n"
9478 "Do not send outside local AS (well-known community)\n"
9479 "Do not advertise to any peer (well-known community)\n"
9480 "Do not export to next AS (well-known community)\n"
9481 "community number\n"
9482 "Do not send outside local AS (well-known community)\n"
9483 "Do not advertise to any peer (well-known community)\n"
9484 "Do not export to next AS (well-known community)\n")
9485
9486DEFUN (show_ip_bgp_ipv4_community,
9487 show_ip_bgp_ipv4_community_cmd,
9488 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
9489 SHOW_STR
9490 IP_STR
9491 BGP_STR
9492 "Address family\n"
9493 "Address Family modifier\n"
9494 "Address Family modifier\n"
9495 "Display routes matching the communities\n"
9496 "community number\n"
9497 "Do not send outside local AS (well-known community)\n"
9498 "Do not advertise to any peer (well-known community)\n"
9499 "Do not export to next AS (well-known community)\n")
9500{
9501 if (strncmp (argv[0], "m", 1) == 0)
9502 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
9503
9504 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
9505}
9506
9507ALIAS (show_ip_bgp_ipv4_community,
9508 show_ip_bgp_ipv4_community2_cmd,
9509 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9510 SHOW_STR
9511 IP_STR
9512 BGP_STR
9513 "Address family\n"
9514 "Address Family modifier\n"
9515 "Address Family modifier\n"
9516 "Display routes matching the communities\n"
9517 "community number\n"
9518 "Do not send outside local AS (well-known community)\n"
9519 "Do not advertise to any peer (well-known community)\n"
9520 "Do not export to next AS (well-known community)\n"
9521 "community number\n"
9522 "Do not send outside local AS (well-known community)\n"
9523 "Do not advertise to any peer (well-known community)\n"
9524 "Do not export to next AS (well-known community)\n")
9525
9526ALIAS (show_ip_bgp_ipv4_community,
9527 show_ip_bgp_ipv4_community3_cmd,
9528 "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)",
9529 SHOW_STR
9530 IP_STR
9531 BGP_STR
9532 "Address family\n"
9533 "Address Family modifier\n"
9534 "Address Family modifier\n"
9535 "Display routes matching the communities\n"
9536 "community number\n"
9537 "Do not send outside local AS (well-known community)\n"
9538 "Do not advertise to any peer (well-known community)\n"
9539 "Do not export to next AS (well-known community)\n"
9540 "community number\n"
9541 "Do not send outside local AS (well-known community)\n"
9542 "Do not advertise to any peer (well-known community)\n"
9543 "Do not export to next AS (well-known community)\n"
9544 "community number\n"
9545 "Do not send outside local AS (well-known community)\n"
9546 "Do not advertise to any peer (well-known community)\n"
9547 "Do not export to next AS (well-known community)\n")
9548
9549ALIAS (show_ip_bgp_ipv4_community,
9550 show_ip_bgp_ipv4_community4_cmd,
9551 "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)",
9552 SHOW_STR
9553 IP_STR
9554 BGP_STR
9555 "Address family\n"
9556 "Address Family modifier\n"
9557 "Address Family modifier\n"
9558 "Display routes matching the communities\n"
9559 "community number\n"
9560 "Do not send outside local AS (well-known community)\n"
9561 "Do not advertise to any peer (well-known community)\n"
9562 "Do not export to next AS (well-known community)\n"
9563 "community number\n"
9564 "Do not send outside local AS (well-known community)\n"
9565 "Do not advertise to any peer (well-known community)\n"
9566 "Do not export to next AS (well-known community)\n"
9567 "community number\n"
9568 "Do not send outside local AS (well-known community)\n"
9569 "Do not advertise to any peer (well-known community)\n"
9570 "Do not export to next AS (well-known community)\n"
9571 "community number\n"
9572 "Do not send outside local AS (well-known community)\n"
9573 "Do not advertise to any peer (well-known community)\n"
9574 "Do not export to next AS (well-known community)\n")
9575
9576DEFUN (show_ip_bgp_community_exact,
9577 show_ip_bgp_community_exact_cmd,
9578 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9579 SHOW_STR
9580 IP_STR
9581 BGP_STR
9582 "Display routes matching the communities\n"
9583 "community number\n"
9584 "Do not send outside local AS (well-known community)\n"
9585 "Do not advertise to any peer (well-known community)\n"
9586 "Do not export to next AS (well-known community)\n"
9587 "Exact match of the communities")
9588{
9589 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9590}
9591
9592ALIAS (show_ip_bgp_community_exact,
9593 show_ip_bgp_community2_exact_cmd,
9594 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9595 SHOW_STR
9596 IP_STR
9597 BGP_STR
9598 "Display routes matching the communities\n"
9599 "community number\n"
9600 "Do not send outside local AS (well-known community)\n"
9601 "Do not advertise to any peer (well-known community)\n"
9602 "Do not export to next AS (well-known community)\n"
9603 "community number\n"
9604 "Do not send outside local AS (well-known community)\n"
9605 "Do not advertise to any peer (well-known community)\n"
9606 "Do not export to next AS (well-known community)\n"
9607 "Exact match of the communities")
9608
9609ALIAS (show_ip_bgp_community_exact,
9610 show_ip_bgp_community3_exact_cmd,
9611 "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",
9612 SHOW_STR
9613 IP_STR
9614 BGP_STR
9615 "Display routes matching the communities\n"
9616 "community number\n"
9617 "Do not send outside local AS (well-known community)\n"
9618 "Do not advertise to any peer (well-known community)\n"
9619 "Do not export to next AS (well-known community)\n"
9620 "community number\n"
9621 "Do not send outside local AS (well-known community)\n"
9622 "Do not advertise to any peer (well-known community)\n"
9623 "Do not export to next AS (well-known community)\n"
9624 "community number\n"
9625 "Do not send outside local AS (well-known community)\n"
9626 "Do not advertise to any peer (well-known community)\n"
9627 "Do not export to next AS (well-known community)\n"
9628 "Exact match of the communities")
9629
9630ALIAS (show_ip_bgp_community_exact,
9631 show_ip_bgp_community4_exact_cmd,
9632 "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",
9633 SHOW_STR
9634 IP_STR
9635 BGP_STR
9636 "Display routes matching the communities\n"
9637 "community number\n"
9638 "Do not send outside local AS (well-known community)\n"
9639 "Do not advertise to any peer (well-known community)\n"
9640 "Do not export to next AS (well-known community)\n"
9641 "community number\n"
9642 "Do not send outside local AS (well-known community)\n"
9643 "Do not advertise to any peer (well-known community)\n"
9644 "Do not export to next AS (well-known community)\n"
9645 "community number\n"
9646 "Do not send outside local AS (well-known community)\n"
9647 "Do not advertise to any peer (well-known community)\n"
9648 "Do not export to next AS (well-known community)\n"
9649 "community number\n"
9650 "Do not send outside local AS (well-known community)\n"
9651 "Do not advertise to any peer (well-known community)\n"
9652 "Do not export to next AS (well-known community)\n"
9653 "Exact match of the communities")
9654
9655DEFUN (show_ip_bgp_ipv4_community_exact,
9656 show_ip_bgp_ipv4_community_exact_cmd,
9657 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9658 SHOW_STR
9659 IP_STR
9660 BGP_STR
9661 "Address family\n"
9662 "Address Family modifier\n"
9663 "Address Family modifier\n"
9664 "Display routes matching the communities\n"
9665 "community number\n"
9666 "Do not send outside local AS (well-known community)\n"
9667 "Do not advertise to any peer (well-known community)\n"
9668 "Do not export to next AS (well-known community)\n"
9669 "Exact match of the communities")
9670{
9671 if (strncmp (argv[0], "m", 1) == 0)
9672 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
9673
9674 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
9675}
9676
9677ALIAS (show_ip_bgp_ipv4_community_exact,
9678 show_ip_bgp_ipv4_community2_exact_cmd,
9679 "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",
9680 SHOW_STR
9681 IP_STR
9682 BGP_STR
9683 "Address family\n"
9684 "Address Family modifier\n"
9685 "Address Family modifier\n"
9686 "Display routes matching the communities\n"
9687 "community number\n"
9688 "Do not send outside local AS (well-known community)\n"
9689 "Do not advertise to any peer (well-known community)\n"
9690 "Do not export to next AS (well-known community)\n"
9691 "community number\n"
9692 "Do not send outside local AS (well-known community)\n"
9693 "Do not advertise to any peer (well-known community)\n"
9694 "Do not export to next AS (well-known community)\n"
9695 "Exact match of the communities")
9696
9697ALIAS (show_ip_bgp_ipv4_community_exact,
9698 show_ip_bgp_ipv4_community3_exact_cmd,
9699 "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",
9700 SHOW_STR
9701 IP_STR
9702 BGP_STR
9703 "Address family\n"
9704 "Address Family modifier\n"
9705 "Address Family modifier\n"
9706 "Display routes matching the communities\n"
9707 "community number\n"
9708 "Do not send outside local AS (well-known community)\n"
9709 "Do not advertise to any peer (well-known community)\n"
9710 "Do not export to next AS (well-known community)\n"
9711 "community number\n"
9712 "Do not send outside local AS (well-known community)\n"
9713 "Do not advertise to any peer (well-known community)\n"
9714 "Do not export to next AS (well-known community)\n"
9715 "community number\n"
9716 "Do not send outside local AS (well-known community)\n"
9717 "Do not advertise to any peer (well-known community)\n"
9718 "Do not export to next AS (well-known community)\n"
9719 "Exact match of the communities")
9720
9721ALIAS (show_ip_bgp_ipv4_community_exact,
9722 show_ip_bgp_ipv4_community4_exact_cmd,
9723 "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",
9724 SHOW_STR
9725 IP_STR
9726 BGP_STR
9727 "Address family\n"
9728 "Address Family modifier\n"
9729 "Address Family modifier\n"
9730 "Display routes matching the communities\n"
9731 "community number\n"
9732 "Do not send outside local AS (well-known community)\n"
9733 "Do not advertise to any peer (well-known community)\n"
9734 "Do not export to next AS (well-known community)\n"
9735 "community number\n"
9736 "Do not send outside local AS (well-known community)\n"
9737 "Do not advertise to any peer (well-known community)\n"
9738 "Do not export to next AS (well-known community)\n"
9739 "community number\n"
9740 "Do not send outside local AS (well-known community)\n"
9741 "Do not advertise to any peer (well-known community)\n"
9742 "Do not export to next AS (well-known community)\n"
9743 "community number\n"
9744 "Do not send outside local AS (well-known community)\n"
9745 "Do not advertise to any peer (well-known community)\n"
9746 "Do not export to next AS (well-known community)\n"
9747 "Exact match of the communities")
9748
Lou Bergerf9b6c392016-01-12 13:42:09 -05009749DEFUN (show_bgp_community,
9750 show_bgp_community_cmd,
9751 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
9752 SHOW_STR
9753 BGP_STR
9754 "Display routes matching the communities\n"
9755 "community number\n"
9756 "Do not send outside local AS (well-known community)\n"
9757 "Do not advertise to any peer (well-known community)\n"
9758 "Do not export to next AS (well-known community)\n")
9759{
9760 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9761}
9762
9763ALIAS (show_bgp_community,
9764 show_bgp_ipv6_community_cmd,
9765 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
9766 SHOW_STR
9767 BGP_STR
9768 "Address family\n"
9769 "Display routes matching the communities\n"
9770 "community number\n"
9771 "Do not send outside local AS (well-known community)\n"
9772 "Do not advertise to any peer (well-known community)\n"
9773 "Do not export to next AS (well-known community)\n")
9774
9775ALIAS (show_bgp_community,
9776 show_bgp_community2_cmd,
9777 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9778 SHOW_STR
9779 BGP_STR
9780 "Display routes matching the communities\n"
9781 "community number\n"
9782 "Do not send outside local AS (well-known community)\n"
9783 "Do not advertise to any peer (well-known community)\n"
9784 "Do not export to next AS (well-known community)\n"
9785 "community number\n"
9786 "Do not send outside local AS (well-known community)\n"
9787 "Do not advertise to any peer (well-known community)\n"
9788 "Do not export to next AS (well-known community)\n")
9789
9790ALIAS (show_bgp_community,
9791 show_bgp_ipv6_community2_cmd,
9792 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9793 SHOW_STR
9794 BGP_STR
9795 "Address family\n"
9796 "Display routes matching the communities\n"
9797 "community number\n"
9798 "Do not send outside local AS (well-known community)\n"
9799 "Do not advertise to any peer (well-known community)\n"
9800 "Do not export to next AS (well-known community)\n"
9801 "community number\n"
9802 "Do not send outside local AS (well-known community)\n"
9803 "Do not advertise to any peer (well-known community)\n"
9804 "Do not export to next AS (well-known community)\n")
9805
9806ALIAS (show_bgp_community,
9807 show_bgp_community3_cmd,
9808 "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)",
9809 SHOW_STR
9810 BGP_STR
9811 "Display routes matching the communities\n"
9812 "community number\n"
9813 "Do not send outside local AS (well-known community)\n"
9814 "Do not advertise to any peer (well-known community)\n"
9815 "Do not export to next AS (well-known community)\n"
9816 "community number\n"
9817 "Do not send outside local AS (well-known community)\n"
9818 "Do not advertise to any peer (well-known community)\n"
9819 "Do not export to next AS (well-known community)\n"
9820 "community number\n"
9821 "Do not send outside local AS (well-known community)\n"
9822 "Do not advertise to any peer (well-known community)\n"
9823 "Do not export to next AS (well-known community)\n")
9824
9825ALIAS (show_bgp_community,
9826 show_bgp_ipv6_community3_cmd,
9827 "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)",
9828 SHOW_STR
9829 BGP_STR
9830 "Address family\n"
9831 "Display routes matching the communities\n"
9832 "community number\n"
9833 "Do not send outside local AS (well-known community)\n"
9834 "Do not advertise to any peer (well-known community)\n"
9835 "Do not export to next AS (well-known community)\n"
9836 "community number\n"
9837 "Do not send outside local AS (well-known community)\n"
9838 "Do not advertise to any peer (well-known community)\n"
9839 "Do not export to next AS (well-known community)\n"
9840 "community number\n"
9841 "Do not send outside local AS (well-known community)\n"
9842 "Do not advertise to any peer (well-known community)\n"
9843 "Do not export to next AS (well-known community)\n")
9844
9845ALIAS (show_bgp_community,
9846 show_bgp_community4_cmd,
9847 "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)",
9848 SHOW_STR
9849 BGP_STR
9850 "Display routes matching the communities\n"
9851 "community number\n"
9852 "Do not send outside local AS (well-known community)\n"
9853 "Do not advertise to any peer (well-known community)\n"
9854 "Do not export to next AS (well-known community)\n"
9855 "community number\n"
9856 "Do not send outside local AS (well-known community)\n"
9857 "Do not advertise to any peer (well-known community)\n"
9858 "Do not export to next AS (well-known community)\n"
9859 "community number\n"
9860 "Do not send outside local AS (well-known community)\n"
9861 "Do not advertise to any peer (well-known community)\n"
9862 "Do not export to next AS (well-known community)\n"
9863 "community number\n"
9864 "Do not send outside local AS (well-known community)\n"
9865 "Do not advertise to any peer (well-known community)\n"
9866 "Do not export to next AS (well-known community)\n")
9867
9868ALIAS (show_bgp_community,
9869 show_bgp_ipv6_community4_cmd,
9870 "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)",
9871 SHOW_STR
9872 BGP_STR
9873 "Address family\n"
9874 "Display routes matching the communities\n"
9875 "community number\n"
9876 "Do not send outside local AS (well-known community)\n"
9877 "Do not advertise to any peer (well-known community)\n"
9878 "Do not export to next AS (well-known community)\n"
9879 "community number\n"
9880 "Do not send outside local AS (well-known community)\n"
9881 "Do not advertise to any peer (well-known community)\n"
9882 "Do not export to next AS (well-known community)\n"
9883 "community number\n"
9884 "Do not send outside local AS (well-known community)\n"
9885 "Do not advertise to any peer (well-known community)\n"
9886 "Do not export to next AS (well-known community)\n"
9887 "community number\n"
9888 "Do not send outside local AS (well-known community)\n"
9889 "Do not advertise to any peer (well-known community)\n"
9890 "Do not export to next AS (well-known community)\n")
9891
9892/* old command */
9893DEFUN (show_ipv6_bgp_community,
9894 show_ipv6_bgp_community_cmd,
9895 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
9896 SHOW_STR
9897 IPV6_STR
9898 BGP_STR
9899 "Display routes matching the communities\n"
9900 "community number\n"
9901 "Do not send outside local AS (well-known community)\n"
9902 "Do not advertise to any peer (well-known community)\n"
9903 "Do not export to next AS (well-known community)\n")
9904{
9905 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
9906}
9907
9908/* old command */
9909ALIAS (show_ipv6_bgp_community,
9910 show_ipv6_bgp_community2_cmd,
9911 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9912 SHOW_STR
9913 IPV6_STR
9914 BGP_STR
9915 "Display routes matching the communities\n"
9916 "community number\n"
9917 "Do not send outside local AS (well-known community)\n"
9918 "Do not advertise to any peer (well-known community)\n"
9919 "Do not export to next AS (well-known community)\n"
9920 "community number\n"
9921 "Do not send outside local AS (well-known community)\n"
9922 "Do not advertise to any peer (well-known community)\n"
9923 "Do not export to next AS (well-known community)\n")
9924
9925/* old command */
9926ALIAS (show_ipv6_bgp_community,
9927 show_ipv6_bgp_community3_cmd,
9928 "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)",
9929 SHOW_STR
9930 IPV6_STR
9931 BGP_STR
9932 "Display routes matching the communities\n"
9933 "community number\n"
9934 "Do not send outside local AS (well-known community)\n"
9935 "Do not advertise to any peer (well-known community)\n"
9936 "Do not export to next AS (well-known community)\n"
9937 "community number\n"
9938 "Do not send outside local AS (well-known community)\n"
9939 "Do not advertise to any peer (well-known community)\n"
9940 "Do not export to next AS (well-known community)\n"
9941 "community number\n"
9942 "Do not send outside local AS (well-known community)\n"
9943 "Do not advertise to any peer (well-known community)\n"
9944 "Do not export to next AS (well-known community)\n")
9945
9946/* old command */
9947ALIAS (show_ipv6_bgp_community,
9948 show_ipv6_bgp_community4_cmd,
9949 "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)",
9950 SHOW_STR
9951 IPV6_STR
9952 BGP_STR
9953 "Display routes matching the communities\n"
9954 "community number\n"
9955 "Do not send outside local AS (well-known community)\n"
9956 "Do not advertise to any peer (well-known community)\n"
9957 "Do not export to next AS (well-known community)\n"
9958 "community number\n"
9959 "Do not send outside local AS (well-known community)\n"
9960 "Do not advertise to any peer (well-known community)\n"
9961 "Do not export to next AS (well-known community)\n"
9962 "community number\n"
9963 "Do not send outside local AS (well-known community)\n"
9964 "Do not advertise to any peer (well-known community)\n"
9965 "Do not export to next AS (well-known community)\n"
9966 "community number\n"
9967 "Do not send outside local AS (well-known community)\n"
9968 "Do not advertise to any peer (well-known community)\n"
9969 "Do not export to next AS (well-known community)\n")
9970
9971DEFUN (show_bgp_community_exact,
9972 show_bgp_community_exact_cmd,
9973 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9974 SHOW_STR
9975 BGP_STR
9976 "Display routes matching the communities\n"
9977 "community number\n"
9978 "Do not send outside local AS (well-known community)\n"
9979 "Do not advertise to any peer (well-known community)\n"
9980 "Do not export to next AS (well-known community)\n"
9981 "Exact match of the communities")
9982{
9983 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
9984}
9985
9986ALIAS (show_bgp_community_exact,
9987 show_bgp_ipv6_community_exact_cmd,
9988 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9989 SHOW_STR
9990 BGP_STR
9991 "Address family\n"
9992 "Display routes matching the communities\n"
9993 "community number\n"
9994 "Do not send outside local AS (well-known community)\n"
9995 "Do not advertise to any peer (well-known community)\n"
9996 "Do not export to next AS (well-known community)\n"
9997 "Exact match of the communities")
9998
9999ALIAS (show_bgp_community_exact,
10000 show_bgp_community2_exact_cmd,
10001 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10002 SHOW_STR
10003 BGP_STR
10004 "Display routes matching the communities\n"
10005 "community number\n"
10006 "Do not send outside local AS (well-known community)\n"
10007 "Do not advertise to any peer (well-known community)\n"
10008 "Do not export to next AS (well-known community)\n"
10009 "community number\n"
10010 "Do not send outside local AS (well-known community)\n"
10011 "Do not advertise to any peer (well-known community)\n"
10012 "Do not export to next AS (well-known community)\n"
10013 "Exact match of the communities")
10014
10015ALIAS (show_bgp_community_exact,
10016 show_bgp_ipv6_community2_exact_cmd,
10017 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10018 SHOW_STR
10019 BGP_STR
10020 "Address family\n"
10021 "Display routes matching the communities\n"
10022 "community number\n"
10023 "Do not send outside local AS (well-known community)\n"
10024 "Do not advertise to any peer (well-known community)\n"
10025 "Do not export to next AS (well-known community)\n"
10026 "community number\n"
10027 "Do not send outside local AS (well-known community)\n"
10028 "Do not advertise to any peer (well-known community)\n"
10029 "Do not export to next AS (well-known community)\n"
10030 "Exact match of the communities")
10031
10032ALIAS (show_bgp_community_exact,
10033 show_bgp_community3_exact_cmd,
10034 "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",
10035 SHOW_STR
10036 BGP_STR
10037 "Display routes matching the communities\n"
10038 "community number\n"
10039 "Do not send outside local AS (well-known community)\n"
10040 "Do not advertise to any peer (well-known community)\n"
10041 "Do not export to next AS (well-known community)\n"
10042 "community number\n"
10043 "Do not send outside local AS (well-known community)\n"
10044 "Do not advertise to any peer (well-known community)\n"
10045 "Do not export to next AS (well-known community)\n"
10046 "community number\n"
10047 "Do not send outside local AS (well-known community)\n"
10048 "Do not advertise to any peer (well-known community)\n"
10049 "Do not export to next AS (well-known community)\n"
10050 "Exact match of the communities")
10051
10052ALIAS (show_bgp_community_exact,
10053 show_bgp_ipv6_community3_exact_cmd,
10054 "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",
10055 SHOW_STR
10056 BGP_STR
10057 "Address family\n"
10058 "Display routes matching the communities\n"
10059 "community number\n"
10060 "Do not send outside local AS (well-known community)\n"
10061 "Do not advertise to any peer (well-known community)\n"
10062 "Do not export to next AS (well-known community)\n"
10063 "community number\n"
10064 "Do not send outside local AS (well-known community)\n"
10065 "Do not advertise to any peer (well-known community)\n"
10066 "Do not export to next AS (well-known community)\n"
10067 "community number\n"
10068 "Do not send outside local AS (well-known community)\n"
10069 "Do not advertise to any peer (well-known community)\n"
10070 "Do not export to next AS (well-known community)\n"
10071 "Exact match of the communities")
10072
10073ALIAS (show_bgp_community_exact,
10074 show_bgp_community4_exact_cmd,
10075 "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",
10076 SHOW_STR
10077 BGP_STR
10078 "Display routes matching the communities\n"
10079 "community number\n"
10080 "Do not send outside local AS (well-known community)\n"
10081 "Do not advertise to any peer (well-known community)\n"
10082 "Do not export to next AS (well-known community)\n"
10083 "community number\n"
10084 "Do not send outside local AS (well-known community)\n"
10085 "Do not advertise to any peer (well-known community)\n"
10086 "Do not export to next AS (well-known community)\n"
10087 "community number\n"
10088 "Do not send outside local AS (well-known community)\n"
10089 "Do not advertise to any peer (well-known community)\n"
10090 "Do not export to next AS (well-known community)\n"
10091 "community number\n"
10092 "Do not send outside local AS (well-known community)\n"
10093 "Do not advertise to any peer (well-known community)\n"
10094 "Do not export to next AS (well-known community)\n"
10095 "Exact match of the communities")
10096
10097ALIAS (show_bgp_community_exact,
10098 show_bgp_ipv6_community4_exact_cmd,
10099 "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",
10100 SHOW_STR
10101 BGP_STR
10102 "Address family\n"
10103 "Display routes matching the communities\n"
10104 "community number\n"
10105 "Do not send outside local AS (well-known community)\n"
10106 "Do not advertise to any peer (well-known community)\n"
10107 "Do not export to next AS (well-known community)\n"
10108 "community number\n"
10109 "Do not send outside local AS (well-known community)\n"
10110 "Do not advertise to any peer (well-known community)\n"
10111 "Do not export to next AS (well-known community)\n"
10112 "community number\n"
10113 "Do not send outside local AS (well-known community)\n"
10114 "Do not advertise to any peer (well-known community)\n"
10115 "Do not export to next AS (well-known community)\n"
10116 "community number\n"
10117 "Do not send outside local AS (well-known community)\n"
10118 "Do not advertise to any peer (well-known community)\n"
10119 "Do not export to next AS (well-known community)\n"
10120 "Exact match of the communities")
10121
10122/* old command */
10123DEFUN (show_ipv6_bgp_community_exact,
10124 show_ipv6_bgp_community_exact_cmd,
10125 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10126 SHOW_STR
10127 IPV6_STR
10128 BGP_STR
10129 "Display routes matching the communities\n"
10130 "community number\n"
10131 "Do not send outside local AS (well-known community)\n"
10132 "Do not advertise to any peer (well-known community)\n"
10133 "Do not export to next AS (well-known community)\n"
10134 "Exact match of the communities")
10135{
10136 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
10137}
10138
10139/* old command */
10140ALIAS (show_ipv6_bgp_community_exact,
10141 show_ipv6_bgp_community2_exact_cmd,
10142 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10143 SHOW_STR
10144 IPV6_STR
10145 BGP_STR
10146 "Display routes matching the communities\n"
10147 "community number\n"
10148 "Do not send outside local AS (well-known community)\n"
10149 "Do not advertise to any peer (well-known community)\n"
10150 "Do not export to next AS (well-known community)\n"
10151 "community number\n"
10152 "Do not send outside local AS (well-known community)\n"
10153 "Do not advertise to any peer (well-known community)\n"
10154 "Do not export to next AS (well-known community)\n"
10155 "Exact match of the communities")
10156
10157/* old command */
10158ALIAS (show_ipv6_bgp_community_exact,
10159 show_ipv6_bgp_community3_exact_cmd,
10160 "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",
10161 SHOW_STR
10162 IPV6_STR
10163 BGP_STR
10164 "Display routes matching the communities\n"
10165 "community number\n"
10166 "Do not send outside local AS (well-known community)\n"
10167 "Do not advertise to any peer (well-known community)\n"
10168 "Do not export to next AS (well-known community)\n"
10169 "community number\n"
10170 "Do not send outside local AS (well-known community)\n"
10171 "Do not advertise to any peer (well-known community)\n"
10172 "Do not export to next AS (well-known community)\n"
10173 "community number\n"
10174 "Do not send outside local AS (well-known community)\n"
10175 "Do not advertise to any peer (well-known community)\n"
10176 "Do not export to next AS (well-known community)\n"
10177 "Exact match of the communities")
10178
10179/* old command */
10180ALIAS (show_ipv6_bgp_community_exact,
10181 show_ipv6_bgp_community4_exact_cmd,
10182 "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",
10183 SHOW_STR
10184 IPV6_STR
10185 BGP_STR
10186 "Display routes matching the communities\n"
10187 "community number\n"
10188 "Do not send outside local AS (well-known community)\n"
10189 "Do not advertise to any peer (well-known community)\n"
10190 "Do not export to next AS (well-known community)\n"
10191 "community number\n"
10192 "Do not send outside local AS (well-known community)\n"
10193 "Do not advertise to any peer (well-known community)\n"
10194 "Do not export to next AS (well-known community)\n"
10195 "community number\n"
10196 "Do not send outside local AS (well-known community)\n"
10197 "Do not advertise to any peer (well-known community)\n"
10198 "Do not export to next AS (well-known community)\n"
10199 "community number\n"
10200 "Do not send outside local AS (well-known community)\n"
10201 "Do not advertise to any peer (well-known community)\n"
10202 "Do not export to next AS (well-known community)\n"
10203 "Exact match of the communities")
10204
10205/* old command */
10206DEFUN (show_ipv6_mbgp_community,
10207 show_ipv6_mbgp_community_cmd,
10208 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
10209 SHOW_STR
10210 IPV6_STR
10211 MBGP_STR
10212 "Display routes matching the communities\n"
10213 "community number\n"
10214 "Do not send outside local AS (well-known community)\n"
10215 "Do not advertise to any peer (well-known community)\n"
10216 "Do not export to next AS (well-known community)\n")
10217{
10218 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
10219}
10220
10221/* old command */
10222ALIAS (show_ipv6_mbgp_community,
10223 show_ipv6_mbgp_community2_cmd,
10224 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
10225 SHOW_STR
10226 IPV6_STR
10227 MBGP_STR
10228 "Display routes matching the communities\n"
10229 "community number\n"
10230 "Do not send outside local AS (well-known community)\n"
10231 "Do not advertise to any peer (well-known community)\n"
10232 "Do not export to next AS (well-known community)\n"
10233 "community number\n"
10234 "Do not send outside local AS (well-known community)\n"
10235 "Do not advertise to any peer (well-known community)\n"
10236 "Do not export to next AS (well-known community)\n")
10237
10238/* old command */
10239ALIAS (show_ipv6_mbgp_community,
10240 show_ipv6_mbgp_community3_cmd,
10241 "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)",
10242 SHOW_STR
10243 IPV6_STR
10244 MBGP_STR
10245 "Display routes matching the communities\n"
10246 "community number\n"
10247 "Do not send outside local AS (well-known community)\n"
10248 "Do not advertise to any peer (well-known community)\n"
10249 "Do not export to next AS (well-known community)\n"
10250 "community number\n"
10251 "Do not send outside local AS (well-known community)\n"
10252 "Do not advertise to any peer (well-known community)\n"
10253 "Do not export to next AS (well-known community)\n"
10254 "community number\n"
10255 "Do not send outside local AS (well-known community)\n"
10256 "Do not advertise to any peer (well-known community)\n"
10257 "Do not export to next AS (well-known community)\n")
10258
10259/* old command */
10260ALIAS (show_ipv6_mbgp_community,
10261 show_ipv6_mbgp_community4_cmd,
10262 "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)",
10263 SHOW_STR
10264 IPV6_STR
10265 MBGP_STR
10266 "Display routes matching the communities\n"
10267 "community number\n"
10268 "Do not send outside local AS (well-known community)\n"
10269 "Do not advertise to any peer (well-known community)\n"
10270 "Do not export to next AS (well-known community)\n"
10271 "community number\n"
10272 "Do not send outside local AS (well-known community)\n"
10273 "Do not advertise to any peer (well-known community)\n"
10274 "Do not export to next AS (well-known community)\n"
10275 "community number\n"
10276 "Do not send outside local AS (well-known community)\n"
10277 "Do not advertise to any peer (well-known community)\n"
10278 "Do not export to next AS (well-known community)\n"
10279 "community number\n"
10280 "Do not send outside local AS (well-known community)\n"
10281 "Do not advertise to any peer (well-known community)\n"
10282 "Do not export to next AS (well-known community)\n")
10283
10284/* old command */
10285DEFUN (show_ipv6_mbgp_community_exact,
10286 show_ipv6_mbgp_community_exact_cmd,
10287 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
10288 SHOW_STR
10289 IPV6_STR
10290 MBGP_STR
10291 "Display routes matching the communities\n"
10292 "community number\n"
10293 "Do not send outside local AS (well-known community)\n"
10294 "Do not advertise to any peer (well-known community)\n"
10295 "Do not export to next AS (well-known community)\n"
10296 "Exact match of the communities")
10297{
10298 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
10299}
10300
10301/* old command */
10302ALIAS (show_ipv6_mbgp_community_exact,
10303 show_ipv6_mbgp_community2_exact_cmd,
10304 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
10305 SHOW_STR
10306 IPV6_STR
10307 MBGP_STR
10308 "Display routes matching the communities\n"
10309 "community number\n"
10310 "Do not send outside local AS (well-known community)\n"
10311 "Do not advertise to any peer (well-known community)\n"
10312 "Do not export to next AS (well-known community)\n"
10313 "community number\n"
10314 "Do not send outside local AS (well-known community)\n"
10315 "Do not advertise to any peer (well-known community)\n"
10316 "Do not export to next AS (well-known community)\n"
10317 "Exact match of the communities")
10318
10319/* old command */
10320ALIAS (show_ipv6_mbgp_community_exact,
10321 show_ipv6_mbgp_community3_exact_cmd,
10322 "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",
10323 SHOW_STR
10324 IPV6_STR
10325 MBGP_STR
10326 "Display routes matching the communities\n"
10327 "community number\n"
10328 "Do not send outside local AS (well-known community)\n"
10329 "Do not advertise to any peer (well-known community)\n"
10330 "Do not export to next AS (well-known community)\n"
10331 "community number\n"
10332 "Do not send outside local AS (well-known community)\n"
10333 "Do not advertise to any peer (well-known community)\n"
10334 "Do not export to next AS (well-known community)\n"
10335 "community number\n"
10336 "Do not send outside local AS (well-known community)\n"
10337 "Do not advertise to any peer (well-known community)\n"
10338 "Do not export to next AS (well-known community)\n"
10339 "Exact match of the communities")
10340
10341/* old command */
10342ALIAS (show_ipv6_mbgp_community_exact,
10343 show_ipv6_mbgp_community4_exact_cmd,
10344 "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",
10345 SHOW_STR
10346 IPV6_STR
10347 MBGP_STR
10348 "Display routes matching the communities\n"
10349 "community number\n"
10350 "Do not send outside local AS (well-known community)\n"
10351 "Do not advertise to any peer (well-known community)\n"
10352 "Do not export to next AS (well-known community)\n"
10353 "community number\n"
10354 "Do not send outside local AS (well-known community)\n"
10355 "Do not advertise to any peer (well-known community)\n"
10356 "Do not export to next AS (well-known community)\n"
10357 "community number\n"
10358 "Do not send outside local AS (well-known community)\n"
10359 "Do not advertise to any peer (well-known community)\n"
10360 "Do not export to next AS (well-known community)\n"
10361 "community number\n"
10362 "Do not send outside local AS (well-known community)\n"
10363 "Do not advertise to any peer (well-known community)\n"
10364 "Do not export to next AS (well-known community)\n"
10365 "Exact match of the communities")
Lou Bergerf9b6c392016-01-12 13:42:09 -050010366
Lou Berger651b4022016-01-12 13:42:07 -050010367DEFUN (show_bgp_ipv4_community,
10368 show_bgp_ipv4_community_cmd,
10369 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010370 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010371 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010372 IP_STR
paul718e3742002-12-13 20:15:29 +000010373 "Display routes matching the communities\n"
10374 "community number\n"
10375 "Do not send outside local AS (well-known community)\n"
10376 "Do not advertise to any peer (well-known community)\n"
10377 "Do not export to next AS (well-known community)\n")
10378{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010379 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010380}
10381
Lou Berger651b4022016-01-12 13:42:07 -050010382ALIAS (show_bgp_ipv4_community,
10383 show_bgp_ipv4_community2_cmd,
10384 "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 +000010385 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010386 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010387 IP_STR
paul718e3742002-12-13 20:15:29 +000010388 "Display routes matching the communities\n"
10389 "community number\n"
10390 "Do not send outside local AS (well-known community)\n"
10391 "Do not advertise to any peer (well-known community)\n"
10392 "Do not export to next AS (well-known community)\n"
10393 "community number\n"
10394 "Do not send outside local AS (well-known community)\n"
10395 "Do not advertise to any peer (well-known community)\n"
10396 "Do not export to next AS (well-known community)\n")
10397
Lou Berger651b4022016-01-12 13:42:07 -050010398ALIAS (show_bgp_ipv4_community,
10399 show_bgp_ipv4_community3_cmd,
10400 "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 +000010401 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010402 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010403 IP_STR
paul718e3742002-12-13 20:15:29 +000010404 "Display routes matching the communities\n"
10405 "community number\n"
10406 "Do not send outside local AS (well-known community)\n"
10407 "Do not advertise to any peer (well-known community)\n"
10408 "Do not export to next AS (well-known community)\n"
10409 "community number\n"
10410 "Do not send outside local AS (well-known community)\n"
10411 "Do not advertise to any peer (well-known community)\n"
10412 "Do not export to next AS (well-known community)\n"
10413 "community number\n"
10414 "Do not send outside local AS (well-known community)\n"
10415 "Do not advertise to any peer (well-known community)\n"
10416 "Do not export to next AS (well-known community)\n")
10417
Lou Berger651b4022016-01-12 13:42:07 -050010418ALIAS (show_bgp_ipv4_community,
10419 show_bgp_ipv4_community4_cmd,
10420 "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 +000010421 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010422 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010423 IP_STR
paul718e3742002-12-13 20:15:29 +000010424 "Display routes matching the communities\n"
10425 "community number\n"
10426 "Do not send outside local AS (well-known community)\n"
10427 "Do not advertise to any peer (well-known community)\n"
10428 "Do not export to next AS (well-known community)\n"
10429 "community number\n"
10430 "Do not send outside local AS (well-known community)\n"
10431 "Do not advertise to any peer (well-known community)\n"
10432 "Do not export to next AS (well-known community)\n"
10433 "community number\n"
10434 "Do not send outside local AS (well-known community)\n"
10435 "Do not advertise to any peer (well-known community)\n"
10436 "Do not export to next AS (well-known community)\n"
10437 "community number\n"
10438 "Do not send outside local AS (well-known community)\n"
10439 "Do not advertise to any peer (well-known community)\n"
10440 "Do not export to next AS (well-known community)\n")
10441
Lou Berger651b4022016-01-12 13:42:07 -050010442DEFUN (show_bgp_ipv4_safi_community,
10443 show_bgp_ipv4_safi_community_cmd,
10444 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010445 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010446 BGP_STR
10447 "Address family\n"
10448 "Address Family modifier\n"
10449 "Address Family modifier\n"
10450 "Display routes matching the communities\n"
10451 "community number\n"
10452 "Do not send outside local AS (well-known community)\n"
10453 "Do not advertise to any peer (well-known community)\n"
10454 "Do not export to next AS (well-known community)\n")
10455{
10456 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010457 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010458
Michael Lambert95cbbd22010-07-23 14:43:04 -040010459 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010460}
10461
Lou Berger651b4022016-01-12 13:42:07 -050010462ALIAS (show_bgp_ipv4_safi_community,
10463 show_bgp_ipv4_safi_community2_cmd,
10464 "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 +000010465 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010466 BGP_STR
10467 "Address family\n"
10468 "Address Family modifier\n"
10469 "Address Family modifier\n"
10470 "Display routes matching the communities\n"
10471 "community number\n"
10472 "Do not send outside local AS (well-known community)\n"
10473 "Do not advertise to any peer (well-known community)\n"
10474 "Do not export to next AS (well-known community)\n"
10475 "community number\n"
10476 "Do not send outside local AS (well-known community)\n"
10477 "Do not advertise to any peer (well-known community)\n"
10478 "Do not export to next AS (well-known community)\n")
10479
Lou Berger651b4022016-01-12 13:42:07 -050010480ALIAS (show_bgp_ipv4_safi_community,
10481 show_bgp_ipv4_safi_community3_cmd,
10482 "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 +000010483 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010484 BGP_STR
10485 "Address family\n"
10486 "Address Family modifier\n"
10487 "Address Family modifier\n"
10488 "Display routes matching the communities\n"
10489 "community number\n"
10490 "Do not send outside local AS (well-known community)\n"
10491 "Do not advertise to any peer (well-known community)\n"
10492 "Do not export to next AS (well-known community)\n"
10493 "community number\n"
10494 "Do not send outside local AS (well-known community)\n"
10495 "Do not advertise to any peer (well-known community)\n"
10496 "Do not export to next AS (well-known community)\n"
10497 "community number\n"
10498 "Do not send outside local AS (well-known community)\n"
10499 "Do not advertise to any peer (well-known community)\n"
10500 "Do not export to next AS (well-known community)\n")
10501
Lou Berger651b4022016-01-12 13:42:07 -050010502ALIAS (show_bgp_ipv4_safi_community,
10503 show_bgp_ipv4_safi_community4_cmd,
10504 "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 +000010505 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010506 BGP_STR
10507 "Address family\n"
10508 "Address Family modifier\n"
10509 "Address Family modifier\n"
10510 "Display routes matching the communities\n"
10511 "community number\n"
10512 "Do not send outside local AS (well-known community)\n"
10513 "Do not advertise to any peer (well-known community)\n"
10514 "Do not export to next AS (well-known community)\n"
10515 "community number\n"
10516 "Do not send outside local AS (well-known community)\n"
10517 "Do not advertise to any peer (well-known community)\n"
10518 "Do not export to next AS (well-known community)\n"
10519 "community number\n"
10520 "Do not send outside local AS (well-known community)\n"
10521 "Do not advertise to any peer (well-known community)\n"
10522 "Do not export to next AS (well-known community)\n"
10523 "community number\n"
10524 "Do not send outside local AS (well-known community)\n"
10525 "Do not advertise to any peer (well-known community)\n"
10526 "Do not export to next AS (well-known community)\n")
10527
Michael Lambert95cbbd22010-07-23 14:43:04 -040010528DEFUN (show_bgp_view_afi_safi_community_all,
10529 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010530 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010531 SHOW_STR
10532 BGP_STR
10533 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010534 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010535 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010536 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010537 "Address Family modifier\n"
10538 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +000010539 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -040010540{
10541 int afi;
10542 int safi;
10543 struct bgp *bgp;
10544
10545 /* BGP structure lookup. */
10546 bgp = bgp_lookup_by_name (argv[0]);
10547 if (bgp == NULL)
10548 {
10549 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10550 return CMD_WARNING;
10551 }
10552
Michael Lambert95cbbd22010-07-23 14:43:04 -040010553 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10554 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010555 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
10556}
10557
10558DEFUN (show_bgp_view_afi_safi_community,
10559 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010560 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -040010561 SHOW_STR
10562 BGP_STR
10563 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010564 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010565 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010566 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010567 "Address family modifier\n"
10568 "Address family modifier\n"
10569 "Display routes matching the communities\n"
10570 "community number\n"
10571 "Do not send outside local AS (well-known community)\n"
10572 "Do not advertise to any peer (well-known community)\n"
10573 "Do not export to next AS (well-known community)\n")
10574{
10575 int afi;
10576 int safi;
10577
Michael Lambert95cbbd22010-07-23 14:43:04 -040010578 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10579 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10580 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010581}
10582
10583ALIAS (show_bgp_view_afi_safi_community,
10584 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010585 "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 -040010586 SHOW_STR
10587 BGP_STR
10588 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010589 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010590 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010591 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010592 "Address family modifier\n"
10593 "Address family modifier\n"
10594 "Display routes matching the communities\n"
10595 "community number\n"
10596 "Do not send outside local AS (well-known community)\n"
10597 "Do not advertise to any peer (well-known community)\n"
10598 "Do not export to next AS (well-known community)\n"
10599 "community number\n"
10600 "Do not send outside local AS (well-known community)\n"
10601 "Do not advertise to any peer (well-known community)\n"
10602 "Do not export to next AS (well-known community)\n")
10603
10604ALIAS (show_bgp_view_afi_safi_community,
10605 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010606 "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 -040010607 SHOW_STR
10608 BGP_STR
10609 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010610 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010611 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010612 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010613 "Address family modifier\n"
10614 "Address family modifier\n"
10615 "Display routes matching the communities\n"
10616 "community number\n"
10617 "Do not send outside local AS (well-known community)\n"
10618 "Do not advertise to any peer (well-known community)\n"
10619 "Do not export to next AS (well-known community)\n"
10620 "community number\n"
10621 "Do not send outside local AS (well-known community)\n"
10622 "Do not advertise to any peer (well-known community)\n"
10623 "Do not export to next AS (well-known community)\n"
10624 "community number\n"
10625 "Do not send outside local AS (well-known community)\n"
10626 "Do not advertise to any peer (well-known community)\n"
10627 "Do not export to next AS (well-known community)\n")
10628
10629ALIAS (show_bgp_view_afi_safi_community,
10630 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010631 "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 -040010632 SHOW_STR
10633 BGP_STR
10634 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010635 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010636 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010637 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010638 "Address family modifier\n"
10639 "Address family modifier\n"
10640 "Display routes matching the communities\n"
10641 "community number\n"
10642 "Do not send outside local AS (well-known community)\n"
10643 "Do not advertise to any peer (well-known community)\n"
10644 "Do not export to next AS (well-known community)\n"
10645 "community number\n"
10646 "Do not send outside local AS (well-known community)\n"
10647 "Do not advertise to any peer (well-known community)\n"
10648 "Do not export to next AS (well-known community)\n"
10649 "community number\n"
10650 "Do not send outside local AS (well-known community)\n"
10651 "Do not advertise to any peer (well-known community)\n"
10652 "Do not export to next AS (well-known community)\n"
10653 "community number\n"
10654 "Do not send outside local AS (well-known community)\n"
10655 "Do not advertise to any peer (well-known community)\n"
10656 "Do not export to next AS (well-known community)\n")
10657
Lou Berger651b4022016-01-12 13:42:07 -050010658DEFUN (show_bgp_ipv4_community_exact,
10659 show_bgp_ipv4_community_exact_cmd,
10660 "show bgp ipv4 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010661 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010662 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010663 IP_STR
paul718e3742002-12-13 20:15:29 +000010664 "Display routes matching the communities\n"
10665 "community number\n"
10666 "Do not send outside local AS (well-known community)\n"
10667 "Do not advertise to any peer (well-known community)\n"
10668 "Do not export to next AS (well-known community)\n"
10669 "Exact match of the communities")
10670{
Michael Lambert95cbbd22010-07-23 14:43:04 -040010671 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010672}
10673
Lou Berger651b4022016-01-12 13:42:07 -050010674ALIAS (show_bgp_ipv4_community_exact,
10675 show_bgp_ipv4_community2_exact_cmd,
10676 "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 +000010677 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010678 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010679 IP_STR
paul718e3742002-12-13 20:15:29 +000010680 "Display routes matching the communities\n"
10681 "community number\n"
10682 "Do not send outside local AS (well-known community)\n"
10683 "Do not advertise to any peer (well-known community)\n"
10684 "Do not export to next AS (well-known community)\n"
10685 "community number\n"
10686 "Do not send outside local AS (well-known community)\n"
10687 "Do not advertise to any peer (well-known community)\n"
10688 "Do not export to next AS (well-known community)\n"
10689 "Exact match of the communities")
10690
Lou Berger651b4022016-01-12 13:42:07 -050010691ALIAS (show_bgp_ipv4_community_exact,
10692 show_bgp_ipv4_community3_exact_cmd,
10693 "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 +000010694 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010695 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010696 IP_STR
paul718e3742002-12-13 20:15:29 +000010697 "Display routes matching the communities\n"
10698 "community number\n"
10699 "Do not send outside local AS (well-known community)\n"
10700 "Do not advertise to any peer (well-known community)\n"
10701 "Do not export to next AS (well-known community)\n"
10702 "community number\n"
10703 "Do not send outside local AS (well-known community)\n"
10704 "Do not advertise to any peer (well-known community)\n"
10705 "Do not export to next AS (well-known community)\n"
10706 "community number\n"
10707 "Do not send outside local AS (well-known community)\n"
10708 "Do not advertise to any peer (well-known community)\n"
10709 "Do not export to next AS (well-known community)\n"
10710 "Exact match of the communities")
10711
Lou Berger651b4022016-01-12 13:42:07 -050010712ALIAS (show_bgp_ipv4_community_exact,
10713 show_bgp_ipv4_community4_exact_cmd,
10714 "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 +000010715 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010716 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010717 IP_STR
paul718e3742002-12-13 20:15:29 +000010718 "Display routes matching the communities\n"
10719 "community number\n"
10720 "Do not send outside local AS (well-known community)\n"
10721 "Do not advertise to any peer (well-known community)\n"
10722 "Do not export to next AS (well-known community)\n"
10723 "community number\n"
10724 "Do not send outside local AS (well-known community)\n"
10725 "Do not advertise to any peer (well-known community)\n"
10726 "Do not export to next AS (well-known community)\n"
10727 "community number\n"
10728 "Do not send outside local AS (well-known community)\n"
10729 "Do not advertise to any peer (well-known community)\n"
10730 "Do not export to next AS (well-known community)\n"
10731 "community number\n"
10732 "Do not send outside local AS (well-known community)\n"
10733 "Do not advertise to any peer (well-known community)\n"
10734 "Do not export to next AS (well-known community)\n"
10735 "Exact match of the communities")
10736
Lou Berger651b4022016-01-12 13:42:07 -050010737DEFUN (show_bgp_ipv4_safi_community4_exact,
10738 show_bgp_ipv4_safi_community_exact_cmd,
10739 "show bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010740 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010741 BGP_STR
10742 "Address family\n"
10743 "Address Family modifier\n"
10744 "Address Family modifier\n"
10745 "Display routes matching the communities\n"
10746 "community number\n"
10747 "Do not send outside local AS (well-known community)\n"
10748 "Do not advertise to any peer (well-known community)\n"
10749 "Do not export to next AS (well-known community)\n"
10750 "Exact match of the communities")
10751{
10752 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -040010753 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +000010754
Michael Lambert95cbbd22010-07-23 14:43:04 -040010755 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000010756}
10757
Lou Berger651b4022016-01-12 13:42:07 -050010758ALIAS (show_bgp_ipv4_safi_community4_exact,
10759 show_bgp_ipv4_safi_community2_exact_cmd,
10760 "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 +000010761 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010762 BGP_STR
10763 "Address family\n"
10764 "Address Family modifier\n"
10765 "Address Family modifier\n"
10766 "Display routes matching the communities\n"
10767 "community number\n"
10768 "Do not send outside local AS (well-known community)\n"
10769 "Do not advertise to any peer (well-known community)\n"
10770 "Do not export to next AS (well-known community)\n"
10771 "community number\n"
10772 "Do not send outside local AS (well-known community)\n"
10773 "Do not advertise to any peer (well-known community)\n"
10774 "Do not export to next AS (well-known community)\n"
10775 "Exact match of the communities")
10776
Lou Berger651b4022016-01-12 13:42:07 -050010777ALIAS (show_bgp_ipv4_safi_community4_exact,
10778 show_bgp_ipv4_safi_community3_exact_cmd,
10779 "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 +000010780 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010781 BGP_STR
10782 "Address family\n"
10783 "Address Family modifier\n"
10784 "Address Family modifier\n"
10785 "Display routes matching the communities\n"
10786 "community number\n"
10787 "Do not send outside local AS (well-known community)\n"
10788 "Do not advertise to any peer (well-known community)\n"
10789 "Do not export to next AS (well-known community)\n"
10790 "community number\n"
10791 "Do not send outside local AS (well-known community)\n"
10792 "Do not advertise to any peer (well-known community)\n"
10793 "Do not export to next AS (well-known community)\n"
10794 "community number\n"
10795 "Do not send outside local AS (well-known community)\n"
10796 "Do not advertise to any peer (well-known community)\n"
10797 "Do not export to next AS (well-known community)\n"
10798 "Exact match of the communities")
10799
Lou Berger651b4022016-01-12 13:42:07 -050010800ALIAS (show_bgp_ipv4_safi_community4_exact,
10801 show_bgp_ipv4_safi_community4_exact_cmd,
10802 "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 +000010803 SHOW_STR
paul718e3742002-12-13 20:15:29 +000010804 BGP_STR
10805 "Address family\n"
10806 "Address Family modifier\n"
10807 "Address Family modifier\n"
10808 "Display routes matching the communities\n"
10809 "community number\n"
10810 "Do not send outside local AS (well-known community)\n"
10811 "Do not advertise to any peer (well-known community)\n"
10812 "Do not export to next AS (well-known community)\n"
10813 "community number\n"
10814 "Do not send outside local AS (well-known community)\n"
10815 "Do not advertise to any peer (well-known community)\n"
10816 "Do not export to next AS (well-known community)\n"
10817 "community number\n"
10818 "Do not send outside local AS (well-known community)\n"
10819 "Do not advertise to any peer (well-known community)\n"
10820 "Do not export to next AS (well-known community)\n"
10821 "community number\n"
10822 "Do not send outside local AS (well-known community)\n"
10823 "Do not advertise to any peer (well-known community)\n"
10824 "Do not export to next AS (well-known community)\n"
10825 "Exact match of the communities")
10826
Lou Bergerf9b6c392016-01-12 13:42:09 -050010827DEFUN (show_bgp_ipv6_safi_community,
10828 show_bgp_ipv6_safi_community_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010829 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export)",
paul718e3742002-12-13 20:15:29 +000010830 SHOW_STR
10831 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010832 "Address family\n"
10833 "Address family modifier\n"
10834 "Address family modifier\n"
10835 "Address family modifier\n"
10836 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010837 "Display routes matching the communities\n"
10838 "community number\n"
10839 "Do not send outside local AS (well-known community)\n"
10840 "Do not advertise to any peer (well-known community)\n"
10841 "Do not export to next AS (well-known community)\n")
10842{
Lou Berger651b4022016-01-12 13:42:07 -050010843 safi_t safi;
10844
10845 if (bgp_parse_safi(argv[0], &safi)) {
10846 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10847 return CMD_WARNING;
10848 }
10849 return bgp_show_community (vty, NULL, argc-1, argv+1, 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010850}
10851
Lou Bergerf9b6c392016-01-12 13:42:09 -050010852ALIAS (show_bgp_ipv6_safi_community,
10853 show_bgp_ipv6_safi_community2_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010854 "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 +000010855 SHOW_STR
10856 BGP_STR
10857 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010858 "Address family modifier\n"
10859 "Address family modifier\n"
10860 "Address family modifier\n"
10861 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010862 "Display routes matching the communities\n"
10863 "community number\n"
10864 "Do not send outside local AS (well-known community)\n"
10865 "Do not advertise to any peer (well-known community)\n"
10866 "Do not export to next AS (well-known community)\n"
10867 "community number\n"
10868 "Do not send outside local AS (well-known community)\n"
10869 "Do not advertise to any peer (well-known community)\n"
10870 "Do not export to next AS (well-known community)\n")
10871
Lou Bergerf9b6c392016-01-12 13:42:09 -050010872ALIAS (show_bgp_ipv6_safi_community,
10873 show_bgp_ipv6_safi_community3_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010874 "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 +000010875 SHOW_STR
10876 BGP_STR
10877 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010878 "Address family modifier\n"
10879 "Address family modifier\n"
10880 "Address family modifier\n"
10881 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010882 "Display routes matching the communities\n"
10883 "community number\n"
10884 "Do not send outside local AS (well-known community)\n"
10885 "Do not advertise to any peer (well-known community)\n"
10886 "Do not export to next AS (well-known community)\n"
10887 "community number\n"
10888 "Do not send outside local AS (well-known community)\n"
10889 "Do not advertise to any peer (well-known community)\n"
10890 "Do not export to next AS (well-known community)\n"
10891 "community number\n"
10892 "Do not send outside local AS (well-known community)\n"
10893 "Do not advertise to any peer (well-known community)\n"
10894 "Do not export to next AS (well-known community)\n")
10895
Lou Bergerf9b6c392016-01-12 13:42:09 -050010896ALIAS (show_bgp_ipv6_safi_community,
10897 show_bgp_ipv6_safi_community4_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010898 "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 +000010899 SHOW_STR
10900 BGP_STR
10901 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010902 "Address family modifier\n"
10903 "Address family modifier\n"
10904 "Address family modifier\n"
10905 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010906 "Display routes matching the communities\n"
10907 "community number\n"
10908 "Do not send outside local AS (well-known community)\n"
10909 "Do not advertise to any peer (well-known community)\n"
10910 "Do not export to next AS (well-known community)\n"
10911 "community number\n"
10912 "Do not send outside local AS (well-known community)\n"
10913 "Do not advertise to any peer (well-known community)\n"
10914 "Do not export to next AS (well-known community)\n"
10915 "community number\n"
10916 "Do not send outside local AS (well-known community)\n"
10917 "Do not advertise to any peer (well-known community)\n"
10918 "Do not export to next AS (well-known community)\n"
10919 "community number\n"
10920 "Do not send outside local AS (well-known community)\n"
10921 "Do not advertise to any peer (well-known community)\n"
10922 "Do not export to next AS (well-known community)\n")
10923
paul718e3742002-12-13 20:15:29 +000010924
Lou Bergerf9b6c392016-01-12 13:42:09 -050010925DEFUN (show_bgp_ipv6_safi_community_exact,
10926 show_bgp_ipv6_safi_community_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010927 "show bgp ipv6 (encap|multicast|unicast|vpn) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
paul718e3742002-12-13 20:15:29 +000010928 SHOW_STR
10929 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050010930 "Address family\n"
10931 "Address family modifier\n"
10932 "Address family modifier\n"
10933 "Address family modifier\n"
10934 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010935 "Display routes matching the communities\n"
10936 "community number\n"
10937 "Do not send outside local AS (well-known community)\n"
10938 "Do not advertise to any peer (well-known community)\n"
10939 "Do not export to next AS (well-known community)\n"
10940 "Exact match of the communities")
10941{
Lou Berger651b4022016-01-12 13:42:07 -050010942 safi_t safi;
10943
10944 if (bgp_parse_safi(argv[0], &safi)) {
10945 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
10946 return CMD_WARNING;
10947 }
10948 return bgp_show_community (vty, NULL, argc-1, argv+1, 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000010949}
10950
paul718e3742002-12-13 20:15:29 +000010951
10952ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010953 show_bgp_ipv6_safi_community2_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010954 "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 +000010955 SHOW_STR
10956 BGP_STR
10957 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010958 "Address family modifier\n"
10959 "Address family modifier\n"
10960 "Address family modifier\n"
10961 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010962 "Display routes matching the communities\n"
10963 "community number\n"
10964 "Do not send outside local AS (well-known community)\n"
10965 "Do not advertise to any peer (well-known community)\n"
10966 "Do not export to next AS (well-known community)\n"
10967 "community number\n"
10968 "Do not send outside local AS (well-known community)\n"
10969 "Do not advertise to any peer (well-known community)\n"
10970 "Do not export to next AS (well-known community)\n"
10971 "Exact match of the communities")
10972
10973ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010974 show_bgp_ipv6_safi_community3_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050010975 "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 +000010976 SHOW_STR
10977 BGP_STR
10978 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050010979 "Address family modifier\n"
10980 "Address family modifier\n"
10981 "Address family modifier\n"
10982 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000010983 "Display routes matching the communities\n"
10984 "community number\n"
10985 "Do not send outside local AS (well-known community)\n"
10986 "Do not advertise to any peer (well-known community)\n"
10987 "Do not export to next AS (well-known community)\n"
10988 "community number\n"
10989 "Do not send outside local AS (well-known community)\n"
10990 "Do not advertise to any peer (well-known community)\n"
10991 "Do not export to next AS (well-known community)\n"
10992 "community number\n"
10993 "Do not send outside local AS (well-known community)\n"
10994 "Do not advertise to any peer (well-known community)\n"
10995 "Do not export to next AS (well-known community)\n"
10996 "Exact match of the communities")
10997
10998ALIAS (show_bgp_community_exact,
Lou Bergerf9b6c392016-01-12 13:42:09 -050010999 show_bgp_ipv6_safi_community4_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011000 "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 +000011001 SHOW_STR
11002 BGP_STR
11003 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011004 "Address family modifier\n"
11005 "Address family modifier\n"
11006 "Address family modifier\n"
11007 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011008 "Display routes matching the communities\n"
11009 "community number\n"
11010 "Do not send outside local AS (well-known community)\n"
11011 "Do not advertise to any peer (well-known community)\n"
11012 "Do not export to next AS (well-known community)\n"
11013 "community number\n"
11014 "Do not send outside local AS (well-known community)\n"
11015 "Do not advertise to any peer (well-known community)\n"
11016 "Do not export to next AS (well-known community)\n"
11017 "community number\n"
11018 "Do not send outside local AS (well-known community)\n"
11019 "Do not advertise to any peer (well-known community)\n"
11020 "Do not export to next AS (well-known community)\n"
11021 "community number\n"
11022 "Do not send outside local AS (well-known community)\n"
11023 "Do not advertise to any peer (well-known community)\n"
11024 "Do not export to next AS (well-known community)\n"
11025 "Exact match of the communities")
11026
paul94f2b392005-06-28 12:44:16 +000011027static int
paulfd79ac92004-10-13 05:06:08 +000011028bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -040011029 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +000011030{
11031 struct community_list *list;
11032
hassofee6e4e2005-02-02 16:29:31 +000011033 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +000011034 if (list == NULL)
11035 {
11036 vty_out (vty, "%% %s is not a valid community-list name%s", com,
11037 VTY_NEWLINE);
11038 return CMD_WARNING;
11039 }
11040
ajs5a646652004-11-05 01:25:55 +000011041 return bgp_show (vty, NULL, afi, safi,
11042 (exact ? bgp_show_type_community_list_exact :
11043 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +000011044}
11045
Lou Bergerf9b6c392016-01-12 13:42:09 -050011046DEFUN (show_ip_bgp_community_list,
11047 show_ip_bgp_community_list_cmd,
11048 "show ip bgp community-list (<1-500>|WORD)",
11049 SHOW_STR
11050 IP_STR
11051 BGP_STR
11052 "Display routes matching the community-list\n"
11053 "community-list number\n"
11054 "community-list name\n")
11055{
11056 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11057}
11058
11059DEFUN (show_ip_bgp_ipv4_community_list,
11060 show_ip_bgp_ipv4_community_list_cmd,
11061 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
11062 SHOW_STR
11063 IP_STR
11064 BGP_STR
11065 "Address family\n"
11066 "Address Family modifier\n"
11067 "Address Family modifier\n"
11068 "Display routes matching the community-list\n"
11069 "community-list number\n"
11070 "community-list name\n")
11071{
11072 if (strncmp (argv[0], "m", 1) == 0)
11073 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11074
11075 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11076}
11077
11078DEFUN (show_ip_bgp_community_list_exact,
11079 show_ip_bgp_community_list_exact_cmd,
11080 "show ip bgp community-list (<1-500>|WORD) exact-match",
11081 SHOW_STR
11082 IP_STR
11083 BGP_STR
11084 "Display routes matching the community-list\n"
11085 "community-list number\n"
11086 "community-list name\n"
11087 "Exact match of the communities\n")
11088{
11089 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11090}
11091
11092DEFUN (show_ip_bgp_ipv4_community_list_exact,
11093 show_ip_bgp_ipv4_community_list_exact_cmd,
11094 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
11095 SHOW_STR
11096 IP_STR
11097 BGP_STR
11098 "Address family\n"
11099 "Address Family modifier\n"
11100 "Address Family modifier\n"
11101 "Display routes matching the community-list\n"
11102 "community-list number\n"
11103 "community-list name\n"
11104 "Exact match of the communities\n")
11105{
11106 if (strncmp (argv[0], "m", 1) == 0)
11107 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11108
11109 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11110}
11111
Lou Bergerf9b6c392016-01-12 13:42:09 -050011112DEFUN (show_bgp_community_list,
11113 show_bgp_community_list_cmd,
11114 "show bgp community-list (<1-500>|WORD)",
11115 SHOW_STR
11116 BGP_STR
11117 "Display routes matching the community-list\n"
11118 "community-list number\n"
11119 "community-list name\n")
11120{
11121 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11122}
11123
11124ALIAS (show_bgp_community_list,
11125 show_bgp_ipv6_community_list_cmd,
11126 "show bgp ipv6 community-list (<1-500>|WORD)",
11127 SHOW_STR
11128 BGP_STR
11129 "Address family\n"
11130 "Display routes matching the community-list\n"
11131 "community-list number\n"
11132 "community-list name\n")
11133
11134/* old command */
11135DEFUN (show_ipv6_bgp_community_list,
11136 show_ipv6_bgp_community_list_cmd,
11137 "show ipv6 bgp community-list WORD",
11138 SHOW_STR
11139 IPV6_STR
11140 BGP_STR
11141 "Display routes matching the community-list\n"
11142 "community-list name\n")
11143{
11144 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
11145}
11146
11147/* old command */
11148DEFUN (show_ipv6_mbgp_community_list,
11149 show_ipv6_mbgp_community_list_cmd,
11150 "show ipv6 mbgp community-list WORD",
11151 SHOW_STR
11152 IPV6_STR
11153 MBGP_STR
11154 "Display routes matching the community-list\n"
11155 "community-list name\n")
11156{
11157 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
11158}
11159
11160DEFUN (show_bgp_community_list_exact,
11161 show_bgp_community_list_exact_cmd,
11162 "show bgp community-list (<1-500>|WORD) exact-match",
11163 SHOW_STR
11164 BGP_STR
11165 "Display routes matching the community-list\n"
11166 "community-list number\n"
11167 "community-list name\n"
11168 "Exact match of the communities\n")
11169{
11170 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11171}
11172
11173ALIAS (show_bgp_community_list_exact,
11174 show_bgp_ipv6_community_list_exact_cmd,
11175 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
11176 SHOW_STR
11177 BGP_STR
11178 "Address family\n"
11179 "Display routes matching the community-list\n"
11180 "community-list number\n"
11181 "community-list name\n"
11182 "Exact match of the communities\n")
11183
11184/* old command */
11185DEFUN (show_ipv6_bgp_community_list_exact,
11186 show_ipv6_bgp_community_list_exact_cmd,
11187 "show ipv6 bgp community-list WORD exact-match",
11188 SHOW_STR
11189 IPV6_STR
11190 BGP_STR
11191 "Display routes matching the community-list\n"
11192 "community-list name\n"
11193 "Exact match of the communities\n")
11194{
11195 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
11196}
11197
11198/* old command */
11199DEFUN (show_ipv6_mbgp_community_list_exact,
11200 show_ipv6_mbgp_community_list_exact_cmd,
11201 "show ipv6 mbgp community-list WORD exact-match",
11202 SHOW_STR
11203 IPV6_STR
11204 MBGP_STR
11205 "Display routes matching the community-list\n"
11206 "community-list name\n"
11207 "Exact match of the communities\n")
11208{
11209 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
11210}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011211
Lou Berger651b4022016-01-12 13:42:07 -050011212DEFUN (show_bgp_ipv4_community_list,
11213 show_bgp_ipv4_community_list_cmd,
11214 "show bgp ipv4 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011215 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011216 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011217 IP_STR
paul718e3742002-12-13 20:15:29 +000011218 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011219 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011220 "community-list name\n")
11221{
11222 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
11223}
11224
Lou Berger651b4022016-01-12 13:42:07 -050011225DEFUN (show_bgp_ipv4_safi_community_list,
11226 show_bgp_ipv4_safi_community_list_cmd,
11227 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011228 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011229 BGP_STR
11230 "Address family\n"
11231 "Address Family modifier\n"
11232 "Address Family modifier\n"
11233 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011234 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011235 "community-list name\n")
11236{
11237 if (strncmp (argv[0], "m", 1) == 0)
11238 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
11239
11240 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
11241}
11242
Lou Berger651b4022016-01-12 13:42:07 -050011243DEFUN (show_bgp_ipv4_community_list_exact,
11244 show_bgp_ipv4_community_list_exact_cmd,
11245 "show bgp ipv4 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011246 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011247 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011248 IP_STR
paul718e3742002-12-13 20:15:29 +000011249 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011250 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011251 "community-list name\n"
11252 "Exact match of the communities\n")
11253{
11254 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
11255}
11256
Lou Berger651b4022016-01-12 13:42:07 -050011257DEFUN (show_bgp_ipv4_safi_community_list_exact,
11258 show_bgp_ipv4_safi_community_list_exact_cmd,
11259 "show bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011260 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011261 BGP_STR
11262 "Address family\n"
11263 "Address Family modifier\n"
11264 "Address Family modifier\n"
11265 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011266 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011267 "community-list name\n"
11268 "Exact match of the communities\n")
11269{
11270 if (strncmp (argv[0], "m", 1) == 0)
11271 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
11272
11273 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
11274}
11275
Lou Bergerf9b6c392016-01-12 13:42:09 -050011276DEFUN (show_bgp_ipv6_safi_community_list,
11277 show_bgp_ipv6_safi_community_list_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011278 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +000011279 SHOW_STR
11280 BGP_STR
11281 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011282 "Address family modifier\n"
11283 "Address family modifier\n"
11284 "Address family modifier\n"
11285 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011286 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011287 "community-list number\n"
paule8e19462006-01-19 20:16:55 +000011288 "community-list name\n")
paul718e3742002-12-13 20:15:29 +000011289{
Lou Berger651b4022016-01-12 13:42:07 -050011290 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011291
Lou Berger651b4022016-01-12 13:42:07 -050011292 if (bgp_parse_safi(argv[0], &safi)) {
11293 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11294 return CMD_WARNING;
11295 }
11296 return bgp_show_community_list (vty, argv[1], 0, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011297}
11298
Lou Bergerf9b6c392016-01-12 13:42:09 -050011299DEFUN (show_bgp_ipv6_safi_community_list_exact,
11300 show_bgp_ipv6_safi_community_list_exact_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050011301 "show bgp ipv6 (encap|multicast|unicast|vpn) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +000011302 SHOW_STR
11303 BGP_STR
11304 "Address family\n"
Lou Berger651b4022016-01-12 13:42:07 -050011305 "Address family modifier\n"
11306 "Address family modifier\n"
11307 "Address family modifier\n"
11308 "Address family modifier\n"
paul718e3742002-12-13 20:15:29 +000011309 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +000011310 "community-list number\n"
paul718e3742002-12-13 20:15:29 +000011311 "community-list name\n"
11312 "Exact match of the communities\n")
paul718e3742002-12-13 20:15:29 +000011313{
Lou Berger651b4022016-01-12 13:42:07 -050011314 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011315
Lou Berger651b4022016-01-12 13:42:07 -050011316 if (bgp_parse_safi(argv[0], &safi)) {
11317 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11318 return CMD_WARNING;
11319 }
11320 return bgp_show_community_list (vty, argv[1], 1, AFI_IP6, safi);
paul718e3742002-12-13 20:15:29 +000011321}
David Lamparter6b0655a2014-06-04 06:53:35 +020011322
paul94f2b392005-06-28 12:44:16 +000011323static int
paulfd79ac92004-10-13 05:06:08 +000011324bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +000011325 safi_t safi, enum bgp_show_type type)
11326{
11327 int ret;
11328 struct prefix *p;
11329
11330 p = prefix_new();
11331
11332 ret = str2prefix (prefix, p);
11333 if (! ret)
11334 {
11335 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
11336 return CMD_WARNING;
11337 }
11338
ajs5a646652004-11-05 01:25:55 +000011339 ret = bgp_show (vty, NULL, afi, safi, type, p);
11340 prefix_free(p);
11341 return ret;
paul718e3742002-12-13 20:15:29 +000011342}
11343
Lou Bergerf9b6c392016-01-12 13:42:09 -050011344DEFUN (show_ip_bgp_prefix_longer,
11345 show_ip_bgp_prefix_longer_cmd,
11346 "show ip bgp A.B.C.D/M longer-prefixes",
11347 SHOW_STR
11348 IP_STR
11349 BGP_STR
11350 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11351 "Display route and more specific routes\n")
11352{
11353 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11354 bgp_show_type_prefix_longer);
11355}
11356
11357DEFUN (show_ip_bgp_flap_prefix_longer,
11358 show_ip_bgp_flap_prefix_longer_cmd,
11359 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
11360 SHOW_STR
11361 IP_STR
11362 BGP_STR
11363 "Display flap statistics of routes\n"
11364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11365 "Display route and more specific routes\n")
11366{
11367 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11368 bgp_show_type_flap_prefix_longer);
11369}
11370
11371ALIAS (show_ip_bgp_flap_prefix_longer,
11372 show_ip_bgp_damp_flap_prefix_longer_cmd,
11373 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
11374 SHOW_STR
11375 IP_STR
11376 BGP_STR
11377 "Display detailed information about dampening\n"
11378 "Display flap statistics of routes\n"
11379 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11380 "Display route and more specific routes\n")
11381
11382DEFUN (show_ip_bgp_ipv4_prefix_longer,
11383 show_ip_bgp_ipv4_prefix_longer_cmd,
11384 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
11385 SHOW_STR
11386 IP_STR
11387 BGP_STR
11388 "Address family\n"
11389 "Address Family modifier\n"
11390 "Address Family modifier\n"
11391 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11392 "Display route and more specific routes\n")
11393{
11394 if (strncmp (argv[0], "m", 1) == 0)
11395 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
11396 bgp_show_type_prefix_longer);
11397
11398 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
11399 bgp_show_type_prefix_longer);
11400}
11401
11402DEFUN (show_ip_bgp_flap_address,
11403 show_ip_bgp_flap_address_cmd,
11404 "show ip bgp flap-statistics A.B.C.D",
11405 SHOW_STR
11406 IP_STR
11407 BGP_STR
11408 "Display flap statistics of routes\n"
11409 "Network in the BGP routing table to display\n")
11410{
11411 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11412 bgp_show_type_flap_address);
11413}
11414
11415ALIAS (show_ip_bgp_flap_address,
11416 show_ip_bgp_damp_flap_address_cmd,
11417 "show ip bgp dampening flap-statistics A.B.C.D",
11418 SHOW_STR
11419 IP_STR
11420 BGP_STR
11421 "Display detailed information about dampening\n"
11422 "Display flap statistics of routes\n"
11423 "Network in the BGP routing table to display\n")
11424
11425DEFUN (show_ip_bgp_flap_prefix,
11426 show_ip_bgp_flap_prefix_cmd,
11427 "show ip bgp flap-statistics A.B.C.D/M",
11428 SHOW_STR
11429 IP_STR
11430 BGP_STR
11431 "Display flap statistics of routes\n"
11432 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11433{
11434 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11435 bgp_show_type_flap_prefix);
11436}
11437
11438ALIAS (show_ip_bgp_flap_prefix,
11439 show_ip_bgp_damp_flap_prefix_cmd,
11440 "show ip bgp dampening flap-statistics A.B.C.D/M",
11441 SHOW_STR
11442 IP_STR
11443 BGP_STR
11444 "Display detailed information about dampening\n"
11445 "Display flap statistics of routes\n"
11446 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11447
Lou Bergerf9b6c392016-01-12 13:42:09 -050011448DEFUN (show_bgp_prefix_longer,
11449 show_bgp_prefix_longer_cmd,
11450 "show bgp X:X::X:X/M longer-prefixes",
11451 SHOW_STR
11452 BGP_STR
11453 "IPv6 prefix <network>/<length>\n"
11454 "Display route and more specific routes\n")
11455{
11456 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11457 bgp_show_type_prefix_longer);
11458}
11459
11460/* old command */
11461DEFUN (show_ipv6_bgp_prefix_longer,
11462 show_ipv6_bgp_prefix_longer_cmd,
11463 "show ipv6 bgp X:X::X:X/M longer-prefixes",
11464 SHOW_STR
11465 IPV6_STR
11466 BGP_STR
11467 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11468 "Display route and more specific routes\n")
11469{
11470 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11471 bgp_show_type_prefix_longer);
11472}
11473
11474/* old command */
11475DEFUN (show_ipv6_mbgp_prefix_longer,
11476 show_ipv6_mbgp_prefix_longer_cmd,
11477 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
11478 SHOW_STR
11479 IPV6_STR
11480 MBGP_STR
11481 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
11482 "Display route and more specific routes\n")
11483{
11484 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
11485 bgp_show_type_prefix_longer);
11486}
Lou Bergerf9b6c392016-01-12 13:42:09 -050011487
Lou Berger651b4022016-01-12 13:42:07 -050011488DEFUN (show_bgp_ipv4_prefix_longer,
11489 show_bgp_ipv4_prefix_longer_cmd,
11490 "show bgp ipv4 A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011491 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011492 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011493 IP_STR
paul718e3742002-12-13 20:15:29 +000011494 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11495 "Display route and more specific routes\n")
11496{
11497 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
11498 bgp_show_type_prefix_longer);
11499}
11500
Lou Berger651b4022016-01-12 13:42:07 -050011501DEFUN (show_bgp_ipv4_safi_flap_prefix_longer,
11502 show_bgp_ipv4_safi_flap_prefix_longer_cmd,
11503 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011504 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011505 BGP_STR
11506 "Address family\n"
11507 "Address Family modifier\n"
11508 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050011509 "Address Family modifier\n"
11510 "Address Family modifier\n"
11511 "Display flap statistics of routes\n"
paul718e3742002-12-13 20:15:29 +000011512 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11513 "Display route and more specific routes\n")
11514{
Lou Berger651b4022016-01-12 13:42:07 -050011515 safi_t safi;
paul718e3742002-12-13 20:15:29 +000011516
Lou Berger651b4022016-01-12 13:42:07 -050011517 if (bgp_parse_safi(argv[0], &safi)) {
11518 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11519 return CMD_WARNING;
11520 }
11521 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11522 bgp_show_type_flap_prefix_longer);
paul718e3742002-12-13 20:15:29 +000011523}
11524
Lou Berger651b4022016-01-12 13:42:07 -050011525ALIAS (show_bgp_ipv4_safi_flap_prefix_longer,
11526 show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd,
11527 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M longer-prefixes",
paul718e3742002-12-13 20:15:29 +000011528 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011529 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011530 "Address family\n"
11531 "Address Family modifier\n"
11532 "Address Family modifier\n"
11533 "Address Family modifier\n"
11534 "Address Family modifier\n"
11535 "Display detailed information about dampening\n"
11536 "Display flap statistics of routes\n"
11537 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11538 "Display route and more specific routes\n")
11539
Lou Berger651b4022016-01-12 13:42:07 -050011540DEFUN (show_bgp_ipv6_safi_flap_prefix_longer,
11541 show_bgp_ipv6_safi_flap_prefix_longer_cmd,
11542 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M longer-prefixes",
11543 SHOW_STR
11544 BGP_STR
11545 "Address family\n"
11546 "Address Family modifier\n"
11547 "Address Family modifier\n"
11548 "Address Family modifier\n"
11549 "Address Family modifier\n"
11550 "Display flap statistics of routes\n"
11551 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11552 "Display route and more specific routes\n")
11553{
11554 safi_t safi;
11555
11556 if (bgp_parse_safi(argv[0], &safi)) {
11557 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11558 return CMD_WARNING;
11559 }
11560 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11561 bgp_show_type_flap_prefix_longer);
11562}
11563ALIAS (show_bgp_ipv6_safi_flap_prefix_longer,
11564 show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd,
11565 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M longer-prefixes",
11566 SHOW_STR
11567 BGP_STR
11568 "Address family\n"
11569 "Address Family modifier\n"
11570 "Address Family modifier\n"
11571 "Address Family modifier\n"
11572 "Address Family modifier\n"
11573 "Display detailed information about dampening\n"
11574 "Display flap statistics of routes\n"
11575 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11576 "Display route and more specific routes\n")
Lou Berger651b4022016-01-12 13:42:07 -050011577
11578DEFUN (show_bgp_ipv4_safi_prefix_longer,
11579 show_bgp_ipv4_safi_prefix_longer_cmd,
11580 "show bgp ipv4 (encap|multicast|unicast|vpn) A.B.C.D/M longer-prefixes",
11581 SHOW_STR
11582 BGP_STR
11583 "Address family\n"
11584 "Address Family modifier\n"
11585 "Address Family modifier\n"
11586 "Address Family modifier\n"
11587 "Address Family modifier\n"
11588 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11589 "Display route and more specific routes\n")
11590{
11591 safi_t safi;
11592
11593 if (bgp_parse_safi(argv[0], &safi)) {
11594 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11595 return CMD_WARNING;
11596 }
11597
11598 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11599 bgp_show_type_prefix_longer);
11600}
11601
Lou Berger651b4022016-01-12 13:42:07 -050011602DEFUN (show_bgp_ipv6_safi_prefix_longer,
11603 show_bgp_ipv6_safi_prefix_longer_cmd,
11604 "show bgp ipv6 (encap|multicast|unicast|vpn) X:X::X:X/M longer-prefixes",
11605 SHOW_STR
11606 BGP_STR
11607 "Address family\n"
11608 "Address Family modifier\n"
11609 "Address Family modifier\n"
11610 "Address Family modifier\n"
11611 "Address Family modifier\n"
11612 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
11613 "Display route and more specific routes\n")
11614{
11615 safi_t safi;
11616
11617 if (bgp_parse_safi(argv[0], &safi)) {
11618 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11619 return CMD_WARNING;
11620 }
11621
11622 return bgp_show_prefix_longer (vty, argv[1], AFI_IP6, safi,
11623 bgp_show_type_prefix_longer);
11624}
Lou Berger651b4022016-01-12 13:42:07 -050011625
11626DEFUN (show_bgp_ipv4_safi_flap_address,
11627 show_bgp_ipv4_safi_flap_address_cmd,
11628 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
11629 SHOW_STR
11630 BGP_STR
11631 "Address family\n"
11632 "Address Family modifier\n"
11633 "Address Family modifier\n"
11634 "Address Family modifier\n"
11635 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011636 "Display flap statistics of routes\n"
11637 "Network in the BGP routing table to display\n")
11638{
Lou Berger651b4022016-01-12 13:42:07 -050011639 safi_t safi;
11640
11641 if (bgp_parse_safi(argv[0], &safi)) {
11642 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
11643 return CMD_WARNING;
11644 }
11645 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011646 bgp_show_type_flap_address);
11647}
Lou Berger651b4022016-01-12 13:42:07 -050011648ALIAS (show_bgp_ipv4_safi_flap_address,
11649 show_bgp_ipv4_safi_damp_flap_address_cmd,
11650 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
Balaji3921cc52015-05-16 23:12:17 +053011651 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011652 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011653 "Address family\n"
11654 "Address Family modifier\n"
11655 "Address Family modifier\n"
11656 "Address Family modifier\n"
11657 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011658 "Display detailed information about dampening\n"
11659 "Display flap statistics of routes\n"
11660 "Network in the BGP routing table to display\n")
Lou Berger205e6742016-01-12 13:42:11 -050011661
Lou Berger651b4022016-01-12 13:42:07 -050011662DEFUN (show_bgp_ipv6_flap_address,
11663 show_bgp_ipv6_flap_address_cmd,
11664 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D",
paul718e3742002-12-13 20:15:29 +000011665 SHOW_STR
paul718e3742002-12-13 20:15:29 +000011666 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011667 "Address family\n"
11668 "Address Family modifier\n"
11669 "Address Family modifier\n"
11670 "Address Family modifier\n"
11671 "Address Family modifier\n"
11672 "Display flap statistics of routes\n"
11673 "Network in the BGP routing table to display\n")
11674{
11675 safi_t safi;
11676
11677 if (bgp_parse_safi(argv[0], &safi)) {
11678 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11679 return CMD_WARNING;
11680 }
11681 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, safi,
11682 bgp_show_type_flap_address);
11683}
11684ALIAS (show_bgp_ipv6_flap_address,
11685 show_bgp_ipv6_damp_flap_address_cmd,
11686 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D",
11687 SHOW_STR
11688 BGP_STR
11689 "Address family\n"
11690 "Address Family modifier\n"
11691 "Address Family modifier\n"
11692 "Address Family modifier\n"
11693 "Address Family modifier\n"
11694 "Display detailed information about dampening\n"
11695 "Display flap statistics of routes\n"
11696 "Network in the BGP routing table to display\n")
Lou Berger651b4022016-01-12 13:42:07 -050011697
11698DEFUN (show_bgp_ipv4_safi_flap_prefix,
11699 show_bgp_ipv4_safi_flap_prefix_cmd,
11700 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics A.B.C.D/M",
11701 SHOW_STR
11702 BGP_STR
11703 "Address family\n"
11704 "Address Family modifier\n"
11705 "Address Family modifier\n"
11706 "Address Family modifier\n"
11707 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000011708 "Display flap statistics of routes\n"
11709 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11710{
Lou Berger651b4022016-01-12 13:42:07 -050011711 safi_t safi;
11712
11713 if (bgp_parse_safi(argv[0], &safi)) {
11714 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11715 return CMD_WARNING;
11716 }
11717 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000011718 bgp_show_type_flap_prefix);
11719}
Balaji3921cc52015-05-16 23:12:17 +053011720
Lou Berger651b4022016-01-12 13:42:07 -050011721ALIAS (show_bgp_ipv4_safi_flap_prefix,
11722 show_bgp_ipv4_safi_damp_flap_prefix_cmd,
11723 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics A.B.C.D/M",
Balaji3921cc52015-05-16 23:12:17 +053011724 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053011725 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011726 "Address family\n"
11727 "Address Family modifier\n"
11728 "Address Family modifier\n"
11729 "Address Family modifier\n"
11730 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053011731 "Display detailed information about dampening\n"
11732 "Display flap statistics of routes\n"
11733 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11734
Lou Berger651b4022016-01-12 13:42:07 -050011735DEFUN (show_bgp_ipv6_safi_flap_prefix,
11736 show_bgp_ipv6_safi_flap_prefix_cmd,
11737 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics X:X::X:X/M",
paul718e3742002-12-13 20:15:29 +000011738 SHOW_STR
11739 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050011740 "Address family\n"
11741 "Address Family modifier\n"
11742 "Address Family modifier\n"
11743 "Address Family modifier\n"
11744 "Address Family modifier\n"
11745 "Display flap statistics of routes\n"
11746 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +000011747{
Lou Berger651b4022016-01-12 13:42:07 -050011748 safi_t safi;
11749
11750 if (bgp_parse_safi(argv[0], &safi)) {
11751 vty_out (vty, "Error: Bad SAFI: %s%s", argv[1], VTY_NEWLINE);
11752 return CMD_WARNING;
11753 }
11754 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, safi,
11755 bgp_show_type_flap_prefix);
paul718e3742002-12-13 20:15:29 +000011756}
11757
Lou Berger651b4022016-01-12 13:42:07 -050011758ALIAS (show_bgp_ipv6_safi_flap_prefix,
11759 show_bgp_ipv6_safi_damp_flap_prefix_cmd,
11760 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics X:X::X:X/M",
11761 SHOW_STR
11762 BGP_STR
11763 "Address family\n"
11764 "Address Family modifier\n"
11765 "Address Family modifier\n"
11766 "Address Family modifier\n"
11767 "Address Family modifier\n"
11768 "Display detailed information about dampening\n"
11769 "Display flap statistics of routes\n"
11770 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11771
11772DEFUN (show_bgp_ipv6_prefix_longer,
paul718e3742002-12-13 20:15:29 +000011773 show_bgp_ipv6_prefix_longer_cmd,
11774 "show bgp ipv6 X:X::X:X/M longer-prefixes",
11775 SHOW_STR
11776 BGP_STR
11777 "Address family\n"
11778 "IPv6 prefix <network>/<length>\n"
11779 "Display route and more specific routes\n")
paul718e3742002-12-13 20:15:29 +000011780{
11781 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
11782 bgp_show_type_prefix_longer);
11783}
11784
paul94f2b392005-06-28 12:44:16 +000011785static struct peer *
paulfd79ac92004-10-13 05:06:08 +000011786peer_lookup_in_view (struct vty *vty, const char *view_name,
11787 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +000011788{
11789 int ret;
11790 struct bgp *bgp;
11791 struct peer *peer;
11792 union sockunion su;
11793
11794 /* BGP structure lookup. */
11795 if (view_name)
11796 {
11797 bgp = bgp_lookup_by_name (view_name);
11798 if (! bgp)
11799 {
11800 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11801 return NULL;
11802 }
11803 }
paul5228ad22004-06-04 17:58:18 +000011804 else
paulbb46e942003-10-24 19:02:03 +000011805 {
11806 bgp = bgp_get_default ();
11807 if (! bgp)
11808 {
11809 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11810 return NULL;
11811 }
11812 }
11813
11814 /* Get peer sockunion. */
11815 ret = str2sockunion (ip_str, &su);
11816 if (ret < 0)
11817 {
11818 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
11819 return NULL;
11820 }
11821
11822 /* Peer structure lookup. */
11823 peer = peer_lookup (bgp, &su);
11824 if (! peer)
11825 {
11826 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
11827 return NULL;
11828 }
11829
11830 return peer;
11831}
David Lamparter6b0655a2014-06-04 06:53:35 +020011832
Paul Jakma2815e612006-09-14 02:56:07 +000011833enum bgp_stats
11834{
11835 BGP_STATS_MAXBITLEN = 0,
11836 BGP_STATS_RIB,
11837 BGP_STATS_PREFIXES,
11838 BGP_STATS_TOTPLEN,
11839 BGP_STATS_UNAGGREGATEABLE,
11840 BGP_STATS_MAX_AGGREGATEABLE,
11841 BGP_STATS_AGGREGATES,
11842 BGP_STATS_SPACE,
11843 BGP_STATS_ASPATH_COUNT,
11844 BGP_STATS_ASPATH_MAXHOPS,
11845 BGP_STATS_ASPATH_TOTHOPS,
11846 BGP_STATS_ASPATH_MAXSIZE,
11847 BGP_STATS_ASPATH_TOTSIZE,
11848 BGP_STATS_ASN_HIGHEST,
11849 BGP_STATS_MAX,
11850};
paulbb46e942003-10-24 19:02:03 +000011851
Paul Jakma2815e612006-09-14 02:56:07 +000011852static const char *table_stats_strs[] =
11853{
11854 [BGP_STATS_PREFIXES] = "Total Prefixes",
11855 [BGP_STATS_TOTPLEN] = "Average prefix length",
11856 [BGP_STATS_RIB] = "Total Advertisements",
11857 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
11858 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
11859 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
11860 [BGP_STATS_SPACE] = "Address space advertised",
11861 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
11862 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
11863 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
11864 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
11865 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
11866 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
11867 [BGP_STATS_MAX] = NULL,
11868};
11869
11870struct bgp_table_stats
11871{
11872 struct bgp_table *table;
11873 unsigned long long counts[BGP_STATS_MAX];
11874};
11875
11876#if 0
11877#define TALLY_SIGFIG 100000
11878static unsigned long
11879ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
11880{
11881 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
11882 unsigned long res = (newtot * TALLY_SIGFIG) / count;
11883 unsigned long ret = newtot / count;
11884
11885 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
11886 return ret + 1;
11887 else
11888 return ret;
11889}
11890#endif
11891
11892static int
11893bgp_table_stats_walker (struct thread *t)
11894{
11895 struct bgp_node *rn;
11896 struct bgp_node *top;
11897 struct bgp_table_stats *ts = THREAD_ARG (t);
11898 unsigned int space = 0;
11899
Paul Jakma53d9f672006-10-15 23:41:16 +000011900 if (!(top = bgp_table_top (ts->table)))
11901 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +000011902
11903 switch (top->p.family)
11904 {
11905 case AF_INET:
11906 space = IPV4_MAX_BITLEN;
11907 break;
11908 case AF_INET6:
11909 space = IPV6_MAX_BITLEN;
11910 break;
11911 }
11912
11913 ts->counts[BGP_STATS_MAXBITLEN] = space;
11914
11915 for (rn = top; rn; rn = bgp_route_next (rn))
11916 {
11917 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -070011918 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +000011919 unsigned int rinum = 0;
11920
11921 if (rn == top)
11922 continue;
11923
11924 if (!rn->info)
11925 continue;
11926
11927 ts->counts[BGP_STATS_PREFIXES]++;
11928 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
11929
11930#if 0
11931 ts->counts[BGP_STATS_AVGPLEN]
11932 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
11933 ts->counts[BGP_STATS_AVGPLEN],
11934 rn->p.prefixlen);
11935#endif
11936
11937 /* check if the prefix is included by any other announcements */
11938 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -070011939 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +000011940
11941 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +000011942 {
11943 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
11944 /* announced address space */
11945 if (space)
11946 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
11947 }
Paul Jakma2815e612006-09-14 02:56:07 +000011948 else if (prn->info)
11949 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
11950
Paul Jakma2815e612006-09-14 02:56:07 +000011951 for (ri = rn->info; ri; ri = ri->next)
11952 {
11953 rinum++;
11954 ts->counts[BGP_STATS_RIB]++;
11955
11956 if (ri->attr &&
11957 (CHECK_FLAG (ri->attr->flag,
11958 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
11959 ts->counts[BGP_STATS_AGGREGATES]++;
11960
11961 /* as-path stats */
11962 if (ri->attr && ri->attr->aspath)
11963 {
11964 unsigned int hops = aspath_count_hops (ri->attr->aspath);
11965 unsigned int size = aspath_size (ri->attr->aspath);
11966 as_t highest = aspath_highest (ri->attr->aspath);
11967
11968 ts->counts[BGP_STATS_ASPATH_COUNT]++;
11969
11970 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
11971 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
11972
11973 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
11974 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
11975
11976 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
11977 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
11978#if 0
11979 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
11980 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11981 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
11982 hops);
11983 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
11984 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
11985 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
11986 size);
11987#endif
11988 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
11989 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
11990 }
11991 }
11992 }
11993 return 0;
11994}
11995
11996static int
11997bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
11998{
11999 struct bgp_table_stats ts;
12000 unsigned int i;
12001
12002 if (!bgp->rib[afi][safi])
12003 {
Donald Sharp3c964042016-01-25 23:38:53 -050012004 vty_out (vty, "%% No RIB exists for the specified AFI(%d)/SAFI(%d) %s",
12005 afi, safi, VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012006 return CMD_WARNING;
12007 }
12008
12009 memset (&ts, 0, sizeof (ts));
12010 ts.table = bgp->rib[afi][safi];
12011 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
12012
12013 vty_out (vty, "BGP %s RIB statistics%s%s",
12014 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
12015
12016 for (i = 0; i < BGP_STATS_MAX; i++)
12017 {
12018 if (!table_stats_strs[i])
12019 continue;
12020
12021 switch (i)
12022 {
12023#if 0
12024 case BGP_STATS_ASPATH_AVGHOPS:
12025 case BGP_STATS_ASPATH_AVGSIZE:
12026 case BGP_STATS_AVGPLEN:
12027 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12028 vty_out (vty, "%12.2f",
12029 (float)ts.counts[i] / (float)TALLY_SIGFIG);
12030 break;
12031#endif
12032 case BGP_STATS_ASPATH_TOTHOPS:
12033 case BGP_STATS_ASPATH_TOTSIZE:
12034 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12035 vty_out (vty, "%12.2f",
12036 ts.counts[i] ?
12037 (float)ts.counts[i] /
12038 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
12039 : 0);
12040 break;
12041 case BGP_STATS_TOTPLEN:
12042 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12043 vty_out (vty, "%12.2f",
12044 ts.counts[i] ?
12045 (float)ts.counts[i] /
12046 (float)ts.counts[BGP_STATS_PREFIXES]
12047 : 0);
12048 break;
12049 case BGP_STATS_SPACE:
12050 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12051 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
12052 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
12053 break;
Paul Jakma30a22312008-08-15 14:05:22 +010012054 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +000012055 vty_out (vty, "%12.2f%s",
12056 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +000012057 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +000012058 VTY_NEWLINE);
12059 vty_out (vty, "%30s: ", "/8 equivalent ");
12060 vty_out (vty, "%12.2f%s",
12061 (float)ts.counts[BGP_STATS_SPACE] /
12062 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
12063 VTY_NEWLINE);
12064 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
12065 break;
12066 vty_out (vty, "%30s: ", "/24 equivalent ");
12067 vty_out (vty, "%12.2f",
12068 (float)ts.counts[BGP_STATS_SPACE] /
12069 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
12070 break;
12071 default:
12072 vty_out (vty, "%-30s: ", table_stats_strs[i]);
12073 vty_out (vty, "%12llu", ts.counts[i]);
12074 }
12075
12076 vty_out (vty, "%s", VTY_NEWLINE);
12077 }
12078 return CMD_SUCCESS;
12079}
12080
12081static int
12082bgp_table_stats_vty (struct vty *vty, const char *name,
12083 const char *afi_str, const char *safi_str)
12084{
12085 struct bgp *bgp;
12086 afi_t afi;
12087 safi_t safi;
12088
12089 if (name)
12090 bgp = bgp_lookup_by_name (name);
12091 else
12092 bgp = bgp_get_default ();
12093
12094 if (!bgp)
12095 {
Lou Bergerbf1ae6c2016-01-12 13:42:08 -050012096 vty_out (vty, "%% No such BGP instance exists%s", VTY_NEWLINE);
Paul Jakma2815e612006-09-14 02:56:07 +000012097 return CMD_WARNING;
12098 }
12099 if (strncmp (afi_str, "ipv", 3) == 0)
12100 {
12101 if (strncmp (afi_str, "ipv4", 4) == 0)
12102 afi = AFI_IP;
12103 else if (strncmp (afi_str, "ipv6", 4) == 0)
12104 afi = AFI_IP6;
12105 else
12106 {
12107 vty_out (vty, "%% Invalid address family %s%s",
12108 afi_str, VTY_NEWLINE);
12109 return CMD_WARNING;
12110 }
Lou Berger298cc2f2016-01-12 13:42:02 -050012111 switch (safi_str[0]) {
12112 case 'm':
12113 safi = SAFI_MULTICAST;
12114 break;
12115 case 'u':
12116 safi = SAFI_UNICAST;
12117 break;
12118 case 'v':
Donald Sharp3c964042016-01-25 23:38:53 -050012119 safi = SAFI_MPLS_VPN;
Lou Berger298cc2f2016-01-12 13:42:02 -050012120 break;
12121 case 'e':
12122 safi = SAFI_ENCAP;
12123 break;
12124 default:
12125 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012126 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -050012127 return CMD_WARNING;
12128 }
Paul Jakma2815e612006-09-14 02:56:07 +000012129 }
12130 else
12131 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012132 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +000012133 afi_str, VTY_NEWLINE);
12134 return CMD_WARNING;
12135 }
12136
Paul Jakma2815e612006-09-14 02:56:07 +000012137 return bgp_table_stats (vty, bgp, afi, safi);
12138}
12139
12140DEFUN (show_bgp_statistics,
12141 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012142 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012143 SHOW_STR
12144 BGP_STR
12145 "Address family\n"
12146 "Address family\n"
12147 "Address Family modifier\n"
12148 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012149 "Address Family modifier\n"
12150 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012151 "BGP RIB advertisement statistics\n")
12152{
12153 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12154}
12155
Lou Bergerf9b6c392016-01-12 13:42:09 -050012156ALIAS (show_bgp_statistics,
12157 show_bgp_statistics_vpnv4_cmd,
12158 "show bgp (ipv4) (vpnv4) statistics",
12159 SHOW_STR
12160 BGP_STR
12161 "Address family\n"
12162 "Address Family modifier\n"
12163 "BGP RIB advertisement statistics\n")
12164
Paul Jakma2815e612006-09-14 02:56:07 +000012165DEFUN (show_bgp_statistics_view,
12166 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -050012167 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012168 SHOW_STR
12169 BGP_STR
12170 "BGP view\n"
12171 "Address family\n"
12172 "Address family\n"
12173 "Address Family modifier\n"
12174 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -050012175 "Address Family modifier\n"
12176 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +000012177 "BGP RIB advertisement statistics\n")
12178{
12179 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
12180}
12181
12182ALIAS (show_bgp_statistics_view,
Lou Bergerf9b6c392016-01-12 13:42:09 -050012183 show_bgp_statistics_view_vpnv4_cmd,
12184 "show bgp view WORD (ipv4) (vpnv4) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +000012185 SHOW_STR
12186 BGP_STR
12187 "BGP view\n"
12188 "Address family\n"
12189 "Address Family modifier\n"
12190 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +020012191
Paul Jakmaff7924f2006-09-04 01:10:36 +000012192enum bgp_pcounts
12193{
12194 PCOUNT_ADJ_IN = 0,
12195 PCOUNT_DAMPED,
12196 PCOUNT_REMOVED,
12197 PCOUNT_HISTORY,
12198 PCOUNT_STALE,
12199 PCOUNT_VALID,
12200 PCOUNT_ALL,
12201 PCOUNT_COUNTED,
12202 PCOUNT_PFCNT, /* the figure we display to users */
12203 PCOUNT_MAX,
12204};
12205
12206static const char *pcount_strs[] =
12207{
12208 [PCOUNT_ADJ_IN] = "Adj-in",
12209 [PCOUNT_DAMPED] = "Damped",
12210 [PCOUNT_REMOVED] = "Removed",
12211 [PCOUNT_HISTORY] = "History",
12212 [PCOUNT_STALE] = "Stale",
12213 [PCOUNT_VALID] = "Valid",
12214 [PCOUNT_ALL] = "All RIB",
12215 [PCOUNT_COUNTED] = "PfxCt counted",
12216 [PCOUNT_PFCNT] = "Useable",
12217 [PCOUNT_MAX] = NULL,
12218};
12219
Paul Jakma2815e612006-09-14 02:56:07 +000012220struct peer_pcounts
12221{
12222 unsigned int count[PCOUNT_MAX];
12223 const struct peer *peer;
12224 const struct bgp_table *table;
12225};
12226
Paul Jakmaff7924f2006-09-04 01:10:36 +000012227static int
Paul Jakma2815e612006-09-14 02:56:07 +000012228bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000012229{
12230 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000012231 struct peer_pcounts *pc = THREAD_ARG (t);
12232 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012233
Paul Jakma2815e612006-09-14 02:56:07 +000012234 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012235 {
12236 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000012237 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012238
12239 for (ain = rn->adj_in; ain; ain = ain->next)
12240 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000012241 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012242
Paul Jakmaff7924f2006-09-04 01:10:36 +000012243 for (ri = rn->info; ri; ri = ri->next)
12244 {
12245 char buf[SU_ADDRSTRLEN];
12246
12247 if (ri->peer != peer)
12248 continue;
12249
Paul Jakma2815e612006-09-14 02:56:07 +000012250 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012251
12252 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000012253 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012254 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000012255 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012256 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000012257 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012258 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000012259 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012260 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000012261 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012262 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000012263 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012264
12265 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
12266 {
Paul Jakma2815e612006-09-14 02:56:07 +000012267 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000012268 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012269 plog_warn (peer->log,
12270 "%s [pcount] %s/%d is counted but flags 0x%x",
12271 peer->host,
12272 inet_ntop(rn->p.family, &rn->p.u.prefix,
12273 buf, SU_ADDRSTRLEN),
12274 rn->p.prefixlen,
12275 ri->flags);
12276 }
12277 else
12278 {
Paul Jakma1a392d42006-09-07 00:24:49 +000012279 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000012280 plog_warn (peer->log,
12281 "%s [pcount] %s/%d not counted but flags 0x%x",
12282 peer->host,
12283 inet_ntop(rn->p.family, &rn->p.u.prefix,
12284 buf, SU_ADDRSTRLEN),
12285 rn->p.prefixlen,
12286 ri->flags);
12287 }
12288 }
12289 }
Paul Jakma2815e612006-09-14 02:56:07 +000012290 return 0;
12291}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012292
Paul Jakma2815e612006-09-14 02:56:07 +000012293static int
12294bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
12295{
12296 struct peer_pcounts pcounts = { .peer = peer };
12297 unsigned int i;
12298
12299 if (!peer || !peer->bgp || !peer->afc[afi][safi]
12300 || !peer->bgp->rib[afi][safi])
12301 {
12302 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12303 return CMD_WARNING;
12304 }
12305
12306 memset (&pcounts, 0, sizeof(pcounts));
12307 pcounts.peer = peer;
12308 pcounts.table = peer->bgp->rib[afi][safi];
12309
12310 /* in-place call via thread subsystem so as to record execution time
12311 * stats for the thread-walk (i.e. ensure this can't be blamed on
12312 * on just vty_read()).
12313 */
12314 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
12315
Paul Jakmaff7924f2006-09-04 01:10:36 +000012316 vty_out (vty, "Prefix counts for %s, %s%s",
12317 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
12318 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
12319 vty_out (vty, "%sCounts from RIB table walk:%s%s",
12320 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
12321
12322 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000012323 vty_out (vty, "%20s: %-10d%s",
12324 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012325
Paul Jakma2815e612006-09-14 02:56:07 +000012326 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000012327 {
12328 vty_out (vty, "%s [pcount] PfxCt drift!%s",
12329 peer->host, VTY_NEWLINE);
12330 vty_out (vty, "Please report this bug, with the above command output%s",
12331 VTY_NEWLINE);
12332 }
12333
12334 return CMD_SUCCESS;
12335}
12336
Lou Bergerf9b6c392016-01-12 13:42:09 -050012337DEFUN (show_ip_bgp_neighbor_prefix_counts,
12338 show_ip_bgp_neighbor_prefix_counts_cmd,
12339 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12340 SHOW_STR
12341 IP_STR
12342 BGP_STR
12343 "Detailed information on TCP and BGP neighbor connections\n"
12344 "Neighbor to display information about\n"
12345 "Neighbor to display information about\n"
12346 "Display detailed prefix count information\n")
12347{
12348 struct peer *peer;
12349
12350 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12351 if (! peer)
12352 return CMD_WARNING;
12353
12354 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12355}
12356
Paul Jakmaff7924f2006-09-04 01:10:36 +000012357DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
12358 show_bgp_ipv6_neighbor_prefix_counts_cmd,
12359 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12360 SHOW_STR
12361 BGP_STR
12362 "Address family\n"
12363 "Detailed information on TCP and BGP neighbor connections\n"
12364 "Neighbor to display information about\n"
12365 "Neighbor to display information about\n"
12366 "Display detailed prefix count information\n")
12367{
12368 struct peer *peer;
12369
12370 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12371 if (! peer)
12372 return CMD_WARNING;
12373
12374 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
12375}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012376
12377DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
12378 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
12379 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12380 SHOW_STR
12381 IP_STR
12382 BGP_STR
12383 "Address family\n"
12384 "Address Family modifier\n"
12385 "Address Family modifier\n"
12386 "Detailed information on TCP and BGP neighbor connections\n"
12387 "Neighbor to display information about\n"
12388 "Neighbor to display information about\n"
12389 "Display detailed prefix count information\n")
12390{
12391 struct peer *peer;
12392
12393 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12394 if (! peer)
12395 return CMD_WARNING;
12396
12397 if (strncmp (argv[0], "m", 1) == 0)
12398 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
12399
12400 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
12401}
12402
12403DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
12404 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
12405 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12406 SHOW_STR
12407 IP_STR
12408 BGP_STR
12409 "Address family\n"
12410 "Address Family modifier\n"
12411 "Address Family modifier\n"
12412 "Detailed information on TCP and BGP neighbor connections\n"
12413 "Neighbor to display information about\n"
12414 "Neighbor to display information about\n"
12415 "Display detailed prefix count information\n")
12416{
12417 struct peer *peer;
12418
12419 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12420 if (! peer)
12421 return CMD_WARNING;
12422
12423 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
12424}
Paul Jakmaff7924f2006-09-04 01:10:36 +000012425
Lou Berger651b4022016-01-12 13:42:07 -050012426DEFUN (show_bgp_ipv4_safi_neighbor_prefix_counts,
12427 show_bgp_ipv4_safi_neighbor_prefix_counts_cmd,
12428 "show bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012429 SHOW_STR
Paul Jakmaff7924f2006-09-04 01:10:36 +000012430 BGP_STR
12431 "Address family\n"
12432 "Address Family modifier\n"
12433 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050012434 "Address Family modifier\n"
12435 "Address Family modifier\n"
Paul Jakmaff7924f2006-09-04 01:10:36 +000012436 "Detailed information on TCP and BGP neighbor connections\n"
12437 "Neighbor to display information about\n"
12438 "Neighbor to display information about\n"
12439 "Display detailed prefix count information\n")
12440{
12441 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012442 safi_t safi;
12443
12444 if (bgp_parse_safi(argv[0], &safi)) {
12445 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12446 return CMD_WARNING;
12447 }
Paul Jakmaff7924f2006-09-04 01:10:36 +000012448
12449 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12450 if (! peer)
12451 return CMD_WARNING;
12452
Lou Berger651b4022016-01-12 13:42:07 -050012453 return bgp_peer_counts (vty, peer, AFI_IP, safi);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012454}
Lou Berger205e6742016-01-12 13:42:11 -050012455
Lou Berger651b4022016-01-12 13:42:07 -050012456DEFUN (show_bgp_ipv6_safi_neighbor_prefix_counts,
12457 show_bgp_ipv6_safi_neighbor_prefix_counts_cmd,
12458 "show bgp ipv6 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
12459 SHOW_STR
12460 BGP_STR
12461 "Address family\n"
12462 "Address Family modifier\n"
12463 "Address Family modifier\n"
12464 "Address Family modifier\n"
12465 "Address Family modifier\n"
12466 "Detailed information on TCP and BGP neighbor connections\n"
12467 "Neighbor to display information about\n"
12468 "Neighbor to display information about\n"
12469 "Display detailed prefix count information\n")
12470{
12471 struct peer *peer;
12472 safi_t safi;
Paul Jakmaff7924f2006-09-04 01:10:36 +000012473
Lou Berger651b4022016-01-12 13:42:07 -050012474 if (bgp_parse_safi(argv[0], &safi)) {
12475 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
12476 return CMD_WARNING;
12477 }
12478
12479 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12480 if (! peer)
12481 return CMD_WARNING;
12482
12483 return bgp_peer_counts (vty, peer, AFI_IP6, safi);
12484}
Lou Berger651b4022016-01-12 13:42:07 -050012485
12486DEFUN (show_ip_bgp_encap_neighbor_prefix_counts,
12487 show_ip_bgp_encap_neighbor_prefix_counts_cmd,
12488 "show ip bgp encap all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
Paul Jakmaff7924f2006-09-04 01:10:36 +000012489 SHOW_STR
12490 IP_STR
12491 BGP_STR
12492 "Address family\n"
12493 "Address Family modifier\n"
12494 "Address Family modifier\n"
12495 "Detailed information on TCP and BGP neighbor connections\n"
12496 "Neighbor to display information about\n"
12497 "Neighbor to display information about\n"
12498 "Display detailed prefix count information\n")
12499{
12500 struct peer *peer;
12501
12502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12503 if (! peer)
12504 return CMD_WARNING;
12505
Lou Berger651b4022016-01-12 13:42:07 -050012506 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_ENCAP);
Paul Jakmaff7924f2006-09-04 01:10:36 +000012507}
12508
12509
paul94f2b392005-06-28 12:44:16 +000012510static void
paul718e3742002-12-13 20:15:29 +000012511show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
12512 int in)
12513{
12514 struct bgp_table *table;
12515 struct bgp_adj_in *ain;
12516 struct bgp_adj_out *adj;
12517 unsigned long output_count;
12518 struct bgp_node *rn;
12519 int header1 = 1;
12520 struct bgp *bgp;
12521 int header2 = 1;
12522
paulbb46e942003-10-24 19:02:03 +000012523 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000012524
12525 if (! bgp)
12526 return;
12527
12528 table = bgp->rib[afi][safi];
12529
12530 output_count = 0;
12531
12532 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
12533 PEER_STATUS_DEFAULT_ORIGINATE))
12534 {
12535 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 +000012536 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12537 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012538
12539 vty_out (vty, "Originating default network 0.0.0.0%s%s",
12540 VTY_NEWLINE, VTY_NEWLINE);
12541 header1 = 0;
12542 }
12543
12544 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12545 if (in)
12546 {
12547 for (ain = rn->adj_in; ain; ain = ain->next)
12548 if (ain->peer == peer)
12549 {
12550 if (header1)
12551 {
12552 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 +000012553 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12554 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012555 header1 = 0;
12556 }
12557 if (header2)
12558 {
12559 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12560 header2 = 0;
12561 }
12562 if (ain->attr)
12563 {
12564 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
12565 output_count++;
12566 }
12567 }
12568 }
12569 else
12570 {
12571 for (adj = rn->adj_out; adj; adj = adj->next)
12572 if (adj->peer == peer)
12573 {
12574 if (header1)
12575 {
12576 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 +000012577 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
12578 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000012579 header1 = 0;
12580 }
12581 if (header2)
12582 {
12583 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
12584 header2 = 0;
12585 }
12586 if (adj->attr)
12587 {
12588 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
12589 output_count++;
12590 }
12591 }
12592 }
12593
12594 if (output_count != 0)
12595 vty_out (vty, "%sTotal number of prefixes %ld%s",
12596 VTY_NEWLINE, output_count, VTY_NEWLINE);
12597}
12598
paul94f2b392005-06-28 12:44:16 +000012599static int
paulbb46e942003-10-24 19:02:03 +000012600peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
12601{
paul718e3742002-12-13 20:15:29 +000012602 if (! peer || ! peer->afc[afi][safi])
12603 {
12604 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
12605 return CMD_WARNING;
12606 }
12607
12608 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
12609 {
12610 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
12611 VTY_NEWLINE);
12612 return CMD_WARNING;
12613 }
12614
12615 show_adj_route (vty, peer, afi, safi, in);
12616
12617 return CMD_SUCCESS;
12618}
12619
Lou Bergerf9b6c392016-01-12 13:42:09 -050012620DEFUN (show_ip_bgp_view_neighbor_advertised_route,
12621 show_ip_bgp_view_neighbor_advertised_route_cmd,
12622 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12623 SHOW_STR
12624 IP_STR
12625 BGP_STR
12626 "BGP view\n"
12627 "View name\n"
12628 "Detailed information on TCP and BGP neighbor connections\n"
12629 "Neighbor to display information about\n"
12630 "Neighbor to display information about\n"
12631 "Display the routes advertised to a BGP neighbor\n")
12632{
12633 struct peer *peer;
12634
12635 if (argc == 2)
12636 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12637 else
12638 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12639
12640 if (! peer)
12641 return CMD_WARNING;
12642
12643 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12644}
12645
12646ALIAS (show_ip_bgp_view_neighbor_advertised_route,
12647 show_ip_bgp_neighbor_advertised_route_cmd,
12648 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12649 SHOW_STR
12650 IP_STR
12651 BGP_STR
12652 "Detailed information on TCP and BGP neighbor connections\n"
12653 "Neighbor to display information about\n"
12654 "Neighbor to display information about\n"
12655 "Display the routes advertised to a BGP neighbor\n")
12656
12657DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
12658 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
12659 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12660 SHOW_STR
12661 IP_STR
12662 BGP_STR
12663 "Address family\n"
12664 "Address Family modifier\n"
12665 "Address Family modifier\n"
12666 "Detailed information on TCP and BGP neighbor connections\n"
12667 "Neighbor to display information about\n"
12668 "Neighbor to display information about\n"
12669 "Display the routes advertised to a BGP neighbor\n")
12670{
12671 struct peer *peer;
12672
12673 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12674 if (! peer)
12675 return CMD_WARNING;
12676
12677 if (strncmp (argv[0], "m", 1) == 0)
12678 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
12679
12680 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
12681}
12682
Lou Bergerf9b6c392016-01-12 13:42:09 -050012683DEFUN (show_bgp_view_neighbor_advertised_route,
12684 show_bgp_view_neighbor_advertised_route_cmd,
12685 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12686 SHOW_STR
12687 BGP_STR
12688 "BGP view\n"
12689 "View name\n"
12690 "Detailed information on TCP and BGP neighbor connections\n"
12691 "Neighbor to display information about\n"
12692 "Neighbor to display information about\n"
12693 "Display the routes advertised to a BGP neighbor\n")
12694{
12695 struct peer *peer;
12696
12697 if (argc == 2)
12698 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12699 else
12700 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12701
12702 if (! peer)
12703 return CMD_WARNING;
12704
12705 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
12706}
12707
12708DEFUN (show_bgp_view_neighbor_received_routes,
12709 show_bgp_view_neighbor_received_routes_cmd,
12710 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12711 SHOW_STR
12712 BGP_STR
12713 "BGP view\n"
12714 "View name\n"
12715 "Detailed information on TCP and BGP neighbor connections\n"
12716 "Neighbor to display information about\n"
12717 "Neighbor to display information about\n"
12718 "Display the received routes from neighbor\n")
12719{
12720 struct peer *peer;
12721
12722 if (argc == 2)
12723 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12724 else
12725 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12726
12727 if (! peer)
12728 return CMD_WARNING;
12729
12730 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
12731}
12732
12733ALIAS (show_bgp_view_neighbor_advertised_route,
12734 show_bgp_neighbor_advertised_route_cmd,
12735 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12736 SHOW_STR
12737 BGP_STR
12738 "Detailed information on TCP and BGP neighbor connections\n"
12739 "Neighbor to display information about\n"
12740 "Neighbor to display information about\n"
12741 "Display the routes advertised to a BGP neighbor\n")
12742
12743ALIAS (show_bgp_view_neighbor_advertised_route,
12744 show_bgp_ipv6_neighbor_advertised_route_cmd,
12745 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12746 SHOW_STR
12747 BGP_STR
12748 "Address family\n"
12749 "Detailed information on TCP and BGP neighbor connections\n"
12750 "Neighbor to display information about\n"
12751 "Neighbor to display information about\n"
12752 "Display the routes advertised to a BGP neighbor\n")
12753
12754/* old command */
12755ALIAS (show_bgp_view_neighbor_advertised_route,
12756 ipv6_bgp_neighbor_advertised_route_cmd,
12757 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12758 SHOW_STR
12759 IPV6_STR
12760 BGP_STR
12761 "Detailed information on TCP and BGP neighbor connections\n"
12762 "Neighbor to display information about\n"
12763 "Neighbor to display information about\n"
12764 "Display the routes advertised to a BGP neighbor\n")
12765
12766/* old command */
12767DEFUN (ipv6_mbgp_neighbor_advertised_route,
12768 ipv6_mbgp_neighbor_advertised_route_cmd,
12769 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
12770 SHOW_STR
12771 IPV6_STR
12772 MBGP_STR
12773 "Detailed information on TCP and BGP neighbor connections\n"
12774 "Neighbor to display information about\n"
12775 "Neighbor to display information about\n"
12776 "Display the routes advertised to a BGP neighbor\n")
12777{
12778 struct peer *peer;
12779
12780 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12781 if (! peer)
12782 return CMD_WARNING;
12783
12784 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
12785}
Lou Bergerf9b6c392016-01-12 13:42:09 -050012786
12787DEFUN (show_ip_bgp_view_neighbor_received_routes,
12788 show_ip_bgp_view_neighbor_received_routes_cmd,
12789 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
12790 SHOW_STR
12791 IP_STR
12792 BGP_STR
12793 "BGP view\n"
12794 "View name\n"
12795 "Detailed information on TCP and BGP neighbor connections\n"
12796 "Neighbor to display information about\n"
12797 "Neighbor to display information about\n"
12798 "Display the received routes from neighbor\n")
12799{
12800 struct peer *peer;
12801
12802 if (argc == 2)
12803 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
12804 else
12805 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12806
12807 if (! peer)
12808 return CMD_WARNING;
12809
12810 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12811}
12812
12813ALIAS (show_ip_bgp_view_neighbor_received_routes,
12814 show_ip_bgp_neighbor_received_routes_cmd,
12815 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12816 SHOW_STR
12817 IP_STR
12818 BGP_STR
12819 "Detailed information on TCP and BGP neighbor connections\n"
12820 "Neighbor to display information about\n"
12821 "Neighbor to display information about\n"
12822 "Display the received routes from neighbor\n")
12823
12824ALIAS (show_bgp_view_neighbor_received_routes,
12825 show_bgp_ipv6_neighbor_received_routes_cmd,
12826 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
12827 SHOW_STR
12828 BGP_STR
12829 "Address family\n"
12830 "Detailed information on TCP and BGP neighbor connections\n"
12831 "Neighbor to display information about\n"
12832 "Neighbor to display information about\n"
12833 "Display the received routes from neighbor\n")
12834
12835DEFUN (show_bgp_neighbor_received_prefix_filter,
12836 show_bgp_neighbor_received_prefix_filter_cmd,
12837 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12838 SHOW_STR
12839 BGP_STR
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 information received from a BGP neighbor\n"
12844 "Display the prefixlist filter\n")
12845{
12846 char name[BUFSIZ];
12847 union sockunion su;
12848 struct peer *peer;
12849 int count, ret;
12850
12851 ret = str2sockunion (argv[0], &su);
12852 if (ret < 0)
12853 {
12854 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
12855 return CMD_WARNING;
12856 }
12857
12858 peer = peer_lookup (NULL, &su);
12859 if (! peer)
12860 return CMD_WARNING;
12861
12862 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12863 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12864 if (count)
12865 {
12866 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12867 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12868 }
12869
12870 return CMD_SUCCESS;
12871}
12872
12873/* old command */
12874ALIAS (show_bgp_view_neighbor_received_routes,
12875 ipv6_bgp_neighbor_received_routes_cmd,
12876 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12877 SHOW_STR
12878 IPV6_STR
12879 BGP_STR
12880 "Detailed information on TCP and BGP neighbor connections\n"
12881 "Neighbor to display information about\n"
12882 "Neighbor to display information about\n"
12883 "Display the received routes from neighbor\n")
12884
12885/* old command */
12886DEFUN (ipv6_mbgp_neighbor_received_routes,
12887 ipv6_mbgp_neighbor_received_routes_cmd,
12888 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
12889 SHOW_STR
12890 IPV6_STR
12891 MBGP_STR
12892 "Detailed information on TCP and BGP neighbor connections\n"
12893 "Neighbor to display information about\n"
12894 "Neighbor to display information about\n"
12895 "Display the received routes from neighbor\n")
12896{
12897 struct peer *peer;
12898
12899 peer = peer_lookup_in_view (vty, NULL, argv[0]);
12900 if (! peer)
12901 return CMD_WARNING;
12902
12903 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
12904}
12905
12906DEFUN (show_bgp_view_neighbor_received_prefix_filter,
12907 show_bgp_view_neighbor_received_prefix_filter_cmd,
12908 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
12909 SHOW_STR
12910 BGP_STR
12911 "BGP view\n"
12912 "View name\n"
12913 "Detailed information on TCP and BGP neighbor connections\n"
12914 "Neighbor to display information about\n"
12915 "Neighbor to display information about\n"
12916 "Display information received from a BGP neighbor\n"
12917 "Display the prefixlist filter\n")
12918{
12919 char name[BUFSIZ];
12920 union sockunion su;
12921 struct peer *peer;
12922 struct bgp *bgp;
12923 int count, ret;
12924
12925 /* BGP structure lookup. */
12926 bgp = bgp_lookup_by_name (argv[0]);
12927 if (bgp == NULL)
12928 {
12929 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
12930 return CMD_WARNING;
12931 }
12932
12933 ret = str2sockunion (argv[1], &su);
12934 if (ret < 0)
12935 {
12936 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
12937 return CMD_WARNING;
12938 }
12939
12940 peer = peer_lookup (bgp, &su);
12941 if (! peer)
12942 return CMD_WARNING;
12943
12944 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
12945 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
12946 if (count)
12947 {
12948 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
12949 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
12950 }
12951
12952 return CMD_SUCCESS;
12953}
12954
12955
12956DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
12957 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
12958 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
12959 SHOW_STR
12960 IP_STR
12961 BGP_STR
12962 "Address family\n"
12963 "Address Family modifier\n"
12964 "Address Family modifier\n"
12965 "Detailed information on TCP and BGP neighbor connections\n"
12966 "Neighbor to display information about\n"
12967 "Neighbor to display information about\n"
12968 "Display the received routes from neighbor\n")
12969{
12970 struct peer *peer;
12971
12972 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12973 if (! peer)
12974 return CMD_WARNING;
12975
12976 if (strncmp (argv[0], "m", 1) == 0)
12977 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
12978
12979 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
12980}
12981
Lou Berger651b4022016-01-12 13:42:07 -050012982DEFUN (show_bgp_ipv4_safi_neighbor_advertised_route,
12983 show_bgp_ipv4_safi_neighbor_advertised_route_cmd,
12984 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012985 SHOW_STR
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012986 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050012987 "Address Family modifier\n"
12988 "Address Family modifier\n"
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012989 "Detailed information on TCP and BGP neighbor connections\n"
12990 "Neighbor to display information about\n"
12991 "Neighbor to display information about\n"
12992 "Display the routes advertised to a BGP neighbor\n")
12993{
12994 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050012995 safi_t safi;
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012996
Lou Berger651b4022016-01-12 13:42:07 -050012997 if (bgp_parse_safi(argv[0], &safi)) {
12998 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012999 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013000 }
paul718e3742002-12-13 20:15:29 +000013001
paulbb46e942003-10-24 19:02:03 +000013002 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13003 if (! peer)
13004 return CMD_WARNING;
13005
Lou Berger651b4022016-01-12 13:42:07 -050013006 return peer_adj_routes (vty, peer, AFI_IP, safi, 0);
13007}
Lou Berger205e6742016-01-12 13:42:11 -050013008
Lou Berger651b4022016-01-12 13:42:07 -050013009DEFUN (show_bgp_ipv6_safi_neighbor_advertised_route,
13010 show_bgp_ipv6_safi_neighbor_advertised_route_cmd,
13011 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
13012 SHOW_STR
13013 BGP_STR
13014 "Address Family modifier\n"
13015 "Address Family modifier\n"
13016 "Address Family modifier\n"
13017 "Detailed information on TCP and BGP neighbor connections\n"
13018 "Neighbor to display information about\n"
13019 "Neighbor to display information about\n"
13020 "Display the routes advertised to a BGP neighbor\n")
13021{
13022 struct peer *peer;
13023 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013024
Lou Berger651b4022016-01-12 13:42:07 -050013025 if (bgp_parse_safi(argv[0], &safi)) {
13026 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13027 return CMD_WARNING;
13028 }
13029
13030 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13031 if (! peer)
13032 return CMD_WARNING;
13033
13034 return peer_adj_routes (vty, peer, AFI_IP6, safi, 0);
paul718e3742002-12-13 20:15:29 +000013035}
13036
Lou Bergerf9b6c392016-01-12 13:42:09 -050013037DEFUN (show_bgp_view_ipv6_neighbor_advertised_route,
Lou Berger651b4022016-01-12 13:42:07 -050013038 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
13039 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
paulbb46e942003-10-24 19:02:03 +000013040 SHOW_STR
13041 BGP_STR
13042 "BGP view\n"
13043 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013044 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013045 "Detailed information on TCP and BGP neighbor connections\n"
13046 "Neighbor to display information about\n"
13047 "Neighbor to display information about\n"
13048 "Display the routes advertised to a BGP neighbor\n")
13049{
13050 struct peer *peer;
13051
13052 if (argc == 2)
13053 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13054 else
13055 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13056
13057 if (! peer)
13058 return CMD_WARNING;
13059
13060 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
13061}
13062
Lou Bergerf9b6c392016-01-12 13:42:09 -050013063DEFUN (show_bgp_view_ipv6_neighbor_received_routes,
Lou Berger651b4022016-01-12 13:42:07 -050013064 show_bgp_view_ipv6_neighbor_received_routes_cmd,
13065 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
paulbb46e942003-10-24 19:02:03 +000013066 SHOW_STR
13067 BGP_STR
13068 "BGP view\n"
13069 "View name\n"
13070 "Address family\n"
13071 "Detailed information on TCP and BGP neighbor connections\n"
13072 "Neighbor to display information about\n"
13073 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000013074 "Display the received routes from neighbor\n")
13075{
13076 struct peer *peer;
13077
13078 if (argc == 2)
13079 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13080 else
13081 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13082
13083 if (! peer)
13084 return CMD_WARNING;
13085
13086 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
13087}
Lou Berger651b4022016-01-12 13:42:07 -050013088
13089DEFUN (show_bgp_ipv4_safi_neighbor_received_routes,
13090 show_bgp_ipv4_safi_neighbor_received_routes_cmd,
13091 "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 +010013092 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013093 BGP_STR
13094 "Address family\n"
13095 "Address Family modifier\n"
13096 "Address Family modifier\n"
Lou Berger651b4022016-01-12 13:42:07 -050013097 "Address Family modifier\n"
13098 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013099 "Detailed information on TCP and BGP neighbor connections\n"
13100 "Neighbor to display information about\n"
13101 "Neighbor to display information about\n"
13102 "Display the received routes from neighbor\n")
13103{
paulbb46e942003-10-24 19:02:03 +000013104 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013105 safi_t safi;
13106
13107 if (bgp_parse_safi(argv[0], &safi)) {
13108 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13109 return CMD_WARNING;
13110 }
paul718e3742002-12-13 20:15:29 +000013111
paulbb46e942003-10-24 19:02:03 +000013112 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13113 if (! peer)
13114 return CMD_WARNING;
13115
Lou Berger651b4022016-01-12 13:42:07 -050013116 return peer_adj_routes (vty, peer, AFI_IP, safi, 1);
paul718e3742002-12-13 20:15:29 +000013117}
Lou Berger205e6742016-01-12 13:42:11 -050013118
Lou Berger651b4022016-01-12 13:42:07 -050013119DEFUN (show_bgp_ipv6_safi_neighbor_received_routes,
13120 show_bgp_ipv6_safi_neighbor_received_routes_cmd,
13121 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) received-routes",
13122 SHOW_STR
13123 BGP_STR
13124 "Address family\n"
13125 "Address Family modifier\n"
13126 "Address Family modifier\n"
13127 "Address Family modifier\n"
13128 "Address Family modifier\n"
13129 "Detailed information on TCP and BGP neighbor connections\n"
13130 "Neighbor to display information about\n"
13131 "Neighbor to display information about\n"
13132 "Display the received routes from neighbor\n")
13133{
13134 struct peer *peer;
13135 safi_t safi;
13136
13137 if (bgp_parse_safi(argv[0], &safi)) {
13138 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13139 return CMD_WARNING;
13140 }
13141
13142 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13143 if (! peer)
13144 return CMD_WARNING;
13145
13146 return peer_adj_routes (vty, peer, AFI_IP6, safi, 1);
13147}
paul718e3742002-12-13 20:15:29 +000013148
Michael Lambert95cbbd22010-07-23 14:43:04 -040013149DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
13150 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040013151 "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 -040013152 SHOW_STR
13153 BGP_STR
13154 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013155 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013156 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013157 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013158 "Address family modifier\n"
13159 "Address family modifier\n"
13160 "Detailed information on TCP and BGP neighbor connections\n"
13161 "Neighbor to display information about\n"
13162 "Neighbor to display information about\n"
13163 "Display the advertised routes to neighbor\n"
13164 "Display the received routes from neighbor\n")
13165{
13166 int afi;
13167 int safi;
13168 int in;
13169 struct peer *peer;
13170
David Lamparter94bad672015-03-03 08:52:22 +010013171 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013172
13173 if (! peer)
13174 return CMD_WARNING;
13175
Michael Lambert95cbbd22010-07-23 14:43:04 -040013176 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
13177 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13178 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040013179
13180 return peer_adj_routes (vty, peer, afi, safi, in);
13181}
13182
Lou Bergerf9b6c392016-01-12 13:42:09 -050013183DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
13184 show_ip_bgp_neighbor_received_prefix_filter_cmd,
13185 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13186 SHOW_STR
13187 IP_STR
13188 BGP_STR
13189 "Detailed information on TCP and BGP neighbor connections\n"
13190 "Neighbor to display information about\n"
13191 "Neighbor to display information about\n"
13192 "Display information received from a BGP neighbor\n"
13193 "Display the prefixlist filter\n")
13194{
13195 char name[BUFSIZ];
13196 union sockunion su;
13197 struct peer *peer;
13198 int count, ret;
13199
13200 ret = str2sockunion (argv[0], &su);
13201 if (ret < 0)
13202 {
13203 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13204 return CMD_WARNING;
13205 }
13206
13207 peer = peer_lookup (NULL, &su);
13208 if (! peer)
13209 return CMD_WARNING;
13210
13211 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13212 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13213 if (count)
13214 {
13215 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13216 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13217 }
13218
13219 return CMD_SUCCESS;
13220}
13221
13222DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
13223 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
13224 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
13225 SHOW_STR
13226 IP_STR
13227 BGP_STR
13228 "Address family\n"
13229 "Address Family modifier\n"
13230 "Address Family modifier\n"
13231 "Detailed information on TCP and BGP neighbor connections\n"
13232 "Neighbor to display information about\n"
13233 "Neighbor to display information about\n"
13234 "Display information received from a BGP neighbor\n"
13235 "Display the prefixlist filter\n")
13236{
13237 char name[BUFSIZ];
13238 union sockunion su;
13239 struct peer *peer;
13240 int count, ret;
13241
13242 ret = str2sockunion (argv[1], &su);
13243 if (ret < 0)
13244 {
13245 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13246 return CMD_WARNING;
13247 }
13248
13249 peer = peer_lookup (NULL, &su);
13250 if (! peer)
13251 return CMD_WARNING;
13252
13253 if (strncmp (argv[0], "m", 1) == 0)
13254 {
13255 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
13256 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13257 if (count)
13258 {
13259 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
13260 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13261 }
13262 }
13263 else
13264 {
13265 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
13266 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13267 if (count)
13268 {
13269 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
13270 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13271 }
13272 }
13273
13274 return CMD_SUCCESS;
13275}
13276
13277ALIAS (show_bgp_view_neighbor_received_routes,
13278 show_bgp_neighbor_received_routes_cmd,
13279 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
13280 SHOW_STR
13281 BGP_STR
13282 "Detailed information on TCP and BGP neighbor connections\n"
13283 "Neighbor to display information about\n"
13284 "Neighbor to display information about\n"
13285 "Display the received routes from neighbor\n")
13286
Lou Berger651b4022016-01-12 13:42:07 -050013287DEFUN (show_bgp_ipv4_safi_neighbor_received_prefix_filter,
13288 show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd,
13289 "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 +000013290 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013291 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013292 IP_STR
13293 "Address Family modifier\n"
13294 "Address Family modifier\n"
13295 "Address Family modifier\n"
13296 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013297 "Detailed information on TCP and BGP neighbor connections\n"
13298 "Neighbor to display information about\n"
13299 "Neighbor to display information about\n"
13300 "Display information received from a BGP neighbor\n"
13301 "Display the prefixlist filter\n")
13302{
13303 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013304 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013305 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013306 int count, ret;
Lou Berger651b4022016-01-12 13:42:07 -050013307 safi_t safi;
paul718e3742002-12-13 20:15:29 +000013308
Lou Berger651b4022016-01-12 13:42:07 -050013309 if (bgp_parse_safi(argv[0], &safi)) {
13310 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013311 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013312 }
paul718e3742002-12-13 20:15:29 +000013313
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013314 ret = str2sockunion (argv[1], &su);
13315 if (ret < 0)
13316 {
13317 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13318 return CMD_WARNING;
13319 }
paul718e3742002-12-13 20:15:29 +000013320
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013321 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013322 if (! peer)
13323 return CMD_WARNING;
13324
Lou Berger651b4022016-01-12 13:42:07 -050013325 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, safi);
13326 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
13327 if (count) {
13328 vty_out (vty, "Address family: IPv4 %s%s", safi2str(safi), VTY_NEWLINE);
13329 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
13330 }
paul718e3742002-12-13 20:15:29 +000013331
13332 return CMD_SUCCESS;
13333}
Lou Berger205e6742016-01-12 13:42:11 -050013334
Lou Berger651b4022016-01-12 13:42:07 -050013335DEFUN (show_bgp_ipv6_safi_neighbor_received_prefix_filter,
13336 show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd,
13337 "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 +000013338 SHOW_STR
13339 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013340 IP_STR
13341 "Address Family modifier\n"
13342 "Address Family modifier\n"
13343 "Address Family modifier\n"
13344 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000013345 "Detailed information on TCP and BGP neighbor connections\n"
13346 "Neighbor to display information about\n"
13347 "Neighbor to display information about\n"
Lou Berger651b4022016-01-12 13:42:07 -050013348 "Display information received from a BGP neighbor\n"
13349 "Display the prefixlist filter\n")
13350{
13351 char name[BUFSIZ];
13352 union sockunion su;
13353 struct peer *peer;
13354 int count, ret;
13355 safi_t safi;
13356
13357 if (bgp_parse_safi(argv[0], &safi)) {
13358 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13359 return CMD_WARNING;
13360 }
13361
13362 ret = str2sockunion (argv[1], &su);
13363 if (ret < 0)
13364 {
13365 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13366 return CMD_WARNING;
13367 }
13368
13369 peer = peer_lookup (NULL, &su);
13370 if (! peer)
13371 return CMD_WARNING;
13372
13373 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, safi);
13374 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13375 if (count) {
13376 vty_out (vty, "Address family: IPv6 %s%s", safi2str(safi), VTY_NEWLINE);
13377 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13378 }
13379
13380 return CMD_SUCCESS;
13381}
paul718e3742002-12-13 20:15:29 +000013382
Lou Bergerf9b6c392016-01-12 13:42:09 -050013383DEFUN (show_bgp_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013384 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
13385 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paul718e3742002-12-13 20:15:29 +000013386 SHOW_STR
13387 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013388 "Address family\n"
paul718e3742002-12-13 20:15:29 +000013389 "Detailed information on TCP and BGP neighbor connections\n"
13390 "Neighbor to display information about\n"
13391 "Neighbor to display information about\n"
13392 "Display information received from a BGP neighbor\n"
13393 "Display the prefixlist filter\n")
13394{
13395 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013396 union sockunion su;
paul718e3742002-12-13 20:15:29 +000013397 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013398 int count, ret;
paul718e3742002-12-13 20:15:29 +000013399
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013400 ret = str2sockunion (argv[0], &su);
13401 if (ret < 0)
13402 {
13403 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
13404 return CMD_WARNING;
13405 }
paul718e3742002-12-13 20:15:29 +000013406
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013407 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000013408 if (! peer)
13409 return CMD_WARNING;
13410
13411 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13412 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13413 if (count)
13414 {
13415 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13416 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13417 }
13418
13419 return CMD_SUCCESS;
13420}
13421
Lou Bergerf9b6c392016-01-12 13:42:09 -050013422DEFUN (show_bgp_view_ipv6_neighbor_received_prefix_filter,
Lou Berger651b4022016-01-12 13:42:07 -050013423 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
13424 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
paulbb46e942003-10-24 19:02:03 +000013425 SHOW_STR
13426 BGP_STR
13427 "BGP view\n"
13428 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050013429 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000013430 "Detailed information on TCP and BGP neighbor connections\n"
13431 "Neighbor to display information about\n"
13432 "Neighbor to display information about\n"
13433 "Display information received from a BGP neighbor\n"
13434 "Display the prefixlist filter\n")
13435{
13436 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013437 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000013438 struct peer *peer;
13439 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013440 int count, ret;
paulbb46e942003-10-24 19:02:03 +000013441
13442 /* BGP structure lookup. */
13443 bgp = bgp_lookup_by_name (argv[0]);
13444 if (bgp == NULL)
13445 {
13446 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13447 return CMD_WARNING;
13448 }
13449
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013450 ret = str2sockunion (argv[1], &su);
13451 if (ret < 0)
13452 {
13453 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
13454 return CMD_WARNING;
13455 }
paulbb46e942003-10-24 19:02:03 +000013456
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020013457 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000013458 if (! peer)
13459 return CMD_WARNING;
13460
13461 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
13462 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
13463 if (count)
13464 {
13465 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
13466 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
13467 }
13468
13469 return CMD_SUCCESS;
13470}
David Lamparter6b0655a2014-06-04 06:53:35 +020013471
paul94f2b392005-06-28 12:44:16 +000013472static int
paulbb46e942003-10-24 19:02:03 +000013473bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000013474 safi_t safi, enum bgp_show_type type)
13475{
paul718e3742002-12-13 20:15:29 +000013476 if (! peer || ! peer->afc[afi][safi])
13477 {
13478 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000013479 return CMD_WARNING;
13480 }
13481
ajs5a646652004-11-05 01:25:55 +000013482 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000013483}
Lou Bergerf9b6c392016-01-12 13:42:09 -050013484DEFUN (show_ip_bgp_neighbor_routes,
13485 show_ip_bgp_neighbor_routes_cmd,
13486 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
13487 SHOW_STR
13488 IP_STR
13489 BGP_STR
13490 "Detailed information on TCP and BGP neighbor connections\n"
13491 "Neighbor to display information about\n"
13492 "Neighbor to display information about\n"
13493 "Display routes learned from neighbor\n")
13494{
13495 struct peer *peer;
13496
13497 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13498 if (! peer)
13499 return CMD_WARNING;
13500
13501 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13502 bgp_show_type_neighbor);
13503}
13504
13505DEFUN (show_ip_bgp_neighbor_flap,
13506 show_ip_bgp_neighbor_flap_cmd,
13507 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
13508 SHOW_STR
13509 IP_STR
13510 BGP_STR
13511 "Detailed information on TCP and BGP neighbor connections\n"
13512 "Neighbor to display information about\n"
13513 "Neighbor to display information about\n"
13514 "Display flap statistics of the routes learned from neighbor\n")
13515{
13516 struct peer *peer;
13517
13518 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13519 if (! peer)
13520 return CMD_WARNING;
13521
13522 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13523 bgp_show_type_flap_neighbor);
13524}
13525
13526DEFUN (show_ip_bgp_neighbor_damp,
13527 show_ip_bgp_neighbor_damp_cmd,
13528 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13529 SHOW_STR
13530 IP_STR
13531 BGP_STR
13532 "Detailed information on TCP and BGP neighbor connections\n"
13533 "Neighbor to display information about\n"
13534 "Neighbor to display information about\n"
13535 "Display the dampened routes received from neighbor\n")
13536{
13537 struct peer *peer;
13538
13539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13540 if (! peer)
13541 return CMD_WARNING;
13542
13543 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13544 bgp_show_type_damp_neighbor);
13545}
13546
13547DEFUN (show_ip_bgp_ipv4_neighbor_routes,
13548 show_ip_bgp_ipv4_neighbor_routes_cmd,
13549 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
13550 SHOW_STR
13551 IP_STR
13552 BGP_STR
13553 "Address family\n"
13554 "Address Family modifier\n"
13555 "Address Family modifier\n"
13556 "Detailed information on TCP and BGP neighbor connections\n"
13557 "Neighbor to display information about\n"
13558 "Neighbor to display information about\n"
13559 "Display routes learned from neighbor\n")
13560{
13561 struct peer *peer;
13562
13563 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13564 if (! peer)
13565 return CMD_WARNING;
13566
13567 if (strncmp (argv[0], "m", 1) == 0)
13568 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
13569 bgp_show_type_neighbor);
13570
13571 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
13572 bgp_show_type_neighbor);
13573}
13574
13575DEFUN (show_ip_bgp_view_rsclient,
13576 show_ip_bgp_view_rsclient_cmd,
13577 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
13578 SHOW_STR
13579 IP_STR
13580 BGP_STR
13581 "BGP view\n"
13582 "View name\n"
13583 "Information about Route Server Client\n"
13584 NEIGHBOR_ADDR_STR)
13585{
13586 struct bgp_table *table;
13587 struct peer *peer;
13588
13589 if (argc == 2)
13590 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13591 else
13592 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13593
13594 if (! peer)
13595 return CMD_WARNING;
13596
13597 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13598 {
13599 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13600 VTY_NEWLINE);
13601 return CMD_WARNING;
13602 }
13603
13604 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13605 PEER_FLAG_RSERVER_CLIENT))
13606 {
13607 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13608 VTY_NEWLINE);
13609 return CMD_WARNING;
13610 }
13611
13612 table = peer->rib[AFI_IP][SAFI_UNICAST];
13613
13614 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13615}
13616
13617ALIAS (show_ip_bgp_view_rsclient,
13618 show_ip_bgp_rsclient_cmd,
13619 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
13620 SHOW_STR
13621 IP_STR
13622 BGP_STR
13623 "Information about Route Server Client\n"
13624 NEIGHBOR_ADDR_STR)
13625
13626DEFUN (show_bgp_view_ipv4_safi_rsclient,
13627 show_bgp_view_ipv4_safi_rsclient_cmd,
13628 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13629 SHOW_STR
13630 BGP_STR
13631 "BGP view\n"
13632 "View name\n"
13633 "Address family\n"
13634 "Address Family modifier\n"
13635 "Address Family modifier\n"
13636 "Information about Route Server Client\n"
13637 NEIGHBOR_ADDR_STR)
13638{
13639 struct bgp_table *table;
13640 struct peer *peer;
13641 safi_t safi;
13642
13643 if (argc == 3) {
13644 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13645 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13646 } else {
13647 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13648 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13649 }
13650
13651 if (! peer)
13652 return CMD_WARNING;
13653
13654 if (! peer->afc[AFI_IP][safi])
13655 {
13656 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13657 VTY_NEWLINE);
13658 return CMD_WARNING;
13659 }
13660
13661 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13662 PEER_FLAG_RSERVER_CLIENT))
13663 {
13664 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13665 VTY_NEWLINE);
13666 return CMD_WARNING;
13667 }
13668
13669 table = peer->rib[AFI_IP][safi];
13670
13671 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
13672}
13673
13674ALIAS (show_bgp_view_ipv4_safi_rsclient,
13675 show_bgp_ipv4_safi_rsclient_cmd,
13676 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
13677 SHOW_STR
13678 BGP_STR
13679 "Address family\n"
13680 "Address Family modifier\n"
13681 "Address Family modifier\n"
13682 "Information about Route Server Client\n"
13683 NEIGHBOR_ADDR_STR)
13684
13685DEFUN (show_ip_bgp_view_rsclient_route,
13686 show_ip_bgp_view_rsclient_route_cmd,
13687 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13688 SHOW_STR
13689 IP_STR
13690 BGP_STR
13691 "BGP view\n"
13692 "View name\n"
13693 "Information about Route Server Client\n"
13694 NEIGHBOR_ADDR_STR
13695 "Network in the BGP routing table to display\n")
13696{
13697 struct bgp *bgp;
13698 struct peer *peer;
13699
13700 /* BGP structure lookup. */
13701 if (argc == 3)
13702 {
13703 bgp = bgp_lookup_by_name (argv[0]);
13704 if (bgp == NULL)
13705 {
13706 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13707 return CMD_WARNING;
13708 }
13709 }
13710 else
13711 {
13712 bgp = bgp_get_default ();
13713 if (bgp == NULL)
13714 {
13715 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13716 return CMD_WARNING;
13717 }
13718 }
13719
13720 if (argc == 3)
13721 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
13722 else
13723 peer = peer_lookup_in_view (vty, NULL, argv[0]);
13724
13725 if (! peer)
13726 return CMD_WARNING;
13727
13728 if (! peer->afc[AFI_IP][SAFI_UNICAST])
13729 {
13730 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13731 VTY_NEWLINE);
13732 return CMD_WARNING;
13733}
13734
13735 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
13736 PEER_FLAG_RSERVER_CLIENT))
13737 {
13738 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13739 VTY_NEWLINE);
13740 return CMD_WARNING;
13741 }
13742
13743 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
13744 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070013745 AFI_IP, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050013746}
13747
13748ALIAS (show_ip_bgp_view_rsclient_route,
13749 show_ip_bgp_rsclient_route_cmd,
13750 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13751 SHOW_STR
13752 IP_STR
13753 BGP_STR
13754 "Information about Route Server Client\n"
13755 NEIGHBOR_ADDR_STR
13756 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +000013757
Lou Berger651b4022016-01-12 13:42:07 -050013758DEFUN (show_bgp_ipv4_safi_neighbor_flap,
13759 show_bgp_ipv4_safi_neighbor_flap_cmd,
13760 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013761 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013762 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013763 "Address Family Modifier\n"
13764 "Address Family Modifier\n"
13765 "Address Family Modifier\n"
13766 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013767 "Detailed information on TCP and BGP neighbor connections\n"
13768 "Neighbor to display information about\n"
13769 "Neighbor to display information about\n"
13770 "Display flap statistics of the routes learned from neighbor\n")
13771{
paulbb46e942003-10-24 19:02:03 +000013772 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013773 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013774
Lou Berger651b4022016-01-12 13:42:07 -050013775 if (bgp_parse_safi(argv[0], &safi)) {
13776 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13777 return CMD_WARNING;
13778 }
13779
13780 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013781 if (! peer)
13782 return CMD_WARNING;
13783
Lou Berger651b4022016-01-12 13:42:07 -050013784 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013785 bgp_show_type_flap_neighbor);
13786}
Lou Berger205e6742016-01-12 13:42:11 -050013787
Lou Berger651b4022016-01-12 13:42:07 -050013788DEFUN (show_bgp_ipv6_safi_neighbor_flap,
13789 show_bgp_ipv6_safi_neighbor_flap_cmd,
13790 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paul718e3742002-12-13 20:15:29 +000013791 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013792 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013793 "Address Family Modifier\n"
13794 "Address Family Modifier\n"
13795 "Address Family Modifier\n"
13796 "Address Family Modifier\n"
13797 "Detailed information on TCP and BGP neighbor connections\n"
13798 "Neighbor to display information about\n"
13799 "Neighbor to display information about\n"
13800 "Display flap statistics of the routes learned from neighbor\n")
13801{
13802 struct peer *peer;
13803 safi_t safi;
13804
13805 if (bgp_parse_safi(argv[0], &safi)) {
13806 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13807 return CMD_WARNING;
13808 }
13809
13810 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13811 if (! peer)
13812 return CMD_WARNING;
13813
13814 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13815 bgp_show_type_flap_neighbor);
13816}
Lou Berger651b4022016-01-12 13:42:07 -050013817
13818DEFUN (show_bgp_ipv4_safi_neighbor_damp,
13819 show_bgp_ipv4_safi_neighbor_damp_cmd,
13820 "show bgp ipv4 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
13821 SHOW_STR
13822 BGP_STR
13823 "Address Family Modifier\n"
13824 "Address Family Modifier\n"
13825 "Address Family Modifier\n"
13826 "Address Family Modifier\n"
paul718e3742002-12-13 20:15:29 +000013827 "Detailed information on TCP and BGP neighbor connections\n"
13828 "Neighbor to display information about\n"
13829 "Neighbor to display information about\n"
13830 "Display the dampened routes received from neighbor\n")
13831{
paulbb46e942003-10-24 19:02:03 +000013832 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013833 safi_t safi;
paulbb46e942003-10-24 19:02:03 +000013834
Lou Berger651b4022016-01-12 13:42:07 -050013835 if (bgp_parse_safi(argv[0], &safi)) {
13836 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13837 return CMD_WARNING;
13838 }
13839
13840 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulbb46e942003-10-24 19:02:03 +000013841 if (! peer)
13842 return CMD_WARNING;
13843
Lou Berger651b4022016-01-12 13:42:07 -050013844 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013845 bgp_show_type_damp_neighbor);
13846}
Lou Berger205e6742016-01-12 13:42:11 -050013847
Lou Berger651b4022016-01-12 13:42:07 -050013848DEFUN (show_bgp_ipv6_safi_neighbor_damp,
13849 show_bgp_ipv6_safi_neighbor_damp_cmd,
13850 "show bgp ipv6 (encap|multicast|unicast|vpn) neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paul718e3742002-12-13 20:15:29 +000013851 SHOW_STR
Lou Berger651b4022016-01-12 13:42:07 -050013852 BGP_STR
13853 "Address Family Modifier\n"
13854 "Address Family Modifier\n"
13855 "Address Family Modifier\n"
13856 "Address Family Modifier\n"
13857 "Detailed information on TCP and BGP neighbor connections\n"
13858 "Neighbor to display information about\n"
13859 "Neighbor to display information about\n"
13860 "Display the dampened routes received from neighbor\n")
13861{
13862 struct peer *peer;
13863 safi_t safi;
13864
13865 if (bgp_parse_safi(argv[0], &safi)) {
13866 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13867 return CMD_WARNING;
13868 }
13869
13870 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13871 if (! peer)
13872 return CMD_WARNING;
13873
13874 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13875 bgp_show_type_damp_neighbor);
13876}
Lou Berger651b4022016-01-12 13:42:07 -050013877
13878DEFUN (show_bgp_ipv4_safi_neighbor_routes,
13879 show_bgp_ipv4_safi_neighbor_routes_cmd,
13880 "show bgp ipv4 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
13881 SHOW_STR
paul718e3742002-12-13 20:15:29 +000013882 BGP_STR
13883 "Address family\n"
13884 "Address Family modifier\n"
13885 "Address Family modifier\n"
13886 "Detailed information on TCP and BGP neighbor connections\n"
13887 "Neighbor to display information about\n"
13888 "Neighbor to display information about\n"
13889 "Display routes learned from neighbor\n")
13890{
paulbb46e942003-10-24 19:02:03 +000013891 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013892 safi_t safi;
13893
13894 if (bgp_parse_safi(argv[0], &safi)) {
13895 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13896 return CMD_WARNING;
13897 }
paulbb46e942003-10-24 19:02:03 +000013898
13899 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13900 if (! peer)
13901 return CMD_WARNING;
13902
Lou Berger651b4022016-01-12 13:42:07 -050013903 return bgp_show_neighbor_route (vty, peer, AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +000013904 bgp_show_type_neighbor);
13905}
Lou Berger205e6742016-01-12 13:42:11 -050013906
Lou Berger651b4022016-01-12 13:42:07 -050013907DEFUN (show_bgp_ipv6_safi_neighbor_routes,
13908 show_bgp_ipv6_safi_neighbor_routes_cmd,
13909 "show bgp ipv6 (multicast|unicast) neighbors (A.B.C.D|X:X::X:X) routes",
paulfee0f4c2004-09-13 05:12:46 +000013910 SHOW_STR
paulfee0f4c2004-09-13 05:12:46 +000013911 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050013912 "Address family\n"
13913 "Address Family modifier\n"
13914 "Address Family modifier\n"
13915 "Detailed information on TCP and BGP neighbor connections\n"
13916 NEIGHBOR_ADDR_STR
13917 NEIGHBOR_ADDR_STR
13918 "Display routes learned from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000013919{
paulfee0f4c2004-09-13 05:12:46 +000013920 struct peer *peer;
Lou Berger651b4022016-01-12 13:42:07 -050013921 safi_t safi;
paulfee0f4c2004-09-13 05:12:46 +000013922
Lou Berger651b4022016-01-12 13:42:07 -050013923 if (bgp_parse_safi(argv[0], &safi)) {
13924 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
13925 return CMD_WARNING;
13926 }
paulfee0f4c2004-09-13 05:12:46 +000013927
Lou Berger651b4022016-01-12 13:42:07 -050013928 peer = peer_lookup_in_view (vty, NULL, argv[1]);
paulfee0f4c2004-09-13 05:12:46 +000013929 if (! peer)
13930 return CMD_WARNING;
Lou Berger651b4022016-01-12 13:42:07 -050013931
13932 return bgp_show_neighbor_route (vty, peer, AFI_IP6, safi,
13933 bgp_show_type_neighbor);
paulfee0f4c2004-09-13 05:12:46 +000013934}
paulfee0f4c2004-09-13 05:12:46 +000013935
Michael Lambert95cbbd22010-07-23 14:43:04 -040013936DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
13937 show_bgp_view_ipv4_safi_rsclient_route_cmd,
13938 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
13939 SHOW_STR
13940 BGP_STR
13941 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000013942 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040013943 "Address family\n"
13944 "Address Family modifier\n"
13945 "Address Family modifier\n"
13946 "Information about Route Server Client\n"
13947 NEIGHBOR_ADDR_STR
13948 "Network in the BGP routing table to display\n")
13949{
13950 struct bgp *bgp;
13951 struct peer *peer;
13952 safi_t safi;
13953
13954 /* BGP structure lookup. */
13955 if (argc == 4)
13956 {
13957 bgp = bgp_lookup_by_name (argv[0]);
13958 if (bgp == NULL)
13959 {
13960 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
13961 return CMD_WARNING;
13962 }
13963 }
13964 else
13965 {
13966 bgp = bgp_get_default ();
13967 if (bgp == NULL)
13968 {
13969 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
13970 return CMD_WARNING;
13971 }
13972 }
13973
13974 if (argc == 4) {
13975 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
13976 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13977 } else {
13978 peer = peer_lookup_in_view (vty, NULL, argv[1]);
13979 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
13980 }
13981
13982 if (! peer)
13983 return CMD_WARNING;
13984
13985 if (! peer->afc[AFI_IP][safi])
13986 {
13987 vty_out (vty, "%% Activate the neighbor for the address family first%s",
13988 VTY_NEWLINE);
13989 return CMD_WARNING;
13990}
13991
13992 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
13993 PEER_FLAG_RSERVER_CLIENT))
13994 {
13995 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
13996 VTY_NEWLINE);
13997 return CMD_WARNING;
13998 }
13999
14000 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14001 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014002 AFI_IP, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014003}
14004
14005ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
14006 show_bgp_ipv4_safi_rsclient_route_cmd,
14007 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
14008 SHOW_STR
14009 BGP_STR
14010 "Address family\n"
14011 "Address Family modifier\n"
14012 "Address Family modifier\n"
14013 "Information about Route Server Client\n"
14014 NEIGHBOR_ADDR_STR
14015 "Network in the BGP routing table to display\n")
14016
paulfee0f4c2004-09-13 05:12:46 +000014017
Michael Lambert95cbbd22010-07-23 14:43:04 -040014018DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
14019 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
14020 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14021 SHOW_STR
14022 BGP_STR
14023 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014024 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014025 "Address family\n"
14026 "Address Family modifier\n"
14027 "Address Family modifier\n"
14028 "Information about Route Server Client\n"
14029 NEIGHBOR_ADDR_STR
14030 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14031{
14032 struct bgp *bgp;
14033 struct peer *peer;
14034 safi_t safi;
14035
14036 /* BGP structure lookup. */
14037 if (argc == 4)
14038 {
14039 bgp = bgp_lookup_by_name (argv[0]);
14040 if (bgp == NULL)
14041 {
14042 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14043 return CMD_WARNING;
14044 }
14045 }
14046 else
14047 {
14048 bgp = bgp_get_default ();
14049 if (bgp == NULL)
14050 {
14051 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14052 return CMD_WARNING;
14053 }
14054 }
14055
14056 if (argc == 4) {
14057 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14058 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14059 } else {
14060 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14061 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14062 }
14063
14064 if (! peer)
14065 return CMD_WARNING;
14066
14067 if (! peer->afc[AFI_IP][safi])
14068 {
14069 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14070 VTY_NEWLINE);
14071 return CMD_WARNING;
14072}
14073
14074 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
14075 PEER_FLAG_RSERVER_CLIENT))
14076{
14077 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14078 VTY_NEWLINE);
14079 return CMD_WARNING;
14080 }
14081
14082 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
14083 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014084 AFI_IP, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014085}
14086
Lou Bergerf9b6c392016-01-12 13:42:09 -050014087DEFUN (show_ip_bgp_view_rsclient_prefix,
14088 show_ip_bgp_view_rsclient_prefix_cmd,
14089 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14090 SHOW_STR
14091 IP_STR
14092 BGP_STR
14093 "BGP view\n"
14094 "View name\n"
14095 "Information about Route Server Client\n"
14096 NEIGHBOR_ADDR_STR
14097 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14098{
14099 struct bgp *bgp;
14100 struct peer *peer;
14101
14102 /* BGP structure lookup. */
14103 if (argc == 3)
14104 {
14105 bgp = bgp_lookup_by_name (argv[0]);
14106 if (bgp == NULL)
14107 {
14108 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14109 return CMD_WARNING;
14110 }
14111 }
14112 else
14113 {
14114 bgp = bgp_get_default ();
14115 if (bgp == NULL)
14116 {
14117 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14118 return CMD_WARNING;
14119 }
14120 }
14121
14122 if (argc == 3)
14123 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14124 else
14125 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14126
14127 if (! peer)
14128 return CMD_WARNING;
14129
14130 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14131 {
14132 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14133 VTY_NEWLINE);
14134 return CMD_WARNING;
14135}
14136
14137 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14138 PEER_FLAG_RSERVER_CLIENT))
14139{
14140 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14141 VTY_NEWLINE);
14142 return CMD_WARNING;
14143 }
14144
14145 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
14146 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014147 AFI_IP, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014148}
14149
14150ALIAS (show_ip_bgp_view_rsclient_prefix,
14151 show_ip_bgp_rsclient_prefix_cmd,
14152 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14153 SHOW_STR
14154 IP_STR
14155 BGP_STR
14156 "Information about Route Server Client\n"
14157 NEIGHBOR_ADDR_STR
14158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
14159
Michael Lambert95cbbd22010-07-23 14:43:04 -040014160ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
14161 show_bgp_ipv4_safi_rsclient_prefix_cmd,
14162 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
14163 SHOW_STR
14164 BGP_STR
14165 "Address family\n"
14166 "Address Family modifier\n"
14167 "Address Family modifier\n"
14168 "Information about Route Server Client\n"
14169 NEIGHBOR_ADDR_STR
14170 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000014171
Lou Bergerf9b6c392016-01-12 13:42:09 -050014172DEFUN (show_bgp_view_ipv6_neighbor_routes,
Lou Berger651b4022016-01-12 13:42:07 -050014173 show_bgp_view_ipv6_neighbor_routes_cmd,
14174 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
paulbb46e942003-10-24 19:02:03 +000014175 SHOW_STR
14176 BGP_STR
14177 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014178 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014179 "Address family\n"
paulbb46e942003-10-24 19:02:03 +000014180 "Detailed information on TCP and BGP neighbor connections\n"
14181 "Neighbor to display information about\n"
14182 "Neighbor to display information about\n"
14183 "Display routes learned from neighbor\n")
14184{
14185 struct peer *peer;
14186
14187 if (argc == 2)
14188 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14189 else
14190 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14191
14192 if (! peer)
14193 return CMD_WARNING;
14194
14195 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14196 bgp_show_type_neighbor);
14197}
14198
Lou Berger651b4022016-01-12 13:42:07 -050014199DEFUN (show_bgp_view_neighbor_damp,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014200 show_bgp_view_neighbor_damp_cmd,
14201 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14202 SHOW_STR
14203 BGP_STR
14204 "BGP view\n"
14205 "View name\n"
14206 "Detailed information on TCP and BGP neighbor connections\n"
14207 "Neighbor to display information about\n"
14208 "Neighbor to display information about\n"
14209 "Display the dampened routes received from neighbor\n")
14210{
14211 struct peer *peer;
14212
14213 if (argc == 2)
14214 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14215 else
14216 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14217
14218 if (! peer)
14219 return CMD_WARNING;
14220
14221 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14222 bgp_show_type_damp_neighbor);
14223}
14224
14225DEFUN (show_bgp_view_ipv6_neighbor_damp,
Lou Berger651b4022016-01-12 13:42:07 -050014226 show_bgp_view_ipv6_neighbor_damp_cmd,
14227 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
paulbb46e942003-10-24 19:02:03 +000014228 SHOW_STR
14229 BGP_STR
14230 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014231 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014232 "Address family\n"
14233 "Detailed information on TCP and BGP neighbor connections\n"
14234 "Neighbor to display information about\n"
14235 "Neighbor to display information about\n"
paulbb46e942003-10-24 19:02:03 +000014236 "Display the dampened routes received from neighbor\n")
14237{
14238 struct peer *peer;
14239
14240 if (argc == 2)
14241 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14242 else
14243 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14244
14245 if (! peer)
14246 return CMD_WARNING;
14247
14248 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14249 bgp_show_type_damp_neighbor);
14250}
14251
Lou Bergerf9b6c392016-01-12 13:42:09 -050014252DEFUN (show_bgp_view_ipv6_neighbor_flap,
Lou Berger651b4022016-01-12 13:42:07 -050014253 show_bgp_view_ipv6_neighbor_flap_cmd,
14254 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
paulbb46e942003-10-24 19:02:03 +000014255 SHOW_STR
14256 BGP_STR
14257 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014258 "View name\n"
paulbb46e942003-10-24 19:02:03 +000014259 "Address family\n"
14260 "Detailed information on TCP and BGP neighbor connections\n"
14261 "Neighbor to display information about\n"
14262 "Neighbor to display information about\n"
14263 "Display the dampened routes received from neighbor\n")
paulbb46e942003-10-24 19:02:03 +000014264{
14265 struct peer *peer;
14266
14267 if (argc == 2)
14268 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14269 else
14270 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14271
14272 if (! peer)
14273 return CMD_WARNING;
14274
14275 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14276 bgp_show_type_flap_neighbor);
14277}
14278
Lou Bergerf9b6c392016-01-12 13:42:09 -050014279DEFUN (show_bgp_view_neighbor_flap,
14280 show_bgp_view_neighbor_flap_cmd,
14281 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14282 SHOW_STR
14283 BGP_STR
14284 "BGP view\n"
14285 "View name\n"
14286 "Detailed information on TCP and BGP neighbor connections\n"
14287 "Neighbor to display information about\n"
14288 "Neighbor to display information about\n"
14289 "Display flap statistics of the routes learned from neighbor\n")
14290{
14291 struct peer *peer;
14292
14293 if (argc == 2)
14294 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14295 else
14296 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14297
14298 if (! peer)
14299 return CMD_WARNING;
14300
14301 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14302 bgp_show_type_flap_neighbor);
14303}
14304
14305ALIAS (show_bgp_view_neighbor_flap,
14306 show_bgp_neighbor_flap_cmd,
14307 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14308 SHOW_STR
14309 BGP_STR
14310 "Detailed information on TCP and BGP neighbor connections\n"
14311 "Neighbor to display information about\n"
14312 "Neighbor to display information about\n"
14313 "Display flap statistics of the routes learned from neighbor\n")
14314
14315ALIAS (show_bgp_view_neighbor_damp,
14316 show_bgp_neighbor_damp_cmd,
14317 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
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 the dampened routes received from neighbor\n")
14324
14325DEFUN (show_bgp_view_neighbor_routes,
14326 show_bgp_view_neighbor_routes_cmd,
14327 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
14328 SHOW_STR
14329 BGP_STR
14330 "BGP view\n"
14331 "View name\n"
14332 "Detailed information on TCP and BGP neighbor connections\n"
14333 "Neighbor to display information about\n"
14334 "Neighbor to display information about\n"
14335 "Display routes learned from neighbor\n")
14336{
14337 struct peer *peer;
14338
14339 if (argc == 2)
14340 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14341 else
14342 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14343
14344 if (! peer)
14345 return CMD_WARNING;
14346
14347 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
14348 bgp_show_type_neighbor);
14349}
14350
14351ALIAS (show_bgp_view_neighbor_routes,
14352 show_bgp_neighbor_routes_cmd,
14353 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
14354 SHOW_STR
14355 BGP_STR
14356 "Detailed information on TCP and BGP neighbor connections\n"
14357 "Neighbor to display information about\n"
14358 "Neighbor to display information about\n"
14359 "Display routes learned from neighbor\n")
14360
paulbb46e942003-10-24 19:02:03 +000014361ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000014362 show_bgp_ipv6_neighbor_routes_cmd,
14363 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
14364 SHOW_STR
14365 BGP_STR
14366 "Address family\n"
14367 "Detailed information on TCP and BGP neighbor connections\n"
14368 "Neighbor to display information about\n"
14369 "Neighbor to display information about\n"
14370 "Display routes learned from neighbor\n")
14371
Lou Bergerf9b6c392016-01-12 13:42:09 -050014372/* old command */
14373ALIAS (show_bgp_view_neighbor_routes,
14374 ipv6_bgp_neighbor_routes_cmd,
14375 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
14376 SHOW_STR
14377 IPV6_STR
14378 BGP_STR
14379 "Detailed information on TCP and BGP neighbor connections\n"
14380 "Neighbor to display information about\n"
14381 "Neighbor to display information about\n"
14382 "Display routes learned from neighbor\n")
14383
14384/* old command */
14385DEFUN (ipv6_mbgp_neighbor_routes,
14386 ipv6_mbgp_neighbor_routes_cmd,
14387 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
14388 SHOW_STR
14389 IPV6_STR
14390 MBGP_STR
14391 "Detailed information on TCP and BGP neighbor connections\n"
14392 "Neighbor to display information about\n"
14393 "Neighbor to display information about\n"
14394 "Display routes learned from neighbor\n")
14395{
14396 struct peer *peer;
14397
14398 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14399 if (! peer)
14400 return CMD_WARNING;
14401
14402 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
14403 bgp_show_type_neighbor);
14404}
14405
paulbb46e942003-10-24 19:02:03 +000014406ALIAS (show_bgp_view_neighbor_flap,
14407 show_bgp_ipv6_neighbor_flap_cmd,
14408 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
14409 SHOW_STR
14410 BGP_STR
14411 "Address family\n"
14412 "Detailed information on TCP and BGP neighbor connections\n"
14413 "Neighbor to display information about\n"
14414 "Neighbor to display information about\n"
14415 "Display flap statistics of the routes learned from neighbor\n")
14416
14417ALIAS (show_bgp_view_neighbor_damp,
paulbb46e942003-10-24 19:02:03 +000014418 show_bgp_ipv6_neighbor_damp_cmd,
14419 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
14420 SHOW_STR
14421 BGP_STR
14422 "Address family\n"
14423 "Detailed information on TCP and BGP neighbor connections\n"
14424 "Neighbor to display information about\n"
14425 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000014426 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000014427
Lou Bergerf9b6c392016-01-12 13:42:09 -050014428DEFUN (show_bgp_view_rsclient,
14429 show_bgp_view_rsclient_cmd,
14430 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
14431 SHOW_STR
14432 BGP_STR
14433 "BGP view\n"
14434 "View name\n"
14435 "Information about Route Server Client\n"
14436 NEIGHBOR_ADDR_STR)
14437{
14438 struct bgp_table *table;
14439 struct peer *peer;
14440
14441 if (argc == 2)
14442 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14443 else
14444 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14445
14446 if (! peer)
14447 return CMD_WARNING;
14448
14449 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14450 {
14451 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14452 VTY_NEWLINE);
14453 return CMD_WARNING;
14454 }
14455
14456 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14457 PEER_FLAG_RSERVER_CLIENT))
14458 {
14459 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14460 VTY_NEWLINE);
14461 return CMD_WARNING;
14462 }
14463
14464 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14465
14466 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14467}
14468
14469ALIAS (show_bgp_view_rsclient,
14470 show_bgp_rsclient_cmd,
14471 "show bgp rsclient (A.B.C.D|X:X::X:X)",
14472 SHOW_STR
14473 BGP_STR
14474 "Information about Route Server Client\n"
14475 NEIGHBOR_ADDR_STR)
14476
Lou Berger651b4022016-01-12 13:42:07 -050014477DEFUN (show_bgp_view_ipv4_rsclient,
14478 show_bgp_view_ipv4_rsclient_cmd,
14479 "show bgp view WORD ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014480 SHOW_STR
14481 BGP_STR
14482 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014483 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014484 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014485 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014486 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014487{
Lou Berger651b4022016-01-12 13:42:07 -050014488 struct bgp_table *table;
14489 struct peer *peer;
14490
14491 if (argc == 2)
14492 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14493 else
14494 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14495
14496 if (! peer)
14497 return CMD_WARNING;
14498
14499 if (! peer->afc[AFI_IP][SAFI_UNICAST])
14500 {
14501 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14502 VTY_NEWLINE);
14503 return CMD_WARNING;
14504 }
14505
14506 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
14507 PEER_FLAG_RSERVER_CLIENT))
14508 {
14509 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14510 VTY_NEWLINE);
14511 return CMD_WARNING;
14512 }
14513
14514 table = peer->rib[AFI_IP][SAFI_UNICAST];
14515
14516 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14517}
14518DEFUN (show_bgp_view_ipv6_rsclient,
14519 show_bgp_view_ipv6_rsclient_cmd,
14520 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X)",
14521 SHOW_STR
14522 BGP_STR
14523 "BGP view\n"
14524 "BGP view name\n"
14525 "Address Family\n"
14526 "Information about Route Server Client\n"
14527 NEIGHBOR_ADDR_STR2)
14528{
14529 struct bgp_table *table;
14530 struct peer *peer;
paulfee0f4c2004-09-13 05:12:46 +000014531
14532 if (argc == 2)
14533 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14534 else
14535 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14536
14537 if (! peer)
14538 return CMD_WARNING;
14539
14540 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14541 {
14542 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14543 VTY_NEWLINE);
14544 return CMD_WARNING;
14545 }
14546
14547 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14548 PEER_FLAG_RSERVER_CLIENT))
14549 {
14550 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14551 VTY_NEWLINE);
14552 return CMD_WARNING;
14553 }
14554
14555 table = peer->rib[AFI_IP6][SAFI_UNICAST];
14556
ajs5a646652004-11-05 01:25:55 +000014557 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000014558}
14559
Lou Berger651b4022016-01-12 13:42:07 -050014560ALIAS (show_bgp_view_ipv4_rsclient,
14561 show_bgp_ipv4_rsclient_cmd,
14562 "show bgp ipv4 rsclient (A.B.C.D|X:X::X:X)",
paulfee0f4c2004-09-13 05:12:46 +000014563 SHOW_STR
14564 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014565 "Address Family\n"
paulfee0f4c2004-09-13 05:12:46 +000014566 "Information about Route Server Client\n"
Lou Berger651b4022016-01-12 13:42:07 -050014567 NEIGHBOR_ADDR_STR2)
14568
Lou Berger651b4022016-01-12 13:42:07 -050014569ALIAS (show_bgp_view_ipv6_rsclient,
14570 show_bgp_ipv6_rsclient_cmd,
14571 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X)",
14572 SHOW_STR
14573 BGP_STR
14574 "Address Family\n"
14575 "Information about Route Server Client\n"
14576 NEIGHBOR_ADDR_STR2)
paulfee0f4c2004-09-13 05:12:46 +000014577
Michael Lambert95cbbd22010-07-23 14:43:04 -040014578DEFUN (show_bgp_view_ipv6_safi_rsclient,
14579 show_bgp_view_ipv6_safi_rsclient_cmd,
14580 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14581 SHOW_STR
14582 BGP_STR
14583 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014584 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014585 "Address family\n"
14586 "Address Family modifier\n"
14587 "Address Family modifier\n"
14588 "Information about Route Server Client\n"
14589 NEIGHBOR_ADDR_STR)
14590{
14591 struct bgp_table *table;
14592 struct peer *peer;
14593 safi_t safi;
14594
14595 if (argc == 3) {
14596 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14597 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14598 } else {
14599 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14600 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14601 }
14602
14603 if (! peer)
14604 return CMD_WARNING;
14605
14606 if (! peer->afc[AFI_IP6][safi])
14607 {
14608 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14609 VTY_NEWLINE);
14610 return CMD_WARNING;
14611 }
14612
14613 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14614 PEER_FLAG_RSERVER_CLIENT))
14615 {
14616 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14617 VTY_NEWLINE);
14618 return CMD_WARNING;
14619 }
14620
14621 table = peer->rib[AFI_IP6][safi];
14622
14623 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
14624}
14625
14626ALIAS (show_bgp_view_ipv6_safi_rsclient,
14627 show_bgp_ipv6_safi_rsclient_cmd,
14628 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
14629 SHOW_STR
14630 BGP_STR
14631 "Address family\n"
14632 "Address Family modifier\n"
14633 "Address Family modifier\n"
14634 "Information about Route Server Client\n"
14635 NEIGHBOR_ADDR_STR)
14636
paulfee0f4c2004-09-13 05:12:46 +000014637DEFUN (show_bgp_view_rsclient_route,
14638 show_bgp_view_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014639 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14640 SHOW_STR
14641 BGP_STR
14642 "BGP view\n"
14643 "View name\n"
14644 "Information about Route Server Client\n"
14645 NEIGHBOR_ADDR_STR
14646 "Network in the BGP routing table to display\n")
14647{
14648 struct bgp *bgp;
14649 struct peer *peer;
14650
14651 /* BGP structure lookup. */
14652 if (argc == 3)
14653 {
14654 bgp = bgp_lookup_by_name (argv[0]);
14655 if (bgp == NULL)
14656 {
14657 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14658 return CMD_WARNING;
14659 }
14660 }
14661 else
14662 {
14663 bgp = bgp_get_default ();
14664 if (bgp == NULL)
14665 {
14666 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14667 return CMD_WARNING;
14668 }
14669 }
14670
14671 if (argc == 3)
14672 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14673 else
14674 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14675
14676 if (! peer)
14677 return CMD_WARNING;
14678
14679 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14680 {
14681 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14682 VTY_NEWLINE);
14683 return CMD_WARNING;
14684 }
14685
14686 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14687 PEER_FLAG_RSERVER_CLIENT))
14688 {
14689 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14690 VTY_NEWLINE);
14691 return CMD_WARNING;
14692 }
14693
14694 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14695 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014696 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014697}
14698
14699DEFUN (show_bgp_view_ipv6_rsclient_route,
14700 show_bgp_view_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014701 "show bgp view WORD ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014702 SHOW_STR
14703 BGP_STR
14704 "BGP view\n"
Lou Berger651b4022016-01-12 13:42:07 -050014705 "BGP view name\n"
14706 "IP6_STR"
paulfee0f4c2004-09-13 05:12:46 +000014707 "Information about Route Server Client\n"
14708 NEIGHBOR_ADDR_STR
14709 "Network in the BGP routing table to display\n")
14710{
14711 struct bgp *bgp;
14712 struct peer *peer;
14713
14714 /* BGP structure lookup. */
14715 if (argc == 3)
14716 {
14717 bgp = bgp_lookup_by_name (argv[0]);
14718 if (bgp == NULL)
14719 {
14720 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14721 return CMD_WARNING;
14722 }
14723 }
14724 else
14725 {
14726 bgp = bgp_get_default ();
14727 if (bgp == NULL)
14728 {
14729 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14730 return CMD_WARNING;
14731 }
14732 }
14733
14734 if (argc == 3)
14735 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14736 else
14737 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14738
14739 if (! peer)
14740 return CMD_WARNING;
14741
14742 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14743 {
14744 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14745 VTY_NEWLINE);
14746 return CMD_WARNING;
14747 }
14748
14749 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14750 PEER_FLAG_RSERVER_CLIENT))
14751 {
14752 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14753 VTY_NEWLINE);
14754 return CMD_WARNING;
14755 }
14756
14757 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14758 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014759 AFI_IP6, SAFI_UNICAST, NULL, 0, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014760}
14761
Lou Bergerf9b6c392016-01-12 13:42:09 -050014762ALIAS (show_bgp_view_ipv6_rsclient_route,
paulfee0f4c2004-09-13 05:12:46 +000014763 show_bgp_rsclient_route_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014764 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14765 SHOW_STR
14766 BGP_STR
14767 "Information about Route Server Client\n"
14768 NEIGHBOR_ADDR_STR
14769 "Network in the BGP routing table to display\n")
14770
14771ALIAS (show_bgp_view_ipv6_rsclient_route,
14772 show_bgp_ipv6_rsclient_route_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014773 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
paulfee0f4c2004-09-13 05:12:46 +000014774 SHOW_STR
14775 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050014776 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014777 "Information about Route Server Client\n"
14778 NEIGHBOR_ADDR_STR
14779 "Network in the BGP routing table to display\n")
14780
Michael Lambert95cbbd22010-07-23 14:43:04 -040014781DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
14782 show_bgp_view_ipv6_safi_rsclient_route_cmd,
14783 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14784 SHOW_STR
14785 BGP_STR
14786 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014787 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040014788 "Address family\n"
14789 "Address Family modifier\n"
14790 "Address Family modifier\n"
14791 "Information about Route Server Client\n"
14792 NEIGHBOR_ADDR_STR
14793 "Network in the BGP routing table to display\n")
14794{
14795 struct bgp *bgp;
14796 struct peer *peer;
14797 safi_t safi;
14798
14799 /* BGP structure lookup. */
14800 if (argc == 4)
14801 {
14802 bgp = bgp_lookup_by_name (argv[0]);
14803 if (bgp == NULL)
14804 {
14805 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14806 return CMD_WARNING;
14807 }
14808 }
14809 else
14810 {
14811 bgp = bgp_get_default ();
14812 if (bgp == NULL)
14813 {
14814 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14815 return CMD_WARNING;
14816 }
14817 }
14818
14819 if (argc == 4) {
14820 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
14821 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14822 } else {
14823 peer = peer_lookup_in_view (vty, NULL, argv[1]);
14824 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
14825 }
14826
14827 if (! peer)
14828 return CMD_WARNING;
14829
14830 if (! peer->afc[AFI_IP6][safi])
14831 {
14832 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14833 VTY_NEWLINE);
14834 return CMD_WARNING;
14835}
14836
14837 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
14838 PEER_FLAG_RSERVER_CLIENT))
14839 {
14840 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14841 VTY_NEWLINE);
14842 return CMD_WARNING;
14843 }
14844
14845 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
14846 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014847 AFI_IP6, safi, NULL, 0, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040014848}
14849
14850ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
14851 show_bgp_ipv6_safi_rsclient_route_cmd,
14852 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
14853 SHOW_STR
14854 BGP_STR
14855 "Address family\n"
14856 "Address Family modifier\n"
14857 "Address Family modifier\n"
14858 "Information about Route Server Client\n"
14859 NEIGHBOR_ADDR_STR
14860 "Network in the BGP routing table to display\n")
14861
Lou Berger651b4022016-01-12 13:42:07 -050014862
paulfee0f4c2004-09-13 05:12:46 +000014863DEFUN (show_bgp_view_rsclient_prefix,
14864 show_bgp_view_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014865 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14866 SHOW_STR
14867 BGP_STR
14868 "BGP view\n"
14869 "View name\n"
14870 "Information about Route Server Client\n"
14871 NEIGHBOR_ADDR_STR
14872 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14873{
14874 struct bgp *bgp;
14875 struct peer *peer;
14876
14877 /* BGP structure lookup. */
14878 if (argc == 3)
14879 {
14880 bgp = bgp_lookup_by_name (argv[0]);
14881 if (bgp == NULL)
14882 {
14883 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14884 return CMD_WARNING;
14885 }
14886 }
14887 else
14888 {
14889 bgp = bgp_get_default ();
14890 if (bgp == NULL)
14891 {
14892 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14893 return CMD_WARNING;
14894 }
14895 }
14896
14897 if (argc == 3)
14898 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14899 else
14900 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14901
14902 if (! peer)
14903 return CMD_WARNING;
14904
14905 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14906 {
14907 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14908 VTY_NEWLINE);
14909 return CMD_WARNING;
14910 }
14911
14912 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14913 PEER_FLAG_RSERVER_CLIENT))
14914 {
14915 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14916 VTY_NEWLINE);
14917 return CMD_WARNING;
14918 }
14919
14920 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14921 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014922 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
Lou Bergerf9b6c392016-01-12 13:42:09 -050014923}
14924
14925DEFUN (show_bgp_view_ipv6_rsclient_prefix,
14926 show_bgp_view_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014927 "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 +000014928 SHOW_STR
14929 BGP_STR
14930 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000014931 "View name\n"
Lou Berger651b4022016-01-12 13:42:07 -050014932 IP6_STR
paulfee0f4c2004-09-13 05:12:46 +000014933 "Information about Route Server Client\n"
14934 NEIGHBOR_ADDR_STR
14935 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14936{
14937 struct bgp *bgp;
14938 struct peer *peer;
14939
14940 /* BGP structure lookup. */
14941 if (argc == 3)
14942 {
14943 bgp = bgp_lookup_by_name (argv[0]);
14944 if (bgp == NULL)
14945 {
14946 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
14947 return CMD_WARNING;
14948 }
14949 }
14950 else
14951 {
14952 bgp = bgp_get_default ();
14953 if (bgp == NULL)
14954 {
14955 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
14956 return CMD_WARNING;
14957 }
14958 }
14959
14960 if (argc == 3)
14961 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
14962 else
14963 peer = peer_lookup_in_view (vty, NULL, argv[0]);
14964
14965 if (! peer)
14966 return CMD_WARNING;
14967
14968 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
14969 {
14970 vty_out (vty, "%% Activate the neighbor for the address family first%s",
14971 VTY_NEWLINE);
14972 return CMD_WARNING;
14973 }
14974
14975 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
14976 PEER_FLAG_RSERVER_CLIENT))
14977 {
14978 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
14979 VTY_NEWLINE);
14980 return CMD_WARNING;
14981 }
14982
14983 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
14984 (argc == 3) ? argv[2] : argv[1],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070014985 AFI_IP6, SAFI_UNICAST, NULL, 1, BGP_PATH_ALL);
paulfee0f4c2004-09-13 05:12:46 +000014986}
14987
Lou Bergerf9b6c392016-01-12 13:42:09 -050014988ALIAS (show_bgp_view_ipv6_rsclient_prefix,
paulfee0f4c2004-09-13 05:12:46 +000014989 show_bgp_rsclient_prefix_cmd,
Lou Bergerf9b6c392016-01-12 13:42:09 -050014990 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
14991 SHOW_STR
14992 BGP_STR
14993 "Information about Route Server Client\n"
14994 NEIGHBOR_ADDR_STR
14995 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
14996
14997ALIAS (show_bgp_view_ipv6_rsclient_prefix,
14998 show_bgp_ipv6_rsclient_prefix_cmd,
Lou Berger651b4022016-01-12 13:42:07 -050014999 "show bgp ipv6 rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
paulfee0f4c2004-09-13 05:12:46 +000015000 SHOW_STR
15001 BGP_STR
15002 "Information about Route Server Client\n"
15003 NEIGHBOR_ADDR_STR
15004 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
15005
Michael Lambert95cbbd22010-07-23 14:43:04 -040015006DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
15007 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
15008 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15009 SHOW_STR
15010 BGP_STR
15011 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000015012 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040015013 "Address family\n"
15014 "Address Family modifier\n"
15015 "Address Family modifier\n"
15016 "Information about Route Server Client\n"
15017 NEIGHBOR_ADDR_STR
15018 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15019{
15020 struct bgp *bgp;
15021 struct peer *peer;
15022 safi_t safi;
15023
15024 /* BGP structure lookup. */
15025 if (argc == 4)
15026 {
15027 bgp = bgp_lookup_by_name (argv[0]);
15028 if (bgp == NULL)
15029 {
15030 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
15031 return CMD_WARNING;
15032 }
15033 }
15034 else
15035 {
15036 bgp = bgp_get_default ();
15037 if (bgp == NULL)
15038 {
15039 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
15040 return CMD_WARNING;
15041 }
15042 }
15043
15044 if (argc == 4) {
15045 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
15046 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15047 } else {
15048 peer = peer_lookup_in_view (vty, NULL, argv[1]);
15049 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
15050 }
15051
15052 if (! peer)
15053 return CMD_WARNING;
15054
15055 if (! peer->afc[AFI_IP6][safi])
15056 {
15057 vty_out (vty, "%% Activate the neighbor for the address family first%s",
15058 VTY_NEWLINE);
15059 return CMD_WARNING;
15060}
15061
15062 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
15063 PEER_FLAG_RSERVER_CLIENT))
15064{
15065 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
15066 VTY_NEWLINE);
15067 return CMD_WARNING;
15068 }
15069
15070 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
15071 (argc == 4) ? argv[3] : argv[2],
Daniel Walton59fe0ee2015-05-19 17:58:11 -070015072 AFI_IP6, safi, NULL, 1, BGP_PATH_ALL);
Michael Lambert95cbbd22010-07-23 14:43:04 -040015073}
15074
15075ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
15076 show_bgp_ipv6_safi_rsclient_prefix_cmd,
15077 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
15078 SHOW_STR
15079 BGP_STR
15080 "Address family\n"
15081 "Address Family modifier\n"
15082 "Address Family modifier\n"
15083 "Information about Route Server Client\n"
15084 NEIGHBOR_ADDR_STR
15085 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
15086
paul718e3742002-12-13 20:15:29 +000015087struct bgp_table *bgp_distance_table;
15088
15089struct bgp_distance
15090{
15091 /* Distance value for the IP source prefix. */
15092 u_char distance;
15093
15094 /* Name of the access-list to be matched. */
15095 char *access_list;
15096};
15097
paul94f2b392005-06-28 12:44:16 +000015098static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080015099bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000015100{
Stephen Hemminger393deb92008-08-18 14:13:29 -070015101 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000015102}
15103
paul94f2b392005-06-28 12:44:16 +000015104static void
paul718e3742002-12-13 20:15:29 +000015105bgp_distance_free (struct bgp_distance *bdistance)
15106{
15107 XFREE (MTYPE_BGP_DISTANCE, bdistance);
15108}
15109
paul94f2b392005-06-28 12:44:16 +000015110static int
paulfd79ac92004-10-13 05:06:08 +000015111bgp_distance_set (struct vty *vty, const char *distance_str,
15112 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015113{
15114 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015115 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015116 u_char distance;
15117 struct bgp_node *rn;
15118 struct bgp_distance *bdistance;
15119
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015120 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015121 if (ret == 0)
15122 {
15123 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15124 return CMD_WARNING;
15125 }
15126
15127 distance = atoi (distance_str);
15128
15129 /* Get BGP distance node. */
15130 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
15131 if (rn->info)
15132 {
15133 bdistance = rn->info;
15134 bgp_unlock_node (rn);
15135 }
15136 else
15137 {
15138 bdistance = bgp_distance_new ();
15139 rn->info = bdistance;
15140 }
15141
15142 /* Set distance value. */
15143 bdistance->distance = distance;
15144
15145 /* Reset access-list configuration. */
15146 if (bdistance->access_list)
15147 {
15148 free (bdistance->access_list);
15149 bdistance->access_list = NULL;
15150 }
15151 if (access_list_str)
15152 bdistance->access_list = strdup (access_list_str);
15153
15154 return CMD_SUCCESS;
15155}
15156
paul94f2b392005-06-28 12:44:16 +000015157static int
paulfd79ac92004-10-13 05:06:08 +000015158bgp_distance_unset (struct vty *vty, const char *distance_str,
15159 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000015160{
15161 int ret;
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015162 struct prefix p;
paul718e3742002-12-13 20:15:29 +000015163 u_char distance;
15164 struct bgp_node *rn;
15165 struct bgp_distance *bdistance;
15166
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015167 ret = str2prefix (ip_str, &p);
paul718e3742002-12-13 20:15:29 +000015168 if (ret == 0)
15169 {
15170 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
15171 return CMD_WARNING;
15172 }
15173
15174 distance = atoi (distance_str);
15175
15176 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
15177 if (! rn)
15178 {
15179 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
15180 return CMD_WARNING;
15181 }
15182
15183 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010015184
15185 if (bdistance->distance != distance)
15186 {
15187 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
15188 return CMD_WARNING;
15189 }
15190
paul718e3742002-12-13 20:15:29 +000015191 if (bdistance->access_list)
15192 free (bdistance->access_list);
15193 bgp_distance_free (bdistance);
15194
15195 rn->info = NULL;
15196 bgp_unlock_node (rn);
15197 bgp_unlock_node (rn);
15198
15199 return CMD_SUCCESS;
15200}
15201
paul718e3742002-12-13 20:15:29 +000015202/* Apply BGP information to distance method. */
15203u_char
15204bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15205{
15206 struct bgp_node *rn;
15207 struct prefix_ipv4 q;
15208 struct peer *peer;
15209 struct bgp_distance *bdistance;
15210 struct access_list *alist;
15211 struct bgp_static *bgp_static;
15212
15213 if (! bgp)
15214 return 0;
15215
15216 if (p->family != AF_INET)
15217 return 0;
15218
15219 peer = rinfo->peer;
15220
15221 if (peer->su.sa.sa_family != AF_INET)
15222 return 0;
15223
15224 memset (&q, 0, sizeof (struct prefix_ipv4));
15225 q.family = AF_INET;
15226 q.prefix = peer->su.sin.sin_addr;
15227 q.prefixlen = IPV4_MAX_BITLEN;
15228
15229 /* Check source address. */
15230 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15231 if (rn)
15232 {
15233 bdistance = rn->info;
15234 bgp_unlock_node (rn);
15235
15236 if (bdistance->access_list)
15237 {
15238 alist = access_list_lookup (AFI_IP, bdistance->access_list);
15239 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15240 return bdistance->distance;
15241 }
15242 else
15243 return bdistance->distance;
15244 }
15245
15246 /* Backdoor check. */
15247 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
15248 if (rn)
15249 {
15250 bgp_static = rn->info;
15251 bgp_unlock_node (rn);
15252
15253 if (bgp_static->backdoor)
15254 {
15255 if (bgp->distance_local)
15256 return bgp->distance_local;
15257 else
15258 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15259 }
15260 }
15261
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000015262 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000015263 {
15264 if (bgp->distance_ebgp)
15265 return bgp->distance_ebgp;
15266 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15267 }
15268 else
15269 {
15270 if (bgp->distance_ibgp)
15271 return bgp->distance_ibgp;
15272 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15273 }
15274}
15275
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015276#ifdef HAVE_IPV6
15277/* Apply BGP information to ipv6 distance method. */
15278u_char
15279ipv6_bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
15280{
15281 struct bgp_node *rn;
15282 struct prefix_ipv6 q;
15283 struct peer *peer;
15284 struct bgp_distance *bdistance;
15285 struct access_list *alist;
15286 struct bgp_static *bgp_static;
15287
15288 if (! bgp)
15289 return 0;
15290
15291 if (p->family != AF_INET6)
15292 return 0;
15293
15294 peer = rinfo->peer;
15295
15296 if (peer->su.sa.sa_family != AF_INET6)
15297 return 0;
15298
15299 memset (&q, 0, sizeof (struct prefix_ipv6));
15300 q.family = AF_INET;
15301 q.prefix = peer->su.sin6.sin6_addr;
15302 q.prefixlen = IPV6_MAX_BITLEN;
15303
15304 /* Check source address. */
15305 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
15306 if (rn)
15307 {
15308 bdistance = rn->info;
15309 bgp_unlock_node (rn);
15310
15311 if (bdistance->access_list)
15312 {
15313 alist = access_list_lookup (AFI_IP6, bdistance->access_list);
15314 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
15315 return bdistance->distance;
15316 }
15317 else
15318 return bdistance->distance;
15319 }
15320 /* Backdoor check. */
15321 rn = bgp_node_lookup (bgp->route[AFI_IP6][SAFI_UNICAST], p);
15322 if (rn)
15323 {
15324 bgp_static = rn->info;
15325 bgp_unlock_node (rn);
15326
15327 if (bgp_static->backdoor)
15328 {
15329 if (bgp->ipv6_distance_local)
15330 return bgp->ipv6_distance_local;
15331 else
15332 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15333 }
15334 }
15335
15336 if (peer_sort (peer) == BGP_PEER_EBGP)
15337 {
15338 if (bgp->ipv6_distance_ebgp)
15339 return bgp->ipv6_distance_ebgp;
15340 return ZEBRA_EBGP_DISTANCE_DEFAULT;
15341 }
15342 else
15343 {
15344 if (bgp->ipv6_distance_ibgp)
15345 return bgp->ipv6_distance_ibgp;
15346 return ZEBRA_IBGP_DISTANCE_DEFAULT;
15347 }
15348}
15349#endif /* HAVE_IPV6 */
15350
paul718e3742002-12-13 20:15:29 +000015351DEFUN (bgp_distance,
15352 bgp_distance_cmd,
15353 "distance bgp <1-255> <1-255> <1-255>",
15354 "Define an administrative distance\n"
15355 "BGP distance\n"
15356 "Distance for routes external to the AS\n"
15357 "Distance for routes internal to the AS\n"
15358 "Distance for local routes\n")
15359{
15360 struct bgp *bgp;
15361
15362 bgp = vty->index;
15363
15364 bgp->distance_ebgp = atoi (argv[0]);
15365 bgp->distance_ibgp = atoi (argv[1]);
15366 bgp->distance_local = atoi (argv[2]);
15367 return CMD_SUCCESS;
15368}
15369
15370DEFUN (no_bgp_distance,
15371 no_bgp_distance_cmd,
15372 "no distance bgp <1-255> <1-255> <1-255>",
15373 NO_STR
15374 "Define an administrative distance\n"
15375 "BGP distance\n"
15376 "Distance for routes external to the AS\n"
15377 "Distance for routes internal to the AS\n"
15378 "Distance for local routes\n")
15379{
15380 struct bgp *bgp;
15381
15382 bgp = vty->index;
15383
15384 bgp->distance_ebgp= 0;
15385 bgp->distance_ibgp = 0;
15386 bgp->distance_local = 0;
15387 return CMD_SUCCESS;
15388}
15389
15390ALIAS (no_bgp_distance,
15391 no_bgp_distance2_cmd,
15392 "no distance bgp",
15393 NO_STR
15394 "Define an administrative distance\n"
15395 "BGP distance\n")
15396
15397DEFUN (bgp_distance_source,
15398 bgp_distance_source_cmd,
15399 "distance <1-255> A.B.C.D/M",
15400 "Define an administrative distance\n"
15401 "Administrative distance\n"
15402 "IP source prefix\n")
15403{
15404 bgp_distance_set (vty, argv[0], argv[1], NULL);
15405 return CMD_SUCCESS;
15406}
15407
15408DEFUN (no_bgp_distance_source,
15409 no_bgp_distance_source_cmd,
15410 "no distance <1-255> A.B.C.D/M",
15411 NO_STR
15412 "Define an administrative distance\n"
15413 "Administrative distance\n"
15414 "IP source prefix\n")
15415{
15416 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15417 return CMD_SUCCESS;
15418}
15419
15420DEFUN (bgp_distance_source_access_list,
15421 bgp_distance_source_access_list_cmd,
15422 "distance <1-255> A.B.C.D/M WORD",
15423 "Define an administrative distance\n"
15424 "Administrative distance\n"
15425 "IP source prefix\n"
15426 "Access list name\n")
15427{
15428 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15429 return CMD_SUCCESS;
15430}
15431
15432DEFUN (no_bgp_distance_source_access_list,
15433 no_bgp_distance_source_access_list_cmd,
15434 "no distance <1-255> A.B.C.D/M WORD",
15435 NO_STR
15436 "Define an administrative distance\n"
15437 "Administrative distance\n"
15438 "IP source prefix\n"
15439 "Access list name\n")
15440{
15441 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15442 return CMD_SUCCESS;
15443}
David Lamparter6b0655a2014-06-04 06:53:35 +020015444
Roman Hoog Antink6184c392014-03-17 14:01:42 +010015445#ifdef HAVE_IPV6
15446DEFUN (ipv6_bgp_distance,
15447 ipv6_bgp_distance_cmd,
15448 "distance bgp <1-255> <1-255> <1-255>",
15449 "Define an administrative distance\n"
15450 "BGP distance\n"
15451 "Distance for routes external to the AS\n"
15452 "Distance for routes internal to the AS\n"
15453 "Distance for local routes\n")
15454{
15455 struct bgp *bgp;
15456
15457 bgp = vty->index;
15458
15459 bgp->ipv6_distance_ebgp = atoi (argv[0]);
15460 bgp->ipv6_distance_ibgp = atoi (argv[1]);
15461 bgp->ipv6_distance_local = atoi (argv[2]);
15462 return CMD_SUCCESS;
15463}
15464
15465DEFUN (no_ipv6_bgp_distance,
15466 no_ipv6_bgp_distance_cmd,
15467 "no distance bgp <1-255> <1-255> <1-255>",
15468 NO_STR
15469 "Define an administrative distance\n"
15470 "BGP distance\n"
15471 "Distance for routes external to the AS\n"
15472 "Distance for routes internal to the AS\n"
15473 "Distance for local routes\n")
15474{
15475 struct bgp *bgp;
15476
15477 bgp = vty->index;
15478
15479 bgp->ipv6_distance_ebgp= 0;
15480 bgp->ipv6_distance_ibgp = 0;
15481 bgp->ipv6_distance_local = 0;
15482 return CMD_SUCCESS;
15483}
15484
15485ALIAS (no_ipv6_bgp_distance,
15486 no_ipv6_bgp_distance2_cmd,
15487 "no distance bgp",
15488 NO_STR
15489 "Define an administrative distance\n"
15490 "BGP distance\n")
15491
15492DEFUN (ipv6_bgp_distance_source,
15493 ipv6_bgp_distance_source_cmd,
15494 "distance <1-255> X:X::X:X/M",
15495 "Define an administrative distance\n"
15496 "Administrative distance\n"
15497 "IP source prefix\n")
15498{
15499 bgp_distance_set (vty, argv[0], argv[1], NULL);
15500 return CMD_SUCCESS;
15501}
15502
15503DEFUN (no_ipv6_bgp_distance_source,
15504 no_ipv6_bgp_distance_source_cmd,
15505 "no distance <1-255> X:X::X:X/M",
15506 NO_STR
15507 "Define an administrative distance\n"
15508 "Administrative distance\n"
15509 "IP source prefix\n")
15510{
15511 bgp_distance_unset (vty, argv[0], argv[1], NULL);
15512 return CMD_SUCCESS;
15513}
15514
15515DEFUN (ipv6_bgp_distance_source_access_list,
15516 ipv6_bgp_distance_source_access_list_cmd,
15517 "distance <1-255> X:X::X:X/M WORD",
15518 "Define an administrative distance\n"
15519 "Administrative distance\n"
15520 "IP source prefix\n"
15521 "Access list name\n")
15522{
15523 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
15524 return CMD_SUCCESS;
15525}
15526
15527DEFUN (no_ipv6_bgp_distance_source_access_list,
15528 no_ipv6_bgp_distance_source_access_list_cmd,
15529 "no distance <1-255> X:X::X:X/M WORD",
15530 NO_STR
15531 "Define an administrative distance\n"
15532 "Administrative distance\n"
15533 "IP source prefix\n"
15534 "Access list name\n")
15535{
15536 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
15537 return CMD_SUCCESS;
15538}
15539#endif
15540
paul718e3742002-12-13 20:15:29 +000015541DEFUN (bgp_damp_set,
15542 bgp_damp_set_cmd,
15543 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15544 "BGP Specific commands\n"
15545 "Enable route-flap dampening\n"
15546 "Half-life time for the penalty\n"
15547 "Value to start reusing a route\n"
15548 "Value to start suppressing a route\n"
15549 "Maximum duration to suppress a stable route\n")
15550{
15551 struct bgp *bgp;
15552 int half = DEFAULT_HALF_LIFE * 60;
15553 int reuse = DEFAULT_REUSE;
15554 int suppress = DEFAULT_SUPPRESS;
15555 int max = 4 * half;
15556
15557 if (argc == 4)
15558 {
15559 half = atoi (argv[0]) * 60;
15560 reuse = atoi (argv[1]);
15561 suppress = atoi (argv[2]);
15562 max = atoi (argv[3]) * 60;
15563 }
15564 else if (argc == 1)
15565 {
15566 half = atoi (argv[0]) * 60;
15567 max = 4 * half;
15568 }
15569
15570 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000015571
15572 if (suppress < reuse)
15573 {
15574 vty_out (vty, "Suppress value cannot be less than reuse value %s",
15575 VTY_NEWLINE);
15576 return 0;
15577 }
15578
paul718e3742002-12-13 20:15:29 +000015579 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
15580 half, reuse, suppress, max);
15581}
15582
15583ALIAS (bgp_damp_set,
15584 bgp_damp_set2_cmd,
15585 "bgp dampening <1-45>",
15586 "BGP Specific commands\n"
15587 "Enable route-flap dampening\n"
15588 "Half-life time for the penalty\n")
15589
15590ALIAS (bgp_damp_set,
15591 bgp_damp_set3_cmd,
15592 "bgp dampening",
15593 "BGP Specific commands\n"
15594 "Enable route-flap dampening\n")
15595
15596DEFUN (bgp_damp_unset,
15597 bgp_damp_unset_cmd,
15598 "no bgp dampening",
15599 NO_STR
15600 "BGP Specific commands\n"
15601 "Enable route-flap dampening\n")
15602{
15603 struct bgp *bgp;
15604
15605 bgp = vty->index;
15606 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
15607}
15608
15609ALIAS (bgp_damp_unset,
15610 bgp_damp_unset2_cmd,
15611 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
15612 NO_STR
15613 "BGP Specific commands\n"
15614 "Enable route-flap dampening\n"
15615 "Half-life time for the penalty\n"
15616 "Value to start reusing a route\n"
15617 "Value to start suppressing a route\n"
15618 "Maximum duration to suppress a stable route\n")
15619
Lou Bergerf9b6c392016-01-12 13:42:09 -050015620DEFUN (show_ip_bgp_dampened_paths,
15621 show_ip_bgp_dampened_paths_cmd,
15622 "show ip bgp dampened-paths",
15623 SHOW_STR
15624 IP_STR
15625 BGP_STR
15626 "Display paths suppressed due to dampening\n")
15627{
15628 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
15629 NULL);
15630}
15631
15632ALIAS (show_ip_bgp_dampened_paths,
15633 show_ip_bgp_damp_dampened_paths_cmd,
15634 "show ip bgp dampening dampened-paths",
15635 SHOW_STR
15636 IP_STR
15637 BGP_STR
15638 "Display detailed information about dampening\n"
15639 "Display paths suppressed due to dampening\n")
15640
15641DEFUN (show_ip_bgp_flap_statistics,
15642 show_ip_bgp_flap_statistics_cmd,
15643 "show ip bgp flap-statistics",
15644 SHOW_STR
15645 IP_STR
15646 BGP_STR
15647 "Display flap statistics of routes\n")
15648{
15649 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
15650 bgp_show_type_flap_statistics, NULL);
15651}
15652
15653ALIAS (show_ip_bgp_flap_statistics,
15654 show_ip_bgp_damp_flap_statistics_cmd,
15655 "show ip bgp dampening flap-statistics",
15656 SHOW_STR
15657 IP_STR
15658 BGP_STR
15659 "Display detailed information about dampening\n"
15660 "Display flap statistics of routes\n")
15661
Lou Berger651b4022016-01-12 13:42:07 -050015662DEFUN (show_bgp_ipv4_safi_dampened_paths,
15663 show_bgp_ipv4_safi_dampened_paths_cmd,
15664 "show bgp ipv4 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015665 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015666 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015667 IP_STR
15668 "Address Family modifier\n"
15669 "Address Family modifier\n"
15670 "Address Family modifier\n"
15671 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015672 "Display paths suppressed due to dampening\n")
15673{
Lou Berger651b4022016-01-12 13:42:07 -050015674 safi_t safi;
paul718e3742002-12-13 20:15:29 +000015675
Lou Berger651b4022016-01-12 13:42:07 -050015676 if (bgp_parse_safi(argv[0], &safi)) {
15677 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15678 return CMD_WARNING;
15679 }
15680
15681 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_dampend_paths, NULL);
15682}
15683ALIAS (show_bgp_ipv4_safi_dampened_paths,
15684 show_bgp_ipv4_safi_damp_dampened_paths_cmd,
15685 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening dampened-paths",
Balaji3921cc52015-05-16 23:12:17 +053015686 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015687 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015688 IP_STR
15689 "Address Family modifier\n"
15690 "Address Family modifier\n"
15691 "Address Family modifier\n"
15692 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015693 "Display detailed information about dampening\n"
15694 "Display paths suppressed due to dampening\n")
Lou Berger205e6742016-01-12 13:42:11 -050015695
Lou Berger651b4022016-01-12 13:42:07 -050015696DEFUN (show_bgp_ipv6_safi_dampened_paths,
15697 show_bgp_ipv6_safi_dampened_paths_cmd,
15698 "show bgp ipv6 (encap|multicast|unicast|vpn) dampened-paths",
paul718e3742002-12-13 20:15:29 +000015699 SHOW_STR
paul718e3742002-12-13 20:15:29 +000015700 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015701 IPV6_STR
15702 "Address Family modifier\n"
15703 "Address Family modifier\n"
15704 "Address Family modifier\n"
15705 "Address Family modifier\n"
15706 "Display paths suppressed due to dampening\n")
15707{
15708 safi_t safi;
15709
15710 if (bgp_parse_safi(argv[0], &safi)) {
15711 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15712 return CMD_WARNING;
15713 }
15714
15715 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_dampend_paths, NULL);
15716}
15717ALIAS (show_bgp_ipv6_safi_dampened_paths,
15718 show_bgp_ipv6_safi_damp_dampened_paths_cmd,
15719 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening dampened-paths",
15720 SHOW_STR
15721 BGP_STR
15722 IPV6_STR
15723 "Address Family modifier\n"
15724 "Address Family modifier\n"
15725 "Address Family modifier\n"
15726 "Address Family modifier\n"
15727 "Display detailed information about dampening\n"
15728 "Display paths suppressed due to dampening\n")
Lou Berger651b4022016-01-12 13:42:07 -050015729
15730DEFUN (show_bgp_ipv4_safi_flap_statistics,
15731 show_bgp_ipv4_safi_flap_statistics_cmd,
15732 "show bgp ipv4 (encap|multicast|unicast|vpn) flap-statistics",
15733 SHOW_STR
15734 BGP_STR
15735 "Address Family\n"
15736 "Address Family modifier\n"
15737 "Address Family modifier\n"
15738 "Address Family modifier\n"
15739 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +000015740 "Display flap statistics of routes\n")
15741{
Lou Berger651b4022016-01-12 13:42:07 -050015742 safi_t safi;
David Lamparter6b0655a2014-06-04 06:53:35 +020015743
Lou Berger651b4022016-01-12 13:42:07 -050015744 if (bgp_parse_safi(argv[0], &safi)) {
15745 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15746 return CMD_WARNING;
15747 }
15748
15749 return bgp_show (vty, NULL, AFI_IP, safi, bgp_show_type_flap_statistics, NULL);
15750}
15751ALIAS (show_bgp_ipv4_safi_flap_statistics,
15752 show_bgp_ipv4_safi_damp_flap_statistics_cmd,
15753 "show bgp ipv4 (encap|multicast|unicast|vpn) dampening flap-statistics",
Balaji3921cc52015-05-16 23:12:17 +053015754 SHOW_STR
Balaji3921cc52015-05-16 23:12:17 +053015755 BGP_STR
Lou Berger651b4022016-01-12 13:42:07 -050015756 "Address Family\n"
15757 "Address Family modifier\n"
15758 "Address Family modifier\n"
15759 "Address Family modifier\n"
15760 "Address Family modifier\n"
Balaji3921cc52015-05-16 23:12:17 +053015761 "Display detailed information about dampening\n"
15762 "Display flap statistics of routes\n")
Lou Berger205e6742016-01-12 13:42:11 -050015763
Lou Berger651b4022016-01-12 13:42:07 -050015764DEFUN (show_bgp_ipv6_safi_flap_statistics,
15765 show_bgp_ipv6_safi_flap_statistics_cmd,
15766 "show bgp ipv6 (encap|multicast|unicast|vpn) flap-statistics",
15767 SHOW_STR
15768 BGP_STR
15769 "Address Family\n"
15770 "Address Family modifier\n"
15771 "Address Family modifier\n"
15772 "Address Family modifier\n"
15773 "Address Family modifier\n"
15774 "Display flap statistics of routes\n")
15775{
15776 safi_t safi;
15777
15778 if (bgp_parse_safi(argv[0], &safi)) {
15779 vty_out (vty, "Error: Bad SAFI: %s%s", argv[0], VTY_NEWLINE);
15780 return CMD_WARNING;
15781 }
15782
15783 return bgp_show (vty, NULL, AFI_IP6, safi, bgp_show_type_flap_statistics, NULL);
15784}
15785ALIAS (show_bgp_ipv6_safi_flap_statistics,
15786 show_bgp_ipv6_safi_damp_flap_statistics_cmd,
15787 "show bgp ipv6 (encap|multicast|unicast|vpn) dampening flap-statistics",
15788 SHOW_STR
15789 BGP_STR
15790 "Address Family\n"
15791 "Address Family modifier\n"
15792 "Address Family modifier\n"
15793 "Address Family modifier\n"
15794 "Address Family modifier\n"
15795 "Display detailed information about dampening\n"
15796 "Display flap statistics of routes\n")
Balaji3921cc52015-05-16 23:12:17 +053015797
paul718e3742002-12-13 20:15:29 +000015798/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000015799static int
paulfd79ac92004-10-13 05:06:08 +000015800bgp_clear_damp_route (struct vty *vty, const char *view_name,
15801 const char *ip_str, afi_t afi, safi_t safi,
15802 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000015803{
15804 int ret;
15805 struct prefix match;
15806 struct bgp_node *rn;
15807 struct bgp_node *rm;
15808 struct bgp_info *ri;
15809 struct bgp_info *ri_temp;
15810 struct bgp *bgp;
15811 struct bgp_table *table;
15812
15813 /* BGP structure lookup. */
15814 if (view_name)
15815 {
15816 bgp = bgp_lookup_by_name (view_name);
15817 if (bgp == NULL)
15818 {
15819 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
15820 return CMD_WARNING;
15821 }
15822 }
15823 else
15824 {
15825 bgp = bgp_get_default ();
15826 if (bgp == NULL)
15827 {
15828 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
15829 return CMD_WARNING;
15830 }
15831 }
15832
15833 /* Check IP address argument. */
15834 ret = str2prefix (ip_str, &match);
15835 if (! ret)
15836 {
15837 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
15838 return CMD_WARNING;
15839 }
15840
15841 match.family = afi2family (afi);
15842
Lou Berger298cc2f2016-01-12 13:42:02 -050015843 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000015844 {
Lou Berger298cc2f2016-01-12 13:42:02 -050015845 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000015846 {
15847 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
15848 continue;
15849
15850 if ((table = rn->info) != NULL)
15851 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015852 {
15853 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
15854 {
15855 ri = rm->info;
15856 while (ri)
15857 {
15858 if (ri->extra && ri->extra->damp_info)
15859 {
15860 ri_temp = ri->next;
15861 bgp_damp_info_free (ri->extra->damp_info, 1);
15862 ri = ri_temp;
15863 }
15864 else
15865 ri = ri->next;
15866 }
15867 }
15868
15869 bgp_unlock_node (rm);
15870 }
paul718e3742002-12-13 20:15:29 +000015871 }
15872 }
15873 else
15874 {
15875 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000015876 {
15877 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
15878 {
15879 ri = rn->info;
15880 while (ri)
15881 {
15882 if (ri->extra && ri->extra->damp_info)
15883 {
15884 ri_temp = ri->next;
15885 bgp_damp_info_free (ri->extra->damp_info, 1);
15886 ri = ri_temp;
15887 }
15888 else
15889 ri = ri->next;
15890 }
15891 }
15892
15893 bgp_unlock_node (rn);
15894 }
paul718e3742002-12-13 20:15:29 +000015895 }
15896
15897 return CMD_SUCCESS;
15898}
15899
15900DEFUN (clear_ip_bgp_dampening,
15901 clear_ip_bgp_dampening_cmd,
15902 "clear ip bgp dampening",
15903 CLEAR_STR
15904 IP_STR
15905 BGP_STR
15906 "Clear route flap dampening information\n")
15907{
15908 bgp_damp_info_clean ();
15909 return CMD_SUCCESS;
15910}
15911
15912DEFUN (clear_ip_bgp_dampening_prefix,
15913 clear_ip_bgp_dampening_prefix_cmd,
15914 "clear ip bgp dampening A.B.C.D/M",
15915 CLEAR_STR
15916 IP_STR
15917 BGP_STR
15918 "Clear route flap dampening information\n"
15919 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
15920{
15921 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15922 SAFI_UNICAST, NULL, 1);
15923}
15924
15925DEFUN (clear_ip_bgp_dampening_address,
15926 clear_ip_bgp_dampening_address_cmd,
15927 "clear ip bgp dampening A.B.C.D",
15928 CLEAR_STR
15929 IP_STR
15930 BGP_STR
15931 "Clear route flap dampening information\n"
15932 "Network to clear damping information\n")
15933{
15934 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
15935 SAFI_UNICAST, NULL, 0);
15936}
15937
15938DEFUN (clear_ip_bgp_dampening_address_mask,
15939 clear_ip_bgp_dampening_address_mask_cmd,
15940 "clear ip bgp dampening A.B.C.D A.B.C.D",
15941 CLEAR_STR
15942 IP_STR
15943 BGP_STR
15944 "Clear route flap dampening information\n"
15945 "Network to clear damping information\n"
15946 "Network mask\n")
15947{
15948 int ret;
15949 char prefix_str[BUFSIZ];
15950
15951 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
15952 if (! ret)
15953 {
15954 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
15955 return CMD_WARNING;
15956 }
15957
15958 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
15959 SAFI_UNICAST, NULL, 0);
15960}
David Lamparter6b0655a2014-06-04 06:53:35 +020015961
Lou Berger298cc2f2016-01-12 13:42:02 -050015962/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000015963static int
paul718e3742002-12-13 20:15:29 +000015964bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
15965 afi_t afi, safi_t safi, int *write)
15966{
15967 struct bgp_node *prn;
15968 struct bgp_node *rn;
15969 struct bgp_table *table;
15970 struct prefix *p;
15971 struct prefix_rd *prd;
15972 struct bgp_static *bgp_static;
15973 u_int32_t label;
15974 char buf[SU_ADDRSTRLEN];
15975 char rdbuf[RD_ADDRSTRLEN];
15976
15977 /* Network configuration. */
15978 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
15979 if ((table = prn->info) != NULL)
15980 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
15981 if ((bgp_static = rn->info) != NULL)
15982 {
15983 p = &rn->p;
15984 prd = (struct prefix_rd *) &prn->p;
15985
15986 /* "address-family" display. */
15987 bgp_config_write_family_header (vty, afi, safi, write);
15988
15989 /* "network" configuration display. */
15990 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
15991 label = decode_label (bgp_static->tag);
15992
15993 vty_out (vty, " network %s/%d rd %s tag %d",
15994 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
15995 p->prefixlen,
15996 rdbuf, label);
15997 vty_out (vty, "%s", VTY_NEWLINE);
15998 }
15999 return 0;
16000}
16001
16002/* Configuration of static route announcement and aggregate
16003 information. */
16004int
16005bgp_config_write_network (struct vty *vty, struct bgp *bgp,
16006 afi_t afi, safi_t safi, int *write)
16007{
16008 struct bgp_node *rn;
16009 struct prefix *p;
16010 struct bgp_static *bgp_static;
16011 struct bgp_aggregate *bgp_aggregate;
16012 char buf[SU_ADDRSTRLEN];
16013
Lou Berger298cc2f2016-01-12 13:42:02 -050016014 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000016015 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
16016
16017 /* Network configuration. */
16018 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
16019 if ((bgp_static = rn->info) != NULL)
16020 {
16021 p = &rn->p;
16022
16023 /* "address-family" display. */
16024 bgp_config_write_family_header (vty, afi, safi, write);
16025
16026 /* "network" configuration display. */
16027 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16028 {
16029 u_int32_t destination;
16030 struct in_addr netmask;
16031
16032 destination = ntohl (p->u.prefix4.s_addr);
16033 masklen2ip (p->prefixlen, &netmask);
16034 vty_out (vty, " network %s",
16035 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
16036
16037 if ((IN_CLASSC (destination) && p->prefixlen == 24)
16038 || (IN_CLASSB (destination) && p->prefixlen == 16)
16039 || (IN_CLASSA (destination) && p->prefixlen == 8)
16040 || p->u.prefix4.s_addr == 0)
16041 {
16042 /* Natural mask is not display. */
16043 }
16044 else
16045 vty_out (vty, " mask %s", inet_ntoa (netmask));
16046 }
16047 else
16048 {
16049 vty_out (vty, " network %s/%d",
16050 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16051 p->prefixlen);
16052 }
16053
16054 if (bgp_static->rmap.name)
16055 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000016056 else
16057 {
16058 if (bgp_static->backdoor)
16059 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000016060 }
paul718e3742002-12-13 20:15:29 +000016061
16062 vty_out (vty, "%s", VTY_NEWLINE);
16063 }
16064
16065 /* Aggregate-address configuration. */
16066 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
16067 if ((bgp_aggregate = rn->info) != NULL)
16068 {
16069 p = &rn->p;
16070
16071 /* "address-family" display. */
16072 bgp_config_write_family_header (vty, afi, safi, write);
16073
16074 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
16075 {
16076 struct in_addr netmask;
16077
16078 masklen2ip (p->prefixlen, &netmask);
16079 vty_out (vty, " aggregate-address %s %s",
16080 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16081 inet_ntoa (netmask));
16082 }
16083 else
16084 {
16085 vty_out (vty, " aggregate-address %s/%d",
16086 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
16087 p->prefixlen);
16088 }
16089
16090 if (bgp_aggregate->as_set)
16091 vty_out (vty, " as-set");
16092
16093 if (bgp_aggregate->summary_only)
16094 vty_out (vty, " summary-only");
16095
16096 vty_out (vty, "%s", VTY_NEWLINE);
16097 }
16098
16099 return 0;
16100}
16101
16102int
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016103bgp_config_write_distance (struct vty *vty, struct bgp *bgp,
16104 afi_t afi, safi_t safi, int *write)
paul718e3742002-12-13 20:15:29 +000016105{
16106 struct bgp_node *rn;
16107 struct bgp_distance *bdistance;
16108
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016109 if (afi == AFI_IP && safi == SAFI_UNICAST)
16110 {
16111 /* Distance configuration. */
16112 if (bgp->distance_ebgp
16113 && bgp->distance_ibgp
16114 && bgp->distance_local
16115 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16116 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16117 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16118 vty_out (vty, " distance bgp %d %d %d%s",
16119 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
16120 VTY_NEWLINE);
16121
16122 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16123 if ((bdistance = rn->info) != NULL)
16124 {
16125 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16126 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
16127 bdistance->access_list ? bdistance->access_list : "",
16128 VTY_NEWLINE);
16129 }
16130 }
16131
16132#ifdef HAVE_IPV6
16133 else if (afi == AFI_IP6 && safi == SAFI_UNICAST)
16134 {
16135 bgp_config_write_family_header (vty, afi, safi, write);
16136 if (bgp->ipv6_distance_ebgp
16137 && bgp->ipv6_distance_ibgp
16138 && bgp->ipv6_distance_local
16139 && (bgp->ipv6_distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
16140 || bgp->ipv6_distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
16141 || bgp->ipv6_distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
16142 vty_out (vty, " distance bgp %d %d %d%s",
16143 bgp->ipv6_distance_ebgp, bgp->ipv6_distance_ibgp, bgp->ipv6_distance_local,
16144 VTY_NEWLINE);
16145
16146 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
16147 if ((bdistance = rn->info) != NULL)
16148 {
16149 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
16150 inet6_ntoa (rn->p.u.prefix6), rn->p.prefixlen,
16151 bdistance->access_list ? bdistance->access_list : "",
16152 VTY_NEWLINE);
16153 }
16154 }
16155#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016156
16157 return 0;
16158}
16159
16160/* Allocate routing table structure and install commands. */
16161void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080016162bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000016163{
16164 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000016165 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000016166
16167 /* IPv4 BGP commands. */
16168 install_element (BGP_NODE, &bgp_network_cmd);
16169 install_element (BGP_NODE, &bgp_network_mask_cmd);
16170 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
16171 install_element (BGP_NODE, &bgp_network_route_map_cmd);
16172 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
16173 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
16174 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
16175 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
16176 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
16177 install_element (BGP_NODE, &no_bgp_network_cmd);
16178 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
16179 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
16180 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
16181 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
16182 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16183 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
16184 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
16185 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
16186
16187 install_element (BGP_NODE, &aggregate_address_cmd);
16188 install_element (BGP_NODE, &aggregate_address_mask_cmd);
16189 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
16190 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
16191 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
16192 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
16193 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
16194 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
16195 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
16196 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
16197 install_element (BGP_NODE, &no_aggregate_address_cmd);
16198 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
16199 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
16200 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
16201 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
16202 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
16203 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
16204 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
16205 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16206 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16207
16208 /* IPv4 unicast configuration. */
16209 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
16210 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
16211 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
16212 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
16213 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
16214 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016215 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000016216 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
16217 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
16218 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
16219 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
16220 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016221
paul718e3742002-12-13 20:15:29 +000016222 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
16223 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
16224 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
16225 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
16226 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
16227 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
16228 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
16229 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
16230 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
16231 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
16232 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
16233 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
16234 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
16235 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
16236 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
16237 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
16238 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
16239 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
16240 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16241 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16242
16243 /* IPv4 multicast configuration. */
16244 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
16245 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
16246 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
16247 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
16248 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
16249 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
16250 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
16251 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
16252 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
16253 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
16254 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
16255 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
16256 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
16257 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
16258 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
16259 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
16260 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
16261 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
16262 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
16263 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
16264 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
16265 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
16266 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
16267 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
16268 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
16269 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
16270 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
16271 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
16272 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
16273 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
16274 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
16275 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
16276
Michael Lambert95cbbd22010-07-23 14:43:04 -040016277 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016278 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016279 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_route_cmd);
16280 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_route_cmd);
16281 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16282 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16283 install_element (VIEW_NODE, &show_bgp_ipv4_encap_route_cmd);
16284 install_element (VIEW_NODE, &show_bgp_ipv6_encap_route_cmd);
16285 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16286 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16287 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016288 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016289 install_element (VIEW_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16290 install_element (VIEW_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16291 install_element (VIEW_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16292 install_element (VIEW_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16293 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16294 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16295 install_element (VIEW_NODE, &show_bgp_afi_safi_view_cmd);
16296 install_element (VIEW_NODE, &show_bgp_view_afi_safi_route_cmd);
16297 install_element (VIEW_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16298 install_element (VIEW_NODE, &show_bgp_ipv4_safi_regexp_cmd);
16299 install_element (VIEW_NODE, &show_bgp_ipv6_safi_regexp_cmd);
16300 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_list_cmd);
16301 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_list_cmd);
16302 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_list_cmd);
16303 install_element (VIEW_NODE, &show_bgp_ipv4_filter_list_cmd);
16304 install_element (VIEW_NODE, &show_bgp_ipv4_safi_filter_list_cmd);
16305 install_element (VIEW_NODE, &show_bgp_ipv6_safi_filter_list_cmd);
16306 install_element (VIEW_NODE, &show_bgp_ipv4_route_map_cmd);
16307 install_element (VIEW_NODE, &show_bgp_ipv4_cidr_only_cmd);
16308 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cidr_only_cmd);
16309 install_element (VIEW_NODE, &show_bgp_ipv4_community_cmd);
16310 install_element (VIEW_NODE, &show_bgp_ipv4_community2_cmd);
16311 install_element (VIEW_NODE, &show_bgp_ipv4_community3_cmd);
16312 install_element (VIEW_NODE, &show_bgp_ipv4_community4_cmd);
16313 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_cmd);
16314 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_cmd);
16315 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_cmd);
16316 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016317 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16318 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
16319 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
16320 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
16321 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016322 install_element (VIEW_NODE, &show_bgp_ipv4_community_exact_cmd);
16323 install_element (VIEW_NODE, &show_bgp_ipv4_community2_exact_cmd);
16324 install_element (VIEW_NODE, &show_bgp_ipv4_community3_exact_cmd);
16325 install_element (VIEW_NODE, &show_bgp_ipv4_community4_exact_cmd);
16326 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16327 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16328 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16329 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
16330 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_cmd);
16331 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_cmd);
16332 install_element (VIEW_NODE, &show_bgp_ipv4_community_list_exact_cmd);
16333 install_element (VIEW_NODE, &show_bgp_ipv4_safi_community_list_exact_cmd);
16334 install_element (VIEW_NODE, &show_bgp_ipv4_prefix_longer_cmd);
16335 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_longer_cmd);
16336 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_longer_cmd);
16337 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_advertised_route_cmd);
16338 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_advertised_route_cmd);
16339 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_routes_cmd);
16340 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016341 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016342 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_routes_cmd);
16343 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_routes_cmd);
16344 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_received_prefix_filter_cmd);
16345 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_received_prefix_filter_cmd);
16346 install_element (VIEW_NODE, &show_bgp_ipv4_safi_dampened_paths_cmd);
16347 install_element (VIEW_NODE, &show_bgp_ipv6_safi_dampened_paths_cmd);
16348 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_dampened_paths_cmd);
16349 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_dampened_paths_cmd);
16350 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_statistics_cmd);
16351 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_statistics_cmd);
16352 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_statistics_cmd);
16353 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_statistics_cmd);
16354 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_address_cmd);
16355 install_element (VIEW_NODE, &show_bgp_ipv6_flap_address_cmd);
16356 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_address_cmd);
16357 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_cmd);
16358 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_cmd);
16359 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_cmd);
16360 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_cmd);
16361 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_cidr_only_cmd);
16362 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_cidr_only_cmd);
16363 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_regexp_cmd);
16364 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_regexp_cmd);
16365 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_regexp_cmd);
16366 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_regexp_cmd);
16367 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_filter_list_cmd);
16368 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_filter_list_cmd);
16369 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_filter_list_cmd);
16370 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_filter_list_cmd);
16371 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_list_cmd);
16372 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_list_cmd);
16373 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_list_cmd);
16374 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_list_cmd);
16375 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_prefix_longer_cmd);
16376 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_prefix_longer_cmd);
16377 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_prefix_longer_cmd);
16378 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_prefix_longer_cmd);
16379 install_element (VIEW_NODE, &show_bgp_ipv4_safi_flap_route_map_cmd);
16380 install_element (VIEW_NODE, &show_bgp_ipv6_safi_flap_route_map_cmd);
16381 install_element (VIEW_NODE, &show_bgp_ipv4_safi_damp_flap_route_map_cmd);
16382 install_element (VIEW_NODE, &show_bgp_ipv6_safi_damp_flap_route_map_cmd);
16383 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_flap_cmd);
16384 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_flap_cmd);
16385 install_element (VIEW_NODE, &show_bgp_ipv4_safi_neighbor_damp_cmd);
16386 install_element (VIEW_NODE, &show_bgp_ipv6_safi_neighbor_damp_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016387 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016388 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016389 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016390 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016391 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016392 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016393
16394 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
Michael Lambert95cbbd22010-07-23 14:43:04 -040016395 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016396 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_rd_route_cmd);
16397 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_rd_route_cmd);
16398 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_route_cmd);
16399 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_route_cmd);
16400 install_element (RESTRICTED_NODE, &show_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016401 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016402 install_element (RESTRICTED_NODE, &show_bgp_ipv4_vpn_prefix_cmd);
16403 install_element (RESTRICTED_NODE, &show_bgp_ipv6_vpn_prefix_cmd);
16404 install_element (RESTRICTED_NODE, &show_bgp_ipv4_encap_prefix_cmd);
16405 install_element (RESTRICTED_NODE, &show_bgp_ipv6_encap_prefix_cmd);
16406 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rd_prefix_cmd);
16407 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rd_prefix_cmd);
16408 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_route_cmd);
16409 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_prefix_cmd);
16410 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_cmd);
16411 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_cmd);
16412 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_cmd);
16413 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_cmd);
16414 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_cmd);
16415 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_cmd);
16416 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_cmd);
16417 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016418 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
16419 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
16420 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
16421 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
16422 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016423 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community_exact_cmd);
16424 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community2_exact_cmd);
16425 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community3_exact_cmd);
16426 install_element (RESTRICTED_NODE, &show_bgp_ipv4_community4_exact_cmd);
16427 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community_exact_cmd);
16428 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community2_exact_cmd);
16429 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community3_exact_cmd);
16430 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_community4_exact_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016431 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016432 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016433 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016434 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016435
Donald Sharp68b45cc2016-03-11 14:27:13 -050016436 /* BGP dampening clear commands */
paul718e3742002-12-13 20:15:29 +000016437 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
16438 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
16439 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
16440 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
16441
paul718e3742002-12-13 20:15:29 +000016442 /* New config IPv6 BGP commands. */
16443 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
16444 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
16445 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
16446 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
16447
16448 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
16449 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
16450 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
16451 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
16452
G.Balaji73bfe0b2011-09-23 22:36:20 +053016453 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
16454 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
16455
paul718e3742002-12-13 20:15:29 +000016456 /* Old config IPv6 BGP commands. */
16457 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
16458 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
16459
16460 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
16461 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
16462 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
16463 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
16464
Michael Lambert95cbbd22010-07-23 14:43:04 -040016465 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000016466 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016467 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000016468 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016469 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016470 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000016471 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000016472 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000016473 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016474 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_cmd);
16475 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_cmd);
16476 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_cmd);
16477 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_cmd);
16478 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16479 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16480 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16481 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
paul718e3742002-12-13 20:15:29 +000016482 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
paul718e3742002-12-13 20:15:29 +000016483 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000016484 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
paul718e3742002-12-13 20:15:29 +000016485 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016486 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
paul718e3742002-12-13 20:15:29 +000016487 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016488 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016489 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016490 install_element (VIEW_NODE, &show_bgp_ipv4_rsclient_cmd);
16491 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016492 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016493 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016494 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016495 install_element (VIEW_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016496 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016497 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
paulbb46e942003-10-24 19:02:03 +000016498 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016499 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000016500 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
paulbb46e942003-10-24 19:02:03 +000016501 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016502 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
paulbb46e942003-10-24 19:02:03 +000016503 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000016504 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
paulbb46e942003-10-24 19:02:03 +000016505 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016506 install_element (VIEW_NODE, &show_bgp_view_ipv4_rsclient_cmd);
16507 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016508 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016509 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016510 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016511 install_element (VIEW_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016512 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016513
16514 /* Restricted:
16515 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
16516 */
Paul Jakma62687ff2008-08-23 14:27:06 +010016517 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016518 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016519 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016520 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016521 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_cmd);
16522 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_cmd);
16523 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_cmd);
16524 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_cmd);
16525 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community_exact_cmd);
16526 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community2_exact_cmd);
16527 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community3_exact_cmd);
16528 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_community4_exact_cmd);
16529 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016530 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016531 install_element (RESTRICTED_NODE, &show_bgp_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016532 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016533 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016534 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010016535 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016536 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016537 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016538 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040016539 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016540
Paul Jakma2815e612006-09-14 02:56:07 +000016541 /* Statistics */
16542 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger651b4022016-01-12 13:42:07 -050016543 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
paul718e3742002-12-13 20:15:29 +000016544
16545 install_element (BGP_NODE, &bgp_distance_cmd);
16546 install_element (BGP_NODE, &no_bgp_distance_cmd);
16547 install_element (BGP_NODE, &no_bgp_distance2_cmd);
16548 install_element (BGP_NODE, &bgp_distance_source_cmd);
16549 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
16550 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
16551 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
Roman Hoog Antink6184c392014-03-17 14:01:42 +010016552#ifdef HAVE_IPV6
16553 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_cmd);
16554 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_cmd);
16555 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance2_cmd);
16556 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_cmd);
16557 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_cmd);
16558 install_element (BGP_IPV6_NODE, &ipv6_bgp_distance_source_access_list_cmd);
16559 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_distance_source_access_list_cmd);
16560#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000016561
16562 install_element (BGP_NODE, &bgp_damp_set_cmd);
16563 install_element (BGP_NODE, &bgp_damp_set2_cmd);
16564 install_element (BGP_NODE, &bgp_damp_set3_cmd);
16565 install_element (BGP_NODE, &bgp_damp_unset_cmd);
16566 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
16567 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
16568 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
16569 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
16570 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
16571 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Balaji9145f0e2016-01-20 22:59:27 +053016572
16573 /* IPv4 Multicast Mode */
16574 install_element (BGP_IPV4M_NODE, &bgp_damp_set_cmd);
16575 install_element (BGP_IPV4M_NODE, &bgp_damp_set2_cmd);
16576 install_element (BGP_IPV4M_NODE, &bgp_damp_set3_cmd);
16577 install_element (BGP_IPV4M_NODE, &bgp_damp_unset_cmd);
16578 install_element (BGP_IPV4M_NODE, &bgp_damp_unset2_cmd);
16579
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016580
16581 /* Deprecated AS-Pathlimit commands */
16582 install_element (BGP_NODE, &bgp_network_ttl_cmd);
16583 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
16584 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
16585 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
16586 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16587 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16588
16589 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
16590 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
16591 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16592 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
16593 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16594 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16595
16596 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
16597 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
16598 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
16599 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
16600 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16601 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16602
16603 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
16604 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
16605 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16606 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
16607 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16608 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
16609
16610 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
16611 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
16612 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
16613 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
16614 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
16615 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
16616
16617 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
16618 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
16619 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
16620 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
16621 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
16622 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000016623
Paul Jakmac8f3fe32010-12-05 20:28:02 +000016624 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
16625 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016626
16627 /* old style commands */
16628 install_element (VIEW_NODE, &show_ip_bgp_cmd);
16629 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
16630 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016631 install_element (VIEW_NODE, &show_ip_bgp_route_pathtype_cmd);
16632 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016633 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
16634 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
16635 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16636 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
16637 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016638 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16639 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16640 install_element (VIEW_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016641 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16642 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16643 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
16644 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
16645 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
16646 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
16647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
16648 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
16649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
16650 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
16651 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
16652 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
16653 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
16654 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
16655 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
16656 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
16657 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
16658 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
16659 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
16660 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
16661 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
16662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
16663 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
16664 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
16665 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
16666 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
16667 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
16668 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
16669 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
16670 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16671 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16672 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16673 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16674 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
16675 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
16676 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
16677 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
16678 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
16679 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
16680 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
16681 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
16682 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
16683 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
16684 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
16685 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
16686 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
16687 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
16688 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016689 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_parameters_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016690 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji9c52cae2016-01-20 22:59:26 +053016691 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_dampd_paths_cmd);
16692 install_element (VIEW_NODE, &show_ip_bgp_ipv4_dampening_flap_stats_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016693 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
16694 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
16695 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
16696 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
16697 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
16698 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
16699 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
16700 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
16701 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
16702 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
16703 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
16704 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
16705 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
16706 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
16707 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
16708 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
16709 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
16710 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
16711 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
16712 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
16713 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
16714 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16715 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
16716 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
16717 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
16718 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16719 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016720
Lou Bergerf9b6c392016-01-12 13:42:09 -050016721 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016722 install_element (RESTRICTED_NODE, &show_ip_bgp_route_pathtype_cmd);
16723 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016724 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
16725 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
16726 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
16727 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016728 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_pathtype_cmd);
16729 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_pathtype_cmd);
16730 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016731 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
16732 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
16733 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
16734 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
16735 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
16736 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
16737 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
16738 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
16739 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
16740 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
16741 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
16742 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
16743 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
16744 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
16745 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
16746 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
16747 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
16748 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
16749 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
16750 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
16751 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
16752 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
16753 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
16754 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016755
16756 install_element (VIEW_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
16757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
16758 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016759
Lou Bergerf9b6c392016-01-12 13:42:09 -050016760 install_element (VIEW_NODE, &show_bgp_cmd);
16761 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
16762 install_element (VIEW_NODE, &show_bgp_route_cmd);
16763 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016764 install_element (VIEW_NODE, &show_bgp_route_pathtype_cmd);
16765 install_element (VIEW_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16766 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16767 install_element (VIEW_NODE, &show_bgp_prefix_pathtype_cmd);
16768 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16769 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016770 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
16771 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
16772 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
16773 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
16774 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
16775 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
16776 install_element (VIEW_NODE, &show_bgp_community_cmd);
16777 install_element (VIEW_NODE, &show_bgp_community2_cmd);
16778 install_element (VIEW_NODE, &show_bgp_community3_cmd);
16779 install_element (VIEW_NODE, &show_bgp_community4_cmd);
16780 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
16781 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
16782 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
16783 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
16784 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_cmd);
16785 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
16786 install_element (VIEW_NODE, &show_bgp_ipv6_safi_community_list_exact_cmd);
16787 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
16788 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
16789 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
16790 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
16791 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
16792 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
16793 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
16794 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
16795 install_element (VIEW_NODE, &show_bgp_view_cmd);
16796 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
16797 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
16798 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
16799 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
16800 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
16801 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
16802 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
16803 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
16804 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016805
Lou Bergerf9b6c392016-01-12 13:42:09 -050016806 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
16807 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016808 install_element (RESTRICTED_NODE, &show_bgp_route_pathtype_cmd);
16809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_pathtype_cmd);
16810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_pathtype_cmd);
16811 install_element (RESTRICTED_NODE, &show_bgp_prefix_pathtype_cmd);
16812 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_pathtype_cmd);
16813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_pathtype_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016814 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
16815 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
16816 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
16817 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
16818 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
16819 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
16820 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
16821 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
16822 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
16823 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
16824 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
Daniel Walton59fe0ee2015-05-19 17:58:11 -070016825
Lou Bergerf9b6c392016-01-12 13:42:09 -050016826 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
16827 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016828
Lou Bergerf9b6c392016-01-12 13:42:09 -050016829 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
16830 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
16831 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
16832 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
16833 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
16834 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
16835 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
16836 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
16837 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
16838 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
16839 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
16840 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
16841 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
16842 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
16843 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
16844 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
16845 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
16846 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
16847 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
16848 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
16849 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
16850 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
16851 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
16852 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
16853 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
16854 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
16855 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
16856 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
16857 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
16858 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
16859 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
16860 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
16861 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
16862 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
16863 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
16864 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016865 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016866 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016867 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016868 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016869 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016870 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016871 /* old with name safi collision */
16872 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
16873 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
16874 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
16875 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
16876 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
16877 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
16878 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
16879 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
16880 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
16881 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
16882 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
16883 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
16884 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
16885 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
16886 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
16887 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
Donald Sharp68b45cc2016-03-11 14:27:13 -050016888
Lou Bergerf9b6c392016-01-12 13:42:09 -050016889 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
16890 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016891
16892 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
16893 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
16894 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
16895 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Lou Bergerf9b6c392016-01-12 13:42:09 -050016896
16897 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
16898 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
16899 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
16900 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000016901}
Chris Caputo228da422009-07-18 05:44:03 +000016902
16903void
16904bgp_route_finish (void)
16905{
16906 bgp_table_unlock (bgp_distance_table);
16907 bgp_distance_table = NULL;
16908}